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

Function benchmark_winograd

dnn/test/common/conv_bias.cpp:969–1023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

967}
968
969void benchmark_winograd(
970 const char* algo_name, Handle* handle, size_t kernel, size_t pack_size,
971 size_t io_pack_size) {
972 auto&& args = get_winograd_benchmark_args(kernel, pack_size, io_pack_size);
973 using namespace conv_bias;
974 constexpr size_t RUN = 10;
975 Benchmarker<Convolution> benchmark(handle);
976 benchmark.set_display(false);
977 benchmark.set_times(RUN);
978
979 Benchmarker<ConvBias> benchmark_winograd(handle);
980 benchmark_winograd.set_display(false);
981 benchmark_winograd.set_times(RUN);
982
983 for (auto&& arg : args) {
984 TensorLayout dst_layout;
985 auto opr = handle->create_operator<ConvBias>();
986 opr->param() = arg.param;
987 opr->deduce_layout(
988 {arg.src, dtype::Float32()}, {arg.filter, dtype::Float32()},
989 {arg.bias, dtype::Float32()}, {}, dst_layout);
990 float computations = 0.0;
991 if (io_pack_size == 1) {
992 //! dst.nr_elems * IC * FH * FW * 2
993 computations = dst_layout.total_nr_elems() * arg.filter[1] * arg.filter[2] *
994 arg.filter[3] * 2.0 / (1024 * 1024 * 1024) * 1e3;
995 } else {
996 //! dst.nr_elems * IC/4 * FH * FW * 4 * 2
997 computations = dst_layout.total_nr_elems() * arg.filter[1] * arg.filter[2] *
998 arg.filter[3] * arg.filter[4] * 2.0 / (1024 * 1024 * 1024) *
999 1e3;
1000 }
1001
1002 param::Convolution conv_param;
1003 conv_param.pad_h = arg.param.pad_h;
1004 conv_param.pad_w = arg.param.pad_w;
1005 conv_param.stride_h = arg.param.stride_h;
1006 conv_param.stride_w = arg.param.stride_w;
1007 auto used =
1008 benchmark.set_param(conv_param).exec({arg.src, arg.filter, {}}) / RUN;
1009
1010 benchmark_winograd.set_param(arg.param);
1011 auto used_winograd = algo_benchmark<ConvBias>(
1012 benchmark_winograd,
1013 {arg.src, arg.filter, {}, {}, {}}, algo_name) /
1014 RUN;
1015
1016 printf("%s %s: normal: %f ms %f Gflops winograd: %f ms %f GFlops "
1017 "speedup: "
1018 "%f\n",
1019 arg.src.to_string().c_str(), arg.filter.to_string().c_str(), used,
1020 computations / used, used_winograd, computations / used_winograd,
1021 used / used_winograd);
1022 }
1023}
1024
1025// usage of weight pre-processing for winograd benchmark
1026void benchmark_winograd_weight_preprocess(

Callers

nothing calls this directly

Calls 6

paramMethod · 0.45
deduce_layoutMethod · 0.45
total_nr_elemsMethod · 0.45
execMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected