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

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

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