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

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

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