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

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

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