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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  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. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  612. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2) {
  613. constexpr size_t RUNS = 50;
  614. param::ConvBias param;
  615. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  616. param.pad_h = 1;
  617. param.pad_w = 1;
  618. param.stride_h = 2;
  619. param.stride_w = 2;
  620. param.sparse = param::ConvBias::Sparse::GROUP;
  621. std::vector<std::pair<SmallVector<TensorShape>, float>>
  622. shapes_and_computation;
  623. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  624. size_t FS, size_t group, size_t P, size_t S) {
  625. SmallVector<TensorShape> shapes{
  626. {N, IC, H, W},
  627. {group, OC / group, IC / group, FS, FS},
  628. {1, OC, 1, 1},
  629. {},
  630. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  631. TensorShape dst{N, OC, H, W};
  632. float computations =
  633. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  634. dst.total_nr_elems()) *
  635. 1e-6;
  636. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  637. };
  638. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  639. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  640. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  641. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  642. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  643. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  644. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  645. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  646. std::string algo_name = "S8STRD2_LARGE_GROUP";
  647. printf("Benchmark S8STRD2_LARGE_GROUP algo\n");
  648. std::vector<DType> data_type = {
  649. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  650. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  651. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  652. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  653. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  654. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  655. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  656. {1, {4}}, data_type);
  657. shapes_and_computation.clear();
  658. algo_name = "S8STRD2_SMALL_GROUP";
  659. printf("Benchmark S8STRD2_SMALL_GROUP algo\n");
  660. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  661. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  662. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  663. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  664. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  665. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  666. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  667. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  668. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  669. {1, {4}}, data_type);
  670. }
  671. #if __ARM_FEATURE_DOTPROD
  672. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  673. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1_WITHDOTPROD) {
  674. constexpr size_t RUNS = 50;
  675. param::ConvBias param;
  676. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  677. param.pad_h = 1;
  678. param.pad_w = 1;
  679. param.stride_h = 1;
  680. param.stride_w = 1;
  681. param.sparse = param::ConvBias::Sparse::GROUP;
  682. std::vector<std::pair<SmallVector<TensorShape>, float>>
  683. shapes_and_computation;
  684. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  685. size_t FS, size_t group, size_t P, size_t S) {
  686. SmallVector<TensorShape> shapes{
  687. {N, IC, H, W},
  688. {group, OC / group, IC / group, FS, FS},
  689. {1, OC, 1, 1},
  690. {},
  691. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  692. TensorShape dst{N, OC, H, W};
  693. float computations =
  694. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  695. dst.total_nr_elems()) *
  696. 1e-6;
  697. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  698. };
  699. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  700. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  701. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  702. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  703. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  704. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  705. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  706. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  707. std::string algo_name = "ARMDOTS8STRD1_LARGE_GROUP";
  708. printf("Benchmark ARMDOTS8STRD1_LARGE_GROUP algo\n");
  709. std::vector<DType> data_type = {
  710. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  711. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  712. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  713. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  714. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  715. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  716. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  717. {1, {4}}, data_type);
  718. shapes_and_computation.clear();
  719. algo_name = "ARMDOTS8STRD1_SMALL_GROUP";
  720. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  721. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  722. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  723. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  724. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  725. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  726. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  727. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  728. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  729. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  730. {1, {4}}, data_type);
  731. }
  732. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  733. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2_WITHDOTPROD) {
  734. constexpr size_t RUNS = 50;
  735. param::ConvBias param;
  736. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  737. param.pad_h = 1;
  738. param.pad_w = 1;
  739. param.stride_h = 2;
  740. param.stride_w = 2;
  741. param.sparse = param::ConvBias::Sparse::GROUP;
  742. std::vector<std::pair<SmallVector<TensorShape>, float>>
  743. shapes_and_computation;
  744. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  745. size_t FS, size_t group, size_t P, size_t S) {
  746. SmallVector<TensorShape> shapes{
  747. {N, IC, H, W},
  748. {group, OC / group, IC / group, FS, FS},
  749. {1, OC, 1, 1},
  750. {},
  751. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  752. TensorShape dst{N, OC, H, W};
  753. float computations =
  754. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  755. dst.total_nr_elems()) *
  756. 1e-6;
  757. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  758. };
  759. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  760. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  761. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  762. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  763. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  764. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  765. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  766. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  767. std::string algo_name = "ARMDOTS8STRD2_LARGE_GROUP";
  768. printf("Benchmark ARMDOTS8STRD2_LARGE_GROUP algo\n");
  769. std::vector<DType> data_type = {
  770. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  771. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  772. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  773. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  774. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  775. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  776. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  777. {1, {4}}, data_type);
  778. shapes_and_computation.clear();
  779. algo_name = "ARMDOTS8STRD2_SMALL_GROUP";
  780. printf("Benchmark ARMDOTS8STRD2_SMALL_GROUP algo\n");
  781. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  782. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  783. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  784. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  785. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  786. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  787. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  788. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  789. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  790. {1, {4}}, data_type);
  791. }
  792. #endif
  793. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  794. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1) {
  795. constexpr size_t RUNS = 50;
  796. param::ConvBias param;
  797. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  798. param.pad_h = 1;
  799. param.pad_w = 1;
  800. param.stride_h = 1;
  801. param.stride_w = 1;
  802. param.sparse = param::ConvBias::Sparse::GROUP;
  803. std::vector<std::pair<SmallVector<TensorShape>, float>>
  804. shapes_and_computation;
  805. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  806. size_t FS, size_t group, size_t P, size_t S) {
  807. SmallVector<TensorShape> shapes{
  808. {N, IC, H, W},
  809. {group, OC / group, IC / group, FS, FS},
  810. {1, OC, 1, 1},
  811. {},
  812. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  813. TensorShape dst{N, OC, H, W};
  814. float computations =
  815. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  816. dst.total_nr_elems()) *
  817. 1e-6;
  818. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  819. };
  820. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  821. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  822. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  823. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  824. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  825. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  826. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  827. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  828. std::string algo_name = "QU8STRD1_LARGE_GROUP";
  829. printf("Benchmark QU8STRD1_LARGE_GROUP algo\n");
  830. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  831. dtype::Quantized8Asymm(0.2f, 120),
  832. dtype::QuantizedS32(0.04f),
  833. dtype::Quantized8Asymm(1.4f, 110)};
  834. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  835. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  836. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  837. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  838. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  839. {1, {4}}, data_type);
  840. shapes_and_computation.clear();
  841. algo_name = "QU8STRD1_SMALL_GROUP";
  842. printf("Benchmark QU8STRD1_SMALL_GROUP algo\n");
  843. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  844. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  845. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  846. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  847. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  848. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  849. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  850. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  851. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  852. {1, {4}}, data_type);
  853. }
  854. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  855. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2) {
  856. constexpr size_t RUNS = 50;
  857. param::ConvBias param;
  858. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  859. param.pad_h = 1;
  860. param.pad_w = 1;
  861. param.stride_h = 2;
  862. param.stride_w = 2;
  863. param.sparse = param::ConvBias::Sparse::GROUP;
  864. std::vector<std::pair<SmallVector<TensorShape>, float>>
  865. shapes_and_computation;
  866. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  867. size_t FS, size_t group, size_t P, size_t S) {
  868. SmallVector<TensorShape> shapes{
  869. {N, IC, H, W},
  870. {group, OC / group, IC / group, FS, FS},
  871. {1, OC, 1, 1},
  872. {},
  873. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  874. TensorShape dst{N, OC, H, W};
  875. float computations =
  876. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  877. dst.total_nr_elems()) *
  878. 1e-6;
  879. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  880. };
  881. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  882. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  883. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  884. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  885. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  886. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  887. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  888. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  889. std::string algo_name = "QU8STRD2_LARGE_GROUP";
  890. printf("Benchmark QU8STRD2_LARGE_GROUP algo\n");
  891. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  892. dtype::Quantized8Asymm(0.2f, 120),
  893. dtype::QuantizedS32(0.04f),
  894. dtype::Quantized8Asymm(1.4f, 110)};
  895. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  896. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  897. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  898. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  899. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  900. {1, {4}}, data_type);
  901. shapes_and_computation.clear();
  902. algo_name = "QU8STRD2_SMALL_GROUP";
  903. printf("Benchmark QU8STRD2_SMALL_GROUP algo\n");
  904. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  905. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  906. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  907. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  908. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  909. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  910. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  911. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  912. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  913. {1, {4}}, data_type);
  914. }
  915. #if __ARM_FEATURE_DOTPROD
  916. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  917. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1_WITHDOTPROD) {
  918. constexpr size_t RUNS = 50;
  919. param::ConvBias param;
  920. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  921. param.pad_h = 1;
  922. param.pad_w = 1;
  923. param.stride_h = 1;
  924. param.stride_w = 1;
  925. param.sparse = param::ConvBias::Sparse::GROUP;
  926. std::vector<std::pair<SmallVector<TensorShape>, float>>
  927. shapes_and_computation;
  928. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  929. size_t FS, size_t group, size_t P, size_t S) {
  930. SmallVector<TensorShape> shapes{
  931. {N, IC, H, W},
  932. {group, OC / group, IC / group, FS, FS},
  933. {1, OC, 1, 1},
  934. {},
  935. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  936. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  937. (W + 2 * P - FS) / S + 1};
  938. float computations =
  939. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  940. dst.total_nr_elems()) *
  941. 1e-6;
  942. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  943. };
  944. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  945. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  946. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  947. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  948. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  949. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  950. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  951. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  952. std::string algo_name = "ARMDOTU8STRD1_LARGE_GROUP";
  953. printf("Benchmark ARMDOTU8STRD1_LARGE_GROUP algo\n");
  954. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  955. dtype::Quantized8Asymm(0.2f, 120),
  956. dtype::QuantizedS32(0.04f),
  957. dtype::Quantized8Asymm(1.4f, 110)};
  958. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  959. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  960. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  961. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  962. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  963. {1, {4}}, data_type);
  964. shapes_and_computation.clear();
  965. algo_name = "ARMDOTU8STRD1_SMALL_GROUP";
  966. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  967. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  968. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  969. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  970. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  971. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  972. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  973. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  974. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  975. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  976. {1, {4}}, data_type);
  977. }
  978. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  979. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2_WITHDOTPROD) {
  980. constexpr size_t RUNS = 50;
  981. param::ConvBias param;
  982. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  983. param.pad_h = 1;
  984. param.pad_w = 1;
  985. param.stride_h = 2;
  986. param.stride_w = 2;
  987. param.sparse = param::ConvBias::Sparse::GROUP;
  988. std::vector<std::pair<SmallVector<TensorShape>, float>>
  989. shapes_and_computation;
  990. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  991. size_t FS, size_t group, size_t P, size_t S) {
  992. SmallVector<TensorShape> shapes{
  993. {N, IC, H, W},
  994. {group, OC / group, IC / group, FS, FS},
  995. {1, OC, 1, 1},
  996. {},
  997. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  998. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  999. (W + 2 * P - FS) / S + 1};
  1000. float computations =
  1001. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1002. dst.total_nr_elems()) *
  1003. 1e-6;
  1004. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1005. };
  1006. bench_case(1, 32, 32, 200, 200, 5, 4, 1, 2);
  1007. bench_case(1, 32, 32, 200, 200, 5, 32, 1, 2);
  1008. bench_case(1, 32, 32, 128, 128, 5, 4, 1, 2);
  1009. bench_case(1, 32, 32, 128, 128, 5, 32, 1, 2);
  1010. bench_case(1, 32, 32, 100, 100, 5, 4, 1, 2);
  1011. bench_case(1, 32, 32, 100, 100, 5, 32, 1, 2);
  1012. bench_case(1, 32, 32, 80, 80, 5, 4, 1, 2);
  1013. bench_case(1, 32, 32, 80, 80, 5, 32, 1, 2);
  1014. std::string algo_name = "ARMDOTU8STRD2_LARGE_GROUP";
  1015. printf("Benchmark ARMDOTU8STRD2_LARGE_GROUP algo\n");
  1016. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1017. dtype::Quantized8Asymm(0.2f, 120),
  1018. dtype::QuantizedS32(0.04f),
  1019. dtype::Quantized8Asymm(1.4f, 110)};
  1020. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1021. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1022. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1023. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1024. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1025. {1, {4}}, data_type);
  1026. shapes_and_computation.clear();
  1027. algo_name = "ARMDOTU8STRD2_SMALL_GROUP";
  1028. printf("Benchmark ARMDOTU8STRD2_SMALL_GROUP algo\n");
  1029. bench_case(1, 32, 32, 200, 200, 5, 1, 1, 2);
  1030. bench_case(1, 32, 32, 128, 128, 5, 1, 1, 2);
  1031. bench_case(1, 32, 32, 100, 100, 5, 1, 1, 2);
  1032. bench_case(1, 32, 32, 80, 80, 5, 1, 1, 2);
  1033. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1034. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1035. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1036. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1037. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1038. {1, {4}}, data_type);
  1039. }
  1040. #endif
  1041. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_F32) {
  1042. constexpr size_t RUNS = 50;
  1043. param::ConvBias param;
  1044. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1045. param.pad_h = 1;
  1046. param.pad_w = 1;
  1047. param.stride_h = 1;
  1048. param.stride_w = 1;
  1049. param.sparse = param::ConvBias::Sparse::GROUP;
  1050. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1051. shapes_and_computation;
  1052. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1053. size_t FS, size_t group) {
  1054. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1055. {group, OC / group, IC / group, FS, FS},
  1056. {1, OC, 1, 1},
  1057. {},
  1058. {N, OC, H, W}};
  1059. TensorShape dst{N, OC, H, W};
  1060. float computations =
  1061. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1062. dst.total_nr_elems()) *
  1063. 1e-6;
  1064. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1065. };
  1066. bench_case(1, 32, 32, 200, 200, 3, 4);
  1067. bench_case(1, 32, 32, 200, 200, 3, 1);
  1068. bench_case(1, 32, 32, 128, 128, 3, 4);
  1069. bench_case(1, 32, 32, 128, 128, 3, 1);
  1070. bench_case(1, 32, 32, 100, 100, 3, 4);
  1071. bench_case(1, 32, 32, 100, 100, 3, 1);
  1072. bench_case(1, 32, 32, 80, 80, 3, 4);
  1073. bench_case(1, 512, 512, 14, 14, 3, 1);
  1074. bench_case(1, 512, 256, 14, 14, 3, 1);
  1075. bench_case(1, 512, 128, 14, 14, 3, 1);
  1076. bench_case(1, 512, 64, 14, 14, 3, 1);
  1077. bench_case(1, 512, 512, 7, 7, 3, 1);
  1078. bench_case(1, 512, 256, 7, 7, 3, 1);
  1079. bench_case(1, 512, 128, 7, 7, 3, 1);
  1080. bench_case(1, 512, 64, 7, 7, 3, 1);
  1081. std::string algo_name;
  1082. #if MEGDNN_AARCH64
  1083. algo_name = "WINOGRAD:AARCH64_F32_MK4_4x16:4:2";
  1084. #else
  1085. algo_name = "WINOGRAD:ARMV7_F32_MK4_4x8:4:2";
  1086. #endif
  1087. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1088. dtype::Float32(), dtype::Float32()};
  1089. printf("Benchmark WINOGRAD_F32_MK4 algo\n");
  1090. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1091. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1092. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1093. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1094. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1095. {1, {4}}, data_type);
  1096. }
  1097. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_FP32) {
  1098. constexpr size_t RUNS = 50;
  1099. param::ConvBias param;
  1100. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1101. param.pad_h = 1;
  1102. param.pad_w = 1;
  1103. param.stride_h = 1;
  1104. param.stride_w = 1;
  1105. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1106. shapes_and_computation;
  1107. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1108. size_t FS, size_t group) {
  1109. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1110. {OC, IC / group, FS, FS},
  1111. {1, OC, 1, 1},
  1112. {},
  1113. {N, OC, H, W}};
  1114. TensorShape dst{N, OC, H, W};
  1115. float computations =
  1116. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1117. dst.total_nr_elems()) *
  1118. 1e-6;
  1119. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1120. };
  1121. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1122. dtype::Float32(), dtype::Float32()};
  1123. bench_case(1, 32, 32, 300, 300, 3, 1);
  1124. bench_case(1, 32, 32, 400, 400, 3, 1);
  1125. bench_case(1, 32, 32, 100, 100, 3, 1);
  1126. bench_case(1, 32, 32, 80, 80, 3, 1);
  1127. bench_case(1, 32, 64, 200, 200, 3, 1);
  1128. bench_case(1, 32, 64, 128, 128, 3, 1);
  1129. bench_case(1, 32, 64, 100, 100, 3, 1);
  1130. bench_case(1, 32, 64, 80, 80, 3, 1);
  1131. bench_case(1, 32, 128, 200, 200, 3, 1);
  1132. bench_case(1, 32, 128, 128, 128, 3, 1);
  1133. bench_case(1, 32, 128, 100, 100, 3, 1);
  1134. bench_case(1, 32, 128, 80, 80, 3, 1);
  1135. bench_case(1, 64, 32, 7, 7, 3, 1);
  1136. bench_case(1, 64, 64, 7, 7, 3, 1);
  1137. bench_case(1, 64, 128, 7, 7, 3, 1);
  1138. bench_case(1, 64, 256, 7, 7, 3, 1);
  1139. bench_case(1, 64, 512, 7, 7, 3, 1);
  1140. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1141. bench_case(1, 64, 32, 14, 14, 3, 1);
  1142. bench_case(1, 64, 64, 14, 14, 3, 1);
  1143. bench_case(1, 64, 128, 14, 14, 3, 1);
  1144. bench_case(1, 64, 256, 14, 14, 3, 1);
  1145. bench_case(1, 64, 512, 14, 14, 3, 1);
  1146. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1147. bench_case(1, 128, 128, 14, 14, 3, 1);
  1148. bench_case(1, 128, 256, 14, 14, 3, 1);
  1149. bench_case(1, 512, 512, 14, 14, 3, 1);
  1150. bench_case(1, 256, 512, 14, 14, 3, 1);
  1151. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1152. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1153. std::string algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:96";
  1154. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:96\n");
  1155. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1156. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1157. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1158. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1159. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1160. {1, {4}}, data_type);
  1161. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:192";
  1162. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:192\n");
  1163. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1164. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1165. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1166. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1167. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1168. {1, {4}}, data_type);
  1169. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:384";
  1170. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:384\n");
  1171. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1172. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1173. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1174. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1175. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1176. {1, {4}}, data_type);
  1177. shapes_and_computation.clear();
  1178. }
  1179. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1180. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT8_STRIDE1) {
  1181. constexpr size_t RUNS = 50;
  1182. param::ConvBias param;
  1183. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1184. param.pad_h = 1;
  1185. param.pad_w = 1;
  1186. param.stride_h = 1;
  1187. param.stride_w = 1;
  1188. param.sparse = param::ConvBias::Sparse::GROUP;
  1189. param.format = param::ConvBias::Format::NCHW44;
  1190. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1191. shapes_and_computation;
  1192. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1193. size_t P) {
  1194. size_t group = IC;
  1195. size_t OC = IC;
  1196. size_t S = 1;
  1197. SmallVector<TensorShape> shapes{
  1198. {N, IC, H, W, 4},
  1199. {group, 1, 1, FS, FS, 4},
  1200. {1, OC, 1, 1, 4},
  1201. {},
  1202. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1203. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1204. (W + 2 * P - FS) / S + 1, 4};
  1205. float computations =
  1206. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1207. dst.total_nr_elems()) *
  1208. 1e-6;
  1209. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1210. };
  1211. bench_case(1, 128, 200, 200, 3, 1);
  1212. bench_case(1, 128, 128, 128, 3, 1);
  1213. bench_case(1, 128, 100, 100, 3, 1);
  1214. bench_case(1, 128, 80, 80, 3, 1);
  1215. bench_case(1, 128, 56, 56, 3, 1);
  1216. bench_case(1, 128, 28, 28, 3, 1);
  1217. bench_case(1, 128, 14, 14, 3, 1);
  1218. bench_case(1, 64, 200, 200, 3, 1);
  1219. bench_case(1, 64, 128, 128, 3, 1);
  1220. bench_case(1, 64, 100, 100, 3, 1);
  1221. bench_case(1, 64, 80, 80, 3, 1);
  1222. bench_case(1, 64, 56, 56, 3, 1);
  1223. bench_case(1, 64, 28, 28, 3, 1);
  1224. bench_case(1, 64, 14, 14, 3, 1);
  1225. bench_case(1, 32, 200, 200, 3, 1);
  1226. bench_case(1, 32, 128, 128, 3, 1);
  1227. bench_case(1, 32, 100, 100, 3, 1);
  1228. bench_case(1, 32, 80, 80, 3, 1);
  1229. bench_case(1, 32, 56, 56, 3, 1);
  1230. bench_case(1, 32, 28, 28, 3, 1);
  1231. bench_case(1, 32, 14, 14, 3, 1);
  1232. std::string algo_name = "S8_CHAN_WISE_STRD1_NCHW44";
  1233. printf("Benchmarker S8_CHAN_WISE_STRD1_NCHW44 algo\n");
  1234. std::vector<DType> data_type = {
  1235. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1236. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1237. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1238. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1239. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1240. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1241. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1242. {1, {4}}, data_type);
  1243. }
  1244. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1245. BENCHMARK_IM2COL_NCHW44_INT8x8x32_STRIDE1) {
  1246. constexpr size_t RUNS = 50;
  1247. param::ConvBias param;
  1248. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1249. param.pad_h = 1;
  1250. param.pad_w = 1;
  1251. param.stride_h = 1;
  1252. param.stride_w = 1;
  1253. param.sparse = param::ConvBias::Sparse::DENSE;
  1254. param.format = param::ConvBias::Format::NCHW44;
  1255. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1256. shapes_and_computation;
  1257. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1258. size_t FS, size_t group=1) {
  1259. SmallVector<TensorShape> shapes{{N, IC, H, W,4},
  1260. {OC, IC / group, FS, FS,4,4},
  1261. {/*1, OC, 1, 1*/},
  1262. {},
  1263. {N, OC, H, W,4}};
  1264. TensorShape dst{N, OC, H, W,4};
  1265. float computations =
  1266. ((4 * IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1267. dst.total_nr_elems()) *
  1268. 1e-6;
  1269. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1270. };
  1271. bench_case(1, 32, 32, 300, 300, 3, 1);
  1272. bench_case(1, 32, 32, 400, 400, 3, 1);
  1273. bench_case(1, 32, 32, 100, 100, 3, 1);
  1274. bench_case(1, 32, 32, 80, 80, 3, 1);
  1275. bench_case(1, 32, 64, 200, 200, 3, 1);
  1276. bench_case(1, 32, 64, 128, 128, 3, 1);
  1277. bench_case(1, 32, 64, 100, 100, 3, 1);
  1278. bench_case(1, 32, 64, 80, 80, 3, 1);
  1279. bench_case(1, 32, 128, 200, 200, 3, 1);
  1280. bench_case(1, 32, 128, 128, 128, 3, 1);
  1281. bench_case(1, 32, 128, 100, 100, 3, 1);
  1282. bench_case(1, 32, 128, 80, 80, 3, 1);
  1283. #if 1
  1284. bench_case(1, 64, 32, 7, 7, 3, 1);
  1285. bench_case(1, 64, 64, 7, 7, 3, 1);
  1286. bench_case(1, 64, 128, 7, 7, 3, 1);
  1287. bench_case(1, 64, 256, 7, 7, 3, 1);
  1288. bench_case(1, 64, 512, 7, 7, 3, 1);
  1289. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1290. bench_case(1, 64, 32, 14, 14, 3, 1);
  1291. bench_case(1, 64, 64, 14, 14, 3, 1);
  1292. bench_case(1, 64, 128, 14, 14, 3, 1);
  1293. bench_case(1, 64, 256, 14, 14, 3, 1);
  1294. bench_case(1, 64, 512, 14, 14, 3, 1);
  1295. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1296. bench_case(1, 128, 128, 14, 14, 3, 1);
  1297. bench_case(1, 128, 256, 14, 14, 3, 1);
  1298. bench_case(1, 512, 512, 14, 14, 3, 1);
  1299. bench_case(1, 256, 512, 14, 14, 3, 1);
  1300. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1301. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1302. #endif
  1303. std::string algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96";
  1304. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96 algo\n");
  1305. std::vector<DType> data_type = {
  1306. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1307. dtype::QuantizedS32(6.25f), {}};
  1308. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1309. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1310. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1311. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1312. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1313. {1, {4}}, data_type);
  1314. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192";
  1315. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192 algo\n");
  1316. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1317. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1318. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1319. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1320. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1321. {1, {4}}, data_type);
  1322. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384";
  1323. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384 algo\n");
  1324. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1325. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1326. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1327. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1328. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1329. {1, {4}}, data_type);
  1330. }
  1331. #endif
  1332. /*================== BENCHMARK MULTITHREAD CONV1X1 =====================*/
  1333. #if MEGDNN_WITH_BENCHMARK
  1334. namespace {
  1335. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1336. get_conv1x1_multithread_benchmark_args() {
  1337. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1338. shapes_and_computation;
  1339. auto bench_case = [&](size_t IC, size_t OC, size_t H, size_t W) {
  1340. SmallVector<TensorShape> shapes{{1, IC, H, W},
  1341. {OC, IC, 1, 1},
  1342. {1, OC, 1, 1},
  1343. {},
  1344. {1, OC, H, W}};
  1345. TensorShape dst{1, OC, H, W};
  1346. float computations =
  1347. (IC * dst.total_nr_elems() * 2 + dst.total_nr_elems()) * 1e-6;
  1348. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1349. };
  1350. bench_case(32, 32, 300, 300);
  1351. bench_case(32, 32, 400, 400);
  1352. bench_case(32, 32, 100, 100);
  1353. bench_case(32, 32, 80, 80);
  1354. bench_case(32, 64, 200, 200);
  1355. bench_case(32, 64, 128, 128);
  1356. bench_case(32, 64, 100, 100);
  1357. bench_case(32, 64, 80, 80);
  1358. bench_case(32, 128, 200, 200);
  1359. bench_case(32, 128, 128, 128);
  1360. bench_case(32, 128, 100, 100);
  1361. bench_case(32, 128, 80, 80);
  1362. bench_case(64, 32, 7, 7);
  1363. bench_case(64, 64, 7, 7);
  1364. bench_case(64, 128, 7, 7);
  1365. bench_case(64, 256, 7, 7);
  1366. bench_case(64, 512, 7, 7);
  1367. bench_case(64, 1024, 7, 7);
  1368. bench_case(64, 32, 14, 14);
  1369. bench_case(64, 64, 14, 14);
  1370. bench_case(64, 128, 14, 14);
  1371. bench_case(64, 256, 14, 14);
  1372. bench_case(64, 512, 14, 14);
  1373. bench_case(64, 1024, 14, 14);
  1374. bench_case(128, 128, 14, 14);
  1375. bench_case(128, 256, 14, 14);
  1376. bench_case(512, 512, 14, 14);
  1377. bench_case(256, 512, 14, 14);
  1378. bench_case(512, 1024, 14, 14);
  1379. bench_case(1024, 1024, 14, 14);
  1380. return shapes_and_computation;
  1381. }
  1382. void conv1x1_multithread_benchmark(const char* algo_name, DType stype,
  1383. DType ftype, DType btype, DType dtype) {
  1384. constexpr size_t RUNS = 50;
  1385. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1386. shapes_and_computation = get_conv1x1_multithread_benchmark_args();
  1387. std::vector<DType> data_type = {stype, ftype, btype, dtype};
  1388. param::ConvBias param;
  1389. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1390. param.pad_h = 0;
  1391. param.pad_w = 0;
  1392. param.stride_h = 1;
  1393. param.stride_w = 1;
  1394. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1395. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1396. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1397. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1398. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1399. {1, {4}}, data_type);
  1400. shapes_and_computation.clear();
  1401. }
  1402. } // namespace
  1403. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CONV1X1_S1_FP32) {
  1404. #if MEGDNN_AARCH64
  1405. conv1x1_multithread_benchmark("CONV1x1:AARCH64_F32K8X12X1:8",
  1406. dtype::Float32(), dtype::Float32(),
  1407. dtype::Float32(), dtype::Float32());
  1408. #else
  1409. conv1x1_multithread_benchmark("CONV1x1:ARMV7_F32:8", dtype::Float32(),
  1410. dtype::Float32(), dtype::Float32(),
  1411. dtype::Float32());
  1412. #endif
  1413. }
  1414. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1415. BENCHMARK_CONVBIAS_CONV1X1_S1_QUANTIZEDASYM) {
  1416. dtype::Quantized8Asymm stype(0.2f, 100);
  1417. dtype::Quantized8Asymm ftype(0.2f, 120);
  1418. dtype::QuantizedS32 btype(0.04f);
  1419. dtype::Quantized8Asymm dtype(1.4f, 110);
  1420. #if MEGDNN_AARCH64
  1421. #if __ARM_FEATURE_DOTPROD
  1422. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:8",
  1423. stype, ftype, btype, dtype);
  1424. #else
  1425. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X8:8", stype,
  1426. ftype, btype, dtype);
  1427. #endif
  1428. #else
  1429. conv1x1_multithread_benchmark("CONV1x1:ARMV7_QUINT8_K4X8X8:8", stype, ftype,
  1430. btype, dtype);
  1431. #endif
  1432. }
  1433. #endif
  1434. // vim: syntax=cpp.doxygen

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