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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297
  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, false, \
  1832. true, false, true, false, false, true), \
  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. false, false, true), \
  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, false, \
  1874. true, false, true, false, false, true), \
  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. false, false, true), \
  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( \
  2009. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  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(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  2015. &rng, epsilon, \
  2016. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2017. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2018. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2019. #if MEGDNN_AARCH64
  2020. #if __ARM_FEATURE_DOTPROD
  2021. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2022. #else
  2023. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2024. #endif
  2025. #elif MEGDNN_ARMV7
  2026. #if __ARM_FEATURE_DOTPROD
  2027. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  2028. #endif
  2029. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2030. #endif
  2031. #undef cb
  2032. }
  2033. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32_FILTERPREPROCESS) {
  2034. UniformIntRNG rng{-50, 50};
  2035. float epsilon = 0.001;
  2036. #define cb(name) \
  2037. check_conv_bias_preprocess( \
  2038. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2039. handle(), &rng, epsilon, \
  2040. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2041. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2042. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  2043. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2044. handle(), &rng, epsilon, \
  2045. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2046. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2047. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2048. #if MEGDNN_AARCH64
  2049. #if __ARM_FEATURE_DOTPROD
  2050. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  2051. #else
  2052. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  2053. #endif
  2054. #elif MEGDNN_ARMV7
  2055. #if __ARM_FEATURE_DOTPROD
  2056. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  2057. #endif
  2058. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  2059. #endif
  2060. #undef cb
  2061. }
  2062. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  2063. UniformIntRNG rng{-50, 50};
  2064. float epsilon = 0.001;
  2065. std::vector<conv_bias::TestArg> args_nchw44 =
  2066. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, true, true, true,
  2067. false, false, false, false, true);
  2068. std::vector<conv_bias::TestArg> args_nchw44_1x1s2 =
  2069. get_nchw44_conv_bias_args({1}, 2, true, true, true, false, false,
  2070. false, false, true);
  2071. #define cb(name) \
  2072. checker_conv_bias( \
  2073. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2074. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2075. dtype::Int16{}, dtype::Int16{}, name); \
  2076. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  2077. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2078. dtype::Int16{}, dtype::Int16{}, name);
  2079. #define cb_nchw44(name) \
  2080. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2081. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name); \
  2082. checker_conv_bias(args_nchw44_1x1s2, handle(), &rng, epsilon, \
  2083. dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  2084. dtype::Int16{}, name);
  2085. #if MEGDNN_AARCH64
  2086. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2087. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2088. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2089. #elif MEGDNN_ARMV7
  2090. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2091. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2092. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2093. cb_nchw44("IM2COLMATMUL:ARMV7_INT8X8X16_MK4_K8X8X4");
  2094. #endif
  2095. #undef cb
  2096. #undef cb_nchw44
  2097. }
  2098. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_FILTERPREPROCESS) {
  2099. UniformIntRNG rng{-50, 50};
  2100. float epsilon = 0.001;
  2101. #define cb(name) \
  2102. check_conv_bias_preprocess( \
  2103. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2104. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2105. dtype::Int16{}, dtype::Int16{}, name); \
  2106. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2107. handle(), &rng, epsilon, dtype::Int8{}, \
  2108. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2109. name);
  2110. #if MEGDNN_AARCH64
  2111. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2112. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2113. #elif MEGDNN_ARMV7
  2114. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2115. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2116. #endif
  2117. #undef cb
  2118. }
  2119. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_NOPACK_FILTERPREPROCESS) {
  2120. UniformIntRNG rng{-50, 50};
  2121. float epsilon = 0.001;
  2122. #define cb(name) \
  2123. check_conv_bias_preprocess( \
  2124. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2125. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2126. dtype::Int16{}, dtype::Int16{}, name); \
  2127. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2128. handle(), &rng, epsilon, dtype::Int8{}, \
  2129. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2130. name);
  2131. #if MEGDNN_AARCH64
  2132. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2133. #elif MEGDNN_ARMV7
  2134. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2135. #endif
  2136. #undef cb
  2137. }
  2138. #endif
  2139. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2140. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  2141. using namespace conv_bias;
  2142. param::ConvBias cur_param;
  2143. std::vector<conv_bias::TestArg> args =
  2144. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2145. std::vector<conv_bias::TestArg> args1 =
  2146. get_conv_bias_args({1}, 2, false, false, false);
  2147. args.insert(args.begin(), args1.begin(), args1.end());
  2148. NormalRNG rng(1);
  2149. #define cb(name) \
  2150. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2151. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  2152. name);
  2153. #if MEGDNN_AARCH64
  2154. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2155. #elif MEGDNN_ARMV7
  2156. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2157. #endif
  2158. #undef cb
  2159. }
  2160. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16_FILTERPREPROCESS) {
  2161. using namespace conv_bias;
  2162. param::ConvBias cur_param;
  2163. std::vector<conv_bias::TestArg> args =
  2164. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2165. std::vector<conv_bias::TestArg> args1 =
  2166. get_conv_bias_args({1}, 2, false, false, false);
  2167. args.insert(args.begin(), args1.begin(), args1.end());
  2168. NormalRNG rng(1);
  2169. #define cb(name) \
  2170. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2171. dtype::Float16{}, dtype::Float16{}, \
  2172. dtype::Float16{}, name);
  2173. #if MEGDNN_AARCH64
  2174. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2175. #elif MEGDNN_ARMV7
  2176. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2177. #endif
  2178. #undef cb
  2179. }
  2180. #endif
  2181. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  2182. Handle* handle, const char* algo_name) {
  2183. using namespace conv_bias;
  2184. Checker<ConvBias> checker(handle);
  2185. checker.set_before_exec_callback(
  2186. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2187. checker.set_dtype(0, dtype::Int8());
  2188. checker.set_dtype(1, dtype::Int8());
  2189. checker.set_dtype(2, dtype::Int32());
  2190. checker.set_dtype(4, dtype::Int32());
  2191. for (auto&& arg : args) {
  2192. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2193. }
  2194. UniformIntRNG rng{-50, 50};
  2195. for (auto&& arg : args) {
  2196. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2197. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2198. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2199. .set_dtype(4, {})
  2200. .set_rng(0, &rng)
  2201. .set_rng(1, &rng)
  2202. .set_rng(2, &rng)
  2203. .set_param(arg.param)
  2204. .execs({arg.src, arg.filter, {}, {}, {}});
  2205. }
  2206. }
  2207. void checker_conv_bias_int8x8x32_preprocess(std::vector<conv_bias::TestArg> args,
  2208. Handle* handle, const char* algo_name) {
  2209. using namespace conv_bias;
  2210. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  2211. handle);
  2212. checker.set_before_exec_callback(
  2213. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2214. checker.set_dtype(0, dtype::Int8());
  2215. checker.set_dtype(1, dtype::Int8());
  2216. checker.set_dtype(2, dtype::Int32());
  2217. checker.set_dtype(4, dtype::Int32());
  2218. for (auto&& arg : args) {
  2219. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2220. }
  2221. UniformIntRNG rng{-50, 50};
  2222. for (auto&& arg : args) {
  2223. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2224. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2225. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2226. .set_dtype(4, {})
  2227. .set_rng(0, &rng)
  2228. .set_rng(1, &rng)
  2229. .set_rng(2, &rng)
  2230. .set_param(arg.param)
  2231. .execs({arg.src, arg.filter, {}, {}, {}});
  2232. }
  2233. }
  2234. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2235. #if !__ARM_FEATURE_DOTPROD
  2236. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  2237. using namespace conv_bias;
  2238. std::vector<conv_bias::TestArg> args =
  2239. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2240. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2241. #if MEGDNN_AARCH64
  2242. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2243. #else
  2244. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2245. #endif
  2246. #undef cb
  2247. }
  2248. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2_PREPROCESS) {
  2249. using namespace conv_bias;
  2250. std::vector<conv_bias::TestArg> args =
  2251. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2252. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2253. #if MEGDNN_AARCH64
  2254. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2255. #else
  2256. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2257. #endif
  2258. #undef cb
  2259. }
  2260. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  2261. using namespace conv_bias;
  2262. std::vector<conv_bias::TestArg> args =
  2263. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2264. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2265. #if MEGDNN_AARCH64
  2266. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2267. #else
  2268. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2269. #endif
  2270. #undef cb
  2271. }
  2272. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1_PREPROCESS) {
  2273. using namespace conv_bias;
  2274. std::vector<conv_bias::TestArg> args =
  2275. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2276. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2277. #if MEGDNN_AARCH64
  2278. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2279. #else
  2280. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2281. #endif
  2282. #undef cb
  2283. }
  2284. TEST_F(ARM_COMMON_MULTI_THREADS,
  2285. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  2286. UniformIntRNG rng{-50, 50};
  2287. #define cb(name) \
  2288. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  2289. epsilon, dtype::QuantizedS8(2.5f), \
  2290. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2291. dtype::QuantizedS8(60.25f), name);
  2292. float epsilon = 0.001;
  2293. #if MEGDNN_AARCH64
  2294. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2295. #else
  2296. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2297. #endif
  2298. #undef cb
  2299. }
  2300. TEST_F(ARM_COMMON_MULTI_THREADS,
  2301. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2_PREPROCESS) {
  2302. UniformIntRNG rng{-50, 50};
  2303. #define cb(name) \
  2304. check_conv_bias_preprocess( \
  2305. get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, epsilon, \
  2306. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2307. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2308. float epsilon = 0.001;
  2309. #if MEGDNN_AARCH64
  2310. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2311. #else
  2312. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2313. #endif
  2314. #undef cb
  2315. }
  2316. TEST_F(ARM_COMMON_MULTI_THREADS,
  2317. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  2318. UniformIntRNG rng{-50, 50};
  2319. #define cb(name) \
  2320. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  2321. epsilon, dtype::QuantizedS8(2.5f), \
  2322. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2323. dtype::QuantizedS8(60.25f), name);
  2324. float epsilon = 0.001;
  2325. #if MEGDNN_AARCH64
  2326. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2327. #else
  2328. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2329. #endif
  2330. #undef cb
  2331. }
  2332. TEST_F(ARM_COMMON_MULTI_THREADS,
  2333. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1_PREPROCESS) {
  2334. UniformIntRNG rng{-50, 50};
  2335. #define cb(name) \
  2336. check_conv_bias_preprocess( \
  2337. get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, epsilon, \
  2338. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2339. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2340. float epsilon = 0.001;
  2341. #if MEGDNN_AARCH64
  2342. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2343. #else
  2344. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2345. #endif
  2346. #undef cb
  2347. }
  2348. #if MEGDNN_AARCH64
  2349. TEST_F(ARM_COMMON_MULTI_THREADS,
  2350. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  2351. UniformIntRNG rng{-50, 50};
  2352. #define cb(name) \
  2353. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  2354. epsilon, dtype::QuantizedS8(2.5f), \
  2355. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2356. dtype::QuantizedS8(60.25f), name);
  2357. float epsilon = 0.001;
  2358. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2359. #undef cb
  2360. }
  2361. TEST_F(ARM_COMMON_MULTI_THREADS,
  2362. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE_PREPROCESS) {
  2363. UniformIntRNG rng{-50, 50};
  2364. #define cb(name) \
  2365. check_conv_bias_preprocess( \
  2366. get_nchw44_conv_bias_args({3}, 1), handle(), &rng, epsilon, \
  2367. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2368. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2369. float epsilon = 0.001;
  2370. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2371. #undef cb
  2372. }
  2373. #endif
  2374. #endif
  2375. #endif
  2376. #if MEGDNN_AARCH64
  2377. #if __ARM_FEATURE_DOTPROD
  2378. TEST_F(ARM_COMMON_MULTI_THREADS,
  2379. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE) {
  2380. UniformIntRNG rng{-50, 50};
  2381. #define cb(name) \
  2382. checker_conv_bias( \
  2383. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2384. true, false, false, false), \
  2385. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2386. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2387. dtype::QuantizedS8(60.25f), name);
  2388. float epsilon = 0.001;
  2389. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2390. #undef cb
  2391. }
  2392. TEST_F(ARM_COMMON_MULTI_THREADS,
  2393. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE_PREPROCESS) {
  2394. UniformIntRNG rng{-50, 50};
  2395. #define cb(name) \
  2396. check_conv_bias_preprocess( \
  2397. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2398. true, false, false, false), \
  2399. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2400. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2401. dtype::QuantizedS8(60.25f), name);
  2402. float epsilon = 0.001;
  2403. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2404. #undef cb
  2405. }
  2406. #endif
  2407. #endif
  2408. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  2409. using namespace conv_bias;
  2410. std::vector<conv_bias::TestArg> args =
  2411. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2412. std::vector<conv_bias::TestArg> args1 =
  2413. get_conv_bias_args({1}, 2, false, true, true);
  2414. args.insert(args.begin(), args1.begin(), args1.end());
  2415. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2416. #if MEGDNN_AARCH64
  2417. #if __ARM_FEATURE_DOTPROD
  2418. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2419. #else
  2420. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2421. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2422. #endif
  2423. #elif MEGDNN_ARMV7
  2424. #if __ARM_FEATURE_DOTPROD
  2425. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2426. #endif
  2427. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2428. #endif
  2429. #if MEGDNN_ARMV7
  2430. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2431. #endif
  2432. #undef cb
  2433. }
  2434. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8X8X32_FILTER_PREPROCESS) {
  2435. using namespace conv_bias;
  2436. std::vector<conv_bias::TestArg> args =
  2437. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2438. std::vector<conv_bias::TestArg> args1 =
  2439. get_conv_bias_args({1}, 2, false, true, true);
  2440. args.insert(args.begin(), args1.begin(), args1.end());
  2441. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2442. #if MEGDNN_AARCH64
  2443. #if __ARM_FEATURE_DOTPROD
  2444. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2445. #else
  2446. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2447. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2448. #endif
  2449. #elif MEGDNN_ARMV7
  2450. #if __ARM_FEATURE_DOTPROD
  2451. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2452. #endif
  2453. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2454. #endif
  2455. #if MEGDNN_ARMV7
  2456. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2457. #endif
  2458. #undef cb
  2459. }
  2460. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  2461. using namespace conv_bias;
  2462. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2463. {2, 4, 7}, 1, false, false, false, false, false, true, true);
  2464. #if MEGDNN_AARCH64
  2465. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2466. #elif MEGDNN_ARMV7
  2467. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2468. #endif
  2469. }
  2470. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32_PREPROCESS) {
  2471. using namespace conv_bias;
  2472. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2473. {2, 4, 7}, 1, false, false, false, false, false, true,true);
  2474. #define cb(name) \
  2475. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2476. dtype::Float32(), dtype::Float32(), \
  2477. dtype::Float32(), dtype::Float32(), name);
  2478. #if MEGDNN_AARCH64
  2479. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2480. #elif MEGDNN_ARMV7
  2481. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2482. #endif
  2483. #undef cb
  2484. }
  2485. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  2486. using namespace conv_bias;
  2487. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2488. {3, 5, 6}, 2, false, false, false, false, false, true, true);
  2489. #define cb(name) check_conv_bias(args, handle(), name);
  2490. #if MEGDNN_AARCH64
  2491. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2492. #elif MEGDNN_ARMV7
  2493. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2494. #endif
  2495. #undef cb
  2496. }
  2497. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE_PREPROCESS) {
  2498. using namespace conv_bias;
  2499. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2500. {3}, 2, false, false, false, false, false, true, true, false);
  2501. #define cb(name) \
  2502. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2503. dtype::Float32(), dtype::Float32(), \
  2504. dtype::Float32(), dtype::Float32(), name);
  2505. #if MEGDNN_AARCH64
  2506. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2507. #elif MEGDNN_ARMV7
  2508. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2509. #endif
  2510. #undef cb
  2511. }
  2512. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE) {
  2513. using namespace conv_bias;
  2514. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2515. {3}, 2, false, false, false, false, false, true, true, false);
  2516. #define cb(name) check_conv_bias(args, handle(), name);
  2517. #if MEGDNN_AARCH64
  2518. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2519. #elif MEGDNN_ARMV7
  2520. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2521. #endif
  2522. #undef cb
  2523. }
  2524. /***************************** Conv1x1 Algo Test ***********************/
  2525. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  2526. using namespace conv_bias;
  2527. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2528. #if MEGDNN_AARCH64
  2529. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  2530. #elif MEGDNN_ARMV7
  2531. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  2532. #endif
  2533. std::vector<conv_bias::TestArg> gemv_args;
  2534. for (auto&& arg : args)
  2535. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2536. gemv_args.emplace_back(arg);
  2537. }
  2538. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2539. }
  2540. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32_PREPROCESS) {
  2541. using namespace conv_bias;
  2542. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2543. #define cb(name) \
  2544. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2545. dtype::Float32(), dtype::Float32(), \
  2546. dtype::Float32(), dtype::Float32(), name);
  2547. #if MEGDNN_AARCH64
  2548. cb("CONV1x1:AARCH64_F32K8X12X1:24");
  2549. #elif MEGDNN_ARMV7
  2550. cb("CONV1x1:ARMV7_F32:48");
  2551. #endif
  2552. #undef cb
  2553. }
  2554. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  2555. using namespace conv_bias;
  2556. std::vector<conv_bias::TestArg> args =
  2557. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2558. #if MEGDNN_AARCH64
  2559. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2560. #elif MEGDNN_ARMV7
  2561. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2562. #endif
  2563. std::vector<conv_bias::TestArg> gemv_args;
  2564. for (auto&& arg : args)
  2565. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2566. gemv_args.emplace_back(arg);
  2567. }
  2568. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2569. }
  2570. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32_PREPROCESS) {
  2571. using namespace conv_bias;
  2572. std::vector<conv_bias::TestArg> args =
  2573. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2574. #define cb(name) \
  2575. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2576. dtype::Float32(), dtype::Float32(), \
  2577. dtype::Float32(), dtype::Float32(), name);
  2578. #if MEGDNN_AARCH64
  2579. cb("CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2580. #elif MEGDNN_ARMV7
  2581. cb("CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2582. #endif
  2583. #undef cb
  2584. }
  2585. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  2586. using namespace conv_bias;
  2587. std::vector<conv_bias::TestArg> args =
  2588. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2589. std::vector<conv_bias::TestArg> args_of_4;
  2590. for (auto&& arg : args) {
  2591. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  2592. args_of_4.push_back(arg);
  2593. }
  2594. }
  2595. #if MEGDNN_AARCH64
  2596. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  2597. #elif MEGDNN_ARMV7
  2598. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  2599. #endif
  2600. }
  2601. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2602. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  2603. using namespace conv_bias;
  2604. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2605. NormalRNG rng(1);
  2606. #if MEGDNN_AARCH64
  2607. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2608. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2609. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2610. #elif MEGDNN_ARMV7
  2611. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2612. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2613. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2614. #endif
  2615. std::vector<conv_bias::TestArg> gemv_args;
  2616. for (auto&& arg : args)
  2617. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2618. gemv_args.emplace_back(arg);
  2619. }
  2620. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2621. }
  2622. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16_PREPROCESS) {
  2623. using namespace conv_bias;
  2624. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2625. NormalRNG rng(1);
  2626. #if MEGDNN_AARCH64
  2627. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{},
  2628. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2629. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2630. #elif MEGDNN_ARMV7
  2631. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{},
  2632. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2633. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2634. #endif
  2635. }
  2636. #endif
  2637. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  2638. UniformIntRNG rng{-50, 50};
  2639. float epsilon = 0.001;
  2640. std::vector<conv_bias::TestArg> args =
  2641. get_conv_bias_1x1_args(false, false, true, true);
  2642. #define cb(name) \
  2643. checker_conv_bias(args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2644. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2645. dtype::QuantizedS8(60.25f), name);
  2646. #if MEGDNN_AARCH64
  2647. #if __ARM_FEATURE_DOTPROD
  2648. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2649. #else
  2650. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2651. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2652. #endif
  2653. #elif MEGDNN_ARMV7
  2654. epsilon = 1;
  2655. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2656. #endif
  2657. #undef cb
  2658. std::vector<conv_bias::TestArg> gemv_args;
  2659. for (auto&& arg : args)
  2660. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2661. gemv_args.emplace_back(arg);
  2662. }
  2663. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2664. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2665. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2666. "CONV1x1_GEMV");
  2667. }
  2668. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM_PREPROCESS) {
  2669. UniformIntRNG rng{-50, 50};
  2670. float epsilon = 0.001;
  2671. std::vector<conv_bias::TestArg> args =
  2672. get_conv_bias_1x1_args(false, false, true, true);
  2673. #define cb(name) \
  2674. check_conv_bias_preprocess( \
  2675. args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2676. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2677. dtype::QuantizedS8(60.25f), name);
  2678. #if MEGDNN_AARCH64
  2679. #if __ARM_FEATURE_DOTPROD
  2680. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2681. #else
  2682. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2683. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2684. #endif
  2685. #elif MEGDNN_ARMV7
  2686. epsilon = 1;
  2687. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2688. #endif
  2689. #undef cb
  2690. }
  2691. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2692. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  2693. UniformIntRNG rng{-50, 50};
  2694. std::vector<conv_bias::TestArg> args =
  2695. get_conv_bias_1x1_args(false, false, true, true);
  2696. #define cb(name) \
  2697. checker_conv_bias(args, handle(), &rng, epsilon, \
  2698. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2699. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2700. dtype::QuantizedS32(1.2 * 1.3), \
  2701. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2702. float epsilon = 0.001;
  2703. #if MEGDNN_AARCH64
  2704. #if __ARM_FEATURE_DOTPROD
  2705. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2706. #else
  2707. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2708. #endif
  2709. #elif MEGDNN_ARMV7
  2710. epsilon = 1;
  2711. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2712. #endif
  2713. #undef cb
  2714. std::vector<conv_bias::TestArg> gemv_args;
  2715. for (auto&& arg : args)
  2716. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2717. gemv_args.emplace_back(arg);
  2718. }
  2719. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2720. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2721. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2722. dtype::QuantizedS32(1.2 * 1.3),
  2723. dtype::Quantized8Asymm(50.3f, (uint8_t)120),
  2724. "CONV1x1_GEMV");
  2725. }
  2726. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM_PREPROCESS) {
  2727. UniformIntRNG rng{-50, 50};
  2728. std::vector<conv_bias::TestArg> args =
  2729. get_conv_bias_1x1_args(false, false, true, true);
  2730. #define cb(name) \
  2731. check_conv_bias_preprocess(args, handle(), &rng, epsilon, \
  2732. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2733. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2734. dtype::QuantizedS32(1.2 * 1.3), \
  2735. dtype::Quantized8Asymm(50.3f, (uint8_t)120), \
  2736. name);
  2737. float epsilon = 0.001;
  2738. #if MEGDNN_AARCH64
  2739. #if __ARM_FEATURE_DOTPROD
  2740. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2741. #else
  2742. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2743. #endif
  2744. #elif MEGDNN_ARMV7
  2745. epsilon = 1;
  2746. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2747. #endif
  2748. #undef cb
  2749. }
  2750. #endif
  2751. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2752. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  2753. NormalRNG rng(128.f);
  2754. float epsilon = 0.001;
  2755. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2756. #define cb(name) \
  2757. checker_conv_bias(args, handle(), &rng, epsilon, \
  2758. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2759. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2760. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2761. #if MEGDNN_AARCH64
  2762. #if __ARM_FEATURE_DOTPROD
  2763. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2764. #else
  2765. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2766. #endif
  2767. #elif MEGDNN_ARMV7
  2768. #if __ARM_FEATURE_DOTPROD
  2769. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2770. #endif
  2771. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2772. #endif
  2773. #undef cb
  2774. std::vector<conv_bias::TestArg> gemv_args;
  2775. for (auto&& arg : args)
  2776. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2777. gemv_args.emplace_back(arg);
  2778. }
  2779. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2780. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  2781. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  2782. dtype::QuantizedS32(1.2 * 1.3), {}, "CONV1x1_GEMV");
  2783. }
  2784. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32_PREPROCESS) {
  2785. NormalRNG rng(128.f);
  2786. float epsilon = 0.001;
  2787. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2788. #define cb(name) \
  2789. check_conv_bias_preprocess(args, handle(), &rng, epsilon, \
  2790. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2791. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2792. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2793. #if MEGDNN_AARCH64
  2794. #if __ARM_FEATURE_DOTPROD
  2795. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2796. #else
  2797. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2798. #endif
  2799. #elif MEGDNN_ARMV7
  2800. #if __ARM_FEATURE_DOTPROD
  2801. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2802. #endif
  2803. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2804. #endif
  2805. #undef cb
  2806. }
  2807. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  2808. UniformIntRNG rng{-50, 50};
  2809. float epsilon = 0.001;
  2810. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2811. std::vector<conv_bias::TestArg> args_nchw44 = get_nchw44_conv_bias_args(
  2812. {1}, 1, true, true, true, false, false, false, false, true);
  2813. #define cb(name) \
  2814. checker_conv_bias(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2815. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2816. #define cb_nchw44(name) \
  2817. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2818. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2819. #if MEGDNN_AARCH64
  2820. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2821. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2822. #elif MEGDNN_ARMV7
  2823. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2824. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2825. cb_nchw44("CONV1x1:ARMV7_INT8X8X16_MK4_K8X8X4:48");
  2826. #endif
  2827. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  2828. #undef cb
  2829. #undef cb_nchw44
  2830. std::vector<conv_bias::TestArg> gemv_args;
  2831. for (auto&& arg : args)
  2832. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2833. gemv_args.emplace_back(arg);
  2834. }
  2835. checker_conv_bias(gemv_args, handle(), &rng, epsilon, dtype::Int8{},
  2836. dtype::Int8{}, dtype::Int16{}, dtype::Int16{},
  2837. "CONV1x1_GEMV");
  2838. }
  2839. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16_PREPROCESS) {
  2840. UniformIntRNG rng{-50, 50};
  2841. float epsilon = 0.001;
  2842. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2843. #define cb(name) \
  2844. check_conv_bias_preprocess(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2845. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2846. name);
  2847. #if MEGDNN_AARCH64
  2848. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2849. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2850. cb("CONV1x1:ARM_COMMON_INT8X8X16:24");//!add nopack test
  2851. #elif MEGDNN_ARMV7
  2852. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2853. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2854. cb("CONV1x1:ARM_COMMON_INT8X8X16:24");//!add nopack test
  2855. #endif
  2856. #undef cb
  2857. }
  2858. #endif
  2859. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  2860. using namespace conv_bias;
  2861. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2862. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2863. #if MEGDNN_AARCH64
  2864. #if __ARM_FEATURE_DOTPROD
  2865. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2866. #else
  2867. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2868. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2869. #endif
  2870. #elif MEGDNN_ARMV7
  2871. #if __ARM_FEATURE_DOTPROD
  2872. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2873. #endif
  2874. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2875. #endif
  2876. #if MEGDNN_ARMV7
  2877. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2878. #endif
  2879. #undef cb
  2880. std::vector<conv_bias::TestArg> gemv_args;
  2881. for (auto&& arg : args)
  2882. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2883. gemv_args.emplace_back(arg);
  2884. }
  2885. checker_conv_bias_mul_int8x8x32(gemv_args, handle(), "CONV1x1_GEMV");
  2886. }
  2887. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_PREPROCESS) {
  2888. using namespace conv_bias;
  2889. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2890. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2891. #if MEGDNN_AARCH64
  2892. #if __ARM_FEATURE_DOTPROD
  2893. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2894. #else
  2895. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2896. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2897. #endif
  2898. #elif MEGDNN_ARMV7
  2899. #if __ARM_FEATURE_DOTPROD
  2900. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2901. #endif
  2902. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2903. #endif
  2904. #if MEGDNN_ARMV7
  2905. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2906. #endif
  2907. #undef cb
  2908. }
  2909. #ifndef __ARM_FEATURE_DOTPROD
  2910. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  2911. using namespace conv_bias;
  2912. std::vector<conv_bias::TestArg> args =
  2913. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2914. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2915. #if MEGDNN_AARCH64
  2916. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2917. #elif MEGDNN_ARMV7
  2918. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2919. #endif
  2920. #undef cb
  2921. UniformIntRNG rng{-50, 50};
  2922. float epsilon = 0.001;
  2923. #define cb(name) \
  2924. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2925. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2926. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2927. dtype::QuantizedS8(60.25f), name);
  2928. #if MEGDNN_AARCH64
  2929. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2930. #elif MEGDNN_ARMV7
  2931. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2932. #endif
  2933. #undef cb
  2934. }
  2935. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4_PREPROCESS) {
  2936. using namespace conv_bias;
  2937. std::vector<conv_bias::TestArg> args =
  2938. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2939. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2940. #if MEGDNN_AARCH64
  2941. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2942. #elif MEGDNN_ARMV7
  2943. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2944. #endif
  2945. #undef cb
  2946. UniformIntRNG rng{-50, 50};
  2947. float epsilon = 0.001;
  2948. #define cb(name) \
  2949. check_conv_bias_preprocess(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2950. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2951. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2952. dtype::QuantizedS8(60.25f), name);
  2953. #if MEGDNN_AARCH64
  2954. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2955. #elif MEGDNN_ARMV7
  2956. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2957. #endif
  2958. #undef cb
  2959. }
  2960. #endif
  2961. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  2962. using namespace conv_bias;
  2963. std::vector<conv_bias::TestArg> args =
  2964. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2965. UniformIntRNG rng{-50, 50};
  2966. float epsilon = 0.001;
  2967. std::vector<conv_bias::TestArg> gemv_args;
  2968. for (auto&& arg : args)
  2969. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2970. gemv_args.emplace_back(arg);
  2971. }
  2972. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2973. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2974. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2975. "CONV1x1_GEMV");
  2976. }
  2977. #ifdef __ARM_FEATURE_DOTPROD
  2978. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  2979. using namespace conv_bias;
  2980. std::vector<conv_bias::TestArg> args =
  2981. get_nchw44_conv_bias_args({1}, 1, true, false, false, false, true);
  2982. UniformIntRNG rng{-50, 50};
  2983. float epsilon = 0.001;
  2984. std::vector<conv_bias::TestArg> gemv_args;
  2985. for (auto&& arg : args)
  2986. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2987. gemv_args.emplace_back(arg);
  2988. }
  2989. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2990. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2991. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2992. "CONV1x1_GEMV");
  2993. }
  2994. #endif
  2995. // vim: syntax=cpp.doxygen

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