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

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

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