| 2248 | } |
| 2249 | |
| 2250 | void benchmark_conv1x1( |
| 2251 | const char* matmul_algo_name, Handle* handle, DType stype, DType matmul_dtype, |
| 2252 | DType bias_type, DType conv_dtype, bool is_mk4 = false) { |
| 2253 | using namespace conv_bias; |
| 2254 | int pack_size = is_mk4 ? 4 : 1; |
| 2255 | std::vector<TestArg> conv_bias_1x1_args = |
| 2256 | get_conv_bias_1x1_benchmark_args(pack_size); |
| 2257 | |
| 2258 | constexpr size_t RUNS = 50; |
| 2259 | |
| 2260 | param::MatrixMul param; |
| 2261 | param.transposeA = false; |
| 2262 | param.transposeB = false; |
| 2263 | if (is_mk4) { |
| 2264 | param.format = MatrixMul::Param::Format::MK4; |
| 2265 | } |
| 2266 | Benchmarker<MatrixMul> benchmark_matmul(handle); |
| 2267 | benchmark_matmul.set_before_exec_callback(AlgoChecker<MatrixMul>(matmul_algo_name)); |
| 2268 | benchmark_matmul.set_times(RUNS) |
| 2269 | .set_dtype(0, stype) |
| 2270 | .set_dtype(1, stype) |
| 2271 | .set_dtype(2, matmul_dtype) |
| 2272 | .set_param(param) |
| 2273 | .set_display(false); |
| 2274 | |
| 2275 | std::string conv1x1_algo_name = ssprintf("CONV1x1:%s:24", matmul_algo_name); |
| 2276 | Benchmarker<ConvBias> benchmark_conv1x1(handle); |
| 2277 | benchmark_conv1x1.set_before_exec_callback( |
| 2278 | conv_bias::ConvBiasAlgoChecker<ConvBias>(conv1x1_algo_name.c_str())); |
| 2279 | benchmark_conv1x1.set_times(RUNS) |
| 2280 | .set_dtype(0, stype) |
| 2281 | .set_dtype(1, stype) |
| 2282 | .set_dtype(2, bias_type) |
| 2283 | .set_dtype(4, conv_dtype) |
| 2284 | .set_display(false); |
| 2285 | |
| 2286 | for (auto&& arg : conv_bias_1x1_args) { |
| 2287 | size_t IC = arg.src[1]; |
| 2288 | size_t OH = arg.src[2]; |
| 2289 | size_t OW = arg.src[3]; |
| 2290 | size_t OC = arg.filter[0]; |
| 2291 | size_t M = OC * pack_size; |
| 2292 | size_t K = IC * pack_size; |
| 2293 | size_t N = OH * OW; |
| 2294 | |
| 2295 | float computations = M * N * K * 2.f / (1024 * 1024 * 1024) * 1e3; |
| 2296 | |
| 2297 | TensorShape A, B; |
| 2298 | A = TensorShape{M, K}; |
| 2299 | B = TensorShape{K, N}; |
| 2300 | if (is_mk4) { |
| 2301 | A = TensorShape{M / 4, K / 4, 4, 4}; |
| 2302 | B = TensorShape{K / 4, N, 4}; |
| 2303 | } |
| 2304 | |
| 2305 | auto conv1x1_used = benchmark_conv1x1.set_param(arg.param).exec( |
| 2306 | {arg.src, arg.filter, arg.bias, {}, {}}) / |
| 2307 | RUNS; |
no test coverage detected