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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. /**
  2. * \file dnn/test/arm_common/conv_bias_multi_thread.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. std::vector<conv_bias::TestArg> get_int8_quint8_conv_bias_args(
  19. std::vector<size_t> kernel, size_t stride, bool no_pad, bool no_bias,
  20. bool no_nonlinemode) {
  21. using namespace conv_bias;
  22. using Param = param::ConvBias;
  23. using NLMode = param::ConvBias::NonlineMode;
  24. std::vector<TestArg> args;
  25. auto pack = [&](size_t n, size_t oc, size_t ic, size_t w, size_t h,
  26. size_t kernel, size_t stride, NLMode nlmode) {
  27. Param param;
  28. param.stride_h = stride;
  29. param.stride_w = stride;
  30. if (!no_pad) {
  31. param.pad_h = kernel / 2;
  32. param.pad_w = kernel / 2;
  33. } else {
  34. param.pad_h = 0;
  35. param.pad_w = 0;
  36. }
  37. param.nonlineMode = nlmode;
  38. args.emplace_back(param, TensorShape{n, ic, h, w},
  39. TensorShape{oc, ic, kernel, kernel}, TensorShape{});
  40. if (!no_bias) {
  41. args.emplace_back(param, TensorShape{n, ic, h, w},
  42. TensorShape{oc, ic, kernel, kernel},
  43. TensorShape{1, oc, 1, 1});
  44. }
  45. };
  46. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  47. if (!no_nonlinemode) {
  48. nonlinemode.emplace_back(NLMode::RELU);
  49. nonlinemode.emplace_back(NLMode::H_SWISH);
  50. }
  51. for (size_t n : {1, 2}) {
  52. for (auto nlmode : nonlinemode) {
  53. for (size_t ic : {1, 3, 7}) {
  54. for (size_t oc : {1, 3, 7}) {
  55. for (size_t size : {4, 6, 8, 14, 16, 18}) {
  56. for (size_t kern : kernel) {
  57. pack(n, oc, ic, size, size, kern, stride, nlmode);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. return args;
  65. }
  66. std::vector<conv_bias::TestArg> get_nchw44_conv_bias_args(
  67. std::vector<size_t> kernel_vec, size_t stride, bool no_pad = false,
  68. bool no_bias = false, bool no_nonlinemode = false,
  69. bool is_input_nchw = false, bool support_full_bias = false,
  70. bool support_sigmoid = false) {
  71. using namespace conv_bias;
  72. using NLMode = param::ConvBias::NonlineMode;
  73. std::vector<TestArg> args;
  74. auto pack = [&](size_t n, size_t oc, size_t ic, size_t h, size_t w,
  75. size_t kernel, size_t stride, size_t group, NLMode nlmode,
  76. megdnn::BiasMode bias_mode, int any_pad = -1) {
  77. constexpr int pack_c = 4;
  78. const size_t pad = any_pad >= 0 ? any_pad : kernel / 2;
  79. auto oc_per_group = oc / group;
  80. auto ic_per_group = ic / group;
  81. bool ok_group = (oc % group == 0 && ic % group == 0) &&
  82. oc_per_group % pack_c == 0 && oc_per_group > 0 &&
  83. ic_per_group > 0;
  84. bool nchw_disable = group > 1 || ic_per_group >= 4;
  85. bool nchw44_disable = ic_per_group % pack_c != 0;
  86. bool invalid_pad = (w + 2 * pad < kernel) || (h + 2 * pad < kernel);
  87. if (!(ok_group) || invalid_pad) {
  88. return;
  89. }
  90. if ((is_input_nchw && nchw_disable) ||
  91. (!is_input_nchw && nchw44_disable)) {
  92. return;
  93. }
  94. size_t kernel_h = kernel;
  95. size_t kernel_w = kernel;
  96. param::ConvBias param;
  97. param.format = param::ConvBias::Format::NCHW44;
  98. param.stride_h = stride;
  99. param.stride_w = stride;
  100. param.pad_h = pad;
  101. param.pad_w = pad;
  102. param.nonlineMode = nlmode;
  103. auto src_tensor_shape = TensorShape{n, ic / pack_c, h, w, pack_c};
  104. auto weight_tensor_shape = TensorShape{
  105. oc / pack_c, ic / pack_c, kernel_h, kernel_w, pack_c, pack_c};
  106. auto bias_tensor_shape = TensorShape{};
  107. if (bias_mode == megdnn::BiasMode::BROADCAST_CHANNEL_BIAS) {
  108. bias_tensor_shape = {1, oc / pack_c, 1, 1, pack_c};
  109. } else if (bias_mode == megdnn::BiasMode::BIAS) {
  110. bias_tensor_shape = {n, oc / pack_c,
  111. (h + 2 * pad - kernel) / stride + 1,
  112. (w + 2 * pad - kernel) / stride + 1, pack_c};
  113. }
  114. if (group == 1) {
  115. param.sparse = param::ConvBias::Sparse::DENSE;
  116. } else if (group > 1 && ic / group == 1 && oc / group == 1) {
  117. megdnn_assert(0, "not support channel wise");
  118. param.sparse = param::ConvBias::Sparse::GROUP;
  119. weight_tensor_shape = TensorShape{group / pack_c, 1, 1,
  120. kernel_h, kernel_w, pack_c};
  121. } else if (group > 1 && oc_per_group % pack_c == 0 && oc / group > 0 &&
  122. ic_per_group % pack_c == 0 && ic / group > 0) {
  123. param.sparse = param::ConvBias::Sparse::GROUP;
  124. weight_tensor_shape = TensorShape{group,
  125. oc_per_group / pack_c,
  126. ic_per_group / pack_c,
  127. kernel_h,
  128. kernel_w,
  129. pack_c,
  130. pack_c};
  131. }
  132. if (is_input_nchw) {
  133. src_tensor_shape = TensorShape{n, ic, h, w};
  134. weight_tensor_shape =
  135. TensorShape{oc / pack_c, kernel_h, kernel_w, ic, pack_c};
  136. }
  137. args.emplace_back(param, src_tensor_shape, weight_tensor_shape,
  138. bias_tensor_shape);
  139. };
  140. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  141. if (!no_nonlinemode) {
  142. nonlinemode.emplace_back(NLMode::RELU);
  143. nonlinemode.emplace_back(NLMode::H_SWISH);
  144. }
  145. if (support_sigmoid) {
  146. nonlinemode.emplace_back(NLMode::SIGMOID);
  147. }
  148. std::vector<megdnn::BiasMode> bias_mode = {
  149. megdnn::BiasMode::BROADCAST_CHANNEL_BIAS};
  150. if (no_bias) {
  151. bias_mode.emplace_back(megdnn::BiasMode::NO_BIAS);
  152. }
  153. if (support_full_bias) {
  154. bias_mode.emplace_back(megdnn::BiasMode::BIAS);
  155. }
  156. for (auto bias : bias_mode)
  157. for (auto nlmode : nonlinemode)
  158. for (size_t n : {1, 2})
  159. for (size_t kernel : kernel_vec)
  160. for (size_t oc : {4, 32})
  161. for (size_t ic : {1, 3, 4, 12, 32})
  162. for (size_t h : {3, 5, 12})
  163. for (size_t w : {7, 23}) {
  164. for (size_t group = 1;
  165. group <= std::min(oc, ic); ++group) {
  166. pack(n, oc, ic, h, w, kernel, stride,
  167. group, nlmode, bias);
  168. }
  169. }
  170. return args;
  171. }
  172. std::vector<conv_bias::TestArg> get_nchw44_channel_wise_args(
  173. std::vector<size_t> kernel, size_t stride, bool no_bias,
  174. bool no_nonlinemode, bool no_full_bias) {
  175. using namespace conv_bias;
  176. using Param = param::ConvBias;
  177. using NLMode = param::ConvBias::NonlineMode;
  178. std::vector<TestArg> args;
  179. auto pack = [&](size_t n, size_t group, size_t w, size_t h, size_t kernel,
  180. size_t stride, NLMode nlmode, bool pad) {
  181. Param param;
  182. param.stride_h = stride;
  183. param.stride_w = stride;
  184. if (pad) {
  185. param.pad_h = kernel / 2;
  186. param.pad_w = kernel / 2;
  187. } else {
  188. param.pad_h = 0;
  189. param.pad_w = 0;
  190. }
  191. param.nonlineMode = nlmode;
  192. param.format = param::ConvBias::Format::NCHW44;
  193. param.sparse = param::ConvBias::Sparse::GROUP;
  194. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  195. TensorShape{group, 1, 1, kernel, kernel, 4},
  196. TensorShape{});
  197. if (!no_bias) {
  198. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  199. TensorShape{group, 1, 1, kernel, kernel, 4},
  200. TensorShape{1, group, 1, 1, 4});
  201. }
  202. if (!no_full_bias) {
  203. args.emplace_back(
  204. param, TensorShape{n, group, h, w, 4},
  205. TensorShape{group, 1, 1, kernel, kernel, 4},
  206. TensorShape{n, group,
  207. (h + 2 * param.pad_w - kernel) / stride + 1,
  208. (w + 2 * param.pad_w - kernel) / stride + 1,
  209. 4});
  210. }
  211. };
  212. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  213. if (!no_nonlinemode) {
  214. nonlinemode.emplace_back(NLMode::RELU);
  215. nonlinemode.emplace_back(NLMode::H_SWISH);
  216. }
  217. for (size_t n : {1, 2}) {
  218. for (auto nlmode : nonlinemode) {
  219. for (bool pad : {true}) {
  220. for (size_t group : {1, 2, 4, 7, 128}) {
  221. for (size_t size : {4, 6, 7, 9, 15, 40}) {
  222. for (size_t kern : kernel) {
  223. pack(n, group, size, size, kern, stride, nlmode,
  224. pad);
  225. }
  226. }
  227. }
  228. }
  229. for (bool pad : {false}) {
  230. for (size_t group : {1, 2, 7, 128}) {
  231. for (size_t size : {7, 9, 15, 40}) {
  232. for (size_t kern : kernel) {
  233. pack(n, group, size, size, kern, stride, nlmode,
  234. pad);
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }
  241. return args;
  242. }
  243. void checker_conv_bias_qint8x8x8(std::vector<conv_bias::TestArg> args,
  244. Handle* handle, const char* algo_name) {
  245. Checker<ConvBias> checker(handle);
  246. checker.set_before_exec_callback(
  247. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  248. #if MEGDNN_ARMV7
  249. checker.set_epsilon(1);
  250. #endif
  251. UniformIntRNG rng{-50, 50};
  252. checker.set_dtype(0, dtype::QuantizedS8(0.41113496f))
  253. .set_dtype(1, dtype::QuantizedS8(0.01887994f))
  254. .set_dtype(2, dtype::QuantizedS32(0.41113496f * 0.01887994f))
  255. .set_dtype(4, dtype::QuantizedS8(0.49550694f))
  256. .set_rng(0, &rng)
  257. .set_rng(1, &rng)
  258. .set_rng(2, &rng);
  259. for (auto&& arg : args) {
  260. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  261. }
  262. }
  263. void checker_conv_bias_qint8x8x32(std::vector<conv_bias::TestArg> args,
  264. Handle* handle, const char* algo_name) {
  265. Checker<ConvBias> checker(handle);
  266. UniformIntRNG rng{-50, 50};
  267. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  268. .set_dtype(1, dtype::QuantizedS8(2.5f))
  269. .set_dtype(2, dtype::QuantizedS32(6.25f))
  270. .set_dtype(4, {});
  271. checker.set_before_exec_callback(
  272. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  273. for (auto&& arg : args) {
  274. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  275. }
  276. }
  277. void checker_conv_bias_quint8x8x8(std::vector<conv_bias::TestArg> args,
  278. Handle* handle, const char* algo_name) {
  279. Checker<ConvBias> checker(handle);
  280. checker.set_before_exec_callback(
  281. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  282. UniformIntRNG rng(0, 255);
  283. checker.set_dtype(0, dtype::Quantized8Asymm(0.2f, 100))
  284. .set_dtype(1, dtype::Quantized8Asymm(0.2f, 120))
  285. .set_dtype(2, dtype::QuantizedS32(0.04f))
  286. .set_dtype(4, dtype::Quantized8Asymm(1.4f, 110))
  287. .set_rng(0, &rng)
  288. .set_rng(1, &rng)
  289. .set_rng(2, &rng);
  290. for (auto&& arg : args) {
  291. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  292. }
  293. }
  294. void checker_conv_bias_quint8x8x32(std::vector<conv_bias::TestArg> args,
  295. Handle* handle, const char* algo_name) {
  296. Checker<ConvBias> checker(handle);
  297. checker.set_before_exec_callback(
  298. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  299. NormalRNG rng(128.f);
  300. checker.set_rng(0, &rng).set_rng(1, &rng);
  301. checker.set_dtype(0, dtype::Quantized8Asymm(1.2f, (uint8_t)127))
  302. .set_dtype(1, dtype::Quantized8Asymm(1.3f, (uint8_t)129))
  303. .set_dtype(2, dtype::QuantizedS32(1.2 * 1.3))
  304. .set_dtype(4, {});
  305. for (auto&& arg : args) {
  306. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  307. }
  308. }
  309. void checker_conv_bias_int8x8x32_multi(std::vector<conv_bias::TestArg> args,
  310. Handle* handle, const char* algo_name) {
  311. Checker<ConvBias> checker(handle);
  312. checker.set_before_exec_callback(
  313. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  314. checker.set_dtype(0, dtype::Int8());
  315. checker.set_dtype(1, dtype::Int8());
  316. checker.set_dtype(2, dtype::Int32());
  317. checker.set_dtype(4, dtype::Int32());
  318. for (auto&& arg : args) {
  319. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  320. }
  321. }
  322. /**********************************F32 direct************************/
  323. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_LARGE_GROUP) {
  324. check_conv_bias(
  325. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  326. handle(), "F32DIRECT_LARGE_GROUP");
  327. }
  328. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_SMALL_GROUP) {
  329. check_conv_bias(
  330. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  331. handle(), "F32DIRECT_SMALL_GROUP");
  332. }
  333. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K7) {
  334. check_conv_bias(get_nchw44_conv_bias_args({7}, 1, false, false, false,
  335. false, false, false),
  336. handle(), "F32_CONV_NCHW44_DIRECT");
  337. }
  338. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K2K3) {
  339. check_conv_bias(get_nchw44_conv_bias_args({2, 3}, 1, false, false, false,
  340. false, true, true),
  341. handle(), "F32_CONV_NCHW44_DIRECT");
  342. }
  343. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K5) {
  344. check_conv_bias(get_nchw44_conv_bias_args({5}, 1, false, false, false,
  345. false, true, true),
  346. handle(), "F32_CONV_NCHW44_DIRECT");
  347. }
  348. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S2) {
  349. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  350. false, false, true, true),
  351. handle(), "F32_CONV_NCHW44_DIRECT");
  352. }
  353. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_LARGE_GROUP) {
  354. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  355. handle(), "F32STRD1_LARGE_GROUP");
  356. }
  357. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_SMALL_GROUP) {
  358. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  359. handle(), "F32STRD1_SMALL_GROUP");
  360. }
  361. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_LARGE_GROUP) {
  362. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  363. handle(), "F32STRD2_LARGE_GROUP");
  364. }
  365. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_SMALL_GROUP) {
  366. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  367. handle(), "F32STRD2_SMALL_GROUP");
  368. }
  369. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_NCHW_NCHW44_F32) {
  370. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  371. false, true),
  372. handle(), "F32_CONV_NCHW_NCHW44");
  373. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false,
  374. false, true),
  375. handle(), "F32_CONV_NCHW_NCHW44");
  376. }
  377. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE1_FP32_NCHW44_1) {
  378. check_conv_bias(
  379. get_nchw44_channel_wise_args({2, 3}, 1, false, false, false),
  380. handle(), "F32_CHANNEL_WISE_NCHW44");
  381. }
  382. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE1_FP32_NCHW44_2) {
  383. check_conv_bias(get_nchw44_channel_wise_args({5}, 1, false, false, false),
  384. handle(), "F32_CHANNEL_WISE_NCHW44");
  385. }
  386. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE2_FP32_NCHW44) {
  387. check_conv_bias(
  388. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, false, false),
  389. handle(), "F32_CHANNEL_WISE_NCHW44");
  390. }
  391. /**********************************F16 direct************************/
  392. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  393. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_LARGE_GROUP) {
  394. NormalRNG rng(1);
  395. checker_conv_bias_f16(
  396. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  397. handle(), rng, "F16DIRECT_LARGE_GROUP", 0.03);
  398. }
  399. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_SMALL_GROUP) {
  400. NormalRNG rng(1);
  401. checker_conv_bias_f16(
  402. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  403. handle(), rng, "F16DIRECT_SMALL_GROUP", 0.03);
  404. }
  405. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_LARGE_GROUP) {
  406. NormalRNG rng(1);
  407. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  408. handle(), rng, "F16STRD1_LARGE_GROUP", 0.03);
  409. }
  410. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_SMALL_GROUP) {
  411. NormalRNG rng(1);
  412. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  413. handle(), rng, "F16STRD1_SMALL_GROUP", 0.03);
  414. }
  415. #endif
  416. /**********************************algo 8816 direct************************/
  417. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_LARGE_GROUP) {
  418. checker_conv_bias_int8x8x16(
  419. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  420. "I8816DIRECT_LARGE_GROUP");
  421. }
  422. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_SMALL_GROUP) {
  423. checker_conv_bias_int8x8x16(
  424. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  425. "I8816DIRECT_SMALL_GROUP");
  426. }
  427. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_LARGE_GROUP) {
  428. checker_conv_bias_int8x8x16(
  429. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  430. "I8816STRD2_LARGE_GROUP");
  431. }
  432. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_SMALL_GROUP) {
  433. checker_conv_bias_int8x8x16(
  434. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  435. "I8816STRD2_SMALL_GROUP");
  436. }
  437. /**********************************algo 8-8-32 direct************************/
  438. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_LARGE_GROUP) {
  439. checker_conv_bias_int8x8x32_multi(
  440. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  441. "S8STRD1_LARGE_GROUP");
  442. }
  443. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_SMALL_GROUP) {
  444. checker_conv_bias_int8x8x32_multi(
  445. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  446. "S8STRD1_SMALL_GROUP");
  447. }
  448. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_LARGE_GROUP) {
  449. checker_conv_bias_int8x8x32_multi(
  450. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  451. "S8STRD2_LARGE_GROUP");
  452. }
  453. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_SMALL_GROUP) {
  454. checker_conv_bias_int8x8x32_multi(
  455. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  456. "S8STRD2_SMALL_GROUP");
  457. }
  458. TEST_F(ARM_COMMON_MULTI_THREADS,
  459. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT1_NCHW44) {
  460. checker_conv_bias_int8x8x32_multi(
  461. get_nchw44_channel_wise_args({2, 3, 5}, 1, false, true, true),
  462. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  463. }
  464. TEST_F(ARM_COMMON_MULTI_THREADS,
  465. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT2_NCHW44) {
  466. checker_conv_bias_int8x8x32_multi(
  467. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, true, true),
  468. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  469. }
  470. /********************************qint8 direct******************************/
  471. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_LARGE_GROUP) {
  472. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  473. {2, 3, 5, 7}, 1, false, false, false),
  474. handle(), "S8STRD1_LARGE_GROUP");
  475. }
  476. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_SMALL_GROUP) {
  477. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  478. {2, 3, 5, 7}, 1, false, false, false),
  479. handle(), "S8STRD1_SMALL_GROUP");
  480. }
  481. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_LARGE_GROUP) {
  482. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  483. {2, 3, 5, 7}, 2, false, false, false),
  484. handle(), "S8STRD2_LARGE_GROUP");
  485. }
  486. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_SMALL_GROUP) {
  487. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  488. {2, 3, 5, 7}, 2, false, false, false),
  489. handle(), "S8STRD2_SMALL_GROUP");
  490. }
  491. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_NCHW44) {
  492. checker_conv_bias_qint8x8x8(
  493. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  494. handle(), "S8_NCHW44_DIRECT_STRD1");
  495. }
  496. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_NCHW44) {
  497. checker_conv_bias_qint8x8x8(
  498. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  499. handle(), "S8_NCHW44_DIRECT_STRD2");
  500. }
  501. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT1_NCHW44) {
  502. checker_conv_bias_qint8x8x8(
  503. get_nchw44_channel_wise_args({2, 3, 5}, 1, false, false, true),
  504. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  505. }
  506. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT2_NCHW44) {
  507. checker_conv_bias_qint8x8x8(
  508. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, false, true),
  509. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  510. }
  511. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_NCHW_NCHW44) {
  512. checker_conv_bias_qint8x8x8(
  513. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false,
  514. true),
  515. handle(), "S8_CONV_NCHW_NCHW44");
  516. checker_conv_bias_qint8x8x8(
  517. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false,
  518. true),
  519. handle(), "S8_CONV_NCHW_NCHW44");
  520. }
  521. /*****************************quint8 direct****************************/
  522. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_LARGE_GROUP) {
  523. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  524. {2, 3, 5, 7}, 1, false, false, false),
  525. handle(), "QU8STRD1_LARGE_GROUP");
  526. }
  527. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_SMALL_GROUP) {
  528. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  529. {2, 3, 5, 7}, 1, false, false, false),
  530. handle(), "QU8STRD1_SMALL_GROUP");
  531. }
  532. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_LARGE_GROUP) {
  533. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  534. {2, 3, 5, 7}, 2, false, false, false),
  535. handle(), "QU8STRD2_LARGE_GROUP");
  536. }
  537. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_SMALL_GROUP) {
  538. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  539. {2, 3, 5, 7}, 2, false, false, false),
  540. handle(), "QU8STRD2_SMALL_GROUP");
  541. }
  542. /****************************dot qint8 direct*************************/
  543. #if __ARM_FEATURE_DOTPROD
  544. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_DOT_NCHW_NCHW44) {
  545. checker_conv_bias_qint8x8x8(
  546. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false,
  547. true),
  548. handle(), "ARMDOTS8_NCHW_NCHW44");
  549. checker_conv_bias_qint8x8x8(
  550. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false,
  551. true),
  552. handle(), "ARMDOTS8_NCHW_NCHW44");
  553. }
  554. TEST_F(ARM_COMMON_MULTI_THREADS,
  555. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  556. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  557. {2, 3, 5, 7}, 1, false, false, false),
  558. handle(), "ARMDOTS8STRD1_LARGE_GROUP");
  559. }
  560. TEST_F(ARM_COMMON_MULTI_THREADS,
  561. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  562. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  563. {2, 3, 5, 7}, 1, false, false, false),
  564. handle(), "ARMDOTS8STRD1_SMALL_GROUP");
  565. }
  566. TEST_F(ARM_COMMON_MULTI_THREADS,
  567. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  568. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  569. {2, 3, 5, 7}, 2, false, false, false),
  570. handle(), "ARMDOTS8STRD2_LARGE_GROUP");
  571. }
  572. TEST_F(ARM_COMMON_MULTI_THREADS,
  573. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  574. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  575. {2, 3, 5, 7}, 2, false, false, false),
  576. handle(), "ARMDOTS8STRD2_SMALL_GROUP");
  577. }
  578. /****************************dot 8-8-32 direct*************************/
  579. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_LARGE_GROUP) {
  580. checker_conv_bias_qint8x8x32(
  581. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  582. "ARMDOTS8STRD1_LARGE_GROUP");
  583. }
  584. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_SMALL_GROUP) {
  585. checker_conv_bias_qint8x8x32(
  586. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  587. "ARMDOTS8STRD1_SMALL_GROUP");
  588. }
  589. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_LARGE_GROUP) {
  590. checker_conv_bias_qint8x8x32(
  591. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  592. "ARMDOTS8STRD2_LARGE_GROUP");
  593. }
  594. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_SMALL_GROUP) {
  595. checker_conv_bias_qint8x8x32(
  596. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  597. "ARMDOTS8STRD2_SMALL_GROUP");
  598. }
  599. /******************************dot quint8*****************************/
  600. TEST_F(ARM_COMMON_MULTI_THREADS,
  601. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  602. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  603. {2, 3, 5, 7}, 1, false, false, false),
  604. handle(), "ARMDOTU8STRD1_LARGE_GROUP");
  605. }
  606. TEST_F(ARM_COMMON_MULTI_THREADS,
  607. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  608. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  609. {2, 3, 5, 7}, 1, false, false, false),
  610. handle(), "ARMDOTU8STRD1_SMALL_GROUP");
  611. }
  612. TEST_F(ARM_COMMON_MULTI_THREADS,
  613. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  614. checker_conv_bias_quint8x8x8(
  615. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  616. handle(), "ARMDOTU8STRD2_LARGE_GROUP");
  617. }
  618. TEST_F(ARM_COMMON_MULTI_THREADS,
  619. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  620. checker_conv_bias_quint8x8x8(
  621. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  622. handle(), "ARMDOTU8STRD2_SMALL_GROUP");
  623. }
  624. /******************************dot quint8x8x32***********************/
  625. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_LARGE_GROUP) {
  626. checker_conv_bias_quint8x8x32(
  627. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  628. "ARMDOTU8STRD1_LARGE_GROUP");
  629. }
  630. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_SMALL_GROUP) {
  631. checker_conv_bias_quint8x8x32(
  632. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  633. "ARMDOTU8STRD1_SMALL_GROUP");
  634. }
  635. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_LARGE_GROUP) {
  636. checker_conv_bias_quint8x8x32(
  637. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  638. "ARMDOTU8STRD2_LARGE_GROUP");
  639. }
  640. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_SMALL_GROUP) {
  641. checker_conv_bias_quint8x8x32(
  642. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  643. "ARMDOTU8STRD2_SMALL_GROUP");
  644. }
  645. /******************************dot int8x8x8 nchw44 ***********************/
  646. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x8) {
  647. using namespace conv_bias;
  648. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 1);
  649. for (auto&& arg : args)
  650. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  651. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  652. }
  653. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x32) {
  654. using namespace conv_bias;
  655. std::vector<TestArg> args =
  656. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  657. for (auto&& arg : args)
  658. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  659. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  660. }
  661. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_8x8x32) {
  662. using namespace conv_bias;
  663. std::vector<TestArg> args =
  664. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  665. for (auto&& arg : args)
  666. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  667. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  668. }
  669. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x8) {
  670. using namespace conv_bias;
  671. //! test qint8x8x8
  672. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 2);
  673. for (auto&& arg : args)
  674. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  675. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  676. }
  677. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x32) {
  678. using namespace conv_bias;
  679. //! test qint8x8x8
  680. std::vector<TestArg> args =
  681. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  682. for (auto&& arg : args)
  683. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  684. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  685. }
  686. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_8x8x32) {
  687. using namespace conv_bias;
  688. //! test qint8x8x8
  689. std::vector<TestArg> args =
  690. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  691. for (auto&& arg : args)
  692. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  693. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  694. }
  695. #endif
  696. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4) {
  697. using namespace conv_bias;
  698. std::vector<TestArg> args = get_winograd_mk_packed_args();
  699. Checker<ConvBiasForward> checker(handle());
  700. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  701. }
  702. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4_NCHW44) {
  703. using namespace conv_bias;
  704. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  705. Checker<ConvBiasForward> checker(handle());
  706. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  707. param::ConvBias::Format::NCHW44);
  708. }
  709. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63) {
  710. using namespace conv_bias;
  711. std::vector<TestArg> args = get_winograd_args(3);
  712. Checker<ConvBiasForward> checker(handle());
  713. check_winograd("1:6:32", checker, args);
  714. }
  715. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4) {
  716. using namespace conv_bias;
  717. std::vector<TestArg> args = get_winograd_mk_packed_args();
  718. Checker<ConvBiasForward> checker(handle());
  719. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  720. }
  721. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_NCHW44) {
  722. using namespace conv_bias;
  723. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  724. Checker<ConvBiasForward> checker(handle());
  725. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  726. param::ConvBias::Format::NCHW44);
  727. }
  728. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  729. using namespace conv_bias;
  730. std::vector<TestArg> args = get_winograd_args(4);
  731. Checker<ConvBiasForward> checker(handle());
  732. check_winograd("1:5:32", checker, args);
  733. }
  734. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  735. using namespace conv_bias;
  736. std::vector<TestArg> args = get_winograd_args(5);
  737. Checker<ConvBiasForward> checker(handle());
  738. check_winograd("1:4:32", checker, args);
  739. }
  740. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  741. using namespace conv_bias;
  742. std::vector<TestArg> args = get_winograd_args(3);
  743. Checker<ConvBiasForward> checker(handle());
  744. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  745. param::ConvBias param, Handle* handle) {
  746. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  747. auto winograd_preprocess_opr =
  748. handle->create_operator<WinogradFilterPreprocess>();
  749. winograd_preprocess_opr->param().output_block_size = m;
  750. TensorLayout filter_transform_layout;
  751. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  752. filter_transform_layout);
  753. size_t winograd_preprocess_workspace_in_bytes =
  754. winograd_preprocess_opr->get_workspace_in_bytes(
  755. tensors[1].layout, filter_transform_layout);
  756. auto conv_bias_opr = handle->create_operator<ConvBias>();
  757. conv_bias_opr->param() = param;
  758. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  759. conv_bias_opr->param().output_block_size = m;
  760. size_t conv_bias_workspace_in_bytes =
  761. conv_bias_opr->get_workspace_in_bytes(
  762. tensors[0].layout, filter_transform_layout,
  763. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  764. nullptr);
  765. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  766. conv_bias_workspace_in_bytes,
  767. winograd_preprocess_workspace_in_bytes});
  768. wb.set(malloc(wb.total_size_in_bytes()));
  769. TensorND filter_transform_tensor(wb.get(0),
  770. std::move(filter_transform_layout));
  771. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  772. wb.get_workspace(2));
  773. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  774. tensors[3], tensors[4], nullptr,
  775. wb.get_workspace(1));
  776. free(wb.ptr());
  777. };
  778. auto run = [&checker, &extra_impl](
  779. Handle* handle, const std::vector<TestArg>& args,
  780. const std::vector<size_t>& out_size, DType A_dtype,
  781. DType B_dtype, DType C_dtype, DType D_dtype,
  782. const float eps) {
  783. for (auto&& arg : args) {
  784. for (uint32_t m : out_size) {
  785. checker.set_extra_opr_impl(std::bind(extra_impl,
  786. std::placeholders::_1, m,
  787. arg.param, handle));
  788. checker.set_dtype(0, A_dtype)
  789. .set_dtype(1, B_dtype)
  790. .set_dtype(2, C_dtype)
  791. .set_dtype(4, D_dtype)
  792. .set_epsilon(eps)
  793. .set_param(arg.param)
  794. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  795. }
  796. }
  797. };
  798. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  799. dtype::Float32(), dtype::Float32(), 1e-3f);
  800. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  801. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  802. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  803. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  804. dtype::Float16(), dtype::Float16(), 0.35f);
  805. #endif
  806. }
  807. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_PREPROCESS_NCHW44) {
  808. using namespace conv_bias;
  809. std::vector<TestArg> nchw44_args = get_nchw44_conv_bias_args({3}, 1);
  810. Checker<ConvBiasForward> checker(handle());
  811. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  812. param::ConvBias param, Handle* handle) {
  813. megdnn_assert(param.format == param::ConvBias::Format::NCHW44);
  814. auto winograd_preprocess_opr =
  815. handle->create_operator<WinogradFilterPreprocess>();
  816. winograd_preprocess_opr->param().output_block_size = m;
  817. winograd_preprocess_opr->param().format = param::MatrixMul::Format::MK4;
  818. TensorLayout filter_transform_layout;
  819. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  820. filter_transform_layout);
  821. size_t winograd_preprocess_workspace_in_bytes =
  822. winograd_preprocess_opr->get_workspace_in_bytes(
  823. tensors[1].layout, filter_transform_layout);
  824. auto conv_bias_opr = handle->create_operator<ConvBias>();
  825. conv_bias_opr->param() = param;
  826. conv_bias_opr->param().format =
  827. param::ConvBias::Format::NCHW44_WINOGRAD;
  828. conv_bias_opr->param().output_block_size = m;
  829. size_t conv_bias_workspace_in_bytes =
  830. conv_bias_opr->get_workspace_in_bytes(
  831. tensors[0].layout, filter_transform_layout,
  832. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  833. nullptr);
  834. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  835. conv_bias_workspace_in_bytes,
  836. winograd_preprocess_workspace_in_bytes});
  837. wb.set(malloc(wb.total_size_in_bytes()));
  838. TensorND filter_transform_tensor(wb.get(0),
  839. std::move(filter_transform_layout));
  840. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  841. wb.get_workspace(2));
  842. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  843. tensors[3], tensors[4], nullptr,
  844. wb.get_workspace(1));
  845. free(wb.ptr());
  846. };
  847. auto run = [&checker, &extra_impl](
  848. Handle* handle, const std::vector<TestArg>& args,
  849. const std::vector<size_t>& out_size, DType A_dtype,
  850. DType B_dtype, DType C_dtype, DType D_dtype,
  851. const float eps) {
  852. for (auto&& arg : args) {
  853. for (uint32_t m : out_size) {
  854. checker.set_extra_opr_impl(std::bind(extra_impl,
  855. std::placeholders::_1, m,
  856. arg.param, handle));
  857. checker.set_dtype(0, A_dtype)
  858. .set_dtype(1, B_dtype)
  859. .set_dtype(2, C_dtype)
  860. .set_dtype(4, D_dtype)
  861. .set_epsilon(eps)
  862. .set_param(arg.param)
  863. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  864. }
  865. }
  866. };
  867. run(handle(), nchw44_args, {2, 6}, dtype::Float32(), dtype::Float32(),
  868. dtype::Float32(), dtype::Float32(), 1e-3f);
  869. }
  870. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  871. using namespace conv_bias;
  872. Checker<ConvBiasForward> checker(handle());
  873. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  874. const std::vector<size_t>& out_size, DType A_dtype,
  875. DType B_dtype, DType C_dtype, DType D_dtype,
  876. param::MatrixMul::Format format, float eps) {
  877. for (auto&& arg : args) {
  878. for (uint32_t m : out_size) {
  879. checker.set_extra_opr_impl(std::bind(
  880. winograd_algo_extra_impl, std::placeholders::_1, m,
  881. arg.param, handle, format));
  882. checker.set_dtype(0, A_dtype)
  883. .set_dtype(1, B_dtype)
  884. .set_dtype(2, C_dtype)
  885. .set_dtype(4, D_dtype)
  886. .set_epsilon(eps)
  887. .set_param(arg.param)
  888. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  889. }
  890. }
  891. };
  892. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  893. std::vector<TestArg> args_first_half(args.begin(),
  894. args.begin() + args.size() / 2);
  895. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  896. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  897. 1e-3f);
  898. }
  899. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  900. using namespace conv_bias;
  901. Checker<ConvBiasForward> checker(handle());
  902. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  903. const std::vector<size_t>& out_size, DType A_dtype,
  904. DType B_dtype, DType C_dtype, DType D_dtype,
  905. param::MatrixMul::Format format, float eps) {
  906. for (auto&& arg : args) {
  907. for (uint32_t m : out_size) {
  908. checker.set_extra_opr_impl(std::bind(
  909. winograd_algo_extra_impl, std::placeholders::_1, m,
  910. arg.param, handle, format));
  911. checker.set_dtype(0, A_dtype)
  912. .set_dtype(1, B_dtype)
  913. .set_dtype(2, C_dtype)
  914. .set_dtype(4, D_dtype)
  915. .set_epsilon(eps)
  916. .set_param(arg.param)
  917. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  918. }
  919. }
  920. };
  921. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  922. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  923. args.end());
  924. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  925. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  926. 1e-3f);
  927. }
  928. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  929. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  930. using namespace conv_bias;
  931. Checker<ConvBiasForward> checker(handle());
  932. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  933. const std::vector<size_t>& out_size, DType A_dtype,
  934. DType B_dtype, DType C_dtype, DType D_dtype,
  935. param::MatrixMul::Format format, float eps) {
  936. for (auto&& arg : args) {
  937. for (uint32_t m : out_size) {
  938. checker.set_extra_opr_impl(std::bind(
  939. winograd_algo_extra_impl, std::placeholders::_1, m,
  940. arg.param, handle, format));
  941. checker.set_dtype(0, A_dtype)
  942. .set_dtype(1, B_dtype)
  943. .set_dtype(2, C_dtype)
  944. .set_dtype(4, D_dtype)
  945. .set_epsilon(eps)
  946. .set_param(arg.param)
  947. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  948. }
  949. }
  950. };
  951. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  952. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  953. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  954. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  955. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  956. 0.25);
  957. }
  958. #endif
  959. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  960. using namespace conv_bias;
  961. Checker<ConvBiasForward> checker(handle());
  962. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  963. const std::vector<size_t>& out_size, DType A_dtype,
  964. DType B_dtype, DType C_dtype, DType D_dtype,
  965. param::MatrixMul::Format format, float eps) {
  966. for (auto&& arg : args) {
  967. for (uint32_t m : out_size) {
  968. checker.set_extra_opr_impl(std::bind(
  969. winograd_algo_extra_impl, std::placeholders::_1, m,
  970. arg.param, handle, format));
  971. checker.set_dtype(0, A_dtype)
  972. .set_dtype(1, B_dtype)
  973. .set_dtype(2, C_dtype)
  974. .set_dtype(4, D_dtype)
  975. .set_epsilon(eps)
  976. .set_param(arg.param)
  977. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  978. }
  979. }
  980. };
  981. #if MEGDNN_AARCH64
  982. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  983. #else
  984. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  985. #endif
  986. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  987. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  988. std::vector<TestArg> quantized_args =
  989. get_quantized_winograd_mk_packed_args(8);
  990. UniformIntRNG int_rng{-50, 50};
  991. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  992. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  993. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  994. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  995. }
  996. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8) {
  997. using namespace conv_bias;
  998. Checker<ConvBiasForward> checker(handle());
  999. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1000. const std::vector<size_t>& out_size, DType A_dtype,
  1001. DType B_dtype, DType C_dtype, DType D_dtype,
  1002. param::MatrixMul::Format format, float eps) {
  1003. for (auto&& arg : args) {
  1004. for (uint32_t m : out_size) {
  1005. checker.set_extra_opr_impl(std::bind(
  1006. winograd_algo_extra_impl, std::placeholders::_1, m,
  1007. arg.param, handle, format));
  1008. checker.set_dtype(0, A_dtype)
  1009. .set_dtype(1, B_dtype)
  1010. .set_dtype(2, C_dtype)
  1011. .set_dtype(4, D_dtype)
  1012. .set_epsilon(eps)
  1013. .set_param(arg.param)
  1014. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1015. }
  1016. }
  1017. };
  1018. #if MEGDNN_AARCH64
  1019. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1020. #else
  1021. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1022. #endif
  1023. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1024. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1025. std::vector<TestArg> quantized_args = get_int8_nchw44_args (3,4);
  1026. UniformIntRNG int_rng{-50, 50};
  1027. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1028. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1029. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1030. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1031. }
  1032. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE) {
  1033. using namespace conv_bias;
  1034. Checker<ConvBiasForward> checker(handle());
  1035. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1036. const std::vector<size_t>& out_size, DType A_dtype,
  1037. DType B_dtype, DType C_dtype, DType D_dtype,
  1038. param::MatrixMul::Format format, float eps) {
  1039. for (auto&& arg : args) {
  1040. for (uint32_t m : out_size) {
  1041. checker.set_extra_opr_impl(std::bind(
  1042. winograd_algo_extra_impl, std::placeholders::_1, m,
  1043. arg.param, handle, format));
  1044. checker.set_dtype(0, A_dtype)
  1045. .set_dtype(1, B_dtype)
  1046. .set_dtype(2, C_dtype)
  1047. .set_dtype(4, D_dtype)
  1048. .set_epsilon(eps)
  1049. .set_param(arg.param)
  1050. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1051. }
  1052. }
  1053. };
  1054. #if MEGDNN_AARCH64
  1055. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1056. #else
  1057. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1058. #endif
  1059. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1060. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1061. std::vector<TestArg> quantized_args =
  1062. get_int8_nchw44_args(3, 4, false, true);
  1063. UniformIntRNG int_rng{-50, 50};
  1064. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1065. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1066. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1067. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1068. }
  1069. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32) {
  1070. using namespace conv_bias;
  1071. Checker<ConvBiasForward> checker(handle());
  1072. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1073. const std::vector<size_t>& out_size, DType A_dtype,
  1074. DType B_dtype, DType C_dtype, DType D_dtype,
  1075. param::MatrixMul::Format format, float eps) {
  1076. for (auto&& arg : args) {
  1077. for (uint32_t m : out_size) {
  1078. checker.set_extra_opr_impl(std::bind(
  1079. winograd_algo_extra_impl, std::placeholders::_1, m,
  1080. arg.param, handle, format));
  1081. checker.set_dtype(0, A_dtype)
  1082. .set_dtype(1, B_dtype)
  1083. .set_dtype(2, C_dtype)
  1084. .set_dtype(4, D_dtype)
  1085. .set_epsilon(eps)
  1086. .set_param(arg.param)
  1087. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1088. }
  1089. }
  1090. };
  1091. float epsilon = 0.001;
  1092. #if MEGDNN_AARCH64
  1093. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1094. #else
  1095. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1096. #endif
  1097. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1098. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1099. std::vector<TestArg> quantized_args =
  1100. get_int8_nchw44_args(3, 4, true);
  1101. UniformIntRNG int_rng{-50, 50};
  1102. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1103. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1104. dtype::QuantizedS8(0.01887994f),
  1105. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1106. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4, epsilon);
  1107. }
  1108. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE) {
  1109. using namespace conv_bias;
  1110. Checker<ConvBiasForward> checker(handle());
  1111. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1112. const std::vector<size_t>& out_size, DType A_dtype,
  1113. DType B_dtype, DType C_dtype, DType D_dtype,
  1114. param::MatrixMul::Format format, float eps) {
  1115. for (auto&& arg : args) {
  1116. for (uint32_t m : out_size) {
  1117. checker.set_extra_opr_impl(std::bind(
  1118. winograd_algo_extra_impl, std::placeholders::_1, m,
  1119. arg.param, handle, format));
  1120. checker.set_dtype(0, A_dtype)
  1121. .set_dtype(1, B_dtype)
  1122. .set_dtype(2, C_dtype)
  1123. .set_dtype(4, D_dtype)
  1124. .set_epsilon(eps)
  1125. .set_param(arg.param)
  1126. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1127. }
  1128. }
  1129. };
  1130. float epsilon = 0.001;
  1131. #if MEGDNN_AARCH64
  1132. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1133. #else
  1134. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1135. #endif
  1136. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1137. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1138. std::vector<TestArg> quantized_args =
  1139. get_int8_nchw44_args(3, 4, true, true);
  1140. UniformIntRNG int_rng{-50, 50};
  1141. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1142. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1143. dtype::QuantizedS8(0.01887994f),
  1144. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1145. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4, epsilon);
  1146. }
  1147. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1148. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  1149. using namespace conv_bias;
  1150. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1151. Checker<ConvBiasForward> checker(handle());
  1152. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1153. }
  1154. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  1155. using namespace conv_bias;
  1156. std::vector<TestArg> args = get_winograd_args(5);
  1157. std::vector<TestArg> args_head_half(args.begin(),
  1158. args.begin() + args.size() / 2);
  1159. Checker<ConvBiasForward> checker(handle());
  1160. //! fp16 range -1.0 ~ 1.0
  1161. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1162. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1163. }
  1164. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  1165. using namespace conv_bias;
  1166. std::vector<TestArg> args = get_winograd_args(5);
  1167. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1168. args.end());
  1169. Checker<ConvBiasForward> checker(handle());
  1170. //! fp16 range -1.0 ~ 1.0
  1171. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1172. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1173. }
  1174. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1175. //! it will pass when run single testcase
  1176. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  1177. using namespace conv_bias;
  1178. std::vector<TestArg> args = get_winograd_args(3);
  1179. Checker<ConvBiasForward> checker(handle());
  1180. //! fp16 range -1.0 ~ 1.0
  1181. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1182. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1183. }
  1184. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  1185. using namespace conv_bias;
  1186. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1187. std::vector<TestArg> args_head_half(args.begin(),
  1188. args.begin() + args.size() / 2);
  1189. Checker<ConvBiasForward> checker(handle());
  1190. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1191. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1192. param::MatrixMul::Format::MK8);
  1193. }
  1194. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  1195. using namespace conv_bias;
  1196. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1197. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1198. args.end());
  1199. Checker<ConvBiasForward> checker(handle());
  1200. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1201. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1202. param::MatrixMul::Format::MK8);
  1203. }
  1204. #endif
  1205. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  1206. using namespace conv_bias;
  1207. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1208. Checker<ConvBiasForward> checker(handle());
  1209. UniformIntRNG rng{-50, 50};
  1210. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1211. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1212. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1213. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1214. .set_rng(0, &rng)
  1215. .set_rng(1, &rng)
  1216. .set_rng(2, &rng);
  1217. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1218. }
  1219. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  1220. RNG* rng, float epsilon, DType type0, DType type1,
  1221. DType type2, DType type3, const char* algo_name) {
  1222. using namespace conv_bias;
  1223. Checker<ConvBias> checker(handle);
  1224. checker.set_before_exec_callback(
  1225. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1226. checker.set_dtype(0, type0);
  1227. checker.set_dtype(1, type1);
  1228. checker.set_dtype(2, type2);
  1229. checker.set_dtype(4, type3);
  1230. checker.set_epsilon(epsilon);
  1231. if (NULL != rng) {
  1232. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  1233. }
  1234. for (auto&& arg : args) {
  1235. checker.set_param(arg.param).execs(
  1236. {arg.src, arg.filter, arg.bias, {}, {}});
  1237. }
  1238. }
  1239. // clang-format off
  1240. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  1241. #define cb(name) \
  1242. check_conv_bias( \
  1243. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1244. handle(), name);
  1245. #if MEGDNN_AARCH64
  1246. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1247. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1248. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1249. #elif MEGDNN_ARMV7
  1250. cb("IM2COLMATMUL:ARMV7_F32")
  1251. #endif
  1252. #undef cb
  1253. }
  1254. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  1255. #define cb(name) \
  1256. check_conv_bias( \
  1257. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1258. handle(), name);
  1259. #if MEGDNN_AARCH64
  1260. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1261. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1262. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1263. #elif MEGDNN_ARMV7
  1264. cb("IM2COLMATMUL:ARMV7_F32")
  1265. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1266. #endif
  1267. #undef cb
  1268. }
  1269. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  1270. UniformIntRNG rng{-50, 50};
  1271. #define cb(name) \
  1272. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1273. false, true, true), \
  1274. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1275. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1276. dtype::QuantizedS8(60.25f), name); \
  1277. checker_conv_bias( \
  1278. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1279. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1280. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1281. dtype::QuantizedS8(60.25f), name);
  1282. float epsilon = 0.001;
  1283. #if MEGDNN_AARCH64
  1284. #if __ARM_FEATURE_DOTPROD
  1285. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1286. #else
  1287. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1288. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1289. #endif
  1290. #elif MEGDNN_ARMV7
  1291. epsilon = 1;
  1292. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1293. #endif
  1294. #undef cb
  1295. }
  1296. // clang-format on
  1297. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1298. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  1299. NormalRNG rng(128.f);
  1300. #define cb(name) \
  1301. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1302. false, true, true), \
  1303. handle(), &rng, epsilon, \
  1304. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1305. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1306. dtype::QuantizedS32(1.2 * 1.3), \
  1307. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1308. checker_conv_bias( \
  1309. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1310. handle(), &rng, epsilon, \
  1311. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1312. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1313. dtype::QuantizedS32(1.2 * 1.3), \
  1314. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1315. float epsilon = 0.001;
  1316. #if MEGDNN_AARCH64
  1317. #if __ARM_FEATURE_DOTPROD
  1318. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1319. #else
  1320. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1321. #endif
  1322. #elif MEGDNN_ARMV7
  1323. epsilon = 1;
  1324. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1325. #endif
  1326. #undef cb
  1327. }
  1328. #endif
  1329. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1330. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  1331. UniformIntRNG rng{-50, 50};
  1332. float epsilon = 0.001;
  1333. #define cb(name) \
  1334. checker_conv_bias( \
  1335. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1336. handle(), &rng, epsilon, \
  1337. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1338. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1339. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1340. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1341. &rng, epsilon, \
  1342. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1343. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1344. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1345. #if MEGDNN_AARCH64
  1346. #if __ARM_FEATURE_DOTPROD
  1347. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1348. #else
  1349. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1350. #endif
  1351. #elif MEGDNN_ARMV7
  1352. #if __ARM_FEATURE_DOTPROD
  1353. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1354. #endif
  1355. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1356. #endif
  1357. #undef cb
  1358. }
  1359. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  1360. UniformIntRNG rng{-50, 50};
  1361. float epsilon = 0.001;
  1362. #define cb(name) \
  1363. checker_conv_bias( \
  1364. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1365. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1366. dtype::Int16{}, dtype::Int16{}, name); \
  1367. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1368. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1369. dtype::Int16{}, dtype::Int16{}, name);
  1370. #if MEGDNN_AARCH64
  1371. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  1372. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  1373. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1374. #elif MEGDNN_ARMV7
  1375. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1376. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  1377. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  1378. #endif
  1379. #undef cb
  1380. }
  1381. #endif
  1382. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1383. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  1384. using namespace conv_bias;
  1385. param::ConvBias cur_param;
  1386. std::vector<conv_bias::TestArg> args =
  1387. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  1388. std::vector<conv_bias::TestArg> args1 =
  1389. get_conv_bias_args({1}, 2, false, false, false);
  1390. args.insert(args.begin(), args1.begin(), args1.end());
  1391. NormalRNG rng(1);
  1392. #define cb(name) \
  1393. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  1394. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  1395. name);
  1396. #if MEGDNN_AARCH64
  1397. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  1398. #elif MEGDNN_ARMV7
  1399. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  1400. #endif
  1401. #undef cb
  1402. }
  1403. #endif
  1404. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  1405. Handle* handle, const char* algo_name) {
  1406. using namespace conv_bias;
  1407. Checker<ConvBias> checker(handle);
  1408. checker.set_before_exec_callback(
  1409. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1410. checker.set_dtype(0, dtype::Int8());
  1411. checker.set_dtype(1, dtype::Int8());
  1412. checker.set_dtype(2, dtype::Int32());
  1413. checker.set_dtype(4, dtype::Int32());
  1414. for (auto&& arg : args) {
  1415. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  1416. }
  1417. UniformIntRNG rng{-50, 50};
  1418. for (auto&& arg : args) {
  1419. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1420. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1421. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1422. .set_dtype(4, {})
  1423. .set_rng(0, &rng)
  1424. .set_rng(1, &rng)
  1425. .set_rng(2, &rng)
  1426. .set_param(arg.param)
  1427. .execs({arg.src, arg.filter, {}, {}, {}});
  1428. }
  1429. }
  1430. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1431. #if !__ARM_FEATURE_DOTPROD
  1432. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  1433. using namespace conv_bias;
  1434. std::vector<conv_bias::TestArg> args =
  1435. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  1436. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1437. #if MEGDNN_AARCH64
  1438. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1439. #else
  1440. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1441. #endif
  1442. #undef cb
  1443. }
  1444. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  1445. using namespace conv_bias;
  1446. std::vector<conv_bias::TestArg> args =
  1447. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  1448. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1449. #if MEGDNN_AARCH64
  1450. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1451. #else
  1452. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1453. #endif
  1454. #undef cb
  1455. }
  1456. TEST_F(ARM_COMMON_MULTI_THREADS,
  1457. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  1458. UniformIntRNG rng{-50, 50};
  1459. #define cb(name) \
  1460. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  1461. epsilon, dtype::QuantizedS8(2.5f), \
  1462. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1463. dtype::QuantizedS8(60.25f), name);
  1464. float epsilon = 0.001;
  1465. #if MEGDNN_AARCH64
  1466. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1467. #else
  1468. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1469. #endif
  1470. #undef cb
  1471. }
  1472. TEST_F(ARM_COMMON_MULTI_THREADS,
  1473. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  1474. UniformIntRNG rng{-50, 50};
  1475. #define cb(name) \
  1476. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  1477. epsilon, dtype::QuantizedS8(2.5f), \
  1478. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1479. dtype::QuantizedS8(60.25f), name);
  1480. float epsilon = 0.001;
  1481. #if MEGDNN_AARCH64
  1482. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1483. #else
  1484. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1485. #endif
  1486. #undef cb
  1487. }
  1488. #if MEGDNN_AARCH64
  1489. TEST_F(ARM_COMMON_MULTI_THREADS,
  1490. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  1491. UniformIntRNG rng{-50, 50};
  1492. #define cb(name) \
  1493. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  1494. epsilon, dtype::QuantizedS8(2.5f), \
  1495. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1496. dtype::QuantizedS8(60.25f), name);
  1497. float epsilon = 0.001;
  1498. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1499. #undef cb
  1500. }
  1501. #endif
  1502. #endif
  1503. #endif
  1504. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  1505. using namespace conv_bias;
  1506. std::vector<conv_bias::TestArg> args =
  1507. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  1508. std::vector<conv_bias::TestArg> args1 =
  1509. get_conv_bias_args({1}, 2, false, true, true);
  1510. args.insert(args.begin(), args1.begin(), args1.end());
  1511. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1512. #if MEGDNN_AARCH64
  1513. #if __ARM_FEATURE_DOTPROD
  1514. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1515. #else
  1516. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1517. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1518. #endif
  1519. #elif MEGDNN_ARMV7
  1520. #if __ARM_FEATURE_DOTPROD
  1521. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  1522. #endif
  1523. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1524. #endif
  1525. #if MEGDNN_ARMV7
  1526. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  1527. #endif
  1528. #undef cb
  1529. }
  1530. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  1531. using namespace conv_bias;
  1532. std::vector<conv_bias::TestArg> args =
  1533. get_nchw44_conv_bias_args({2, 4, 7}, 1);
  1534. #if MEGDNN_AARCH64
  1535. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  1536. #elif MEGDNN_ARMV7
  1537. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  1538. #endif
  1539. }
  1540. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  1541. using namespace conv_bias;
  1542. std::vector<conv_bias::TestArg> args =
  1543. get_nchw44_conv_bias_args({3, 5, 6}, 2);
  1544. #if MEGDNN_AARCH64
  1545. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  1546. #elif MEGDNN_ARMV7
  1547. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  1548. #endif
  1549. }
  1550. /***************************** Conv1x1 Algo Test ***********************/
  1551. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  1552. using namespace conv_bias;
  1553. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1554. #if MEGDNN_AARCH64
  1555. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  1556. #elif MEGDNN_ARMV7
  1557. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  1558. #endif
  1559. }
  1560. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  1561. using namespace conv_bias;
  1562. std::vector<conv_bias::TestArg> args =
  1563. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1564. #if MEGDNN_AARCH64
  1565. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  1566. #elif MEGDNN_ARMV7
  1567. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  1568. #endif
  1569. }
  1570. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  1571. using namespace conv_bias;
  1572. std::vector<conv_bias::TestArg> args =
  1573. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1574. std::vector<conv_bias::TestArg> args_of_4;
  1575. for (auto&& arg : args) {
  1576. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  1577. args_of_4.push_back(arg);
  1578. }
  1579. }
  1580. #if MEGDNN_AARCH64
  1581. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  1582. #elif MEGDNN_ARMV7
  1583. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  1584. #endif
  1585. }
  1586. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1587. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  1588. using namespace conv_bias;
  1589. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1590. NormalRNG rng(1);
  1591. #if MEGDNN_AARCH64
  1592. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1593. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1594. "CONV1x1:AARCH64_F16_K8X24X1:48");
  1595. #elif MEGDNN_ARMV7
  1596. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1597. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1598. "CONV1x1:AARCH32_F16_K4X16X1:24");
  1599. #endif
  1600. }
  1601. #endif
  1602. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  1603. UniformIntRNG rng{-50, 50};
  1604. float epsilon = 0.001;
  1605. #define cb(name) \
  1606. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1607. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1608. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1609. dtype::QuantizedS8(60.25f), name);
  1610. #if MEGDNN_AARCH64
  1611. #if __ARM_FEATURE_DOTPROD
  1612. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  1613. #else
  1614. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1615. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  1616. #endif
  1617. #elif MEGDNN_ARMV7
  1618. epsilon = 1;
  1619. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  1620. #endif
  1621. #undef cb
  1622. }
  1623. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1624. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  1625. NormalRNG rng(128.f);
  1626. #define cb(name) \
  1627. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1628. handle(), &rng, epsilon, \
  1629. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1630. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1631. dtype::QuantizedS32(1.2 * 1.3), \
  1632. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1633. float epsilon = 0.001;
  1634. #if MEGDNN_AARCH64
  1635. #if __ARM_FEATURE_DOTPROD
  1636. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  1637. #else
  1638. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  1639. #endif
  1640. #elif MEGDNN_ARMV7
  1641. epsilon = 1;
  1642. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  1643. #endif
  1644. #undef cb
  1645. }
  1646. #endif
  1647. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1648. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  1649. UniformIntRNG rng{-50, 50};
  1650. float epsilon = 0.001;
  1651. #define cb(name) \
  1652. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1653. epsilon, dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1654. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1655. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1656. #if MEGDNN_AARCH64
  1657. #if __ARM_FEATURE_DOTPROD
  1658. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  1659. #else
  1660. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  1661. #endif
  1662. #elif MEGDNN_ARMV7
  1663. #if __ARM_FEATURE_DOTPROD
  1664. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  1665. #endif
  1666. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  1667. #endif
  1668. #undef cb
  1669. }
  1670. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  1671. UniformIntRNG rng{-50, 50};
  1672. float epsilon = 0.001;
  1673. #define cb(name) \
  1674. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1675. epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  1676. dtype::Int16{}, name);
  1677. #if MEGDNN_AARCH64
  1678. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  1679. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  1680. #elif MEGDNN_ARMV7
  1681. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  1682. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  1683. #endif
  1684. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  1685. #undef cb
  1686. }
  1687. #endif
  1688. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  1689. using namespace conv_bias;
  1690. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  1691. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1692. #if MEGDNN_AARCH64
  1693. #if __ARM_FEATURE_DOTPROD
  1694. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  1695. #else
  1696. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1697. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  1698. #endif
  1699. #elif MEGDNN_ARMV7
  1700. #if __ARM_FEATURE_DOTPROD
  1701. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  1702. #endif
  1703. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  1704. #endif
  1705. #if MEGDNN_ARMV7
  1706. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  1707. #endif
  1708. #undef cb
  1709. }
  1710. #ifndef __ARM_FEATURE_DOTPROD
  1711. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  1712. using namespace conv_bias;
  1713. std::vector<conv_bias::TestArg> args =
  1714. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  1715. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1716. #if MEGDNN_AARCH64
  1717. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1718. #elif MEGDNN_ARMV7
  1719. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1720. #endif
  1721. #undef cb
  1722. UniformIntRNG rng{-50, 50};
  1723. float epsilon = 0.001;
  1724. #define cb(name) \
  1725. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  1726. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1727. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1728. dtype::QuantizedS8(60.25f), name);
  1729. #if MEGDNN_AARCH64
  1730. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1731. #elif MEGDNN_ARMV7
  1732. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1733. #endif
  1734. #undef cb
  1735. }
  1736. #endif
  1737. // vim: syntax=cpp.doxygen

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