2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* 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 <helpers/OpBenchmark.h>
|
|
|
|
#include <helpers/benchmark/ScalarBenchmark.h>
|
|
|
|
#include <helpers/benchmark/TransformBenchmark.h>
|
|
|
|
#include <helpers/benchmark/ReductionBenchmark.h>
|
|
|
|
#include <helpers/benchmark/PairwiseBenchmark.h>
|
|
|
|
#include <helpers/benchmark/DeclarableBenchmark.h>
|
|
|
|
#include <helpers/benchmark/MatrixBenchmark.h>
|
|
|
|
#include <helpers/benchmark/BroadcastBenchmark.h>
|
|
|
|
#include <ops/declarable/DeclarableOp.h>
|
|
|
|
#include <graph/Context.h>
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <array/NDArray.h>
|
|
|
|
#include <helpers/benchmark/Parameters.h>
|
|
|
|
#include <helpers/benchmark/PredefinedParameters.h>
|
|
|
|
#include <helpers/benchmark/ParametersBatch.h>
|
|
|
|
#include <helpers/benchmark/ParametersSpace.h>
|
|
|
|
#include <helpers/benchmark/BoolParameters.h>
|
|
|
|
#include <helpers/benchmark/IntParameters.h>
|
|
|
|
#include <helpers/benchmark/IntPowerParameters.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
#include <array/ResultSet.h>
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-12-02 19:37:21 +01:00
|
|
|
class ND4J_EXPORT BenchmarkHelper {
|
2019-06-06 14:21:15 +02:00
|
|
|
private:
|
|
|
|
unsigned int _wIterations;
|
|
|
|
unsigned int _rIterations;
|
|
|
|
|
|
|
|
protected:
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string benchmarkOperation(OpBenchmark &benchmark);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
void benchmarkScalarOperation(scalar::Ops op, std::string testName, double value, NDArray &x, NDArray &z);
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void benchmarkDeclarableOp(sd::ops::DeclarableOp &op, std::string testName, Context &context);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
void benchmarkGEMM(char orderA, std::initializer_list<Nd4jLong> shapeA, char orderB, std::initializer_list<Nd4jLong> shapeB, char orderC, std::initializer_list<Nd4jLong> shapeC);
|
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string printHeader();
|
2019-06-06 14:21:15 +02:00
|
|
|
public:
|
|
|
|
BenchmarkHelper(unsigned int warmUpIterations = 10, unsigned int runIterations = 100);
|
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string runOperationSuit(std::initializer_list<OpBenchmark*> benchmarks, const char *msg = nullptr);
|
|
|
|
std::string runOperationSuit(std::vector<OpBenchmark*> &benchmarks, bool postHeaders, const char *msg = nullptr);
|
|
|
|
std::string runOperationSuit(OpBenchmark* benchmark);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string runOperationSuit(ScalarBenchmark *op, const std::function<void (ResultSet &, ResultSet &)>& func, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(TransformBenchmark *op, const std::function<void (ResultSet &, ResultSet &)>& func, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(ReductionBenchmark *op, const std::function<void (ResultSet &, ResultSet &)>& func, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(ReductionBenchmark *op, const std::function<void (ResultSet &, ResultSet &, ResultSet &)>& func, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(PairwiseBenchmark *op, const std::function<void (ResultSet &, ResultSet &, ResultSet &)>& func, const char *message = nullptr);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string runOperationSuit(TransformBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(ScalarBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(ReductionBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(ReductionBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(BroadcastBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(PairwiseBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
|
|
|
std::string runOperationSuit(MatrixBenchmark *op, const std::function<void (Parameters &, ResultSet &, ResultSet &, ResultSet &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
std::string runOperationSuit(DeclarableBenchmark *op, const std::function<Context* (Parameters &)>& func, ParametersBatch ¶metersBatch, const char *message = nullptr);
|
2019-06-06 14:21:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif //DEV_TESTS_BENCHMARKHELPER_H
|