From 998ba46b21127726f1d9b107498b3f0000f98571 Mon Sep 17 00:00:00 2001 From: Daniel Nguyen Date: Fri, 10 Jul 2020 23:49:50 +0000 Subject: [PATCH] summary_op_bm --- .../c/kernels/summary_op_benchmark_test.cc | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tensorflow/c/kernels/summary_op_benchmark_test.cc diff --git a/tensorflow/c/kernels/summary_op_benchmark_test.cc b/tensorflow/c/kernels/summary_op_benchmark_test.cc new file mode 100644 index 00000000000..1948253a41d --- /dev/null +++ b/tensorflow/c/kernels/summary_op_benchmark_test.cc @@ -0,0 +1,64 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/common_runtime/kernel_benchmark_testlib.h" +#include "tensorflow/core/framework/tensor.h" +#include "tensorflow/core/graph/node_builder.h" +#include "tensorflow/core/platform/test.h" +#include "tensorflow/core/platform/test_benchmark.h" +#include "tensorflow/core/framework/tensor_shape.h" + +namespace tensorflow { + +static Graph* BM_ScalarSummaryOp(TensorShape shape, const char* tag, + float value) { + Graph* g = new Graph(OpRegistry::Global()); + Tensor tags(DT_STRING, shape); + Tensor values(DT_FLOAT, shape); + for (int i = 0; i < tags.NumElements(); ++i){ + tags.flat()(i) = tag; + values.flat()(i) = value; + } + Node* ret; + TF_CHECK_OK(NodeBuilder(g->NewName("dummy"), "SummaryScalar") + .Input(test::graph::Constant(g, tags)) + .Input(test::graph::Constant(g, values)) + .Attr("T", DT_FLOAT) + .Finalize(g, &ret)); + return g; +} + +// Macro used to parse initializer list for tensorshape +#define DIMARGS(...) {__VA_ARGS__, 0} +// Random parameters for testing +#define LONGTAGPARAM LONGTAG____________________________ +#define LARGEVALUEPARAM 2352352.2623433 + +#define BM_ScalarSummaryDev(device, dims, name, tag, value) \ + static void BM_ScalarSummary_##name##_##device(int iters) { \ + TensorShape tensorshape(DIMARGS(dims)); \ + test::Benchmark(#device, BM_ScalarSummaryOp( \ + tensorshape, #tag, value)).Run(iters); \ + } \ + BENCHMARK(BM_ScalarSummary_##name##_##device); + +BM_ScalarSummaryDev(cpu, (5, 10, 100), Base, tag, 5.2); +// Benchmark for large shapes +BM_ScalarSummaryDev(cpu, (500, 1000, 10000), Large_Shape, tag, 5.2); +// Benchmark for large tag tstring +BM_ScalarSummaryDev(cpu, (5, 10, 100), Long_Tag, LONGTAGPARAM, 5.2); +// Benchmark for large values +BM_ScalarSummaryDev(cpu, (500, 1000, 10000), Large_Value, tag, LARGEVALUEPARAM); +} // namespace tensorflow \ No newline at end of file