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 83 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  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-2020 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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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_LARGE_GROUP";
  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_SMALL_GROUP";
  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, 3, 64, 224, 224, 7, 1, 3, 2, true);
  596. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  597. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  598. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  599. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  600. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  601. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  602. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  603. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  604. bench_case(1, 4, 64, 224, 224, 7, 1, 1, 2);
  605. bench_case(1, 256, 128, 56, 56, 3, 1, 1, 2);
  606. bench_case(1, 512, 256, 28, 28, 3, 1, 1, 2);
  607. bench_case(1, 4, 32, 224, 224, 3, 1, 1, 2);
  608. bench_case(1, 256, 128, 56, 56, 3, 4, 1, 2);
  609. bench_case(1, 512, 256, 28, 28, 3, 4, 1, 2);
  610. }
  611. #if __ARM_FEATURE_DOTPROD
  612. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44_DOT) {
  613. constexpr size_t RUNS = 40;
  614. std::vector<DType> data_type = {
  615. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  616. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  617. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  618. size_t FS, size_t group, size_t P, size_t S,
  619. bool is_nchw = false) {
  620. param::ConvBias param;
  621. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  622. param.pad_h = P;
  623. param.pad_w = P;
  624. param.stride_h = S;
  625. param.stride_w = S;
  626. param.sparse = param::ConvBias::Sparse::DENSE;
  627. param.format = param::ConvBias::Format::NCHW44_DOT;
  628. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  629. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  630. TensorShape src = {N, IC / 4, H, W, 4};
  631. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  632. if (group > 1) {
  633. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  634. param.sparse = param::ConvBias::Sparse::GROUP;
  635. }
  636. if (is_nchw) {
  637. src = {N, IC, H, W};
  638. filter = {OC / 4, FS, FS, IC, 4};
  639. }
  640. TensorShape bias = {1, OC / 4, 1, 1, 4};
  641. TensorShape dst = {N, OC / 4, OH, OW, 4};
  642. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  643. float computations =
  644. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  645. dst.total_nr_elems()) *
  646. 1e-6;
  647. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  648. std::make_pair(shapes, computations)};
  649. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  650. {1, {7}}, data_type);
  651. };
  652. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  653. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  654. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  655. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  656. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  657. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  658. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  659. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  660. }
  661. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44_DOT_S2) {
  662. constexpr size_t RUNS = 40;
  663. std::vector<DType> data_type = {
  664. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  665. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  666. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  667. size_t FS, size_t group, size_t P, size_t S,
  668. bool is_nchw = false) {
  669. param::ConvBias param;
  670. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  671. param.pad_h = P;
  672. param.pad_w = P;
  673. param.stride_h = S;
  674. param.stride_w = S;
  675. param.sparse = param::ConvBias::Sparse::DENSE;
  676. param.format = param::ConvBias::Format::NCHW44_DOT;
  677. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  678. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  679. TensorShape src = {N, IC / 4, H, W, 4};
  680. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  681. if (group > 1) {
  682. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  683. param.sparse = param::ConvBias::Sparse::GROUP;
  684. }
  685. if (is_nchw) {
  686. src = {N, IC, H, W};
  687. filter = {OC / 4, FS, FS, IC, 4};
  688. }
  689. TensorShape bias = {1, OC / 4, 1, 1, 4};
  690. TensorShape dst = {N, OC / 4, OH, OW, 4};
  691. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  692. float computations =
  693. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  694. dst.total_nr_elems()) *
  695. 1e-6;
  696. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  697. std::make_pair(shapes, computations)};
  698. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  699. {1, {7}}, data_type);
  700. };
  701. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  702. bench_case(1, 64, 64, 128, 128, 3, 1, 1, 2);
  703. bench_case(1, 64, 64, 256, 256, 3, 1, 1, 2);
  704. bench_case(1, 64, 64, 156, 156, 3, 1, 1, 2);
  705. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  706. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  707. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  708. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  709. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  710. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  711. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  712. }
  713. #endif
  714. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_FLOAT_NCHW44) {
  715. constexpr size_t RUNS = 40;
  716. std::vector<DType> data_type = {
  717. dtype::Float32(), dtype::Float32(),
  718. dtype::Float32(), dtype::Float32()};
  719. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  720. size_t FS, size_t group, size_t P, size_t S,
  721. bool is_nchw = false) {
  722. param::ConvBias param;
  723. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  724. param.pad_h = P;
  725. param.pad_w = P;
  726. param.stride_h = S;
  727. param.stride_w = S;
  728. param.sparse = param::ConvBias::Sparse::DENSE;
  729. param.format = param::ConvBias::Format::NCHW44;
  730. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  731. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  732. TensorShape src = {N, IC / 4, H, W, 4};
  733. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  734. if (group > 1) {
  735. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  736. param.sparse = param::ConvBias::Sparse::GROUP;
  737. }
  738. if (is_nchw) {
  739. src = {N, IC, H, W};
  740. filter = {OC / 4, FS, FS, IC, 4};
  741. }
  742. TensorShape bias = {1, OC / 4, 1, 1, 4};
  743. TensorShape dst = {N, OC / 4, OH, OW, 4};
  744. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  745. float computations =
  746. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  747. dst.total_nr_elems()) *
  748. 1e-6;
  749. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  750. std::make_pair(shapes, computations)};
  751. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  752. {1, {7}}, data_type);
  753. };
  754. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  755. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  756. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  757. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  758. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  759. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  760. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  761. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  762. bench_case(1, 64, 64, 56*2, 56*2, 3, 4, 1, 2);
  763. bench_case(1, 128, 128, 28*2, 28*2, 3, 4, 1, 2);
  764. bench_case(1, 256, 256, 14*2, 14*2, 3, 4, 1, 2);
  765. bench_case(1, 512, 512, 7*2, 7*2, 3, 4, 1, 2);
  766. }
  767. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  768. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2) {
  769. constexpr size_t RUNS = 50;
  770. param::ConvBias param;
  771. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  772. param.pad_h = 1;
  773. param.pad_w = 1;
  774. param.stride_h = 2;
  775. param.stride_w = 2;
  776. param.sparse = param::ConvBias::Sparse::GROUP;
  777. std::vector<std::pair<SmallVector<TensorShape>, float>>
  778. shapes_and_computation;
  779. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  780. size_t FS, size_t group, size_t P, size_t S) {
  781. SmallVector<TensorShape> shapes{
  782. {N, IC, H, W},
  783. {group, OC / group, IC / group, FS, FS},
  784. {1, OC, 1, 1},
  785. {},
  786. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  787. TensorShape dst{N, OC, H, W};
  788. float computations =
  789. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  790. dst.total_nr_elems()) *
  791. 1e-6;
  792. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  793. };
  794. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  795. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  796. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  797. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  798. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  799. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  800. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  801. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  802. std::string algo_name = "S8STRD2_LARGE_GROUP";
  803. printf("Benchmark S8STRD2_LARGE_GROUP algo\n");
  804. std::vector<DType> data_type = {
  805. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  806. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  807. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  808. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  809. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  810. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  811. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  812. {1, {4}}, data_type);
  813. shapes_and_computation.clear();
  814. algo_name = "S8STRD2_SMALL_GROUP";
  815. printf("Benchmark S8STRD2_SMALL_GROUP algo\n");
  816. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  817. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  818. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  819. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  820. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  821. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  822. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  823. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  824. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  825. {1, {4}}, data_type);
  826. }
  827. #if __ARM_FEATURE_DOTPROD
  828. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  829. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1_WITHDOTPROD) {
  830. constexpr size_t RUNS = 50;
  831. param::ConvBias param;
  832. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  833. param.pad_h = 1;
  834. param.pad_w = 1;
  835. param.stride_h = 1;
  836. param.stride_w = 1;
  837. param.sparse = param::ConvBias::Sparse::GROUP;
  838. std::vector<std::pair<SmallVector<TensorShape>, float>>
  839. shapes_and_computation;
  840. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  841. size_t FS, size_t group, size_t P, size_t S) {
  842. SmallVector<TensorShape> shapes{
  843. {N, IC, H, W},
  844. {group, OC / group, IC / group, FS, FS},
  845. {1, OC, 1, 1},
  846. {},
  847. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  848. TensorShape dst{N, OC, H, W};
  849. float computations =
  850. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  851. dst.total_nr_elems()) *
  852. 1e-6;
  853. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  854. };
  855. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  856. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  857. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  858. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  859. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  860. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  861. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  862. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  863. std::string algo_name = "ARMDOTS8STRD1_LARGE_GROUP";
  864. printf("Benchmark ARMDOTS8STRD1_LARGE_GROUP algo\n");
  865. std::vector<DType> data_type = {
  866. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  867. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  868. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  869. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  870. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  871. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  872. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  873. {1, {4}}, data_type);
  874. shapes_and_computation.clear();
  875. algo_name = "ARMDOTS8STRD1_SMALL_GROUP";
  876. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  877. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  878. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  879. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  880. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  881. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  882. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  883. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  884. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  885. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  886. {1, {4}}, data_type);
  887. }
  888. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  889. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2_WITHDOTPROD) {
  890. constexpr size_t RUNS = 50;
  891. param::ConvBias param;
  892. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  893. param.pad_h = 1;
  894. param.pad_w = 1;
  895. param.stride_h = 2;
  896. param.stride_w = 2;
  897. param.sparse = param::ConvBias::Sparse::GROUP;
  898. std::vector<std::pair<SmallVector<TensorShape>, float>>
  899. shapes_and_computation;
  900. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  901. size_t FS, size_t group, size_t P, size_t S) {
  902. SmallVector<TensorShape> shapes{
  903. {N, IC, H, W},
  904. {group, OC / group, IC / group, FS, FS},
  905. {1, OC, 1, 1},
  906. {},
  907. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  908. TensorShape dst{N, OC, H, W};
  909. float computations =
  910. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  911. dst.total_nr_elems()) *
  912. 1e-6;
  913. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  914. };
  915. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  916. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  917. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  918. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  919. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  920. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  921. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  922. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  923. std::string algo_name = "ARMDOTS8STRD2_LARGE_GROUP";
  924. printf("Benchmark ARMDOTS8STRD2_LARGE_GROUP algo\n");
  925. std::vector<DType> data_type = {
  926. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  927. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  928. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  929. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  930. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  931. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  932. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  933. {1, {4}}, data_type);
  934. shapes_and_computation.clear();
  935. algo_name = "ARMDOTS8STRD2_SMALL_GROUP";
  936. printf("Benchmark ARMDOTS8STRD2_SMALL_GROUP algo\n");
  937. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  938. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  939. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  940. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  941. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  942. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  943. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  944. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  945. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  946. {1, {4}}, data_type);
  947. }
  948. #endif
  949. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  950. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1) {
  951. constexpr size_t RUNS = 50;
  952. param::ConvBias param;
  953. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  954. param.pad_h = 1;
  955. param.pad_w = 1;
  956. param.stride_h = 1;
  957. param.stride_w = 1;
  958. param.sparse = param::ConvBias::Sparse::GROUP;
  959. std::vector<std::pair<SmallVector<TensorShape>, float>>
  960. shapes_and_computation;
  961. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  962. size_t FS, size_t group, size_t P, size_t S) {
  963. SmallVector<TensorShape> shapes{
  964. {N, IC, H, W},
  965. {group, OC / group, IC / group, FS, FS},
  966. {1, OC, 1, 1},
  967. {},
  968. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  969. TensorShape dst{N, OC, H, W};
  970. float computations =
  971. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  972. dst.total_nr_elems()) *
  973. 1e-6;
  974. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  975. };
  976. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  977. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  978. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  979. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  980. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  981. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  982. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  983. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  984. std::string algo_name = "QU8STRD1_LARGE_GROUP";
  985. printf("Benchmark QU8STRD1_LARGE_GROUP algo\n");
  986. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  987. dtype::Quantized8Asymm(0.2f, 120),
  988. dtype::QuantizedS32(0.04f),
  989. dtype::Quantized8Asymm(1.4f, 110)};
  990. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  991. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  992. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  993. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  994. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  995. {1, {4}}, data_type);
  996. shapes_and_computation.clear();
  997. algo_name = "QU8STRD1_SMALL_GROUP";
  998. printf("Benchmark QU8STRD1_SMALL_GROUP algo\n");
  999. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1000. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1001. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1002. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1003. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1004. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1005. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1006. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1007. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1008. {1, {4}}, data_type);
  1009. }
  1010. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1011. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2) {
  1012. constexpr size_t RUNS = 50;
  1013. param::ConvBias param;
  1014. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1015. param.pad_h = 1;
  1016. param.pad_w = 1;
  1017. param.stride_h = 2;
  1018. param.stride_w = 2;
  1019. param.sparse = param::ConvBias::Sparse::GROUP;
  1020. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1021. shapes_and_computation;
  1022. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1023. size_t FS, size_t group, size_t P, size_t S) {
  1024. SmallVector<TensorShape> shapes{
  1025. {N, IC, H, W},
  1026. {group, OC / group, IC / group, FS, FS},
  1027. {1, OC, 1, 1},
  1028. {},
  1029. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1030. TensorShape dst{N, OC, H, W};
  1031. float computations =
  1032. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1033. dst.total_nr_elems()) *
  1034. 1e-6;
  1035. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1036. };
  1037. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  1038. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  1039. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  1040. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  1041. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  1042. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  1043. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  1044. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  1045. std::string algo_name = "QU8STRD2_LARGE_GROUP";
  1046. printf("Benchmark QU8STRD2_LARGE_GROUP algo\n");
  1047. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1048. dtype::Quantized8Asymm(0.2f, 120),
  1049. dtype::QuantizedS32(0.04f),
  1050. dtype::Quantized8Asymm(1.4f, 110)};
  1051. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1052. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1053. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1054. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1055. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1056. {1, {4}}, data_type);
  1057. shapes_and_computation.clear();
  1058. algo_name = "QU8STRD2_SMALL_GROUP";
  1059. printf("Benchmark QU8STRD2_SMALL_GROUP algo\n");
  1060. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  1061. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  1062. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  1063. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  1064. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1065. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1066. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1067. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1068. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1069. {1, {4}}, data_type);
  1070. }
  1071. #if __ARM_FEATURE_DOTPROD
  1072. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1073. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1_WITHDOTPROD) {
  1074. constexpr size_t RUNS = 50;
  1075. param::ConvBias param;
  1076. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1077. param.pad_h = 1;
  1078. param.pad_w = 1;
  1079. param.stride_h = 1;
  1080. param.stride_w = 1;
  1081. param.sparse = param::ConvBias::Sparse::GROUP;
  1082. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1083. shapes_and_computation;
  1084. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1085. size_t FS, size_t group, size_t P, size_t S) {
  1086. SmallVector<TensorShape> shapes{
  1087. {N, IC, H, W},
  1088. {group, OC / group, IC / group, FS, FS},
  1089. {1, OC, 1, 1},
  1090. {},
  1091. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1092. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1093. (W + 2 * P - FS) / S + 1};
  1094. float computations =
  1095. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1096. dst.total_nr_elems()) *
  1097. 1e-6;
  1098. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1099. };
  1100. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  1101. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  1102. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  1103. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  1104. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  1105. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  1106. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  1107. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  1108. std::string algo_name = "ARMDOTU8STRD1_LARGE_GROUP";
  1109. printf("Benchmark ARMDOTU8STRD1_LARGE_GROUP algo\n");
  1110. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1111. dtype::Quantized8Asymm(0.2f, 120),
  1112. dtype::QuantizedS32(0.04f),
  1113. dtype::Quantized8Asymm(1.4f, 110)};
  1114. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1115. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1116. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1117. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1118. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1119. {1, {4}}, data_type);
  1120. shapes_and_computation.clear();
  1121. algo_name = "ARMDOTU8STRD1_SMALL_GROUP";
  1122. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  1123. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1124. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1125. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1126. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1127. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1128. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1129. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1130. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1131. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1132. {1, {4}}, data_type);
  1133. }
  1134. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1135. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2_WITHDOTPROD) {
  1136. constexpr size_t RUNS = 50;
  1137. param::ConvBias param;
  1138. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1139. param.pad_h = 1;
  1140. param.pad_w = 1;
  1141. param.stride_h = 2;
  1142. param.stride_w = 2;
  1143. param.sparse = param::ConvBias::Sparse::GROUP;
  1144. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1145. shapes_and_computation;
  1146. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1147. size_t FS, size_t group, size_t P, size_t S) {
  1148. SmallVector<TensorShape> shapes{
  1149. {N, IC, H, W},
  1150. {group, OC / group, IC / group, FS, FS},
  1151. {1, OC, 1, 1},
  1152. {},
  1153. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1154. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1155. (W + 2 * P - FS) / S + 1};
  1156. float computations =
  1157. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1158. dst.total_nr_elems()) *
  1159. 1e-6;
  1160. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1161. };
  1162. bench_case(1, 32, 32, 200, 200, 5, 4, 1, 2);
  1163. bench_case(1, 32, 32, 200, 200, 5, 32, 1, 2);
  1164. bench_case(1, 32, 32, 128, 128, 5, 4, 1, 2);
  1165. bench_case(1, 32, 32, 128, 128, 5, 32, 1, 2);
  1166. bench_case(1, 32, 32, 100, 100, 5, 4, 1, 2);
  1167. bench_case(1, 32, 32, 100, 100, 5, 32, 1, 2);
  1168. bench_case(1, 32, 32, 80, 80, 5, 4, 1, 2);
  1169. bench_case(1, 32, 32, 80, 80, 5, 32, 1, 2);
  1170. std::string algo_name = "ARMDOTU8STRD2_LARGE_GROUP";
  1171. printf("Benchmark ARMDOTU8STRD2_LARGE_GROUP algo\n");
  1172. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1173. dtype::Quantized8Asymm(0.2f, 120),
  1174. dtype::QuantizedS32(0.04f),
  1175. dtype::Quantized8Asymm(1.4f, 110)};
  1176. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1177. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1178. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1179. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1180. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1181. {1, {4}}, data_type);
  1182. shapes_and_computation.clear();
  1183. algo_name = "ARMDOTU8STRD2_SMALL_GROUP";
  1184. printf("Benchmark ARMDOTU8STRD2_SMALL_GROUP algo\n");
  1185. bench_case(1, 32, 32, 200, 200, 5, 1, 1, 2);
  1186. bench_case(1, 32, 32, 128, 128, 5, 1, 1, 2);
  1187. bench_case(1, 32, 32, 100, 100, 5, 1, 1, 2);
  1188. bench_case(1, 32, 32, 80, 80, 5, 1, 1, 2);
  1189. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1190. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1191. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1192. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1193. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1194. {1, {4}}, data_type);
  1195. }
  1196. #endif
  1197. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_F32) {
  1198. constexpr size_t RUNS = 50;
  1199. param::ConvBias param;
  1200. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1201. param.pad_h = 1;
  1202. param.pad_w = 1;
  1203. param.stride_h = 1;
  1204. param.stride_w = 1;
  1205. param.sparse = param::ConvBias::Sparse::GROUP;
  1206. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1207. shapes_and_computation;
  1208. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1209. size_t FS, size_t group) {
  1210. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1211. {group, OC / group, IC / group, FS, FS},
  1212. {1, OC, 1, 1},
  1213. {},
  1214. {N, OC, H, W}};
  1215. TensorShape dst{N, OC, H, W};
  1216. float computations =
  1217. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1218. dst.total_nr_elems()) *
  1219. 1e-6;
  1220. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1221. };
  1222. bench_case(1, 32, 32, 200, 200, 3, 4);
  1223. bench_case(1, 32, 32, 200, 200, 3, 1);
  1224. bench_case(1, 32, 32, 128, 128, 3, 4);
  1225. bench_case(1, 32, 32, 128, 128, 3, 1);
  1226. bench_case(1, 32, 32, 100, 100, 3, 4);
  1227. bench_case(1, 32, 32, 100, 100, 3, 1);
  1228. bench_case(1, 32, 32, 80, 80, 3, 4);
  1229. bench_case(1, 512, 512, 14, 14, 3, 1);
  1230. bench_case(1, 512, 256, 14, 14, 3, 1);
  1231. bench_case(1, 512, 128, 14, 14, 3, 1);
  1232. bench_case(1, 512, 64, 14, 14, 3, 1);
  1233. bench_case(1, 512, 512, 7, 7, 3, 1);
  1234. bench_case(1, 512, 256, 7, 7, 3, 1);
  1235. bench_case(1, 512, 128, 7, 7, 3, 1);
  1236. bench_case(1, 512, 64, 7, 7, 3, 1);
  1237. std::string algo_name;
  1238. #if MEGDNN_AARCH64
  1239. algo_name = "WINOGRAD:AARCH64_F32_MK4_4x16:4:2";
  1240. #else
  1241. algo_name = "WINOGRAD:ARMV7_F32_MK4_4x8:4:2";
  1242. #endif
  1243. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1244. dtype::Float32(), dtype::Float32()};
  1245. printf("Benchmark WINOGRAD_F32_MK4 algo\n");
  1246. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1247. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1248. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1249. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1250. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1251. {1, {4}}, data_type);
  1252. }
  1253. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_INT8) {
  1254. constexpr size_t RUNS = 50;
  1255. param::ConvBias param;
  1256. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1257. param.pad_h = 1;
  1258. param.pad_w = 1;
  1259. param.stride_h = 1;
  1260. param.stride_w = 1;
  1261. param.sparse = param::ConvBias::Sparse::GROUP;
  1262. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1263. shapes_and_computation;
  1264. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1265. size_t FS, size_t group) {
  1266. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1267. {group, OC / group, IC / group, FS, FS},
  1268. {1, OC, 1, 1},
  1269. {},
  1270. {N, OC, H, W}};
  1271. TensorShape dst{N, OC, H, W};
  1272. float computations =
  1273. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1274. dst.total_nr_elems()) *
  1275. 1e-6;
  1276. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1277. };
  1278. bench_case(1, 32, 32, 200, 200, 3, 4);
  1279. bench_case(1, 32, 32, 200, 200, 3, 1);
  1280. bench_case(1, 32, 32, 128, 128, 3, 4);
  1281. bench_case(1, 32, 32, 128, 128, 3, 1);
  1282. bench_case(1, 32, 32, 100, 100, 3, 4);
  1283. bench_case(1, 32, 32, 100, 100, 3, 1);
  1284. bench_case(1, 32, 32, 80, 80, 3, 4);
  1285. bench_case(1, 512, 512, 14, 14, 3, 1);
  1286. bench_case(1, 512, 256, 14, 14, 3, 1);
  1287. bench_case(1, 512, 128, 14, 14, 3, 1);
  1288. bench_case(1, 512, 64, 14, 14, 3, 1);
  1289. bench_case(1, 512, 512, 7, 7, 3, 1);
  1290. bench_case(1, 512, 256, 7, 7, 3, 1);
  1291. bench_case(1, 512, 128, 7, 7, 3, 1);
  1292. bench_case(1, 512, 64, 7, 7, 3, 1);
  1293. std::string algo_name;
  1294. #if MEGDNN_AARCH64
  1295. algo_name = "WINOGRAD:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1296. #else
  1297. algo_name = "WINOGRAD:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1298. #endif
  1299. std::vector<DType> data_type = {dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1300. dtype::QuantizedS32(6.25f) ,dtype::QuantizedS8(60.25f) };
  1301. printf("Benchmark WINOGRAD_IN8_MK8 algo\n");
  1302. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1303. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1304. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1305. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1306. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1307. {1, {4}}, data_type);
  1308. }
  1309. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1310. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_MK8) {
  1311. constexpr size_t RUNS = 50;
  1312. param::ConvBias param;
  1313. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1314. param.pad_h = 1;
  1315. param.pad_w = 1;
  1316. param.stride_h = 1;
  1317. param.stride_w = 1;
  1318. param.sparse = param::ConvBias::Sparse::DENSE;
  1319. param.format = param::ConvBias::Format::NCHW44;
  1320. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1321. shapes_and_computation;
  1322. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1323. size_t FS, size_t group) {
  1324. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1325. {OC / 4, IC / 4, FS, FS, 4, 4},
  1326. {1, OC / 4, 1, 1, 4},
  1327. {},
  1328. {N, OC / 4, H, W, 4}};
  1329. TensorShape dst{N, OC, H, W};
  1330. float computations =
  1331. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1332. dst.total_nr_elems()) *
  1333. 1e-6;
  1334. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1335. };
  1336. bench_case(1, 32, 32, 200, 200, 3, 1);
  1337. bench_case(1, 32, 32, 128, 128, 3, 1);
  1338. bench_case(1, 32, 32, 100, 100, 3, 1);
  1339. bench_case(1, 512, 512, 14, 14, 3, 1);
  1340. bench_case(1, 512, 256, 14, 14, 3, 1);
  1341. bench_case(1, 512, 128, 14, 14, 3, 1);
  1342. bench_case(1, 512, 64, 14, 14, 3, 1);
  1343. bench_case(1, 512, 512, 7, 7, 3, 1);
  1344. bench_case(1, 512, 256, 7, 7, 3, 1);
  1345. bench_case(1, 512, 128, 7, 7, 3, 1);
  1346. bench_case(1, 512, 64, 7, 7, 3, 1);
  1347. std::string algo_name;
  1348. #if MEGDNN_AARCH64
  1349. algo_name = "WINOGRAD_NCHW44:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1350. #else
  1351. algo_name = "WINOGRAD_NCHW44:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1352. #endif
  1353. std::vector<DType> data_type = {
  1354. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1355. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1356. printf("Benchmark WINOGRAD_INT8_MK8 algo\n");
  1357. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1358. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1359. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1360. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1361. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1362. {1, {4}}, data_type);
  1363. }
  1364. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1365. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_COMP_F32) {
  1366. constexpr size_t RUNS = 50;
  1367. param::ConvBias param;
  1368. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1369. param.pad_h = 1;
  1370. param.pad_w = 1;
  1371. param.stride_h = 1;
  1372. param.stride_w = 1;
  1373. param.sparse = param::ConvBias::Sparse::DENSE; // GROUP;
  1374. param.format = param::ConvBias::Format::NCHW44;
  1375. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1376. shapes_and_computation;
  1377. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1378. size_t FS, size_t group) {
  1379. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1380. {OC / 4, IC / 4, FS, FS, 4, 4},
  1381. {1, OC / 4, 1, 1, 4},
  1382. {},
  1383. {N, OC / 4, H, W, 4}};
  1384. TensorShape dst{N, OC, H, W};
  1385. float computations =
  1386. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1387. dst.total_nr_elems()) *
  1388. 1e-6;
  1389. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1390. };
  1391. bench_case(1, 32, 32, 200, 200, 3, 1);
  1392. bench_case(1, 32, 32, 128, 128, 3, 1);
  1393. bench_case(1, 32, 32, 100, 100, 3, 1);
  1394. bench_case(1, 512, 512, 14, 14, 3, 1);
  1395. bench_case(1, 512, 256, 14, 14, 3, 1);
  1396. bench_case(1, 512, 128, 14, 14, 3, 1);
  1397. bench_case(1, 512, 64, 14, 14, 3, 1);
  1398. bench_case(1, 512, 512, 7, 7, 3, 1);
  1399. bench_case(1, 512, 256, 7, 7, 3, 1);
  1400. bench_case(1, 512, 128, 7, 7, 3, 1);
  1401. bench_case(1, 512, 64, 7, 7, 3, 1);
  1402. std::string algo_name;
  1403. #if MEGDNN_AARCH64
  1404. algo_name = "WINOGRAD_NCHW44:AARCH64_F32_MK4_4x16:4:2:32";
  1405. #else
  1406. algo_name = "WINOGRAD_NCHW44:ARMV7_F32_MK4_4x8:4:2:32";
  1407. #endif
  1408. std::vector<DType> data_type = {
  1409. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1410. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1411. printf("Benchmark WINOGRAD_INT8_NCHW44_MK4_COMP_F32 algo\n");
  1412. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1413. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1414. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1415. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1416. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1417. {1, {4}}, data_type);
  1418. }
  1419. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_FP32) {
  1420. constexpr size_t RUNS = 50;
  1421. param::ConvBias param;
  1422. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1423. param.pad_h = 1;
  1424. param.pad_w = 1;
  1425. param.stride_h = 1;
  1426. param.stride_w = 1;
  1427. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1428. shapes_and_computation;
  1429. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1430. size_t FS, size_t group) {
  1431. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1432. {OC, IC / group, FS, FS},
  1433. {1, OC, 1, 1},
  1434. {},
  1435. {N, OC, H, W}};
  1436. TensorShape dst{N, OC, H, W};
  1437. float computations =
  1438. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1439. dst.total_nr_elems()) *
  1440. 1e-6;
  1441. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1442. };
  1443. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1444. dtype::Float32(), dtype::Float32()};
  1445. bench_case(1, 32, 32, 300, 300, 3, 1);
  1446. bench_case(1, 32, 32, 400, 400, 3, 1);
  1447. bench_case(1, 32, 32, 100, 100, 3, 1);
  1448. bench_case(1, 32, 32, 80, 80, 3, 1);
  1449. bench_case(1, 32, 64, 200, 200, 3, 1);
  1450. bench_case(1, 32, 64, 128, 128, 3, 1);
  1451. bench_case(1, 32, 64, 100, 100, 3, 1);
  1452. bench_case(1, 32, 64, 80, 80, 3, 1);
  1453. bench_case(1, 32, 128, 200, 200, 3, 1);
  1454. bench_case(1, 32, 128, 128, 128, 3, 1);
  1455. bench_case(1, 32, 128, 100, 100, 3, 1);
  1456. bench_case(1, 32, 128, 80, 80, 3, 1);
  1457. bench_case(1, 64, 32, 7, 7, 3, 1);
  1458. bench_case(1, 64, 64, 7, 7, 3, 1);
  1459. bench_case(1, 64, 128, 7, 7, 3, 1);
  1460. bench_case(1, 64, 256, 7, 7, 3, 1);
  1461. bench_case(1, 64, 512, 7, 7, 3, 1);
  1462. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1463. bench_case(1, 64, 32, 14, 14, 3, 1);
  1464. bench_case(1, 64, 64, 14, 14, 3, 1);
  1465. bench_case(1, 64, 128, 14, 14, 3, 1);
  1466. bench_case(1, 64, 256, 14, 14, 3, 1);
  1467. bench_case(1, 64, 512, 14, 14, 3, 1);
  1468. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1469. bench_case(1, 128, 128, 14, 14, 3, 1);
  1470. bench_case(1, 128, 256, 14, 14, 3, 1);
  1471. bench_case(1, 512, 512, 14, 14, 3, 1);
  1472. bench_case(1, 256, 512, 14, 14, 3, 1);
  1473. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1474. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1475. std::string algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:96";
  1476. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:96\n");
  1477. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1478. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1479. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1480. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1481. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1482. {1, {4}}, data_type);
  1483. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:192";
  1484. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:192\n");
  1485. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1486. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1487. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1488. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1489. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1490. {1, {4}}, data_type);
  1491. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:384";
  1492. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:384\n");
  1493. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1494. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1495. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1496. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1497. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1498. {1, {4}}, data_type);
  1499. shapes_and_computation.clear();
  1500. }
  1501. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1502. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT8_STRIDE1) {
  1503. constexpr size_t RUNS = 50;
  1504. param::ConvBias param;
  1505. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1506. param.pad_h = 1;
  1507. param.pad_w = 1;
  1508. param.stride_h = 1;
  1509. param.stride_w = 1;
  1510. param.sparse = param::ConvBias::Sparse::GROUP;
  1511. param.format = param::ConvBias::Format::NCHW44;
  1512. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1513. shapes_and_computation;
  1514. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1515. size_t P) {
  1516. size_t group = IC;
  1517. size_t OC = IC;
  1518. size_t S = 1;
  1519. SmallVector<TensorShape> shapes{
  1520. {N, IC, H, W, 4},
  1521. {group, 1, 1, FS, FS, 4},
  1522. {1, OC, 1, 1, 4},
  1523. {},
  1524. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1525. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1526. (W + 2 * P - FS) / S + 1, 4};
  1527. float computations =
  1528. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1529. dst.total_nr_elems()) *
  1530. 1e-6;
  1531. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1532. };
  1533. bench_case(1, 128, 200, 200, 3, 1);
  1534. bench_case(1, 128, 128, 128, 3, 1);
  1535. bench_case(1, 128, 100, 100, 3, 1);
  1536. bench_case(1, 128, 80, 80, 3, 1);
  1537. bench_case(1, 128, 56, 56, 3, 1);
  1538. bench_case(1, 128, 28, 28, 3, 1);
  1539. bench_case(1, 128, 14, 14, 3, 1);
  1540. bench_case(1, 64, 200, 200, 3, 1);
  1541. bench_case(1, 64, 128, 128, 3, 1);
  1542. bench_case(1, 64, 100, 100, 3, 1);
  1543. bench_case(1, 64, 80, 80, 3, 1);
  1544. bench_case(1, 64, 56, 56, 3, 1);
  1545. bench_case(1, 64, 28, 28, 3, 1);
  1546. bench_case(1, 64, 14, 14, 3, 1);
  1547. bench_case(1, 32, 200, 200, 3, 1);
  1548. bench_case(1, 32, 128, 128, 3, 1);
  1549. bench_case(1, 32, 100, 100, 3, 1);
  1550. bench_case(1, 32, 80, 80, 3, 1);
  1551. bench_case(1, 32, 56, 56, 3, 1);
  1552. bench_case(1, 32, 28, 28, 3, 1);
  1553. bench_case(1, 32, 14, 14, 3, 1);
  1554. std::string algo_name = "S8_CHAN_WISE_STRD1_NCHW44";
  1555. printf("Benchmarker S8_CHAN_WISE_STRD1_NCHW44 algo\n");
  1556. std::vector<DType> data_type = {
  1557. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1558. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1559. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1560. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1561. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1562. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1563. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1564. {1, {4}}, data_type);
  1565. }
  1566. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1567. BENCHMARK_IM2COL_NCHW44_INT8x8x32_STRIDE1) {
  1568. constexpr size_t RUNS = 50;
  1569. param::ConvBias param;
  1570. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1571. param.pad_h = 1;
  1572. param.pad_w = 1;
  1573. param.stride_h = 1;
  1574. param.stride_w = 1;
  1575. param.sparse = param::ConvBias::Sparse::DENSE;
  1576. param.format = param::ConvBias::Format::NCHW44;
  1577. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1578. shapes_and_computation;
  1579. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1580. size_t FS, size_t group=1) {
  1581. SmallVector<TensorShape> shapes{{N, IC, H, W,4},
  1582. {OC, IC / group, FS, FS,4,4},
  1583. {/*1, OC, 1, 1*/},
  1584. {},
  1585. {N, OC, H, W,4}};
  1586. TensorShape dst{N, OC, H, W,4};
  1587. float computations =
  1588. ((4 * IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1589. dst.total_nr_elems()) *
  1590. 1e-6;
  1591. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1592. };
  1593. bench_case(1, 32, 32, 300, 300, 3, 1);
  1594. bench_case(1, 32, 32, 400, 400, 3, 1);
  1595. bench_case(1, 32, 32, 100, 100, 3, 1);
  1596. bench_case(1, 32, 32, 80, 80, 3, 1);
  1597. bench_case(1, 32, 64, 200, 200, 3, 1);
  1598. bench_case(1, 32, 64, 128, 128, 3, 1);
  1599. bench_case(1, 32, 64, 100, 100, 3, 1);
  1600. bench_case(1, 32, 64, 80, 80, 3, 1);
  1601. bench_case(1, 32, 128, 200, 200, 3, 1);
  1602. bench_case(1, 32, 128, 128, 128, 3, 1);
  1603. bench_case(1, 32, 128, 100, 100, 3, 1);
  1604. bench_case(1, 32, 128, 80, 80, 3, 1);
  1605. #if 1
  1606. bench_case(1, 64, 32, 7, 7, 3, 1);
  1607. bench_case(1, 64, 64, 7, 7, 3, 1);
  1608. bench_case(1, 64, 128, 7, 7, 3, 1);
  1609. bench_case(1, 64, 256, 7, 7, 3, 1);
  1610. bench_case(1, 64, 512, 7, 7, 3, 1);
  1611. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1612. bench_case(1, 64, 32, 14, 14, 3, 1);
  1613. bench_case(1, 64, 64, 14, 14, 3, 1);
  1614. bench_case(1, 64, 128, 14, 14, 3, 1);
  1615. bench_case(1, 64, 256, 14, 14, 3, 1);
  1616. bench_case(1, 64, 512, 14, 14, 3, 1);
  1617. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1618. bench_case(1, 128, 128, 14, 14, 3, 1);
  1619. bench_case(1, 128, 256, 14, 14, 3, 1);
  1620. bench_case(1, 512, 512, 14, 14, 3, 1);
  1621. bench_case(1, 256, 512, 14, 14, 3, 1);
  1622. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1623. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1624. #endif
  1625. std::string algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96";
  1626. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96 algo\n");
  1627. std::vector<DType> data_type = {
  1628. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1629. dtype::QuantizedS32(6.25f), {}};
  1630. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1631. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1632. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1633. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1634. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1635. {1, {4}}, data_type);
  1636. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192";
  1637. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192 algo\n");
  1638. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1639. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1640. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1641. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1642. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1643. {1, {4}}, data_type);
  1644. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384";
  1645. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384 algo\n");
  1646. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1647. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1648. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1649. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1650. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1651. {1, {4}}, data_type);
  1652. }
  1653. #endif
  1654. /*================== BENCHMARK MULTITHREAD CONV1X1 =====================*/
  1655. #if MEGDNN_WITH_BENCHMARK
  1656. namespace {
  1657. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1658. get_conv1x1_multithread_benchmark_args() {
  1659. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1660. shapes_and_computation;
  1661. auto bench_case = [&](size_t IC, size_t OC, size_t H, size_t W) {
  1662. SmallVector<TensorShape> shapes{{1, IC, H, W},
  1663. {OC, IC, 1, 1},
  1664. {1, OC, 1, 1},
  1665. {},
  1666. {1, OC, H, W}};
  1667. TensorShape dst{1, OC, H, W};
  1668. float computations =
  1669. (IC * dst.total_nr_elems() * 2 + dst.total_nr_elems()) * 1e-6;
  1670. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1671. };
  1672. bench_case(32, 32, 300, 300);
  1673. bench_case(32, 32, 400, 400);
  1674. bench_case(32, 32, 100, 100);
  1675. bench_case(32, 32, 80, 80);
  1676. bench_case(32, 64, 200, 200);
  1677. bench_case(32, 64, 128, 128);
  1678. bench_case(32, 64, 100, 100);
  1679. bench_case(32, 64, 80, 80);
  1680. bench_case(32, 128, 200, 200);
  1681. bench_case(32, 128, 128, 128);
  1682. bench_case(32, 128, 100, 100);
  1683. bench_case(32, 128, 80, 80);
  1684. bench_case(64, 32, 7, 7);
  1685. bench_case(64, 64, 7, 7);
  1686. bench_case(64, 128, 7, 7);
  1687. bench_case(64, 256, 7, 7);
  1688. bench_case(64, 512, 7, 7);
  1689. bench_case(64, 1024, 7, 7);
  1690. bench_case(64, 32, 14, 14);
  1691. bench_case(64, 64, 14, 14);
  1692. bench_case(64, 128, 14, 14);
  1693. bench_case(64, 256, 14, 14);
  1694. bench_case(64, 512, 14, 14);
  1695. bench_case(64, 1024, 14, 14);
  1696. bench_case(128, 128, 14, 14);
  1697. bench_case(128, 256, 14, 14);
  1698. bench_case(512, 512, 14, 14);
  1699. bench_case(256, 512, 14, 14);
  1700. bench_case(512, 1024, 14, 14);
  1701. bench_case(1024, 1024, 14, 14);
  1702. return shapes_and_computation;
  1703. }
  1704. void conv1x1_multithread_benchmark(const char* algo_name, DType stype,
  1705. DType ftype, DType btype, DType dtype) {
  1706. constexpr size_t RUNS = 50;
  1707. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1708. shapes_and_computation = get_conv1x1_multithread_benchmark_args();
  1709. std::vector<DType> data_type = {stype, ftype, btype, dtype};
  1710. param::ConvBias param;
  1711. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1712. param.pad_h = 0;
  1713. param.pad_w = 0;
  1714. param.stride_h = 1;
  1715. param.stride_w = 1;
  1716. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1717. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1718. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1719. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1720. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1721. {1, {4}}, data_type);
  1722. shapes_and_computation.clear();
  1723. }
  1724. } // namespace
  1725. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CONV1X1_S1_FP32) {
  1726. #if MEGDNN_AARCH64
  1727. conv1x1_multithread_benchmark("CONV1x1:AARCH64_F32K8X12X1:8",
  1728. dtype::Float32(), dtype::Float32(),
  1729. dtype::Float32(), dtype::Float32());
  1730. #else
  1731. conv1x1_multithread_benchmark("CONV1x1:ARMV7_F32:8", dtype::Float32(),
  1732. dtype::Float32(), dtype::Float32(),
  1733. dtype::Float32());
  1734. #endif
  1735. }
  1736. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1737. BENCHMARK_CONVBIAS_CONV1X1_S1_QUANTIZEDASYM) {
  1738. dtype::Quantized8Asymm stype(0.2f, 100);
  1739. dtype::Quantized8Asymm ftype(0.2f, 120);
  1740. dtype::QuantizedS32 btype(0.04f);
  1741. dtype::Quantized8Asymm dtype(1.4f, 110);
  1742. #if MEGDNN_AARCH64
  1743. #if __ARM_FEATURE_DOTPROD
  1744. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:8",
  1745. stype, ftype, btype, dtype);
  1746. #else
  1747. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X8:8", stype,
  1748. ftype, btype, dtype);
  1749. #endif
  1750. #else
  1751. conv1x1_multithread_benchmark("CONV1x1:ARMV7_QUINT8_K4X8X8:8", stype, ftype,
  1752. btype, dtype);
  1753. #endif
  1754. }
  1755. #endif
  1756. // vim: syntax=cpp.doxygen

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