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

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

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