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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  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. using namespace conv_bias;
  71. using NLMode = param::ConvBias::NonlineMode;
  72. std::vector<TestArg> args;
  73. auto pack = [&](size_t n, size_t oc, size_t ic, size_t h, size_t w,
  74. size_t kernel, size_t stride, size_t group, NLMode nlmode,
  75. megdnn::BiasMode bias_mode, int any_pad = -1) {
  76. constexpr int pack_c = 4;
  77. const size_t pad = any_pad >= 0 ? any_pad : kernel / 2;
  78. auto oc_per_group = oc / group;
  79. auto ic_per_group = ic / group;
  80. bool ok_group = (oc % group == 0 && ic % group == 0) &&
  81. oc_per_group % pack_c == 0 && oc_per_group > 0 &&
  82. ic_per_group > 0;
  83. bool nchw_disable = group > 1 || ic_per_group >= 4;
  84. bool nchw44_disable = ic_per_group % pack_c != 0;
  85. bool invalid_pad = (w + 2 * pad < kernel) || (h + 2 * pad < kernel);
  86. if (!(ok_group) || invalid_pad) {
  87. return;
  88. }
  89. if ((is_input_nchw && nchw_disable) ||
  90. (!is_input_nchw && nchw44_disable)) {
  91. return;
  92. }
  93. size_t kernel_h = kernel;
  94. size_t kernel_w = kernel;
  95. param::ConvBias param;
  96. param.format = param::ConvBias::Format::NCHW44;
  97. param.stride_h = stride;
  98. param.stride_w = stride;
  99. param.pad_h = pad;
  100. param.pad_w = pad;
  101. param.nonlineMode = nlmode;
  102. auto src_tensor_shape = TensorShape{n, ic / pack_c, h, w, pack_c};
  103. auto weight_tensor_shape = TensorShape{
  104. oc / pack_c, ic / pack_c, kernel_h, kernel_w, pack_c, pack_c};
  105. auto bias_tensor_shape = TensorShape{};
  106. if (bias_mode == megdnn::BiasMode::BROADCAST_CHANNEL_BIAS) {
  107. bias_tensor_shape = {1, oc / pack_c, 1, 1, pack_c};
  108. } else if (bias_mode == megdnn::BiasMode::BIAS) {
  109. bias_tensor_shape = {n, oc / pack_c,
  110. (h + 2 * pad - kernel) / stride + 1,
  111. (w + 2 * pad - kernel) / stride + 1, pack_c};
  112. }
  113. if (group == 1) {
  114. param.sparse = param::ConvBias::Sparse::DENSE;
  115. } else if (group > 1 && ic / group == 1 && oc / group == 1) {
  116. megdnn_assert(0, "not support channel wise");
  117. param.sparse = param::ConvBias::Sparse::GROUP;
  118. weight_tensor_shape = TensorShape{group / pack_c, 1, 1,
  119. kernel_h, kernel_w, pack_c};
  120. } else if (group > 1 && oc_per_group % pack_c == 0 && oc / group > 0 &&
  121. ic_per_group % pack_c == 0 && ic / group > 0) {
  122. param.sparse = param::ConvBias::Sparse::GROUP;
  123. weight_tensor_shape = TensorShape{group,
  124. oc_per_group / pack_c,
  125. ic_per_group / pack_c,
  126. kernel_h,
  127. kernel_w,
  128. pack_c,
  129. pack_c};
  130. }
  131. if (is_input_nchw) {
  132. src_tensor_shape = TensorShape{n, ic, h, w};
  133. weight_tensor_shape =
  134. TensorShape{oc / pack_c, kernel_h, kernel_w, ic, pack_c};
  135. }
  136. args.emplace_back(param, src_tensor_shape, weight_tensor_shape,
  137. bias_tensor_shape);
  138. };
  139. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  140. if (!no_nonlinemode) {
  141. nonlinemode.emplace_back(NLMode::RELU);
  142. nonlinemode.emplace_back(NLMode::H_SWISH);
  143. }
  144. std::vector<megdnn::BiasMode> bias_mode = {
  145. megdnn::BiasMode::BROADCAST_CHANNEL_BIAS};
  146. if (no_bias) {
  147. bias_mode.emplace_back(megdnn::BiasMode::NO_BIAS);
  148. }
  149. if (support_full_bias) {
  150. bias_mode.emplace_back(megdnn::BiasMode::BIAS);
  151. }
  152. for (auto bias : bias_mode)
  153. for (auto nlmode : nonlinemode)
  154. for (size_t n : {1, 2})
  155. for (size_t kernel : kernel_vec)
  156. for (size_t oc : {4, 12, 32})
  157. for (size_t ic : {1, 3, 4, 12, 32})
  158. for (size_t h : {3, 5, 12})
  159. for (size_t w : {7, 16, 23}) {
  160. for (size_t group = 1;
  161. group <= std::min(oc, ic); ++group) {
  162. pack(n, oc, ic, h, w, kernel, stride,
  163. group, nlmode, bias);
  164. }
  165. }
  166. return args;
  167. }
  168. std::vector<conv_bias::TestArg> get_int8_quint8_nchw44_channel_wise_args(
  169. std::vector<size_t> kernel, size_t stride, bool no_bias,
  170. bool no_nonlinemode) {
  171. using namespace conv_bias;
  172. using Param = param::ConvBias;
  173. using NLMode = param::ConvBias::NonlineMode;
  174. std::vector<TestArg> args;
  175. auto pack = [&](size_t n, size_t group, size_t w, size_t h, size_t kernel,
  176. size_t stride, NLMode nlmode, bool pad) {
  177. Param param;
  178. param.stride_h = stride;
  179. param.stride_w = stride;
  180. if (pad) {
  181. param.pad_h = kernel / 2;
  182. param.pad_w = kernel / 2;
  183. } else {
  184. param.pad_h = 0;
  185. param.pad_w = 0;
  186. }
  187. param.nonlineMode = nlmode;
  188. param.format = param::ConvBias::Format::NCHW44;
  189. param.sparse = param::ConvBias::Sparse::GROUP;
  190. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  191. TensorShape{group, 1, 1, kernel, kernel, 4},
  192. TensorShape{});
  193. if (!no_bias) {
  194. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  195. TensorShape{group, 1, 1, kernel, kernel, 4},
  196. TensorShape{1, group, 1, 1, 4});
  197. }
  198. };
  199. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  200. if (!no_nonlinemode) {
  201. nonlinemode.emplace_back(NLMode::RELU);
  202. nonlinemode.emplace_back(NLMode::H_SWISH);
  203. }
  204. for (size_t n : {1, 2}) {
  205. for (auto nlmode : nonlinemode) {
  206. for (bool pad : {true}) {
  207. for (size_t group : {1, 2, 4, 7, 128}) {
  208. for (size_t size : {4, 5, 6, 7, 8, 9, 10, 15, 40}) {
  209. for (size_t kern : kernel) {
  210. pack(n, group, size, size, kern, stride, nlmode,
  211. pad);
  212. }
  213. }
  214. }
  215. }
  216. for (bool pad : {false}) {
  217. for (size_t group : {1, 2, 7, 128}) {
  218. for (size_t size : {7, 8, 9, 10, 15, 40}) {
  219. for (size_t kern : kernel) {
  220. pack(n, group, size, size, kern, stride, nlmode,
  221. pad);
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. return args;
  229. }
  230. void checker_conv_bias_qint8x8x8(std::vector<conv_bias::TestArg> args,
  231. Handle* handle, const char* algo_name) {
  232. Checker<ConvBias> checker(handle);
  233. checker.set_before_exec_callback(
  234. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  235. #if MEGDNN_ARMV7
  236. checker.set_epsilon(1);
  237. #endif
  238. UniformIntRNG rng{-50, 50};
  239. checker.set_dtype(0, dtype::QuantizedS8(0.41113496f))
  240. .set_dtype(1, dtype::QuantizedS8(0.01887994f))
  241. .set_dtype(2, dtype::QuantizedS32(0.41113496f * 0.01887994f))
  242. .set_dtype(4, dtype::QuantizedS8(0.49550694f))
  243. .set_rng(0, &rng)
  244. .set_rng(1, &rng)
  245. .set_rng(2, &rng);
  246. for (auto&& arg : args) {
  247. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  248. }
  249. }
  250. void checker_conv_bias_qint8x8x32(std::vector<conv_bias::TestArg> args,
  251. Handle* handle, const char* algo_name) {
  252. Checker<ConvBias> checker(handle);
  253. UniformIntRNG rng{-50, 50};
  254. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  255. .set_dtype(1, dtype::QuantizedS8(2.5f))
  256. .set_dtype(2, dtype::QuantizedS32(6.25f))
  257. .set_dtype(4, {});
  258. checker.set_before_exec_callback(
  259. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  260. for (auto&& arg : args) {
  261. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  262. }
  263. }
  264. void checker_conv_bias_quint8x8x8(std::vector<conv_bias::TestArg> args,
  265. Handle* handle, const char* algo_name) {
  266. Checker<ConvBias> checker(handle);
  267. checker.set_before_exec_callback(
  268. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  269. UniformIntRNG rng(0, 255);
  270. checker.set_dtype(0, dtype::Quantized8Asymm(0.2f, 100))
  271. .set_dtype(1, dtype::Quantized8Asymm(0.2f, 120))
  272. .set_dtype(2, dtype::QuantizedS32(0.04f))
  273. .set_dtype(4, dtype::Quantized8Asymm(1.4f, 110))
  274. .set_rng(0, &rng)
  275. .set_rng(1, &rng)
  276. .set_rng(2, &rng);
  277. for (auto&& arg : args) {
  278. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  279. }
  280. }
  281. void checker_conv_bias_quint8x8x32(std::vector<conv_bias::TestArg> args,
  282. Handle* handle, const char* algo_name) {
  283. Checker<ConvBias> checker(handle);
  284. checker.set_before_exec_callback(
  285. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  286. NormalRNG rng(128.f);
  287. checker.set_rng(0, &rng).set_rng(1, &rng);
  288. checker.set_dtype(0, dtype::Quantized8Asymm(1.2f, (uint8_t)127))
  289. .set_dtype(1, dtype::Quantized8Asymm(1.3f, (uint8_t)129))
  290. .set_dtype(2, dtype::QuantizedS32(1.2 * 1.3))
  291. .set_dtype(4, {});
  292. for (auto&& arg : args) {
  293. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  294. }
  295. }
  296. void checker_conv_bias_int8x8x32_multi(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. checker.set_dtype(0, dtype::Int8());
  302. checker.set_dtype(1, dtype::Int8());
  303. checker.set_dtype(2, dtype::Int32());
  304. checker.set_dtype(4, dtype::Int32());
  305. for (auto&& arg : args) {
  306. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  307. }
  308. }
  309. /**********************************F32 direct************************/
  310. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_LARGE_GROUP) {
  311. check_conv_bias(
  312. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  313. handle(), "F32DIRECT_LARGE_GROUP");
  314. }
  315. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_SMALL_GROUP) {
  316. check_conv_bias(
  317. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  318. handle(), "F32DIRECT_SMALL_GROUP");
  319. }
  320. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S2) {
  321. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  322. false, false, true),
  323. handle(), "F32_CONV_NCHW44_DIRECT_S2");
  324. }
  325. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_LARGE_GROUP) {
  326. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  327. handle(), "F32STRD1_LARGE_GROUP");
  328. }
  329. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_SMALL_GROUP) {
  330. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  331. handle(), "F32STRD1_SMALL_GROUP");
  332. }
  333. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_LARGE_GROUP) {
  334. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  335. handle(), "F32STRD2_LARGE_GROUP");
  336. }
  337. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_SMALL_GROUP) {
  338. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  339. handle(), "F32STRD2_SMALL_GROUP");
  340. }
  341. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_NCHW_NCHW44_F32) {
  342. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  343. false, true),
  344. handle(), "F32_CONV_NCHW_NCHW44");
  345. }
  346. /**********************************F16 direct************************/
  347. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  348. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_LARGE_GROUP) {
  349. NormalRNG rng(1);
  350. checker_conv_bias_f16(
  351. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  352. handle(), rng, "F16DIRECT_LARGE_GROUP", 0.03);
  353. }
  354. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_SMALL_GROUP) {
  355. NormalRNG rng(1);
  356. checker_conv_bias_f16(
  357. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  358. handle(), rng, "F16DIRECT_SMALL_GROUP", 0.03);
  359. }
  360. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_LARGE_GROUP) {
  361. NormalRNG rng(1);
  362. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  363. handle(), rng, "F16STRD1_LARGE_GROUP", 0.03);
  364. }
  365. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_SMALL_GROUP) {
  366. NormalRNG rng(1);
  367. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  368. handle(), rng, "F16STRD1_SMALL_GROUP", 0.03);
  369. }
  370. #endif
  371. /**********************************algo 8816 direct************************/
  372. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_LARGE_GROUP) {
  373. checker_conv_bias_int8x8x16(
  374. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  375. "I8816DIRECT_LARGE_GROUP");
  376. }
  377. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_SMALL_GROUP) {
  378. checker_conv_bias_int8x8x16(
  379. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  380. "I8816DIRECT_SMALL_GROUP");
  381. }
  382. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_LARGE_GROUP) {
  383. checker_conv_bias_int8x8x16(
  384. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  385. "I8816STRD2_LARGE_GROUP");
  386. }
  387. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_SMALL_GROUP) {
  388. checker_conv_bias_int8x8x16(
  389. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  390. "I8816STRD2_SMALL_GROUP");
  391. }
  392. /**********************************algo 8-8-32 direct************************/
  393. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_LARGE_GROUP) {
  394. checker_conv_bias_int8x8x32_multi(
  395. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  396. "S8STRD1_LARGE_GROUP");
  397. }
  398. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_SMALL_GROUP) {
  399. checker_conv_bias_int8x8x32_multi(
  400. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  401. "S8STRD1_SMALL_GROUP");
  402. }
  403. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_LARGE_GROUP) {
  404. checker_conv_bias_int8x8x32_multi(
  405. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  406. "S8STRD2_LARGE_GROUP");
  407. }
  408. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_SMALL_GROUP) {
  409. checker_conv_bias_int8x8x32_multi(
  410. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  411. "S8STRD2_SMALL_GROUP");
  412. }
  413. TEST_F(ARM_COMMON_MULTI_THREADS,
  414. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT1_NCHW44) {
  415. checker_conv_bias_int8x8x32_multi(
  416. get_int8_quint8_nchw44_channel_wise_args({2, 3, 5}, 1, false, true),
  417. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  418. }
  419. TEST_F(ARM_COMMON_MULTI_THREADS,
  420. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT2_NCHW44) {
  421. checker_conv_bias_int8x8x32_multi(
  422. get_int8_quint8_nchw44_channel_wise_args({2, 3, 5}, 2, false, true),
  423. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  424. }
  425. /********************************qint8 direct******************************/
  426. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_LARGE_GROUP) {
  427. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  428. {2, 3, 5, 7}, 1, false, false, false),
  429. handle(), "S8STRD1_LARGE_GROUP");
  430. }
  431. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_SMALL_GROUP) {
  432. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  433. {2, 3, 5, 7}, 1, false, false, false),
  434. handle(), "S8STRD1_SMALL_GROUP");
  435. }
  436. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_LARGE_GROUP) {
  437. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  438. {2, 3, 5, 7}, 2, false, false, false),
  439. handle(), "S8STRD2_LARGE_GROUP");
  440. }
  441. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_SMALL_GROUP) {
  442. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  443. {2, 3, 5, 7}, 2, false, false, false),
  444. handle(), "S8STRD2_SMALL_GROUP");
  445. }
  446. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_NCHW44) {
  447. checker_conv_bias_qint8x8x8(
  448. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  449. handle(), "S8_NCHW44_DIRECT_STRD1");
  450. }
  451. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_NCHW44) {
  452. checker_conv_bias_qint8x8x8(
  453. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  454. handle(), "S8_NCHW44_DIRECT_STRD2");
  455. }
  456. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT1_NCHW44) {
  457. checker_conv_bias_qint8x8x8(get_int8_quint8_nchw44_channel_wise_args(
  458. {2, 3, 5}, 1, false, false),
  459. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  460. }
  461. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT2_NCHW44) {
  462. checker_conv_bias_qint8x8x8(get_int8_quint8_nchw44_channel_wise_args(
  463. {2, 3, 5}, 2, false, false),
  464. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  465. }
  466. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_NCHW_NCHW44) {
  467. checker_conv_bias_qint8x8x8(
  468. get_nchw44_conv_bias_args({3, 5, 7}, 2, false, false, false, true),
  469. handle(), "S8_CONV_NCHW_NCHW44");
  470. }
  471. /*****************************quint8 direct****************************/
  472. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_LARGE_GROUP) {
  473. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  474. {2, 3, 5, 7}, 1, false, false, false),
  475. handle(), "QU8STRD1_LARGE_GROUP");
  476. }
  477. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_SMALL_GROUP) {
  478. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  479. {2, 3, 5, 7}, 1, false, false, false),
  480. handle(), "QU8STRD1_SMALL_GROUP");
  481. }
  482. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_LARGE_GROUP) {
  483. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  484. {2, 3, 5, 7}, 2, false, false, false),
  485. handle(), "QU8STRD2_LARGE_GROUP");
  486. }
  487. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_SMALL_GROUP) {
  488. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  489. {2, 3, 5, 7}, 2, false, false, false),
  490. handle(), "QU8STRD2_SMALL_GROUP");
  491. }
  492. /****************************dot qint8 direct*************************/
  493. #if __ARM_FEATURE_DOTPROD
  494. TEST_F(ARM_COMMON_MULTI_THREADS,
  495. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  496. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  497. {2, 3, 5, 7}, 1, false, false, false),
  498. handle(), "ARMDOTS8STRD1_LARGE_GROUP");
  499. }
  500. TEST_F(ARM_COMMON_MULTI_THREADS,
  501. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  502. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  503. {2, 3, 5, 7}, 1, false, false, false),
  504. handle(), "ARMDOTS8STRD1_SMALL_GROUP");
  505. }
  506. TEST_F(ARM_COMMON_MULTI_THREADS,
  507. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  508. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  509. {2, 3, 5, 7}, 2, false, false, false),
  510. handle(), "ARMDOTS8STRD2_LARGE_GROUP");
  511. }
  512. TEST_F(ARM_COMMON_MULTI_THREADS,
  513. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  514. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  515. {2, 3, 5, 7}, 2, false, false, false),
  516. handle(), "ARMDOTS8STRD2_SMALL_GROUP");
  517. }
  518. /****************************dot 8-8-32 direct*************************/
  519. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_LARGE_GROUP) {
  520. checker_conv_bias_qint8x8x32(
  521. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  522. "ARMDOTS8STRD1_LARGE_GROUP");
  523. }
  524. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_SMALL_GROUP) {
  525. checker_conv_bias_qint8x8x32(
  526. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  527. "ARMDOTS8STRD1_SMALL_GROUP");
  528. }
  529. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_LARGE_GROUP) {
  530. checker_conv_bias_qint8x8x32(
  531. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  532. "ARMDOTS8STRD2_LARGE_GROUP");
  533. }
  534. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_SMALL_GROUP) {
  535. checker_conv_bias_qint8x8x32(
  536. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  537. "ARMDOTS8STRD2_SMALL_GROUP");
  538. }
  539. /******************************dot quint8*****************************/
  540. TEST_F(ARM_COMMON_MULTI_THREADS,
  541. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  542. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  543. {2, 3, 5, 7}, 1, false, false, false),
  544. handle(), "ARMDOTU8STRD1_LARGE_GROUP");
  545. }
  546. TEST_F(ARM_COMMON_MULTI_THREADS,
  547. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  548. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  549. {2, 3, 5, 7}, 1, false, false, false),
  550. handle(), "ARMDOTU8STRD1_SMALL_GROUP");
  551. }
  552. TEST_F(ARM_COMMON_MULTI_THREADS,
  553. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  554. checker_conv_bias_quint8x8x8(
  555. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  556. handle(), "ARMDOTU8STRD2_LARGE_GROUP");
  557. }
  558. TEST_F(ARM_COMMON_MULTI_THREADS,
  559. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  560. checker_conv_bias_quint8x8x8(
  561. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  562. handle(), "ARMDOTU8STRD2_SMALL_GROUP");
  563. }
  564. /******************************dot quint8x8x32***********************/
  565. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_LARGE_GROUP) {
  566. checker_conv_bias_quint8x8x32(
  567. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  568. "ARMDOTU8STRD1_LARGE_GROUP");
  569. }
  570. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_SMALL_GROUP) {
  571. checker_conv_bias_quint8x8x32(
  572. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  573. "ARMDOTU8STRD1_SMALL_GROUP");
  574. }
  575. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_LARGE_GROUP) {
  576. checker_conv_bias_quint8x8x32(
  577. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  578. "ARMDOTU8STRD2_LARGE_GROUP");
  579. }
  580. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_SMALL_GROUP) {
  581. checker_conv_bias_quint8x8x32(
  582. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  583. "ARMDOTU8STRD2_SMALL_GROUP");
  584. }
  585. #endif
  586. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4) {
  587. using namespace conv_bias;
  588. std::vector<TestArg> args = get_winograd_mk_packed_args();
  589. Checker<ConvBiasForward> checker(handle());
  590. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  591. }
  592. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63) {
  593. using namespace conv_bias;
  594. std::vector<TestArg> args = get_winograd_args(3);
  595. Checker<ConvBiasForward> checker(handle());
  596. check_winograd("1:6:32", checker, args);
  597. }
  598. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4) {
  599. using namespace conv_bias;
  600. std::vector<TestArg> args = get_winograd_mk_packed_args();
  601. Checker<ConvBiasForward> checker(handle());
  602. check_winograd("4:6:32", checker, args, param::MatrixMul::Format::MK4);
  603. }
  604. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  605. using namespace conv_bias;
  606. std::vector<TestArg> args = get_winograd_args(4);
  607. Checker<ConvBiasForward> checker(handle());
  608. check_winograd("1:5:32", checker, args);
  609. }
  610. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  611. using namespace conv_bias;
  612. std::vector<TestArg> args = get_winograd_args(5);
  613. Checker<ConvBiasForward> checker(handle());
  614. check_winograd("1:4:32", checker, args);
  615. }
  616. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  617. using namespace conv_bias;
  618. std::vector<TestArg> args = get_winograd_args(3);
  619. Checker<ConvBiasForward> checker(handle());
  620. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  621. param::ConvBias param, Handle* handle) {
  622. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  623. auto winograd_preprocess_opr =
  624. handle->create_operator<WinogradFilterPreprocess>();
  625. winograd_preprocess_opr->param().output_block_size = m;
  626. TensorLayout filter_transform_layout;
  627. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  628. filter_transform_layout);
  629. size_t winograd_preprocess_workspace_in_bytes =
  630. winograd_preprocess_opr->get_workspace_in_bytes(
  631. tensors[1].layout, filter_transform_layout);
  632. auto conv_bias_opr = handle->create_operator<ConvBias>();
  633. conv_bias_opr->param() = param;
  634. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  635. conv_bias_opr->param().output_block_size = m;
  636. size_t conv_bias_workspace_in_bytes =
  637. conv_bias_opr->get_workspace_in_bytes(
  638. tensors[0].layout, filter_transform_layout,
  639. tensors[2].layout, tensors[3].layout,
  640. tensors[4].layout, nullptr);
  641. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  642. conv_bias_workspace_in_bytes,
  643. winograd_preprocess_workspace_in_bytes});
  644. wb.set(malloc(wb.total_size_in_bytes()));
  645. TensorND filter_transform_tensor(wb.get(0),
  646. std::move(filter_transform_layout));
  647. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  648. wb.get_workspace(2));
  649. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  650. tensors[3], tensors[4], nullptr,
  651. wb.get_workspace(1));
  652. free(wb.ptr());
  653. };
  654. auto run = [&checker, &extra_impl](
  655. Handle* handle, const std::vector<TestArg>& args,
  656. const std::vector<size_t>& out_size, DType A_dtype,
  657. DType B_dtype, DType C_dtype, DType D_dtype,
  658. const float eps) {
  659. for (auto&& arg : args) {
  660. for (uint32_t m : out_size) {
  661. checker.set_extra_opr_impl(std::bind(extra_impl,
  662. std::placeholders::_1, m,
  663. arg.param, handle));
  664. checker.set_dtype(0, A_dtype)
  665. .set_dtype(1, B_dtype)
  666. .set_dtype(2, C_dtype)
  667. .set_dtype(4, D_dtype)
  668. .set_epsilon(eps)
  669. .set_param(arg.param)
  670. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  671. }
  672. }
  673. };
  674. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  675. dtype::Float32(), dtype::Float32(), 1e-3f);
  676. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  677. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  678. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  679. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  680. dtype::Float16(), dtype::Float16(), 0.35f);
  681. #endif
  682. }
  683. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  684. using namespace conv_bias;
  685. Checker<ConvBiasForward> checker(handle());
  686. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  687. const std::vector<size_t>& out_size, DType A_dtype,
  688. DType B_dtype, DType C_dtype, DType D_dtype,
  689. param::MatrixMul::Format format, float eps) {
  690. for (auto&& arg : args) {
  691. for (uint32_t m : out_size) {
  692. checker.set_extra_opr_impl(std::bind(
  693. winograd_algo_extra_impl, std::placeholders::_1, m,
  694. arg.param, handle, format));
  695. checker.set_dtype(0, A_dtype)
  696. .set_dtype(1, B_dtype)
  697. .set_dtype(2, C_dtype)
  698. .set_dtype(4, D_dtype)
  699. .set_epsilon(eps)
  700. .set_param(arg.param)
  701. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  702. }
  703. }
  704. };
  705. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  706. std::vector<TestArg> args_first_half(args.begin(),
  707. args.begin() + args.size() / 2);
  708. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  709. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  710. 1e-3f);
  711. }
  712. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  713. using namespace conv_bias;
  714. Checker<ConvBiasForward> checker(handle());
  715. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  716. const std::vector<size_t>& out_size, DType A_dtype,
  717. DType B_dtype, DType C_dtype, DType D_dtype,
  718. param::MatrixMul::Format format, float eps) {
  719. for (auto&& arg : args) {
  720. for (uint32_t m : out_size) {
  721. checker.set_extra_opr_impl(std::bind(
  722. winograd_algo_extra_impl, std::placeholders::_1, m,
  723. arg.param, handle, format));
  724. checker.set_dtype(0, A_dtype)
  725. .set_dtype(1, B_dtype)
  726. .set_dtype(2, C_dtype)
  727. .set_dtype(4, D_dtype)
  728. .set_epsilon(eps)
  729. .set_param(arg.param)
  730. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  731. }
  732. }
  733. };
  734. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  735. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  736. args.end());
  737. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  738. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  739. 1e-3f);
  740. }
  741. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  742. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  743. using namespace conv_bias;
  744. Checker<ConvBiasForward> checker(handle());
  745. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  746. const std::vector<size_t>& out_size, DType A_dtype,
  747. DType B_dtype, DType C_dtype, DType D_dtype,
  748. param::MatrixMul::Format format, float eps) {
  749. for (auto&& arg : args) {
  750. for (uint32_t m : out_size) {
  751. checker.set_extra_opr_impl(std::bind(
  752. winograd_algo_extra_impl, std::placeholders::_1, m,
  753. arg.param, handle, format));
  754. checker.set_dtype(0, A_dtype)
  755. .set_dtype(1, B_dtype)
  756. .set_dtype(2, C_dtype)
  757. .set_dtype(4, D_dtype)
  758. .set_epsilon(eps)
  759. .set_param(arg.param)
  760. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  761. }
  762. }
  763. };
  764. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  765. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  766. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  767. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  768. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  769. 0.25);
  770. }
  771. #endif
  772. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  773. using namespace conv_bias;
  774. Checker<ConvBiasForward> checker(handle());
  775. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  776. const std::vector<size_t>& out_size, DType A_dtype,
  777. DType B_dtype, DType C_dtype, DType D_dtype,
  778. param::MatrixMul::Format format, float eps) {
  779. for (auto&& arg : args) {
  780. for (uint32_t m : out_size) {
  781. checker.set_extra_opr_impl(std::bind(
  782. winograd_algo_extra_impl, std::placeholders::_1, m,
  783. arg.param, handle, format));
  784. checker.set_dtype(0, A_dtype)
  785. .set_dtype(1, B_dtype)
  786. .set_dtype(2, C_dtype)
  787. .set_dtype(4, D_dtype)
  788. .set_epsilon(eps)
  789. .set_param(arg.param)
  790. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  791. }
  792. }
  793. };
  794. #if MEGDNN_AARCH64
  795. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  796. #else
  797. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  798. #endif
  799. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  800. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  801. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  802. std::vector<TestArg> quantized_args =
  803. get_quantized_winograd_mk_packed_args(8);
  804. UniformIntRNG int_rng{-50, 50};
  805. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  806. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  807. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  808. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  809. }
  810. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  811. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  812. using namespace conv_bias;
  813. std::vector<TestArg> args = get_winograd_mk_packed_args();
  814. Checker<ConvBiasForward> checker(handle());
  815. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  816. }
  817. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  818. using namespace conv_bias;
  819. std::vector<TestArg> args = get_winograd_args(5);
  820. std::vector<TestArg> args_head_half(args.begin(),
  821. args.begin() + args.size() / 2);
  822. Checker<ConvBiasForward> checker(handle());
  823. //! fp16 range -1.0 ~ 1.0
  824. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  825. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  826. }
  827. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  828. using namespace conv_bias;
  829. std::vector<TestArg> args = get_winograd_args(5);
  830. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  831. args.end());
  832. Checker<ConvBiasForward> checker(handle());
  833. //! fp16 range -1.0 ~ 1.0
  834. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  835. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  836. }
  837. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  838. //! it will pass when run single testcase
  839. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  840. using namespace conv_bias;
  841. std::vector<TestArg> args = get_winograd_args(3);
  842. Checker<ConvBiasForward> checker(handle());
  843. //! fp16 range -1.0 ~ 1.0
  844. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  845. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  846. }
  847. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  848. using namespace conv_bias;
  849. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  850. std::vector<TestArg> args_head_half(args.begin(),
  851. args.begin() + args.size() / 2);
  852. Checker<ConvBiasForward> checker(handle());
  853. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  854. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  855. param::MatrixMul::Format::MK8);
  856. }
  857. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  858. using namespace conv_bias;
  859. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  860. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  861. args.end());
  862. Checker<ConvBiasForward> checker(handle());
  863. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  864. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  865. param::MatrixMul::Format::MK8);
  866. }
  867. #endif
  868. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  869. using namespace conv_bias;
  870. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  871. Checker<ConvBiasForward> checker(handle());
  872. UniformIntRNG rng{-50, 50};
  873. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  874. .set_dtype(1, dtype::QuantizedS8(2.5f))
  875. .set_dtype(2, dtype::QuantizedS32(6.25f))
  876. .set_dtype(4, dtype::QuantizedS8(60.25f))
  877. .set_rng(0, &rng)
  878. .set_rng(1, &rng)
  879. .set_rng(2, &rng);
  880. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  881. }
  882. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  883. RNG* rng, float epsilon, DType type0, DType type1,
  884. DType type2, DType type3, const char* algo_name) {
  885. using namespace conv_bias;
  886. Checker<ConvBias> checker(handle);
  887. checker.set_before_exec_callback(
  888. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  889. checker.set_dtype(0, type0);
  890. checker.set_dtype(1, type1);
  891. checker.set_dtype(2, type2);
  892. checker.set_dtype(4, type3);
  893. checker.set_epsilon(epsilon);
  894. if (NULL != rng) {
  895. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  896. }
  897. for (auto&& arg : args) {
  898. checker.set_param(arg.param).execs(
  899. {arg.src, arg.filter, arg.bias, {}, {}});
  900. }
  901. }
  902. // clang-format off
  903. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  904. #define cb(name) \
  905. check_conv_bias( \
  906. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  907. handle(), name);
  908. #if MEGDNN_AARCH64
  909. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  910. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  911. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  912. #elif MEGDNN_ARMV7
  913. cb("IM2COLMATMUL:ARMV7_F32")
  914. #endif
  915. #undef cb
  916. }
  917. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  918. #define cb(name) \
  919. check_conv_bias( \
  920. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  921. handle(), name);
  922. #if MEGDNN_AARCH64
  923. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  924. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  925. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  926. #elif MEGDNN_ARMV7
  927. cb("IM2COLMATMUL:ARMV7_F32")
  928. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  929. #endif
  930. #undef cb
  931. }
  932. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  933. UniformIntRNG rng{-50, 50};
  934. #define cb(name) \
  935. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  936. false, true, true), \
  937. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  938. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  939. dtype::QuantizedS8(60.25f), name); \
  940. checker_conv_bias( \
  941. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  942. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  943. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  944. dtype::QuantizedS8(60.25f), name);
  945. float epsilon = 0.001;
  946. #if MEGDNN_AARCH64
  947. #if __ARM_FEATURE_DOTPROD
  948. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  949. #else
  950. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  951. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  952. #endif
  953. #elif MEGDNN_ARMV7
  954. epsilon = 1;
  955. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  956. #endif
  957. #undef cb
  958. }
  959. // clang-format on
  960. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  961. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  962. NormalRNG rng(128.f);
  963. #define cb(name) \
  964. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  965. false, true, true), \
  966. handle(), &rng, epsilon, \
  967. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  968. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  969. dtype::QuantizedS32(1.2 * 1.3), \
  970. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  971. checker_conv_bias( \
  972. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  973. handle(), &rng, epsilon, \
  974. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  975. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  976. dtype::QuantizedS32(1.2 * 1.3), \
  977. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  978. float epsilon = 0.001;
  979. #if MEGDNN_AARCH64
  980. #if __ARM_FEATURE_DOTPROD
  981. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  982. #else
  983. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  984. #endif
  985. #elif MEGDNN_ARMV7
  986. epsilon = 1;
  987. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  988. #endif
  989. #undef cb
  990. }
  991. #endif
  992. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  993. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  994. UniformIntRNG rng{-50, 50};
  995. float epsilon = 0.001;
  996. #define cb(name) \
  997. checker_conv_bias( \
  998. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  999. handle(), &rng, epsilon, \
  1000. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1001. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1002. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1003. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1004. &rng, epsilon, \
  1005. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1006. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1007. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1008. #if MEGDNN_AARCH64
  1009. #if __ARM_FEATURE_DOTPROD
  1010. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1011. #else
  1012. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1013. #endif
  1014. #elif MEGDNN_ARMV7
  1015. #if __ARM_FEATURE_DOTPROD
  1016. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1017. #endif
  1018. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1019. #endif
  1020. #undef cb
  1021. }
  1022. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  1023. UniformIntRNG rng{-50, 50};
  1024. float epsilon = 0.001;
  1025. #define cb(name) \
  1026. checker_conv_bias( \
  1027. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1028. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1029. dtype::Int16{}, dtype::Int16{}, name); \
  1030. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1031. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1032. dtype::Int16{}, dtype::Int16{}, name);
  1033. #if MEGDNN_AARCH64
  1034. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  1035. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  1036. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1037. #elif MEGDNN_ARMV7
  1038. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1039. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  1040. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  1041. #endif
  1042. #undef cb
  1043. }
  1044. #endif
  1045. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1046. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  1047. using namespace conv_bias;
  1048. param::ConvBias cur_param;
  1049. std::vector<conv_bias::TestArg> args =
  1050. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  1051. std::vector<conv_bias::TestArg> args1 =
  1052. get_conv_bias_args({1}, 2, false, false, false);
  1053. args.insert(args.begin(), args1.begin(), args1.end());
  1054. NormalRNG rng(1);
  1055. #define cb(name) \
  1056. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  1057. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  1058. name);
  1059. #if MEGDNN_AARCH64
  1060. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  1061. #elif MEGDNN_ARMV7
  1062. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  1063. #endif
  1064. #undef cb
  1065. }
  1066. #endif
  1067. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  1068. Handle* handle, const char* algo_name) {
  1069. using namespace conv_bias;
  1070. Checker<ConvBias> checker(handle);
  1071. checker.set_before_exec_callback(
  1072. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1073. checker.set_dtype(0, dtype::Int8());
  1074. checker.set_dtype(1, dtype::Int8());
  1075. checker.set_dtype(2, dtype::Int32());
  1076. checker.set_dtype(4, dtype::Int32());
  1077. for (auto&& arg : args) {
  1078. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  1079. }
  1080. UniformIntRNG rng{-50, 50};
  1081. for (auto&& arg : args) {
  1082. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1083. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1084. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1085. .set_dtype(4, {})
  1086. .set_rng(0, &rng)
  1087. .set_rng(1, &rng)
  1088. .set_rng(2, &rng)
  1089. .set_param(arg.param)
  1090. .execs({arg.src, arg.filter, {}, {}, {}});
  1091. }
  1092. }
  1093. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1094. #if !__ARM_FEATURE_DOTPROD
  1095. TEST_F(ARM_COMMON, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44) {
  1096. using namespace conv_bias;
  1097. std::vector<conv_bias::TestArg> args =
  1098. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  1099. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1100. #if MEGDNN_AARCH64
  1101. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1102. #else
  1103. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1104. #endif
  1105. #undef cb
  1106. }
  1107. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_MULTI) {
  1108. using namespace conv_bias;
  1109. std::vector<conv_bias::TestArg> args =
  1110. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  1111. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1112. #if MEGDNN_AARCH64
  1113. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1114. #else
  1115. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1116. #endif
  1117. #undef cb
  1118. }
  1119. TEST_F(ARM_COMMON, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44) {
  1120. UniformIntRNG rng{-50, 50};
  1121. #define cb(name) \
  1122. checker_conv_bias(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1), \
  1123. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1124. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1125. dtype::QuantizedS8(60.25f), name);
  1126. float epsilon = 0.001;
  1127. #if MEGDNN_AARCH64
  1128. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1129. #else
  1130. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1131. #endif
  1132. #undef cb
  1133. }
  1134. TEST_F(ARM_COMMON_MULTI_THREADS,
  1135. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_MULTI) {
  1136. UniformIntRNG rng{-50, 50};
  1137. #define cb(name) \
  1138. checker_conv_bias(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1), \
  1139. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1140. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1141. dtype::QuantizedS8(60.25f), name);
  1142. float epsilon = 0.001;
  1143. #if MEGDNN_AARCH64
  1144. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1145. #else
  1146. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  1147. #endif
  1148. #undef cb
  1149. }
  1150. #if MEGDNN_AARCH64
  1151. TEST_F(ARM_COMMON_MULTI_THREADS,
  1152. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  1153. UniformIntRNG rng{-50, 50};
  1154. #define cb(name) \
  1155. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  1156. epsilon, dtype::QuantizedS8(2.5f), \
  1157. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1158. dtype::QuantizedS8(60.25f), name);
  1159. float epsilon = 0.001;
  1160. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  1161. #undef cb
  1162. }
  1163. #endif
  1164. #endif
  1165. #endif
  1166. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  1167. using namespace conv_bias;
  1168. std::vector<conv_bias::TestArg> args =
  1169. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  1170. std::vector<conv_bias::TestArg> args1 =
  1171. get_conv_bias_args({1}, 2, false, true, true);
  1172. args.insert(args.begin(), args1.begin(), args1.end());
  1173. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1174. #if MEGDNN_AARCH64
  1175. #if __ARM_FEATURE_DOTPROD
  1176. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1177. #else
  1178. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1179. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1180. #endif
  1181. #elif MEGDNN_ARMV7
  1182. #if __ARM_FEATURE_DOTPROD
  1183. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  1184. #endif
  1185. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1186. #endif
  1187. #if MEGDNN_ARMV7
  1188. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  1189. #endif
  1190. #undef cb
  1191. }
  1192. /***************************** Conv1x1 Algo Test ***********************/
  1193. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  1194. using namespace conv_bias;
  1195. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1196. #if MEGDNN_AARCH64
  1197. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  1198. #elif MEGDNN_ARMV7
  1199. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  1200. #endif
  1201. }
  1202. #if MEGDNN_AARCH64
  1203. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  1204. using namespace conv_bias;
  1205. std::vector<conv_bias::TestArg> args =
  1206. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1207. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  1208. }
  1209. #endif
  1210. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  1211. using namespace conv_bias;
  1212. std::vector<conv_bias::TestArg> args =
  1213. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  1214. std::vector<conv_bias::TestArg> args_of_4;
  1215. for (auto&& arg : args) {
  1216. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  1217. args_of_4.push_back(arg);
  1218. }
  1219. }
  1220. #if MEGDNN_AARCH64
  1221. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  1222. #elif MEGDNN_ARMV7
  1223. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  1224. #endif
  1225. }
  1226. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1227. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  1228. using namespace conv_bias;
  1229. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  1230. NormalRNG rng(1);
  1231. #if MEGDNN_AARCH64
  1232. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1233. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1234. "CONV1x1:AARCH64_F16_K8X24X1:48");
  1235. #elif MEGDNN_ARMV7
  1236. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  1237. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  1238. "CONV1x1:AARCH32_F16_K4X16X1:24");
  1239. #endif
  1240. }
  1241. #endif
  1242. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  1243. UniformIntRNG rng{-50, 50};
  1244. float epsilon = 0.001;
  1245. #define cb(name) \
  1246. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1247. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1248. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1249. dtype::QuantizedS8(60.25f), name);
  1250. #if MEGDNN_AARCH64
  1251. #if __ARM_FEATURE_DOTPROD
  1252. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  1253. #else
  1254. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1255. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  1256. #endif
  1257. #elif MEGDNN_ARMV7
  1258. epsilon = 1;
  1259. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  1260. #endif
  1261. #undef cb
  1262. }
  1263. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1264. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  1265. NormalRNG rng(128.f);
  1266. #define cb(name) \
  1267. checker_conv_bias(get_conv_bias_1x1_args(false, false, true, true), \
  1268. handle(), &rng, epsilon, \
  1269. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1270. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1271. dtype::QuantizedS32(1.2 * 1.3), \
  1272. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1273. float epsilon = 0.001;
  1274. #if MEGDNN_AARCH64
  1275. #if __ARM_FEATURE_DOTPROD
  1276. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  1277. #else
  1278. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  1279. #endif
  1280. #elif MEGDNN_ARMV7
  1281. epsilon = 1;
  1282. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  1283. #endif
  1284. #undef cb
  1285. }
  1286. #endif
  1287. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1288. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  1289. UniformIntRNG rng{-50, 50};
  1290. float epsilon = 0.001;
  1291. #define cb(name) \
  1292. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1293. epsilon, dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1294. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1295. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1296. #if MEGDNN_AARCH64
  1297. #if __ARM_FEATURE_DOTPROD
  1298. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  1299. #else
  1300. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  1301. #endif
  1302. #elif MEGDNN_ARMV7
  1303. #if __ARM_FEATURE_DOTPROD
  1304. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  1305. #endif
  1306. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  1307. #endif
  1308. #undef cb
  1309. }
  1310. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  1311. UniformIntRNG rng{-50, 50};
  1312. float epsilon = 0.001;
  1313. #define cb(name) \
  1314. checker_conv_bias(get_conv_bias_1x1_args(true, true), handle(), &rng, \
  1315. epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  1316. dtype::Int16{}, name);
  1317. #if MEGDNN_AARCH64
  1318. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  1319. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  1320. #elif MEGDNN_ARMV7
  1321. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  1322. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  1323. #endif
  1324. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  1325. #undef cb
  1326. }
  1327. #endif
  1328. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  1329. using namespace conv_bias;
  1330. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  1331. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1332. #if MEGDNN_AARCH64
  1333. #if __ARM_FEATURE_DOTPROD
  1334. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  1335. #else
  1336. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  1337. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  1338. #endif
  1339. #elif MEGDNN_ARMV7
  1340. #if __ARM_FEATURE_DOTPROD
  1341. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  1342. #endif
  1343. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  1344. #endif
  1345. #if MEGDNN_ARMV7
  1346. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  1347. #endif
  1348. #undef cb
  1349. }
  1350. #ifndef __ARM_FEATURE_DOTPROD
  1351. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  1352. using namespace conv_bias;
  1353. std::vector<conv_bias::TestArg> args =
  1354. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  1355. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  1356. #if MEGDNN_AARCH64
  1357. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1358. #elif MEGDNN_ARMV7
  1359. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1360. #endif
  1361. #undef cb
  1362. UniformIntRNG rng{-50, 50};
  1363. float epsilon = 0.001;
  1364. #define cb(name) \
  1365. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  1366. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1367. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1368. dtype::QuantizedS8(60.25f), name);
  1369. #if MEGDNN_AARCH64
  1370. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  1371. #elif MEGDNN_ARMV7
  1372. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  1373. #endif
  1374. #undef cb
  1375. }
  1376. #endif
  1377. // vim: syntax=cpp.doxygen

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