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

Function BM_ReluFloat

tensorflow/core/kernels/nn_ops_test.cc:1198–1246  ·  view source on GitHub ↗

Relu Op Run benchmark with: */

Source from the content-addressed store, hash-verified

1196Run benchmark with:
1197*/
1198static void BM_ReluFloat(int iters, int batch_size, int rows, int cols,
1199 int depth, int num_threads, const string& label) {
1200 tensorflow::testing::StopTiming();
1201 std::unique_ptr<Device> device(
1202 DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0"));
1203
1204 thread::ThreadPool threadpool(Env::Default(), "test", num_threads);
1205 Eigen::ThreadPoolDevice eigen_cpu_device(threadpool.AsEigenThreadPool(),
1206 num_threads);
1207 device->set_eigen_cpu_device(&eigen_cpu_device);
1208
1209 gtl::InlinedVector<TensorValue, 4> inputs;
1210 TensorShape shape1({batch_size, rows, cols, depth});
1211 Tensor input1(DT_FLOAT, shape1);
1212 test::FillIota<float>(&input1, 1.0);
1213 inputs.push_back({nullptr, &input1});
1214
1215 // Reluing op.
1216 NodeDef relu_node_def;
1217 Status status = NodeDefBuilder("relu_op", "Relu")
1218 .Input(FakeInput(DT_FLOAT))
1219 .Finalize(&relu_node_def);
1220 TF_CHECK_OK(status);
1221 std::unique_ptr<OpKernel> op(CreateOpKernel(DEVICE_CPU, device.get(),
1222 cpu_allocator(), relu_node_def,
1223 TF_GRAPH_DEF_VERSION, &status));
1224 TF_CHECK_OK(status);
1225 OpKernelContext::Params params;
1226 params.device = device.get();
1227 params.frame_iter = FrameAndIter(0, 0);
1228 params.inputs = &inputs;
1229 params.op_kernel = op.get();
1230 std::vector<AllocatorAttributes> attrs;
1231 test::SetOutputAttrs(&params, &attrs);
1232
1233 std::unique_ptr<OpKernelContext> relu_context(new OpKernelContext(&params));
1234
1235 op->Compute(relu_context.get());
1236 testing::UseRealTime();
1237 tensorflow::testing::StartTiming();
1238 for (int i = 0; i < iters; ++i) {
1239 delete relu_context->release_output(0).tensor;
1240 op->Compute(relu_context.get());
1241 }
1242 tensorflow::testing::StopTiming();
1243 testing::ItemsProcessed(relu_context->mutable_output(0)->NumElements() *
1244 iters);
1245 testing::SetLabel(label);
1246}
1247
1248// BS: batch_size
1249// 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