MaxPooling Op */
| 1011 | MaxPooling Op |
| 1012 | */ |
| 1013 | static void BM_MaxPool(int iters, int batch_size, int rows, int cols, int depth, |
| 1014 | int kernel_rows, int kernel_cols, int stride, |
| 1015 | Padding padding, int num_threads, const string& label) { |
| 1016 | tensorflow::testing::StopTiming(); |
| 1017 | SessionOptions options; |
| 1018 | options.config.set_intra_op_parallelism_threads(num_threads); |
| 1019 | |
| 1020 | std::unique_ptr<Device> device( |
| 1021 | DeviceFactory::NewDevice("CPU", options, "/job:a/replica:0/task:0")); |
| 1022 | |
| 1023 | thread::ThreadPool threadpool(Env::Default(), "test", num_threads); |
| 1024 | Eigen::ThreadPoolDevice eigen_cpu_device(threadpool.AsEigenThreadPool(), |
| 1025 | num_threads); |
| 1026 | device->set_eigen_cpu_device(&eigen_cpu_device); |
| 1027 | |
| 1028 | gtl::InlinedVector<TensorValue, 4> inputs; |
| 1029 | TensorShape shape1({batch_size, rows, cols, depth}); |
| 1030 | Tensor input1(DT_FLOAT, shape1); |
| 1031 | test::FillIota<float>(&input1, 1.0); |
| 1032 | inputs.push_back({nullptr, &input1}); |
| 1033 | |
| 1034 | // MaxPooling op. |
| 1035 | NodeDef maxpool_node_def; |
| 1036 | CHECK_EQ(kernel_rows, kernel_cols); |
| 1037 | Status status = NodeDefBuilder("maxpool_op", "MaxPool") |
| 1038 | .Input(FakeInput()) |
| 1039 | .Attr("ksize", {1, kernel_rows, kernel_cols, 1}) |
| 1040 | .Attr("strides", {1, stride, stride, 1}) |
| 1041 | .Attr("padding", padding == VALID ? "VALID" : "SAME") |
| 1042 | .Finalize(&maxpool_node_def); |
| 1043 | TF_CHECK_OK(status); |
| 1044 | std::unique_ptr<OpKernel> op(CreateOpKernel(DEVICE_CPU, device.get(), |
| 1045 | cpu_allocator(), maxpool_node_def, |
| 1046 | TF_GRAPH_DEF_VERSION, &status)); |
| 1047 | TF_CHECK_OK(status); |
| 1048 | OpKernelContext::Params params; |
| 1049 | params.device = device.get(); |
| 1050 | params.frame_iter = FrameAndIter(0, 0); |
| 1051 | params.inputs = &inputs; |
| 1052 | params.op_kernel = op.get(); |
| 1053 | std::vector<AllocatorAttributes> attrs; |
| 1054 | test::SetOutputAttrs(¶ms, &attrs); |
| 1055 | |
| 1056 | std::unique_ptr<OpKernelContext> maxpool_context( |
| 1057 | new OpKernelContext(¶ms)); |
| 1058 | |
| 1059 | op->Compute(maxpool_context.get()); |
| 1060 | testing::UseRealTime(); |
| 1061 | tensorflow::testing::StartTiming(); |
| 1062 | for (int i = 0; i < iters; ++i) { |
| 1063 | delete maxpool_context->release_output(0).tensor; |
| 1064 | op->Compute(maxpool_context.get()); |
| 1065 | } |
| 1066 | tensorflow::testing::StopTiming(); |
| 1067 | testing::ItemsProcessed(maxpool_context->mutable_output(0)->NumElements() * |
| 1068 | iters); |
| 1069 | testing::SetLabel(label); |
| 1070 | } |
nothing calls this directly
no test coverage detected