You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conv_bias_multi_thread_benchmark.cpp 85 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  1. /**
  2. * \file dnn/test/arm_common/conv_bias_multi_thread_benchmark.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #include "test/arm_common/fixture.h"
  13. #include "test/common/benchmarker.h"
  14. #include "test/common/conv_bias.h"
  15. using namespace megdnn;
  16. using namespace test;
  17. using namespace conv_bias;
  18. #if MEGDNN_WITH_BENCHMARK
  19. namespace {
  20. void benchmark_impl(const param::ConvBias param,
  21. std::vector<std::pair<SmallVector<TensorShape>, float>>&
  22. shapes_and_computation,
  23. const std::string algo_name, size_t RUNS,
  24. TaskExecutorConfig&& multi_thread_config,
  25. TaskExecutorConfig&& single_thread_config,
  26. std::vector<DType>& data_type) {
  27. std::vector<float> multi_thread_times, single_thread_times;
  28. {
  29. auto multi_thread_hanle =
  30. create_cpu_handle(0, true, &multi_thread_config);
  31. auto benchmarker = Benchmarker<ConvBias>(multi_thread_hanle.get());
  32. benchmarker.set_times(RUNS)
  33. .set_display(false)
  34. .set_param(param)
  35. .set_dtype(0, data_type[0])
  36. .set_dtype(1, data_type[1])
  37. .set_dtype(2, data_type[2])
  38. .set_dtype(4, data_type[3])
  39. .set_before_exec_callback(
  40. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  41. algo_name.c_str()));
  42. for (auto shape : shapes_and_computation) {
  43. multi_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
  44. }
  45. }
  46. {
  47. auto single_thread_handle =
  48. create_cpu_handle(0, true, &single_thread_config);
  49. auto benchmarker = Benchmarker<ConvBias>(single_thread_handle.get());
  50. benchmarker.set_times(RUNS)
  51. .set_display(false)
  52. .set_param(param)
  53. .set_dtype(0, data_type[0])
  54. .set_dtype(1, data_type[1])
  55. .set_dtype(2, data_type[2])
  56. .set_dtype(4, data_type[3])
  57. .set_before_exec_callback(
  58. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  59. algo_name.c_str()));
  60. for (auto shape : shapes_and_computation) {
  61. single_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
  62. }
  63. }
  64. printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread);
  65. printf("core_ids:");
  66. for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) {
  67. printf("%zu ", multi_thread_config.affinity_core_set[i]);
  68. }
  69. printf(", Single thread core_id %zu\n",
  70. single_thread_config.affinity_core_set[0]);
  71. for (size_t i = 0; i < shapes_and_computation.size(); i++) {
  72. auto shapes = shapes_and_computation[i];
  73. printf("Bench case: ");
  74. for (auto&& shape : shapes.first) {
  75. printf("%s ", shape.to_string().c_str());
  76. }
  77. float computations = shapes.second;
  78. printf("%zu threads gflops: %f,\n single thread gflops: "
  79. "%f. spead up = %f, speedup/cores=%f\n",
  80. multi_thread_config.nr_thread,
  81. computations / multi_thread_times[i],
  82. computations / single_thread_times[i],
  83. single_thread_times[i] / multi_thread_times[i],
  84. single_thread_times[i] / multi_thread_times[i] /
  85. multi_thread_config.nr_thread);
  86. }
  87. }
  88. } // namespace
  89. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF32) {
  90. constexpr size_t RUNS = 50;
  91. param::ConvBias param;
  92. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  93. param.pad_h = 1;
  94. param.pad_w = 1;
  95. param.stride_h = 1;
  96. param.stride_w = 1;
  97. param.sparse = param::ConvBias::Sparse::GROUP;
  98. std::vector<std::pair<SmallVector<TensorShape>, float>>
  99. shapes_and_computation;
  100. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  101. size_t FS, size_t group) {
  102. SmallVector<TensorShape> shapes{{N, IC, H, W},
  103. {group, OC / group, IC / group, FS, FS},
  104. {1, OC, 1, 1},
  105. {},
  106. {N, OC, H, W}};
  107. TensorShape dst{N, OC, H, W};
  108. float computations =
  109. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  110. dst.total_nr_elems()) *
  111. 1e-6;
  112. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  113. };
  114. bench_case(1, 32, 32, 200, 200, 3, 4);
  115. bench_case(1, 32, 32, 200, 200, 3, 32);
  116. bench_case(1, 32, 32, 128, 128, 3, 4);
  117. bench_case(1, 32, 32, 128, 128, 3, 32);
  118. bench_case(1, 32, 32, 100, 100, 3, 4);
  119. bench_case(1, 32, 32, 100, 100, 3, 32);
  120. bench_case(1, 32, 32, 80, 80, 3, 4);
  121. bench_case(1, 32, 32, 80, 80, 3, 32);
  122. std::string algo_name = "F32DIRECT";
  123. printf("Benchmark F32DIRECT_LARGE_GROUP algo\n");
  124. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  125. dtype::Float32(), dtype::Float32()};
  126. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  127. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  128. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  129. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  130. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  131. {1, {4}}, data_type);
  132. shapes_and_computation.clear();
  133. algo_name = "F32DIRECT";
  134. printf("Benchmark F32DIRECT_SMALL_GROUP algo\n");
  135. bench_case(1, 32, 32, 200, 200, 3, 1);
  136. bench_case(1, 32, 32, 128, 128, 3, 1);
  137. bench_case(1, 32, 32, 100, 100, 3, 1);
  138. bench_case(1, 32, 32, 80, 80, 3, 1);
  139. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  140. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  141. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  142. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  143. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  144. {1, {4}}, data_type);
  145. }
  146. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF32_STR1) {
  147. constexpr size_t RUNS = 50;
  148. param::ConvBias param;
  149. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  150. param.pad_h = 1;
  151. param.pad_w = 1;
  152. param.stride_h = 1;
  153. param.stride_w = 1;
  154. param.sparse = param::ConvBias::Sparse::GROUP;
  155. std::vector<std::pair<SmallVector<TensorShape>, float>>
  156. shapes_and_computation;
  157. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  158. size_t FS, size_t group) {
  159. SmallVector<TensorShape> shapes{{N, IC, H, W},
  160. {group, OC / group, IC / group, FS, FS},
  161. {1, OC, 1, 1},
  162. {},
  163. {N, OC, H, W}};
  164. TensorShape dst{N, OC, H, W};
  165. float computations =
  166. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  167. dst.total_nr_elems()) *
  168. 1e-6;
  169. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  170. };
  171. bench_case(1, 32, 32, 200, 200, 3, 4);
  172. bench_case(1, 32, 32, 200, 200, 3, 32);
  173. bench_case(1, 32, 32, 128, 128, 3, 4);
  174. bench_case(1, 32, 32, 128, 128, 3, 32);
  175. bench_case(1, 32, 32, 100, 100, 3, 4);
  176. bench_case(1, 32, 32, 100, 100, 3, 32);
  177. bench_case(1, 32, 32, 80, 80, 3, 4);
  178. bench_case(1, 32, 32, 80, 80, 3, 32);
  179. std::string algo_name = "F32STRD1";
  180. printf("Benchmark F32STRD1_LARGE_GROUP algo\n");
  181. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  182. dtype::Float32(), dtype::Float32()};
  183. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  184. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  185. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  186. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  187. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  188. {1, {4}}, data_type);
  189. shapes_and_computation.clear();
  190. algo_name = "F32STRD1";
  191. printf("Benchmark F32STRD1_SMALL_GROUP algo\n");
  192. bench_case(1, 32, 32, 200, 200, 3, 1);
  193. bench_case(1, 32, 32, 128, 128, 3, 1);
  194. bench_case(1, 32, 32, 100, 100, 3, 1);
  195. bench_case(1, 32, 32, 80, 80, 3, 1);
  196. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  197. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  198. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  199. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  200. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  201. {1, {4}}, data_type);
  202. }
  203. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF32_STR2) {
  204. constexpr size_t RUNS = 50;
  205. param::ConvBias param;
  206. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  207. param.pad_h = 1;
  208. param.pad_w = 1;
  209. param.stride_h = 2;
  210. param.stride_w = 2;
  211. param.sparse = param::ConvBias::Sparse::GROUP;
  212. std::vector<std::pair<SmallVector<TensorShape>, float>>
  213. shapes_and_computation;
  214. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  215. size_t FS, size_t group, size_t P, size_t S) {
  216. SmallVector<TensorShape> shapes{
  217. {N, IC, H, W},
  218. {group, OC / group, IC / group, FS, FS},
  219. {1, OC, 1, 1},
  220. {},
  221. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  222. TensorShape dst{N, OC, H, W};
  223. float computations =
  224. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  225. dst.total_nr_elems()) *
  226. 1e-6;
  227. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  228. };
  229. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  230. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  231. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  232. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  233. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  234. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  235. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  236. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  237. std::string algo_name = "F32STRD2";
  238. printf("Benchmark F32STRD2_LARGE_GROUP algo\n");
  239. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  240. dtype::Float32(), dtype::Float32()};
  241. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  242. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  243. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  244. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  245. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  246. {1, {4}}, data_type);
  247. shapes_and_computation.clear();
  248. algo_name = "F32STRD2";
  249. printf("Benchmark F32STRD2_SMALL_GROUP algo\n");
  250. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  251. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  252. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  253. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  254. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  255. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  256. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  257. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  258. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  259. {1, {4}}, data_type);
  260. }
  261. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  262. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF16) {
  263. constexpr size_t RUNS = 50;
  264. param::ConvBias param;
  265. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  266. param.pad_h = 1;
  267. param.pad_w = 1;
  268. param.stride_h = 1;
  269. param.stride_w = 1;
  270. param.sparse = param::ConvBias::Sparse::GROUP;
  271. std::vector<std::pair<SmallVector<TensorShape>, float>>
  272. shapes_and_computation;
  273. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  274. size_t FS, size_t group) {
  275. SmallVector<TensorShape> shapes{{N, IC, H, W},
  276. {group, OC / group, IC / group, FS, FS},
  277. {1, OC, 1, 1},
  278. {},
  279. {N, OC, H, W}};
  280. TensorShape dst{N, OC, H, W};
  281. float computations =
  282. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  283. dst.total_nr_elems()) *
  284. 1e-6;
  285. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  286. };
  287. bench_case(1, 32, 32, 200, 200, 3, 4);
  288. bench_case(1, 32, 32, 200, 200, 3, 32);
  289. bench_case(1, 32, 32, 128, 128, 3, 4);
  290. bench_case(1, 32, 32, 128, 128, 3, 32);
  291. bench_case(1, 32, 32, 100, 100, 3, 4);
  292. bench_case(1, 32, 32, 100, 100, 3, 32);
  293. bench_case(1, 32, 32, 80, 80, 3, 4);
  294. bench_case(1, 32, 32, 80, 80, 3, 32);
  295. std::string algo_name = "F16DIRECT";
  296. printf("Benchmark F16DIRECT_LARGE_GROUP algo\n");
  297. std::vector<DType> data_type = {dtype::Float16(), dtype::Float16(),
  298. dtype::Float16(), dtype::Float16()};
  299. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  300. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  301. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  302. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  303. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  304. {1, {4}}, data_type);
  305. shapes_and_computation.clear();
  306. algo_name = "F16DIRECT";
  307. printf("Benchmark F16DIRECT_SMALL_GROUP algo\n");
  308. bench_case(1, 32, 32, 200, 200, 3, 1);
  309. bench_case(1, 32, 32, 128, 128, 3, 1);
  310. bench_case(1, 32, 32, 100, 100, 3, 1);
  311. bench_case(1, 32, 32, 80, 80, 3, 1);
  312. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  313. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  314. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  315. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  316. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  317. {1, {4}}, data_type);
  318. }
  319. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF16_STR1) {
  320. constexpr size_t RUNS = 50;
  321. param::ConvBias param;
  322. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  323. param.pad_h = 1;
  324. param.pad_w = 1;
  325. param.stride_h = 1;
  326. param.stride_w = 1;
  327. param.sparse = param::ConvBias::Sparse::GROUP;
  328. std::vector<std::pair<SmallVector<TensorShape>, float>>
  329. shapes_and_computation;
  330. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  331. size_t FS, size_t group) {
  332. SmallVector<TensorShape> shapes{{N, IC, H, W},
  333. {group, OC / group, IC / group, FS, FS},
  334. {1, OC, 1, 1},
  335. {},
  336. {N, OC, H, W}};
  337. TensorShape dst{N, OC, H, W};
  338. float computations =
  339. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  340. dst.total_nr_elems()) *
  341. 1e-6;
  342. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  343. };
  344. bench_case(1, 32, 32, 200, 200, 3, 4);
  345. bench_case(1, 32, 32, 200, 200, 3, 32);
  346. bench_case(1, 32, 32, 128, 128, 3, 4);
  347. bench_case(1, 32, 32, 128, 128, 3, 32);
  348. bench_case(1, 32, 32, 100, 100, 3, 4);
  349. bench_case(1, 32, 32, 100, 100, 3, 32);
  350. bench_case(1, 32, 32, 80, 80, 3, 4);
  351. bench_case(1, 32, 32, 80, 80, 3, 32);
  352. std::string algo_name = "F16STRD1";
  353. printf("Benchmark F16STRD1_LARGE_GROUP algo\n");
  354. std::vector<DType> data_type = {dtype::Float16(), dtype::Float16(),
  355. dtype::Float16(), dtype::Float16()};
  356. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  357. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  358. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  359. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  360. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  361. {1, {4}}, data_type);
  362. shapes_and_computation.clear();
  363. algo_name = "F16STRD1";
  364. printf("Benchmark F16STRD1_SMALL_GROUP algo\n");
  365. bench_case(1, 32, 32, 200, 200, 3, 1);
  366. bench_case(1, 32, 32, 128, 128, 3, 1);
  367. bench_case(1, 32, 32, 100, 100, 3, 1);
  368. bench_case(1, 32, 32, 80, 80, 3, 1);
  369. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  370. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  371. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  372. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  373. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  374. {1, {4}}, data_type);
  375. }
  376. #endif
  377. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  378. BENCHMARK_CONVBIAS_DIRECT_INT8x8x16) {
  379. constexpr size_t RUNS = 50;
  380. param::ConvBias param;
  381. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  382. param.pad_h = 1;
  383. param.pad_w = 1;
  384. param.stride_h = 1;
  385. param.stride_w = 1;
  386. param.sparse = param::ConvBias::Sparse::GROUP;
  387. std::vector<std::pair<SmallVector<TensorShape>, float>>
  388. shapes_and_computation;
  389. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  390. size_t FS, size_t group) {
  391. SmallVector<TensorShape> shapes{{N, IC, H, W},
  392. {group, OC / group, IC / group, FS, FS},
  393. {},
  394. {},
  395. {N, OC, H, W}};
  396. TensorShape dst{N, OC, H, W};
  397. float computations =
  398. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  399. dst.total_nr_elems()) *
  400. 1e-6;
  401. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  402. };
  403. bench_case(1, 32, 32, 200, 200, 3, 4);
  404. bench_case(1, 32, 32, 200, 200, 3, 32);
  405. bench_case(1, 32, 32, 128, 128, 3, 4);
  406. bench_case(1, 32, 32, 128, 128, 3, 32);
  407. bench_case(1, 32, 32, 100, 100, 3, 4);
  408. bench_case(1, 32, 32, 100, 100, 3, 32);
  409. bench_case(1, 32, 32, 80, 80, 3, 4);
  410. bench_case(1, 32, 32, 80, 80, 3, 32);
  411. std::string algo_name = "I8816DIRECT";
  412. printf("Benchmark I8816DIRECT_LARGE_GROUP algo\n");
  413. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  414. dtype::Int16(), dtype::Int16()};
  415. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  416. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  417. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  418. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  419. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  420. {1, {4}}, data_type);
  421. shapes_and_computation.clear();
  422. algo_name = "I8816DIRECT";
  423. printf("Benchmark I8816DIRECT_SMALL_GROUP algo\n");
  424. bench_case(1, 32, 32, 200, 200, 3, 1);
  425. bench_case(1, 32, 32, 128, 128, 3, 1);
  426. bench_case(1, 32, 32, 100, 100, 3, 1);
  427. bench_case(1, 32, 32, 80, 80, 3, 1);
  428. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  429. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  430. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  431. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  432. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  433. {1, {4}}, data_type);
  434. }
  435. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  436. BENCHMARK_CONVBIAS_DIRECT_INT8x8x16_STR2) {
  437. constexpr size_t RUNS = 50;
  438. param::ConvBias param;
  439. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  440. param.pad_h = 1;
  441. param.pad_w = 1;
  442. param.stride_h = 2;
  443. param.stride_w = 2;
  444. param.sparse = param::ConvBias::Sparse::GROUP;
  445. std::vector<std::pair<SmallVector<TensorShape>, float>>
  446. shapes_and_computation;
  447. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  448. size_t FS, size_t group, size_t P, size_t S) {
  449. SmallVector<TensorShape> shapes{
  450. {N, IC, H, W},
  451. {group, OC / group, IC / group, FS, FS},
  452. {},
  453. {},
  454. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  455. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  456. (W + 2 * P - FS) / S + 1};
  457. float computations =
  458. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  459. dst.total_nr_elems()) *
  460. 1e-6;
  461. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  462. };
  463. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  464. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  465. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  466. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  467. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  468. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  469. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  470. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  471. std::string algo_name = "I8816STRD2";
  472. printf("Benchmark I8816STRD2_LARGE_GROUP algo\n");
  473. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  474. dtype::Int16(), dtype::Int16()};
  475. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  476. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  477. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  478. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  479. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  480. {1, {4}}, data_type);
  481. shapes_and_computation.clear();
  482. algo_name = "I8816STRD2";
  483. printf("Benchmark I8816STRD2_SMALL_GROUP algo\n");
  484. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  485. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  486. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  487. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  488. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  489. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  490. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  491. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  492. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  493. {1, {4}}, data_type);
  494. }
  495. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  496. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1) {
  497. constexpr size_t RUNS = 50;
  498. param::ConvBias param;
  499. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  500. param.pad_h = 1;
  501. param.pad_w = 1;
  502. param.stride_h = 1;
  503. param.stride_w = 1;
  504. param.sparse = param::ConvBias::Sparse::GROUP;
  505. std::vector<std::pair<SmallVector<TensorShape>, float>>
  506. shapes_and_computation;
  507. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  508. size_t FS, size_t group, size_t P, size_t S) {
  509. SmallVector<TensorShape> shapes{
  510. {N, IC, H, W},
  511. {group, OC / group, IC / group, FS, FS},
  512. {1, OC, 1, 1},
  513. {},
  514. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  515. TensorShape dst{N, OC, H, W};
  516. float computations =
  517. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  518. dst.total_nr_elems()) *
  519. 1e-6;
  520. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  521. };
  522. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  523. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  524. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  525. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  526. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  527. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  528. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  529. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  530. std::string algo_name = "S8STRD1";
  531. printf("Benchmark S8STRD1_LARGE_GROUP algo\n");
  532. std::vector<DType> data_type = {
  533. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  534. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  535. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  536. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  537. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  538. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  539. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  540. {1, {4}}, data_type);
  541. shapes_and_computation.clear();
  542. algo_name = "S8STRD1";
  543. printf("Benchmark S8STRD1_SMALL_GROUP algo\n");
  544. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  545. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  546. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  547. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  548. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  549. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  550. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  551. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  552. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  553. {1, {4}}, data_type);
  554. }
  555. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44) {
  556. constexpr size_t RUNS = 40;
  557. std::vector<DType> data_type = {
  558. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  559. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  560. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  561. size_t FS, size_t group, size_t P, size_t S,
  562. bool is_nchw = false) {
  563. param::ConvBias param;
  564. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  565. param.pad_h = P;
  566. param.pad_w = P;
  567. param.stride_h = S;
  568. param.stride_w = S;
  569. param.sparse = param::ConvBias::Sparse::DENSE;
  570. param.format = param::ConvBias::Format::NCHW44;
  571. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  572. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  573. TensorShape src = {N, IC / 4, H, W, 4};
  574. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  575. if (group > 1) {
  576. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  577. param.sparse = param::ConvBias::Sparse::GROUP;
  578. }
  579. if (is_nchw) {
  580. src = {N, IC, H, W};
  581. filter = {OC / 4, FS, FS, IC, 4};
  582. }
  583. TensorShape bias = {1, OC / 4, 1, 1, 4};
  584. TensorShape dst = {N, OC / 4, OH, OW, 4};
  585. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  586. float computations =
  587. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  588. dst.total_nr_elems()) *
  589. 1e-6;
  590. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  591. std::make_pair(shapes, computations)};
  592. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  593. {1, {7}}, data_type);
  594. };
  595. bench_case(1, 2, 64, 160, 160, 1, 1, 0, 1, true);
  596. bench_case(1, 3, 64, 224, 224, 7, 1, 3, 2, true);
  597. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  598. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  599. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  600. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  601. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  602. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  603. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  604. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  605. bench_case(1, 4, 64, 224, 224, 7, 1, 1, 2);
  606. bench_case(1, 256, 128, 56, 56, 3, 1, 1, 2);
  607. bench_case(1, 512, 256, 28, 28, 3, 1, 1, 2);
  608. bench_case(1, 4, 32, 224, 224, 3, 1, 1, 2);
  609. bench_case(1, 256, 128, 56, 56, 3, 4, 1, 2);
  610. bench_case(1, 512, 256, 28, 28, 3, 4, 1, 2);
  611. }
  612. #if MGB_ENABLE_DOT
  613. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44_DOT) {
  614. constexpr size_t RUNS = 40;
  615. std::vector<DType> data_type = {
  616. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  617. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  618. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  619. size_t FS, size_t group, size_t P, size_t S,
  620. bool is_nchw = false) {
  621. param::ConvBias param;
  622. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  623. param.pad_h = P;
  624. param.pad_w = P;
  625. param.stride_h = S;
  626. param.stride_w = S;
  627. param.sparse = param::ConvBias::Sparse::DENSE;
  628. param.format = param::ConvBias::Format::NCHW44_DOT;
  629. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  630. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  631. TensorShape src = {N, IC / 4, H, W, 4};
  632. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  633. if (group > 1) {
  634. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  635. param.sparse = param::ConvBias::Sparse::GROUP;
  636. }
  637. if (is_nchw) {
  638. src = {N, IC, H, W};
  639. filter = {OC / 4, FS, FS, IC, 4};
  640. }
  641. TensorShape bias = {1, OC / 4, 1, 1, 4};
  642. TensorShape dst = {N, OC / 4, OH, OW, 4};
  643. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  644. float computations =
  645. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  646. dst.total_nr_elems()) *
  647. 1e-6;
  648. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  649. std::make_pair(shapes, computations)};
  650. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  651. {1, {7}}, data_type);
  652. };
  653. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  654. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  655. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  656. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  657. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  658. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  659. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  660. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  661. }
  662. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44_DOT_S2) {
  663. constexpr size_t RUNS = 40;
  664. std::vector<DType> data_type = {
  665. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  666. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  667. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  668. size_t FS, size_t group, size_t P, size_t S,
  669. bool is_nchw = false) {
  670. param::ConvBias param;
  671. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  672. param.pad_h = P;
  673. param.pad_w = P;
  674. param.stride_h = S;
  675. param.stride_w = S;
  676. param.sparse = param::ConvBias::Sparse::DENSE;
  677. param.format = param::ConvBias::Format::NCHW44_DOT;
  678. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  679. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  680. TensorShape src = {N, IC / 4, H, W, 4};
  681. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  682. if (group > 1) {
  683. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  684. param.sparse = param::ConvBias::Sparse::GROUP;
  685. }
  686. if (is_nchw) {
  687. src = {N, IC, H, W};
  688. filter = {OC / 4, FS, FS, IC, 4};
  689. }
  690. TensorShape bias = {1, OC / 4, 1, 1, 4};
  691. TensorShape dst = {N, OC / 4, OH, OW, 4};
  692. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  693. float computations =
  694. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  695. dst.total_nr_elems()) *
  696. 1e-6;
  697. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  698. std::make_pair(shapes, computations)};
  699. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  700. {1, {7}}, data_type);
  701. };
  702. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  703. bench_case(1, 64, 64, 128, 128, 3, 1, 1, 2);
  704. bench_case(1, 64, 64, 256, 256, 3, 1, 1, 2);
  705. bench_case(1, 64, 64, 156, 156, 3, 1, 1, 2);
  706. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  707. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  708. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  709. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  710. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  711. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  712. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  713. }
  714. #endif
  715. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_FLOAT_NCHW44) {
  716. constexpr size_t RUNS = 40;
  717. std::vector<DType> data_type = {
  718. dtype::Float32(), dtype::Float32(),
  719. dtype::Float32(), dtype::Float32()};
  720. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  721. size_t FS, size_t group, size_t P, size_t S,
  722. bool is_nchw = false) {
  723. param::ConvBias param;
  724. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  725. param.pad_h = P;
  726. param.pad_w = P;
  727. param.stride_h = S;
  728. param.stride_w = S;
  729. param.sparse = param::ConvBias::Sparse::DENSE;
  730. param.format = param::ConvBias::Format::NCHW44;
  731. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  732. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  733. TensorShape src = {N, IC / 4, H, W, 4};
  734. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  735. if (group > 1) {
  736. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  737. param.sparse = param::ConvBias::Sparse::GROUP;
  738. }
  739. if (is_nchw) {
  740. src = {N, IC, H, W};
  741. filter = {OC / 4, FS, FS, IC, 4};
  742. }
  743. TensorShape bias = {1, OC / 4, 1, 1, 4};
  744. TensorShape dst = {N, OC / 4, OH, OW, 4};
  745. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  746. float computations =
  747. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  748. dst.total_nr_elems()) *
  749. 1e-6;
  750. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  751. std::make_pair(shapes, computations)};
  752. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  753. {1, {7}}, data_type);
  754. };
  755. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  756. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  757. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  758. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  759. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  760. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  761. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  762. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  763. bench_case(1, 64, 64, 56*2, 56*2, 3, 4, 1, 2);
  764. bench_case(1, 128, 128, 28*2, 28*2, 3, 4, 1, 2);
  765. bench_case(1, 256, 256, 14*2, 14*2, 3, 4, 1, 2);
  766. bench_case(1, 512, 512, 7*2, 7*2, 3, 4, 1, 2);
  767. }
  768. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  769. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2) {
  770. constexpr size_t RUNS = 50;
  771. param::ConvBias param;
  772. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  773. param.pad_h = 1;
  774. param.pad_w = 1;
  775. param.stride_h = 2;
  776. param.stride_w = 2;
  777. param.sparse = param::ConvBias::Sparse::GROUP;
  778. std::vector<std::pair<SmallVector<TensorShape>, float>>
  779. shapes_and_computation;
  780. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  781. size_t FS, size_t group, size_t P, size_t S) {
  782. SmallVector<TensorShape> shapes{
  783. {N, IC, H, W},
  784. {group, OC / group, IC / group, FS, FS},
  785. {1, OC, 1, 1},
  786. {},
  787. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  788. TensorShape dst{N, OC, H, W};
  789. float computations =
  790. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  791. dst.total_nr_elems()) *
  792. 1e-6;
  793. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  794. };
  795. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  796. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  797. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  798. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  799. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  800. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  801. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  802. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  803. std::string algo_name = "S8STRD2";
  804. printf("Benchmark S8STRD2_LARGE_GROUP algo\n");
  805. std::vector<DType> data_type = {
  806. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  807. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  808. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  809. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  810. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  811. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  812. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  813. {1, {4}}, data_type);
  814. shapes_and_computation.clear();
  815. algo_name = "S8STRD2";
  816. printf("Benchmark S8STRD2_SMALL_GROUP algo\n");
  817. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  818. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  819. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  820. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  821. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  822. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  823. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  824. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  825. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  826. {1, {4}}, data_type);
  827. }
  828. #if MGB_ENABLE_DOT
  829. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  830. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1_WITHDOTPROD) {
  831. constexpr size_t RUNS = 50;
  832. param::ConvBias param;
  833. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  834. param.pad_h = 1;
  835. param.pad_w = 1;
  836. param.stride_h = 1;
  837. param.stride_w = 1;
  838. param.sparse = param::ConvBias::Sparse::GROUP;
  839. std::vector<std::pair<SmallVector<TensorShape>, float>>
  840. shapes_and_computation;
  841. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  842. size_t FS, size_t group, size_t P, size_t S) {
  843. SmallVector<TensorShape> shapes{
  844. {N, IC, H, W},
  845. {group, OC / group, IC / group, FS, FS},
  846. {1, OC, 1, 1},
  847. {},
  848. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  849. TensorShape dst{N, OC, H, W};
  850. float computations =
  851. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  852. dst.total_nr_elems()) *
  853. 1e-6;
  854. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  855. };
  856. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  857. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  858. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  859. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  860. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  861. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  862. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  863. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  864. std::string algo_name = "ARMDOTS8STRD1";
  865. printf("Benchmark ARMDOTS8STRD1_LARGE_GROUP algo\n");
  866. std::vector<DType> data_type = {
  867. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  868. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  869. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  870. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  871. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  872. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  873. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  874. {1, {4}}, data_type);
  875. shapes_and_computation.clear();
  876. algo_name = "ARMDOTS8STRD1";
  877. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  878. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  879. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  880. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  881. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  882. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  883. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  884. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  885. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  886. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  887. {1, {4}}, data_type);
  888. }
  889. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  890. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2_WITHDOTPROD) {
  891. constexpr size_t RUNS = 50;
  892. param::ConvBias param;
  893. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  894. param.pad_h = 1;
  895. param.pad_w = 1;
  896. param.stride_h = 2;
  897. param.stride_w = 2;
  898. param.sparse = param::ConvBias::Sparse::GROUP;
  899. std::vector<std::pair<SmallVector<TensorShape>, float>>
  900. shapes_and_computation;
  901. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  902. size_t FS, size_t group, size_t P, size_t S) {
  903. SmallVector<TensorShape> shapes{
  904. {N, IC, H, W},
  905. {group, OC / group, IC / group, FS, FS},
  906. {1, OC, 1, 1},
  907. {},
  908. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  909. TensorShape dst{N, OC, H, W};
  910. float computations =
  911. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  912. dst.total_nr_elems()) *
  913. 1e-6;
  914. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  915. };
  916. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  917. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  918. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  919. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  920. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  921. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  922. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  923. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  924. std::string algo_name = "ARMDOTS8STRD2";
  925. printf("Benchmark ARMDOTS8STRD2_LARGE_GROUP algo\n");
  926. std::vector<DType> data_type = {
  927. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  928. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  929. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  930. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  931. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  932. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  933. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  934. {1, {4}}, data_type);
  935. shapes_and_computation.clear();
  936. algo_name = "ARMDOTS8STRD2";
  937. printf("Benchmark ARMDOTS8STRD2_SMALL_GROUP algo\n");
  938. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  939. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  940. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  941. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  942. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  943. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  944. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  945. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  946. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  947. {1, {4}}, data_type);
  948. }
  949. #endif
  950. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  951. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1) {
  952. constexpr size_t RUNS = 50;
  953. param::ConvBias param;
  954. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  955. param.pad_h = 1;
  956. param.pad_w = 1;
  957. param.stride_h = 1;
  958. param.stride_w = 1;
  959. param.sparse = param::ConvBias::Sparse::GROUP;
  960. std::vector<std::pair<SmallVector<TensorShape>, float>>
  961. shapes_and_computation;
  962. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  963. size_t FS, size_t group, size_t P, size_t S) {
  964. SmallVector<TensorShape> shapes{
  965. {N, IC, H, W},
  966. {group, OC / group, IC / group, FS, FS},
  967. {1, OC, 1, 1},
  968. {},
  969. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  970. TensorShape dst{N, OC, H, W};
  971. float computations =
  972. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  973. dst.total_nr_elems()) *
  974. 1e-6;
  975. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  976. };
  977. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  978. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  979. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  980. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  981. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  982. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  983. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  984. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  985. std::string algo_name = "QU8STRD1";
  986. printf("Benchmark QU8STRD1_LARGE_GROUP algo\n");
  987. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  988. dtype::Quantized8Asymm(0.2f, 120),
  989. dtype::QuantizedS32(0.04f),
  990. dtype::Quantized8Asymm(1.4f, 110)};
  991. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  992. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  993. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  994. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  995. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  996. {1, {4}}, data_type);
  997. shapes_and_computation.clear();
  998. algo_name = "QU8STRD1";
  999. printf("Benchmark QU8STRD1_SMALL_GROUP algo\n");
  1000. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1001. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1002. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1003. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1004. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1005. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1006. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1007. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1008. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1009. {1, {4}}, data_type);
  1010. }
  1011. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1012. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2) {
  1013. constexpr size_t RUNS = 50;
  1014. param::ConvBias param;
  1015. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1016. param.pad_h = 1;
  1017. param.pad_w = 1;
  1018. param.stride_h = 2;
  1019. param.stride_w = 2;
  1020. param.sparse = param::ConvBias::Sparse::GROUP;
  1021. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1022. shapes_and_computation;
  1023. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1024. size_t FS, size_t group, size_t P, size_t S) {
  1025. SmallVector<TensorShape> shapes{
  1026. {N, IC, H, W},
  1027. {group, OC / group, IC / group, FS, FS},
  1028. {1, OC, 1, 1},
  1029. {},
  1030. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1031. TensorShape dst{N, OC, H, W};
  1032. float computations =
  1033. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1034. dst.total_nr_elems()) *
  1035. 1e-6;
  1036. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1037. };
  1038. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  1039. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  1040. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  1041. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  1042. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  1043. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  1044. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  1045. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  1046. std::string algo_name = "QU8STRD2";
  1047. printf("Benchmark QU8STRD2_LARGE_GROUP algo\n");
  1048. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1049. dtype::Quantized8Asymm(0.2f, 120),
  1050. dtype::QuantizedS32(0.04f),
  1051. dtype::Quantized8Asymm(1.4f, 110)};
  1052. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1053. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1054. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1055. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1056. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1057. {1, {4}}, data_type);
  1058. shapes_and_computation.clear();
  1059. algo_name = "QU8STRD2";
  1060. printf("Benchmark QU8STRD2_SMALL_GROUP algo\n");
  1061. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  1062. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  1063. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  1064. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  1065. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1066. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1067. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1068. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1069. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1070. {1, {4}}, data_type);
  1071. }
  1072. #if MGB_ENABLE_DOT
  1073. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1074. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1_WITHDOTPROD) {
  1075. constexpr size_t RUNS = 50;
  1076. param::ConvBias param;
  1077. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1078. param.pad_h = 1;
  1079. param.pad_w = 1;
  1080. param.stride_h = 1;
  1081. param.stride_w = 1;
  1082. param.sparse = param::ConvBias::Sparse::GROUP;
  1083. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1084. shapes_and_computation;
  1085. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1086. size_t FS, size_t group, size_t P, size_t S) {
  1087. SmallVector<TensorShape> shapes{
  1088. {N, IC, H, W},
  1089. {group, OC / group, IC / group, FS, FS},
  1090. {1, OC, 1, 1},
  1091. {},
  1092. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1093. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1094. (W + 2 * P - FS) / S + 1};
  1095. float computations =
  1096. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1097. dst.total_nr_elems()) *
  1098. 1e-6;
  1099. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1100. };
  1101. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  1102. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  1103. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  1104. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  1105. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  1106. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  1107. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  1108. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  1109. std::string algo_name = "ARMDOTU8STRD1";
  1110. printf("Benchmark ARMDOTU8STRD1_LARGE_GROUP algo\n");
  1111. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1112. dtype::Quantized8Asymm(0.2f, 120),
  1113. dtype::QuantizedS32(0.04f),
  1114. dtype::Quantized8Asymm(1.4f, 110)};
  1115. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1116. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1117. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1118. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1119. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1120. {1, {4}}, data_type);
  1121. shapes_and_computation.clear();
  1122. algo_name = "ARMDOTU8STRD1";
  1123. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  1124. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1125. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1126. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1127. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1128. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1129. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1130. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1131. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1132. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1133. {1, {4}}, data_type);
  1134. }
  1135. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1136. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2_WITHDOTPROD) {
  1137. constexpr size_t RUNS = 50;
  1138. param::ConvBias param;
  1139. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1140. param.pad_h = 1;
  1141. param.pad_w = 1;
  1142. param.stride_h = 2;
  1143. param.stride_w = 2;
  1144. param.sparse = param::ConvBias::Sparse::GROUP;
  1145. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1146. shapes_and_computation;
  1147. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1148. size_t FS, size_t group, size_t P, size_t S) {
  1149. SmallVector<TensorShape> shapes{
  1150. {N, IC, H, W},
  1151. {group, OC / group, IC / group, FS, FS},
  1152. {1, OC, 1, 1},
  1153. {},
  1154. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1155. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1156. (W + 2 * P - FS) / S + 1};
  1157. float computations =
  1158. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1159. dst.total_nr_elems()) *
  1160. 1e-6;
  1161. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1162. };
  1163. bench_case(1, 32, 32, 200, 200, 5, 4, 1, 2);
  1164. bench_case(1, 32, 32, 200, 200, 5, 32, 1, 2);
  1165. bench_case(1, 32, 32, 128, 128, 5, 4, 1, 2);
  1166. bench_case(1, 32, 32, 128, 128, 5, 32, 1, 2);
  1167. bench_case(1, 32, 32, 100, 100, 5, 4, 1, 2);
  1168. bench_case(1, 32, 32, 100, 100, 5, 32, 1, 2);
  1169. bench_case(1, 32, 32, 80, 80, 5, 4, 1, 2);
  1170. bench_case(1, 32, 32, 80, 80, 5, 32, 1, 2);
  1171. std::string algo_name = "ARMDOTU8STRD2";
  1172. printf("Benchmark ARMDOTU8STRD2_LARGE_GROUP algo\n");
  1173. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1174. dtype::Quantized8Asymm(0.2f, 120),
  1175. dtype::QuantizedS32(0.04f),
  1176. dtype::Quantized8Asymm(1.4f, 110)};
  1177. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1178. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1179. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1180. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1181. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1182. {1, {4}}, data_type);
  1183. shapes_and_computation.clear();
  1184. algo_name = "ARMDOTU8STRD2";
  1185. printf("Benchmark ARMDOTU8STRD2_SMALL_GROUP algo\n");
  1186. bench_case(1, 32, 32, 200, 200, 5, 1, 1, 2);
  1187. bench_case(1, 32, 32, 128, 128, 5, 1, 1, 2);
  1188. bench_case(1, 32, 32, 100, 100, 5, 1, 1, 2);
  1189. bench_case(1, 32, 32, 80, 80, 5, 1, 1, 2);
  1190. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1191. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1192. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1193. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1194. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1195. {1, {4}}, data_type);
  1196. }
  1197. #endif
  1198. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_F32) {
  1199. constexpr size_t RUNS = 50;
  1200. param::ConvBias param;
  1201. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1202. param.pad_h = 1;
  1203. param.pad_w = 1;
  1204. param.stride_h = 1;
  1205. param.stride_w = 1;
  1206. param.sparse = param::ConvBias::Sparse::GROUP;
  1207. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1208. shapes_and_computation;
  1209. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1210. size_t FS, size_t group) {
  1211. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1212. {group, OC / group, IC / group, FS, FS},
  1213. {1, OC, 1, 1},
  1214. {},
  1215. {N, OC, H, W}};
  1216. TensorShape dst{N, OC, H, W};
  1217. float computations =
  1218. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1219. dst.total_nr_elems()) *
  1220. 1e-6;
  1221. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1222. };
  1223. bench_case(1, 32, 32, 200, 200, 3, 4);
  1224. bench_case(1, 32, 32, 200, 200, 3, 1);
  1225. bench_case(1, 32, 32, 128, 128, 3, 4);
  1226. bench_case(1, 32, 32, 128, 128, 3, 1);
  1227. bench_case(1, 32, 32, 100, 100, 3, 4);
  1228. bench_case(1, 32, 32, 100, 100, 3, 1);
  1229. bench_case(1, 32, 32, 80, 80, 3, 4);
  1230. bench_case(1, 512, 512, 14, 14, 3, 1);
  1231. bench_case(1, 512, 256, 14, 14, 3, 1);
  1232. bench_case(1, 512, 128, 14, 14, 3, 1);
  1233. bench_case(1, 512, 64, 14, 14, 3, 1);
  1234. bench_case(1, 512, 512, 7, 7, 3, 1);
  1235. bench_case(1, 512, 256, 7, 7, 3, 1);
  1236. bench_case(1, 512, 128, 7, 7, 3, 1);
  1237. bench_case(1, 512, 64, 7, 7, 3, 1);
  1238. std::string algo_name;
  1239. #if MEGDNN_AARCH64
  1240. algo_name = "WINOGRAD:AARCH64_F32_MK4_4x16:4:2";
  1241. #else
  1242. algo_name = "WINOGRAD:ARMV7_F32_MK4_4x8:4:2";
  1243. #endif
  1244. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1245. dtype::Float32(), dtype::Float32()};
  1246. printf("Benchmark WINOGRAD_F32_MK4 algo\n");
  1247. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1248. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1249. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1250. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1251. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1252. {1, {4}}, data_type);
  1253. }
  1254. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_INT8) {
  1255. constexpr size_t RUNS = 50;
  1256. param::ConvBias param;
  1257. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1258. param.pad_h = 1;
  1259. param.pad_w = 1;
  1260. param.stride_h = 1;
  1261. param.stride_w = 1;
  1262. param.sparse = param::ConvBias::Sparse::GROUP;
  1263. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1264. shapes_and_computation;
  1265. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1266. size_t FS, size_t group) {
  1267. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1268. {group, OC / group, IC / group, FS, FS},
  1269. {1, OC, 1, 1},
  1270. {},
  1271. {N, OC, H, W}};
  1272. TensorShape dst{N, OC, H, W};
  1273. float computations =
  1274. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1275. dst.total_nr_elems()) *
  1276. 1e-6;
  1277. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1278. };
  1279. bench_case(1, 32, 32, 200, 200, 3, 4);
  1280. bench_case(1, 32, 32, 200, 200, 3, 1);
  1281. bench_case(1, 32, 32, 128, 128, 3, 4);
  1282. bench_case(1, 32, 32, 128, 128, 3, 1);
  1283. bench_case(1, 32, 32, 100, 100, 3, 4);
  1284. bench_case(1, 32, 32, 100, 100, 3, 1);
  1285. bench_case(1, 32, 32, 80, 80, 3, 4);
  1286. bench_case(1, 512, 512, 14, 14, 3, 1);
  1287. bench_case(1, 512, 256, 14, 14, 3, 1);
  1288. bench_case(1, 512, 128, 14, 14, 3, 1);
  1289. bench_case(1, 512, 64, 14, 14, 3, 1);
  1290. bench_case(1, 512, 512, 7, 7, 3, 1);
  1291. bench_case(1, 512, 256, 7, 7, 3, 1);
  1292. bench_case(1, 512, 128, 7, 7, 3, 1);
  1293. bench_case(1, 512, 64, 7, 7, 3, 1);
  1294. std::string algo_name;
  1295. #if MEGDNN_AARCH64
  1296. algo_name = "WINOGRAD:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1297. #else
  1298. algo_name = "WINOGRAD:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1299. #endif
  1300. std::vector<DType> data_type = {dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1301. dtype::QuantizedS32(6.25f) ,dtype::QuantizedS8(60.25f) };
  1302. printf("Benchmark WINOGRAD_IN8_MK8 algo\n");
  1303. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1304. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1305. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1306. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1307. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1308. {1, {4}}, data_type);
  1309. }
  1310. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1311. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_MK8) {
  1312. constexpr size_t RUNS = 50;
  1313. param::ConvBias param;
  1314. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1315. param.pad_h = 1;
  1316. param.pad_w = 1;
  1317. param.stride_h = 1;
  1318. param.stride_w = 1;
  1319. param.sparse = param::ConvBias::Sparse::DENSE;
  1320. param.format = param::ConvBias::Format::NCHW44;
  1321. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1322. shapes_and_computation;
  1323. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1324. size_t FS, size_t group) {
  1325. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1326. {OC / 4, IC / 4, FS, FS, 4, 4},
  1327. {1, OC / 4, 1, 1, 4},
  1328. {},
  1329. {N, OC / 4, H, W, 4}};
  1330. TensorShape dst{N, OC, H, W};
  1331. float computations =
  1332. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1333. dst.total_nr_elems()) *
  1334. 1e-6;
  1335. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1336. };
  1337. bench_case(1, 32, 32, 200, 200, 3, 1);
  1338. bench_case(1, 32, 32, 128, 128, 3, 1);
  1339. bench_case(1, 32, 32, 100, 100, 3, 1);
  1340. bench_case(1, 512, 512, 14, 14, 3, 1);
  1341. bench_case(1, 512, 256, 14, 14, 3, 1);
  1342. bench_case(1, 512, 128, 14, 14, 3, 1);
  1343. bench_case(1, 512, 64, 14, 14, 3, 1);
  1344. bench_case(1, 512, 512, 7, 7, 3, 1);
  1345. bench_case(1, 512, 256, 7, 7, 3, 1);
  1346. bench_case(1, 512, 128, 7, 7, 3, 1);
  1347. bench_case(1, 512, 64, 7, 7, 3, 1);
  1348. std::string algo_name;
  1349. #if MEGDNN_AARCH64
  1350. algo_name = "WINOGRAD_NCHW44:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1351. #else
  1352. algo_name = "WINOGRAD_NCHW44:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1353. #endif
  1354. std::vector<DType> data_type = {
  1355. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1356. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1357. printf("Benchmark WINOGRAD_INT8_MK8 algo\n");
  1358. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1359. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1360. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1361. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1362. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1363. {1, {4}}, data_type);
  1364. }
  1365. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1366. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_COMP_F32) {
  1367. constexpr size_t RUNS = 50;
  1368. param::ConvBias param;
  1369. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1370. param.pad_h = 1;
  1371. param.pad_w = 1;
  1372. param.stride_h = 1;
  1373. param.stride_w = 1;
  1374. param.sparse = param::ConvBias::Sparse::DENSE; // GROUP;
  1375. param.format = param::ConvBias::Format::NCHW44;
  1376. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1377. shapes_and_computation;
  1378. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1379. size_t FS, size_t group) {
  1380. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1381. {OC / 4, IC / 4, FS, FS, 4, 4},
  1382. {1, OC / 4, 1, 1, 4},
  1383. {},
  1384. {N, OC / 4, H, W, 4}};
  1385. TensorShape dst{N, OC, H, W};
  1386. float computations =
  1387. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1388. dst.total_nr_elems()) *
  1389. 1e-6;
  1390. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1391. };
  1392. bench_case(1, 32, 32, 200, 200, 3, 1);
  1393. bench_case(1, 32, 32, 128, 128, 3, 1);
  1394. bench_case(1, 32, 32, 100, 100, 3, 1);
  1395. bench_case(1, 512, 512, 14, 14, 3, 1);
  1396. bench_case(1, 512, 256, 14, 14, 3, 1);
  1397. bench_case(1, 512, 128, 14, 14, 3, 1);
  1398. bench_case(1, 512, 64, 14, 14, 3, 1);
  1399. bench_case(1, 512, 512, 7, 7, 3, 1);
  1400. bench_case(1, 512, 256, 7, 7, 3, 1);
  1401. bench_case(1, 512, 128, 7, 7, 3, 1);
  1402. bench_case(1, 512, 64, 7, 7, 3, 1);
  1403. std::string algo_name;
  1404. #if MEGDNN_AARCH64
  1405. algo_name = "WINOGRAD_NCHW44:AARCH64_F32_MK4_4x16:4:2:32";
  1406. #else
  1407. algo_name = "WINOGRAD_NCHW44:ARMV7_F32_MK4_4x8:4:2:32";
  1408. #endif
  1409. std::vector<DType> data_type = {
  1410. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1411. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1412. printf("Benchmark WINOGRAD_INT8_NCHW44_MK4_COMP_F32 algo\n");
  1413. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1414. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1415. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1416. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1417. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1418. {1, {4}}, data_type);
  1419. }
  1420. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_FP32) {
  1421. constexpr size_t RUNS = 50;
  1422. param::ConvBias param;
  1423. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1424. param.pad_h = 1;
  1425. param.pad_w = 1;
  1426. param.stride_h = 1;
  1427. param.stride_w = 1;
  1428. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1429. shapes_and_computation;
  1430. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1431. size_t FS, size_t group) {
  1432. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1433. {OC, IC / group, FS, FS},
  1434. {1, OC, 1, 1},
  1435. {},
  1436. {N, OC, H, W}};
  1437. TensorShape dst{N, OC, H, W};
  1438. float computations =
  1439. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1440. dst.total_nr_elems()) *
  1441. 1e-6;
  1442. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1443. };
  1444. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1445. dtype::Float32(), dtype::Float32()};
  1446. bench_case(1, 32, 32, 300, 300, 3, 1);
  1447. bench_case(1, 32, 32, 400, 400, 3, 1);
  1448. bench_case(1, 32, 32, 100, 100, 3, 1);
  1449. bench_case(1, 32, 32, 80, 80, 3, 1);
  1450. bench_case(1, 32, 64, 200, 200, 3, 1);
  1451. bench_case(1, 32, 64, 128, 128, 3, 1);
  1452. bench_case(1, 32, 64, 100, 100, 3, 1);
  1453. bench_case(1, 32, 64, 80, 80, 3, 1);
  1454. bench_case(1, 32, 128, 200, 200, 3, 1);
  1455. bench_case(1, 32, 128, 128, 128, 3, 1);
  1456. bench_case(1, 32, 128, 100, 100, 3, 1);
  1457. bench_case(1, 32, 128, 80, 80, 3, 1);
  1458. bench_case(1, 64, 32, 7, 7, 3, 1);
  1459. bench_case(1, 64, 64, 7, 7, 3, 1);
  1460. bench_case(1, 64, 128, 7, 7, 3, 1);
  1461. bench_case(1, 64, 256, 7, 7, 3, 1);
  1462. bench_case(1, 64, 512, 7, 7, 3, 1);
  1463. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1464. bench_case(1, 64, 32, 14, 14, 3, 1);
  1465. bench_case(1, 64, 64, 14, 14, 3, 1);
  1466. bench_case(1, 64, 128, 14, 14, 3, 1);
  1467. bench_case(1, 64, 256, 14, 14, 3, 1);
  1468. bench_case(1, 64, 512, 14, 14, 3, 1);
  1469. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1470. bench_case(1, 128, 128, 14, 14, 3, 1);
  1471. bench_case(1, 128, 256, 14, 14, 3, 1);
  1472. bench_case(1, 512, 512, 14, 14, 3, 1);
  1473. bench_case(1, 256, 512, 14, 14, 3, 1);
  1474. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1475. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1476. std::string algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:96";
  1477. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:96\n");
  1478. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1479. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1480. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1481. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1482. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1483. {1, {4}}, data_type);
  1484. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:192";
  1485. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:192\n");
  1486. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1487. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1488. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1489. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1490. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1491. {1, {4}}, data_type);
  1492. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:384";
  1493. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:384\n");
  1494. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1495. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1496. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1497. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1498. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1499. {1, {4}}, data_type);
  1500. shapes_and_computation.clear();
  1501. }
  1502. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1503. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT8_STRIDE1) {
  1504. constexpr size_t RUNS = 50;
  1505. param::ConvBias param;
  1506. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1507. param.pad_h = 1;
  1508. param.pad_w = 1;
  1509. param.stride_h = 1;
  1510. param.stride_w = 1;
  1511. param.sparse = param::ConvBias::Sparse::GROUP;
  1512. param.format = param::ConvBias::Format::NCHW44;
  1513. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1514. shapes_and_computation;
  1515. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1516. size_t P) {
  1517. size_t group = IC;
  1518. size_t OC = IC;
  1519. size_t S = 1;
  1520. SmallVector<TensorShape> shapes{
  1521. {N, IC, H, W, 4},
  1522. {group, 1, 1, FS, FS, 4},
  1523. {1, OC, 1, 1, 4},
  1524. {},
  1525. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1526. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1527. (W + 2 * P - FS) / S + 1, 4};
  1528. float computations =
  1529. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1530. dst.total_nr_elems()) *
  1531. 1e-6;
  1532. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1533. };
  1534. bench_case(1, 128, 200, 200, 3, 1);
  1535. bench_case(1, 128, 128, 128, 3, 1);
  1536. bench_case(1, 128, 100, 100, 3, 1);
  1537. bench_case(1, 128, 80, 80, 3, 1);
  1538. bench_case(1, 128, 56, 56, 3, 1);
  1539. bench_case(1, 128, 28, 28, 3, 1);
  1540. bench_case(1, 128, 14, 14, 3, 1);
  1541. bench_case(1, 64, 200, 200, 3, 1);
  1542. bench_case(1, 64, 128, 128, 3, 1);
  1543. bench_case(1, 64, 100, 100, 3, 1);
  1544. bench_case(1, 64, 80, 80, 3, 1);
  1545. bench_case(1, 64, 56, 56, 3, 1);
  1546. bench_case(1, 64, 28, 28, 3, 1);
  1547. bench_case(1, 64, 14, 14, 3, 1);
  1548. bench_case(1, 32, 200, 200, 3, 1);
  1549. bench_case(1, 32, 128, 128, 3, 1);
  1550. bench_case(1, 32, 100, 100, 3, 1);
  1551. bench_case(1, 32, 80, 80, 3, 1);
  1552. bench_case(1, 32, 56, 56, 3, 1);
  1553. bench_case(1, 32, 28, 28, 3, 1);
  1554. bench_case(1, 32, 14, 14, 3, 1);
  1555. std::string algo_name = "S8_CHAN_WISE_STRD1_NCHW44";
  1556. printf("Benchmarker S8_CHAN_WISE_STRD1_NCHW44 algo\n");
  1557. std::vector<DType> data_type = {
  1558. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1559. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1560. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1561. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1562. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1563. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1564. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1565. {1, {4}}, data_type);
  1566. }
  1567. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1568. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT16_STRIDE1) {
  1569. constexpr size_t RUNS = 50;
  1570. param::ConvBias param;
  1571. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1572. param.pad_h = 1;
  1573. param.pad_w = 1;
  1574. param.stride_h = 1;
  1575. param.stride_w = 1;
  1576. param.sparse = param::ConvBias::Sparse::GROUP;
  1577. param.format = param::ConvBias::Format::NCHW44;
  1578. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1579. shapes_and_computation;
  1580. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1581. size_t P) {
  1582. size_t group = IC;
  1583. size_t OC = IC;
  1584. size_t S = 1;
  1585. SmallVector<TensorShape> shapes{
  1586. {N, IC, H, W, 4},
  1587. {group, 1, 1, FS, FS, 4},
  1588. {1, OC, 1, 1, 4},
  1589. {},
  1590. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1591. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1592. (W + 2 * P - FS) / S + 1, 4};
  1593. float computations =
  1594. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1595. dst.total_nr_elems()) *
  1596. 1e-6;
  1597. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1598. };
  1599. bench_case(1, 128, 200, 200, 3, 1);
  1600. bench_case(1, 128, 128, 128, 3, 1);
  1601. bench_case(1, 128, 100, 100, 3, 1);
  1602. bench_case(1, 128, 80, 80, 3, 1);
  1603. bench_case(1, 128, 56, 56, 3, 1);
  1604. bench_case(1, 128, 28, 28, 3, 1);
  1605. bench_case(1, 128, 14, 14, 3, 1);
  1606. bench_case(1, 64, 200, 200, 3, 1);
  1607. bench_case(1, 64, 128, 128, 3, 1);
  1608. bench_case(1, 64, 100, 100, 3, 1);
  1609. bench_case(1, 64, 80, 80, 3, 1);
  1610. bench_case(1, 64, 56, 56, 3, 1);
  1611. bench_case(1, 64, 28, 28, 3, 1);
  1612. bench_case(1, 64, 14, 14, 3, 1);
  1613. bench_case(1, 32, 200, 200, 3, 1);
  1614. bench_case(1, 32, 128, 128, 3, 1);
  1615. bench_case(1, 32, 100, 100, 3, 1);
  1616. bench_case(1, 32, 80, 80, 3, 1);
  1617. bench_case(1, 32, 56, 56, 3, 1);
  1618. bench_case(1, 32, 28, 28, 3, 1);
  1619. bench_case(1, 32, 14, 14, 3, 1);
  1620. std::string algo_name = "S8x8x16_CHAN_WISE_STRD1_STRD2_NCHW44";
  1621. printf("Benchmarker S8x8x16_CHAN_WISE_STRD1_STRD2_NCHW44 algo\n");
  1622. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  1623. dtype::Int16(), dtype::Int16()};
  1624. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1625. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1626. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1627. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1628. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1629. {1, {4}}, data_type);
  1630. }
  1631. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1632. BENCHMARK_IM2COL_NCHW44_INT8x8x32_STRIDE1) {
  1633. constexpr size_t RUNS = 50;
  1634. param::ConvBias param;
  1635. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1636. param.pad_h = 1;
  1637. param.pad_w = 1;
  1638. param.stride_h = 1;
  1639. param.stride_w = 1;
  1640. param.sparse = param::ConvBias::Sparse::DENSE;
  1641. param.format = param::ConvBias::Format::NCHW44;
  1642. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1643. shapes_and_computation;
  1644. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1645. size_t FS, size_t group=1) {
  1646. SmallVector<TensorShape> shapes{{N, IC, H, W,4},
  1647. {OC, IC / group, FS, FS,4,4},
  1648. {/*1, OC, 1, 1*/},
  1649. {},
  1650. {N, OC, H, W,4}};
  1651. TensorShape dst{N, OC, H, W,4};
  1652. float computations =
  1653. ((4 * IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1654. dst.total_nr_elems()) *
  1655. 1e-6;
  1656. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1657. };
  1658. bench_case(1, 32, 32, 300, 300, 3, 1);
  1659. bench_case(1, 32, 32, 400, 400, 3, 1);
  1660. bench_case(1, 32, 32, 100, 100, 3, 1);
  1661. bench_case(1, 32, 32, 80, 80, 3, 1);
  1662. bench_case(1, 32, 64, 200, 200, 3, 1);
  1663. bench_case(1, 32, 64, 128, 128, 3, 1);
  1664. bench_case(1, 32, 64, 100, 100, 3, 1);
  1665. bench_case(1, 32, 64, 80, 80, 3, 1);
  1666. bench_case(1, 32, 128, 200, 200, 3, 1);
  1667. bench_case(1, 32, 128, 128, 128, 3, 1);
  1668. bench_case(1, 32, 128, 100, 100, 3, 1);
  1669. bench_case(1, 32, 128, 80, 80, 3, 1);
  1670. #if 1
  1671. bench_case(1, 64, 32, 7, 7, 3, 1);
  1672. bench_case(1, 64, 64, 7, 7, 3, 1);
  1673. bench_case(1, 64, 128, 7, 7, 3, 1);
  1674. bench_case(1, 64, 256, 7, 7, 3, 1);
  1675. bench_case(1, 64, 512, 7, 7, 3, 1);
  1676. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1677. bench_case(1, 64, 32, 14, 14, 3, 1);
  1678. bench_case(1, 64, 64, 14, 14, 3, 1);
  1679. bench_case(1, 64, 128, 14, 14, 3, 1);
  1680. bench_case(1, 64, 256, 14, 14, 3, 1);
  1681. bench_case(1, 64, 512, 14, 14, 3, 1);
  1682. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1683. bench_case(1, 128, 128, 14, 14, 3, 1);
  1684. bench_case(1, 128, 256, 14, 14, 3, 1);
  1685. bench_case(1, 512, 512, 14, 14, 3, 1);
  1686. bench_case(1, 256, 512, 14, 14, 3, 1);
  1687. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1688. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1689. #endif
  1690. std::string algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96";
  1691. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96 algo\n");
  1692. std::vector<DType> data_type = {
  1693. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1694. dtype::QuantizedS32(6.25f), {}};
  1695. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1696. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1697. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1698. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1699. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1700. {1, {4}}, data_type);
  1701. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192";
  1702. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192 algo\n");
  1703. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1704. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1705. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1706. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1707. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1708. {1, {4}}, data_type);
  1709. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384";
  1710. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384 algo\n");
  1711. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1712. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1713. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1714. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1715. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1716. {1, {4}}, data_type);
  1717. }
  1718. #endif
  1719. /*================== BENCHMARK MULTITHREAD CONV1X1 =====================*/
  1720. #if MEGDNN_WITH_BENCHMARK
  1721. namespace {
  1722. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1723. get_conv1x1_multithread_benchmark_args() {
  1724. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1725. shapes_and_computation;
  1726. auto bench_case = [&](size_t IC, size_t OC, size_t H, size_t W) {
  1727. SmallVector<TensorShape> shapes{{1, IC, H, W},
  1728. {OC, IC, 1, 1},
  1729. {1, OC, 1, 1},
  1730. {},
  1731. {1, OC, H, W}};
  1732. TensorShape dst{1, OC, H, W};
  1733. float computations =
  1734. (IC * dst.total_nr_elems() * 2 + dst.total_nr_elems()) * 1e-6;
  1735. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1736. };
  1737. bench_case(32, 32, 300, 300);
  1738. bench_case(32, 32, 400, 400);
  1739. bench_case(32, 32, 100, 100);
  1740. bench_case(32, 32, 80, 80);
  1741. bench_case(32, 64, 200, 200);
  1742. bench_case(32, 64, 128, 128);
  1743. bench_case(32, 64, 100, 100);
  1744. bench_case(32, 64, 80, 80);
  1745. bench_case(32, 128, 200, 200);
  1746. bench_case(32, 128, 128, 128);
  1747. bench_case(32, 128, 100, 100);
  1748. bench_case(32, 128, 80, 80);
  1749. bench_case(64, 32, 7, 7);
  1750. bench_case(64, 64, 7, 7);
  1751. bench_case(64, 128, 7, 7);
  1752. bench_case(64, 256, 7, 7);
  1753. bench_case(64, 512, 7, 7);
  1754. bench_case(64, 1024, 7, 7);
  1755. bench_case(64, 32, 14, 14);
  1756. bench_case(64, 64, 14, 14);
  1757. bench_case(64, 128, 14, 14);
  1758. bench_case(64, 256, 14, 14);
  1759. bench_case(64, 512, 14, 14);
  1760. bench_case(64, 1024, 14, 14);
  1761. bench_case(128, 128, 14, 14);
  1762. bench_case(128, 256, 14, 14);
  1763. bench_case(512, 512, 14, 14);
  1764. bench_case(256, 512, 14, 14);
  1765. bench_case(512, 1024, 14, 14);
  1766. bench_case(1024, 1024, 14, 14);
  1767. return shapes_and_computation;
  1768. }
  1769. void conv1x1_multithread_benchmark(const char* algo_name, DType stype,
  1770. DType ftype, DType btype, DType dtype) {
  1771. constexpr size_t RUNS = 50;
  1772. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1773. shapes_and_computation = get_conv1x1_multithread_benchmark_args();
  1774. std::vector<DType> data_type = {stype, ftype, btype, dtype};
  1775. param::ConvBias param;
  1776. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1777. param.pad_h = 0;
  1778. param.pad_w = 0;
  1779. param.stride_h = 1;
  1780. param.stride_w = 1;
  1781. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1782. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1783. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1784. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1785. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1786. {1, {4}}, data_type);
  1787. shapes_and_computation.clear();
  1788. }
  1789. } // namespace
  1790. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CONV1X1_S1_FP32) {
  1791. #if MEGDNN_AARCH64
  1792. conv1x1_multithread_benchmark("CONV1x1:AARCH64_F32K8X12X1:8",
  1793. dtype::Float32(), dtype::Float32(),
  1794. dtype::Float32(), dtype::Float32());
  1795. #else
  1796. conv1x1_multithread_benchmark("CONV1x1:ARMV7_F32:8", dtype::Float32(),
  1797. dtype::Float32(), dtype::Float32(),
  1798. dtype::Float32());
  1799. #endif
  1800. }
  1801. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1802. BENCHMARK_CONVBIAS_CONV1X1_S1_QUANTIZEDASYM) {
  1803. dtype::Quantized8Asymm stype(0.2f, 100);
  1804. dtype::Quantized8Asymm ftype(0.2f, 120);
  1805. dtype::QuantizedS32 btype(0.04f);
  1806. dtype::Quantized8Asymm dtype(1.4f, 110);
  1807. #if MEGDNN_AARCH64
  1808. #if MGB_ENABLE_DOT
  1809. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:8",
  1810. stype, ftype, btype, dtype);
  1811. #else
  1812. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X8:8", stype,
  1813. ftype, btype, dtype);
  1814. #endif
  1815. #else
  1816. conv1x1_multithread_benchmark("CONV1x1:ARMV7_QUINT8_K4X8X8:8", stype, ftype,
  1817. btype, dtype);
  1818. #endif
  1819. }
  1820. #endif
  1821. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台