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

Function BM_AvgPool

tensorflow/core/kernels/nn_ops_test.cc:818–873  ·  view source on GitHub ↗

AvgPooling Op */

Source from the content-addressed store, hash-verified

816AvgPooling Op
817*/
818static void BM_AvgPool(int iters, int batch_size, int rows, int cols, int depth,
819 int kernel_rows, int kernel_cols, int stride,
820 Padding padding, int num_threads, const string& label) {
821 tensorflow::testing::StopTiming();
822 std::unique_ptr<Device> device(
823 DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0"));
824
825 thread::ThreadPool threadpool(Env::Default(), "test", num_threads);
826 Eigen::ThreadPoolDevice eigen_cpu_device(threadpool.AsEigenThreadPool(),
827 num_threads);
828 device->set_eigen_cpu_device(&eigen_cpu_device);
829
830 gtl::InlinedVector<TensorValue, 4> inputs;
831 TensorShape shape1({batch_size, rows, cols, depth});
832 Tensor input1(DT_FLOAT, shape1);
833 test::FillIota<float>(&input1, 1.0);
834 inputs.push_back({nullptr, &input1});
835
836 // AvgPooling op.
837 NodeDef avgpool_node_def;
838 CHECK_EQ(kernel_rows, kernel_cols);
839 Status status = NodeDefBuilder("avgpool_op", "AvgPool")
840 .Input(FakeInput(DT_FLOAT))
841 .Attr("ksize", {1, kernel_rows, kernel_cols, 1})
842 .Attr("strides", {1, stride, stride, 1})
843 .Attr("padding", padding == VALID ? "VALID" : "SAME")
844 .Finalize(&avgpool_node_def);
845 TF_CHECK_OK(status);
846
847 std::unique_ptr<OpKernel> op(CreateOpKernel(DEVICE_CPU, device.get(),
848 cpu_allocator(), avgpool_node_def,
849 TF_GRAPH_DEF_VERSION, &status));
850 TF_CHECK_OK(status);
851 OpKernelContext::Params params;
852 params.device = device.get();
853 params.frame_iter = FrameAndIter(0, 0);
854 params.inputs = &inputs;
855 params.op_kernel = op.get();
856 std::vector<AllocatorAttributes> attrs;
857 test::SetOutputAttrs(&params, &attrs);
858
859 std::unique_ptr<OpKernelContext> avgpool_context(
860 new OpKernelContext(&params));
861
862 op->Compute(avgpool_context.get());
863 testing::UseRealTime();
864 tensorflow::testing::StartTiming();
865 for (int i = 0; i < iters; ++i) {
866 delete avgpool_context->release_output(0).tensor;
867 op->Compute(avgpool_context.get());
868 }
869 tensorflow::testing::StopTiming();
870 testing::ItemsProcessed(avgpool_context->mutable_output(0)->NumElements() *
871 iters);
872 testing::SetLabel(label);
873}
874
875// BS: batch_size

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