8 #include <benchmark/benchmark.h>
10 #include <type_traits>
42 return std::plus<Tensor>();
45 return std::minus<Tensor>();
48 return std::multiplies<Tensor>();
51 return std::divides<Tensor>();
113 benchmark::DoNotOptimize(
result);
115 for (
auto _ : state) {
117 benchmark::DoNotOptimize(
result);
123 #define ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, DTYPE) \
124 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100, 100, \
125 BinaryOpCode::OP, DTYPE, DEVICE) \
126 ->Unit(benchmark::kMillisecond); \
127 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100000, 100000, \
128 BinaryOpCode::OP, DTYPE, DEVICE) \
129 ->Unit(benchmark::kMillisecond); \
130 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100000000, \
131 100000000, BinaryOpCode::OP, DTYPE, DEVICE) \
132 ->Unit(benchmark::kMillisecond);
134 #define ENUM_BM_DTYPE(FN, OP, DEVICE, DEVICE_NAME) \
135 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int8) \
136 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt8) \
137 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int16) \
138 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt16) \
139 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int32) \
140 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt32) \
141 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int64) \
142 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt64) \
143 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
144 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
146 #define ENUM_BM_DTYPE_WITH_BOOL(FN, OP, DEVICE, DEVICE_NAME) \
147 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Bool) \
148 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int8) \
149 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt8) \
150 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int16) \
151 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt16) \
152 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int32) \
153 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt32) \
154 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int64) \
155 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt64) \
156 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
157 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
164 #define ENUM_BM_TENSOR(FN, OP) ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
172 #define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP) \
173 ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
#define ENUM_BM_TENSOR(FN, OP)
Tensor LogicalXor(const Tensor &value) const
core::Tensor Rand(const core::SizeVector &shape, size_t seed, const std::pair< core::Scalar, core::Scalar > &range, core::Dtype dtype, const core::Device &device)
Returns a Tensor with random values within the range range .
void BinaryEW(benchmark::State &state, int size, BinaryOpCode op_code, const Dtype &dtype, const Device &device)
static std::function< Tensor(const Tensor &, const Tensor &)> MakeOperation(BinaryOpCode op)
Generic file read and write utility for python interface.