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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  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. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CHANNEL_WISE_FP16_NCHW88) {
  377. constexpr size_t RUNS = 50;
  378. std::string algo_name = "F16_CHANNEL_WISE_NCHW88";
  379. printf("Benchmarker F16_CHANNEL_WISE_NCHW88 algo\n");
  380. std::vector<DType> data_type = {dtype::Float16(), dtype::Float16(),
  381. dtype::Float16(), dtype::Float16()};
  382. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  383. size_t P, size_t S) {
  384. param::ConvBias param;
  385. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  386. param.pad_h = P;
  387. param.pad_w = P;
  388. param.stride_h = S;
  389. param.stride_w = S;
  390. param.sparse = param::ConvBias::Sparse::GROUP;
  391. param.format = param::ConvBias::Format::NCHW88;
  392. size_t group = IC;
  393. size_t OC = IC;
  394. SmallVector<TensorShape> shapes{
  395. {N, IC, H, W, 8},
  396. {group, 1, 1, FS, FS, 8},
  397. {1, OC, 1, 1, 8},
  398. {},
  399. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 8}};
  400. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  401. (W + 2 * P - FS) / S + 1, 8};
  402. float computations =
  403. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  404. dst.total_nr_elems()) *
  405. 1e-6;
  406. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  407. std::make_pair(shapes, computations)};
  408. benchmark_impl(param, shape_arg, algo_name, RUNS, {4, {4, 5, 6, 7}},
  409. {1, {7}}, data_type);
  410. };
  411. bench_case(1, 64, 100, 100, 5, 2, 1);
  412. bench_case(1, 64, 56, 56, 5, 2, 1);
  413. bench_case(1, 64, 28, 28, 5, 2, 1);
  414. bench_case(1, 64, 100, 100, 5, 2, 2);
  415. bench_case(1, 64, 56, 56, 5, 2, 2);
  416. bench_case(1, 64, 28, 28, 5, 2, 2);
  417. bench_case(1, 64, 100, 100, 3, 1, 1);
  418. bench_case(1, 64, 56, 56, 3, 1, 1);
  419. bench_case(1, 64, 28, 28, 3, 1, 1);
  420. bench_case(1, 64, 100, 100, 3, 1, 2);
  421. bench_case(1, 64, 56, 56, 3, 1, 2);
  422. bench_case(1, 64, 28, 28, 3, 1, 2);
  423. bench_case(1, 64, 100, 100, 2, 0, 1);
  424. bench_case(1, 64, 56, 56, 2, 0, 1);
  425. bench_case(1, 64, 28, 28, 2, 0, 1);
  426. bench_case(1, 64, 100, 100, 2, 0, 2);
  427. bench_case(1, 64, 56, 56, 2, 0, 2);
  428. bench_case(1, 64, 28, 28, 2, 0, 2);
  429. }
  430. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_FP16_NCHW88) {
  431. constexpr size_t RUNS = 40;
  432. std::vector<DType> data_type = {dtype::Float16(), dtype::Float16(),
  433. dtype::Float16(), dtype::Float16()};
  434. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  435. size_t FS, size_t group, size_t P, size_t S) {
  436. param::ConvBias param;
  437. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  438. param.pad_h = P;
  439. param.pad_w = P;
  440. param.stride_h = S;
  441. param.stride_w = S;
  442. param.sparse = param::ConvBias::Sparse::DENSE;
  443. param.format = param::ConvBias::Format::NCHW88;
  444. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  445. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  446. TensorShape src = {N, IC / 8, H, W, 8};
  447. TensorShape filter = {OC / 8, IC / 8, FS, FS, 8, 8};
  448. if (group > 1) {
  449. filter = {group, OC / group / 8, IC / group / 8, FS, FS, 8, 8};
  450. param.sparse = param::ConvBias::Sparse::GROUP;
  451. }
  452. TensorShape bias = {1, OC / 8, 1, 1, 8};
  453. TensorShape dst = {N, OC / 8, OH, OW, 8};
  454. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  455. float computations =
  456. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  457. dst.total_nr_elems()) *
  458. 1e-6;
  459. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  460. std::make_pair(shapes, computations)};
  461. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  462. {1, {7}}, data_type);
  463. };
  464. bench_case(1, 64, 64, 28, 28, 3, 1, 1, 1);
  465. bench_case(1, 64, 64, 28, 28, 5, 1, 2, 1);
  466. bench_case(1, 64, 64, 28, 28, 7, 1, 3, 1);
  467. bench_case(1, 64, 64, 28, 28, 3, 1, 1, 2);
  468. bench_case(1, 64, 64, 28, 28, 5, 1, 2, 2);
  469. bench_case(1, 64, 64, 28, 28, 7, 1, 3, 2);
  470. bench_case(1, 64, 64, 28, 28, 3, 2, 1, 1);
  471. bench_case(1, 64, 64, 28, 28, 3, 4, 1, 1);
  472. bench_case(1, 64, 64, 28, 28, 3, 8, 1, 1);
  473. bench_case(1, 16, 16, 28, 28, 3, 1, 1, 1);
  474. bench_case(1, 32, 32, 28, 28, 3, 1, 1, 1);
  475. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  476. bench_case(1, 256, 256, 28, 28, 3, 1, 1, 1);
  477. bench_case(1, 64, 64, 7, 7, 3, 1, 1, 1);
  478. bench_case(1, 64, 64, 14, 14, 3, 1, 1, 1);
  479. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  480. bench_case(1, 64, 64, 112, 112, 3, 1, 1, 1);
  481. }
  482. #endif
  483. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  484. BENCHMARK_CONVBIAS_DIRECT_INT8x8x16) {
  485. constexpr size_t RUNS = 50;
  486. param::ConvBias param;
  487. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  488. param.pad_h = 1;
  489. param.pad_w = 1;
  490. param.stride_h = 1;
  491. param.stride_w = 1;
  492. param.sparse = param::ConvBias::Sparse::GROUP;
  493. std::vector<std::pair<SmallVector<TensorShape>, float>>
  494. shapes_and_computation;
  495. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  496. size_t FS, size_t group) {
  497. SmallVector<TensorShape> shapes{{N, IC, H, W},
  498. {group, OC / group, IC / group, FS, FS},
  499. {},
  500. {},
  501. {N, OC, H, W}};
  502. TensorShape dst{N, OC, H, W};
  503. float computations =
  504. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  505. dst.total_nr_elems()) *
  506. 1e-6;
  507. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  508. };
  509. bench_case(1, 32, 32, 200, 200, 3, 4);
  510. bench_case(1, 32, 32, 200, 200, 3, 32);
  511. bench_case(1, 32, 32, 128, 128, 3, 4);
  512. bench_case(1, 32, 32, 128, 128, 3, 32);
  513. bench_case(1, 32, 32, 100, 100, 3, 4);
  514. bench_case(1, 32, 32, 100, 100, 3, 32);
  515. bench_case(1, 32, 32, 80, 80, 3, 4);
  516. bench_case(1, 32, 32, 80, 80, 3, 32);
  517. std::string algo_name = "I8816DIRECT";
  518. printf("Benchmark I8816DIRECT_LARGE_GROUP algo\n");
  519. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  520. dtype::Int16(), dtype::Int16()};
  521. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  522. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  523. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  524. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  525. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  526. {1, {4}}, data_type);
  527. shapes_and_computation.clear();
  528. algo_name = "I8816DIRECT";
  529. printf("Benchmark I8816DIRECT_SMALL_GROUP algo\n");
  530. bench_case(1, 32, 32, 200, 200, 3, 1);
  531. bench_case(1, 32, 32, 128, 128, 3, 1);
  532. bench_case(1, 32, 32, 100, 100, 3, 1);
  533. bench_case(1, 32, 32, 80, 80, 3, 1);
  534. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  535. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  536. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  537. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  538. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  539. {1, {4}}, data_type);
  540. }
  541. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  542. BENCHMARK_CONVBIAS_DIRECT_INT8x8x16_STR2) {
  543. constexpr size_t RUNS = 50;
  544. param::ConvBias param;
  545. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  546. param.pad_h = 1;
  547. param.pad_w = 1;
  548. param.stride_h = 2;
  549. param.stride_w = 2;
  550. param.sparse = param::ConvBias::Sparse::GROUP;
  551. std::vector<std::pair<SmallVector<TensorShape>, float>>
  552. shapes_and_computation;
  553. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  554. size_t FS, size_t group, size_t P, size_t S) {
  555. SmallVector<TensorShape> shapes{
  556. {N, IC, H, W},
  557. {group, OC / group, IC / group, FS, FS},
  558. {},
  559. {},
  560. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  561. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  562. (W + 2 * P - FS) / S + 1};
  563. float computations =
  564. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  565. dst.total_nr_elems()) *
  566. 1e-6;
  567. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  568. };
  569. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  570. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  571. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  572. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  573. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  574. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  575. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  576. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  577. std::string algo_name = "I8816STRD2";
  578. printf("Benchmark I8816STRD2_LARGE_GROUP algo\n");
  579. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  580. dtype::Int16(), dtype::Int16()};
  581. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  582. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  583. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  584. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  585. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  586. {1, {4}}, data_type);
  587. shapes_and_computation.clear();
  588. algo_name = "I8816STRD2";
  589. printf("Benchmark I8816STRD2_SMALL_GROUP algo\n");
  590. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  591. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  592. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  593. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  594. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  595. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  596. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  597. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  598. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  599. {1, {4}}, data_type);
  600. }
  601. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  602. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1) {
  603. constexpr size_t RUNS = 50;
  604. param::ConvBias param;
  605. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  606. param.pad_h = 1;
  607. param.pad_w = 1;
  608. param.stride_h = 1;
  609. param.stride_w = 1;
  610. param.sparse = param::ConvBias::Sparse::GROUP;
  611. std::vector<std::pair<SmallVector<TensorShape>, float>>
  612. shapes_and_computation;
  613. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  614. size_t FS, size_t group, size_t P, size_t S) {
  615. SmallVector<TensorShape> shapes{
  616. {N, IC, H, W},
  617. {group, OC / group, IC / group, FS, FS},
  618. {1, OC, 1, 1},
  619. {},
  620. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  621. TensorShape dst{N, OC, H, W};
  622. float computations =
  623. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  624. dst.total_nr_elems()) *
  625. 1e-6;
  626. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  627. };
  628. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  629. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  630. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  631. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  632. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  633. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  634. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  635. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  636. std::string algo_name = "S8STRD1";
  637. printf("Benchmark S8STRD1_LARGE_GROUP algo\n");
  638. std::vector<DType> data_type = {
  639. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  640. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  641. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  642. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  643. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  644. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  645. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  646. {1, {4}}, data_type);
  647. shapes_and_computation.clear();
  648. algo_name = "S8STRD1";
  649. printf("Benchmark S8STRD1_SMALL_GROUP algo\n");
  650. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  651. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  652. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  653. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  654. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  655. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  656. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  657. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  658. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  659. {1, {4}}, data_type);
  660. }
  661. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44) {
  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;
  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, 2, 64, 160, 160, 1, 1, 0, 1, true);
  702. bench_case(1, 3, 64, 224, 224, 7, 1, 3, 2, true);
  703. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  704. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  705. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  706. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  707. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  708. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  709. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  710. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  711. bench_case(1, 4, 64, 224, 224, 7, 1, 1, 2);
  712. bench_case(1, 256, 128, 56, 56, 3, 1, 1, 2);
  713. bench_case(1, 512, 256, 28, 28, 3, 1, 1, 2);
  714. bench_case(1, 4, 32, 224, 224, 3, 1, 1, 2);
  715. bench_case(1, 256, 128, 56, 56, 3, 4, 1, 2);
  716. bench_case(1, 512, 256, 28, 28, 3, 4, 1, 2);
  717. }
  718. #if MGB_ENABLE_DOT
  719. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_INT8_NCHW44_DOT) {
  720. constexpr size_t RUNS = 40;
  721. std::vector<DType> data_type = {
  722. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  723. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  724. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  725. size_t FS, size_t group, size_t P, size_t S,
  726. bool is_nchw = false) {
  727. param::ConvBias param;
  728. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  729. param.pad_h = P;
  730. param.pad_w = P;
  731. param.stride_h = S;
  732. param.stride_w = S;
  733. param.sparse = param::ConvBias::Sparse::DENSE;
  734. param.format = param::ConvBias::Format::NCHW44_DOT;
  735. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  736. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  737. TensorShape src = {N, IC / 4, H, W, 4};
  738. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  739. if (group > 1) {
  740. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  741. param.sparse = param::ConvBias::Sparse::GROUP;
  742. }
  743. if (is_nchw) {
  744. src = {N, IC, H, W};
  745. filter = {OC / 4, FS, FS, IC, 4};
  746. }
  747. TensorShape bias = {1, OC / 4, 1, 1, 4};
  748. TensorShape dst = {N, OC / 4, OH, OW, 4};
  749. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  750. float computations =
  751. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  752. dst.total_nr_elems()) *
  753. 1e-6;
  754. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  755. std::make_pair(shapes, computations)};
  756. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  757. {1, {7}}, data_type);
  758. };
  759. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 1);
  760. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 1);
  761. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 1);
  762. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 1);
  763. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 1);
  764. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 1);
  765. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 1);
  766. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 1);
  767. }
  768. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  769. BENCHMARK_CONVBIAS_INT8_NCHW44_DOT_S2) {
  770. constexpr size_t RUNS = 40;
  771. std::vector<DType> data_type = {
  772. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  773. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  774. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  775. size_t FS, size_t group, size_t P, size_t S,
  776. bool is_nchw = false) {
  777. param::ConvBias param;
  778. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  779. param.pad_h = P;
  780. param.pad_w = P;
  781. param.stride_h = S;
  782. param.stride_w = S;
  783. param.sparse = param::ConvBias::Sparse::DENSE;
  784. param.format = param::ConvBias::Format::NCHW44_DOT;
  785. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  786. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  787. TensorShape src = {N, IC / 4, H, W, 4};
  788. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  789. if (group > 1) {
  790. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  791. param.sparse = param::ConvBias::Sparse::GROUP;
  792. }
  793. if (is_nchw) {
  794. src = {N, IC, H, W};
  795. filter = {OC / 4, FS, FS, IC, 4};
  796. }
  797. TensorShape bias = {1, OC / 4, 1, 1, 4};
  798. TensorShape dst = {N, OC / 4, OH, OW, 4};
  799. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  800. float computations =
  801. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  802. dst.total_nr_elems()) *
  803. 1e-6;
  804. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  805. std::make_pair(shapes, computations)};
  806. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  807. {1, {7}}, data_type);
  808. };
  809. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  810. bench_case(1, 64, 64, 128, 128, 3, 1, 1, 2);
  811. bench_case(1, 64, 64, 256, 256, 3, 1, 1, 2);
  812. bench_case(1, 64, 64, 156, 156, 3, 1, 1, 2);
  813. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  814. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  815. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  816. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  817. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  818. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  819. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  820. }
  821. #endif
  822. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_FLOAT_NCHW44) {
  823. constexpr size_t RUNS = 40;
  824. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  825. dtype::Float32(), dtype::Float32()};
  826. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  827. size_t FS, size_t group, size_t P, size_t S,
  828. bool is_nchw = false) {
  829. param::ConvBias param;
  830. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  831. param.pad_h = P;
  832. param.pad_w = P;
  833. param.stride_h = S;
  834. param.stride_w = S;
  835. param.sparse = param::ConvBias::Sparse::DENSE;
  836. param.format = param::ConvBias::Format::NCHW44;
  837. auto OH = (H + 2 * P - FS) / static_cast<size_t>(S) + 1;
  838. auto OW = (W + 2 * P - FS) / static_cast<size_t>(S) + 1;
  839. TensorShape src = {N, IC / 4, H, W, 4};
  840. TensorShape filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  841. if (group > 1) {
  842. filter = {group, OC / group / 4, IC / group / 4, FS, FS, 4, 4};
  843. param.sparse = param::ConvBias::Sparse::GROUP;
  844. }
  845. if (is_nchw) {
  846. src = {N, IC, H, W};
  847. filter = {OC / 4, FS, FS, IC, 4};
  848. }
  849. TensorShape bias = {1, OC / 4, 1, 1, 4};
  850. TensorShape dst = {N, OC / 4, OH, OW, 4};
  851. SmallVector<TensorShape> shapes{src, filter, bias, {}, dst};
  852. float computations =
  853. (((IC / group) * FS * FS + 1) * dst.total_nr_elems() * 2 +
  854. dst.total_nr_elems()) *
  855. 1e-6;
  856. std::vector<std::pair<SmallVector<TensorShape>, float>> shape_arg = {
  857. std::make_pair(shapes, computations)};
  858. benchmark_impl(param, shape_arg, ".+", RUNS, {4, {4, 5, 6, 7}},
  859. {1, {7}}, data_type);
  860. };
  861. bench_case(1, 64, 64, 56, 56, 3, 1, 1, 2);
  862. bench_case(1, 128, 128, 28, 28, 3, 1, 1, 2);
  863. bench_case(1, 256, 256, 14, 14, 3, 1, 1, 2);
  864. bench_case(1, 512, 512, 7, 7, 3, 1, 1, 2);
  865. bench_case(1, 64, 64, 56, 56, 3, 4, 1, 2);
  866. bench_case(1, 128, 128, 28, 28, 3, 4, 1, 2);
  867. bench_case(1, 256, 256, 14, 14, 3, 4, 1, 2);
  868. bench_case(1, 512, 512, 7, 7, 3, 4, 1, 2);
  869. bench_case(1, 64, 64, 56 * 2, 56 * 2, 3, 4, 1, 2);
  870. bench_case(1, 128, 128, 28 * 2, 28 * 2, 3, 4, 1, 2);
  871. bench_case(1, 256, 256, 14 * 2, 14 * 2, 3, 4, 1, 2);
  872. bench_case(1, 512, 512, 7 * 2, 7 * 2, 3, 4, 1, 2);
  873. }
  874. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  875. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2) {
  876. constexpr size_t RUNS = 50;
  877. param::ConvBias param;
  878. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  879. param.pad_h = 1;
  880. param.pad_w = 1;
  881. param.stride_h = 2;
  882. param.stride_w = 2;
  883. param.sparse = param::ConvBias::Sparse::GROUP;
  884. std::vector<std::pair<SmallVector<TensorShape>, float>>
  885. shapes_and_computation;
  886. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  887. size_t FS, size_t group, size_t P, size_t S) {
  888. SmallVector<TensorShape> shapes{
  889. {N, IC, H, W},
  890. {group, OC / group, IC / group, FS, FS},
  891. {1, OC, 1, 1},
  892. {},
  893. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  894. TensorShape dst{N, OC, H, W};
  895. float computations =
  896. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  897. dst.total_nr_elems()) *
  898. 1e-6;
  899. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  900. };
  901. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  902. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  903. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  904. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  905. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  906. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  907. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  908. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  909. std::string algo_name = "S8STRD2";
  910. printf("Benchmark S8STRD2_LARGE_GROUP algo\n");
  911. std::vector<DType> data_type = {
  912. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  913. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  914. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  915. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  916. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  917. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  918. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  919. {1, {4}}, data_type);
  920. shapes_and_computation.clear();
  921. algo_name = "S8STRD2";
  922. printf("Benchmark S8STRD2_SMALL_GROUP algo\n");
  923. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  924. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  925. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  926. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  927. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  928. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  929. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  930. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  931. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  932. {1, {4}}, data_type);
  933. }
  934. #if MGB_ENABLE_DOT
  935. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  936. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE1_WITHDOTPROD) {
  937. constexpr size_t RUNS = 50;
  938. param::ConvBias param;
  939. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  940. param.pad_h = 1;
  941. param.pad_w = 1;
  942. param.stride_h = 1;
  943. param.stride_w = 1;
  944. param.sparse = param::ConvBias::Sparse::GROUP;
  945. std::vector<std::pair<SmallVector<TensorShape>, float>>
  946. shapes_and_computation;
  947. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  948. size_t FS, size_t group, size_t P, size_t S) {
  949. SmallVector<TensorShape> shapes{
  950. {N, IC, H, W},
  951. {group, OC / group, IC / group, FS, FS},
  952. {1, OC, 1, 1},
  953. {},
  954. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  955. TensorShape dst{N, OC, H, W};
  956. float computations =
  957. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  958. dst.total_nr_elems()) *
  959. 1e-6;
  960. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  961. };
  962. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  963. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  964. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  965. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  966. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  967. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  968. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  969. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  970. std::string algo_name = "ARMDOTS8STRD1";
  971. printf("Benchmark ARMDOTS8STRD1_LARGE_GROUP algo\n");
  972. std::vector<DType> data_type = {
  973. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  974. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  975. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  976. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  977. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  978. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  979. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  980. {1, {4}}, data_type);
  981. shapes_and_computation.clear();
  982. algo_name = "ARMDOTS8STRD1";
  983. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  984. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  985. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  986. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  987. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  988. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  989. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  990. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  991. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  992. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  993. {1, {4}}, data_type);
  994. }
  995. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  996. BENCHMARK_CONVBIAS_INT8_INT8_INT8_STRIDE2_WITHDOTPROD) {
  997. constexpr size_t RUNS = 50;
  998. param::ConvBias param;
  999. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1000. param.pad_h = 1;
  1001. param.pad_w = 1;
  1002. param.stride_h = 2;
  1003. param.stride_w = 2;
  1004. param.sparse = param::ConvBias::Sparse::GROUP;
  1005. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1006. shapes_and_computation;
  1007. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1008. size_t FS, size_t group, size_t P, size_t S) {
  1009. SmallVector<TensorShape> shapes{
  1010. {N, IC, H, W},
  1011. {group, OC / group, IC / group, FS, FS},
  1012. {1, OC, 1, 1},
  1013. {},
  1014. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1015. TensorShape dst{N, OC, H, W};
  1016. float computations =
  1017. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1018. dst.total_nr_elems()) *
  1019. 1e-6;
  1020. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1021. };
  1022. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  1023. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  1024. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  1025. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  1026. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  1027. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  1028. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  1029. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  1030. std::string algo_name = "ARMDOTS8STRD2";
  1031. printf("Benchmark ARMDOTS8STRD2_LARGE_GROUP algo\n");
  1032. std::vector<DType> data_type = {
  1033. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1034. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1035. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1036. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1037. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1038. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1039. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1040. {1, {4}}, data_type);
  1041. shapes_and_computation.clear();
  1042. algo_name = "ARMDOTS8STRD2";
  1043. printf("Benchmark ARMDOTS8STRD2_SMALL_GROUP algo\n");
  1044. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  1045. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  1046. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  1047. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  1048. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1049. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1050. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1051. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1052. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1053. {1, {4}}, data_type);
  1054. }
  1055. #endif
  1056. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1057. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1) {
  1058. constexpr size_t RUNS = 50;
  1059. param::ConvBias param;
  1060. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1061. param.pad_h = 1;
  1062. param.pad_w = 1;
  1063. param.stride_h = 1;
  1064. param.stride_w = 1;
  1065. param.sparse = param::ConvBias::Sparse::GROUP;
  1066. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1067. shapes_and_computation;
  1068. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1069. size_t FS, size_t group, size_t P, size_t S) {
  1070. SmallVector<TensorShape> shapes{
  1071. {N, IC, H, W},
  1072. {group, OC / group, IC / group, FS, FS},
  1073. {1, OC, 1, 1},
  1074. {},
  1075. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1076. TensorShape dst{N, OC, H, W};
  1077. float computations =
  1078. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1079. dst.total_nr_elems()) *
  1080. 1e-6;
  1081. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1082. };
  1083. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  1084. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  1085. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  1086. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  1087. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  1088. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  1089. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  1090. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  1091. std::string algo_name = "QU8STRD1";
  1092. printf("Benchmark QU8STRD1_LARGE_GROUP algo\n");
  1093. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1094. dtype::Quantized8Asymm(0.2f, 120),
  1095. dtype::QuantizedS32(0.04f),
  1096. dtype::Quantized8Asymm(1.4f, 110)};
  1097. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1098. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1099. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1100. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1101. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1102. {1, {4}}, data_type);
  1103. shapes_and_computation.clear();
  1104. algo_name = "QU8STRD1";
  1105. printf("Benchmark QU8STRD1_SMALL_GROUP algo\n");
  1106. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1107. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1108. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1109. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1110. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1111. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1112. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1113. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1114. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1115. {1, {4}}, data_type);
  1116. }
  1117. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1118. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2) {
  1119. constexpr size_t RUNS = 50;
  1120. param::ConvBias param;
  1121. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1122. param.pad_h = 1;
  1123. param.pad_w = 1;
  1124. param.stride_h = 2;
  1125. param.stride_w = 2;
  1126. param.sparse = param::ConvBias::Sparse::GROUP;
  1127. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1128. shapes_and_computation;
  1129. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1130. size_t FS, size_t group, size_t P, size_t S) {
  1131. SmallVector<TensorShape> shapes{
  1132. {N, IC, H, W},
  1133. {group, OC / group, IC / group, FS, FS},
  1134. {1, OC, 1, 1},
  1135. {},
  1136. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1137. TensorShape dst{N, OC, H, W};
  1138. float computations =
  1139. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1140. dst.total_nr_elems()) *
  1141. 1e-6;
  1142. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1143. };
  1144. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 2);
  1145. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 2);
  1146. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 2);
  1147. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 2);
  1148. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 2);
  1149. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 2);
  1150. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 2);
  1151. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 2);
  1152. std::string algo_name = "QU8STRD2";
  1153. printf("Benchmark QU8STRD2_LARGE_GROUP algo\n");
  1154. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1155. dtype::Quantized8Asymm(0.2f, 120),
  1156. dtype::QuantizedS32(0.04f),
  1157. dtype::Quantized8Asymm(1.4f, 110)};
  1158. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1159. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1160. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1161. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1162. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1163. {1, {4}}, data_type);
  1164. shapes_and_computation.clear();
  1165. algo_name = "QU8STRD2";
  1166. printf("Benchmark QU8STRD2_SMALL_GROUP algo\n");
  1167. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 2);
  1168. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 2);
  1169. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 2);
  1170. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 2);
  1171. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1172. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1173. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1174. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1175. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1176. {1, {4}}, data_type);
  1177. }
  1178. #if MGB_ENABLE_DOT
  1179. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1180. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE1_WITHDOTPROD) {
  1181. constexpr size_t RUNS = 50;
  1182. param::ConvBias param;
  1183. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1184. param.pad_h = 1;
  1185. param.pad_w = 1;
  1186. param.stride_h = 1;
  1187. param.stride_w = 1;
  1188. param.sparse = param::ConvBias::Sparse::GROUP;
  1189. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1190. shapes_and_computation;
  1191. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1192. size_t FS, size_t group, size_t P, size_t S) {
  1193. SmallVector<TensorShape> shapes{
  1194. {N, IC, H, W},
  1195. {group, OC / group, IC / group, FS, FS},
  1196. {1, OC, 1, 1},
  1197. {},
  1198. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1199. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1200. (W + 2 * P - FS) / S + 1};
  1201. float computations =
  1202. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1203. dst.total_nr_elems()) *
  1204. 1e-6;
  1205. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1206. };
  1207. bench_case(1, 32, 32, 200, 200, 3, 4, 1, 1);
  1208. bench_case(1, 32, 32, 200, 200, 3, 32, 1, 1);
  1209. bench_case(1, 32, 32, 128, 128, 3, 4, 1, 1);
  1210. bench_case(1, 32, 32, 128, 128, 3, 32, 1, 1);
  1211. bench_case(1, 32, 32, 100, 100, 3, 4, 1, 1);
  1212. bench_case(1, 32, 32, 100, 100, 3, 32, 1, 1);
  1213. bench_case(1, 32, 32, 80, 80, 3, 4, 1, 1);
  1214. bench_case(1, 32, 32, 80, 80, 3, 32, 1, 1);
  1215. std::string algo_name = "ARMDOTU8STRD1";
  1216. printf("Benchmark ARMDOTU8STRD1_LARGE_GROUP algo\n");
  1217. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1218. dtype::Quantized8Asymm(0.2f, 120),
  1219. dtype::QuantizedS32(0.04f),
  1220. dtype::Quantized8Asymm(1.4f, 110)};
  1221. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1222. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1223. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1224. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1225. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1226. {1, {4}}, data_type);
  1227. shapes_and_computation.clear();
  1228. algo_name = "ARMDOTU8STRD1";
  1229. printf("Benchmark ARMDOTS8STRD1_SMALL_GROUP algo\n");
  1230. bench_case(1, 32, 32, 200, 200, 3, 1, 1, 1);
  1231. bench_case(1, 32, 32, 128, 128, 3, 1, 1, 1);
  1232. bench_case(1, 32, 32, 100, 100, 3, 1, 1, 1);
  1233. bench_case(1, 32, 32, 80, 80, 3, 1, 1, 1);
  1234. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1235. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1236. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1237. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1238. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1239. {1, {4}}, data_type);
  1240. }
  1241. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1242. BENCHMARK_CONVBIAS_QUINT8_QUINT8_QUINT8_STRIDE2_WITHDOTPROD) {
  1243. constexpr size_t RUNS = 50;
  1244. param::ConvBias param;
  1245. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1246. param.pad_h = 1;
  1247. param.pad_w = 1;
  1248. param.stride_h = 2;
  1249. param.stride_w = 2;
  1250. param.sparse = param::ConvBias::Sparse::GROUP;
  1251. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1252. shapes_and_computation;
  1253. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1254. size_t FS, size_t group, size_t P, size_t S) {
  1255. SmallVector<TensorShape> shapes{
  1256. {N, IC, H, W},
  1257. {group, OC / group, IC / group, FS, FS},
  1258. {1, OC, 1, 1},
  1259. {},
  1260. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1}};
  1261. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1262. (W + 2 * P - FS) / S + 1};
  1263. float computations =
  1264. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1265. dst.total_nr_elems()) *
  1266. 1e-6;
  1267. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1268. };
  1269. bench_case(1, 32, 32, 200, 200, 5, 4, 1, 2);
  1270. bench_case(1, 32, 32, 200, 200, 5, 32, 1, 2);
  1271. bench_case(1, 32, 32, 128, 128, 5, 4, 1, 2);
  1272. bench_case(1, 32, 32, 128, 128, 5, 32, 1, 2);
  1273. bench_case(1, 32, 32, 100, 100, 5, 4, 1, 2);
  1274. bench_case(1, 32, 32, 100, 100, 5, 32, 1, 2);
  1275. bench_case(1, 32, 32, 80, 80, 5, 4, 1, 2);
  1276. bench_case(1, 32, 32, 80, 80, 5, 32, 1, 2);
  1277. std::string algo_name = "ARMDOTU8STRD2";
  1278. printf("Benchmark ARMDOTU8STRD2_LARGE_GROUP algo\n");
  1279. std::vector<DType> data_type = {dtype::Quantized8Asymm(0.2f, 100),
  1280. dtype::Quantized8Asymm(0.2f, 120),
  1281. dtype::QuantizedS32(0.04f),
  1282. dtype::Quantized8Asymm(1.4f, 110)};
  1283. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1284. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1285. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1286. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1287. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1288. {1, {4}}, data_type);
  1289. shapes_and_computation.clear();
  1290. algo_name = "ARMDOTU8STRD2";
  1291. printf("Benchmark ARMDOTU8STRD2_SMALL_GROUP algo\n");
  1292. bench_case(1, 32, 32, 200, 200, 5, 1, 1, 2);
  1293. bench_case(1, 32, 32, 128, 128, 5, 1, 1, 2);
  1294. bench_case(1, 32, 32, 100, 100, 5, 1, 1, 2);
  1295. bench_case(1, 32, 32, 80, 80, 5, 1, 1, 2);
  1296. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1297. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1298. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1299. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1300. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1301. {1, {4}}, data_type);
  1302. }
  1303. #endif
  1304. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_F32) {
  1305. constexpr size_t RUNS = 50;
  1306. param::ConvBias param;
  1307. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1308. param.pad_h = 1;
  1309. param.pad_w = 1;
  1310. param.stride_h = 1;
  1311. param.stride_w = 1;
  1312. param.sparse = param::ConvBias::Sparse::GROUP;
  1313. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1314. shapes_and_computation;
  1315. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1316. size_t FS, size_t group) {
  1317. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1318. {group, OC / group, IC / group, FS, FS},
  1319. {1, OC, 1, 1},
  1320. {},
  1321. {N, OC, H, W}};
  1322. TensorShape dst{N, OC, H, W};
  1323. float computations =
  1324. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1325. dst.total_nr_elems()) *
  1326. 1e-6;
  1327. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1328. };
  1329. bench_case(1, 32, 32, 200, 200, 3, 4);
  1330. bench_case(1, 32, 32, 200, 200, 3, 1);
  1331. bench_case(1, 32, 32, 128, 128, 3, 4);
  1332. bench_case(1, 32, 32, 128, 128, 3, 1);
  1333. bench_case(1, 32, 32, 100, 100, 3, 4);
  1334. bench_case(1, 32, 32, 100, 100, 3, 1);
  1335. bench_case(1, 32, 32, 80, 80, 3, 4);
  1336. bench_case(1, 512, 512, 14, 14, 3, 1);
  1337. bench_case(1, 512, 256, 14, 14, 3, 1);
  1338. bench_case(1, 512, 128, 14, 14, 3, 1);
  1339. bench_case(1, 512, 64, 14, 14, 3, 1);
  1340. bench_case(1, 512, 512, 7, 7, 3, 1);
  1341. bench_case(1, 512, 256, 7, 7, 3, 1);
  1342. bench_case(1, 512, 128, 7, 7, 3, 1);
  1343. bench_case(1, 512, 64, 7, 7, 3, 1);
  1344. std::string algo_name;
  1345. #if MEGDNN_AARCH64
  1346. algo_name = "WINOGRAD:AARCH64_F32_MK4_4x16:4:2";
  1347. #else
  1348. algo_name = "WINOGRAD:ARMV7_F32_MK4_4x8:4:2";
  1349. #endif
  1350. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1351. dtype::Float32(), dtype::Float32()};
  1352. printf("Benchmark WINOGRAD_F32_MK4 algo\n");
  1353. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1354. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1355. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1356. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1357. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1358. {1, {4}}, data_type);
  1359. }
  1360. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_WINOGRAD_INT8) {
  1361. constexpr size_t RUNS = 50;
  1362. param::ConvBias param;
  1363. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1364. param.pad_h = 1;
  1365. param.pad_w = 1;
  1366. param.stride_h = 1;
  1367. param.stride_w = 1;
  1368. param.sparse = param::ConvBias::Sparse::GROUP;
  1369. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1370. shapes_and_computation;
  1371. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1372. size_t FS, size_t group) {
  1373. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1374. {group, OC / group, IC / group, FS, FS},
  1375. {1, OC, 1, 1},
  1376. {},
  1377. {N, OC, H, W}};
  1378. TensorShape dst{N, OC, H, W};
  1379. float computations =
  1380. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1381. dst.total_nr_elems()) *
  1382. 1e-6;
  1383. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1384. };
  1385. bench_case(1, 32, 32, 200, 200, 3, 4);
  1386. bench_case(1, 32, 32, 200, 200, 3, 1);
  1387. bench_case(1, 32, 32, 128, 128, 3, 4);
  1388. bench_case(1, 32, 32, 128, 128, 3, 1);
  1389. bench_case(1, 32, 32, 100, 100, 3, 4);
  1390. bench_case(1, 32, 32, 100, 100, 3, 1);
  1391. bench_case(1, 32, 32, 80, 80, 3, 4);
  1392. bench_case(1, 512, 512, 14, 14, 3, 1);
  1393. bench_case(1, 512, 256, 14, 14, 3, 1);
  1394. bench_case(1, 512, 128, 14, 14, 3, 1);
  1395. bench_case(1, 512, 64, 14, 14, 3, 1);
  1396. bench_case(1, 512, 512, 7, 7, 3, 1);
  1397. bench_case(1, 512, 256, 7, 7, 3, 1);
  1398. bench_case(1, 512, 128, 7, 7, 3, 1);
  1399. bench_case(1, 512, 64, 7, 7, 3, 1);
  1400. std::string algo_name;
  1401. #if MEGDNN_AARCH64
  1402. algo_name = "WINOGRAD:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1403. #else
  1404. algo_name = "WINOGRAD:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1405. #endif
  1406. std::vector<DType> data_type = {
  1407. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1408. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1409. printf("Benchmark WINOGRAD_IN8_MK8 algo\n");
  1410. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1411. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1412. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1413. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1414. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1415. {1, {4}}, data_type);
  1416. }
  1417. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1418. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_MK8) {
  1419. constexpr size_t RUNS = 50;
  1420. param::ConvBias param;
  1421. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1422. param.pad_h = 1;
  1423. param.pad_w = 1;
  1424. param.stride_h = 1;
  1425. param.stride_w = 1;
  1426. param.sparse = param::ConvBias::Sparse::DENSE;
  1427. param.format = param::ConvBias::Format::NCHW44;
  1428. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1429. shapes_and_computation;
  1430. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1431. size_t FS, size_t group) {
  1432. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1433. {OC / 4, IC / 4, FS, FS, 4, 4},
  1434. {1, OC / 4, 1, 1, 4},
  1435. {},
  1436. {N, OC / 4, H, W, 4}};
  1437. TensorShape dst{N, OC, H, W};
  1438. float computations =
  1439. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1440. dst.total_nr_elems()) *
  1441. 1e-6;
  1442. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1443. };
  1444. bench_case(1, 32, 32, 200, 200, 3, 1);
  1445. bench_case(1, 32, 32, 128, 128, 3, 1);
  1446. bench_case(1, 32, 32, 100, 100, 3, 1);
  1447. bench_case(1, 512, 512, 14, 14, 3, 1);
  1448. bench_case(1, 512, 256, 14, 14, 3, 1);
  1449. bench_case(1, 512, 128, 14, 14, 3, 1);
  1450. bench_case(1, 512, 64, 14, 14, 3, 1);
  1451. bench_case(1, 512, 512, 7, 7, 3, 1);
  1452. bench_case(1, 512, 256, 7, 7, 3, 1);
  1453. bench_case(1, 512, 128, 7, 7, 3, 1);
  1454. bench_case(1, 512, 64, 7, 7, 3, 1);
  1455. std::string algo_name;
  1456. #if MEGDNN_AARCH64
  1457. algo_name = "WINOGRAD_NCHW44:AARCH64_INT16X16X32_MK8_8X8:8:2:32";
  1458. #else
  1459. algo_name = "WINOGRAD_NCHW44:ARMV7_INT16X16X32_MK8_4X8:8:2:32";
  1460. #endif
  1461. std::vector<DType> data_type = {
  1462. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1463. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1464. printf("Benchmark WINOGRAD_INT8_MK8 algo\n");
  1465. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1466. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1467. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1468. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1469. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1470. {1, {4}}, data_type);
  1471. }
  1472. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1473. BENCHMARK_CONVBIAS_WINOGRAD_NCHW44_INT8_COMP_F32) {
  1474. constexpr size_t RUNS = 50;
  1475. param::ConvBias param;
  1476. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1477. param.pad_h = 1;
  1478. param.pad_w = 1;
  1479. param.stride_h = 1;
  1480. param.stride_w = 1;
  1481. param.sparse = param::ConvBias::Sparse::DENSE; // GROUP;
  1482. param.format = param::ConvBias::Format::NCHW44;
  1483. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1484. shapes_and_computation;
  1485. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1486. size_t FS, size_t group) {
  1487. SmallVector<TensorShape> shapes{{N, IC / 4, H, W, 4},
  1488. {OC / 4, IC / 4, FS, FS, 4, 4},
  1489. {1, OC / 4, 1, 1, 4},
  1490. {},
  1491. {N, OC / 4, H, W, 4}};
  1492. TensorShape dst{N, OC, H, W};
  1493. float computations =
  1494. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1495. dst.total_nr_elems()) *
  1496. 1e-6;
  1497. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1498. };
  1499. bench_case(1, 32, 32, 200, 200, 3, 1);
  1500. bench_case(1, 32, 32, 128, 128, 3, 1);
  1501. bench_case(1, 32, 32, 100, 100, 3, 1);
  1502. bench_case(1, 512, 512, 14, 14, 3, 1);
  1503. bench_case(1, 512, 256, 14, 14, 3, 1);
  1504. bench_case(1, 512, 128, 14, 14, 3, 1);
  1505. bench_case(1, 512, 64, 14, 14, 3, 1);
  1506. bench_case(1, 512, 512, 7, 7, 3, 1);
  1507. bench_case(1, 512, 256, 7, 7, 3, 1);
  1508. bench_case(1, 512, 128, 7, 7, 3, 1);
  1509. bench_case(1, 512, 64, 7, 7, 3, 1);
  1510. std::string algo_name;
  1511. #if MEGDNN_AARCH64
  1512. algo_name = "WINOGRAD_NCHW44:AARCH64_F32_MK4_4x16:4:2:32";
  1513. #else
  1514. algo_name = "WINOGRAD_NCHW44:ARMV7_F32_MK4_4x8:4:2:32";
  1515. #endif
  1516. std::vector<DType> data_type = {
  1517. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1518. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1519. printf("Benchmark WINOGRAD_INT8_NCHW44_MK4_COMP_F32 algo\n");
  1520. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1521. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1522. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1523. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1524. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1525. {1, {4}}, data_type);
  1526. }
  1527. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_FP32) {
  1528. constexpr size_t RUNS = 50;
  1529. param::ConvBias param;
  1530. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1531. param.pad_h = 1;
  1532. param.pad_w = 1;
  1533. param.stride_h = 1;
  1534. param.stride_w = 1;
  1535. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1536. shapes_and_computation;
  1537. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1538. size_t FS, size_t group) {
  1539. SmallVector<TensorShape> shapes{{N, IC, H, W},
  1540. {OC, IC / group, FS, FS},
  1541. {1, OC, 1, 1},
  1542. {},
  1543. {N, OC, H, W}};
  1544. TensorShape dst{N, OC, H, W};
  1545. float computations =
  1546. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1547. dst.total_nr_elems()) *
  1548. 1e-6;
  1549. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1550. };
  1551. std::vector<DType> data_type = {dtype::Float32(), dtype::Float32(),
  1552. dtype::Float32(), dtype::Float32()};
  1553. bench_case(1, 32, 32, 300, 300, 3, 1);
  1554. bench_case(1, 32, 32, 400, 400, 3, 1);
  1555. bench_case(1, 32, 32, 100, 100, 3, 1);
  1556. bench_case(1, 32, 32, 80, 80, 3, 1);
  1557. bench_case(1, 32, 64, 200, 200, 3, 1);
  1558. bench_case(1, 32, 64, 128, 128, 3, 1);
  1559. bench_case(1, 32, 64, 100, 100, 3, 1);
  1560. bench_case(1, 32, 64, 80, 80, 3, 1);
  1561. bench_case(1, 32, 128, 200, 200, 3, 1);
  1562. bench_case(1, 32, 128, 128, 128, 3, 1);
  1563. bench_case(1, 32, 128, 100, 100, 3, 1);
  1564. bench_case(1, 32, 128, 80, 80, 3, 1);
  1565. bench_case(1, 64, 32, 7, 7, 3, 1);
  1566. bench_case(1, 64, 64, 7, 7, 3, 1);
  1567. bench_case(1, 64, 128, 7, 7, 3, 1);
  1568. bench_case(1, 64, 256, 7, 7, 3, 1);
  1569. bench_case(1, 64, 512, 7, 7, 3, 1);
  1570. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1571. bench_case(1, 64, 32, 14, 14, 3, 1);
  1572. bench_case(1, 64, 64, 14, 14, 3, 1);
  1573. bench_case(1, 64, 128, 14, 14, 3, 1);
  1574. bench_case(1, 64, 256, 14, 14, 3, 1);
  1575. bench_case(1, 64, 512, 14, 14, 3, 1);
  1576. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1577. bench_case(1, 128, 128, 14, 14, 3, 1);
  1578. bench_case(1, 128, 256, 14, 14, 3, 1);
  1579. bench_case(1, 512, 512, 14, 14, 3, 1);
  1580. bench_case(1, 256, 512, 14, 14, 3, 1);
  1581. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1582. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1583. std::string algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:96";
  1584. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:96\n");
  1585. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1586. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1587. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1588. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1589. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1590. {1, {4}}, data_type);
  1591. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:192";
  1592. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:192\n");
  1593. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1594. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1595. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1596. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1597. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1598. {1, {4}}, data_type);
  1599. algo_name = "IM2COLMATMUL:AARCH64_F32K8X12X1:384";
  1600. printf("Benchmark IM2COLMATMUL:AARCH64_F32K8X12X1algo:384\n");
  1601. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1602. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1603. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1604. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1605. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1606. {1, {4}}, data_type);
  1607. shapes_and_computation.clear();
  1608. }
  1609. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1610. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT8_STRIDE1) {
  1611. constexpr size_t RUNS = 50;
  1612. param::ConvBias param;
  1613. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1614. param.pad_h = 1;
  1615. param.pad_w = 1;
  1616. param.stride_h = 1;
  1617. param.stride_w = 1;
  1618. param.sparse = param::ConvBias::Sparse::GROUP;
  1619. param.format = param::ConvBias::Format::NCHW44;
  1620. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1621. shapes_and_computation;
  1622. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1623. size_t P) {
  1624. size_t group = IC;
  1625. size_t OC = IC;
  1626. size_t S = 1;
  1627. SmallVector<TensorShape> shapes{
  1628. {N, IC, H, W, 4},
  1629. {group, 1, 1, FS, FS, 4},
  1630. {1, OC, 1, 1, 4},
  1631. {},
  1632. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1633. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1634. (W + 2 * P - FS) / S + 1, 4};
  1635. float computations =
  1636. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1637. dst.total_nr_elems()) *
  1638. 1e-6;
  1639. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1640. };
  1641. bench_case(1, 128, 200, 200, 3, 1);
  1642. bench_case(1, 128, 128, 128, 3, 1);
  1643. bench_case(1, 128, 100, 100, 3, 1);
  1644. bench_case(1, 128, 80, 80, 3, 1);
  1645. bench_case(1, 128, 56, 56, 3, 1);
  1646. bench_case(1, 128, 28, 28, 3, 1);
  1647. bench_case(1, 128, 14, 14, 3, 1);
  1648. bench_case(1, 64, 200, 200, 3, 1);
  1649. bench_case(1, 64, 128, 128, 3, 1);
  1650. bench_case(1, 64, 100, 100, 3, 1);
  1651. bench_case(1, 64, 80, 80, 3, 1);
  1652. bench_case(1, 64, 56, 56, 3, 1);
  1653. bench_case(1, 64, 28, 28, 3, 1);
  1654. bench_case(1, 64, 14, 14, 3, 1);
  1655. bench_case(1, 32, 200, 200, 3, 1);
  1656. bench_case(1, 32, 128, 128, 3, 1);
  1657. bench_case(1, 32, 100, 100, 3, 1);
  1658. bench_case(1, 32, 80, 80, 3, 1);
  1659. bench_case(1, 32, 56, 56, 3, 1);
  1660. bench_case(1, 32, 28, 28, 3, 1);
  1661. bench_case(1, 32, 14, 14, 3, 1);
  1662. std::string algo_name = "S8_CHAN_WISE_STRD1_NCHW44";
  1663. printf("Benchmarker S8_CHAN_WISE_STRD1_NCHW44 algo\n");
  1664. std::vector<DType> data_type = {
  1665. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  1666. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f)};
  1667. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1668. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1669. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1670. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1671. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1672. {1, {4}}, data_type);
  1673. }
  1674. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1675. BENCHMARK_CHANNEL_WISE_INT8_INT8_INT16_STRIDE1) {
  1676. constexpr size_t RUNS = 50;
  1677. param::ConvBias param;
  1678. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1679. param.pad_h = 1;
  1680. param.pad_w = 1;
  1681. param.stride_h = 1;
  1682. param.stride_w = 1;
  1683. param.sparse = param::ConvBias::Sparse::GROUP;
  1684. param.format = param::ConvBias::Format::NCHW44;
  1685. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1686. shapes_and_computation;
  1687. auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS,
  1688. size_t P) {
  1689. size_t group = IC;
  1690. size_t OC = IC;
  1691. size_t S = 1;
  1692. SmallVector<TensorShape> shapes{
  1693. {N, IC, H, W, 4},
  1694. {group, 1, 1, FS, FS, 4},
  1695. {1, OC, 1, 1, 4},
  1696. {},
  1697. {N, OC, (H + 2 * P - FS) / S + 1, (W + 2 * P - FS) / S + 1, 4}};
  1698. TensorShape dst{N, OC, (H + 2 * P - FS) / S + 1,
  1699. (W + 2 * P - FS) / S + 1, 4};
  1700. float computations =
  1701. ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1702. dst.total_nr_elems()) *
  1703. 1e-6;
  1704. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1705. };
  1706. bench_case(1, 128, 200, 200, 3, 1);
  1707. bench_case(1, 128, 128, 128, 3, 1);
  1708. bench_case(1, 128, 100, 100, 3, 1);
  1709. bench_case(1, 128, 80, 80, 3, 1);
  1710. bench_case(1, 128, 56, 56, 3, 1);
  1711. bench_case(1, 128, 28, 28, 3, 1);
  1712. bench_case(1, 128, 14, 14, 3, 1);
  1713. bench_case(1, 64, 200, 200, 3, 1);
  1714. bench_case(1, 64, 128, 128, 3, 1);
  1715. bench_case(1, 64, 100, 100, 3, 1);
  1716. bench_case(1, 64, 80, 80, 3, 1);
  1717. bench_case(1, 64, 56, 56, 3, 1);
  1718. bench_case(1, 64, 28, 28, 3, 1);
  1719. bench_case(1, 64, 14, 14, 3, 1);
  1720. bench_case(1, 32, 200, 200, 3, 1);
  1721. bench_case(1, 32, 128, 128, 3, 1);
  1722. bench_case(1, 32, 100, 100, 3, 1);
  1723. bench_case(1, 32, 80, 80, 3, 1);
  1724. bench_case(1, 32, 56, 56, 3, 1);
  1725. bench_case(1, 32, 28, 28, 3, 1);
  1726. bench_case(1, 32, 14, 14, 3, 1);
  1727. std::string algo_name = "S8x8x16_CHAN_WISE_STRD1_STRD2_NCHW44";
  1728. printf("Benchmarker S8x8x16_CHAN_WISE_STRD1_STRD2_NCHW44 algo\n");
  1729. std::vector<DType> data_type = {dtype::Int8(), dtype::Int8(),
  1730. dtype::Int16(), dtype::Int16()};
  1731. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1732. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1733. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1734. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1735. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1736. {1, {4}}, data_type);
  1737. }
  1738. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1739. BENCHMARK_IM2COL_NCHW44_INT8x8x32_STRIDE1) {
  1740. constexpr size_t RUNS = 50;
  1741. param::ConvBias param;
  1742. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1743. param.pad_h = 1;
  1744. param.pad_w = 1;
  1745. param.stride_h = 1;
  1746. param.stride_w = 1;
  1747. param.sparse = param::ConvBias::Sparse::DENSE;
  1748. param.format = param::ConvBias::Format::NCHW44;
  1749. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1750. shapes_and_computation;
  1751. auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  1752. size_t FS, size_t group = 1) {
  1753. SmallVector<TensorShape> shapes{{N, IC, H, W, 4},
  1754. {OC, IC / group, FS, FS, 4, 4},
  1755. {/*1, OC, 1, 1*/},
  1756. {},
  1757. {N, OC, H, W, 4}};
  1758. TensorShape dst{N, OC, H, W, 4};
  1759. float computations =
  1760. ((4 * IC / group) * FS * FS * dst.total_nr_elems() * 2 +
  1761. dst.total_nr_elems()) *
  1762. 1e-6;
  1763. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1764. };
  1765. bench_case(1, 32, 32, 300, 300, 3, 1);
  1766. bench_case(1, 32, 32, 400, 400, 3, 1);
  1767. bench_case(1, 32, 32, 100, 100, 3, 1);
  1768. bench_case(1, 32, 32, 80, 80, 3, 1);
  1769. bench_case(1, 32, 64, 200, 200, 3, 1);
  1770. bench_case(1, 32, 64, 128, 128, 3, 1);
  1771. bench_case(1, 32, 64, 100, 100, 3, 1);
  1772. bench_case(1, 32, 64, 80, 80, 3, 1);
  1773. bench_case(1, 32, 128, 200, 200, 3, 1);
  1774. bench_case(1, 32, 128, 128, 128, 3, 1);
  1775. bench_case(1, 32, 128, 100, 100, 3, 1);
  1776. bench_case(1, 32, 128, 80, 80, 3, 1);
  1777. #if 1
  1778. bench_case(1, 64, 32, 7, 7, 3, 1);
  1779. bench_case(1, 64, 64, 7, 7, 3, 1);
  1780. bench_case(1, 64, 128, 7, 7, 3, 1);
  1781. bench_case(1, 64, 256, 7, 7, 3, 1);
  1782. bench_case(1, 64, 512, 7, 7, 3, 1);
  1783. bench_case(1, 64, 1024, 7, 7, 3, 1);
  1784. bench_case(1, 64, 32, 14, 14, 3, 1);
  1785. bench_case(1, 64, 64, 14, 14, 3, 1);
  1786. bench_case(1, 64, 128, 14, 14, 3, 1);
  1787. bench_case(1, 64, 256, 14, 14, 3, 1);
  1788. bench_case(1, 64, 512, 14, 14, 3, 1);
  1789. bench_case(1, 64, 1024, 14, 14, 3, 1);
  1790. bench_case(1, 128, 128, 14, 14, 3, 1);
  1791. bench_case(1, 128, 256, 14, 14, 3, 1);
  1792. bench_case(1, 512, 512, 14, 14, 3, 1);
  1793. bench_case(1, 256, 512, 14, 14, 3, 1);
  1794. bench_case(1, 512, 1024, 14, 14, 3, 1);
  1795. bench_case(1, 1024, 1024, 14, 14, 3, 1);
  1796. #endif
  1797. std::string algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96";
  1798. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96 algo\n");
  1799. std::vector<DType> data_type = {dtype::QuantizedS8(2.5f),
  1800. dtype::QuantizedS8(2.5f),
  1801. dtype::QuantizedS32(6.25f),
  1802. {}};
  1803. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1804. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1805. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1806. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1807. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1808. {1, {4}}, data_type);
  1809. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192";
  1810. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:192 "
  1811. "algo\n");
  1812. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1813. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1814. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1815. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1816. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1817. {1, {4}}, data_type);
  1818. algo_name = "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384";
  1819. printf("Benchmarker IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:384 "
  1820. "algo\n");
  1821. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1822. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1823. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1824. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1825. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1826. {1, {4}}, data_type);
  1827. }
  1828. #endif
  1829. /*================== BENCHMARK MULTITHREAD CONV1X1 =====================*/
  1830. #if MEGDNN_WITH_BENCHMARK
  1831. namespace {
  1832. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1833. get_conv1x1_multithread_benchmark_args() {
  1834. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1835. shapes_and_computation;
  1836. auto bench_case = [&](size_t IC, size_t OC, size_t H, size_t W) {
  1837. SmallVector<TensorShape> shapes{{1, IC, H, W},
  1838. {OC, IC, 1, 1},
  1839. {1, OC, 1, 1},
  1840. {},
  1841. {1, OC, H, W}};
  1842. TensorShape dst{1, OC, H, W};
  1843. float computations =
  1844. (IC * dst.total_nr_elems() * 2 + dst.total_nr_elems()) * 1e-6;
  1845. shapes_and_computation.push_back(std::make_pair(shapes, computations));
  1846. };
  1847. bench_case(32, 32, 300, 300);
  1848. bench_case(32, 32, 400, 400);
  1849. bench_case(32, 32, 100, 100);
  1850. bench_case(32, 32, 80, 80);
  1851. bench_case(32, 64, 200, 200);
  1852. bench_case(32, 64, 128, 128);
  1853. bench_case(32, 64, 100, 100);
  1854. bench_case(32, 64, 80, 80);
  1855. bench_case(32, 128, 200, 200);
  1856. bench_case(32, 128, 128, 128);
  1857. bench_case(32, 128, 100, 100);
  1858. bench_case(32, 128, 80, 80);
  1859. bench_case(64, 32, 7, 7);
  1860. bench_case(64, 64, 7, 7);
  1861. bench_case(64, 128, 7, 7);
  1862. bench_case(64, 256, 7, 7);
  1863. bench_case(64, 512, 7, 7);
  1864. bench_case(64, 1024, 7, 7);
  1865. bench_case(64, 32, 14, 14);
  1866. bench_case(64, 64, 14, 14);
  1867. bench_case(64, 128, 14, 14);
  1868. bench_case(64, 256, 14, 14);
  1869. bench_case(64, 512, 14, 14);
  1870. bench_case(64, 1024, 14, 14);
  1871. bench_case(128, 128, 14, 14);
  1872. bench_case(128, 256, 14, 14);
  1873. bench_case(512, 512, 14, 14);
  1874. bench_case(256, 512, 14, 14);
  1875. bench_case(512, 1024, 14, 14);
  1876. bench_case(1024, 1024, 14, 14);
  1877. return shapes_and_computation;
  1878. }
  1879. void conv1x1_multithread_benchmark(const char* algo_name, DType stype,
  1880. DType ftype, DType btype, DType dtype) {
  1881. constexpr size_t RUNS = 50;
  1882. std::vector<std::pair<SmallVector<TensorShape>, float>>
  1883. shapes_and_computation = get_conv1x1_multithread_benchmark_args();
  1884. std::vector<DType> data_type = {stype, ftype, btype, dtype};
  1885. param::ConvBias param;
  1886. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  1887. param.pad_h = 0;
  1888. param.pad_w = 0;
  1889. param.stride_h = 1;
  1890. param.stride_w = 1;
  1891. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1892. {4, {4, 5, 6, 7}}, {1, {4}}, data_type);
  1893. benchmark_impl(param, shapes_and_computation, algo_name, RUNS,
  1894. {4, {4, 5, 6, 7}}, {1, {7}}, data_type);
  1895. benchmark_impl(param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}},
  1896. {1, {4}}, data_type);
  1897. shapes_and_computation.clear();
  1898. }
  1899. } // namespace
  1900. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CONV1X1_S1_FP32) {
  1901. #if MEGDNN_AARCH64
  1902. conv1x1_multithread_benchmark("CONV1x1:AARCH64_F32K8X12X1:8",
  1903. dtype::Float32(), dtype::Float32(),
  1904. dtype::Float32(), dtype::Float32());
  1905. #else
  1906. conv1x1_multithread_benchmark("CONV1x1:ARMV7_F32:8", dtype::Float32(),
  1907. dtype::Float32(), dtype::Float32(),
  1908. dtype::Float32());
  1909. #endif
  1910. }
  1911. TEST_F(ARM_COMMON_BENCHMARK_MULTI_THREADS,
  1912. BENCHMARK_CONVBIAS_CONV1X1_S1_QUANTIZEDASYM) {
  1913. dtype::Quantized8Asymm stype(0.2f, 100);
  1914. dtype::Quantized8Asymm ftype(0.2f, 120);
  1915. dtype::QuantizedS32 btype(0.04f);
  1916. dtype::Quantized8Asymm dtype(1.4f, 110);
  1917. #if MEGDNN_AARCH64
  1918. #if MGB_ENABLE_DOT
  1919. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:8",
  1920. stype, ftype, btype, dtype);
  1921. #else
  1922. conv1x1_multithread_benchmark("CONV1x1:AARCH64_QUINT8_K8X8X8:8", stype,
  1923. ftype, btype, dtype);
  1924. #endif
  1925. #else
  1926. conv1x1_multithread_benchmark("CONV1x1:ARMV7_QUINT8_K4X8X8:8", stype, ftype,
  1927. btype, dtype);
  1928. #endif
  1929. }
  1930. #endif
  1931. // vim: syntax=cpp.doxygen

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