/******************************************************************************* * Copyright (c) 2015-2018 Skymind, Inc. * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at * https://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. * * SPDX-License-Identifier: Apache-2.0 ******************************************************************************/ /** * @author raver119@gmail.com */ #ifndef LIBND4J_BENCHMARKHELPER_H #define LIBND4J_BENCHMARKHELPER_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace nd4j { class BenchmarkHelper { private: unsigned int _wIterations; unsigned int _rIterations; protected: std::string benchmarkOperation(OpBenchmark &benchmark); void benchmarkScalarOperation(scalar::Ops op, std::string testName, double value, NDArray &x, NDArray &z); void benchmarkDeclarableOp(nd4j::ops::DeclarableOp &op, std::string testName, Context &context); void benchmarkGEMM(char orderA, std::initializer_list shapeA, char orderB, std::initializer_list shapeB, char orderC, std::initializer_list shapeC); std::string printHeader(); public: BenchmarkHelper(unsigned int warmUpIterations = 10, unsigned int runIterations = 100); std::string runOperationSuit(std::initializer_list benchmarks, const char *msg = nullptr); std::string runOperationSuit(std::vector &benchmarks, bool postHeaders, const char *msg = nullptr); std::string runOperationSuit(OpBenchmark* benchmark); std::string runOperationSuit(ScalarBenchmark *op, const std::function& func, const char *message = nullptr); std::string runOperationSuit(TransformBenchmark *op, const std::function& func, const char *message = nullptr); std::string runOperationSuit(ReductionBenchmark *op, const std::function& func, const char *message = nullptr); std::string runOperationSuit(ReductionBenchmark *op, const std::function& func, const char *message = nullptr); std::string runOperationSuit(PairwiseBenchmark *op, const std::function& func, const char *message = nullptr); std::string runOperationSuit(TransformBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(ScalarBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(ReductionBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(ReductionBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(BroadcastBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(PairwiseBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(MatrixBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); std::string runOperationSuit(DeclarableBenchmark *op, const std::function& func, ParametersBatch ¶metersBatch, const char *message = nullptr); }; } #endif //DEV_TESTS_BENCHMARKHELPER_H