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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  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({3, 5, 7}, 2, false, false, false, true),
  514. handle(), "S8_CONV_NCHW_NCHW44");
  515. }
  516. /*****************************quint8 direct****************************/
  517. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_LARGE_GROUP) {
  518. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  519. {2, 3, 5, 7}, 1, false, false, false),
  520. handle(), "QU8STRD1_LARGE_GROUP");
  521. }
  522. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_SMALL_GROUP) {
  523. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  524. {2, 3, 5, 7}, 1, false, false, false),
  525. handle(), "QU8STRD1_SMALL_GROUP");
  526. }
  527. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_LARGE_GROUP) {
  528. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  529. {2, 3, 5, 7}, 2, false, false, false),
  530. handle(), "QU8STRD2_LARGE_GROUP");
  531. }
  532. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_SMALL_GROUP) {
  533. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  534. {2, 3, 5, 7}, 2, false, false, false),
  535. handle(), "QU8STRD2_SMALL_GROUP");
  536. }
  537. /****************************dot qint8 direct*************************/
  538. #if __ARM_FEATURE_DOTPROD
  539. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_DOT_NCHW_NCHW44) {
  540. checker_conv_bias_qint8x8x8(
  541. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false,
  542. true),
  543. handle(), "ARMDOTS8_NCHW_NCHW44");
  544. checker_conv_bias_qint8x8x8(
  545. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false,
  546. true),
  547. handle(), "ARMDOTS8_NCHW_NCHW44");
  548. }
  549. TEST_F(ARM_COMMON_MULTI_THREADS,
  550. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  551. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  552. {2, 3, 5, 7}, 1, false, false, false),
  553. handle(), "ARMDOTS8STRD1_LARGE_GROUP");
  554. }
  555. TEST_F(ARM_COMMON_MULTI_THREADS,
  556. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  557. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  558. {2, 3, 5, 7}, 1, false, false, false),
  559. handle(), "ARMDOTS8STRD1_SMALL_GROUP");
  560. }
  561. TEST_F(ARM_COMMON_MULTI_THREADS,
  562. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  563. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  564. {2, 3, 5, 7}, 2, false, false, false),
  565. handle(), "ARMDOTS8STRD2_LARGE_GROUP");
  566. }
  567. TEST_F(ARM_COMMON_MULTI_THREADS,
  568. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  569. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  570. {2, 3, 5, 7}, 2, false, false, false),
  571. handle(), "ARMDOTS8STRD2_SMALL_GROUP");
  572. }
  573. /****************************dot 8-8-32 direct*************************/
  574. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_LARGE_GROUP) {
  575. checker_conv_bias_qint8x8x32(
  576. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  577. "ARMDOTS8STRD1_LARGE_GROUP");
  578. }
  579. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_SMALL_GROUP) {
  580. checker_conv_bias_qint8x8x32(
  581. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  582. "ARMDOTS8STRD1_SMALL_GROUP");
  583. }
  584. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_LARGE_GROUP) {
  585. checker_conv_bias_qint8x8x32(
  586. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  587. "ARMDOTS8STRD2_LARGE_GROUP");
  588. }
  589. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_SMALL_GROUP) {
  590. checker_conv_bias_qint8x8x32(
  591. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  592. "ARMDOTS8STRD2_SMALL_GROUP");
  593. }
  594. /******************************dot quint8*****************************/
  595. TEST_F(ARM_COMMON_MULTI_THREADS,
  596. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  597. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  598. {2, 3, 5, 7}, 1, false, false, false),
  599. handle(), "ARMDOTU8STRD1_LARGE_GROUP");
  600. }
  601. TEST_F(ARM_COMMON_MULTI_THREADS,
  602. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  603. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  604. {2, 3, 5, 7}, 1, false, false, false),
  605. handle(), "ARMDOTU8STRD1_SMALL_GROUP");
  606. }
  607. TEST_F(ARM_COMMON_MULTI_THREADS,
  608. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  609. checker_conv_bias_quint8x8x8(
  610. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  611. handle(), "ARMDOTU8STRD2_LARGE_GROUP");
  612. }
  613. TEST_F(ARM_COMMON_MULTI_THREADS,
  614. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  615. checker_conv_bias_quint8x8x8(
  616. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  617. handle(), "ARMDOTU8STRD2_SMALL_GROUP");
  618. }
  619. /******************************dot quint8x8x32***********************/
  620. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_LARGE_GROUP) {
  621. checker_conv_bias_quint8x8x32(
  622. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  623. "ARMDOTU8STRD1_LARGE_GROUP");
  624. }
  625. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_SMALL_GROUP) {
  626. checker_conv_bias_quint8x8x32(
  627. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  628. "ARMDOTU8STRD1_SMALL_GROUP");
  629. }
  630. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_LARGE_GROUP) {
  631. checker_conv_bias_quint8x8x32(
  632. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  633. "ARMDOTU8STRD2_LARGE_GROUP");
  634. }
  635. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_SMALL_GROUP) {
  636. checker_conv_bias_quint8x8x32(
  637. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  638. "ARMDOTU8STRD2_SMALL_GROUP");
  639. }
  640. /******************************dot int8x8x8 nchw44 ***********************/
  641. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x8) {
  642. using namespace conv_bias;
  643. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 1);
  644. for (auto&& arg : args)
  645. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  646. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  647. }
  648. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x32) {
  649. using namespace conv_bias;
  650. std::vector<TestArg> args =
  651. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  652. for (auto&& arg : args)
  653. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  654. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  655. }
  656. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_8x8x32) {
  657. using namespace conv_bias;
  658. std::vector<TestArg> args =
  659. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  660. for (auto&& arg : args)
  661. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  662. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  663. }
  664. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x8) {
  665. using namespace conv_bias;
  666. //! test qint8x8x8
  667. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 2);
  668. for (auto&& arg : args)
  669. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  670. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  671. }
  672. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x32) {
  673. using namespace conv_bias;
  674. //! test qint8x8x8
  675. std::vector<TestArg> args =
  676. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  677. for (auto&& arg : args)
  678. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  679. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  680. }
  681. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_8x8x32) {
  682. using namespace conv_bias;
  683. //! test qint8x8x8
  684. std::vector<TestArg> args =
  685. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  686. for (auto&& arg : args)
  687. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  688. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  689. }
  690. #endif
  691. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4) {
  692. using namespace conv_bias;
  693. std::vector<TestArg> args = get_winograd_mk_packed_args();
  694. Checker<ConvBiasForward> checker(handle());
  695. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  696. }
  697. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4_NCHW44) {
  698. using namespace conv_bias;
  699. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  700. Checker<ConvBiasForward> checker(handle());
  701. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  702. param::ConvBias::Format::NCHW44);
  703. }
  704. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63) {
  705. using namespace conv_bias;
  706. std::vector<TestArg> args = get_winograd_args(3);
  707. Checker<ConvBiasForward> checker(handle());
  708. check_winograd("1:6:32", checker, args);
  709. }
  710. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4) {
  711. using namespace conv_bias;
  712. std::vector<TestArg> args = get_winograd_mk_packed_args();
  713. Checker<ConvBiasForward> checker(handle());
  714. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  715. }
  716. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_NCHW44) {
  717. using namespace conv_bias;
  718. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  719. Checker<ConvBiasForward> checker(handle());
  720. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  721. param::ConvBias::Format::NCHW44);
  722. }
  723. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  724. using namespace conv_bias;
  725. std::vector<TestArg> args = get_winograd_args(4);
  726. Checker<ConvBiasForward> checker(handle());
  727. check_winograd("1:5:32", checker, args);
  728. }
  729. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  730. using namespace conv_bias;
  731. std::vector<TestArg> args = get_winograd_args(5);
  732. Checker<ConvBiasForward> checker(handle());
  733. check_winograd("1:4:32", checker, args);
  734. }
  735. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  736. using namespace conv_bias;
  737. std::vector<TestArg> args = get_winograd_args(3);
  738. Checker<ConvBiasForward> checker(handle());
  739. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  740. param::ConvBias param, Handle* handle) {
  741. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  742. auto winograd_preprocess_opr =
  743. handle->create_operator<WinogradFilterPreprocess>();
  744. winograd_preprocess_opr->param().output_block_size = m;
  745. TensorLayout filter_transform_layout;
  746. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  747. filter_transform_layout);
  748. size_t winograd_preprocess_workspace_in_bytes =
  749. winograd_preprocess_opr->get_workspace_in_bytes(
  750. tensors[1].layout, filter_transform_layout);
  751. auto conv_bias_opr = handle->create_operator<ConvBias>();
  752. conv_bias_opr->param() = param;
  753. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  754. conv_bias_opr->param().output_block_size = m;
  755. size_t conv_bias_workspace_in_bytes =
  756. conv_bias_opr->get_workspace_in_bytes(
  757. tensors[0].layout, filter_transform_layout,
  758. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  759. nullptr);
  760. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  761. conv_bias_workspace_in_bytes,
  762. winograd_preprocess_workspace_in_bytes});
  763. wb.set(malloc(wb.total_size_in_bytes()));
  764. TensorND filter_transform_tensor(wb.get(0),
  765. std::move(filter_transform_layout));
  766. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  767. wb.get_workspace(2));
  768. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  769. tensors[3], tensors[4], nullptr,
  770. wb.get_workspace(1));
  771. free(wb.ptr());
  772. };
  773. auto run = [&checker, &extra_impl](
  774. Handle* handle, const std::vector<TestArg>& args,
  775. const std::vector<size_t>& out_size, DType A_dtype,
  776. DType B_dtype, DType C_dtype, DType D_dtype,
  777. const float eps) {
  778. for (auto&& arg : args) {
  779. for (uint32_t m : out_size) {
  780. checker.set_extra_opr_impl(std::bind(extra_impl,
  781. std::placeholders::_1, m,
  782. arg.param, handle));
  783. checker.set_dtype(0, A_dtype)
  784. .set_dtype(1, B_dtype)
  785. .set_dtype(2, C_dtype)
  786. .set_dtype(4, D_dtype)
  787. .set_epsilon(eps)
  788. .set_param(arg.param)
  789. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  790. }
  791. }
  792. };
  793. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  794. dtype::Float32(), dtype::Float32(), 1e-3f);
  795. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  796. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  797. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  798. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  799. dtype::Float16(), dtype::Float16(), 0.35f);
  800. #endif
  801. }
  802. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_PREPROCESS_NCHW44) {
  803. using namespace conv_bias;
  804. std::vector<TestArg> nchw44_args = get_nchw44_conv_bias_args({3}, 1);
  805. Checker<ConvBiasForward> checker(handle());
  806. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  807. param::ConvBias param, Handle* handle) {
  808. megdnn_assert(param.format == param::ConvBias::Format::NCHW44);
  809. auto winograd_preprocess_opr =
  810. handle->create_operator<WinogradFilterPreprocess>();
  811. winograd_preprocess_opr->param().output_block_size = m;
  812. winograd_preprocess_opr->param().format = param::MatrixMul::Format::MK4;
  813. TensorLayout filter_transform_layout;
  814. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  815. filter_transform_layout);
  816. size_t winograd_preprocess_workspace_in_bytes =
  817. winograd_preprocess_opr->get_workspace_in_bytes(
  818. tensors[1].layout, filter_transform_layout);
  819. auto conv_bias_opr = handle->create_operator<ConvBias>();
  820. conv_bias_opr->param() = param;
  821. conv_bias_opr->param().format =
  822. param::ConvBias::Format::NCHW44_WINOGRAD;
  823. conv_bias_opr->param().output_block_size = m;
  824. size_t conv_bias_workspace_in_bytes =
  825. conv_bias_opr->get_workspace_in_bytes(
  826. tensors[0].layout, filter_transform_layout,
  827. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  828. nullptr);
  829. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  830. conv_bias_workspace_in_bytes,
  831. winograd_preprocess_workspace_in_bytes});
  832. wb.set(malloc(wb.total_size_in_bytes()));
  833. TensorND filter_transform_tensor(wb.get(0),
  834. std::move(filter_transform_layout));
  835. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  836. wb.get_workspace(2));
  837. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  838. tensors[3], tensors[4], nullptr,
  839. wb.get_workspace(1));
  840. free(wb.ptr());
  841. };
  842. auto run = [&checker, &extra_impl](
  843. Handle* handle, const std::vector<TestArg>& args,
  844. const std::vector<size_t>& out_size, DType A_dtype,
  845. DType B_dtype, DType C_dtype, DType D_dtype,
  846. const float eps) {
  847. for (auto&& arg : args) {
  848. for (uint32_t m : out_size) {
  849. checker.set_extra_opr_impl(std::bind(extra_impl,
  850. std::placeholders::_1, m,
  851. arg.param, handle));
  852. checker.set_dtype(0, A_dtype)
  853. .set_dtype(1, B_dtype)
  854. .set_dtype(2, C_dtype)
  855. .set_dtype(4, D_dtype)
  856. .set_epsilon(eps)
  857. .set_param(arg.param)
  858. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  859. }
  860. }
  861. };
  862. run(handle(), nchw44_args, {2, 6}, dtype::Float32(), dtype::Float32(),
  863. dtype::Float32(), dtype::Float32(), 1e-3f);
  864. }
  865. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  866. using namespace conv_bias;
  867. Checker<ConvBiasForward> checker(handle());
  868. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  869. const std::vector<size_t>& out_size, DType A_dtype,
  870. DType B_dtype, DType C_dtype, DType D_dtype,
  871. param::MatrixMul::Format format, float eps) {
  872. for (auto&& arg : args) {
  873. for (uint32_t m : out_size) {
  874. checker.set_extra_opr_impl(std::bind(
  875. winograd_algo_extra_impl, std::placeholders::_1, m,
  876. arg.param, handle, format));
  877. checker.set_dtype(0, A_dtype)
  878. .set_dtype(1, B_dtype)
  879. .set_dtype(2, C_dtype)
  880. .set_dtype(4, D_dtype)
  881. .set_epsilon(eps)
  882. .set_param(arg.param)
  883. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  884. }
  885. }
  886. };
  887. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  888. std::vector<TestArg> args_first_half(args.begin(),
  889. args.begin() + args.size() / 2);
  890. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  891. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  892. 1e-3f);
  893. }
  894. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  895. using namespace conv_bias;
  896. Checker<ConvBiasForward> checker(handle());
  897. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  898. const std::vector<size_t>& out_size, DType A_dtype,
  899. DType B_dtype, DType C_dtype, DType D_dtype,
  900. param::MatrixMul::Format format, float eps) {
  901. for (auto&& arg : args) {
  902. for (uint32_t m : out_size) {
  903. checker.set_extra_opr_impl(std::bind(
  904. winograd_algo_extra_impl, std::placeholders::_1, m,
  905. arg.param, handle, format));
  906. checker.set_dtype(0, A_dtype)
  907. .set_dtype(1, B_dtype)
  908. .set_dtype(2, C_dtype)
  909. .set_dtype(4, D_dtype)
  910. .set_epsilon(eps)
  911. .set_param(arg.param)
  912. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  913. }
  914. }
  915. };
  916. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  917. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  918. args.end());
  919. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  920. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  921. 1e-3f);
  922. }
  923. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  924. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  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. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  948. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  949. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  950. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  951. 0.25);
  952. }
  953. #endif
  954. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  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. #if MEGDNN_AARCH64
  977. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  978. #else
  979. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  980. #endif
  981. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  982. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  983. std::vector<TestArg> quantized_args =
  984. get_quantized_winograd_mk_packed_args(8);
  985. UniformIntRNG int_rng{-50, 50};
  986. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  987. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  988. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  989. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  990. }
  991. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8) {
  992. using namespace conv_bias;
  993. Checker<ConvBiasForward> checker(handle());
  994. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  995. const std::vector<size_t>& out_size, DType A_dtype,
  996. DType B_dtype, DType C_dtype, DType D_dtype,
  997. param::MatrixMul::Format format, float eps) {
  998. for (auto&& arg : args) {
  999. for (uint32_t m : out_size) {
  1000. checker.set_extra_opr_impl(std::bind(
  1001. winograd_algo_extra_impl, std::placeholders::_1, m,
  1002. arg.param, handle, format));
  1003. checker.set_dtype(0, A_dtype)
  1004. .set_dtype(1, B_dtype)
  1005. .set_dtype(2, C_dtype)
  1006. .set_dtype(4, D_dtype)
  1007. .set_epsilon(eps)
  1008. .set_param(arg.param)
  1009. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1010. }
  1011. }
  1012. };
  1013. #if MEGDNN_AARCH64
  1014. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1015. #else
  1016. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1017. #endif
  1018. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1019. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1020. std::vector<TestArg> quantized_args = get_int8_nchw44_args (3,4);
  1021. UniformIntRNG int_rng{-50, 50};
  1022. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1023. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1024. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1025. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1026. }
  1027. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE) {
  1028. using namespace conv_bias;
  1029. Checker<ConvBiasForward> checker(handle());
  1030. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1031. const std::vector<size_t>& out_size, DType A_dtype,
  1032. DType B_dtype, DType C_dtype, DType D_dtype,
  1033. param::MatrixMul::Format format, float eps) {
  1034. for (auto&& arg : args) {
  1035. for (uint32_t m : out_size) {
  1036. checker.set_extra_opr_impl(std::bind(
  1037. winograd_algo_extra_impl, std::placeholders::_1, m,
  1038. arg.param, handle, format));
  1039. checker.set_dtype(0, A_dtype)
  1040. .set_dtype(1, B_dtype)
  1041. .set_dtype(2, C_dtype)
  1042. .set_dtype(4, D_dtype)
  1043. .set_epsilon(eps)
  1044. .set_param(arg.param)
  1045. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1046. }
  1047. }
  1048. };
  1049. #if MEGDNN_AARCH64
  1050. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1051. #else
  1052. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1053. #endif
  1054. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1055. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1056. std::vector<TestArg> quantized_args =
  1057. get_int8_nchw44_args(3, 4, false, true);
  1058. UniformIntRNG int_rng{-50, 50};
  1059. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1060. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1061. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1062. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1063. }
  1064. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32) {
  1065. using namespace conv_bias;
  1066. Checker<ConvBiasForward> checker(handle());
  1067. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1068. const std::vector<size_t>& out_size, DType A_dtype,
  1069. DType B_dtype, DType C_dtype, DType D_dtype,
  1070. param::MatrixMul::Format format, float eps) {
  1071. for (auto&& arg : args) {
  1072. for (uint32_t m : out_size) {
  1073. checker.set_extra_opr_impl(std::bind(
  1074. winograd_algo_extra_impl, std::placeholders::_1, m,
  1075. arg.param, handle, format));
  1076. checker.set_dtype(0, A_dtype)
  1077. .set_dtype(1, B_dtype)
  1078. .set_dtype(2, C_dtype)
  1079. .set_dtype(4, D_dtype)
  1080. .set_epsilon(eps)
  1081. .set_param(arg.param)
  1082. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1083. }
  1084. }
  1085. };
  1086. float epsilon = 0.001;
  1087. #if MEGDNN_AARCH64
  1088. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1089. #else
  1090. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1091. #endif
  1092. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1093. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1094. std::vector<TestArg> quantized_args =
  1095. get_int8_nchw44_args(3, 4, true);
  1096. UniformIntRNG int_rng{-50, 50};
  1097. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1098. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1099. dtype::QuantizedS8(0.01887994f),
  1100. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1101. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4, epsilon);
  1102. }
  1103. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE) {
  1104. using namespace conv_bias;
  1105. Checker<ConvBiasForward> checker(handle());
  1106. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1107. const std::vector<size_t>& out_size, DType A_dtype,
  1108. DType B_dtype, DType C_dtype, DType D_dtype,
  1109. param::MatrixMul::Format format, float eps) {
  1110. for (auto&& arg : args) {
  1111. for (uint32_t m : out_size) {
  1112. checker.set_extra_opr_impl(std::bind(
  1113. winograd_algo_extra_impl, std::placeholders::_1, m,
  1114. arg.param, handle, format));
  1115. checker.set_dtype(0, A_dtype)
  1116. .set_dtype(1, B_dtype)
  1117. .set_dtype(2, C_dtype)
  1118. .set_dtype(4, D_dtype)
  1119. .set_epsilon(eps)
  1120. .set_param(arg.param)
  1121. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1122. }
  1123. }
  1124. };
  1125. float epsilon = 0.001;
  1126. #if MEGDNN_AARCH64
  1127. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1128. #else
  1129. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1130. #endif
  1131. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1132. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1133. std::vector<TestArg> quantized_args =
  1134. get_int8_nchw44_args(3, 4, true, true);
  1135. UniformIntRNG int_rng{-50, 50};
  1136. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1137. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1138. dtype::QuantizedS8(0.01887994f),
  1139. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1140. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4, epsilon);
  1141. }
  1142. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1143. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  1144. using namespace conv_bias;
  1145. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1146. Checker<ConvBiasForward> checker(handle());
  1147. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1148. }
  1149. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  1150. using namespace conv_bias;
  1151. std::vector<TestArg> args = get_winograd_args(5);
  1152. std::vector<TestArg> args_head_half(args.begin(),
  1153. args.begin() + args.size() / 2);
  1154. Checker<ConvBiasForward> checker(handle());
  1155. //! fp16 range -1.0 ~ 1.0
  1156. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1157. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1158. }
  1159. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  1160. using namespace conv_bias;
  1161. std::vector<TestArg> args = get_winograd_args(5);
  1162. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1163. args.end());
  1164. Checker<ConvBiasForward> checker(handle());
  1165. //! fp16 range -1.0 ~ 1.0
  1166. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1167. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1168. }
  1169. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1170. //! it will pass when run single testcase
  1171. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  1172. using namespace conv_bias;
  1173. std::vector<TestArg> args = get_winograd_args(3);
  1174. Checker<ConvBiasForward> checker(handle());
  1175. //! fp16 range -1.0 ~ 1.0
  1176. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1177. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1178. }
  1179. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  1180. using namespace conv_bias;
  1181. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1182. std::vector<TestArg> args_head_half(args.begin(),
  1183. args.begin() + args.size() / 2);
  1184. Checker<ConvBiasForward> checker(handle());
  1185. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1186. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1187. param::MatrixMul::Format::MK8);
  1188. }
  1189. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  1190. using namespace conv_bias;
  1191. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1192. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1193. args.end());
  1194. Checker<ConvBiasForward> checker(handle());
  1195. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1196. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1197. param::MatrixMul::Format::MK8);
  1198. }
  1199. #endif
  1200. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  1201. using namespace conv_bias;
  1202. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1203. Checker<ConvBiasForward> checker(handle());
  1204. UniformIntRNG rng{-50, 50};
  1205. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1206. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1207. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1208. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1209. .set_rng(0, &rng)
  1210. .set_rng(1, &rng)
  1211. .set_rng(2, &rng);
  1212. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1213. }
  1214. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  1215. RNG* rng, float epsilon, DType type0, DType type1,
  1216. DType type2, DType type3, const char* algo_name) {
  1217. using namespace conv_bias;
  1218. Checker<ConvBias> checker(handle);
  1219. checker.set_before_exec_callback(
  1220. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1221. checker.set_dtype(0, type0);
  1222. checker.set_dtype(1, type1);
  1223. checker.set_dtype(2, type2);
  1224. checker.set_dtype(4, type3);
  1225. checker.set_epsilon(epsilon);
  1226. if (NULL != rng) {
  1227. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  1228. }
  1229. for (auto&& arg : args) {
  1230. checker.set_param(arg.param).execs(
  1231. {arg.src, arg.filter, arg.bias, {}, {}});
  1232. }
  1233. }
  1234. // clang-format off
  1235. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  1236. #define cb(name) \
  1237. check_conv_bias( \
  1238. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1239. handle(), name);
  1240. #if MEGDNN_AARCH64
  1241. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1242. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1243. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1244. #elif MEGDNN_ARMV7
  1245. cb("IM2COLMATMUL:ARMV7_F32")
  1246. #endif
  1247. #undef cb
  1248. }
  1249. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  1250. #define cb(name) \
  1251. check_conv_bias( \
  1252. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1253. handle(), name);
  1254. #if MEGDNN_AARCH64
  1255. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1256. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1257. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1258. #elif MEGDNN_ARMV7
  1259. cb("IM2COLMATMUL:ARMV7_F32")
  1260. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1261. #endif
  1262. #undef cb
  1263. }
  1264. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  1265. UniformIntRNG rng{-50, 50};
  1266. #define cb(name) \
  1267. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1268. false, true, true), \
  1269. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1270. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1271. dtype::QuantizedS8(60.25f), name); \
  1272. checker_conv_bias( \
  1273. get_conv_bias_args({1}, 2, false, false, 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. float epsilon = 0.001;
  1278. #if MEGDNN_AARCH64
  1279. #if __ARM_FEATURE_DOTPROD
  1280. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1281. #else
  1282. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1283. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1284. #endif
  1285. #elif MEGDNN_ARMV7
  1286. epsilon = 1;
  1287. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1288. #endif
  1289. #undef cb
  1290. }
  1291. // clang-format on
  1292. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1293. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  1294. NormalRNG rng(128.f);
  1295. #define cb(name) \
  1296. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1297. false, true, true), \
  1298. handle(), &rng, epsilon, \
  1299. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1300. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1301. dtype::QuantizedS32(1.2 * 1.3), \
  1302. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1303. checker_conv_bias( \
  1304. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1305. handle(), &rng, epsilon, \
  1306. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1307. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1308. dtype::QuantizedS32(1.2 * 1.3), \
  1309. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1310. float epsilon = 0.001;
  1311. #if MEGDNN_AARCH64
  1312. #if __ARM_FEATURE_DOTPROD
  1313. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1314. #else
  1315. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1316. #endif
  1317. #elif MEGDNN_ARMV7
  1318. epsilon = 1;
  1319. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1320. #endif
  1321. #undef cb
  1322. }
  1323. #endif
  1324. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1325. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  1326. UniformIntRNG rng{-50, 50};
  1327. float epsilon = 0.001;
  1328. #define cb(name) \
  1329. checker_conv_bias( \
  1330. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1331. handle(), &rng, epsilon, \
  1332. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1333. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1334. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1335. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1336. &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. #if MEGDNN_AARCH64
  1341. #if __ARM_FEATURE_DOTPROD
  1342. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1343. #else
  1344. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1345. #endif
  1346. #elif MEGDNN_ARMV7
  1347. #if __ARM_FEATURE_DOTPROD
  1348. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1349. #endif
  1350. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1351. #endif
  1352. #undef cb
  1353. }
  1354. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  1355. UniformIntRNG rng{-50, 50};
  1356. float epsilon = 0.001;
  1357. #define cb(name) \
  1358. checker_conv_bias( \
  1359. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1360. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1361. dtype::Int16{}, dtype::Int16{}, name); \
  1362. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1363. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1364. dtype::Int16{}, dtype::Int16{}, name);
  1365. #if MEGDNN_AARCH64
  1366. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  1367. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  1368. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1369. #elif MEGDNN_ARMV7
  1370. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1371. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  1372. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  1373. #endif
  1374. #undef cb
  1375. }
  1376. #endif
  1377. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1378. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  1379. using namespace conv_bias;
  1380. param::ConvBias cur_param;
  1381. std::vector<conv_bias::TestArg> args =
  1382. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  1383. std::vector<conv_bias::TestArg> args1 =
  1384. get_conv_bias_args({1}, 2, false, false, false);
  1385. args.insert(args.begin(), args1.begin(), args1.end());
  1386. NormalRNG rng(1);
  1387. #define cb(name) \
  1388. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  1389. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  1390. name);
  1391. #if MEGDNN_AARCH64
  1392. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  1393. #elif MEGDNN_ARMV7
  1394. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  1395. #endif
  1396. #undef cb
  1397. }
  1398. #endif
  1399. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  1400. Handle* handle, const char* algo_name) {
  1401. using namespace conv_bias;
  1402. Checker<ConvBias> checker(handle);
  1403. checker.set_before_exec_callback(
  1404. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1405. checker.set_dtype(0, dtype::Int8());
  1406. checker.set_dtype(1, dtype::Int8());
  1407. checker.set_dtype(2, dtype::Int32());
  1408. checker.set_dtype(4, dtype::Int32());
  1409. for (auto&& arg : args) {
  1410. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  1411. }
  1412. UniformIntRNG rng{-50, 50};
  1413. for (auto&& arg : args) {
  1414. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1415. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1416. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1417. .set_dtype(4, {})
  1418. .set_rng(0, &rng)
  1419. .set_rng(1, &rng)
  1420. .set_rng(2, &rng)
  1421. .set_param(arg.param)
  1422. .execs({arg.src, arg.filter, {}, {}, {}});
  1423. }
  1424. }
  1425. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1426. #if !__ARM_FEATURE_DOTPROD
  1427. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  1428. using namespace conv_bias;
  1429. std::vector<conv_bias::TestArg> args =
  1430. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  1431. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1432. #if MEGDNN_AARCH64
  1433. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1434. #else
  1435. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1436. #endif
  1437. #undef cb
  1438. }
  1439. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  1440. using namespace conv_bias;
  1441. std::vector<conv_bias::TestArg> args =
  1442. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  1443. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1444. #if MEGDNN_AARCH64
  1445. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1446. #else
  1447. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1448. #endif
  1449. #undef cb
  1450. }
  1451. TEST_F(ARM_COMMON_MULTI_THREADS,
  1452. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  1453. UniformIntRNG rng{-50, 50};
  1454. #define cb(name) \
  1455. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  1456. epsilon, dtype::QuantizedS8(2.5f), \
  1457. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1458. dtype::QuantizedS8(60.25f), name);
  1459. float epsilon = 0.001;
  1460. #if MEGDNN_AARCH64
  1461. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1462. #else
  1463. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1464. #endif
  1465. #undef cb
  1466. }
  1467. TEST_F(ARM_COMMON_MULTI_THREADS,
  1468. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  1469. UniformIntRNG rng{-50, 50};
  1470. #define cb(name) \
  1471. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  1472. epsilon, dtype::QuantizedS8(2.5f), \
  1473. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1474. dtype::QuantizedS8(60.25f), name);
  1475. float epsilon = 0.001;
  1476. #if MEGDNN_AARCH64
  1477. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1478. #else
  1479. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1480. #endif
  1481. #undef cb
  1482. }
  1483. #if MEGDNN_AARCH64
  1484. TEST_F(ARM_COMMON_MULTI_THREADS,
  1485. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  1486. UniformIntRNG rng{-50, 50};
  1487. #define cb(name) \
  1488. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  1489. epsilon, dtype::QuantizedS8(2.5f), \
  1490. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1491. dtype::QuantizedS8(60.25f), name);
  1492. float epsilon = 0.001;
  1493. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1494. #undef cb
  1495. }
  1496. #endif
  1497. #endif
  1498. #endif
  1499. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  1500. using namespace conv_bias;
  1501. std::vector<conv_bias::TestArg> args =
  1502. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  1503. std::vector<conv_bias::TestArg> args1 =
  1504. get_conv_bias_args({1}, 2, false, true, true);
  1505. args.insert(args.begin(), args1.begin(), args1.end());
  1506. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1507. #if MEGDNN_AARCH64
  1508. #if __ARM_FEATURE_DOTPROD
  1509. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1510. #else
  1511. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1512. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1513. #endif
  1514. #elif MEGDNN_ARMV7
  1515. #if __ARM_FEATURE_DOTPROD
  1516. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  1517. #endif
  1518. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1519. #endif
  1520. #if MEGDNN_ARMV7
  1521. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  1522. #endif
  1523. #undef cb
  1524. }
  1525. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  1526. using namespace conv_bias;
  1527. std::vector<conv_bias::TestArg> args =
  1528. get_nchw44_conv_bias_args({2, 4, 7}, 1);
  1529. #if MEGDNN_AARCH64
  1530. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  1531. #elif MEGDNN_ARMV7
  1532. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  1533. #endif
  1534. }
  1535. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  1536. using namespace conv_bias;
  1537. std::vector<conv_bias::TestArg> args =
  1538. get_nchw44_conv_bias_args({3, 5, 6}, 2);
  1539. #if MEGDNN_AARCH64
  1540. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  1541. #elif MEGDNN_ARMV7
  1542. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  1543. #endif
  1544. }
  1545. /***************************** Conv1x1 Algo Test ***********************/
  1546. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  1547. using namespace conv_bias;
  1548. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1549. #if MEGDNN_AARCH64
  1550. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  1551. #elif MEGDNN_ARMV7
  1552. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  1553. #endif
  1554. }
  1555. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  1556. using namespace conv_bias;
  1557. std::vector<conv_bias::TestArg> args =
  1558. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1559. #if MEGDNN_AARCH64
  1560. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  1561. #elif MEGDNN_ARMV7
  1562. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  1563. #endif
  1564. }
  1565. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  1566. using namespace conv_bias;
  1567. std::vector<conv_bias::TestArg> args =
  1568. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1569. std::vector<conv_bias::TestArg> args_of_4;
  1570. for (auto&& arg : args) {
  1571. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  1572. args_of_4.push_back(arg);
  1573. }
  1574. }
  1575. #if MEGDNN_AARCH64
  1576. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  1577. #elif MEGDNN_ARMV7
  1578. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  1579. #endif
  1580. }
  1581. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1582. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  1583. using namespace conv_bias;
  1584. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1585. NormalRNG rng(1);
  1586. #if MEGDNN_AARCH64
  1587. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1588. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1589. "CONV1x1:AARCH64_F16_K8X24X1:48");
  1590. #elif MEGDNN_ARMV7
  1591. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1592. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1593. "CONV1x1:AARCH32_F16_K4X16X1:24");
  1594. #endif
  1595. }
  1596. #endif
  1597. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  1598. UniformIntRNG rng{-50, 50};
  1599. float epsilon = 0.001;
  1600. #define cb(name) \
  1601. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1602. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1603. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1604. dtype::QuantizedS8(60.25f), name);
  1605. #if MEGDNN_AARCH64
  1606. #if __ARM_FEATURE_DOTPROD
  1607. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  1608. #else
  1609. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1610. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  1611. #endif
  1612. #elif MEGDNN_ARMV7
  1613. epsilon = 1;
  1614. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  1615. #endif
  1616. #undef cb
  1617. }
  1618. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1619. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  1620. NormalRNG rng(128.f);
  1621. #define cb(name) \
  1622. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1623. handle(), &rng, epsilon, \
  1624. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1625. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1626. dtype::QuantizedS32(1.2 * 1.3), \
  1627. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1628. float epsilon = 0.001;
  1629. #if MEGDNN_AARCH64
  1630. #if __ARM_FEATURE_DOTPROD
  1631. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  1632. #else
  1633. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  1634. #endif
  1635. #elif MEGDNN_ARMV7
  1636. epsilon = 1;
  1637. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  1638. #endif
  1639. #undef cb
  1640. }
  1641. #endif
  1642. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1643. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  1644. UniformIntRNG rng{-50, 50};
  1645. float epsilon = 0.001;
  1646. #define cb(name) \
  1647. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1648. epsilon, dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1649. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1650. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1651. #if MEGDNN_AARCH64
  1652. #if __ARM_FEATURE_DOTPROD
  1653. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  1654. #else
  1655. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  1656. #endif
  1657. #elif MEGDNN_ARMV7
  1658. #if __ARM_FEATURE_DOTPROD
  1659. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  1660. #endif
  1661. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  1662. #endif
  1663. #undef cb
  1664. }
  1665. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  1666. UniformIntRNG rng{-50, 50};
  1667. float epsilon = 0.001;
  1668. #define cb(name) \
  1669. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1670. epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  1671. dtype::Int16{}, name);
  1672. #if MEGDNN_AARCH64
  1673. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  1674. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  1675. #elif MEGDNN_ARMV7
  1676. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  1677. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  1678. #endif
  1679. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  1680. #undef cb
  1681. }
  1682. #endif
  1683. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  1684. using namespace conv_bias;
  1685. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  1686. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1687. #if MEGDNN_AARCH64
  1688. #if __ARM_FEATURE_DOTPROD
  1689. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  1690. #else
  1691. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1692. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  1693. #endif
  1694. #elif MEGDNN_ARMV7
  1695. #if __ARM_FEATURE_DOTPROD
  1696. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  1697. #endif
  1698. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  1699. #endif
  1700. #if MEGDNN_ARMV7
  1701. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  1702. #endif
  1703. #undef cb
  1704. }
  1705. #ifndef __ARM_FEATURE_DOTPROD
  1706. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  1707. using namespace conv_bias;
  1708. std::vector<conv_bias::TestArg> args =
  1709. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  1710. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1711. #if MEGDNN_AARCH64
  1712. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1713. #elif MEGDNN_ARMV7
  1714. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1715. #endif
  1716. #undef cb
  1717. UniformIntRNG rng{-50, 50};
  1718. float epsilon = 0.001;
  1719. #define cb(name) \
  1720. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  1721. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1722. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1723. dtype::QuantizedS8(60.25f), name);
  1724. #if MEGDNN_AARCH64
  1725. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1726. #elif MEGDNN_ARMV7
  1727. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1728. #endif
  1729. #undef cb
  1730. }
  1731. #endif
  1732. // vim: syntax=cpp.doxygen

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