1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/core/common_runtime/kernel_benchmark_testlib.h" 17 #include "tensorflow/core/framework/tensor.h" 18 #include "tensorflow/core/graph/node_builder.h" 19 #include "tensorflow/core/platform/test.h" 20 #include "tensorflow/core/platform/test_benchmark.h" 21 22 namespace tensorflow { 23 24 static Graph* BM_AdjustContrast(int batches, int width, int height) { 25 Graph* g = new Graph(OpRegistry::Global()); 26 Tensor in(DT_FLOAT, TensorShape({batches, width, height, 3})); 27 in.flat<float>().setRandom(); 28 Tensor factor(DT_FLOAT, TensorShape({})); 29 factor.flat<float>().setConstant(1.2); 30 31 Node* ret; 32 TF_CHECK_OK(NodeBuilder(g->NewName("n"), "AdjustContrastv2") 33 .Input(test::graph::Constant(g, in)) 34 .Input(test::graph::Constant(g, factor)) 35 .Finalize(g, &ret)); 36 return g; 37 } 38 39 #define BM_AdjustContrastDev(DEVICE, B, W, H) \ 40 static void BM_AdjustContrast_##DEVICE##_##B##_##W##_##H(int iters) { \ 41 testing::ItemsProcessed(iters* B* W* H * 3); \ 42 test::Benchmark(#DEVICE, BM_AdjustContrast(B, W, H)).Run(iters); \ 43 } \ 44 BENCHMARK(BM_AdjustContrast_##DEVICE##_##B##_##W##_##H) 45 46 // Benchmark results as of cl/106323955 47 // BM_AdjustContrast_cpu_1_299_299 3416770 22008951 100 11.6M items/s 48 // BM_AdjustContrast_gpu_32_299_299 37117844 45512374 100 179.8M items/s 49 // Benchmark results as of cl/109478777 50 // (note that the definition has changed to perform no min/max or clamping, 51 // so a comparison to cl/106323955 is inherently unfair) 52 // The GPU test ran with -c opt --config=cuda --copt=-mavx, CPU ran without 53 // --config=cuda because for some reason that killed throughput measurement. 54 // CPU: Intel Haswell with HyperThreading (6 cores) dL1:32KB dL2:256KB dL3:15MB 55 // GPU: Tesla K40m 56 // BM_AdjustContrast_cpu_1_299_299 179084 340186 2181 751.9M items/s 57 // BM_AdjustContrast_gpu_32_299_299 85276 123665 4189 2.9G items/s 58 BM_AdjustContrastDev(cpu, 1, 299, 299); 59 #if GOOGLE_CUDA 60 BM_AdjustContrastDev(gpu, 32, 299, 299); 61 #endif // GOOGLE_CUDA 62 #ifdef TENSORFLOW_USE_SYCL 63 BM_AdjustContrastDev(sycl, 32, 299, 299); 64 #endif // TENSORFLOW_USE_SYCL 65 66 } // namespace tensorflow 67