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

conv_bias_multi_thread_benchmark.cpp 85 kB

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

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