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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645
  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_WEIGHT_PREPROCESS) {
  735. using namespace conv_bias;
  736. std::vector<TestArg> args = get_winograd_mk_packed_args();
  737. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  738. handle());
  739. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  740. }
  741. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4_NCHW44) {
  742. using namespace conv_bias;
  743. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  744. Checker<ConvBiasForward> checker(handle());
  745. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  746. param::ConvBias::Format::NCHW44);
  747. }
  748. TEST_F(ARM_COMMON_MULTI_THREADS,
  749. CONV_BIAS_WINOGRAD_F23_4_NCHW44_WEIGHT_PREPROCESS) {
  750. using namespace conv_bias;
  751. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  752. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  753. handle());
  754. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  755. param::ConvBias::Format::NCHW44);
  756. }
  757. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63) {
  758. using namespace conv_bias;
  759. std::vector<TestArg> args = get_winograd_args(3);
  760. Checker<ConvBiasForward> checker(handle());
  761. check_winograd("1:6:32", checker, args);
  762. }
  763. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_WEIGHT_PREPROCESS) {
  764. using namespace conv_bias;
  765. std::vector<TestArg> args = get_winograd_args(3);
  766. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  767. handle());
  768. check_winograd("1:6:32", checker, args);
  769. }
  770. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4) {
  771. using namespace conv_bias;
  772. std::vector<TestArg> args = get_winograd_mk_packed_args();
  773. Checker<ConvBiasForward> checker(handle());
  774. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  775. }
  776. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_WEIGHT_PREPROCESS) {
  777. using namespace conv_bias;
  778. std::vector<TestArg> args = get_winograd_mk_packed_args();
  779. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  780. handle());
  781. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  782. }
  783. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_NCHW44) {
  784. using namespace conv_bias;
  785. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  786. Checker<ConvBiasForward> checker(handle());
  787. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  788. param::ConvBias::Format::NCHW44);
  789. }
  790. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_NCHW44_WEIGHT_PREPROCESS) {
  791. using namespace conv_bias;
  792. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  793. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  794. handle());
  795. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  796. param::ConvBias::Format::NCHW44);
  797. }
  798. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  799. using namespace conv_bias;
  800. std::vector<TestArg> args = get_winograd_args(4);
  801. Checker<ConvBiasForward> checker(handle());
  802. check_winograd("1:5:32", checker, args);
  803. }
  804. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54_WEIGHT_PREPROCESS) {
  805. using namespace conv_bias;
  806. std::vector<TestArg> args = get_winograd_args(4);
  807. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  808. handle());
  809. check_winograd("1:5:32", checker, args);
  810. }
  811. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  812. using namespace conv_bias;
  813. std::vector<TestArg> args = get_winograd_args(5);
  814. Checker<ConvBiasForward> checker(handle());
  815. check_winograd("1:4:32", checker, args);
  816. }
  817. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45_WEIGHT_PREPROCESS) {
  818. using namespace conv_bias;
  819. std::vector<TestArg> args = get_winograd_args(5);
  820. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  821. handle());
  822. check_winograd("1:4:32", checker, args);
  823. }
  824. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  825. using namespace conv_bias;
  826. std::vector<TestArg> args = get_winograd_args(3);
  827. Checker<ConvBiasForward> checker(handle());
  828. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  829. param::ConvBias param, Handle* handle) {
  830. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  831. auto winograd_preprocess_opr =
  832. handle->create_operator<WinogradFilterPreprocess>();
  833. winograd_preprocess_opr->param().output_block_size = m;
  834. TensorLayout filter_transform_layout;
  835. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  836. filter_transform_layout);
  837. size_t winograd_preprocess_workspace_in_bytes =
  838. winograd_preprocess_opr->get_workspace_in_bytes(
  839. tensors[1].layout, filter_transform_layout);
  840. auto conv_bias_opr = handle->create_operator<ConvBias>();
  841. conv_bias_opr->param() = param;
  842. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  843. conv_bias_opr->param().output_block_size = m;
  844. size_t conv_bias_workspace_in_bytes =
  845. conv_bias_opr->get_workspace_in_bytes(
  846. tensors[0].layout, filter_transform_layout,
  847. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  848. nullptr);
  849. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  850. conv_bias_workspace_in_bytes,
  851. winograd_preprocess_workspace_in_bytes});
  852. wb.set(malloc(wb.total_size_in_bytes()));
  853. TensorND filter_transform_tensor(wb.get(0),
  854. std::move(filter_transform_layout));
  855. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  856. wb.get_workspace(2));
  857. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  858. tensors[3], tensors[4], nullptr,
  859. wb.get_workspace(1));
  860. free(wb.ptr());
  861. };
  862. auto run = [&checker, &extra_impl](
  863. Handle* handle, const std::vector<TestArg>& args,
  864. const std::vector<size_t>& out_size, DType A_dtype,
  865. DType B_dtype, DType C_dtype, DType D_dtype,
  866. const float eps) {
  867. for (auto&& arg : args) {
  868. for (uint32_t m : out_size) {
  869. checker.set_extra_opr_impl(std::bind(extra_impl,
  870. std::placeholders::_1, m,
  871. arg.param, handle));
  872. checker.set_dtype(0, A_dtype)
  873. .set_dtype(1, B_dtype)
  874. .set_dtype(2, C_dtype)
  875. .set_dtype(4, D_dtype)
  876. .set_epsilon(eps)
  877. .set_param(arg.param)
  878. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  879. }
  880. }
  881. };
  882. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  883. dtype::Float32(), dtype::Float32(), 1e-3f);
  884. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  885. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  886. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  887. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  888. dtype::Float16(), dtype::Float16(), 0.35f);
  889. #endif
  890. }
  891. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_PREPROCESS_NCHW44) {
  892. using namespace conv_bias;
  893. std::vector<TestArg> nchw44_args = get_nchw44_conv_bias_args({3}, 1);
  894. Checker<ConvBiasForward> checker(handle());
  895. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  896. param::ConvBias param, Handle* handle) {
  897. megdnn_assert(param.format == param::ConvBias::Format::NCHW44);
  898. auto winograd_preprocess_opr =
  899. handle->create_operator<WinogradFilterPreprocess>();
  900. winograd_preprocess_opr->param().output_block_size = m;
  901. winograd_preprocess_opr->param().format = param::MatrixMul::Format::MK4;
  902. TensorLayout filter_transform_layout;
  903. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  904. filter_transform_layout);
  905. size_t winograd_preprocess_workspace_in_bytes =
  906. winograd_preprocess_opr->get_workspace_in_bytes(
  907. tensors[1].layout, filter_transform_layout);
  908. auto conv_bias_opr = handle->create_operator<ConvBias>();
  909. conv_bias_opr->param() = param;
  910. conv_bias_opr->param().format =
  911. param::ConvBias::Format::NCHW44_WINOGRAD;
  912. conv_bias_opr->param().output_block_size = m;
  913. size_t conv_bias_workspace_in_bytes =
  914. conv_bias_opr->get_workspace_in_bytes(
  915. tensors[0].layout, filter_transform_layout,
  916. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  917. nullptr);
  918. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  919. conv_bias_workspace_in_bytes,
  920. winograd_preprocess_workspace_in_bytes});
  921. wb.set(malloc(wb.total_size_in_bytes()));
  922. TensorND filter_transform_tensor(wb.get(0),
  923. std::move(filter_transform_layout));
  924. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  925. wb.get_workspace(2));
  926. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  927. tensors[3], tensors[4], nullptr,
  928. wb.get_workspace(1));
  929. free(wb.ptr());
  930. };
  931. auto run = [&checker, &extra_impl](
  932. Handle* handle, const std::vector<TestArg>& args,
  933. const std::vector<size_t>& out_size, DType A_dtype,
  934. DType B_dtype, DType C_dtype, DType D_dtype,
  935. const float eps) {
  936. for (auto&& arg : args) {
  937. for (uint32_t m : out_size) {
  938. checker.set_extra_opr_impl(std::bind(extra_impl,
  939. std::placeholders::_1, m,
  940. arg.param, handle));
  941. checker.set_dtype(0, A_dtype)
  942. .set_dtype(1, B_dtype)
  943. .set_dtype(2, C_dtype)
  944. .set_dtype(4, D_dtype)
  945. .set_epsilon(eps)
  946. .set_param(arg.param)
  947. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  948. }
  949. }
  950. };
  951. run(handle(), nchw44_args, {2, 6}, dtype::Float32(), dtype::Float32(),
  952. dtype::Float32(), dtype::Float32(), 1e-3f);
  953. }
  954. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  955. using namespace conv_bias;
  956. Checker<ConvBiasForward> checker(handle());
  957. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  958. const std::vector<size_t>& out_size, DType A_dtype,
  959. DType B_dtype, DType C_dtype, DType D_dtype,
  960. param::MatrixMul::Format format, float eps) {
  961. for (auto&& arg : args) {
  962. for (uint32_t m : out_size) {
  963. checker.set_extra_opr_impl(std::bind(
  964. winograd_algo_extra_impl, std::placeholders::_1, m,
  965. arg.param, handle, format));
  966. checker.set_dtype(0, A_dtype)
  967. .set_dtype(1, B_dtype)
  968. .set_dtype(2, C_dtype)
  969. .set_dtype(4, D_dtype)
  970. .set_epsilon(eps)
  971. .set_param(arg.param)
  972. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  973. }
  974. }
  975. };
  976. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  977. std::vector<TestArg> args_first_half(args.begin(),
  978. args.begin() + args.size() / 2);
  979. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  980. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  981. 1e-3f);
  982. }
  983. TEST_F(ARM_COMMON_MULTI_THREADS,
  984. CONV_BIAS_WINOGRAD_MK_PACKED_F32_1_WEIGHT_PREPROCESS) {
  985. using namespace conv_bias;
  986. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  987. handle());
  988. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  989. const std::vector<size_t>& out_size, DType A_dtype,
  990. DType B_dtype, DType C_dtype, DType D_dtype,
  991. param::MatrixMul::Format format, float eps) {
  992. for (auto&& arg : args) {
  993. for (uint32_t m : out_size) {
  994. checker.set_extra_opr_impl(std::bind(
  995. winograd_algo_extra_impl, std::placeholders::_1, m,
  996. arg.param, handle, format));
  997. checker.set_dtype(0, A_dtype)
  998. .set_dtype(1, B_dtype)
  999. .set_dtype(2, C_dtype)
  1000. .set_dtype(4, D_dtype)
  1001. .set_epsilon(eps)
  1002. .set_param(arg.param)
  1003. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1004. }
  1005. }
  1006. };
  1007. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1008. std::vector<TestArg> args_first_half(args.begin(),
  1009. args.begin() + args.size() / 2);
  1010. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1011. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1012. 1e-3f);
  1013. }
  1014. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  1015. using namespace conv_bias;
  1016. Checker<ConvBiasForward> checker(handle());
  1017. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1018. const std::vector<size_t>& out_size, DType A_dtype,
  1019. DType B_dtype, DType C_dtype, DType D_dtype,
  1020. param::MatrixMul::Format format, float eps) {
  1021. for (auto&& arg : args) {
  1022. for (uint32_t m : out_size) {
  1023. checker.set_extra_opr_impl(std::bind(
  1024. winograd_algo_extra_impl, std::placeholders::_1, m,
  1025. arg.param, handle, format));
  1026. checker.set_dtype(0, A_dtype)
  1027. .set_dtype(1, B_dtype)
  1028. .set_dtype(2, C_dtype)
  1029. .set_dtype(4, D_dtype)
  1030. .set_epsilon(eps)
  1031. .set_param(arg.param)
  1032. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1033. }
  1034. }
  1035. };
  1036. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1037. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  1038. args.end());
  1039. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1040. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1041. 1e-3f);
  1042. }
  1043. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2_WEIGHT_PREPROCESS) {
  1044. using namespace conv_bias;
  1045. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1046. handle());
  1047. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1048. const std::vector<size_t>& out_size, DType A_dtype,
  1049. DType B_dtype, DType C_dtype, DType D_dtype,
  1050. param::MatrixMul::Format format, float eps) {
  1051. for (auto&& arg : args) {
  1052. for (uint32_t m : out_size) {
  1053. checker.set_extra_opr_impl(std::bind(
  1054. winograd_algo_extra_impl, std::placeholders::_1, m,
  1055. arg.param, handle, format));
  1056. checker.set_dtype(0, A_dtype)
  1057. .set_dtype(1, B_dtype)
  1058. .set_dtype(2, C_dtype)
  1059. .set_dtype(4, D_dtype)
  1060. .set_epsilon(eps)
  1061. .set_param(arg.param)
  1062. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1063. }
  1064. }
  1065. };
  1066. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1067. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  1068. args.end());
  1069. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1070. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1071. 1e-3f);
  1072. }
  1073. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1074. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  1075. using namespace conv_bias;
  1076. Checker<ConvBiasForward> checker(handle());
  1077. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1078. const std::vector<size_t>& out_size, DType A_dtype,
  1079. DType B_dtype, DType C_dtype, DType D_dtype,
  1080. param::MatrixMul::Format format, float eps) {
  1081. for (auto&& arg : args) {
  1082. for (uint32_t m : out_size) {
  1083. checker.set_extra_opr_impl(std::bind(
  1084. winograd_algo_extra_impl, std::placeholders::_1, m,
  1085. arg.param, handle, format));
  1086. checker.set_dtype(0, A_dtype)
  1087. .set_dtype(1, B_dtype)
  1088. .set_dtype(2, C_dtype)
  1089. .set_dtype(4, D_dtype)
  1090. .set_epsilon(eps)
  1091. .set_param(arg.param)
  1092. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1093. }
  1094. }
  1095. };
  1096. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1097. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1098. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  1099. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  1100. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  1101. 0.25);
  1102. }
  1103. TEST_F(ARM_COMMON_MULTI_THREADS,
  1104. CONV_BIAS_WINOGRAD_MK_PACKED_F16_WEIGHT_PREPROCESS) {
  1105. using namespace conv_bias;
  1106. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1107. handle());
  1108. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1109. const std::vector<size_t>& out_size, DType A_dtype,
  1110. DType B_dtype, DType C_dtype, DType D_dtype,
  1111. param::MatrixMul::Format format, float eps) {
  1112. for (auto&& arg : args) {
  1113. for (uint32_t m : out_size) {
  1114. checker.set_extra_opr_impl(std::bind(
  1115. winograd_algo_extra_impl, std::placeholders::_1, m,
  1116. arg.param, handle, format));
  1117. checker.set_dtype(0, A_dtype)
  1118. .set_dtype(1, B_dtype)
  1119. .set_dtype(2, C_dtype)
  1120. .set_dtype(4, D_dtype)
  1121. .set_epsilon(eps)
  1122. .set_param(arg.param)
  1123. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1124. }
  1125. }
  1126. };
  1127. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1128. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1129. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  1130. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  1131. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  1132. 0.25);
  1133. }
  1134. #endif
  1135. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  1136. using namespace conv_bias;
  1137. Checker<ConvBiasForward> checker(handle());
  1138. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1139. const std::vector<size_t>& out_size, DType A_dtype,
  1140. DType B_dtype, DType C_dtype, DType D_dtype,
  1141. param::MatrixMul::Format format, float eps) {
  1142. for (auto&& arg : args) {
  1143. for (uint32_t m : out_size) {
  1144. checker.set_extra_opr_impl(std::bind(
  1145. winograd_algo_extra_impl, std::placeholders::_1, m,
  1146. arg.param, handle, format));
  1147. checker.set_dtype(0, A_dtype)
  1148. .set_dtype(1, B_dtype)
  1149. .set_dtype(2, C_dtype)
  1150. .set_dtype(4, D_dtype)
  1151. .set_epsilon(eps)
  1152. .set_param(arg.param)
  1153. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1154. }
  1155. }
  1156. };
  1157. #if MEGDNN_AARCH64
  1158. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1159. #else
  1160. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1161. #endif
  1162. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1163. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1164. std::vector<TestArg> quantized_args =
  1165. get_quantized_winograd_mk_packed_args(8);
  1166. UniformIntRNG int_rng{-50, 50};
  1167. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1168. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1169. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1170. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1171. }
  1172. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8) {
  1173. using namespace conv_bias;
  1174. Checker<ConvBiasForward> checker(handle());
  1175. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1176. const std::vector<size_t>& out_size, DType A_dtype,
  1177. DType B_dtype, DType C_dtype, DType D_dtype,
  1178. param::MatrixMul::Format format, float eps) {
  1179. for (auto&& arg : args) {
  1180. for (uint32_t m : out_size) {
  1181. checker.set_extra_opr_impl(std::bind(
  1182. winograd_algo_extra_impl, std::placeholders::_1, m,
  1183. arg.param, handle, format));
  1184. checker.set_dtype(0, A_dtype)
  1185. .set_dtype(1, B_dtype)
  1186. .set_dtype(2, C_dtype)
  1187. .set_dtype(4, D_dtype)
  1188. .set_epsilon(eps)
  1189. .set_param(arg.param)
  1190. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1191. }
  1192. }
  1193. };
  1194. #if MEGDNN_AARCH64
  1195. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1196. #else
  1197. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1198. #endif
  1199. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1200. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1201. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1202. UniformIntRNG int_rng{-50, 50};
  1203. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1204. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1205. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1206. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1207. }
  1208. TEST_F(ARM_COMMON_MULTI_THREADS,
  1209. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE) {
  1210. using namespace conv_bias;
  1211. Checker<ConvBiasForward> checker(handle());
  1212. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1213. const std::vector<size_t>& out_size, DType A_dtype,
  1214. DType B_dtype, DType C_dtype, DType D_dtype,
  1215. param::MatrixMul::Format format, float eps) {
  1216. for (auto&& arg : args) {
  1217. for (uint32_t m : out_size) {
  1218. checker.set_extra_opr_impl(std::bind(
  1219. winograd_algo_extra_impl, std::placeholders::_1, m,
  1220. arg.param, handle, format));
  1221. checker.set_dtype(0, A_dtype)
  1222. .set_dtype(1, B_dtype)
  1223. .set_dtype(2, C_dtype)
  1224. .set_dtype(4, D_dtype)
  1225. .set_epsilon(eps)
  1226. .set_param(arg.param)
  1227. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1228. }
  1229. }
  1230. };
  1231. #if MEGDNN_AARCH64
  1232. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1233. #else
  1234. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1235. #endif
  1236. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1237. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1238. std::vector<TestArg> quantized_args =
  1239. get_int8_nchw44_args(3, 4, false, true);
  1240. UniformIntRNG int_rng{-50, 50};
  1241. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1242. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1243. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1244. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1245. }
  1246. TEST_F(ARM_COMMON_MULTI_THREADS,
  1247. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32) {
  1248. using namespace conv_bias;
  1249. Checker<ConvBiasForward> checker(handle());
  1250. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1251. const std::vector<size_t>& out_size, DType A_dtype,
  1252. DType B_dtype, DType C_dtype, DType D_dtype,
  1253. param::MatrixMul::Format format, float eps) {
  1254. for (auto&& arg : args) {
  1255. for (uint32_t m : out_size) {
  1256. checker.set_extra_opr_impl(std::bind(
  1257. winograd_algo_extra_impl, std::placeholders::_1, m,
  1258. arg.param, handle, format));
  1259. checker.set_dtype(0, A_dtype)
  1260. .set_dtype(1, B_dtype)
  1261. .set_dtype(2, C_dtype)
  1262. .set_dtype(4, D_dtype)
  1263. .set_epsilon(eps)
  1264. .set_param(arg.param)
  1265. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1266. }
  1267. }
  1268. };
  1269. float epsilon = 0.001;
  1270. #if MEGDNN_AARCH64
  1271. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1272. #else
  1273. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1274. #endif
  1275. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1276. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1277. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1278. UniformIntRNG int_rng{-50, 50};
  1279. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1280. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1281. dtype::QuantizedS8(0.01887994f),
  1282. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1283. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1284. epsilon);
  1285. }
  1286. TEST_F(ARM_COMMON_MULTI_THREADS,
  1287. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE) {
  1288. using namespace conv_bias;
  1289. Checker<ConvBiasForward> checker(handle());
  1290. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1291. const std::vector<size_t>& out_size, DType A_dtype,
  1292. DType B_dtype, DType C_dtype, DType D_dtype,
  1293. param::MatrixMul::Format format, float eps) {
  1294. for (auto&& arg : args) {
  1295. for (uint32_t m : out_size) {
  1296. checker.set_extra_opr_impl(std::bind(
  1297. winograd_algo_extra_impl, std::placeholders::_1, m,
  1298. arg.param, handle, format));
  1299. checker.set_dtype(0, A_dtype)
  1300. .set_dtype(1, B_dtype)
  1301. .set_dtype(2, C_dtype)
  1302. .set_dtype(4, D_dtype)
  1303. .set_epsilon(eps)
  1304. .set_param(arg.param)
  1305. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1306. }
  1307. }
  1308. };
  1309. float epsilon = 0.001;
  1310. #if MEGDNN_AARCH64
  1311. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1312. #else
  1313. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1314. #endif
  1315. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1316. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1317. std::vector<TestArg> quantized_args =
  1318. get_int8_nchw44_args(3, 4, true, true);
  1319. UniformIntRNG int_rng{-50, 50};
  1320. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1321. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1322. dtype::QuantizedS8(0.01887994f),
  1323. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1324. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1325. epsilon);
  1326. }
  1327. TEST_F(ARM_COMMON_MULTI_THREADS,
  1328. CONV_BIAS_WINOGRAD_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1329. using namespace conv_bias;
  1330. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1331. handle());
  1332. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1333. const std::vector<size_t>& out_size, DType A_dtype,
  1334. DType B_dtype, DType C_dtype, DType D_dtype,
  1335. param::MatrixMul::Format format, float eps) {
  1336. for (auto&& arg : args) {
  1337. for (uint32_t m : out_size) {
  1338. checker.set_extra_opr_impl(std::bind(
  1339. winograd_algo_extra_impl, std::placeholders::_1, m,
  1340. arg.param, handle, format));
  1341. checker.set_dtype(0, A_dtype)
  1342. .set_dtype(1, B_dtype)
  1343. .set_dtype(2, C_dtype)
  1344. .set_dtype(4, D_dtype)
  1345. .set_epsilon(eps)
  1346. .set_param(arg.param)
  1347. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1348. }
  1349. }
  1350. };
  1351. #if MEGDNN_AARCH64
  1352. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1353. #else
  1354. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1355. #endif
  1356. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1357. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1358. std::vector<TestArg> quantized_args =
  1359. get_quantized_winograd_mk_packed_args(8);
  1360. UniformIntRNG int_rng{-50, 50};
  1361. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1362. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1363. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1364. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1365. }
  1366. TEST_F(ARM_COMMON_MULTI_THREADS,
  1367. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1368. using namespace conv_bias;
  1369. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1370. handle());
  1371. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1372. const std::vector<size_t>& out_size, DType A_dtype,
  1373. DType B_dtype, DType C_dtype, DType D_dtype,
  1374. param::MatrixMul::Format format, float eps) {
  1375. for (auto&& arg : args) {
  1376. for (uint32_t m : out_size) {
  1377. checker.set_extra_opr_impl(std::bind(
  1378. winograd_algo_extra_impl, std::placeholders::_1, m,
  1379. arg.param, handle, format));
  1380. checker.set_dtype(0, A_dtype)
  1381. .set_dtype(1, B_dtype)
  1382. .set_dtype(2, C_dtype)
  1383. .set_dtype(4, D_dtype)
  1384. .set_epsilon(eps)
  1385. .set_param(arg.param)
  1386. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1387. }
  1388. }
  1389. };
  1390. #if MEGDNN_AARCH64
  1391. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1392. #else
  1393. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1394. #endif
  1395. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1396. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1397. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1398. UniformIntRNG int_rng{-50, 50};
  1399. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1400. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1401. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1402. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1403. }
  1404. TEST_F(ARM_COMMON_MULTI_THREADS,
  1405. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE_WEIGHT_PREPROCESS) {
  1406. using namespace conv_bias;
  1407. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1408. handle());
  1409. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1410. const std::vector<size_t>& out_size, DType A_dtype,
  1411. DType B_dtype, DType C_dtype, DType D_dtype,
  1412. param::MatrixMul::Format format, float eps) {
  1413. for (auto&& arg : args) {
  1414. for (uint32_t m : out_size) {
  1415. checker.set_extra_opr_impl(std::bind(
  1416. winograd_algo_extra_impl, std::placeholders::_1, m,
  1417. arg.param, handle, format));
  1418. checker.set_dtype(0, A_dtype)
  1419. .set_dtype(1, B_dtype)
  1420. .set_dtype(2, C_dtype)
  1421. .set_dtype(4, D_dtype)
  1422. .set_epsilon(eps)
  1423. .set_param(arg.param)
  1424. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1425. }
  1426. }
  1427. };
  1428. #if MEGDNN_AARCH64
  1429. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1430. #else
  1431. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1432. #endif
  1433. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1434. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1435. std::vector<TestArg> quantized_args =
  1436. get_int8_nchw44_args(3, 4, false, true);
  1437. UniformIntRNG int_rng{-50, 50};
  1438. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1439. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1440. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1441. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1442. }
  1443. TEST_F(ARM_COMMON_MULTI_THREADS,
  1444. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_WEIGHT_PREPROCESS) {
  1445. using namespace conv_bias;
  1446. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1447. handle());
  1448. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1449. const std::vector<size_t>& out_size, DType A_dtype,
  1450. DType B_dtype, DType C_dtype, DType D_dtype,
  1451. param::MatrixMul::Format format, float eps) {
  1452. for (auto&& arg : args) {
  1453. for (uint32_t m : out_size) {
  1454. checker.set_extra_opr_impl(std::bind(
  1455. winograd_algo_extra_impl, std::placeholders::_1, m,
  1456. arg.param, handle, format));
  1457. checker.set_dtype(0, A_dtype)
  1458. .set_dtype(1, B_dtype)
  1459. .set_dtype(2, C_dtype)
  1460. .set_dtype(4, D_dtype)
  1461. .set_epsilon(eps)
  1462. .set_param(arg.param)
  1463. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1464. }
  1465. }
  1466. };
  1467. float epsilon = 0.001;
  1468. #if MEGDNN_AARCH64
  1469. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1470. #else
  1471. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1472. #endif
  1473. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1474. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1475. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1476. UniformIntRNG int_rng{-50, 50};
  1477. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1478. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1479. dtype::QuantizedS8(0.01887994f),
  1480. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1481. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1482. epsilon);
  1483. }
  1484. TEST_F(ARM_COMMON_MULTI_THREADS,
  1485. WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE_WEIGHT_PREPROCESS) {
  1486. using namespace conv_bias;
  1487. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1488. handle());
  1489. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1490. const std::vector<size_t>& out_size, DType A_dtype,
  1491. DType B_dtype, DType C_dtype, DType D_dtype,
  1492. param::MatrixMul::Format format, float eps) {
  1493. for (auto&& arg : args) {
  1494. for (uint32_t m : out_size) {
  1495. checker.set_extra_opr_impl(std::bind(
  1496. winograd_algo_extra_impl, std::placeholders::_1, m,
  1497. arg.param, handle, format));
  1498. checker.set_dtype(0, A_dtype)
  1499. .set_dtype(1, B_dtype)
  1500. .set_dtype(2, C_dtype)
  1501. .set_dtype(4, D_dtype)
  1502. .set_epsilon(eps)
  1503. .set_param(arg.param)
  1504. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1505. }
  1506. }
  1507. };
  1508. float epsilon = 0.001;
  1509. #if MEGDNN_AARCH64
  1510. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1511. #else
  1512. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1513. #endif
  1514. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1515. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1516. std::vector<TestArg> quantized_args =
  1517. get_int8_nchw44_args(3, 4, true, true);
  1518. UniformIntRNG int_rng{-50, 50};
  1519. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1520. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1521. dtype::QuantizedS8(0.01887994f),
  1522. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1523. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1524. epsilon);
  1525. }
  1526. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1527. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  1528. using namespace conv_bias;
  1529. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1530. Checker<ConvBiasForward> checker(handle());
  1531. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1532. }
  1533. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  1534. using namespace conv_bias;
  1535. std::vector<TestArg> args = get_winograd_args(5);
  1536. std::vector<TestArg> args_head_half(args.begin(),
  1537. args.begin() + args.size() / 2);
  1538. Checker<ConvBiasForward> checker(handle());
  1539. //! fp16 range -1.0 ~ 1.0
  1540. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1541. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1542. }
  1543. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  1544. using namespace conv_bias;
  1545. std::vector<TestArg> args = get_winograd_args(5);
  1546. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1547. args.end());
  1548. Checker<ConvBiasForward> checker(handle());
  1549. //! fp16 range -1.0 ~ 1.0
  1550. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1551. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1552. }
  1553. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1554. //! it will pass when run single testcase
  1555. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  1556. using namespace conv_bias;
  1557. std::vector<TestArg> args = get_winograd_args(3);
  1558. Checker<ConvBiasForward> checker(handle());
  1559. //! fp16 range -1.0 ~ 1.0
  1560. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1561. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1562. }
  1563. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  1564. using namespace conv_bias;
  1565. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1566. std::vector<TestArg> args_head_half(args.begin(),
  1567. args.begin() + args.size() / 2);
  1568. Checker<ConvBiasForward> checker(handle());
  1569. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1570. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1571. param::MatrixMul::Format::MK8);
  1572. }
  1573. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  1574. using namespace conv_bias;
  1575. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1576. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1577. args.end());
  1578. Checker<ConvBiasForward> checker(handle());
  1579. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1580. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1581. param::MatrixMul::Format::MK8);
  1582. }
  1583. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23_WEIGHT_PREPROCESS) {
  1584. using namespace conv_bias;
  1585. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1586. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1587. handle());
  1588. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1589. }
  1590. TEST_F(ARM_COMMON_MULTI_THREADS,
  1591. CONV_BIAS_WINOGRAD_F16_F45_1_WEIGHT_PREPROCESS) {
  1592. using namespace conv_bias;
  1593. std::vector<TestArg> args = get_winograd_args(5);
  1594. std::vector<TestArg> args_head_half(args.begin(),
  1595. args.begin() + args.size() / 2);
  1596. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1597. handle());
  1598. //! fp16 range -1.0 ~ 1.0
  1599. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1600. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1601. }
  1602. TEST_F(ARM_COMMON_MULTI_THREADS,
  1603. CONV_BIAS_WINOGRAD_F16_F45_2_WEIGHT_PREPROCESS) {
  1604. using namespace conv_bias;
  1605. std::vector<TestArg> args = get_winograd_args(5);
  1606. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1607. args.end());
  1608. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1609. handle());
  1610. //! fp16 range -1.0 ~ 1.0
  1611. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1612. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1613. }
  1614. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1615. //! it will pass when run single testcase
  1616. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63_WEIGHT_PREPROCESS) {
  1617. using namespace conv_bias;
  1618. std::vector<TestArg> args = get_winograd_args(3);
  1619. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1620. handle());
  1621. //! fp16 range -1.0 ~ 1.0
  1622. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1623. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1624. }
  1625. TEST_F(ARM_COMMON_MULTI_THREADS,
  1626. CONV_BIAS_WINOGRAD_F16_8x8_1_WEIGHT_PREPROCESS) {
  1627. using namespace conv_bias;
  1628. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1629. std::vector<TestArg> args_head_half(args.begin(),
  1630. args.begin() + args.size() / 2);
  1631. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1632. handle());
  1633. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1634. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1635. param::MatrixMul::Format::MK8);
  1636. }
  1637. TEST_F(ARM_COMMON_MULTI_THREADS,
  1638. CONV_BIAS_WINOGRAD_F16_8x8_2_WEIGHT_PREPROCESS) {
  1639. using namespace conv_bias;
  1640. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1641. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1642. args.end());
  1643. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1644. handle());
  1645. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1646. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1647. param::MatrixMul::Format::MK8);
  1648. }
  1649. #endif
  1650. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  1651. using namespace conv_bias;
  1652. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1653. Checker<ConvBiasForward> checker(handle());
  1654. UniformIntRNG rng{-50, 50};
  1655. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1656. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1657. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1658. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1659. .set_rng(0, &rng)
  1660. .set_rng(1, &rng)
  1661. .set_rng(2, &rng);
  1662. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1663. }
  1664. TEST_F(ARM_COMMON_MULTI_THREADS,
  1665. CONV_BIAS_WINOGRAD_INT8_8X8_WEIGHT_PREPROCESS) {
  1666. using namespace conv_bias;
  1667. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1668. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1669. handle());
  1670. UniformIntRNG rng{-50, 50};
  1671. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1672. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1673. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1674. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1675. .set_rng(0, &rng)
  1676. .set_rng(1, &rng)
  1677. .set_rng(2, &rng);
  1678. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1679. }
  1680. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  1681. RNG* rng, float epsilon, DType type0, DType type1,
  1682. DType type2, DType type3, const char* algo_name) {
  1683. using namespace conv_bias;
  1684. Checker<ConvBias> checker(handle);
  1685. checker.set_before_exec_callback(
  1686. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1687. checker.set_dtype(0, type0);
  1688. checker.set_dtype(1, type1);
  1689. checker.set_dtype(2, type2);
  1690. checker.set_dtype(4, type3);
  1691. checker.set_epsilon(epsilon);
  1692. if (NULL != rng) {
  1693. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  1694. }
  1695. for (auto&& arg : args) {
  1696. checker.set_param(arg.param).execs(
  1697. {arg.src, arg.filter, arg.bias, {}, {}});
  1698. }
  1699. }
  1700. // clang-format off
  1701. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  1702. #define cb(name) \
  1703. check_conv_bias( \
  1704. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1705. handle(), name);
  1706. #if MEGDNN_AARCH64
  1707. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1708. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1709. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1710. #elif MEGDNN_ARMV7
  1711. cb("IM2COLMATMUL:ARMV7_F32")
  1712. #endif
  1713. #undef cb
  1714. }
  1715. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  1716. #define cb(name) \
  1717. check_conv_bias( \
  1718. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1719. handle(), name);
  1720. #if MEGDNN_AARCH64
  1721. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1722. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1723. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1724. #elif MEGDNN_ARMV7
  1725. cb("IM2COLMATMUL:ARMV7_F32")
  1726. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1727. #endif
  1728. #undef cb
  1729. }
  1730. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  1731. UniformIntRNG rng{-50, 50};
  1732. #define cb(name) \
  1733. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1734. false, true, true), \
  1735. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1736. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1737. dtype::QuantizedS8(60.25f), name); \
  1738. checker_conv_bias( \
  1739. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1740. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1741. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1742. dtype::QuantizedS8(60.25f), name);
  1743. float epsilon = 0.001;
  1744. #if MEGDNN_AARCH64
  1745. #if __ARM_FEATURE_DOTPROD
  1746. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1747. #else
  1748. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1749. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1750. #endif
  1751. #elif MEGDNN_ARMV7
  1752. epsilon = 1;
  1753. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1754. #endif
  1755. #undef cb
  1756. }
  1757. #if __ARM_FEATURE_DOTPROD
  1758. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT) {
  1759. UniformIntRNG rng{-50, 50};
  1760. #define cb(name) \
  1761. checker_conv_bias(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, \
  1762. false, false, false, true), \
  1763. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1764. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1765. dtype::QuantizedS8(60.25f), name); \
  1766. checker_conv_bias( \
  1767. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true), \
  1768. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1769. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1770. dtype::QuantizedS8(60.25f), name);
  1771. float epsilon = 0.001;
  1772. #if MEGDNN_AARCH64
  1773. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1774. #elif MEGDNN_ARMV7
  1775. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1776. #endif
  1777. #undef cb
  1778. }
  1779. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT_S2_FUSE) {
  1780. UniformIntRNG rng{-50, 50};
  1781. #define cb(name) \
  1782. checker_conv_bias(get_nchw44_conv_bias_args({3}, 2, false, \
  1783. false, false, false, true), \
  1784. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1785. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1786. dtype::QuantizedS8(60.25f), name); \
  1787. float epsilon = 0.001;
  1788. #if MEGDNN_AARCH64
  1789. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1790. #elif MEGDNN_ARMV7
  1791. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1792. #endif
  1793. #undef cb
  1794. }
  1795. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_S8x8x32_MK4_DOT) {
  1796. UniformIntRNG rng{-50, 50};
  1797. #define cb(name) \
  1798. checker_conv_bias( \
  1799. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1800. true, false, true, false, false, true), \
  1801. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1802. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1803. checker_conv_bias( \
  1804. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1805. false, false, true), \
  1806. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1807. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name);
  1808. float epsilon = 0.001;
  1809. #if MEGDNN_AARCH64
  1810. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1811. #elif MEGDNN_ARMV7
  1812. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1813. #endif
  1814. #undef cb
  1815. }
  1816. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32_MK4_DOT) {
  1817. UniformIntRNG rng{-50, 50};
  1818. #define cb(name) \
  1819. checker_conv_bias( \
  1820. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1821. true, false, true, false, false, true), \
  1822. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1823. dtype::Int32(), {}, name); \
  1824. checker_conv_bias( \
  1825. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1826. false, false, true), \
  1827. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1828. dtype::Int32(), {}, name);
  1829. float epsilon = 0.001;
  1830. #if MEGDNN_AARCH64
  1831. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1832. #elif MEGDNN_ARMV7
  1833. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1834. #endif
  1835. #undef cb
  1836. }
  1837. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CONV1x1_QUANTIZEDSYM_MK4_DOT) {
  1838. UniformIntRNG rng{-50, 50};
  1839. #define cb(name) \
  1840. checker_conv_bias( \
  1841. get_nchw44_conv_bias_args({1}, 1, true, true, false, false, true), \
  1842. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1843. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1844. dtype::QuantizedS8(60.25f), name); \
  1845. checker_conv_bias( \
  1846. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1847. false, false, true), \
  1848. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1849. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1850. checker_conv_bias( \
  1851. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1852. false, false, true), \
  1853. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1854. dtype::Int32(), {}, name);
  1855. float epsilon = 0.001;
  1856. #if MEGDNN_AARCH64
  1857. cb("CONV1x1:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD");
  1858. #elif MEGDNN_ARMV7
  1859. cb("CONV1x1:AARCH32_INT8_MK4_8X4X4_DOTPROD");
  1860. #endif
  1861. #undef cb
  1862. }
  1863. #endif
  1864. // clang-format on
  1865. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1866. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  1867. NormalRNG rng(128.f);
  1868. #define cb(name) \
  1869. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1870. false, true, true), \
  1871. handle(), &rng, epsilon, \
  1872. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1873. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1874. dtype::QuantizedS32(1.2 * 1.3), \
  1875. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1876. checker_conv_bias( \
  1877. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1878. handle(), &rng, epsilon, \
  1879. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1880. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1881. dtype::QuantizedS32(1.2 * 1.3), \
  1882. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1883. float epsilon = 0.001;
  1884. #if MEGDNN_AARCH64
  1885. #if __ARM_FEATURE_DOTPROD
  1886. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1887. #else
  1888. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1889. #endif
  1890. #elif MEGDNN_ARMV7
  1891. epsilon = 1;
  1892. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1893. #endif
  1894. #undef cb
  1895. }
  1896. #endif
  1897. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1898. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  1899. UniformIntRNG rng{-50, 50};
  1900. float epsilon = 0.001;
  1901. #define cb(name) \
  1902. checker_conv_bias( \
  1903. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1904. handle(), &rng, epsilon, \
  1905. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1906. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1907. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1908. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1909. &rng, epsilon, \
  1910. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1911. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1912. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1913. #if MEGDNN_AARCH64
  1914. #if __ARM_FEATURE_DOTPROD
  1915. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1916. #else
  1917. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1918. #endif
  1919. #elif MEGDNN_ARMV7
  1920. #if __ARM_FEATURE_DOTPROD
  1921. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1922. #endif
  1923. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1924. #endif
  1925. #undef cb
  1926. }
  1927. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  1928. UniformIntRNG rng{-50, 50};
  1929. float epsilon = 0.001;
  1930. #define cb(name) \
  1931. checker_conv_bias( \
  1932. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1933. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1934. dtype::Int16{}, dtype::Int16{}, name); \
  1935. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1936. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  1937. dtype::Int16{}, dtype::Int16{}, name);
  1938. #if MEGDNN_AARCH64
  1939. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  1940. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  1941. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1942. #elif MEGDNN_ARMV7
  1943. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  1944. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  1945. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  1946. #endif
  1947. #undef cb
  1948. }
  1949. #endif
  1950. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1951. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  1952. using namespace conv_bias;
  1953. param::ConvBias cur_param;
  1954. std::vector<conv_bias::TestArg> args =
  1955. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  1956. std::vector<conv_bias::TestArg> args1 =
  1957. get_conv_bias_args({1}, 2, false, false, false);
  1958. args.insert(args.begin(), args1.begin(), args1.end());
  1959. NormalRNG rng(1);
  1960. #define cb(name) \
  1961. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  1962. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  1963. name);
  1964. #if MEGDNN_AARCH64
  1965. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  1966. #elif MEGDNN_ARMV7
  1967. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  1968. #endif
  1969. #undef cb
  1970. }
  1971. #endif
  1972. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  1973. Handle* handle, const char* algo_name) {
  1974. using namespace conv_bias;
  1975. Checker<ConvBias> checker(handle);
  1976. checker.set_before_exec_callback(
  1977. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1978. checker.set_dtype(0, dtype::Int8());
  1979. checker.set_dtype(1, dtype::Int8());
  1980. checker.set_dtype(2, dtype::Int32());
  1981. checker.set_dtype(4, dtype::Int32());
  1982. for (auto&& arg : args) {
  1983. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  1984. }
  1985. UniformIntRNG rng{-50, 50};
  1986. for (auto&& arg : args) {
  1987. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1988. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1989. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1990. .set_dtype(4, {})
  1991. .set_rng(0, &rng)
  1992. .set_rng(1, &rng)
  1993. .set_rng(2, &rng)
  1994. .set_param(arg.param)
  1995. .execs({arg.src, arg.filter, {}, {}, {}});
  1996. }
  1997. }
  1998. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1999. #if !__ARM_FEATURE_DOTPROD
  2000. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  2001. using namespace conv_bias;
  2002. std::vector<conv_bias::TestArg> args =
  2003. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2004. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2005. #if MEGDNN_AARCH64
  2006. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2007. #else
  2008. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2009. #endif
  2010. #undef cb
  2011. }
  2012. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  2013. using namespace conv_bias;
  2014. std::vector<conv_bias::TestArg> args =
  2015. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2016. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2017. #if MEGDNN_AARCH64
  2018. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2019. #else
  2020. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2021. #endif
  2022. #undef cb
  2023. }
  2024. TEST_F(ARM_COMMON_MULTI_THREADS,
  2025. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  2026. UniformIntRNG rng{-50, 50};
  2027. #define cb(name) \
  2028. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  2029. epsilon, dtype::QuantizedS8(2.5f), \
  2030. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2031. dtype::QuantizedS8(60.25f), name);
  2032. float epsilon = 0.001;
  2033. #if MEGDNN_AARCH64
  2034. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2035. #else
  2036. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2037. #endif
  2038. #undef cb
  2039. }
  2040. TEST_F(ARM_COMMON_MULTI_THREADS,
  2041. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  2042. UniformIntRNG rng{-50, 50};
  2043. #define cb(name) \
  2044. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  2045. epsilon, dtype::QuantizedS8(2.5f), \
  2046. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2047. dtype::QuantizedS8(60.25f), name);
  2048. float epsilon = 0.001;
  2049. #if MEGDNN_AARCH64
  2050. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2051. #else
  2052. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2053. #endif
  2054. #undef cb
  2055. }
  2056. #if MEGDNN_AARCH64
  2057. TEST_F(ARM_COMMON_MULTI_THREADS,
  2058. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  2059. UniformIntRNG rng{-50, 50};
  2060. #define cb(name) \
  2061. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  2062. epsilon, dtype::QuantizedS8(2.5f), \
  2063. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2064. dtype::QuantizedS8(60.25f), name);
  2065. float epsilon = 0.001;
  2066. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2067. #undef cb
  2068. }
  2069. #endif
  2070. #endif
  2071. #endif
  2072. #if MEGDNN_AARCH64
  2073. #if __ARM_FEATURE_DOTPROD
  2074. TEST_F(ARM_COMMON_MULTI_THREADS,
  2075. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE) {
  2076. UniformIntRNG rng{-50, 50};
  2077. #define cb(name) \
  2078. checker_conv_bias( \
  2079. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2080. true, false, false, false), \
  2081. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2082. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2083. dtype::QuantizedS8(60.25f), name);
  2084. float epsilon = 0.001;
  2085. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2086. #undef cb
  2087. }
  2088. #endif
  2089. #endif
  2090. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  2091. using namespace conv_bias;
  2092. std::vector<conv_bias::TestArg> args =
  2093. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2094. std::vector<conv_bias::TestArg> args1 =
  2095. get_conv_bias_args({1}, 2, false, true, true);
  2096. args.insert(args.begin(), args1.begin(), args1.end());
  2097. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2098. #if MEGDNN_AARCH64
  2099. #if __ARM_FEATURE_DOTPROD
  2100. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2101. #else
  2102. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2103. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2104. #endif
  2105. #elif MEGDNN_ARMV7
  2106. #if __ARM_FEATURE_DOTPROD
  2107. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2108. #endif
  2109. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2110. #endif
  2111. #if MEGDNN_ARMV7
  2112. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2113. #endif
  2114. #undef cb
  2115. }
  2116. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  2117. using namespace conv_bias;
  2118. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2119. {2, 4, 7}, 1, false, false, false, false, false, true, true);
  2120. #if MEGDNN_AARCH64
  2121. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2122. #elif MEGDNN_ARMV7
  2123. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2124. #endif
  2125. }
  2126. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  2127. using namespace conv_bias;
  2128. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2129. {3, 5, 6}, 2, false, false, false, false, false, true, true);
  2130. #if MEGDNN_AARCH64
  2131. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2132. #elif MEGDNN_ARMV7
  2133. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2134. #endif
  2135. }
  2136. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE) {
  2137. using namespace conv_bias;
  2138. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2139. {3}, 2, false, false, false, false, false, true, true, false);
  2140. #if MEGDNN_AARCH64
  2141. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2142. #elif MEGDNN_ARMV7
  2143. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2144. #endif
  2145. }
  2146. /***************************** Conv1x1 Algo Test ***********************/
  2147. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  2148. using namespace conv_bias;
  2149. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2150. #if MEGDNN_AARCH64
  2151. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  2152. #elif MEGDNN_ARMV7
  2153. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  2154. #endif
  2155. std::vector<conv_bias::TestArg> gemv_args;
  2156. for (auto&& arg : args)
  2157. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2158. gemv_args.emplace_back(arg);
  2159. }
  2160. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2161. }
  2162. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  2163. using namespace conv_bias;
  2164. std::vector<conv_bias::TestArg> args =
  2165. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2166. #if MEGDNN_AARCH64
  2167. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2168. #elif MEGDNN_ARMV7
  2169. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2170. #endif
  2171. std::vector<conv_bias::TestArg> gemv_args;
  2172. for (auto&& arg : args)
  2173. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2174. gemv_args.emplace_back(arg);
  2175. }
  2176. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2177. }
  2178. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  2179. using namespace conv_bias;
  2180. std::vector<conv_bias::TestArg> args =
  2181. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2182. std::vector<conv_bias::TestArg> args_of_4;
  2183. for (auto&& arg : args) {
  2184. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  2185. args_of_4.push_back(arg);
  2186. }
  2187. }
  2188. #if MEGDNN_AARCH64
  2189. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  2190. #elif MEGDNN_ARMV7
  2191. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  2192. #endif
  2193. }
  2194. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2195. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  2196. using namespace conv_bias;
  2197. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2198. NormalRNG rng(1);
  2199. #if MEGDNN_AARCH64
  2200. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2201. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2202. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2203. #elif MEGDNN_ARMV7
  2204. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2205. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2206. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2207. #endif
  2208. std::vector<conv_bias::TestArg> gemv_args;
  2209. for (auto&& arg : args)
  2210. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2211. gemv_args.emplace_back(arg);
  2212. }
  2213. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2214. }
  2215. #endif
  2216. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  2217. UniformIntRNG rng{-50, 50};
  2218. float epsilon = 0.001;
  2219. std::vector<conv_bias::TestArg> args =
  2220. get_conv_bias_1x1_args(false, false, true, true);
  2221. #define cb(name) \
  2222. checker_conv_bias(args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2223. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2224. dtype::QuantizedS8(60.25f), name);
  2225. #if MEGDNN_AARCH64
  2226. #if __ARM_FEATURE_DOTPROD
  2227. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2228. #else
  2229. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2230. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2231. #endif
  2232. #elif MEGDNN_ARMV7
  2233. epsilon = 1;
  2234. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2235. #endif
  2236. #undef cb
  2237. std::vector<conv_bias::TestArg> gemv_args;
  2238. for (auto&& arg : args)
  2239. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2240. gemv_args.emplace_back(arg);
  2241. }
  2242. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2243. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2244. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2245. "CONV1x1_GEMV");
  2246. }
  2247. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2248. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  2249. UniformIntRNG rng{-50, 50};
  2250. std::vector<conv_bias::TestArg> args =
  2251. get_conv_bias_1x1_args(false, false, true, true);
  2252. #define cb(name) \
  2253. checker_conv_bias(args, handle(), &rng, epsilon, \
  2254. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2255. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2256. dtype::QuantizedS32(1.2 * 1.3), \
  2257. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2258. float epsilon = 0.001;
  2259. #if MEGDNN_AARCH64
  2260. #if __ARM_FEATURE_DOTPROD
  2261. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2262. #else
  2263. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2264. #endif
  2265. #elif MEGDNN_ARMV7
  2266. epsilon = 1;
  2267. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2268. #endif
  2269. #undef cb
  2270. std::vector<conv_bias::TestArg> gemv_args;
  2271. for (auto&& arg : args)
  2272. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2273. gemv_args.emplace_back(arg);
  2274. }
  2275. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2276. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2277. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2278. dtype::QuantizedS32(1.2 * 1.3),
  2279. dtype::Quantized8Asymm(50.3f, (uint8_t)120),
  2280. "CONV1x1_GEMV");
  2281. }
  2282. #endif
  2283. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2284. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  2285. NormalRNG rng(128.f);
  2286. float epsilon = 0.001;
  2287. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2288. #define cb(name) \
  2289. checker_conv_bias(args, handle(), &rng, epsilon, \
  2290. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2291. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2292. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2293. #if MEGDNN_AARCH64
  2294. #if __ARM_FEATURE_DOTPROD
  2295. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2296. #else
  2297. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2298. #endif
  2299. #elif MEGDNN_ARMV7
  2300. #if __ARM_FEATURE_DOTPROD
  2301. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2302. #endif
  2303. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2304. #endif
  2305. #undef cb
  2306. std::vector<conv_bias::TestArg> gemv_args;
  2307. for (auto&& arg : args)
  2308. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2309. gemv_args.emplace_back(arg);
  2310. }
  2311. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2312. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2313. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2314. dtype::QuantizedS32(1.2 * 1.3), {}, "CONV1x1_GEMV");
  2315. }
  2316. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  2317. UniformIntRNG rng{-50, 50};
  2318. float epsilon = 0.001;
  2319. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2320. #define cb(name) \
  2321. checker_conv_bias(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2322. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2323. #if MEGDNN_AARCH64
  2324. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2325. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2326. #elif MEGDNN_ARMV7
  2327. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2328. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2329. #endif
  2330. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  2331. #undef cb
  2332. std::vector<conv_bias::TestArg> gemv_args;
  2333. for (auto&& arg : args)
  2334. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2335. gemv_args.emplace_back(arg);
  2336. }
  2337. checker_conv_bias(gemv_args, handle(), &rng, epsilon, dtype::Int8{},
  2338. dtype::Int8{}, dtype::Int16{}, dtype::Int16{},
  2339. "CONV1x1_GEMV");
  2340. }
  2341. #endif
  2342. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  2343. using namespace conv_bias;
  2344. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2345. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2346. #if MEGDNN_AARCH64
  2347. #if __ARM_FEATURE_DOTPROD
  2348. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2349. #else
  2350. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2351. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2352. #endif
  2353. #elif MEGDNN_ARMV7
  2354. #if __ARM_FEATURE_DOTPROD
  2355. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2356. #endif
  2357. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2358. #endif
  2359. #if MEGDNN_ARMV7
  2360. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2361. #endif
  2362. #undef cb
  2363. std::vector<conv_bias::TestArg> gemv_args;
  2364. for (auto&& arg : args)
  2365. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2366. gemv_args.emplace_back(arg);
  2367. }
  2368. checker_conv_bias_mul_int8x8x32(gemv_args, handle(), "CONV1x1_GEMV");
  2369. }
  2370. #ifndef __ARM_FEATURE_DOTPROD
  2371. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  2372. using namespace conv_bias;
  2373. std::vector<conv_bias::TestArg> args =
  2374. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2375. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2376. #if MEGDNN_AARCH64
  2377. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2378. #elif MEGDNN_ARMV7
  2379. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2380. #endif
  2381. #undef cb
  2382. UniformIntRNG rng{-50, 50};
  2383. float epsilon = 0.001;
  2384. #define cb(name) \
  2385. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2386. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2387. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2388. dtype::QuantizedS8(60.25f), name);
  2389. #if MEGDNN_AARCH64
  2390. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2391. #elif MEGDNN_ARMV7
  2392. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2393. #endif
  2394. #undef cb
  2395. }
  2396. #endif
  2397. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  2398. using namespace conv_bias;
  2399. std::vector<conv_bias::TestArg> args =
  2400. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2401. UniformIntRNG rng{-50, 50};
  2402. float epsilon = 0.001;
  2403. std::vector<conv_bias::TestArg> gemv_args;
  2404. for (auto&& arg : args)
  2405. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2406. gemv_args.emplace_back(arg);
  2407. }
  2408. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2409. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2410. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2411. "CONV1x1_GEMV");
  2412. }
  2413. #ifdef __ARM_FEATURE_DOTPROD
  2414. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  2415. using namespace conv_bias;
  2416. std::vector<conv_bias::TestArg> args =
  2417. get_nchw44_conv_bias_args({1}, 1, true, false, false, false, true);
  2418. UniformIntRNG rng{-50, 50};
  2419. float epsilon = 0.001;
  2420. std::vector<conv_bias::TestArg> gemv_args;
  2421. for (auto&& arg : args)
  2422. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2423. gemv_args.emplace_back(arg);
  2424. }
  2425. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2426. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2427. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2428. "CONV1x1_GEMV");
  2429. }
  2430. #endif
  2431. // vim: syntax=cpp.doxygen

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