MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / benchmark_single_algo

Method benchmark_single_algo

dnn/test/common/matrix_mul.cpp:427–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427void matrix_mul::benchmark_single_algo(
428 Handle* handle, const std::vector<TestArg>& args, DType A_dtype, DType B_dtype,
429 DType C_dtype, const char* algo, param::MatrixMul::Format format) {
430 using Param = MatrixMul::Param;
431
432 megdnn_assert(A_dtype.enumv() == B_dtype.enumv());
433 Benchmarker<MatrixMul> benchmark(handle);
434 constexpr size_t RUNS = 50;
435 if (algo) {
436 benchmark.set_before_exec_callback(AlgoChecker<MatrixMul>(algo));
437 }
438 benchmark.set_dtype(0, A_dtype).set_dtype(1, B_dtype).set_dtype(2, C_dtype);
439 benchmark.set_times(RUNS);
440
441 auto bench = [](Benchmarker<MatrixMul>& benchmark, Param param,
442 param::MatrixMul::Format format, size_t m, size_t n, size_t k,
443 size_t pack_size) -> float {
444 param.format = format;
445 benchmark.set_param(param);
446 float used_algo = 1.0;
447 if (format == param::MatrixMul::Format::DEFAULT) {
448 size_t A0 = m * pack_size, A1 = k * pack_size, B0 = k * pack_size, B1 = n;
449 TensorShape A, B;
450 if (param.transposeA) {
451 std::swap(A0, A1);
452 }
453 if (param.transposeB) {
454 std::swap(B0, B1);
455 }
456 used_algo = benchmark.execs({{A0, A1}, {B0, B1}, {}}) / RUNS;
457 } else {
458 size_t A0 = m, A1 = k, B0 = k, B1 = n;
459 if (param.transposeA) {
460 std::swap(A0, A1);
461 }
462 if (param.transposeB) {
463 std::swap(B0, B1);
464 }
465
466 used_algo =
467 benchmark.execs(
468 {{A0, A1, pack_size, pack_size}, {B0, B1, pack_size}, {}}) /
469 RUNS;
470 }
471 return used_algo;
472 };
473
474 size_t pack_size = MatrixMulForward::pack_size(format);
475 for (auto& arg : args) {
476 Param param;
477 param.transposeA = arg.mask & 0x1;
478 param.transposeB = arg.mask & 0x2;
479
480 auto used_algo =
481 bench(benchmark, param, format, arg.m, arg.n, arg.k, pack_size);
482
483 float computations = 2.f * arg.m * pack_size * arg.k * pack_size * arg.n * 1e-6;
484 printf("run: {(%zu, %zu) x (%zu, %zu)} %f ms %f Gflops\n", arg.m * pack_size,

Callers

nothing calls this directly

Calls 4

swapFunction · 0.85
set_dtypeMethod · 0.80
enumvMethod · 0.45
execsMethod · 0.45

Tested by

no test coverage detected