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

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

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