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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140
  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. MEGDNN_MARK_USED_VAR(no_pad);
  76. auto pack = [&](size_t n, size_t oc, size_t ic, size_t h, size_t w,
  77. size_t kernel, size_t stride, size_t group, NLMode nlmode,
  78. megdnn::BiasMode bias_mode, int any_pad = -1) {
  79. constexpr int pack_c = 4;
  80. const size_t pad = any_pad >= 0 ? any_pad : kernel / 2;
  81. auto oc_per_group = oc / group;
  82. auto ic_per_group = ic / group;
  83. bool ok_group = (oc % group == 0 && ic % group == 0) &&
  84. oc_per_group % pack_c == 0 && oc_per_group > 0 &&
  85. ic_per_group > 0;
  86. bool nchw_disable = group > 1 || ic_per_group >= 4;
  87. bool nchw44_disable = ic_per_group % pack_c != 0;
  88. bool invalid_pad = (w + 2 * pad < kernel) || (h + 2 * pad < kernel);
  89. if (!(ok_group) || invalid_pad) {
  90. return;
  91. }
  92. if ((is_input_nchw && nchw_disable) ||
  93. (!is_input_nchw && nchw44_disable)) {
  94. return;
  95. }
  96. size_t kernel_h = kernel;
  97. size_t kernel_w = kernel;
  98. param::ConvBias param;
  99. if (!is_nchw44_dot) {
  100. param.format = param::ConvBias::Format::NCHW44;
  101. } else {
  102. param.format = param::ConvBias::Format::NCHW44_DOT;
  103. }
  104. param.stride_h = stride;
  105. param.stride_w = stride;
  106. param.pad_h = pad;
  107. param.pad_w = pad;
  108. param.nonlineMode = nlmode;
  109. auto src_tensor_shape = TensorShape{n, ic / pack_c, h, w, pack_c};
  110. auto weight_tensor_shape = TensorShape{
  111. oc / pack_c, ic / pack_c, kernel_h, kernel_w, pack_c, pack_c};
  112. auto bias_tensor_shape = TensorShape{};
  113. if (bias_mode == megdnn::BiasMode::BROADCAST_CHANNEL_BIAS) {
  114. bias_tensor_shape = {1, oc / pack_c, 1, 1, pack_c};
  115. } else if (bias_mode == megdnn::BiasMode::BIAS) {
  116. bias_tensor_shape = {n, oc / pack_c,
  117. (h + 2 * pad - kernel) / stride + 1,
  118. (w + 2 * pad - kernel) / stride + 1, pack_c};
  119. }
  120. if (group == 1) {
  121. param.sparse = param::ConvBias::Sparse::DENSE;
  122. } else if (group > 1 && ic / group == 1 && oc / group == 1) {
  123. megdnn_assert(0, "not support channel wise");
  124. param.sparse = param::ConvBias::Sparse::GROUP;
  125. weight_tensor_shape = TensorShape{group / pack_c, 1, 1,
  126. kernel_h, kernel_w, pack_c};
  127. } else if (group > 1 && oc_per_group % pack_c == 0 && oc / group > 0 &&
  128. ic_per_group % pack_c == 0 && ic / group > 0) {
  129. param.sparse = param::ConvBias::Sparse::GROUP;
  130. weight_tensor_shape = TensorShape{group,
  131. oc_per_group / pack_c,
  132. ic_per_group / pack_c,
  133. kernel_h,
  134. kernel_w,
  135. pack_c,
  136. pack_c};
  137. }
  138. if (is_input_nchw) {
  139. src_tensor_shape = TensorShape{n, ic, h, w};
  140. weight_tensor_shape =
  141. TensorShape{oc / pack_c, kernel_h, kernel_w, ic, pack_c};
  142. }
  143. args.emplace_back(param, src_tensor_shape, weight_tensor_shape,
  144. bias_tensor_shape);
  145. };
  146. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  147. if (!no_nonlinemode) {
  148. nonlinemode.emplace_back(NLMode::RELU);
  149. nonlinemode.emplace_back(NLMode::H_SWISH);
  150. }
  151. if (support_sigmoid) {
  152. nonlinemode.emplace_back(NLMode::SIGMOID);
  153. }
  154. std::vector<megdnn::BiasMode> bias_mode;
  155. if (!only_no_bias) {
  156. bias_mode.emplace_back(megdnn::BiasMode::BROADCAST_CHANNEL_BIAS);
  157. if (no_bias) {
  158. bias_mode.emplace_back(megdnn::BiasMode::NO_BIAS);
  159. }
  160. } else {
  161. bias_mode.emplace_back(megdnn::BiasMode::NO_BIAS);
  162. }
  163. if (support_full_bias) {
  164. bias_mode.emplace_back(megdnn::BiasMode::BIAS);
  165. }
  166. for (auto bias : bias_mode)
  167. for (auto nlmode : nonlinemode)
  168. for (size_t n : {1, 2})
  169. for (size_t kernel : kernel_vec)
  170. for (size_t oc : {4, 12})
  171. for (size_t ic : {1, 3, 4, 12})
  172. for (size_t h : {1, 3, 12})
  173. for (size_t w : {1, 16, 23}) {
  174. for (size_t group = 1;
  175. group <=
  176. std::min(std::min(oc, ic), 4_z);
  177. ++group) {
  178. if (kernel != 1 && (h == 1 || w == 1)) {
  179. continue;
  180. }
  181. pack(n, oc, ic, h, w, kernel, stride,
  182. group, nlmode, bias);
  183. }
  184. }
  185. return args;
  186. }
  187. std::vector<conv_bias::TestArg> get_nchw44_channel_wise_args(
  188. std::vector<size_t> kernel, size_t stride, bool no_bias,
  189. bool no_nonlinemode, bool no_full_bias) {
  190. using namespace conv_bias;
  191. using Param = param::ConvBias;
  192. using NLMode = param::ConvBias::NonlineMode;
  193. std::vector<TestArg> args;
  194. auto pack = [&](size_t n, size_t group, size_t w, size_t h, size_t kernel,
  195. size_t stride, NLMode nlmode, bool pad) {
  196. Param param;
  197. param.stride_h = stride;
  198. param.stride_w = stride;
  199. if (pad) {
  200. param.pad_h = kernel / 2;
  201. param.pad_w = kernel / 2;
  202. } else {
  203. param.pad_h = 0;
  204. param.pad_w = 0;
  205. }
  206. param.nonlineMode = nlmode;
  207. param.format = param::ConvBias::Format::NCHW44;
  208. param.sparse = param::ConvBias::Sparse::GROUP;
  209. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  210. TensorShape{group, 1, 1, kernel, kernel, 4},
  211. TensorShape{});
  212. if (!no_bias) {
  213. args.emplace_back(param, TensorShape{n, group, h, w, 4},
  214. TensorShape{group, 1, 1, kernel, kernel, 4},
  215. TensorShape{1, group, 1, 1, 4});
  216. }
  217. if (!no_full_bias) {
  218. args.emplace_back(
  219. param, TensorShape{n, group, h, w, 4},
  220. TensorShape{group, 1, 1, kernel, kernel, 4},
  221. TensorShape{n, group,
  222. (h + 2 * param.pad_w - kernel) / stride + 1,
  223. (w + 2 * param.pad_w - kernel) / stride + 1,
  224. 4});
  225. }
  226. };
  227. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  228. if (!no_nonlinemode) {
  229. nonlinemode.emplace_back(NLMode::RELU);
  230. nonlinemode.emplace_back(NLMode::H_SWISH);
  231. }
  232. for (size_t n : {1, 2}) {
  233. for (auto nlmode : nonlinemode) {
  234. for (bool pad : {true}) {
  235. for (size_t group : {1, 2, 4, 7, 128}) {
  236. for (size_t size : {4, 6, 7, 9, 15, 40}) {
  237. for (size_t kern : kernel) {
  238. pack(n, group, size, size, kern, stride, nlmode,
  239. pad);
  240. }
  241. }
  242. }
  243. }
  244. for (bool pad : {false}) {
  245. for (size_t group : {1, 2, 7, 128}) {
  246. for (size_t size : {7, 9, 15, 40}) {
  247. for (size_t kern : kernel) {
  248. pack(n, group, size, size, kern, stride, nlmode,
  249. pad);
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. return args;
  257. }
  258. void checker_conv_bias_qint8x8x8(std::vector<conv_bias::TestArg> args,
  259. Handle* handle, const char* algo_name) {
  260. Checker<ConvBias> checker(handle);
  261. checker.set_before_exec_callback(
  262. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  263. #if MEGDNN_ARMV7
  264. checker.set_epsilon(1);
  265. #endif
  266. UniformIntRNG rng{-50, 50};
  267. checker.set_dtype(0, dtype::QuantizedS8(0.41113496f))
  268. .set_dtype(1, dtype::QuantizedS8(0.01887994f))
  269. .set_dtype(2, dtype::QuantizedS32(0.41113496f * 0.01887994f))
  270. .set_dtype(4, dtype::QuantizedS8(0.49550694f))
  271. .set_rng(0, &rng)
  272. .set_rng(1, &rng)
  273. .set_rng(2, &rng);
  274. for (auto&& arg : args) {
  275. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  276. }
  277. }
  278. void checker_conv_bias_qint8x8x32(std::vector<conv_bias::TestArg> args,
  279. Handle* handle, const char* algo_name) {
  280. Checker<ConvBias> checker(handle);
  281. UniformIntRNG rng{-50, 50};
  282. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  283. .set_dtype(1, dtype::QuantizedS8(2.5f))
  284. .set_dtype(2, dtype::QuantizedS32(6.25f))
  285. .set_dtype(4, {});
  286. checker.set_before_exec_callback(
  287. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  288. for (auto&& arg : args) {
  289. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  290. }
  291. }
  292. void checker_conv_bias_quint8x8x8(std::vector<conv_bias::TestArg> args,
  293. Handle* handle, const char* algo_name) {
  294. Checker<ConvBias> checker(handle);
  295. checker.set_before_exec_callback(
  296. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  297. UniformIntRNG rng(0, 255);
  298. checker.set_dtype(0, dtype::Quantized8Asymm(0.2f, 100))
  299. .set_dtype(1, dtype::Quantized8Asymm(0.2f, 120))
  300. .set_dtype(2, dtype::QuantizedS32(0.04f))
  301. .set_dtype(4, dtype::Quantized8Asymm(1.4f, 110))
  302. .set_rng(0, &rng)
  303. .set_rng(1, &rng)
  304. .set_rng(2, &rng);
  305. for (auto&& arg : args) {
  306. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  307. }
  308. }
  309. void checker_conv_bias_quint8x8x32(std::vector<conv_bias::TestArg> args,
  310. Handle* handle, const char* algo_name) {
  311. Checker<ConvBias> checker(handle);
  312. checker.set_before_exec_callback(
  313. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  314. NormalRNG rng(128.f);
  315. checker.set_rng(0, &rng).set_rng(1, &rng);
  316. checker.set_dtype(0, dtype::Quantized8Asymm(1.2f, (uint8_t)127))
  317. .set_dtype(1, dtype::Quantized8Asymm(1.3f, (uint8_t)129))
  318. .set_dtype(2, dtype::QuantizedS32(1.2 * 1.3))
  319. .set_dtype(4, {});
  320. for (auto&& arg : args) {
  321. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  322. }
  323. }
  324. void checker_conv_bias_int8x8x32_multi(std::vector<conv_bias::TestArg> args,
  325. Handle* handle, const char* algo_name) {
  326. Checker<ConvBias> checker(handle);
  327. checker.set_before_exec_callback(
  328. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  329. checker.set_dtype(0, dtype::Int8());
  330. checker.set_dtype(1, dtype::Int8());
  331. checker.set_dtype(2, dtype::Int32());
  332. checker.set_dtype(4, dtype::Int32());
  333. for (auto&& arg : args) {
  334. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  335. }
  336. }
  337. /**********************************F32 direct************************/
  338. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_LARGE_GROUP) {
  339. check_conv_bias(
  340. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  341. handle(), "F32DIRECT_LARGE_GROUP");
  342. }
  343. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_SMALL_GROUP) {
  344. check_conv_bias(
  345. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  346. handle(), "F32DIRECT_SMALL_GROUP");
  347. }
  348. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K7) {
  349. check_conv_bias(get_nchw44_conv_bias_args({7}, 1, false, true, true, false,
  350. false, false),
  351. handle(), "F32_CONV_NCHW44_DIRECT");
  352. }
  353. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K2K3) {
  354. check_conv_bias(get_nchw44_conv_bias_args({2, 3}, 1, false, false, false,
  355. false, false, true, true),
  356. handle(), "F32_CONV_NCHW44_DIRECT");
  357. }
  358. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S1_K5) {
  359. check_conv_bias(get_nchw44_conv_bias_args({5}, 1, false, false, false,
  360. false, false, true, true),
  361. handle(), "F32_CONV_NCHW44_DIRECT");
  362. }
  363. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_NCHW44_S2) {
  364. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  365. false, false, false, true, true),
  366. handle(), "F32_CONV_NCHW44_DIRECT");
  367. }
  368. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_LARGE_GROUP) {
  369. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  370. handle(), "F32STRD1_LARGE_GROUP");
  371. }
  372. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR1_SMALL_GROUP) {
  373. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  374. handle(), "F32STRD1_SMALL_GROUP");
  375. }
  376. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_LARGE_GROUP) {
  377. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  378. handle(), "F32STRD2_LARGE_GROUP");
  379. }
  380. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP32_STR2_SMALL_GROUP) {
  381. check_conv_bias(get_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  382. handle(), "F32STRD2_SMALL_GROUP");
  383. }
  384. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_NCHW_NCHW44_F32_S2) {
  385. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false,
  386. false, true),
  387. handle(), "F32_CONV_NCHW_NCHW44");
  388. }
  389. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_NCHW_NCHW44_F32_S1) {
  390. check_conv_bias(get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false,
  391. false, true),
  392. handle(), "F32_CONV_NCHW_NCHW44");
  393. }
  394. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE1_FP32_NCHW44_1) {
  395. check_conv_bias(
  396. get_nchw44_channel_wise_args({2, 3}, 1, false, false, false),
  397. handle(), "F32_CHANNEL_WISE_NCHW44");
  398. }
  399. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE1_FP32_NCHW44_2) {
  400. check_conv_bias(get_nchw44_channel_wise_args({5}, 1, false, false, false),
  401. handle(), "F32_CHANNEL_WISE_NCHW44");
  402. }
  403. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CHANNEL_WISE_STRIDE2_FP32_NCHW44) {
  404. check_conv_bias(
  405. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, false, false),
  406. handle(), "F32_CHANNEL_WISE_NCHW44");
  407. }
  408. /**********************************F16 direct************************/
  409. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  410. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_LARGE_GROUP) {
  411. NormalRNG rng(1);
  412. checker_conv_bias_f16(
  413. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  414. handle(), rng, "F16DIRECT_LARGE_GROUP", 0.03);
  415. }
  416. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_SMALL_GROUP) {
  417. NormalRNG rng(1);
  418. checker_conv_bias_f16(
  419. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 1, false, false, false),
  420. handle(), rng, "F16DIRECT_SMALL_GROUP", 0.03);
  421. }
  422. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_LARGE_GROUP) {
  423. NormalRNG rng(1);
  424. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  425. handle(), rng, "F16STRD1_LARGE_GROUP", 0.03);
  426. }
  427. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_DIRECT_FP16_STR1_SMALL_GROUP) {
  428. NormalRNG rng(1);
  429. checker_conv_bias_f16(get_conv_bias_args({2, 3, 5}, 1, false, false, false),
  430. handle(), rng, "F16STRD1_SMALL_GROUP", 0.03);
  431. }
  432. #endif
  433. /**********************************algo 8816 direct************************/
  434. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_LARGE_GROUP) {
  435. checker_conv_bias_int8x8x16(
  436. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  437. "I8816DIRECT_LARGE_GROUP");
  438. }
  439. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_DIRECT_SMALL_GROUP) {
  440. checker_conv_bias_int8x8x16(
  441. get_conv_bias_args({2, 3, 5}, 1, false, true, true), handle(),
  442. "I8816DIRECT_SMALL_GROUP");
  443. }
  444. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_LARGE_GROUP) {
  445. checker_conv_bias_int8x8x16(
  446. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  447. "I8816STRD2_LARGE_GROUP");
  448. }
  449. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT16_STRIDE2_SMALL_GROUP) {
  450. checker_conv_bias_int8x8x16(
  451. get_conv_bias_args({2, 3, 5}, 2, false, true, true), handle(),
  452. "I8816STRD2_SMALL_GROUP");
  453. }
  454. /**********************************algo 8-8-32 direct************************/
  455. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_LARGE_GROUP) {
  456. checker_conv_bias_int8x8x32_multi(
  457. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  458. "S8STRD1_LARGE_GROUP");
  459. }
  460. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE1_SMALL_GROUP) {
  461. checker_conv_bias_int8x8x32_multi(
  462. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  463. "S8STRD1_SMALL_GROUP");
  464. }
  465. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_LARGE_GROUP) {
  466. checker_conv_bias_int8x8x32_multi(
  467. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  468. "S8STRD2_LARGE_GROUP");
  469. }
  470. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_INT8_INT32_STRIDE2_SMALL_GROUP) {
  471. checker_conv_bias_int8x8x32_multi(
  472. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  473. "S8STRD2_SMALL_GROUP");
  474. }
  475. TEST_F(ARM_COMMON_MULTI_THREADS,
  476. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT1_NCHW44) {
  477. checker_conv_bias_int8x8x32_multi(
  478. get_nchw44_channel_wise_args({2, 3, 5}, 1, false, true, true),
  479. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  480. }
  481. TEST_F(ARM_COMMON_MULTI_THREADS,
  482. CONV_BIAS_INT8_INT8_INT32_CHANNEL_WISE_DIRECT2_NCHW44) {
  483. checker_conv_bias_int8x8x32_multi(
  484. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, true, true),
  485. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  486. }
  487. /********************************qint8 direct******************************/
  488. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_LARGE_GROUP) {
  489. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  490. {2, 3, 5, 7}, 1, false, false, false),
  491. handle(), "S8STRD1_LARGE_GROUP");
  492. }
  493. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_SMALL_GROUP) {
  494. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  495. {2, 3, 5, 7}, 1, false, false, false),
  496. handle(), "S8STRD1_SMALL_GROUP");
  497. }
  498. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_LARGE_GROUP) {
  499. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  500. {2, 3, 5, 7}, 2, false, false, false),
  501. handle(), "S8STRD2_LARGE_GROUP");
  502. }
  503. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_SMALL_GROUP) {
  504. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  505. {2, 3, 5, 7}, 2, false, false, false),
  506. handle(), "S8STRD2_SMALL_GROUP");
  507. }
  508. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_NCHW44) {
  509. checker_conv_bias_qint8x8x8(
  510. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false),
  511. handle(), "S8_NCHW44_DIRECT");
  512. }
  513. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE1_NCHW44_8832) {
  514. checker_conv_bias_qint8x8x32(
  515. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, true),
  516. handle(), "S8_NCHW44_DIRECT");
  517. }
  518. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_NCHW44_8832) {
  519. checker_conv_bias_qint8x8x32(
  520. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, true),
  521. handle(), "S8_NCHW44_DIRECT");
  522. }
  523. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_STRIDE2_NCHW44) {
  524. checker_conv_bias_qint8x8x8(
  525. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false),
  526. handle(), "S8_NCHW44_DIRECT");
  527. }
  528. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT1_NCHW44) {
  529. checker_conv_bias_qint8x8x8(
  530. get_nchw44_channel_wise_args({2, 3, 5}, 1, false, false, true),
  531. handle(), "S8_CHAN_WISE_STRD1_NCHW44");
  532. }
  533. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QS8_CHANNEL_WISE_DIRECT2_NCHW44) {
  534. checker_conv_bias_qint8x8x8(
  535. get_nchw44_channel_wise_args({2, 3, 5}, 2, false, false, true),
  536. handle(), "S8_CHAN_WISE_STRD2_NCHW44");
  537. }
  538. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_NCHW_NCHW44_S1) {
  539. checker_conv_bias_qint8x8x8(
  540. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false,
  541. true),
  542. handle(), "S8_CONV_NCHW_NCHW44");
  543. }
  544. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_INT8_NCHW_NCHW44_S2) {
  545. checker_conv_bias_qint8x8x8(
  546. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false,
  547. true),
  548. handle(), "S8_CONV_NCHW_NCHW44");
  549. }
  550. /*****************************quint8 direct****************************/
  551. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_LARGE_GROUP) {
  552. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  553. {2, 3, 5, 7}, 1, false, false, false),
  554. handle(), "QU8STRD1_LARGE_GROUP");
  555. }
  556. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE1_SMALL_GROUP) {
  557. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  558. {2, 3, 5, 7}, 1, false, false, false),
  559. handle(), "QU8STRD1_SMALL_GROUP");
  560. }
  561. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_LARGE_GROUP) {
  562. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  563. {2, 3, 5, 7}, 2, false, false, false),
  564. handle(), "QU8STRD2_LARGE_GROUP");
  565. }
  566. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_QUINT8_STRIDE2_SMALL_GROUP) {
  567. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  568. {2, 3, 5, 7}, 2, false, false, false),
  569. handle(), "QU8STRD2_SMALL_GROUP");
  570. }
  571. /****************************dot qint8 direct*************************/
  572. #if __ARM_FEATURE_DOTPROD
  573. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_DOT_NCHW_NCHW44) {
  574. auto args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, false, false,
  575. true);
  576. for (auto&& arg : args) {
  577. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  578. }
  579. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8_NCHW_NCHW44");
  580. args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, false, false,
  581. true);
  582. for (auto&& arg : args) {
  583. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  584. }
  585. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8_NCHW_NCHW44");
  586. }
  587. TEST_F(ARM_COMMON_MULTI_THREADS,
  588. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  589. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  590. {2, 3, 5, 7}, 1, false, false, false),
  591. handle(), "ARMDOTS8STRD1_LARGE_GROUP");
  592. }
  593. TEST_F(ARM_COMMON_MULTI_THREADS,
  594. CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  595. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  596. {2, 3, 5, 7}, 1, false, false, false),
  597. handle(), "ARMDOTS8STRD1_SMALL_GROUP");
  598. }
  599. TEST_F(ARM_COMMON_MULTI_THREADS,
  600. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  601. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  602. {2, 3, 5, 7}, 2, false, false, false),
  603. handle(), "ARMDOTS8STRD2_LARGE_GROUP");
  604. }
  605. TEST_F(ARM_COMMON_MULTI_THREADS,
  606. CONV_BIAS_INT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  607. checker_conv_bias_qint8x8x8(get_int8_quint8_conv_bias_args(
  608. {2, 3, 5, 7}, 2, false, false, false),
  609. handle(), "ARMDOTS8STRD2_SMALL_GROUP");
  610. }
  611. /****************************dot 8-8-32 direct*************************/
  612. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_LARGE_GROUP) {
  613. checker_conv_bias_qint8x8x32(
  614. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  615. "ARMDOTS8STRD1_LARGE_GROUP");
  616. }
  617. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD1_WITHDOT_SMALL_GROUP) {
  618. checker_conv_bias_qint8x8x32(
  619. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  620. "ARMDOTS8STRD1_SMALL_GROUP");
  621. }
  622. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_LARGE_GROUP) {
  623. checker_conv_bias_qint8x8x32(
  624. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  625. "ARMDOTS8STRD2_LARGE_GROUP");
  626. }
  627. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_I8832STRD2_WITHDOT_SMALL_GROUP) {
  628. checker_conv_bias_qint8x8x32(
  629. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  630. "ARMDOTS8STRD2_SMALL_GROUP");
  631. }
  632. /******************************dot quint8*****************************/
  633. TEST_F(ARM_COMMON_MULTI_THREADS,
  634. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_LARGE_GROUP) {
  635. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  636. {2, 3, 5, 7}, 1, false, false, false),
  637. handle(), "ARMDOTU8STRD1_LARGE_GROUP");
  638. }
  639. TEST_F(ARM_COMMON_MULTI_THREADS,
  640. CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD_SMALL_GROUP) {
  641. checker_conv_bias_quint8x8x8(get_int8_quint8_conv_bias_args(
  642. {2, 3, 5, 7}, 1, false, false, false),
  643. handle(), "ARMDOTU8STRD1_SMALL_GROUP");
  644. }
  645. TEST_F(ARM_COMMON_MULTI_THREADS,
  646. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_LARGE_GROUP) {
  647. checker_conv_bias_quint8x8x8(
  648. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  649. handle(), "ARMDOTU8STRD2_LARGE_GROUP");
  650. }
  651. TEST_F(ARM_COMMON_MULTI_THREADS,
  652. CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD_SMALL_GROUP) {
  653. checker_conv_bias_quint8x8x8(
  654. get_int8_quint8_conv_bias_args({2, 5, 7}, 2, false, false, false),
  655. handle(), "ARMDOTU8STRD2_SMALL_GROUP");
  656. }
  657. /******************************dot quint8x8x32***********************/
  658. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_LARGE_GROUP) {
  659. checker_conv_bias_quint8x8x32(
  660. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  661. "ARMDOTU8STRD1_LARGE_GROUP");
  662. }
  663. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE1_SMALL_GROUP) {
  664. checker_conv_bias_quint8x8x32(
  665. get_conv_bias_args({2, 3, 5, 7}, 1, false, true, true), handle(),
  666. "ARMDOTU8STRD1_SMALL_GROUP");
  667. }
  668. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_LARGE_GROUP) {
  669. checker_conv_bias_quint8x8x32(
  670. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  671. "ARMDOTU8STRD2_LARGE_GROUP");
  672. }
  673. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_QUINT8_DIRECT_STRIDE2_SMALL_GROUP) {
  674. checker_conv_bias_quint8x8x32(
  675. get_conv_bias_args({2, 3, 5, 7}, 2, false, true, true), handle(),
  676. "ARMDOTU8STRD2_SMALL_GROUP");
  677. }
  678. /******************************dot int8x8x8 nchw44 ***********************/
  679. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x8) {
  680. using namespace conv_bias;
  681. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 1);
  682. for (auto&& arg : args)
  683. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  684. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  685. }
  686. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_Q8x8x32) {
  687. using namespace conv_bias;
  688. std::vector<TestArg> args =
  689. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  690. for (auto&& arg : args)
  691. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  692. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  693. }
  694. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S1_8x8x32) {
  695. using namespace conv_bias;
  696. std::vector<TestArg> args =
  697. get_nchw44_conv_bias_args({2, 3, 5, 7}, 1, false, true, true);
  698. for (auto&& arg : args)
  699. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  700. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  701. }
  702. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x8) {
  703. using namespace conv_bias;
  704. //! test qint8x8x8
  705. std::vector<TestArg> args = get_nchw44_conv_bias_args({2, 3, 5, 7}, 2);
  706. for (auto&& arg : args)
  707. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  708. checker_conv_bias_qint8x8x8(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  709. }
  710. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_Q8x8x32) {
  711. using namespace conv_bias;
  712. //! test qint8x8x8
  713. std::vector<TestArg> args =
  714. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  715. for (auto&& arg : args)
  716. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  717. checker_conv_bias_qint8x8x32(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  718. }
  719. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_INT8_DIRECT_DOT_NCHW44_S2_8x8x32) {
  720. using namespace conv_bias;
  721. //! test qint8x8x8
  722. std::vector<TestArg> args =
  723. get_nchw44_conv_bias_args({2, 3, 5, 7}, 2, false, true, true);
  724. for (auto&& arg : args)
  725. arg.param.format = param::ConvBias::Format::NCHW44_DOT;
  726. checker_conv_bias_int8x8x32_multi(args, handle(), "ARMDOTS8DIRECT_NCHW44");
  727. }
  728. #endif
  729. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4) {
  730. using namespace conv_bias;
  731. std::vector<TestArg> args = get_winograd_mk_packed_args();
  732. Checker<ConvBiasForward> checker(handle());
  733. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  734. }
  735. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4_WEIGHT_PREPROCESS) {
  736. using namespace conv_bias;
  737. std::vector<TestArg> args = get_winograd_mk_packed_args();
  738. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  739. handle());
  740. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4);
  741. }
  742. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F23_4_NCHW44) {
  743. using namespace conv_bias;
  744. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  745. Checker<ConvBiasForward> checker(handle());
  746. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  747. param::ConvBias::Format::NCHW44);
  748. }
  749. TEST_F(ARM_COMMON_MULTI_THREADS,
  750. CONV_BIAS_WINOGRAD_F23_4_NCHW44_WEIGHT_PREPROCESS) {
  751. using namespace conv_bias;
  752. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  753. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  754. handle());
  755. check_winograd("4:2:32", checker, args, param::MatrixMul::Format::MK4,
  756. param::ConvBias::Format::NCHW44);
  757. }
  758. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63) {
  759. using namespace conv_bias;
  760. std::vector<TestArg> args = get_winograd_args(3);
  761. Checker<ConvBiasForward> checker(handle());
  762. check_winograd("1:6:32", checker, args);
  763. }
  764. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_WEIGHT_PREPROCESS) {
  765. using namespace conv_bias;
  766. std::vector<TestArg> args = get_winograd_args(3);
  767. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  768. handle());
  769. check_winograd("1:6:32", checker, args);
  770. }
  771. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4) {
  772. using namespace conv_bias;
  773. std::vector<TestArg> args = get_winograd_mk_packed_args();
  774. Checker<ConvBiasForward> checker(handle());
  775. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  776. }
  777. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_WEIGHT_PREPROCESS) {
  778. using namespace conv_bias;
  779. std::vector<TestArg> args = get_winograd_mk_packed_args();
  780. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  781. handle());
  782. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4);
  783. }
  784. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F63_4_NCHW44) {
  785. using namespace conv_bias;
  786. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  787. Checker<ConvBiasForward> checker(handle());
  788. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  789. param::ConvBias::Format::NCHW44);
  790. }
  791. TEST_F(ARM_COMMON_MULTI_THREADS,
  792. CONV_BIAS_WINOGRAD_F63_4_NCHW44_WEIGHT_PREPROCESS) {
  793. using namespace conv_bias;
  794. std::vector<TestArg> args = get_nchw44_conv_bias_args({3}, 1);
  795. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  796. handle());
  797. check_winograd("4:6:16", checker, args, param::MatrixMul::Format::MK4,
  798. param::ConvBias::Format::NCHW44);
  799. }
  800. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  801. using namespace conv_bias;
  802. std::vector<TestArg> args = get_winograd_args(4);
  803. Checker<ConvBiasForward> checker(handle());
  804. check_winograd("1:5:32", checker, args);
  805. }
  806. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54_WEIGHT_PREPROCESS) {
  807. using namespace conv_bias;
  808. std::vector<TestArg> args = get_winograd_args(4);
  809. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  810. handle());
  811. check_winograd("1:5:32", checker, args);
  812. }
  813. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  814. using namespace conv_bias;
  815. std::vector<TestArg> args = get_winograd_args(5);
  816. Checker<ConvBiasForward> checker(handle());
  817. check_winograd("1:4:32", checker, args);
  818. }
  819. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45_WEIGHT_PREPROCESS) {
  820. using namespace conv_bias;
  821. std::vector<TestArg> args = get_winograd_args(5);
  822. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  823. handle());
  824. check_winograd("1:4:32", checker, args);
  825. }
  826. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  827. using namespace conv_bias;
  828. std::vector<TestArg> args = get_winograd_args(3);
  829. Checker<ConvBiasForward> checker(handle());
  830. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  831. param::ConvBias param, Handle* handle) {
  832. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  833. auto winograd_preprocess_opr =
  834. handle->create_operator<WinogradFilterPreprocess>();
  835. winograd_preprocess_opr->param().output_block_size = m;
  836. TensorLayout filter_transform_layout;
  837. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  838. filter_transform_layout);
  839. size_t winograd_preprocess_workspace_in_bytes =
  840. winograd_preprocess_opr->get_workspace_in_bytes(
  841. tensors[1].layout, filter_transform_layout);
  842. auto conv_bias_opr = handle->create_operator<ConvBias>();
  843. conv_bias_opr->param() = param;
  844. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  845. conv_bias_opr->param().output_block_size = m;
  846. size_t conv_bias_workspace_in_bytes =
  847. conv_bias_opr->get_workspace_in_bytes(
  848. tensors[0].layout, filter_transform_layout,
  849. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  850. nullptr);
  851. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  852. conv_bias_workspace_in_bytes,
  853. winograd_preprocess_workspace_in_bytes});
  854. wb.set(malloc(wb.total_size_in_bytes()));
  855. TensorND filter_transform_tensor(wb.get(0),
  856. std::move(filter_transform_layout));
  857. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  858. wb.get_workspace(2));
  859. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  860. tensors[3], tensors[4], nullptr,
  861. wb.get_workspace(1));
  862. free(wb.ptr());
  863. };
  864. auto run = [&checker, &extra_impl](
  865. Handle* handle, const std::vector<TestArg>& args,
  866. const std::vector<size_t>& out_size, DType A_dtype,
  867. DType B_dtype, DType C_dtype, DType D_dtype,
  868. const float eps) {
  869. for (auto&& arg : args) {
  870. for (uint32_t m : out_size) {
  871. checker.set_extra_opr_impl(std::bind(extra_impl,
  872. std::placeholders::_1, m,
  873. arg.param, handle));
  874. checker.set_dtype(0, A_dtype)
  875. .set_dtype(1, B_dtype)
  876. .set_dtype(2, C_dtype)
  877. .set_dtype(4, D_dtype)
  878. .set_epsilon(eps)
  879. .set_param(arg.param)
  880. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  881. }
  882. }
  883. };
  884. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  885. dtype::Float32(), dtype::Float32(), 1e-3f);
  886. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  887. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  888. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  889. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  890. dtype::Float16(), dtype::Float16(), 0.35f);
  891. #endif
  892. }
  893. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_PREPROCESS_NCHW44) {
  894. using namespace conv_bias;
  895. std::vector<TestArg> nchw44_args = get_nchw44_conv_bias_args({3}, 1);
  896. Checker<ConvBiasForward> checker(handle());
  897. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  898. param::ConvBias param, Handle* handle) {
  899. megdnn_assert(param.format == param::ConvBias::Format::NCHW44);
  900. auto winograd_preprocess_opr =
  901. handle->create_operator<WinogradFilterPreprocess>();
  902. winograd_preprocess_opr->param().output_block_size = m;
  903. winograd_preprocess_opr->param().format = param::MatrixMul::Format::MK4;
  904. TensorLayout filter_transform_layout;
  905. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  906. filter_transform_layout);
  907. size_t winograd_preprocess_workspace_in_bytes =
  908. winograd_preprocess_opr->get_workspace_in_bytes(
  909. tensors[1].layout, filter_transform_layout);
  910. auto conv_bias_opr = handle->create_operator<ConvBias>();
  911. conv_bias_opr->param() = param;
  912. conv_bias_opr->param().format =
  913. param::ConvBias::Format::NCHW44_WINOGRAD;
  914. conv_bias_opr->param().output_block_size = m;
  915. size_t conv_bias_workspace_in_bytes =
  916. conv_bias_opr->get_workspace_in_bytes(
  917. tensors[0].layout, filter_transform_layout,
  918. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  919. nullptr);
  920. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  921. conv_bias_workspace_in_bytes,
  922. winograd_preprocess_workspace_in_bytes});
  923. wb.set(malloc(wb.total_size_in_bytes()));
  924. TensorND filter_transform_tensor(wb.get(0),
  925. std::move(filter_transform_layout));
  926. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  927. wb.get_workspace(2));
  928. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  929. tensors[3], tensors[4], nullptr,
  930. wb.get_workspace(1));
  931. free(wb.ptr());
  932. };
  933. auto run = [&checker, &extra_impl](
  934. Handle* handle, const std::vector<TestArg>& args,
  935. const std::vector<size_t>& out_size, DType A_dtype,
  936. DType B_dtype, DType C_dtype, DType D_dtype,
  937. const float eps) {
  938. for (auto&& arg : args) {
  939. for (uint32_t m : out_size) {
  940. checker.set_extra_opr_impl(std::bind(extra_impl,
  941. std::placeholders::_1, m,
  942. arg.param, handle));
  943. checker.set_dtype(0, A_dtype)
  944. .set_dtype(1, B_dtype)
  945. .set_dtype(2, C_dtype)
  946. .set_dtype(4, D_dtype)
  947. .set_epsilon(eps)
  948. .set_param(arg.param)
  949. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  950. }
  951. }
  952. };
  953. run(handle(), nchw44_args, {2, 6}, dtype::Float32(), dtype::Float32(),
  954. dtype::Float32(), dtype::Float32(), 1e-3f);
  955. }
  956. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  957. using namespace conv_bias;
  958. Checker<ConvBiasForward> checker(handle());
  959. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  960. const std::vector<size_t>& out_size, DType A_dtype,
  961. DType B_dtype, DType C_dtype, DType D_dtype,
  962. param::MatrixMul::Format format, float eps) {
  963. for (auto&& arg : args) {
  964. for (uint32_t m : out_size) {
  965. checker.set_extra_opr_impl(std::bind(
  966. winograd_algo_extra_impl, std::placeholders::_1, m,
  967. arg.param, handle, format));
  968. checker.set_dtype(0, A_dtype)
  969. .set_dtype(1, B_dtype)
  970. .set_dtype(2, C_dtype)
  971. .set_dtype(4, D_dtype)
  972. .set_epsilon(eps)
  973. .set_param(arg.param)
  974. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  975. }
  976. }
  977. };
  978. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  979. std::vector<TestArg> args_first_half(args.begin(),
  980. args.begin() + args.size() / 2);
  981. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  982. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  983. 1e-3f);
  984. }
  985. TEST_F(ARM_COMMON_MULTI_THREADS,
  986. CONV_BIAS_WINOGRAD_MK_PACKED_F32_1_WEIGHT_PREPROCESS) {
  987. using namespace conv_bias;
  988. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  989. handle());
  990. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  991. const std::vector<size_t>& out_size, DType A_dtype,
  992. DType B_dtype, DType C_dtype, DType D_dtype,
  993. param::MatrixMul::Format format, float eps) {
  994. for (auto&& arg : args) {
  995. for (uint32_t m : out_size) {
  996. checker.set_extra_opr_impl(std::bind(
  997. winograd_algo_extra_impl, std::placeholders::_1, m,
  998. arg.param, handle, format));
  999. checker.set_dtype(0, A_dtype)
  1000. .set_dtype(1, B_dtype)
  1001. .set_dtype(2, C_dtype)
  1002. .set_dtype(4, D_dtype)
  1003. .set_epsilon(eps)
  1004. .set_param(arg.param)
  1005. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1006. }
  1007. }
  1008. };
  1009. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1010. std::vector<TestArg> args_first_half(args.begin(),
  1011. args.begin() + args.size() / 2);
  1012. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1013. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1014. 1e-3f);
  1015. }
  1016. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  1017. using namespace conv_bias;
  1018. Checker<ConvBiasForward> checker(handle());
  1019. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1020. const std::vector<size_t>& out_size, DType A_dtype,
  1021. DType B_dtype, DType C_dtype, DType D_dtype,
  1022. param::MatrixMul::Format format, float eps) {
  1023. for (auto&& arg : args) {
  1024. for (uint32_t m : out_size) {
  1025. checker.set_extra_opr_impl(std::bind(
  1026. winograd_algo_extra_impl, std::placeholders::_1, m,
  1027. arg.param, handle, format));
  1028. checker.set_dtype(0, A_dtype)
  1029. .set_dtype(1, B_dtype)
  1030. .set_dtype(2, C_dtype)
  1031. .set_dtype(4, D_dtype)
  1032. .set_epsilon(eps)
  1033. .set_param(arg.param)
  1034. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1035. }
  1036. }
  1037. };
  1038. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1039. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  1040. args.end());
  1041. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1042. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1043. 1e-3f);
  1044. }
  1045. TEST_F(ARM_COMMON_MULTI_THREADS,
  1046. CONV_BIAS_WINOGRAD_MK_PACKED_F32_2_WEIGHT_PREPROCESS) {
  1047. using namespace conv_bias;
  1048. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1049. handle());
  1050. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1051. const std::vector<size_t>& out_size, DType A_dtype,
  1052. DType B_dtype, DType C_dtype, DType D_dtype,
  1053. param::MatrixMul::Format format, float eps) {
  1054. for (auto&& arg : args) {
  1055. for (uint32_t m : out_size) {
  1056. checker.set_extra_opr_impl(std::bind(
  1057. winograd_algo_extra_impl, std::placeholders::_1, m,
  1058. arg.param, handle, format));
  1059. checker.set_dtype(0, A_dtype)
  1060. .set_dtype(1, B_dtype)
  1061. .set_dtype(2, C_dtype)
  1062. .set_dtype(4, D_dtype)
  1063. .set_epsilon(eps)
  1064. .set_param(arg.param)
  1065. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1066. }
  1067. }
  1068. };
  1069. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1070. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  1071. args.end());
  1072. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  1073. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  1074. 1e-3f);
  1075. }
  1076. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1077. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  1078. using namespace conv_bias;
  1079. Checker<ConvBiasForward> checker(handle());
  1080. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1081. const std::vector<size_t>& out_size, DType A_dtype,
  1082. DType B_dtype, DType C_dtype, DType D_dtype,
  1083. param::MatrixMul::Format format, float eps) {
  1084. for (auto&& arg : args) {
  1085. for (uint32_t m : out_size) {
  1086. checker.set_extra_opr_impl(std::bind(
  1087. winograd_algo_extra_impl, std::placeholders::_1, m,
  1088. arg.param, handle, format));
  1089. checker.set_dtype(0, A_dtype)
  1090. .set_dtype(1, B_dtype)
  1091. .set_dtype(2, C_dtype)
  1092. .set_dtype(4, D_dtype)
  1093. .set_epsilon(eps)
  1094. .set_param(arg.param)
  1095. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1096. }
  1097. }
  1098. };
  1099. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1100. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1101. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  1102. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  1103. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  1104. 0.25);
  1105. }
  1106. TEST_F(ARM_COMMON_MULTI_THREADS,
  1107. CONV_BIAS_WINOGRAD_MK_PACKED_F16_WEIGHT_PREPROCESS) {
  1108. using namespace conv_bias;
  1109. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1110. handle());
  1111. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1112. const std::vector<size_t>& out_size, DType A_dtype,
  1113. DType B_dtype, DType C_dtype, DType D_dtype,
  1114. param::MatrixMul::Format format, float eps) {
  1115. for (auto&& arg : args) {
  1116. for (uint32_t m : out_size) {
  1117. checker.set_extra_opr_impl(std::bind(
  1118. winograd_algo_extra_impl, std::placeholders::_1, m,
  1119. arg.param, handle, format));
  1120. checker.set_dtype(0, A_dtype)
  1121. .set_dtype(1, B_dtype)
  1122. .set_dtype(2, C_dtype)
  1123. .set_dtype(4, D_dtype)
  1124. .set_epsilon(eps)
  1125. .set_param(arg.param)
  1126. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1127. }
  1128. }
  1129. };
  1130. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1131. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1132. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  1133. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  1134. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  1135. 0.25);
  1136. }
  1137. #endif
  1138. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  1139. using namespace conv_bias;
  1140. Checker<ConvBiasForward> checker(handle());
  1141. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1142. const std::vector<size_t>& out_size, DType A_dtype,
  1143. DType B_dtype, DType C_dtype, DType D_dtype,
  1144. param::MatrixMul::Format format, float eps) {
  1145. for (auto&& arg : args) {
  1146. for (uint32_t m : out_size) {
  1147. checker.set_extra_opr_impl(std::bind(
  1148. winograd_algo_extra_impl, std::placeholders::_1, m,
  1149. arg.param, handle, format));
  1150. checker.set_dtype(0, A_dtype)
  1151. .set_dtype(1, B_dtype)
  1152. .set_dtype(2, C_dtype)
  1153. .set_dtype(4, D_dtype)
  1154. .set_epsilon(eps)
  1155. .set_param(arg.param)
  1156. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1157. }
  1158. }
  1159. };
  1160. #if MEGDNN_AARCH64
  1161. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1162. #else
  1163. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1164. #endif
  1165. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1166. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1167. std::vector<TestArg> quantized_args =
  1168. get_quantized_winograd_mk_packed_args(8);
  1169. UniformIntRNG int_rng{-50, 50};
  1170. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1171. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1172. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1173. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1174. }
  1175. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8) {
  1176. using namespace conv_bias;
  1177. Checker<ConvBiasForward> checker(handle());
  1178. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1179. const std::vector<size_t>& out_size, DType A_dtype,
  1180. DType B_dtype, DType C_dtype, DType D_dtype,
  1181. param::MatrixMul::Format format, float eps) {
  1182. for (auto&& arg : args) {
  1183. for (uint32_t m : out_size) {
  1184. checker.set_extra_opr_impl(std::bind(
  1185. winograd_algo_extra_impl, std::placeholders::_1, m,
  1186. arg.param, handle, format));
  1187. checker.set_dtype(0, A_dtype)
  1188. .set_dtype(1, B_dtype)
  1189. .set_dtype(2, C_dtype)
  1190. .set_dtype(4, D_dtype)
  1191. .set_epsilon(eps)
  1192. .set_param(arg.param)
  1193. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1194. }
  1195. }
  1196. };
  1197. #if MEGDNN_AARCH64
  1198. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1199. #else
  1200. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1201. #endif
  1202. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1203. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1204. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1205. UniformIntRNG int_rng{-50, 50};
  1206. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1207. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1208. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1209. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1210. }
  1211. TEST_F(ARM_COMMON_MULTI_THREADS,
  1212. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE) {
  1213. using namespace conv_bias;
  1214. Checker<ConvBiasForward> checker(handle());
  1215. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1216. const std::vector<size_t>& out_size, DType A_dtype,
  1217. DType B_dtype, DType C_dtype, DType D_dtype,
  1218. param::MatrixMul::Format format, float eps) {
  1219. for (auto&& arg : args) {
  1220. for (uint32_t m : out_size) {
  1221. checker.set_extra_opr_impl(std::bind(
  1222. winograd_algo_extra_impl, std::placeholders::_1, m,
  1223. arg.param, handle, format));
  1224. checker.set_dtype(0, A_dtype)
  1225. .set_dtype(1, B_dtype)
  1226. .set_dtype(2, C_dtype)
  1227. .set_dtype(4, D_dtype)
  1228. .set_epsilon(eps)
  1229. .set_param(arg.param)
  1230. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1231. }
  1232. }
  1233. };
  1234. #if MEGDNN_AARCH64
  1235. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1236. #else
  1237. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1238. #endif
  1239. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1240. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1241. std::vector<TestArg> quantized_args =
  1242. get_int8_nchw44_args(3, 4, false, true);
  1243. UniformIntRNG int_rng{-50, 50};
  1244. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1245. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1246. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1247. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1248. }
  1249. TEST_F(ARM_COMMON_MULTI_THREADS,
  1250. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32) {
  1251. using namespace conv_bias;
  1252. Checker<ConvBiasForward> checker(handle());
  1253. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1254. const std::vector<size_t>& out_size, DType A_dtype,
  1255. DType B_dtype, DType C_dtype, DType D_dtype,
  1256. param::MatrixMul::Format format, float eps) {
  1257. for (auto&& arg : args) {
  1258. for (uint32_t m : out_size) {
  1259. checker.set_extra_opr_impl(std::bind(
  1260. winograd_algo_extra_impl, std::placeholders::_1, m,
  1261. arg.param, handle, format));
  1262. checker.set_dtype(0, A_dtype)
  1263. .set_dtype(1, B_dtype)
  1264. .set_dtype(2, C_dtype)
  1265. .set_dtype(4, D_dtype)
  1266. .set_epsilon(eps)
  1267. .set_param(arg.param)
  1268. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1269. }
  1270. }
  1271. };
  1272. float epsilon = 0.001;
  1273. #if MEGDNN_AARCH64
  1274. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1275. #else
  1276. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1277. #endif
  1278. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1279. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1280. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1281. UniformIntRNG int_rng{-50, 50};
  1282. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1283. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1284. dtype::QuantizedS8(0.01887994f),
  1285. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1286. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1287. epsilon);
  1288. }
  1289. TEST_F(ARM_COMMON_MULTI_THREADS,
  1290. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE) {
  1291. using namespace conv_bias;
  1292. Checker<ConvBiasForward> checker(handle());
  1293. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1294. const std::vector<size_t>& out_size, DType A_dtype,
  1295. DType B_dtype, DType C_dtype, DType D_dtype,
  1296. param::MatrixMul::Format format, float eps) {
  1297. for (auto&& arg : args) {
  1298. for (uint32_t m : out_size) {
  1299. checker.set_extra_opr_impl(std::bind(
  1300. winograd_algo_extra_impl, std::placeholders::_1, m,
  1301. arg.param, handle, format));
  1302. checker.set_dtype(0, A_dtype)
  1303. .set_dtype(1, B_dtype)
  1304. .set_dtype(2, C_dtype)
  1305. .set_dtype(4, D_dtype)
  1306. .set_epsilon(eps)
  1307. .set_param(arg.param)
  1308. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1309. }
  1310. }
  1311. };
  1312. float epsilon = 0.001;
  1313. #if MEGDNN_AARCH64
  1314. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1315. #else
  1316. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1317. #endif
  1318. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1319. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1320. std::vector<TestArg> quantized_args =
  1321. get_int8_nchw44_args(3, 4, true, true);
  1322. UniformIntRNG int_rng{-50, 50};
  1323. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1324. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1325. dtype::QuantizedS8(0.01887994f),
  1326. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1327. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1328. epsilon);
  1329. }
  1330. TEST_F(ARM_COMMON_MULTI_THREADS,
  1331. CONV_BIAS_WINOGRAD_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1332. using namespace conv_bias;
  1333. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1334. handle());
  1335. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1336. const std::vector<size_t>& out_size, DType A_dtype,
  1337. DType B_dtype, DType C_dtype, DType D_dtype,
  1338. param::MatrixMul::Format format, float eps) {
  1339. for (auto&& arg : args) {
  1340. for (uint32_t m : out_size) {
  1341. checker.set_extra_opr_impl(std::bind(
  1342. winograd_algo_extra_impl, std::placeholders::_1, m,
  1343. arg.param, handle, format));
  1344. checker.set_dtype(0, A_dtype)
  1345. .set_dtype(1, B_dtype)
  1346. .set_dtype(2, C_dtype)
  1347. .set_dtype(4, D_dtype)
  1348. .set_epsilon(eps)
  1349. .set_param(arg.param)
  1350. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1351. }
  1352. }
  1353. };
  1354. #if MEGDNN_AARCH64
  1355. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1356. #else
  1357. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1358. #endif
  1359. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1360. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1361. std::vector<TestArg> quantized_args =
  1362. get_quantized_winograd_mk_packed_args(8);
  1363. UniformIntRNG int_rng{-50, 50};
  1364. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1365. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1366. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1367. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1368. }
  1369. TEST_F(ARM_COMMON_MULTI_THREADS,
  1370. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1371. using namespace conv_bias;
  1372. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1373. handle());
  1374. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1375. const std::vector<size_t>& out_size, DType A_dtype,
  1376. DType B_dtype, DType C_dtype, DType D_dtype,
  1377. param::MatrixMul::Format format, float eps) {
  1378. for (auto&& arg : args) {
  1379. for (uint32_t m : out_size) {
  1380. checker.set_extra_opr_impl(std::bind(
  1381. winograd_algo_extra_impl, std::placeholders::_1, m,
  1382. arg.param, handle, format));
  1383. checker.set_dtype(0, A_dtype)
  1384. .set_dtype(1, B_dtype)
  1385. .set_dtype(2, C_dtype)
  1386. .set_dtype(4, D_dtype)
  1387. .set_epsilon(eps)
  1388. .set_param(arg.param)
  1389. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1390. }
  1391. }
  1392. };
  1393. #if MEGDNN_AARCH64
  1394. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1395. #else
  1396. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1397. #endif
  1398. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1399. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1400. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1401. UniformIntRNG int_rng{-50, 50};
  1402. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1403. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1404. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1405. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1406. }
  1407. TEST_F(ARM_COMMON_MULTI_THREADS,
  1408. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE_WEIGHT_PREPROCESS) {
  1409. using namespace conv_bias;
  1410. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1411. handle());
  1412. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1413. const std::vector<size_t>& out_size, DType A_dtype,
  1414. DType B_dtype, DType C_dtype, DType D_dtype,
  1415. param::MatrixMul::Format format, float eps) {
  1416. for (auto&& arg : args) {
  1417. for (uint32_t m : out_size) {
  1418. checker.set_extra_opr_impl(std::bind(
  1419. winograd_algo_extra_impl, std::placeholders::_1, m,
  1420. arg.param, handle, format));
  1421. checker.set_dtype(0, A_dtype)
  1422. .set_dtype(1, B_dtype)
  1423. .set_dtype(2, C_dtype)
  1424. .set_dtype(4, D_dtype)
  1425. .set_epsilon(eps)
  1426. .set_param(arg.param)
  1427. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1428. }
  1429. }
  1430. };
  1431. #if MEGDNN_AARCH64
  1432. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1433. #else
  1434. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1435. #endif
  1436. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1437. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1438. std::vector<TestArg> quantized_args =
  1439. get_int8_nchw44_args(3, 4, false, true);
  1440. UniformIntRNG int_rng{-50, 50};
  1441. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1442. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1443. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1444. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1445. }
  1446. TEST_F(ARM_COMMON_MULTI_THREADS,
  1447. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_WEIGHT_PREPROCESS) {
  1448. using namespace conv_bias;
  1449. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1450. handle());
  1451. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1452. const std::vector<size_t>& out_size, DType A_dtype,
  1453. DType B_dtype, DType C_dtype, DType D_dtype,
  1454. param::MatrixMul::Format format, float eps) {
  1455. for (auto&& arg : args) {
  1456. for (uint32_t m : out_size) {
  1457. checker.set_extra_opr_impl(std::bind(
  1458. winograd_algo_extra_impl, std::placeholders::_1, m,
  1459. arg.param, handle, format));
  1460. checker.set_dtype(0, A_dtype)
  1461. .set_dtype(1, B_dtype)
  1462. .set_dtype(2, C_dtype)
  1463. .set_dtype(4, D_dtype)
  1464. .set_epsilon(eps)
  1465. .set_param(arg.param)
  1466. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1467. }
  1468. }
  1469. };
  1470. float epsilon = 0.001;
  1471. #if MEGDNN_AARCH64
  1472. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1473. #else
  1474. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1475. #endif
  1476. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1477. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1478. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1479. UniformIntRNG int_rng{-50, 50};
  1480. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1481. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1482. dtype::QuantizedS8(0.01887994f),
  1483. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1484. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1485. epsilon);
  1486. }
  1487. TEST_F(ARM_COMMON_MULTI_THREADS,
  1488. WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE_WEIGHT_PREPROCESS) {
  1489. using namespace conv_bias;
  1490. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1491. handle());
  1492. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1493. const std::vector<size_t>& out_size, DType A_dtype,
  1494. DType B_dtype, DType C_dtype, DType D_dtype,
  1495. param::MatrixMul::Format format, float eps) {
  1496. for (auto&& arg : args) {
  1497. for (uint32_t m : out_size) {
  1498. checker.set_extra_opr_impl(std::bind(
  1499. winograd_algo_extra_impl, std::placeholders::_1, m,
  1500. arg.param, handle, format));
  1501. checker.set_dtype(0, A_dtype)
  1502. .set_dtype(1, B_dtype)
  1503. .set_dtype(2, C_dtype)
  1504. .set_dtype(4, D_dtype)
  1505. .set_epsilon(eps)
  1506. .set_param(arg.param)
  1507. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1508. }
  1509. }
  1510. };
  1511. float epsilon = 0.001;
  1512. #if MEGDNN_AARCH64
  1513. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1514. #else
  1515. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1516. #endif
  1517. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1518. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1519. std::vector<TestArg> quantized_args =
  1520. get_int8_nchw44_args(3, 4, true, true);
  1521. UniformIntRNG int_rng{-50, 50};
  1522. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1523. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1524. dtype::QuantizedS8(0.01887994f),
  1525. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1526. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1527. epsilon);
  1528. }
  1529. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1530. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  1531. using namespace conv_bias;
  1532. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1533. Checker<ConvBiasForward> checker(handle());
  1534. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1535. }
  1536. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  1537. using namespace conv_bias;
  1538. std::vector<TestArg> args = get_winograd_args(5);
  1539. std::vector<TestArg> args_head_half(args.begin(),
  1540. args.begin() + args.size() / 2);
  1541. Checker<ConvBiasForward> checker(handle());
  1542. //! fp16 range -1.0 ~ 1.0
  1543. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1544. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1545. }
  1546. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  1547. using namespace conv_bias;
  1548. std::vector<TestArg> args = get_winograd_args(5);
  1549. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1550. args.end());
  1551. Checker<ConvBiasForward> checker(handle());
  1552. //! fp16 range -1.0 ~ 1.0
  1553. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1554. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1555. }
  1556. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1557. //! it will pass when run single testcase
  1558. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  1559. using namespace conv_bias;
  1560. std::vector<TestArg> args = get_winograd_args(3);
  1561. Checker<ConvBiasForward> checker(handle());
  1562. //! fp16 range -1.0 ~ 1.0
  1563. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1564. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1565. }
  1566. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  1567. using namespace conv_bias;
  1568. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1569. std::vector<TestArg> args_head_half(args.begin(),
  1570. args.begin() + args.size() / 2);
  1571. Checker<ConvBiasForward> checker(handle());
  1572. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1573. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1574. param::MatrixMul::Format::MK8);
  1575. }
  1576. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  1577. using namespace conv_bias;
  1578. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1579. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1580. args.end());
  1581. Checker<ConvBiasForward> checker(handle());
  1582. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1583. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1584. param::MatrixMul::Format::MK8);
  1585. }
  1586. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23_WEIGHT_PREPROCESS) {
  1587. using namespace conv_bias;
  1588. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1589. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1590. handle());
  1591. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1592. }
  1593. TEST_F(ARM_COMMON_MULTI_THREADS,
  1594. CONV_BIAS_WINOGRAD_F16_F45_1_WEIGHT_PREPROCESS) {
  1595. using namespace conv_bias;
  1596. std::vector<TestArg> args = get_winograd_args(5);
  1597. std::vector<TestArg> args_head_half(args.begin(),
  1598. args.begin() + args.size() / 2);
  1599. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1600. handle());
  1601. //! fp16 range -1.0 ~ 1.0
  1602. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1603. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1604. }
  1605. TEST_F(ARM_COMMON_MULTI_THREADS,
  1606. CONV_BIAS_WINOGRAD_F16_F45_2_WEIGHT_PREPROCESS) {
  1607. using namespace conv_bias;
  1608. std::vector<TestArg> args = get_winograd_args(5);
  1609. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1610. args.end());
  1611. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1612. handle());
  1613. //! fp16 range -1.0 ~ 1.0
  1614. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1615. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1616. }
  1617. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1618. //! it will pass when run single testcase
  1619. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63_WEIGHT_PREPROCESS) {
  1620. using namespace conv_bias;
  1621. std::vector<TestArg> args = get_winograd_args(3);
  1622. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1623. handle());
  1624. //! fp16 range -1.0 ~ 1.0
  1625. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1626. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1627. }
  1628. TEST_F(ARM_COMMON_MULTI_THREADS,
  1629. CONV_BIAS_WINOGRAD_F16_8x8_1_WEIGHT_PREPROCESS) {
  1630. using namespace conv_bias;
  1631. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1632. std::vector<TestArg> args_head_half(args.begin(),
  1633. args.begin() + args.size() / 2);
  1634. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1635. handle());
  1636. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1637. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1638. param::MatrixMul::Format::MK8);
  1639. }
  1640. TEST_F(ARM_COMMON_MULTI_THREADS,
  1641. CONV_BIAS_WINOGRAD_F16_8x8_2_WEIGHT_PREPROCESS) {
  1642. using namespace conv_bias;
  1643. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1644. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1645. args.end());
  1646. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1647. handle());
  1648. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1649. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1650. param::MatrixMul::Format::MK8);
  1651. }
  1652. #endif
  1653. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  1654. using namespace conv_bias;
  1655. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1656. Checker<ConvBiasForward> checker(handle());
  1657. UniformIntRNG rng{-50, 50};
  1658. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1659. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1660. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1661. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1662. .set_rng(0, &rng)
  1663. .set_rng(1, &rng)
  1664. .set_rng(2, &rng);
  1665. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1666. }
  1667. TEST_F(ARM_COMMON_MULTI_THREADS,
  1668. CONV_BIAS_WINOGRAD_INT8_8X8_WEIGHT_PREPROCESS) {
  1669. using namespace conv_bias;
  1670. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1671. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1672. handle());
  1673. UniformIntRNG rng{-50, 50};
  1674. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1675. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1676. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1677. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1678. .set_rng(0, &rng)
  1679. .set_rng(1, &rng)
  1680. .set_rng(2, &rng);
  1681. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1682. }
  1683. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  1684. RNG* rng, float epsilon, DType type0, DType type1,
  1685. DType type2, DType type3, const char* algo_name) {
  1686. using namespace conv_bias;
  1687. Checker<ConvBias> checker(handle);
  1688. checker.set_before_exec_callback(
  1689. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1690. checker.set_dtype(0, type0);
  1691. checker.set_dtype(1, type1);
  1692. checker.set_dtype(2, type2);
  1693. checker.set_dtype(4, type3);
  1694. checker.set_epsilon(epsilon);
  1695. if (NULL != rng) {
  1696. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  1697. }
  1698. for (auto&& arg : args) {
  1699. checker.set_param(arg.param).execs(
  1700. {arg.src, arg.filter, arg.bias, {}, {}});
  1701. }
  1702. }
  1703. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2_PREPROCESS) {
  1704. #define cb(name) \
  1705. check_conv_bias_preprocess( \
  1706. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1707. handle(), nullptr, 0.001, dtype::Float32(), dtype::Float32(), \
  1708. dtype::Float32(), dtype::Float32(), name);
  1709. #if MEGDNN_AARCH64
  1710. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1711. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1712. #elif MEGDNN_ARMV7
  1713. cb("IM2COLMATMUL:ARMV7_F32")
  1714. #endif
  1715. #undef cb
  1716. }
  1717. // clang-format off
  1718. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  1719. #define cb(name) \
  1720. check_conv_bias( \
  1721. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1722. handle(), name);
  1723. #if MEGDNN_AARCH64
  1724. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1725. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1726. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1727. #elif MEGDNN_ARMV7
  1728. cb("IM2COLMATMUL:ARMV7_F32")
  1729. #endif
  1730. #undef cb
  1731. }
  1732. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1_PREPROCESS) {
  1733. #define cb(name) \
  1734. check_conv_bias_preprocess( \
  1735. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1736. handle(), nullptr, 0.001, dtype::Float32(), dtype::Float32(), \
  1737. dtype::Float32(), dtype::Float32(), name);
  1738. #if MEGDNN_AARCH64
  1739. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1740. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1741. #elif MEGDNN_ARMV7
  1742. cb("IM2COLMATMUL:ARMV7_F32")
  1743. #endif
  1744. #undef cb
  1745. }
  1746. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  1747. #define cb(name) \
  1748. check_conv_bias( \
  1749. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1750. handle(), name);
  1751. #if MEGDNN_AARCH64
  1752. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1753. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1754. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1755. #elif MEGDNN_ARMV7
  1756. cb("IM2COLMATMUL:ARMV7_F32")
  1757. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1758. #endif
  1759. #undef cb
  1760. }
  1761. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  1762. UniformIntRNG rng{-50, 50};
  1763. #define cb(name) \
  1764. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1765. false, true, true), \
  1766. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1767. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1768. dtype::QuantizedS8(60.25f), name); \
  1769. checker_conv_bias( \
  1770. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1771. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1772. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1773. dtype::QuantizedS8(60.25f), name);
  1774. float epsilon = 0.001;
  1775. #if MEGDNN_AARCH64
  1776. #if __ARM_FEATURE_DOTPROD
  1777. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1778. #else
  1779. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1780. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1781. #endif
  1782. #elif MEGDNN_ARMV7
  1783. epsilon = 1;
  1784. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1785. #endif
  1786. #undef cb
  1787. }
  1788. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_PREPROCESS) {
  1789. UniformIntRNG rng{-50, 50};
  1790. #define cb(name) \
  1791. check_conv_bias_preprocess(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1792. false, true, true), \
  1793. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1794. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1795. dtype::QuantizedS8(60.25f), name); \
  1796. check_conv_bias_preprocess( \
  1797. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1798. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1799. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1800. dtype::QuantizedS8(60.25f), name);
  1801. float epsilon = 0.001;
  1802. #if MEGDNN_AARCH64
  1803. #if __ARM_FEATURE_DOTPROD
  1804. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1805. #else
  1806. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1807. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1808. #endif
  1809. #elif MEGDNN_ARMV7
  1810. epsilon = 1;
  1811. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1812. #endif
  1813. #undef cb
  1814. }
  1815. #if __ARM_FEATURE_DOTPROD
  1816. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT) {
  1817. UniformIntRNG rng{-50, 50};
  1818. #define cb(name) \
  1819. checker_conv_bias(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, \
  1820. false, false, false, true), \
  1821. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1822. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1823. dtype::QuantizedS8(60.25f), name); \
  1824. checker_conv_bias( \
  1825. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true), \
  1826. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1827. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1828. dtype::QuantizedS8(60.25f), name);
  1829. float epsilon = 0.001;
  1830. #if MEGDNN_AARCH64
  1831. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1832. #elif MEGDNN_ARMV7
  1833. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1834. #endif
  1835. #undef cb
  1836. }
  1837. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT_PREPROCESS) {
  1838. UniformIntRNG rng{-50, 50};
  1839. #define cb(name) \
  1840. check_conv_bias_preprocess(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, \
  1841. false, false, false, true), \
  1842. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1843. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1844. dtype::QuantizedS8(60.25f), name); \
  1845. checker_conv_bias( \
  1846. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true), \
  1847. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1848. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1849. dtype::QuantizedS8(60.25f), name);
  1850. float epsilon = 0.001;
  1851. #if MEGDNN_AARCH64
  1852. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1853. #elif MEGDNN_ARMV7
  1854. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1855. #endif
  1856. #undef cb
  1857. }
  1858. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT_S2_FUSE) {
  1859. UniformIntRNG rng{-50, 50};
  1860. #define cb(name) \
  1861. checker_conv_bias(get_nchw44_conv_bias_args({3}, 2, false, \
  1862. false, false, false, true), \
  1863. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1864. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1865. dtype::QuantizedS8(60.25f), name); \
  1866. float epsilon = 0.001;
  1867. #if MEGDNN_AARCH64
  1868. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1869. #elif MEGDNN_ARMV7
  1870. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1871. #endif
  1872. #undef cb
  1873. }
  1874. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_S8x8x32_MK4_DOT) {
  1875. UniformIntRNG rng{-50, 50};
  1876. #define cb(name) \
  1877. checker_conv_bias( \
  1878. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1879. true, false, true, false, false, true), \
  1880. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1881. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1882. checker_conv_bias( \
  1883. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1884. false, false, true), \
  1885. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1886. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name);
  1887. float epsilon = 0.001;
  1888. #if MEGDNN_AARCH64
  1889. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1890. #elif MEGDNN_ARMV7
  1891. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1892. #endif
  1893. #undef cb
  1894. }
  1895. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_S8x8x32_MK4_DOT_PREPROCESS) {
  1896. UniformIntRNG rng{-50, 50};
  1897. #define cb(name) \
  1898. check_conv_bias_preprocess( \
  1899. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1900. true, false, true, false, false, true), \
  1901. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1902. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1903. check_conv_bias_preprocess( \
  1904. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1905. false, false, true), \
  1906. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1907. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name);
  1908. float epsilon = 0.001;
  1909. #if MEGDNN_AARCH64
  1910. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1911. #elif MEGDNN_ARMV7
  1912. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1913. #endif
  1914. #undef cb
  1915. }
  1916. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32_MK4_DOT) {
  1917. UniformIntRNG rng{-50, 50};
  1918. #define cb(name) \
  1919. checker_conv_bias( \
  1920. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1921. true, false, true, false, false, true), \
  1922. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1923. dtype::Int32(), {}, name); \
  1924. checker_conv_bias( \
  1925. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1926. false, false, true), \
  1927. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1928. dtype::Int32(), {}, name);
  1929. float epsilon = 0.001;
  1930. #if MEGDNN_AARCH64
  1931. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1932. #elif MEGDNN_ARMV7
  1933. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1934. #endif
  1935. #undef cb
  1936. }
  1937. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32_MK4_DOT_PREPROCESS) {
  1938. UniformIntRNG rng{-50, 50};
  1939. #define cb(name) \
  1940. check_conv_bias_preprocess( \
  1941. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1942. true, false, true, false, false, true), \
  1943. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1944. dtype::Int32(), {}, name); \
  1945. check_conv_bias_preprocess( \
  1946. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1947. false, false, true), \
  1948. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1949. dtype::Int32(), {}, name);
  1950. float epsilon = 0.001;
  1951. #if MEGDNN_AARCH64
  1952. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1953. #elif MEGDNN_ARMV7
  1954. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1955. #endif
  1956. #undef cb
  1957. }
  1958. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CONV1x1_QUANTIZEDSYM_MK4_DOT) {
  1959. UniformIntRNG rng{-50, 50};
  1960. #define cb(name) \
  1961. checker_conv_bias( \
  1962. get_nchw44_conv_bias_args({1}, 1, true, true, false, false, true), \
  1963. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1964. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1965. dtype::QuantizedS8(60.25f), name); \
  1966. checker_conv_bias( \
  1967. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1968. false, false, true), \
  1969. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1970. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1971. checker_conv_bias( \
  1972. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1973. false, false, true), \
  1974. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1975. dtype::Int32(), {}, name);
  1976. float epsilon = 0.001;
  1977. #if MEGDNN_AARCH64
  1978. cb("CONV1x1:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD");
  1979. #elif MEGDNN_ARMV7
  1980. cb("CONV1x1:AARCH32_INT8_MK4_8X4X4_DOTPROD");
  1981. #endif
  1982. #undef cb
  1983. }
  1984. #endif
  1985. // clang-format on
  1986. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1987. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  1988. NormalRNG rng(128.f);
  1989. #define cb(name) \
  1990. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1991. false, true, true), \
  1992. handle(), &rng, epsilon, \
  1993. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1994. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1995. dtype::QuantizedS32(1.2 * 1.3), \
  1996. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1997. checker_conv_bias( \
  1998. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1999. handle(), &rng, epsilon, \
  2000. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2001. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2002. dtype::QuantizedS32(1.2 * 1.3), \
  2003. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2004. float epsilon = 0.001;
  2005. #if MEGDNN_AARCH64
  2006. #if __ARM_FEATURE_DOTPROD
  2007. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2008. #else
  2009. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2010. #endif
  2011. #elif MEGDNN_ARMV7
  2012. epsilon = 1;
  2013. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2014. #endif
  2015. #undef cb
  2016. }
  2017. TEST_F(ARM_COMMON_MULTI_THREADS,
  2018. CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM_FILTERPREPROCESS) {
  2019. NormalRNG rng(128.f);
  2020. #define cb(name) \
  2021. check_conv_bias_preprocess( \
  2022. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false, \
  2023. true, true), \
  2024. handle(), &rng, epsilon, \
  2025. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2026. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2027. dtype::QuantizedS32(1.2 * 1.3), \
  2028. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  2029. check_conv_bias_preprocess( \
  2030. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  2031. handle(), &rng, epsilon, \
  2032. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2033. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2034. dtype::QuantizedS32(1.2 * 1.3), \
  2035. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2036. float epsilon = 0.001;
  2037. #if MEGDNN_AARCH64
  2038. #if __ARM_FEATURE_DOTPROD
  2039. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2040. #else
  2041. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2042. #endif
  2043. #elif MEGDNN_ARMV7
  2044. epsilon = 1;
  2045. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2046. #endif
  2047. #undef cb
  2048. }
  2049. #endif
  2050. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2051. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  2052. UniformIntRNG rng{-50, 50};
  2053. float epsilon = 0.001;
  2054. #define cb(name) \
  2055. checker_conv_bias( \
  2056. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2057. handle(), &rng, epsilon, \
  2058. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2059. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2060. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  2061. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  2062. &rng, epsilon, \
  2063. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2064. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2065. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2066. #if MEGDNN_AARCH64
  2067. #if __ARM_FEATURE_DOTPROD
  2068. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2069. #else
  2070. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2071. #endif
  2072. #elif MEGDNN_ARMV7
  2073. #if __ARM_FEATURE_DOTPROD
  2074. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  2075. #endif
  2076. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2077. #endif
  2078. #undef cb
  2079. }
  2080. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32_FILTERPREPROCESS) {
  2081. UniformIntRNG rng{-50, 50};
  2082. float epsilon = 0.001;
  2083. #define cb(name) \
  2084. check_conv_bias_preprocess( \
  2085. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2086. handle(), &rng, epsilon, \
  2087. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2088. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2089. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  2090. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2091. handle(), &rng, epsilon, \
  2092. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2093. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2094. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2095. #if MEGDNN_AARCH64
  2096. #if __ARM_FEATURE_DOTPROD
  2097. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2098. #else
  2099. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2100. #endif
  2101. #elif MEGDNN_ARMV7
  2102. #if __ARM_FEATURE_DOTPROD
  2103. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  2104. #endif
  2105. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2106. #endif
  2107. #undef cb
  2108. }
  2109. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  2110. UniformIntRNG rng{-50, 50};
  2111. float epsilon = 0.001;
  2112. std::vector<conv_bias::TestArg> args_nchw44 =
  2113. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, true, true, true,
  2114. false, false, false, false, true);
  2115. std::vector<conv_bias::TestArg> args_nchw44_1x1s2 =
  2116. get_nchw44_conv_bias_args({1}, 2, true, true, true, false, false,
  2117. false, false, true);
  2118. #define cb(name) \
  2119. checker_conv_bias( \
  2120. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2121. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2122. dtype::Int16{}, dtype::Int16{}, name); \
  2123. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  2124. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2125. dtype::Int16{}, dtype::Int16{}, name);
  2126. #define cb_nchw44(name) \
  2127. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2128. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name); \
  2129. checker_conv_bias(args_nchw44_1x1s2, handle(), &rng, epsilon, \
  2130. dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  2131. dtype::Int16{}, name);
  2132. #if MEGDNN_AARCH64
  2133. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2134. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2135. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2136. #elif MEGDNN_ARMV7
  2137. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2138. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2139. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2140. cb_nchw44("IM2COLMATMUL:ARMV7_INT8X8X16_MK4_K8X8X4");
  2141. #endif
  2142. #undef cb
  2143. #undef cb_nchw44
  2144. }
  2145. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_FILTERPREPROCESS) {
  2146. UniformIntRNG rng{-50, 50};
  2147. float epsilon = 0.001;
  2148. #define cb(name) \
  2149. check_conv_bias_preprocess( \
  2150. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2151. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2152. dtype::Int16{}, dtype::Int16{}, name); \
  2153. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2154. handle(), &rng, epsilon, dtype::Int8{}, \
  2155. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2156. name);
  2157. #if MEGDNN_AARCH64
  2158. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2159. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2160. #elif MEGDNN_ARMV7
  2161. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2162. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2163. #endif
  2164. #undef cb
  2165. }
  2166. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_NOPACK_FILTERPREPROCESS) {
  2167. UniformIntRNG rng{-50, 50};
  2168. float epsilon = 0.001;
  2169. #define cb(name) \
  2170. check_conv_bias_preprocess( \
  2171. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2172. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2173. dtype::Int16{}, dtype::Int16{}, name); \
  2174. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2175. handle(), &rng, epsilon, dtype::Int8{}, \
  2176. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2177. name);
  2178. #if MEGDNN_AARCH64
  2179. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2180. #elif MEGDNN_ARMV7
  2181. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2182. #endif
  2183. #undef cb
  2184. }
  2185. #endif
  2186. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2187. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  2188. using namespace conv_bias;
  2189. param::ConvBias cur_param;
  2190. std::vector<conv_bias::TestArg> args =
  2191. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2192. std::vector<conv_bias::TestArg> args1 =
  2193. get_conv_bias_args({1}, 2, false, false, false);
  2194. args.insert(args.begin(), args1.begin(), args1.end());
  2195. NormalRNG rng(1);
  2196. #define cb(name) \
  2197. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2198. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  2199. name);
  2200. #if MEGDNN_AARCH64
  2201. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2202. #elif MEGDNN_ARMV7
  2203. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2204. #endif
  2205. #undef cb
  2206. }
  2207. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16_FILTERPREPROCESS) {
  2208. using namespace conv_bias;
  2209. param::ConvBias cur_param;
  2210. std::vector<conv_bias::TestArg> args =
  2211. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2212. std::vector<conv_bias::TestArg> args1 =
  2213. get_conv_bias_args({1}, 2, false, false, false);
  2214. args.insert(args.begin(), args1.begin(), args1.end());
  2215. NormalRNG rng(1);
  2216. #define cb(name) \
  2217. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2218. dtype::Float16{}, dtype::Float16{}, \
  2219. dtype::Float16{}, name);
  2220. #if MEGDNN_AARCH64
  2221. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2222. #elif MEGDNN_ARMV7
  2223. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2224. #endif
  2225. #undef cb
  2226. }
  2227. #endif
  2228. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  2229. Handle* handle, const char* algo_name) {
  2230. using namespace conv_bias;
  2231. Checker<ConvBias> checker(handle);
  2232. checker.set_before_exec_callback(
  2233. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2234. checker.set_dtype(0, dtype::Int8());
  2235. checker.set_dtype(1, dtype::Int8());
  2236. checker.set_dtype(2, dtype::Int32());
  2237. checker.set_dtype(4, dtype::Int32());
  2238. for (auto&& arg : args) {
  2239. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2240. }
  2241. UniformIntRNG rng{-50, 50};
  2242. for (auto&& arg : args) {
  2243. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2244. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2245. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2246. .set_dtype(4, {})
  2247. .set_rng(0, &rng)
  2248. .set_rng(1, &rng)
  2249. .set_rng(2, &rng)
  2250. .set_param(arg.param)
  2251. .execs({arg.src, arg.filter, {}, {}, {}});
  2252. }
  2253. }
  2254. void checker_conv_bias_int8x8x32_preprocess(std::vector<conv_bias::TestArg> args,
  2255. Handle* handle, const char* algo_name) {
  2256. using namespace conv_bias;
  2257. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  2258. handle);
  2259. checker.set_before_exec_callback(
  2260. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2261. checker.set_dtype(0, dtype::Int8());
  2262. checker.set_dtype(1, dtype::Int8());
  2263. checker.set_dtype(2, dtype::Int32());
  2264. checker.set_dtype(4, dtype::Int32());
  2265. for (auto&& arg : args) {
  2266. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2267. }
  2268. UniformIntRNG rng{-50, 50};
  2269. for (auto&& arg : args) {
  2270. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2271. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2272. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2273. .set_dtype(4, {})
  2274. .set_rng(0, &rng)
  2275. .set_rng(1, &rng)
  2276. .set_rng(2, &rng)
  2277. .set_param(arg.param)
  2278. .execs({arg.src, arg.filter, {}, {}, {}});
  2279. }
  2280. }
  2281. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2282. #if !__ARM_FEATURE_DOTPROD
  2283. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  2284. using namespace conv_bias;
  2285. std::vector<conv_bias::TestArg> args =
  2286. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2287. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2288. #if MEGDNN_AARCH64
  2289. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2290. #else
  2291. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2292. #endif
  2293. #undef cb
  2294. }
  2295. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2_PREPROCESS) {
  2296. using namespace conv_bias;
  2297. std::vector<conv_bias::TestArg> args =
  2298. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2299. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2300. #if MEGDNN_AARCH64
  2301. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2302. #else
  2303. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2304. #endif
  2305. #undef cb
  2306. }
  2307. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  2308. using namespace conv_bias;
  2309. std::vector<conv_bias::TestArg> args =
  2310. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2311. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2312. #if MEGDNN_AARCH64
  2313. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2314. #else
  2315. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2316. #endif
  2317. #undef cb
  2318. }
  2319. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1_PREPROCESS) {
  2320. using namespace conv_bias;
  2321. std::vector<conv_bias::TestArg> args =
  2322. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2323. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2324. #if MEGDNN_AARCH64
  2325. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2326. #else
  2327. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2328. #endif
  2329. #undef cb
  2330. }
  2331. TEST_F(ARM_COMMON_MULTI_THREADS,
  2332. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  2333. UniformIntRNG rng{-50, 50};
  2334. #define cb(name) \
  2335. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  2336. epsilon, dtype::QuantizedS8(2.5f), \
  2337. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2338. dtype::QuantizedS8(60.25f), name);
  2339. float epsilon = 0.001;
  2340. #if MEGDNN_AARCH64
  2341. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2342. #else
  2343. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2344. #endif
  2345. #undef cb
  2346. }
  2347. TEST_F(ARM_COMMON_MULTI_THREADS,
  2348. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2_PREPROCESS) {
  2349. UniformIntRNG rng{-50, 50};
  2350. #define cb(name) \
  2351. check_conv_bias_preprocess( \
  2352. get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, epsilon, \
  2353. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2354. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2355. float epsilon = 0.001;
  2356. #if MEGDNN_AARCH64
  2357. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2358. #else
  2359. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2360. #endif
  2361. #undef cb
  2362. }
  2363. TEST_F(ARM_COMMON_MULTI_THREADS,
  2364. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  2365. UniformIntRNG rng{-50, 50};
  2366. #define cb(name) \
  2367. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  2368. epsilon, dtype::QuantizedS8(2.5f), \
  2369. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2370. dtype::QuantizedS8(60.25f), name);
  2371. float epsilon = 0.001;
  2372. #if MEGDNN_AARCH64
  2373. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2374. #else
  2375. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2376. #endif
  2377. #undef cb
  2378. }
  2379. TEST_F(ARM_COMMON_MULTI_THREADS,
  2380. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1_PREPROCESS) {
  2381. UniformIntRNG rng{-50, 50};
  2382. #define cb(name) \
  2383. check_conv_bias_preprocess( \
  2384. get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, epsilon, \
  2385. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2386. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2387. float epsilon = 0.001;
  2388. #if MEGDNN_AARCH64
  2389. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2390. #else
  2391. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2392. #endif
  2393. #undef cb
  2394. }
  2395. #if MEGDNN_AARCH64
  2396. TEST_F(ARM_COMMON_MULTI_THREADS,
  2397. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  2398. UniformIntRNG rng{-50, 50};
  2399. #define cb(name) \
  2400. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  2401. epsilon, dtype::QuantizedS8(2.5f), \
  2402. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2403. dtype::QuantizedS8(60.25f), name);
  2404. float epsilon = 0.001;
  2405. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2406. #undef cb
  2407. }
  2408. TEST_F(ARM_COMMON_MULTI_THREADS,
  2409. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE_PREPROCESS) {
  2410. UniformIntRNG rng{-50, 50};
  2411. #define cb(name) \
  2412. check_conv_bias_preprocess( \
  2413. get_nchw44_conv_bias_args({3}, 1), handle(), &rng, epsilon, \
  2414. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2415. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2416. float epsilon = 0.001;
  2417. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2418. #undef cb
  2419. }
  2420. #endif
  2421. #endif
  2422. #endif
  2423. #if MEGDNN_AARCH64
  2424. #if __ARM_FEATURE_DOTPROD
  2425. TEST_F(ARM_COMMON_MULTI_THREADS,
  2426. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE) {
  2427. UniformIntRNG rng{-50, 50};
  2428. #define cb(name) \
  2429. checker_conv_bias( \
  2430. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2431. true, false, false, false), \
  2432. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2433. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2434. dtype::QuantizedS8(60.25f), name);
  2435. float epsilon = 0.001;
  2436. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2437. #undef cb
  2438. }
  2439. TEST_F(ARM_COMMON_MULTI_THREADS,
  2440. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE_PREPROCESS) {
  2441. UniformIntRNG rng{-50, 50};
  2442. #define cb(name) \
  2443. check_conv_bias_preprocess( \
  2444. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2445. true, false, false, false), \
  2446. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2447. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2448. dtype::QuantizedS8(60.25f), name);
  2449. float epsilon = 0.001;
  2450. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2451. #undef cb
  2452. }
  2453. #endif
  2454. #endif
  2455. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  2456. using namespace conv_bias;
  2457. std::vector<conv_bias::TestArg> args =
  2458. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2459. std::vector<conv_bias::TestArg> args1 =
  2460. get_conv_bias_args({1}, 2, false, true, true);
  2461. args.insert(args.begin(), args1.begin(), args1.end());
  2462. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2463. #if MEGDNN_AARCH64
  2464. #if __ARM_FEATURE_DOTPROD
  2465. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2466. #else
  2467. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2468. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2469. #endif
  2470. #elif MEGDNN_ARMV7
  2471. #if __ARM_FEATURE_DOTPROD
  2472. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2473. #endif
  2474. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2475. #endif
  2476. #if MEGDNN_ARMV7
  2477. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2478. #endif
  2479. #undef cb
  2480. }
  2481. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8X8X32_FILTER_PREPROCESS) {
  2482. using namespace conv_bias;
  2483. std::vector<conv_bias::TestArg> args =
  2484. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2485. std::vector<conv_bias::TestArg> args1 =
  2486. get_conv_bias_args({1}, 2, false, true, true);
  2487. args.insert(args.begin(), args1.begin(), args1.end());
  2488. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2489. #if MEGDNN_AARCH64
  2490. #if __ARM_FEATURE_DOTPROD
  2491. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2492. #else
  2493. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2494. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2495. #endif
  2496. #elif MEGDNN_ARMV7
  2497. #if __ARM_FEATURE_DOTPROD
  2498. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2499. #endif
  2500. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2501. #endif
  2502. #if MEGDNN_ARMV7
  2503. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2504. #endif
  2505. #undef cb
  2506. }
  2507. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  2508. using namespace conv_bias;
  2509. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2510. {2, 4, 7}, 1, false, false, false, false, false, true, true);
  2511. #if MEGDNN_AARCH64
  2512. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2513. #elif MEGDNN_ARMV7
  2514. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2515. #endif
  2516. }
  2517. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32_PREPROCESS) {
  2518. using namespace conv_bias;
  2519. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2520. {2, 4, 7}, 1, false, false, false, false, false, true,true);
  2521. #define cb(name) \
  2522. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2523. dtype::Float32(), dtype::Float32(), \
  2524. dtype::Float32(), dtype::Float32(), name);
  2525. #if MEGDNN_AARCH64
  2526. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2527. #elif MEGDNN_ARMV7
  2528. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2529. #endif
  2530. #undef cb
  2531. }
  2532. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  2533. using namespace conv_bias;
  2534. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2535. {3, 5, 6}, 2, false, false, false, false, false, true, true);
  2536. #define cb(name) check_conv_bias(args, handle(), name);
  2537. #if MEGDNN_AARCH64
  2538. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2539. #elif MEGDNN_ARMV7
  2540. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2541. #endif
  2542. #undef cb
  2543. }
  2544. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE_PREPROCESS) {
  2545. using namespace conv_bias;
  2546. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2547. {3}, 2, false, false, false, false, false, true, true, false);
  2548. #define cb(name) \
  2549. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2550. dtype::Float32(), dtype::Float32(), \
  2551. dtype::Float32(), dtype::Float32(), name);
  2552. #if MEGDNN_AARCH64
  2553. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2554. #elif MEGDNN_ARMV7
  2555. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2556. #endif
  2557. #undef cb
  2558. }
  2559. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE) {
  2560. using namespace conv_bias;
  2561. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2562. {3}, 2, false, false, false, false, false, true, true, false);
  2563. #define cb(name) check_conv_bias(args, handle(), name);
  2564. #if MEGDNN_AARCH64
  2565. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2566. #elif MEGDNN_ARMV7
  2567. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2568. #endif
  2569. #undef cb
  2570. }
  2571. /***************************** Conv1x1 Algo Test ***********************/
  2572. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  2573. using namespace conv_bias;
  2574. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2575. #if MEGDNN_AARCH64
  2576. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  2577. #elif MEGDNN_ARMV7
  2578. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  2579. #endif
  2580. std::vector<conv_bias::TestArg> gemv_args;
  2581. for (auto&& arg : args)
  2582. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2583. gemv_args.emplace_back(arg);
  2584. }
  2585. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2586. }
  2587. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  2588. using namespace conv_bias;
  2589. std::vector<conv_bias::TestArg> args =
  2590. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2591. #if MEGDNN_AARCH64
  2592. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2593. #elif MEGDNN_ARMV7
  2594. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2595. #endif
  2596. std::vector<conv_bias::TestArg> gemv_args;
  2597. for (auto&& arg : args)
  2598. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2599. gemv_args.emplace_back(arg);
  2600. }
  2601. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2602. }
  2603. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  2604. using namespace conv_bias;
  2605. std::vector<conv_bias::TestArg> args =
  2606. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2607. std::vector<conv_bias::TestArg> args_of_4;
  2608. for (auto&& arg : args) {
  2609. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  2610. args_of_4.push_back(arg);
  2611. }
  2612. }
  2613. #if MEGDNN_AARCH64
  2614. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  2615. #elif MEGDNN_ARMV7
  2616. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  2617. #endif
  2618. }
  2619. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2620. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  2621. using namespace conv_bias;
  2622. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2623. NormalRNG rng(1);
  2624. #if MEGDNN_AARCH64
  2625. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2626. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2627. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2628. #elif MEGDNN_ARMV7
  2629. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2630. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2631. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2632. #endif
  2633. std::vector<conv_bias::TestArg> gemv_args;
  2634. for (auto&& arg : args)
  2635. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2636. gemv_args.emplace_back(arg);
  2637. }
  2638. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2639. }
  2640. #endif
  2641. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  2642. UniformIntRNG rng{-50, 50};
  2643. float epsilon = 0.001;
  2644. std::vector<conv_bias::TestArg> args =
  2645. get_conv_bias_1x1_args(false, false, true, true);
  2646. #define cb(name) \
  2647. checker_conv_bias(args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2648. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2649. dtype::QuantizedS8(60.25f), name);
  2650. #if MEGDNN_AARCH64
  2651. #if __ARM_FEATURE_DOTPROD
  2652. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2653. #else
  2654. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2655. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2656. #endif
  2657. #elif MEGDNN_ARMV7
  2658. epsilon = 1;
  2659. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2660. #endif
  2661. #undef cb
  2662. std::vector<conv_bias::TestArg> gemv_args;
  2663. for (auto&& arg : args)
  2664. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2665. gemv_args.emplace_back(arg);
  2666. }
  2667. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2668. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2669. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2670. "CONV1x1_GEMV");
  2671. }
  2672. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2673. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  2674. UniformIntRNG rng{-50, 50};
  2675. std::vector<conv_bias::TestArg> args =
  2676. get_conv_bias_1x1_args(false, false, true, true);
  2677. #define cb(name) \
  2678. checker_conv_bias(args, handle(), &rng, epsilon, \
  2679. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2680. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2681. dtype::QuantizedS32(1.2 * 1.3), \
  2682. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2683. float epsilon = 0.001;
  2684. #if MEGDNN_AARCH64
  2685. #if __ARM_FEATURE_DOTPROD
  2686. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2687. #else
  2688. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2689. #endif
  2690. #elif MEGDNN_ARMV7
  2691. epsilon = 1;
  2692. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2693. #endif
  2694. #undef cb
  2695. std::vector<conv_bias::TestArg> gemv_args;
  2696. for (auto&& arg : args)
  2697. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2698. gemv_args.emplace_back(arg);
  2699. }
  2700. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2701. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2702. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2703. dtype::QuantizedS32(1.2 * 1.3),
  2704. dtype::Quantized8Asymm(50.3f, (uint8_t)120),
  2705. "CONV1x1_GEMV");
  2706. }
  2707. #endif
  2708. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2709. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  2710. NormalRNG rng(128.f);
  2711. float epsilon = 0.001;
  2712. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2713. #define cb(name) \
  2714. checker_conv_bias(args, handle(), &rng, epsilon, \
  2715. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2716. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2717. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2718. #if MEGDNN_AARCH64
  2719. #if __ARM_FEATURE_DOTPROD
  2720. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2721. #else
  2722. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2723. #endif
  2724. #elif MEGDNN_ARMV7
  2725. #if __ARM_FEATURE_DOTPROD
  2726. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2727. #endif
  2728. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2729. #endif
  2730. #undef cb
  2731. std::vector<conv_bias::TestArg> gemv_args;
  2732. for (auto&& arg : args)
  2733. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2734. gemv_args.emplace_back(arg);
  2735. }
  2736. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2737. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2738. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2739. dtype::QuantizedS32(1.2 * 1.3), {}, "CONV1x1_GEMV");
  2740. }
  2741. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  2742. UniformIntRNG rng{-50, 50};
  2743. float epsilon = 0.001;
  2744. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2745. std::vector<conv_bias::TestArg> args_nchw44 = get_nchw44_conv_bias_args(
  2746. {1}, 1, true, true, true, false, false, false, false, true);
  2747. #define cb(name) \
  2748. checker_conv_bias(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2749. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2750. #define cb_nchw44(name) \
  2751. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2752. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2753. #if MEGDNN_AARCH64
  2754. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2755. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2756. #elif MEGDNN_ARMV7
  2757. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2758. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2759. cb_nchw44("CONV1x1:ARMV7_INT8X8X16_MK4_K8X8X4:48");
  2760. #endif
  2761. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  2762. #undef cb
  2763. #undef cb_nchw44
  2764. std::vector<conv_bias::TestArg> gemv_args;
  2765. for (auto&& arg : args)
  2766. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2767. gemv_args.emplace_back(arg);
  2768. }
  2769. checker_conv_bias(gemv_args, handle(), &rng, epsilon, dtype::Int8{},
  2770. dtype::Int8{}, dtype::Int16{}, dtype::Int16{},
  2771. "CONV1x1_GEMV");
  2772. }
  2773. #endif
  2774. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  2775. using namespace conv_bias;
  2776. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2777. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2778. #if MEGDNN_AARCH64
  2779. #if __ARM_FEATURE_DOTPROD
  2780. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2781. #else
  2782. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2783. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2784. #endif
  2785. #elif MEGDNN_ARMV7
  2786. #if __ARM_FEATURE_DOTPROD
  2787. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2788. #endif
  2789. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2790. #endif
  2791. #if MEGDNN_ARMV7
  2792. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2793. #endif
  2794. #undef cb
  2795. std::vector<conv_bias::TestArg> gemv_args;
  2796. for (auto&& arg : args)
  2797. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2798. gemv_args.emplace_back(arg);
  2799. }
  2800. checker_conv_bias_mul_int8x8x32(gemv_args, handle(), "CONV1x1_GEMV");
  2801. }
  2802. #ifndef __ARM_FEATURE_DOTPROD
  2803. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  2804. using namespace conv_bias;
  2805. std::vector<conv_bias::TestArg> args =
  2806. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2807. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2808. #if MEGDNN_AARCH64
  2809. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2810. #elif MEGDNN_ARMV7
  2811. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2812. #endif
  2813. #undef cb
  2814. UniformIntRNG rng{-50, 50};
  2815. float epsilon = 0.001;
  2816. #define cb(name) \
  2817. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2818. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2819. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2820. dtype::QuantizedS8(60.25f), name);
  2821. #if MEGDNN_AARCH64
  2822. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2823. #elif MEGDNN_ARMV7
  2824. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2825. #endif
  2826. #undef cb
  2827. }
  2828. #endif
  2829. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  2830. using namespace conv_bias;
  2831. std::vector<conv_bias::TestArg> args =
  2832. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2833. UniformIntRNG rng{-50, 50};
  2834. float epsilon = 0.001;
  2835. std::vector<conv_bias::TestArg> gemv_args;
  2836. for (auto&& arg : args)
  2837. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2838. gemv_args.emplace_back(arg);
  2839. }
  2840. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2841. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2842. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2843. "CONV1x1_GEMV");
  2844. }
  2845. #ifdef __ARM_FEATURE_DOTPROD
  2846. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  2847. using namespace conv_bias;
  2848. std::vector<conv_bias::TestArg> args =
  2849. get_nchw44_conv_bias_args({1}, 1, true, false, false, false, true);
  2850. UniformIntRNG rng{-50, 50};
  2851. float epsilon = 0.001;
  2852. std::vector<conv_bias::TestArg> gemv_args;
  2853. for (auto&& arg : args)
  2854. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2855. gemv_args.emplace_back(arg);
  2856. }
  2857. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2858. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2859. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2860. "CONV1x1_GEMV");
  2861. }
  2862. #endif
  2863. // vim: syntax=cpp.doxygen

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