You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conv_bias_multi_thread.cpp 80 kB

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

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