Home | History | Annotate | Download | only in kernels
      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/fake_input.h"
     18 #include "tensorflow/core/framework/node_def_builder.h"
     19 #include "tensorflow/core/framework/tensor.h"
     20 #include "tensorflow/core/graph/node_builder.h"
     21 #include "tensorflow/core/kernels/ops_testutil.h"
     22 #include "tensorflow/core/platform/test.h"
     23 #include "tensorflow/core/platform/test_benchmark.h"
     24 
     25 namespace tensorflow {
     26 
     27 static Graph* Bincount(int arr_size, int nbins) {
     28   Graph* g = new Graph(OpRegistry::Global());
     29 
     30   Tensor arr(DT_INT32, TensorShape({arr_size}));
     31   arr.flat<int32>() = arr.flat<int32>().setRandom().abs();
     32 
     33   Tensor size(DT_INT32, TensorShape({static_cast<int32>(1)}));
     34   size.flat<int32>()(0) = static_cast<int32>(nbins);
     35 
     36   Tensor weights(DT_INT32, TensorShape({0}));
     37 
     38   Node* node;
     39   TF_CHECK_OK(NodeBuilder(g->NewName("n"), "Bincount")
     40                   .Input(test::graph::Constant(g, arr))
     41                   .Input(test::graph::Constant(g, size))
     42                   .Input(test::graph::Constant(g, weights))
     43                   .Attr("T", DT_INT32)
     44                   .Finalize(g, &node));
     45   return g;
     46 }
     47 
     48 #define BM_BincountDev(K, NBINS, type)                             \
     49   static void BM_Bincount##_##type##_##K##_##NBINS(int iters) {    \
     50     testing::ItemsProcessed(static_cast<int64>(iters) * K * 1024); \
     51     test::Benchmark(#type, Bincount(K * 1024, NBINS)).Run(iters);  \
     52   }                                                                \
     53   BENCHMARK(BM_Bincount##_##type##_##K##_##NBINS);
     54 
     55 BM_BincountDev(32, 1000, cpu);
     56 BM_BincountDev(32, 2000, cpu);
     57 BM_BincountDev(32, 5000, cpu);
     58 BM_BincountDev(64, 1000, cpu);
     59 BM_BincountDev(64, 2000, cpu);
     60 BM_BincountDev(64, 5000, cpu);
     61 BM_BincountDev(128, 1000, cpu);
     62 BM_BincountDev(128, 2000, cpu);
     63 BM_BincountDev(128, 5000, cpu);
     64 
     65 BM_BincountDev(32, 1000, gpu);
     66 BM_BincountDev(32, 2000, gpu);
     67 BM_BincountDev(32, 5000, gpu);
     68 BM_BincountDev(64, 1000, gpu);
     69 BM_BincountDev(64, 2000, gpu);
     70 BM_BincountDev(64, 5000, gpu);
     71 BM_BincountDev(128, 1000, gpu);
     72 BM_BincountDev(128, 2000, gpu);
     73 BM_BincountDev(128, 5000, gpu);
     74 
     75 }  // end namespace tensorflow
     76