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

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

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