MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BM_SoftplusFloat

Function BM_SoftplusFloat

tensorflow/core/kernels/nn_ops_test.cc:1271–1320  ·  view source on GitHub ↗

Softplus Op Run benchmark with: */

Source from the content-addressed store, hash-verified

1269Run benchmark with:
1270*/
1271static void BM_SoftplusFloat(int iters, int batch_size, int rows, int cols,
1272 int depth, int num_threads, const string& label) {
1273 tensorflow::testing::StopTiming();
1274 std::unique_ptr<Device> device(
1275 DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0"));
1276
1277 thread::ThreadPool threadpool(Env::Default(), "test", num_threads);
1278 Eigen::ThreadPoolDevice eigen_cpu_device(threadpool.AsEigenThreadPool(),
1279 num_threads);
1280 device->set_eigen_cpu_device(&eigen_cpu_device);
1281
1282 gtl::InlinedVector<TensorValue, 4> inputs;
1283 TensorShape shape1({batch_size, rows, cols, depth});
1284 Tensor input1(DT_FLOAT, shape1);
1285 input1.flat<float>().setRandom();
1286 inputs.push_back({nullptr, &input1});
1287
1288 // Softplusing op.
1289 NodeDef softplus_node_def;
1290 Status status = NodeDefBuilder("softplus_op", "Softplus")
1291 .Input(FakeInput(DT_FLOAT))
1292 .Finalize(&softplus_node_def);
1293 TF_CHECK_OK(status);
1294 std::unique_ptr<OpKernel> op(
1295 CreateOpKernel(DEVICE_CPU, device.get(), cpu_allocator(),
1296 softplus_node_def, TF_GRAPH_DEF_VERSION, &status));
1297 TF_CHECK_OK(status);
1298 OpKernelContext::Params params;
1299 params.device = device.get();
1300 params.frame_iter = FrameAndIter(0, 0);
1301 params.inputs = &inputs;
1302 params.op_kernel = op.get();
1303 std::vector<AllocatorAttributes> attrs;
1304 test::SetOutputAttrs(&params, &attrs);
1305
1306 std::unique_ptr<OpKernelContext> softplus_context(
1307 new OpKernelContext(&params));
1308
1309 op->Compute(softplus_context.get());
1310 testing::UseRealTime();
1311 tensorflow::testing::StartTiming();
1312 for (int i = 0; i < iters; ++i) {
1313 delete softplus_context->release_output(0).tensor;
1314 op->Compute(softplus_context.get());
1315 }
1316 tensorflow::testing::StopTiming();
1317 testing::ItemsProcessed(softplus_context->mutable_output(0)->NumElements() *
1318 iters);
1319 testing::SetLabel(label);
1320}
1321
1322// BS: batch_size
1323// IR: input_rows

Callers

nothing calls this directly

Calls 15

StopTimingFunction · 0.85
DefaultFunction · 0.85
NodeDefBuilderClass · 0.85
CreateOpKernelFunction · 0.85
cpu_allocatorFunction · 0.85
FrameAndIterClass · 0.85
SetOutputAttrsFunction · 0.85
UseRealTimeFunction · 0.85
StartTimingFunction · 0.85
ItemsProcessedFunction · 0.85
SetLabelFunction · 0.85
AsEigenThreadPoolMethod · 0.80

Tested by

no test coverage detected