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

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

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