8 #include <benchmark/benchmark.h>
11 #include <type_traits>
98 benchmark::DoNotOptimize(
result);
100 for (
auto _ : state) {
102 benchmark::DoNotOptimize(
result);
108 #define ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, DTYPE) \
109 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100, 100, \
110 UnaryOpCode::OP, DTYPE, DEVICE) \
111 ->Unit(benchmark::kMillisecond); \
112 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100000, 100000, \
113 UnaryOpCode::OP, DTYPE, DEVICE) \
114 ->Unit(benchmark::kMillisecond); \
115 BENCHMARK_CAPTURE(FN, OP##__##DEVICE_NAME##_##DTYPE##__100000000, \
116 100000000, UnaryOpCode::OP, DTYPE, DEVICE) \
117 ->Unit(benchmark::kMillisecond);
119 #define ENUM_BM_DTYPE(FN, OP, DEVICE, DEVICE_NAME) \
120 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int8) \
121 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt8) \
122 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int16) \
123 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt16) \
124 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int32) \
125 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt32) \
126 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int64) \
127 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt64) \
128 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
129 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
131 #define ENUM_BM_DTYPE_FLOAT(FN, OP, DEVICE, DEVICE_NAME) \
132 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
133 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
135 #define ENUM_BM_DTYPE_WITH_BOOL(FN, OP, DEVICE, DEVICE_NAME) \
136 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Bool) \
137 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int8) \
138 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt8) \
139 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int16) \
140 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt16) \
141 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int32) \
142 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt32) \
143 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Int64) \
144 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, UInt64) \
145 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float32) \
146 ENUM_BM_SIZE(FN, OP, DEVICE, DEVICE_NAME, Float64)
153 #define ENUM_BM_TENSOR(FN, OP) ENUM_BM_DTYPE(FN, OP, Device("CPU:0"), CPU)
161 #define ENUM_BM_TENSOR_FLOAT(FN, OP) \
162 ENUM_BM_DTYPE_FLOAT(FN, OP, Device("CPU:0"), CPU)
170 #define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP) \
171 ENUM_BM_DTYPE_WITH_BOOL(FN, OP, Device("CPU:0"), CPU)
#define ENUM_BM_TENSOR_FLOAT(FN, OP)
#define ENUM_BM_TENSOR_WTIH_BOOL(FN, OP)
#define ENUM_BM_TENSOR(FN, OP)
Tensor Sqrt() const
Element-wise square root of a tensor, returns a new tensor.
Tensor Neg() const
Element-wise negation of a tensor, returning a new tensor.
Tensor Round() const
Element-wise round value of a tensor, returning a new tensor.
Tensor Trunc() const
Element-wise trunc value of a tensor, returning a new tensor.
Tensor LogicalNot() const
Tensor Exp() const
Element-wise exponential of a tensor, returning a new tensor.
Tensor Cos() const
Element-wise cosine of a tensor, returning a new tensor.
Tensor Abs() const
Element-wise absolute value of a tensor, returning a new tensor.
Tensor Sin() const
Element-wise sine of a tensor, returning a new tensor.
Tensor Ceil() const
Element-wise ceil value of a tensor, returning a new tensor.
Tensor Floor() const
Element-wise floor value of a tensor, returning a new tensor.
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 UnaryEW(benchmark::State &state, int size, UnaryOpCode 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.