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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229
  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. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54) {
  691. using namespace conv_bias;
  692. std::vector<TestArg> args = get_winograd_args(4);
  693. Checker<ConvBiasForward> checker(handle());
  694. check_winograd("1:5:32", checker, args);
  695. }
  696. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F54_WEIGHT_PREPROCESS) {
  697. using namespace conv_bias;
  698. std::vector<TestArg> args = get_winograd_args(4);
  699. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  700. handle());
  701. check_winograd("1:5:32", checker, args);
  702. }
  703. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45) {
  704. using namespace conv_bias;
  705. std::vector<TestArg> args = get_winograd_args(5);
  706. Checker<ConvBiasForward> checker(handle());
  707. check_winograd("1:4:32", checker, args);
  708. }
  709. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F45_WEIGHT_PREPROCESS) {
  710. using namespace conv_bias;
  711. std::vector<TestArg> args = get_winograd_args(5);
  712. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  713. handle());
  714. check_winograd("1:4:32", checker, args);
  715. }
  716. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD) {
  717. using namespace conv_bias;
  718. std::vector<TestArg> args = get_winograd_args(3);
  719. Checker<ConvBiasForward> checker(handle());
  720. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  721. param::ConvBias param, Handle* handle) {
  722. megdnn_assert(param.format == param::ConvBias::Format::NCHW);
  723. auto winograd_preprocess_opr =
  724. handle->create_operator<WinogradFilterPreprocess>();
  725. winograd_preprocess_opr->param().output_block_size = m;
  726. TensorLayout filter_transform_layout;
  727. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  728. filter_transform_layout);
  729. size_t winograd_preprocess_workspace_in_bytes =
  730. winograd_preprocess_opr->get_workspace_in_bytes(
  731. tensors[1].layout, filter_transform_layout);
  732. auto conv_bias_opr = handle->create_operator<ConvBias>();
  733. conv_bias_opr->param() = param;
  734. conv_bias_opr->param().format = param::ConvBias::Format::NCHW_WINOGRAD;
  735. conv_bias_opr->param().output_block_size = m;
  736. size_t conv_bias_workspace_in_bytes =
  737. conv_bias_opr->get_workspace_in_bytes(
  738. tensors[0].layout, filter_transform_layout,
  739. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  740. nullptr);
  741. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  742. conv_bias_workspace_in_bytes,
  743. winograd_preprocess_workspace_in_bytes});
  744. wb.set(malloc(wb.total_size_in_bytes()));
  745. TensorND filter_transform_tensor(wb.get(0),
  746. std::move(filter_transform_layout));
  747. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  748. wb.get_workspace(2));
  749. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  750. tensors[3], tensors[4], nullptr,
  751. wb.get_workspace(1));
  752. free(wb.ptr());
  753. };
  754. auto run = [&checker, &extra_impl](
  755. Handle* handle, const std::vector<TestArg>& args,
  756. const std::vector<size_t>& out_size, DType A_dtype,
  757. DType B_dtype, DType C_dtype, DType D_dtype,
  758. const float eps) {
  759. for (auto&& arg : args) {
  760. for (uint32_t m : out_size) {
  761. checker.set_extra_opr_impl(std::bind(extra_impl,
  762. std::placeholders::_1, m,
  763. arg.param, handle));
  764. checker.set_dtype(0, A_dtype)
  765. .set_dtype(1, B_dtype)
  766. .set_dtype(2, C_dtype)
  767. .set_dtype(4, D_dtype)
  768. .set_epsilon(eps)
  769. .set_param(arg.param)
  770. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  771. }
  772. }
  773. };
  774. run(handle(), args, {6}, dtype::Float32(), dtype::Float32(),
  775. dtype::Float32(), dtype::Float32(), 1e-3f);
  776. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  777. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  778. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  779. run(handle(), args, {6}, dtype::Float16(), dtype::Float16(),
  780. dtype::Float16(), dtype::Float16(), 0.35f);
  781. #endif
  782. }
  783. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_PREPROCESS_NCHW44) {
  784. using namespace conv_bias;
  785. std::vector<TestArg> nchw44_args = get_nchw44_conv_bias_args({3}, 1);
  786. Checker<ConvBiasForward> checker(handle());
  787. auto extra_impl = [](const TensorNDArray& tensors, uint32_t m,
  788. param::ConvBias param, Handle* handle) {
  789. megdnn_assert(param.format == param::ConvBias::Format::NCHW44);
  790. auto winograd_preprocess_opr =
  791. handle->create_operator<WinogradFilterPreprocess>();
  792. winograd_preprocess_opr->param().output_block_size = m;
  793. winograd_preprocess_opr->param().format = param::MatrixMul::Format::MK4;
  794. TensorLayout filter_transform_layout;
  795. winograd_preprocess_opr->deduce_layout(tensors[1].layout,
  796. filter_transform_layout);
  797. size_t winograd_preprocess_workspace_in_bytes =
  798. winograd_preprocess_opr->get_workspace_in_bytes(
  799. tensors[1].layout, filter_transform_layout);
  800. auto conv_bias_opr = handle->create_operator<ConvBias>();
  801. conv_bias_opr->param() = param;
  802. conv_bias_opr->param().format =
  803. param::ConvBias::Format::NCHW44_WINOGRAD;
  804. conv_bias_opr->param().output_block_size = m;
  805. size_t conv_bias_workspace_in_bytes =
  806. conv_bias_opr->get_workspace_in_bytes(
  807. tensors[0].layout, filter_transform_layout,
  808. tensors[2].layout, tensors[3].layout, tensors[4].layout,
  809. nullptr);
  810. WorkspaceBundle wb(nullptr, {filter_transform_layout.span().dist_byte(),
  811. conv_bias_workspace_in_bytes,
  812. winograd_preprocess_workspace_in_bytes});
  813. wb.set(malloc(wb.total_size_in_bytes()));
  814. TensorND filter_transform_tensor(wb.get(0),
  815. std::move(filter_transform_layout));
  816. winograd_preprocess_opr->exec(tensors[1], filter_transform_tensor,
  817. wb.get_workspace(2));
  818. conv_bias_opr->exec(tensors[0], filter_transform_tensor, tensors[2],
  819. tensors[3], tensors[4], nullptr,
  820. wb.get_workspace(1));
  821. free(wb.ptr());
  822. };
  823. auto run = [&checker, &extra_impl](
  824. Handle* handle, const std::vector<TestArg>& args,
  825. const std::vector<size_t>& out_size, DType A_dtype,
  826. DType B_dtype, DType C_dtype, DType D_dtype,
  827. const float eps) {
  828. for (auto&& arg : args) {
  829. for (uint32_t m : out_size) {
  830. checker.set_extra_opr_impl(std::bind(extra_impl,
  831. std::placeholders::_1, m,
  832. arg.param, handle));
  833. checker.set_dtype(0, A_dtype)
  834. .set_dtype(1, B_dtype)
  835. .set_dtype(2, C_dtype)
  836. .set_dtype(4, D_dtype)
  837. .set_epsilon(eps)
  838. .set_param(arg.param)
  839. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  840. }
  841. }
  842. };
  843. run(handle(), nchw44_args, {2, 6}, dtype::Float32(), dtype::Float32(),
  844. dtype::Float32(), dtype::Float32(), 1e-3f);
  845. }
  846. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_1) {
  847. using namespace conv_bias;
  848. Checker<ConvBiasForward> checker(handle());
  849. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  850. const std::vector<size_t>& out_size, DType A_dtype,
  851. DType B_dtype, DType C_dtype, DType D_dtype,
  852. param::MatrixMul::Format format, float eps) {
  853. for (auto&& arg : args) {
  854. for (uint32_t m : out_size) {
  855. checker.set_extra_opr_impl(std::bind(
  856. winograd_algo_extra_impl, std::placeholders::_1, m,
  857. arg.param, handle, format));
  858. checker.set_dtype(0, A_dtype)
  859. .set_dtype(1, B_dtype)
  860. .set_dtype(2, C_dtype)
  861. .set_dtype(4, D_dtype)
  862. .set_epsilon(eps)
  863. .set_param(arg.param)
  864. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  865. }
  866. }
  867. };
  868. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  869. std::vector<TestArg> args_first_half(args.begin(),
  870. args.begin() + args.size() / 2);
  871. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  872. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  873. 1e-3f);
  874. }
  875. TEST_F(ARM_COMMON_MULTI_THREADS,
  876. CONV_BIAS_WINOGRAD_MK_PACKED_F32_1_WEIGHT_PREPROCESS) {
  877. using namespace conv_bias;
  878. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  879. handle());
  880. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  881. const std::vector<size_t>& out_size, DType A_dtype,
  882. DType B_dtype, DType C_dtype, DType D_dtype,
  883. param::MatrixMul::Format format, float eps) {
  884. for (auto&& arg : args) {
  885. for (uint32_t m : out_size) {
  886. checker.set_extra_opr_impl(std::bind(
  887. winograd_algo_extra_impl, std::placeholders::_1, m,
  888. arg.param, handle, format));
  889. checker.set_dtype(0, A_dtype)
  890. .set_dtype(1, B_dtype)
  891. .set_dtype(2, C_dtype)
  892. .set_dtype(4, D_dtype)
  893. .set_epsilon(eps)
  894. .set_param(arg.param)
  895. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  896. }
  897. }
  898. };
  899. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  900. std::vector<TestArg> args_first_half(args.begin(),
  901. args.begin() + args.size() / 2);
  902. run(handle(), args_first_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  903. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  904. 1e-3f);
  905. }
  906. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F32_2) {
  907. using namespace conv_bias;
  908. Checker<ConvBiasForward> checker(handle());
  909. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  910. const std::vector<size_t>& out_size, DType A_dtype,
  911. DType B_dtype, DType C_dtype, DType D_dtype,
  912. param::MatrixMul::Format format, float eps) {
  913. for (auto&& arg : args) {
  914. for (uint32_t m : out_size) {
  915. checker.set_extra_opr_impl(std::bind(
  916. winograd_algo_extra_impl, std::placeholders::_1, m,
  917. arg.param, handle, format));
  918. checker.set_dtype(0, A_dtype)
  919. .set_dtype(1, B_dtype)
  920. .set_dtype(2, C_dtype)
  921. .set_dtype(4, D_dtype)
  922. .set_epsilon(eps)
  923. .set_param(arg.param)
  924. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  925. }
  926. }
  927. };
  928. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  929. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  930. args.end());
  931. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  932. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  933. 1e-3f);
  934. }
  935. TEST_F(ARM_COMMON_MULTI_THREADS,
  936. CONV_BIAS_WINOGRAD_MK_PACKED_F32_2_WEIGHT_PREPROCESS) {
  937. using namespace conv_bias;
  938. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  939. handle());
  940. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  941. const std::vector<size_t>& out_size, DType A_dtype,
  942. DType B_dtype, DType C_dtype, DType D_dtype,
  943. param::MatrixMul::Format format, float eps) {
  944. for (auto&& arg : args) {
  945. for (uint32_t m : out_size) {
  946. checker.set_extra_opr_impl(std::bind(
  947. winograd_algo_extra_impl, std::placeholders::_1, m,
  948. arg.param, handle, format));
  949. checker.set_dtype(0, A_dtype)
  950. .set_dtype(1, B_dtype)
  951. .set_dtype(2, C_dtype)
  952. .set_dtype(4, D_dtype)
  953. .set_epsilon(eps)
  954. .set_param(arg.param)
  955. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  956. }
  957. }
  958. };
  959. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  960. std::vector<TestArg> args_second_half(args.begin() + args.size() / 2,
  961. args.end());
  962. run(handle(), args_second_half, {2, 6}, dtype::Float32{}, dtype::Float32{},
  963. dtype::Float32{}, dtype::Float32{}, param::MatrixMul::Format::MK4,
  964. 1e-3f);
  965. }
  966. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  967. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_F16) {
  968. using namespace conv_bias;
  969. Checker<ConvBiasForward> checker(handle());
  970. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  971. const std::vector<size_t>& out_size, DType A_dtype,
  972. DType B_dtype, DType C_dtype, DType D_dtype,
  973. param::MatrixMul::Format format, float eps) {
  974. for (auto&& arg : args) {
  975. for (uint32_t m : out_size) {
  976. checker.set_extra_opr_impl(std::bind(
  977. winograd_algo_extra_impl, std::placeholders::_1, m,
  978. arg.param, handle, format));
  979. checker.set_dtype(0, A_dtype)
  980. .set_dtype(1, B_dtype)
  981. .set_dtype(2, C_dtype)
  982. .set_dtype(4, D_dtype)
  983. .set_epsilon(eps)
  984. .set_param(arg.param)
  985. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  986. }
  987. }
  988. };
  989. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  990. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  991. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  992. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  993. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  994. 0.25);
  995. }
  996. TEST_F(ARM_COMMON_MULTI_THREADS,
  997. CONV_BIAS_WINOGRAD_MK_PACKED_F16_WEIGHT_PREPROCESS) {
  998. using namespace conv_bias;
  999. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1000. handle());
  1001. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1002. const std::vector<size_t>& out_size, DType A_dtype,
  1003. DType B_dtype, DType C_dtype, DType D_dtype,
  1004. param::MatrixMul::Format format, float eps) {
  1005. for (auto&& arg : args) {
  1006. for (uint32_t m : out_size) {
  1007. checker.set_extra_opr_impl(std::bind(
  1008. winograd_algo_extra_impl, std::placeholders::_1, m,
  1009. arg.param, handle, format));
  1010. checker.set_dtype(0, A_dtype)
  1011. .set_dtype(1, B_dtype)
  1012. .set_dtype(2, C_dtype)
  1013. .set_dtype(4, D_dtype)
  1014. .set_epsilon(eps)
  1015. .set_param(arg.param)
  1016. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1017. }
  1018. }
  1019. };
  1020. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1021. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1022. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng);
  1023. run(handle(), args, {2}, dtype::Float16{}, dtype::Float16{},
  1024. dtype::Float16{}, dtype::Float16{}, param::MatrixMul::Format::MK8,
  1025. 0.25);
  1026. }
  1027. #endif
  1028. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_MK_PACKED_INT8) {
  1029. using namespace conv_bias;
  1030. Checker<ConvBiasForward> checker(handle());
  1031. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1032. const std::vector<size_t>& out_size, DType A_dtype,
  1033. DType B_dtype, DType C_dtype, DType D_dtype,
  1034. param::MatrixMul::Format format, float eps) {
  1035. for (auto&& arg : args) {
  1036. for (uint32_t m : out_size) {
  1037. checker.set_extra_opr_impl(std::bind(
  1038. winograd_algo_extra_impl, std::placeholders::_1, m,
  1039. arg.param, handle, format));
  1040. checker.set_dtype(0, A_dtype)
  1041. .set_dtype(1, B_dtype)
  1042. .set_dtype(2, C_dtype)
  1043. .set_dtype(4, D_dtype)
  1044. .set_epsilon(eps)
  1045. .set_param(arg.param)
  1046. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1047. }
  1048. }
  1049. };
  1050. #if MEGDNN_AARCH64
  1051. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1052. #else
  1053. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1054. #endif
  1055. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1056. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1057. std::vector<TestArg> quantized_args =
  1058. get_quantized_winograd_mk_packed_args(8);
  1059. UniformIntRNG int_rng{-50, 50};
  1060. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1061. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1062. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1063. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1064. }
  1065. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8) {
  1066. using namespace conv_bias;
  1067. Checker<ConvBiasForward> checker(handle());
  1068. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1069. const std::vector<size_t>& out_size, DType A_dtype,
  1070. DType B_dtype, DType C_dtype, DType D_dtype,
  1071. param::MatrixMul::Format format, float eps) {
  1072. for (auto&& arg : args) {
  1073. for (uint32_t m : out_size) {
  1074. checker.set_extra_opr_impl(std::bind(
  1075. winograd_algo_extra_impl, std::placeholders::_1, m,
  1076. arg.param, handle, format));
  1077. checker.set_dtype(0, A_dtype)
  1078. .set_dtype(1, B_dtype)
  1079. .set_dtype(2, C_dtype)
  1080. .set_dtype(4, D_dtype)
  1081. .set_epsilon(eps)
  1082. .set_param(arg.param)
  1083. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1084. }
  1085. }
  1086. };
  1087. #if MEGDNN_AARCH64
  1088. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1089. #else
  1090. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1091. #endif
  1092. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1093. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1094. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1095. UniformIntRNG int_rng{-50, 50};
  1096. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1097. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1098. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1099. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1100. }
  1101. TEST_F(ARM_COMMON_MULTI_THREADS,
  1102. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE) {
  1103. using namespace conv_bias;
  1104. Checker<ConvBiasForward> checker(handle());
  1105. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1106. const std::vector<size_t>& out_size, DType A_dtype,
  1107. DType B_dtype, DType C_dtype, DType D_dtype,
  1108. param::MatrixMul::Format format, float eps) {
  1109. for (auto&& arg : args) {
  1110. for (uint32_t m : out_size) {
  1111. checker.set_extra_opr_impl(std::bind(
  1112. winograd_algo_extra_impl, std::placeholders::_1, m,
  1113. arg.param, handle, format));
  1114. checker.set_dtype(0, A_dtype)
  1115. .set_dtype(1, B_dtype)
  1116. .set_dtype(2, C_dtype)
  1117. .set_dtype(4, D_dtype)
  1118. .set_epsilon(eps)
  1119. .set_param(arg.param)
  1120. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1121. }
  1122. }
  1123. };
  1124. #if MEGDNN_AARCH64
  1125. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1126. #else
  1127. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1128. #endif
  1129. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1130. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1131. std::vector<TestArg> quantized_args =
  1132. get_int8_nchw44_args(3, 4, false, true);
  1133. UniformIntRNG int_rng{-50, 50};
  1134. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1135. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1136. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1137. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1138. }
  1139. TEST_F(ARM_COMMON_MULTI_THREADS,
  1140. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32) {
  1141. using namespace conv_bias;
  1142. Checker<ConvBiasForward> checker(handle());
  1143. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1144. const std::vector<size_t>& out_size, DType A_dtype,
  1145. DType B_dtype, DType C_dtype, DType D_dtype,
  1146. param::MatrixMul::Format format, float eps) {
  1147. for (auto&& arg : args) {
  1148. for (uint32_t m : out_size) {
  1149. checker.set_extra_opr_impl(std::bind(
  1150. winograd_algo_extra_impl, std::placeholders::_1, m,
  1151. arg.param, handle, format));
  1152. checker.set_dtype(0, A_dtype)
  1153. .set_dtype(1, B_dtype)
  1154. .set_dtype(2, C_dtype)
  1155. .set_dtype(4, D_dtype)
  1156. .set_epsilon(eps)
  1157. .set_param(arg.param)
  1158. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1159. }
  1160. }
  1161. };
  1162. float epsilon = 0.001;
  1163. #if MEGDNN_AARCH64
  1164. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1165. #else
  1166. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1167. #endif
  1168. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1169. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1170. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1171. UniformIntRNG int_rng{-50, 50};
  1172. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1173. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1174. dtype::QuantizedS8(0.01887994f),
  1175. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1176. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1177. epsilon);
  1178. }
  1179. TEST_F(ARM_COMMON_MULTI_THREADS,
  1180. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE) {
  1181. using namespace conv_bias;
  1182. Checker<ConvBiasForward> checker(handle());
  1183. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1184. const std::vector<size_t>& out_size, DType A_dtype,
  1185. DType B_dtype, DType C_dtype, DType D_dtype,
  1186. param::MatrixMul::Format format, float eps) {
  1187. for (auto&& arg : args) {
  1188. for (uint32_t m : out_size) {
  1189. checker.set_extra_opr_impl(std::bind(
  1190. winograd_algo_extra_impl, std::placeholders::_1, m,
  1191. arg.param, handle, format));
  1192. checker.set_dtype(0, A_dtype)
  1193. .set_dtype(1, B_dtype)
  1194. .set_dtype(2, C_dtype)
  1195. .set_dtype(4, D_dtype)
  1196. .set_epsilon(eps)
  1197. .set_param(arg.param)
  1198. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1199. }
  1200. }
  1201. };
  1202. float epsilon = 0.001;
  1203. #if MEGDNN_AARCH64
  1204. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1205. #else
  1206. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1207. #endif
  1208. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1209. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1210. std::vector<TestArg> quantized_args =
  1211. get_int8_nchw44_args(3, 4, true, true);
  1212. UniformIntRNG int_rng{-50, 50};
  1213. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1214. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1215. dtype::QuantizedS8(0.01887994f),
  1216. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1217. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1218. epsilon);
  1219. }
  1220. TEST_F(ARM_COMMON_MULTI_THREADS,
  1221. CONV_BIAS_WINOGRAD_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1222. using namespace conv_bias;
  1223. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1224. handle());
  1225. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1226. const std::vector<size_t>& out_size, DType A_dtype,
  1227. DType B_dtype, DType C_dtype, DType D_dtype,
  1228. param::MatrixMul::Format format, float eps) {
  1229. for (auto&& arg : args) {
  1230. for (uint32_t m : out_size) {
  1231. checker.set_extra_opr_impl(std::bind(
  1232. winograd_algo_extra_impl, std::placeholders::_1, m,
  1233. arg.param, handle, format));
  1234. checker.set_dtype(0, A_dtype)
  1235. .set_dtype(1, B_dtype)
  1236. .set_dtype(2, C_dtype)
  1237. .set_dtype(4, D_dtype)
  1238. .set_epsilon(eps)
  1239. .set_param(arg.param)
  1240. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1241. }
  1242. }
  1243. };
  1244. #if MEGDNN_AARCH64
  1245. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1246. #else
  1247. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1248. #endif
  1249. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1250. ssprintf("WINOGRAD:%s:8:2:32", matmul_name).c_str()));
  1251. std::vector<TestArg> quantized_args =
  1252. get_quantized_winograd_mk_packed_args(8);
  1253. UniformIntRNG int_rng{-50, 50};
  1254. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1255. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1256. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1257. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1258. }
  1259. TEST_F(ARM_COMMON_MULTI_THREADS,
  1260. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_WEIGHT_PREPROCESS) {
  1261. using namespace conv_bias;
  1262. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1263. handle());
  1264. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1265. const std::vector<size_t>& out_size, DType A_dtype,
  1266. DType B_dtype, DType C_dtype, DType D_dtype,
  1267. param::MatrixMul::Format format, float eps) {
  1268. for (auto&& arg : args) {
  1269. for (uint32_t m : out_size) {
  1270. checker.set_extra_opr_impl(std::bind(
  1271. winograd_algo_extra_impl, std::placeholders::_1, m,
  1272. arg.param, handle, format));
  1273. checker.set_dtype(0, A_dtype)
  1274. .set_dtype(1, B_dtype)
  1275. .set_dtype(2, C_dtype)
  1276. .set_dtype(4, D_dtype)
  1277. .set_epsilon(eps)
  1278. .set_param(arg.param)
  1279. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1280. }
  1281. }
  1282. };
  1283. #if MEGDNN_AARCH64
  1284. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1285. #else
  1286. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1287. #endif
  1288. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1289. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1290. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4);
  1291. UniformIntRNG int_rng{-50, 50};
  1292. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1293. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1294. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1295. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1296. }
  1297. TEST_F(ARM_COMMON_MULTI_THREADS,
  1298. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_GROUPMODE_WEIGHT_PREPROCESS) {
  1299. using namespace conv_bias;
  1300. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1301. handle());
  1302. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1303. const std::vector<size_t>& out_size, DType A_dtype,
  1304. DType B_dtype, DType C_dtype, DType D_dtype,
  1305. param::MatrixMul::Format format, float eps) {
  1306. for (auto&& arg : args) {
  1307. for (uint32_t m : out_size) {
  1308. checker.set_extra_opr_impl(std::bind(
  1309. winograd_algo_extra_impl, std::placeholders::_1, m,
  1310. arg.param, handle, format));
  1311. checker.set_dtype(0, A_dtype)
  1312. .set_dtype(1, B_dtype)
  1313. .set_dtype(2, C_dtype)
  1314. .set_dtype(4, D_dtype)
  1315. .set_epsilon(eps)
  1316. .set_param(arg.param)
  1317. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1318. }
  1319. }
  1320. };
  1321. #if MEGDNN_AARCH64
  1322. const char* matmul_name = "AARCH64_INT16X16X32_MK8_8X8";
  1323. #else
  1324. const char* matmul_name = "ARMV7_INT16X16X32_MK8_4X8";
  1325. #endif
  1326. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1327. ssprintf("WINOGRAD_NCHW44:%s:8:2:32", matmul_name).c_str()));
  1328. std::vector<TestArg> quantized_args =
  1329. get_int8_nchw44_args(3, 4, false, true);
  1330. UniformIntRNG int_rng{-50, 50};
  1331. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1332. run(handle(), quantized_args, {2}, dtype::QuantizedS8(2.5f),
  1333. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  1334. dtype::QuantizedS8(60.25f), param::MatrixMul::Format::MK8, 1e-3);
  1335. }
  1336. TEST_F(ARM_COMMON_MULTI_THREADS,
  1337. CONV_BIAS_WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_WEIGHT_PREPROCESS) {
  1338. using namespace conv_bias;
  1339. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1340. handle());
  1341. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1342. const std::vector<size_t>& out_size, DType A_dtype,
  1343. DType B_dtype, DType C_dtype, DType D_dtype,
  1344. param::MatrixMul::Format format, float eps) {
  1345. for (auto&& arg : args) {
  1346. for (uint32_t m : out_size) {
  1347. checker.set_extra_opr_impl(std::bind(
  1348. winograd_algo_extra_impl, std::placeholders::_1, m,
  1349. arg.param, handle, format));
  1350. checker.set_dtype(0, A_dtype)
  1351. .set_dtype(1, B_dtype)
  1352. .set_dtype(2, C_dtype)
  1353. .set_dtype(4, D_dtype)
  1354. .set_epsilon(eps)
  1355. .set_param(arg.param)
  1356. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1357. }
  1358. }
  1359. };
  1360. float epsilon = 0.001;
  1361. #if MEGDNN_AARCH64
  1362. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1363. #else
  1364. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1365. #endif
  1366. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1367. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1368. std::vector<TestArg> quantized_args = get_int8_nchw44_args(3, 4, true);
  1369. UniformIntRNG int_rng{-50, 50};
  1370. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1371. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1372. dtype::QuantizedS8(0.01887994f),
  1373. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1374. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1375. epsilon);
  1376. }
  1377. TEST_F(ARM_COMMON_MULTI_THREADS,
  1378. WINOGRAD_NCHW44_MK_PACKED_INT8_COMP_F32_GROUPMODE_WEIGHT_PREPROCESS) {
  1379. using namespace conv_bias;
  1380. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1381. handle());
  1382. auto run = [&checker](Handle* handle, const std::vector<TestArg>& args,
  1383. const std::vector<size_t>& out_size, DType A_dtype,
  1384. DType B_dtype, DType C_dtype, DType D_dtype,
  1385. param::MatrixMul::Format format, float eps) {
  1386. for (auto&& arg : args) {
  1387. for (uint32_t m : out_size) {
  1388. checker.set_extra_opr_impl(std::bind(
  1389. winograd_algo_extra_impl, std::placeholders::_1, m,
  1390. arg.param, handle, format));
  1391. checker.set_dtype(0, A_dtype)
  1392. .set_dtype(1, B_dtype)
  1393. .set_dtype(2, C_dtype)
  1394. .set_dtype(4, D_dtype)
  1395. .set_epsilon(eps)
  1396. .set_param(arg.param)
  1397. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  1398. }
  1399. }
  1400. };
  1401. float epsilon = 0.001;
  1402. #if MEGDNN_AARCH64
  1403. const char* matmul_name = "AARCH64_F32_MK4_4x16";
  1404. #else
  1405. const char* matmul_name = "ARMV7_F32_MK4_4x8";
  1406. #endif
  1407. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1408. ssprintf("WINOGRAD_NCHW44:%s:4:2:32", matmul_name).c_str()));
  1409. std::vector<TestArg> quantized_args =
  1410. get_int8_nchw44_args(3, 4, true, true);
  1411. UniformIntRNG int_rng{-50, 50};
  1412. checker.set_rng(0, &int_rng).set_rng(1, &int_rng).set_rng(2, &int_rng);
  1413. run(handle(), quantized_args, {2}, dtype::QuantizedS8(0.41113496f),
  1414. dtype::QuantizedS8(0.01887994f),
  1415. dtype::QuantizedS32(0.41113496f * 0.01887994f),
  1416. dtype::QuantizedS8(0.49550694f), param::MatrixMul::Format::MK4,
  1417. epsilon);
  1418. }
  1419. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1420. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23) {
  1421. using namespace conv_bias;
  1422. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1423. Checker<ConvBiasForward> checker(handle());
  1424. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1425. }
  1426. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_1) {
  1427. using namespace conv_bias;
  1428. std::vector<TestArg> args = get_winograd_args(5);
  1429. std::vector<TestArg> args_head_half(args.begin(),
  1430. args.begin() + args.size() / 2);
  1431. Checker<ConvBiasForward> checker(handle());
  1432. //! fp16 range -1.0 ~ 1.0
  1433. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1434. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1435. }
  1436. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F45_2) {
  1437. using namespace conv_bias;
  1438. std::vector<TestArg> args = get_winograd_args(5);
  1439. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1440. args.end());
  1441. Checker<ConvBiasForward> checker(handle());
  1442. //! fp16 range -1.0 ~ 1.0
  1443. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1444. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1445. }
  1446. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1447. //! it will pass when run single testcase
  1448. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63) {
  1449. using namespace conv_bias;
  1450. std::vector<TestArg> args = get_winograd_args(3);
  1451. Checker<ConvBiasForward> checker(handle());
  1452. //! fp16 range -1.0 ~ 1.0
  1453. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1454. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1455. }
  1456. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_1) {
  1457. using namespace conv_bias;
  1458. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1459. std::vector<TestArg> args_head_half(args.begin(),
  1460. args.begin() + args.size() / 2);
  1461. Checker<ConvBiasForward> checker(handle());
  1462. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1463. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1464. param::MatrixMul::Format::MK8);
  1465. }
  1466. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_8x8_2) {
  1467. using namespace conv_bias;
  1468. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1469. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1470. args.end());
  1471. Checker<ConvBiasForward> checker(handle());
  1472. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1473. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1474. param::MatrixMul::Format::MK8);
  1475. }
  1476. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F23_WEIGHT_PREPROCESS) {
  1477. using namespace conv_bias;
  1478. std::vector<TestArg> args = get_winograd_mk_packed_args();
  1479. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1480. handle());
  1481. check_winograd_fp16("1:2:32", checker, args, NULL, 0.08);
  1482. }
  1483. TEST_F(ARM_COMMON_MULTI_THREADS,
  1484. CONV_BIAS_WINOGRAD_F16_F45_1_WEIGHT_PREPROCESS) {
  1485. using namespace conv_bias;
  1486. std::vector<TestArg> args = get_winograd_args(5);
  1487. std::vector<TestArg> args_head_half(args.begin(),
  1488. args.begin() + args.size() / 2);
  1489. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1490. handle());
  1491. //! fp16 range -1.0 ~ 1.0
  1492. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1493. check_winograd_fp16("1:4:32", checker, args_head_half, rng, 0.25);
  1494. }
  1495. TEST_F(ARM_COMMON_MULTI_THREADS,
  1496. CONV_BIAS_WINOGRAD_F16_F45_2_WEIGHT_PREPROCESS) {
  1497. using namespace conv_bias;
  1498. std::vector<TestArg> args = get_winograd_args(5);
  1499. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1500. args.end());
  1501. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1502. handle());
  1503. //! fp16 range -1.0 ~ 1.0
  1504. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1505. check_winograd_fp16("1:4:32", checker, args_back_half, rng, 0.25);
  1506. }
  1507. //! FIXME: This test may be failed if run `ARM_COMMON.CONV_BIAS_WINOGRAD*`, but
  1508. //! it will pass when run single testcase
  1509. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_F16_F63_WEIGHT_PREPROCESS) {
  1510. using namespace conv_bias;
  1511. std::vector<TestArg> args = get_winograd_args(3);
  1512. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1513. handle());
  1514. //! fp16 range -1.0 ~ 1.0
  1515. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1516. check_winograd_fp16("1:6:32", checker, args, rng, 0.3);
  1517. }
  1518. TEST_F(ARM_COMMON_MULTI_THREADS,
  1519. CONV_BIAS_WINOGRAD_F16_8x8_1_WEIGHT_PREPROCESS) {
  1520. using namespace conv_bias;
  1521. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1522. std::vector<TestArg> args_head_half(args.begin(),
  1523. args.begin() + args.size() / 2);
  1524. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1525. handle());
  1526. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1527. check_winograd_fp16("8:2:32", checker, args_head_half, rng, 0.25,
  1528. param::MatrixMul::Format::MK8);
  1529. }
  1530. TEST_F(ARM_COMMON_MULTI_THREADS,
  1531. CONV_BIAS_WINOGRAD_F16_8x8_2_WEIGHT_PREPROCESS) {
  1532. using namespace conv_bias;
  1533. std::vector<TestArg> args = get_winograd_mk_packed_args(8);
  1534. std::vector<TestArg> args_back_half(args.begin() + args.size() / 2,
  1535. args.end());
  1536. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1537. handle());
  1538. Float16PeriodicalRNG* rng = new Float16PeriodicalRNG(0x3c00);
  1539. check_winograd_fp16("8:2:32", checker, args_back_half, rng, 0.25,
  1540. param::MatrixMul::Format::MK8);
  1541. }
  1542. #endif
  1543. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_WINOGRAD_INT8_8X8) {
  1544. using namespace conv_bias;
  1545. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1546. Checker<ConvBiasForward> checker(handle());
  1547. UniformIntRNG rng{-50, 50};
  1548. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1549. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1550. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1551. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1552. .set_rng(0, &rng)
  1553. .set_rng(1, &rng)
  1554. .set_rng(2, &rng);
  1555. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1556. }
  1557. TEST_F(ARM_COMMON_MULTI_THREADS,
  1558. CONV_BIAS_WINOGRAD_INT8_8X8_WEIGHT_PREPROCESS) {
  1559. using namespace conv_bias;
  1560. std::vector<TestArg> args = get_quantized_winograd_mk_packed_args(8);
  1561. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  1562. handle());
  1563. UniformIntRNG rng{-50, 50};
  1564. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  1565. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1566. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1567. .set_dtype(4, dtype::QuantizedS8(60.25f))
  1568. .set_rng(0, &rng)
  1569. .set_rng(1, &rng)
  1570. .set_rng(2, &rng);
  1571. check_winograd("8:2:32", checker, args, param::MatrixMul::Format::MK8);
  1572. }
  1573. void checker_conv_bias(std::vector<conv_bias::TestArg> args, Handle* handle,
  1574. RNG* rng, float epsilon, DType type0, DType type1,
  1575. DType type2, DType type3, const char* algo_name) {
  1576. using namespace conv_bias;
  1577. Checker<ConvBias> checker(handle);
  1578. checker.set_before_exec_callback(
  1579. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  1580. checker.set_dtype(0, type0);
  1581. checker.set_dtype(1, type1);
  1582. checker.set_dtype(2, type2);
  1583. checker.set_dtype(4, type3);
  1584. checker.set_epsilon(epsilon);
  1585. if (NULL != rng) {
  1586. checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
  1587. }
  1588. for (auto&& arg : args) {
  1589. checker.set_param(arg.param).execs(
  1590. {arg.src, arg.filter, arg.bias, {}, {}});
  1591. }
  1592. }
  1593. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2_PREPROCESS) {
  1594. #define cb(name) \
  1595. check_conv_bias_preprocess( \
  1596. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1597. handle(), nullptr, 0.001, dtype::Float32(), dtype::Float32(), \
  1598. dtype::Float32(), dtype::Float32(), name);
  1599. #if MEGDNN_AARCH64
  1600. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1601. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1602. #elif MEGDNN_ARMV7
  1603. cb("IM2COLMATMUL:ARMV7_F32")
  1604. #endif
  1605. #undef cb
  1606. }
  1607. // clang-format off
  1608. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE2) {
  1609. #define cb(name) \
  1610. check_conv_bias( \
  1611. get_conv_bias_args({1, 2, 3, 4, 5, 6, 7}, 2, false, false, false), \
  1612. handle(), name);
  1613. #if MEGDNN_AARCH64
  1614. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1615. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1616. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1617. #elif MEGDNN_ARMV7
  1618. cb("IM2COLMATMUL:ARMV7_F32")
  1619. #endif
  1620. #undef cb
  1621. }
  1622. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1_PREPROCESS) {
  1623. #define cb(name) \
  1624. check_conv_bias_preprocess( \
  1625. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1626. handle(), nullptr, 0.001, dtype::Float32(), dtype::Float32(), \
  1627. dtype::Float32(), dtype::Float32(), name);
  1628. #if MEGDNN_AARCH64
  1629. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1630. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1631. #elif MEGDNN_ARMV7
  1632. cb("IM2COLMATMUL:ARMV7_F32")
  1633. #endif
  1634. #undef cb
  1635. }
  1636. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COL_FP32_STRIDE1) {
  1637. #define cb(name) \
  1638. check_conv_bias( \
  1639. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false), \
  1640. handle(), name);
  1641. #if MEGDNN_AARCH64
  1642. cb("IM2COLMATMUL:AARCH64_F32K8X12X1")
  1643. cb("IM2COLMATMUL:AARCH64_F32K4X16X1")
  1644. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1645. #elif MEGDNN_ARMV7
  1646. cb("IM2COLMATMUL:ARMV7_F32")
  1647. cb("IM2COLMATMUL:FB_F32_K8X12X1")
  1648. #endif
  1649. #undef cb
  1650. }
  1651. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM) {
  1652. UniformIntRNG rng{-50, 50};
  1653. #define cb(name) \
  1654. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1655. false, true, true), \
  1656. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1657. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1658. dtype::QuantizedS8(60.25f), name); \
  1659. checker_conv_bias( \
  1660. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1661. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1662. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1663. dtype::QuantizedS8(60.25f), name);
  1664. float epsilon = 0.001;
  1665. #if MEGDNN_AARCH64
  1666. #if __ARM_FEATURE_DOTPROD
  1667. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1668. #else
  1669. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1670. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1671. #endif
  1672. #elif MEGDNN_ARMV7
  1673. epsilon = 1;
  1674. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1675. #endif
  1676. #undef cb
  1677. }
  1678. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_PREPROCESS) {
  1679. UniformIntRNG rng{-50, 50};
  1680. #define cb(name) \
  1681. check_conv_bias_preprocess(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1682. 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. check_conv_bias_preprocess( \
  1687. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1688. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1689. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1690. dtype::QuantizedS8(60.25f), name);
  1691. float epsilon = 0.001;
  1692. #if MEGDNN_AARCH64
  1693. #if __ARM_FEATURE_DOTPROD
  1694. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  1695. #else
  1696. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  1697. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  1698. #endif
  1699. #elif MEGDNN_ARMV7
  1700. epsilon = 1;
  1701. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  1702. #endif
  1703. #undef cb
  1704. }
  1705. #if __ARM_FEATURE_DOTPROD
  1706. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT) {
  1707. UniformIntRNG rng{-50, 50};
  1708. #define cb(name) \
  1709. checker_conv_bias(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, \
  1710. false, false, false, true), \
  1711. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1712. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1713. dtype::QuantizedS8(60.25f), name); \
  1714. checker_conv_bias( \
  1715. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true), \
  1716. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1717. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1718. dtype::QuantizedS8(60.25f), name);
  1719. float epsilon = 0.001;
  1720. #if MEGDNN_AARCH64
  1721. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1722. #elif MEGDNN_ARMV7
  1723. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1724. #endif
  1725. #undef cb
  1726. }
  1727. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT_PREPROCESS) {
  1728. UniformIntRNG rng{-50, 50};
  1729. #define cb(name) \
  1730. check_conv_bias_preprocess(get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, \
  1731. false, false, false, true), \
  1732. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1733. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1734. dtype::QuantizedS8(60.25f), name); \
  1735. checker_conv_bias( \
  1736. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true), \
  1737. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1738. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1739. dtype::QuantizedS8(60.25f), name);
  1740. float epsilon = 0.001;
  1741. #if MEGDNN_AARCH64
  1742. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1743. #elif MEGDNN_ARMV7
  1744. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1745. #endif
  1746. #undef cb
  1747. }
  1748. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_MK4_DOT_S2_FUSE) {
  1749. UniformIntRNG rng{-50, 50};
  1750. #define cb(name) \
  1751. checker_conv_bias(get_nchw44_conv_bias_args({3}, 2, false, \
  1752. false, false, false, true), \
  1753. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1754. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1755. dtype::QuantizedS8(60.25f), name); \
  1756. float epsilon = 0.001;
  1757. #if MEGDNN_AARCH64
  1758. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1759. #elif MEGDNN_ARMV7
  1760. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1761. #endif
  1762. #undef cb
  1763. }
  1764. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_S8x8x32_MK4_DOT) {
  1765. UniformIntRNG rng{-50, 50};
  1766. #define cb(name) \
  1767. checker_conv_bias( \
  1768. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1769. true, false, true, false, false, true), \
  1770. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1771. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1772. checker_conv_bias( \
  1773. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1774. false, false, true), \
  1775. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1776. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name);
  1777. float epsilon = 0.001;
  1778. #if MEGDNN_AARCH64
  1779. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1780. #elif MEGDNN_ARMV7
  1781. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1782. #endif
  1783. #undef cb
  1784. }
  1785. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_S8x8x32_MK4_DOT_PREPROCESS) {
  1786. UniformIntRNG rng{-50, 50};
  1787. #define cb(name) \
  1788. check_conv_bias_preprocess( \
  1789. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1790. true, false, true, false, false, true), \
  1791. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1792. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1793. check_conv_bias_preprocess( \
  1794. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1795. false, false, true), \
  1796. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1797. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name);
  1798. float epsilon = 0.001;
  1799. #if MEGDNN_AARCH64
  1800. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1801. #elif MEGDNN_ARMV7
  1802. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1803. #endif
  1804. #undef cb
  1805. }
  1806. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32_MK4_DOT) {
  1807. UniformIntRNG rng{-50, 50};
  1808. #define cb(name) \
  1809. checker_conv_bias( \
  1810. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1811. true, false, true, false, false, true), \
  1812. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1813. dtype::Int32(), {}, name); \
  1814. checker_conv_bias( \
  1815. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1816. false, false, true), \
  1817. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1818. dtype::Int32(), {}, name);
  1819. float epsilon = 0.001;
  1820. #if MEGDNN_AARCH64
  1821. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1822. #elif MEGDNN_ARMV7
  1823. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1824. #endif
  1825. #undef cb
  1826. }
  1827. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32_MK4_DOT_PREPROCESS) {
  1828. UniformIntRNG rng{-50, 50};
  1829. #define cb(name) \
  1830. check_conv_bias_preprocess( \
  1831. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1832. true, false, true, false, false, true), \
  1833. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1834. dtype::Int32(), {}, name); \
  1835. check_conv_bias_preprocess( \
  1836. get_nchw44_conv_bias_args({1}, 2, false, true, true, false, true, \
  1837. false, false, true), \
  1838. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1839. dtype::Int32(), {}, name);
  1840. float epsilon = 0.001;
  1841. #if MEGDNN_AARCH64
  1842. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  1843. #elif MEGDNN_ARMV7
  1844. cb("IM2COLMATMUL:AARCH32_INT8_MK4_8X4X4_DOTPROD:96");
  1845. #endif
  1846. #undef cb
  1847. }
  1848. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CONV1x1_QUANTIZEDSYM_MK4_DOT) {
  1849. UniformIntRNG rng{-50, 50};
  1850. #define cb(name) \
  1851. checker_conv_bias( \
  1852. get_nchw44_conv_bias_args({1}, 1, true, true, false, false, true), \
  1853. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1854. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  1855. dtype::QuantizedS8(60.25f), name); \
  1856. checker_conv_bias( \
  1857. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1858. false, false, true), \
  1859. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  1860. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  1861. checker_conv_bias( \
  1862. get_nchw44_conv_bias_args({1}, 1, true, true, true, false, true, \
  1863. false, false, true), \
  1864. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  1865. dtype::Int32(), {}, name);
  1866. float epsilon = 0.001;
  1867. #if MEGDNN_AARCH64
  1868. cb("CONV1x1:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD");
  1869. #elif MEGDNN_ARMV7
  1870. cb("CONV1x1:AARCH32_INT8_MK4_8X4X4_DOTPROD");
  1871. #endif
  1872. #undef cb
  1873. }
  1874. #endif
  1875. // clang-format on
  1876. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1877. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM) {
  1878. NormalRNG rng(128.f);
  1879. #define cb(name) \
  1880. checker_conv_bias(get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, \
  1881. false, true, true), \
  1882. handle(), &rng, epsilon, \
  1883. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1884. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1885. dtype::QuantizedS32(1.2 * 1.3), \
  1886. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1887. checker_conv_bias( \
  1888. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1889. handle(), &rng, epsilon, \
  1890. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1891. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1892. dtype::QuantizedS32(1.2 * 1.3), \
  1893. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1894. float epsilon = 0.001;
  1895. #if MEGDNN_AARCH64
  1896. #if __ARM_FEATURE_DOTPROD
  1897. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1898. #else
  1899. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1900. #endif
  1901. #elif MEGDNN_ARMV7
  1902. epsilon = 1;
  1903. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1904. #endif
  1905. #undef cb
  1906. }
  1907. TEST_F(ARM_COMMON_MULTI_THREADS,
  1908. CONV_BIAS_IM2COLMATMUL_QUANTIZEDASYM_FILTERPREPROCESS) {
  1909. NormalRNG rng(128.f);
  1910. #define cb(name) \
  1911. check_conv_bias_preprocess( \
  1912. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false, \
  1913. true, true), \
  1914. handle(), &rng, epsilon, \
  1915. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1916. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1917. dtype::QuantizedS32(1.2 * 1.3), \
  1918. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name); \
  1919. check_conv_bias_preprocess( \
  1920. get_conv_bias_args({1}, 2, false, false, false, true, true), \
  1921. handle(), &rng, epsilon, \
  1922. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1923. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1924. dtype::QuantizedS32(1.2 * 1.3), \
  1925. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  1926. float epsilon = 0.001;
  1927. #if MEGDNN_AARCH64
  1928. #if __ARM_FEATURE_DOTPROD
  1929. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1930. #else
  1931. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1932. #endif
  1933. #elif MEGDNN_ARMV7
  1934. epsilon = 1;
  1935. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1936. #endif
  1937. #undef cb
  1938. }
  1939. #endif
  1940. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  1941. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32) {
  1942. UniformIntRNG rng{-50, 50};
  1943. float epsilon = 0.001;
  1944. #define cb(name) \
  1945. checker_conv_bias( \
  1946. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1947. handle(), &rng, epsilon, \
  1948. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1949. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1950. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1951. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  1952. &rng, epsilon, \
  1953. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1954. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1955. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1956. #if MEGDNN_AARCH64
  1957. #if __ARM_FEATURE_DOTPROD
  1958. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1959. #else
  1960. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1961. #endif
  1962. #elif MEGDNN_ARMV7
  1963. #if __ARM_FEATURE_DOTPROD
  1964. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1965. #endif
  1966. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1967. #endif
  1968. #undef cb
  1969. }
  1970. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QUINT8x8x32_FILTERPREPROCESS) {
  1971. UniformIntRNG rng{-50, 50};
  1972. float epsilon = 0.001;
  1973. #define cb(name) \
  1974. check_conv_bias_preprocess( \
  1975. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  1976. handle(), &rng, epsilon, \
  1977. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1978. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1979. dtype::QuantizedS32(1.2 * 1.3), {}, name); \
  1980. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  1981. handle(), &rng, epsilon, \
  1982. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  1983. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  1984. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  1985. #if MEGDNN_AARCH64
  1986. #if __ARM_FEATURE_DOTPROD
  1987. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X4_DOTPROD");
  1988. #else
  1989. cb("IM2COLMATMUL:AARCH64_QUINT8_K8X8X8");
  1990. #endif
  1991. #elif MEGDNN_ARMV7
  1992. #if __ARM_FEATURE_DOTPROD
  1993. cb("IM2COLMATMUL:AARCH32_QUINT8_K4X8X4");
  1994. #endif
  1995. cb("IM2COLMATMUL:ARMV7_QUINT8_K4X8X8");
  1996. #endif
  1997. #undef cb
  1998. }
  1999. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16) {
  2000. UniformIntRNG rng{-50, 50};
  2001. float epsilon = 0.001;
  2002. std::vector<conv_bias::TestArg> args_nchw44 =
  2003. get_nchw44_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, true, true, true,
  2004. false, false, false, false, true);
  2005. std::vector<conv_bias::TestArg> args_nchw44_1x1s2 =
  2006. get_nchw44_conv_bias_args({1}, 2, true, true, true, false, false,
  2007. false, false, true);
  2008. #define cb(name) \
  2009. checker_conv_bias( \
  2010. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2011. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2012. dtype::Int16{}, dtype::Int16{}, name); \
  2013. checker_conv_bias(get_conv_bias_args({1}, 2, false, true, true), handle(), \
  2014. &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2015. dtype::Int16{}, dtype::Int16{}, name);
  2016. #define cb_nchw44(name) \
  2017. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2018. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name); \
  2019. checker_conv_bias(args_nchw44_1x1s2, handle(), &rng, epsilon, \
  2020. dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  2021. dtype::Int16{}, name);
  2022. #if MEGDNN_AARCH64
  2023. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2024. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2025. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2026. #elif MEGDNN_ARMV7
  2027. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2028. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2029. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2030. cb_nchw44("IM2COLMATMUL:ARMV7_INT8X8X16_MK4_K8X8X4");
  2031. #endif
  2032. #undef cb
  2033. #undef cb_nchw44
  2034. }
  2035. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_FILTERPREPROCESS) {
  2036. UniformIntRNG rng{-50, 50};
  2037. float epsilon = 0.001;
  2038. #define cb(name) \
  2039. check_conv_bias_preprocess( \
  2040. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2041. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2042. dtype::Int16{}, dtype::Int16{}, name); \
  2043. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2044. handle(), &rng, epsilon, dtype::Int8{}, \
  2045. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2046. name);
  2047. #if MEGDNN_AARCH64
  2048. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K8X8X8");
  2049. cb("IM2COLMATMUL:AARCH64_INT8X8X16_K4X4X16");
  2050. #elif MEGDNN_ARMV7
  2051. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X8X8");
  2052. cb("IM2COLMATMUL:ARMV7_INT8X8X16_K4X2X16");
  2053. #endif
  2054. #undef cb
  2055. }
  2056. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_IM2COLMATMUL_INT8x8x16_NOPACK_FILTERPREPROCESS) {
  2057. UniformIntRNG rng{-50, 50};
  2058. float epsilon = 0.001;
  2059. #define cb(name) \
  2060. check_conv_bias_preprocess( \
  2061. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true), \
  2062. handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  2063. dtype::Int16{}, dtype::Int16{}, name); \
  2064. check_conv_bias_preprocess(get_conv_bias_args({1}, 2, false, true, true), \
  2065. handle(), &rng, epsilon, dtype::Int8{}, \
  2066. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2067. name);
  2068. #if MEGDNN_AARCH64
  2069. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2070. #elif MEGDNN_ARMV7
  2071. cb("IM2COLMATMUL:ARM_COMMON_INT8X8X16");
  2072. #endif
  2073. #undef cb
  2074. }
  2075. #endif
  2076. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2077. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16) {
  2078. using namespace conv_bias;
  2079. param::ConvBias cur_param;
  2080. std::vector<conv_bias::TestArg> args =
  2081. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2082. std::vector<conv_bias::TestArg> args1 =
  2083. get_conv_bias_args({1}, 2, false, false, false);
  2084. args.insert(args.begin(), args1.begin(), args1.end());
  2085. NormalRNG rng(1);
  2086. #define cb(name) \
  2087. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2088. dtype::Float16{}, dtype::Float16{}, dtype::Float16{}, \
  2089. name);
  2090. #if MEGDNN_AARCH64
  2091. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2092. #elif MEGDNN_ARMV7
  2093. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2094. #endif
  2095. #undef cb
  2096. }
  2097. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP16_FILTERPREPROCESS) {
  2098. using namespace conv_bias;
  2099. param::ConvBias cur_param;
  2100. std::vector<conv_bias::TestArg> args =
  2101. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, false, false);
  2102. std::vector<conv_bias::TestArg> args1 =
  2103. get_conv_bias_args({1}, 2, false, false, false);
  2104. args.insert(args.begin(), args1.begin(), args1.end());
  2105. NormalRNG rng(1);
  2106. #define cb(name) \
  2107. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{}, \
  2108. dtype::Float16{}, dtype::Float16{}, \
  2109. dtype::Float16{}, name);
  2110. #if MEGDNN_AARCH64
  2111. cb("IM2COLMATMUL:AARCH64_F16_K8X24X1");
  2112. #elif MEGDNN_ARMV7
  2113. cb("IM2COLMATMUL:AARCH32_F16_K4X16X1");
  2114. #endif
  2115. #undef cb
  2116. }
  2117. #endif
  2118. void checker_conv_bias_mul_int8x8x32(std::vector<conv_bias::TestArg> args,
  2119. Handle* handle, const char* algo_name) {
  2120. using namespace conv_bias;
  2121. Checker<ConvBias> checker(handle);
  2122. checker.set_before_exec_callback(
  2123. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2124. checker.set_dtype(0, dtype::Int8());
  2125. checker.set_dtype(1, dtype::Int8());
  2126. checker.set_dtype(2, dtype::Int32());
  2127. checker.set_dtype(4, dtype::Int32());
  2128. for (auto&& arg : args) {
  2129. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2130. }
  2131. UniformIntRNG rng{-50, 50};
  2132. for (auto&& arg : args) {
  2133. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2134. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2135. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2136. .set_dtype(4, {})
  2137. .set_rng(0, &rng)
  2138. .set_rng(1, &rng)
  2139. .set_rng(2, &rng)
  2140. .set_param(arg.param)
  2141. .execs({arg.src, arg.filter, {}, {}, {}});
  2142. }
  2143. }
  2144. void checker_conv_bias_int8x8x32_preprocess(std::vector<conv_bias::TestArg> args,
  2145. Handle* handle, const char* algo_name) {
  2146. using namespace conv_bias;
  2147. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  2148. handle);
  2149. checker.set_before_exec_callback(
  2150. conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
  2151. checker.set_dtype(0, dtype::Int8());
  2152. checker.set_dtype(1, dtype::Int8());
  2153. checker.set_dtype(2, dtype::Int32());
  2154. checker.set_dtype(4, dtype::Int32());
  2155. for (auto&& arg : args) {
  2156. checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}});
  2157. }
  2158. UniformIntRNG rng{-50, 50};
  2159. for (auto&& arg : args) {
  2160. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  2161. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2162. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2163. .set_dtype(4, {})
  2164. .set_rng(0, &rng)
  2165. .set_rng(1, &rng)
  2166. .set_rng(2, &rng)
  2167. .set_param(arg.param)
  2168. .execs({arg.src, arg.filter, {}, {}, {}});
  2169. }
  2170. }
  2171. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2172. #if !__ARM_FEATURE_DOTPROD
  2173. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2) {
  2174. using namespace conv_bias;
  2175. std::vector<conv_bias::TestArg> args =
  2176. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2177. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2178. #if MEGDNN_AARCH64
  2179. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2180. #else
  2181. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2182. #endif
  2183. #undef cb
  2184. }
  2185. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S2_PREPROCESS) {
  2186. using namespace conv_bias;
  2187. std::vector<conv_bias::TestArg> args =
  2188. get_nchw44_conv_bias_args({2, 5, 7}, 2, false, true, true);
  2189. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2190. #if MEGDNN_AARCH64
  2191. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2192. #else
  2193. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2194. #endif
  2195. #undef cb
  2196. }
  2197. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1) {
  2198. using namespace conv_bias;
  2199. std::vector<conv_bias::TestArg> args =
  2200. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2201. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2202. #if MEGDNN_AARCH64
  2203. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2204. #else
  2205. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2206. #endif
  2207. #undef cb
  2208. }
  2209. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32NCHW44_S1_PREPROCESS) {
  2210. using namespace conv_bias;
  2211. std::vector<conv_bias::TestArg> args =
  2212. get_nchw44_conv_bias_args({3, 4, 6}, 1, false, true, true);
  2213. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2214. #if MEGDNN_AARCH64
  2215. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2216. #else
  2217. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2218. #endif
  2219. #undef cb
  2220. }
  2221. TEST_F(ARM_COMMON_MULTI_THREADS,
  2222. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2) {
  2223. UniformIntRNG rng{-50, 50};
  2224. #define cb(name) \
  2225. checker_conv_bias(get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, \
  2226. epsilon, dtype::QuantizedS8(2.5f), \
  2227. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2228. dtype::QuantizedS8(60.25f), name);
  2229. float epsilon = 0.001;
  2230. #if MEGDNN_AARCH64
  2231. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2232. #else
  2233. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2234. #endif
  2235. #undef cb
  2236. }
  2237. TEST_F(ARM_COMMON_MULTI_THREADS,
  2238. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S2_PREPROCESS) {
  2239. UniformIntRNG rng{-50, 50};
  2240. #define cb(name) \
  2241. check_conv_bias_preprocess( \
  2242. get_nchw44_conv_bias_args({3, 4, 6}, 2), handle(), &rng, epsilon, \
  2243. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2244. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2245. float epsilon = 0.001;
  2246. #if MEGDNN_AARCH64
  2247. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2248. #else
  2249. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2250. #endif
  2251. #undef cb
  2252. }
  2253. TEST_F(ARM_COMMON_MULTI_THREADS,
  2254. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1) {
  2255. UniformIntRNG rng{-50, 50};
  2256. #define cb(name) \
  2257. checker_conv_bias(get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, \
  2258. epsilon, dtype::QuantizedS8(2.5f), \
  2259. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2260. dtype::QuantizedS8(60.25f), name);
  2261. float epsilon = 0.001;
  2262. #if MEGDNN_AARCH64
  2263. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2264. #else
  2265. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2266. #endif
  2267. #undef cb
  2268. }
  2269. TEST_F(ARM_COMMON_MULTI_THREADS,
  2270. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_S1_PREPROCESS) {
  2271. UniformIntRNG rng{-50, 50};
  2272. #define cb(name) \
  2273. check_conv_bias_preprocess( \
  2274. get_nchw44_conv_bias_args({2, 5, 7}, 1), handle(), &rng, epsilon, \
  2275. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2276. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2277. float epsilon = 0.001;
  2278. #if MEGDNN_AARCH64
  2279. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2280. #else
  2281. cb("IM2COLMATMUL:ARMV7_INT8X8X32_MK4_4X2X16:96");
  2282. #endif
  2283. #undef cb
  2284. }
  2285. #if MEGDNN_AARCH64
  2286. TEST_F(ARM_COMMON_MULTI_THREADS,
  2287. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE) {
  2288. UniformIntRNG rng{-50, 50};
  2289. #define cb(name) \
  2290. checker_conv_bias(get_nchw44_conv_bias_args({3}, 1), handle(), &rng, \
  2291. epsilon, dtype::QuantizedS8(2.5f), \
  2292. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2293. dtype::QuantizedS8(60.25f), name);
  2294. float epsilon = 0.001;
  2295. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2296. #undef cb
  2297. }
  2298. TEST_F(ARM_COMMON_MULTI_THREADS,
  2299. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44_FUSE_PREPROCESS) {
  2300. UniformIntRNG rng{-50, 50};
  2301. #define cb(name) \
  2302. check_conv_bias_preprocess( \
  2303. get_nchw44_conv_bias_args({3}, 1), handle(), &rng, epsilon, \
  2304. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f), \
  2305. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f), name);
  2306. float epsilon = 0.001;
  2307. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16:96");
  2308. #undef cb
  2309. }
  2310. #endif
  2311. #endif
  2312. #endif
  2313. #if MEGDNN_AARCH64
  2314. #if __ARM_FEATURE_DOTPROD
  2315. TEST_F(ARM_COMMON_MULTI_THREADS,
  2316. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE) {
  2317. UniformIntRNG rng{-50, 50};
  2318. #define cb(name) \
  2319. checker_conv_bias( \
  2320. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2321. true, false, false, false), \
  2322. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2323. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2324. dtype::QuantizedS8(60.25f), name);
  2325. float epsilon = 0.001;
  2326. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2327. #undef cb
  2328. }
  2329. TEST_F(ARM_COMMON_MULTI_THREADS,
  2330. CONV_BIAS_IM2COLMATMUL_QUANTIZEDSYM_NCHW44DOT_FUSE_PREPROCESS) {
  2331. UniformIntRNG rng{-50, 50};
  2332. #define cb(name) \
  2333. check_conv_bias_preprocess( \
  2334. get_nchw44_conv_bias_args({3}, 1, false, false, false, false, \
  2335. true, false, false, false), \
  2336. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2337. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2338. dtype::QuantizedS8(60.25f), name);
  2339. float epsilon = 0.001;
  2340. cb("IM2COLMATMUL:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD:96");
  2341. #undef cb
  2342. }
  2343. #endif
  2344. #endif
  2345. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8x8x32) {
  2346. using namespace conv_bias;
  2347. std::vector<conv_bias::TestArg> args =
  2348. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2349. std::vector<conv_bias::TestArg> args1 =
  2350. get_conv_bias_args({1}, 2, false, true, true);
  2351. args.insert(args.begin(), args1.begin(), args1.end());
  2352. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2353. #if MEGDNN_AARCH64
  2354. #if __ARM_FEATURE_DOTPROD
  2355. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2356. #else
  2357. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2358. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2359. #endif
  2360. #elif MEGDNN_ARMV7
  2361. #if __ARM_FEATURE_DOTPROD
  2362. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2363. #endif
  2364. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2365. #endif
  2366. #if MEGDNN_ARMV7
  2367. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2368. #endif
  2369. #undef cb
  2370. }
  2371. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8X8X32_FILTER_PREPROCESS) {
  2372. using namespace conv_bias;
  2373. std::vector<conv_bias::TestArg> args =
  2374. get_conv_bias_args({2, 3, 4, 5, 6, 7}, 1, false, true, true);
  2375. std::vector<conv_bias::TestArg> args1 =
  2376. get_conv_bias_args({1}, 2, false, true, true);
  2377. args.insert(args.begin(), args1.begin(), args1.end());
  2378. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2379. #if MEGDNN_AARCH64
  2380. #if __ARM_FEATURE_DOTPROD
  2381. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X12X4_DOTPROD");
  2382. #else
  2383. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K8X8X8");
  2384. cb("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16");
  2385. #endif
  2386. #elif MEGDNN_ARMV7
  2387. #if __ARM_FEATURE_DOTPROD
  2388. cb("IM2COLMATMUL:AARCH32_INT8_K6X8X4");
  2389. #endif
  2390. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8");
  2391. #endif
  2392. #if MEGDNN_ARMV7
  2393. cb("IM2COLMATMUL:ARMV7_INT8X8X32_K4X2X16");
  2394. #endif
  2395. #undef cb
  2396. }
  2397. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32) {
  2398. using namespace conv_bias;
  2399. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2400. {2, 4, 7}, 1, false, false, false, false, false, true, true);
  2401. #if MEGDNN_AARCH64
  2402. check_conv_bias(args, handle(), "IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2403. #elif MEGDNN_ARMV7
  2404. check_conv_bias(args, handle(), "IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2405. #endif
  2406. }
  2407. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S1_MK4_PACK_F32_PREPROCESS) {
  2408. using namespace conv_bias;
  2409. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2410. {2, 4, 7}, 1, false, false, false, false, false, true,true);
  2411. #define cb(name) \
  2412. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2413. dtype::Float32(), dtype::Float32(), \
  2414. dtype::Float32(), dtype::Float32(), name);
  2415. #if MEGDNN_AARCH64
  2416. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2417. #elif MEGDNN_ARMV7
  2418. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2419. #endif
  2420. #undef cb
  2421. }
  2422. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32) {
  2423. using namespace conv_bias;
  2424. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2425. {3, 5, 6}, 2, false, false, false, false, false, true, true);
  2426. #define cb(name) check_conv_bias(args, handle(), name);
  2427. #if MEGDNN_AARCH64
  2428. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2429. #elif MEGDNN_ARMV7
  2430. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2431. #endif
  2432. #undef cb
  2433. }
  2434. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE_PREPROCESS) {
  2435. using namespace conv_bias;
  2436. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2437. {3}, 2, false, false, false, false, false, true, true, false);
  2438. #define cb(name) \
  2439. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2440. dtype::Float32(), dtype::Float32(), \
  2441. dtype::Float32(), dtype::Float32(), name);
  2442. #if MEGDNN_AARCH64
  2443. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2444. #elif MEGDNN_ARMV7
  2445. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2446. #endif
  2447. #undef cb
  2448. }
  2449. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_IM2COL_S2_MK4_PACK_F32_FUSE) {
  2450. using namespace conv_bias;
  2451. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  2452. {3}, 2, false, false, false, false, false, true, true, false);
  2453. #define cb(name) check_conv_bias(args, handle(), name);
  2454. #if MEGDNN_AARCH64
  2455. cb("IM2COLMATMUL:AARCH64_F32_MK4_K8X12X1");
  2456. #elif MEGDNN_ARMV7
  2457. cb("IM2COLMATMUL:ARMV7_F32_MK4_PACK_4X12");
  2458. #endif
  2459. #undef cb
  2460. }
  2461. /***************************** Conv1x1 Algo Test ***********************/
  2462. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  2463. using namespace conv_bias;
  2464. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2465. #if MEGDNN_AARCH64
  2466. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  2467. #elif MEGDNN_ARMV7
  2468. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  2469. #endif
  2470. std::vector<conv_bias::TestArg> gemv_args;
  2471. for (auto&& arg : args)
  2472. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2473. gemv_args.emplace_back(arg);
  2474. }
  2475. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2476. }
  2477. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32_PREPROCESS) {
  2478. using namespace conv_bias;
  2479. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2480. #define cb(name) \
  2481. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2482. dtype::Float32(), dtype::Float32(), \
  2483. dtype::Float32(), dtype::Float32(), name);
  2484. #if MEGDNN_AARCH64
  2485. cb("CONV1x1:AARCH64_F32K8X12X1:24");
  2486. #elif MEGDNN_ARMV7
  2487. cb("CONV1x1:ARMV7_F32:48");
  2488. #endif
  2489. #undef cb
  2490. }
  2491. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  2492. using namespace conv_bias;
  2493. std::vector<conv_bias::TestArg> args =
  2494. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2495. #if MEGDNN_AARCH64
  2496. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2497. #elif MEGDNN_ARMV7
  2498. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2499. #endif
  2500. std::vector<conv_bias::TestArg> gemv_args;
  2501. for (auto&& arg : args)
  2502. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2503. gemv_args.emplace_back(arg);
  2504. }
  2505. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2506. }
  2507. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32_PREPROCESS) {
  2508. using namespace conv_bias;
  2509. std::vector<conv_bias::TestArg> args =
  2510. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2511. #define cb(name) \
  2512. check_conv_bias_preprocess(args, handle(), nullptr, 0.001, \
  2513. dtype::Float32(), dtype::Float32(), \
  2514. dtype::Float32(), dtype::Float32(), name);
  2515. #if MEGDNN_AARCH64
  2516. cb("CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  2517. #elif MEGDNN_ARMV7
  2518. cb("CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  2519. #endif
  2520. #undef cb
  2521. }
  2522. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  2523. using namespace conv_bias;
  2524. std::vector<conv_bias::TestArg> args =
  2525. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2526. std::vector<conv_bias::TestArg> args_of_4;
  2527. for (auto&& arg : args) {
  2528. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  2529. args_of_4.push_back(arg);
  2530. }
  2531. }
  2532. #if MEGDNN_AARCH64
  2533. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  2534. #elif MEGDNN_ARMV7
  2535. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  2536. #endif
  2537. }
  2538. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  2539. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  2540. using namespace conv_bias;
  2541. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2542. NormalRNG rng(1);
  2543. #if MEGDNN_AARCH64
  2544. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2545. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2546. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2547. #elif MEGDNN_ARMV7
  2548. checker_conv_bias(args, handle(), &rng, 0.03, dtype::Float16{},
  2549. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2550. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2551. #endif
  2552. std::vector<conv_bias::TestArg> gemv_args;
  2553. for (auto&& arg : args)
  2554. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2555. gemv_args.emplace_back(arg);
  2556. }
  2557. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  2558. }
  2559. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16_PREPROCESS) {
  2560. using namespace conv_bias;
  2561. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  2562. NormalRNG rng(1);
  2563. #if MEGDNN_AARCH64
  2564. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{},
  2565. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2566. "CONV1x1:AARCH64_F16_K8X24X1:48");
  2567. #elif MEGDNN_ARMV7
  2568. check_conv_bias_preprocess(args, handle(), &rng, 0.03, dtype::Float16{},
  2569. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  2570. "CONV1x1:AARCH32_F16_K4X16X1:24");
  2571. #endif
  2572. }
  2573. #endif
  2574. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  2575. UniformIntRNG rng{-50, 50};
  2576. float epsilon = 0.001;
  2577. std::vector<conv_bias::TestArg> args =
  2578. get_conv_bias_1x1_args(false, false, true, true);
  2579. #define cb(name) \
  2580. checker_conv_bias(args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2581. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2582. dtype::QuantizedS8(60.25f), name);
  2583. #if MEGDNN_AARCH64
  2584. #if __ARM_FEATURE_DOTPROD
  2585. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2586. #else
  2587. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2588. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2589. #endif
  2590. #elif MEGDNN_ARMV7
  2591. epsilon = 1;
  2592. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2593. #endif
  2594. #undef cb
  2595. std::vector<conv_bias::TestArg> gemv_args;
  2596. for (auto&& arg : args)
  2597. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2598. gemv_args.emplace_back(arg);
  2599. }
  2600. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2601. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2602. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2603. "CONV1x1_GEMV");
  2604. }
  2605. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM_PREPROCESS) {
  2606. UniformIntRNG rng{-50, 50};
  2607. float epsilon = 0.001;
  2608. std::vector<conv_bias::TestArg> args =
  2609. get_conv_bias_1x1_args(false, false, true, true);
  2610. #define cb(name) \
  2611. check_conv_bias_preprocess( \
  2612. args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2613. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2614. dtype::QuantizedS8(60.25f), name);
  2615. #if MEGDNN_AARCH64
  2616. #if __ARM_FEATURE_DOTPROD
  2617. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  2618. #else
  2619. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2620. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  2621. #endif
  2622. #elif MEGDNN_ARMV7
  2623. epsilon = 1;
  2624. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  2625. #endif
  2626. #undef cb
  2627. }
  2628. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2629. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  2630. UniformIntRNG rng{-50, 50};
  2631. std::vector<conv_bias::TestArg> args =
  2632. get_conv_bias_1x1_args(false, false, true, true);
  2633. #define cb(name) \
  2634. checker_conv_bias(args, handle(), &rng, epsilon, \
  2635. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2636. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2637. dtype::QuantizedS32(1.2 * 1.3), \
  2638. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  2639. float epsilon = 0.001;
  2640. #if MEGDNN_AARCH64
  2641. #if __ARM_FEATURE_DOTPROD
  2642. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2643. #else
  2644. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2645. #endif
  2646. #elif MEGDNN_ARMV7
  2647. epsilon = 1;
  2648. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2649. #endif
  2650. #undef cb
  2651. std::vector<conv_bias::TestArg> gemv_args;
  2652. for (auto&& arg : args)
  2653. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2654. gemv_args.emplace_back(arg);
  2655. }
  2656. checker_conv_bias(gemv_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),
  2661. "CONV1x1_GEMV");
  2662. }
  2663. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM_PREPROCESS) {
  2664. UniformIntRNG rng{-50, 50};
  2665. std::vector<conv_bias::TestArg> args =
  2666. get_conv_bias_1x1_args(false, false, true, true);
  2667. #define cb(name) \
  2668. check_conv_bias_preprocess(args, handle(), &rng, epsilon, \
  2669. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2670. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2671. dtype::QuantizedS32(1.2 * 1.3), \
  2672. dtype::Quantized8Asymm(50.3f, (uint8_t)120), \
  2673. name);
  2674. float epsilon = 0.001;
  2675. #if MEGDNN_AARCH64
  2676. #if __ARM_FEATURE_DOTPROD
  2677. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  2678. #else
  2679. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  2680. #endif
  2681. #elif MEGDNN_ARMV7
  2682. epsilon = 1;
  2683. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  2684. #endif
  2685. #undef cb
  2686. }
  2687. #endif
  2688. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  2689. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  2690. NormalRNG rng(128.f);
  2691. float epsilon = 0.001;
  2692. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2693. #define cb(name) \
  2694. checker_conv_bias(args, handle(), &rng, epsilon, \
  2695. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2696. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2697. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2698. #if MEGDNN_AARCH64
  2699. #if __ARM_FEATURE_DOTPROD
  2700. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2701. #else
  2702. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2703. #endif
  2704. #elif MEGDNN_ARMV7
  2705. #if __ARM_FEATURE_DOTPROD
  2706. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2707. #endif
  2708. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2709. #endif
  2710. #undef cb
  2711. std::vector<conv_bias::TestArg> gemv_args;
  2712. for (auto&& arg : args)
  2713. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2714. gemv_args.emplace_back(arg);
  2715. }
  2716. checker_conv_bias(gemv_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), {}, "CONV1x1_GEMV");
  2720. }
  2721. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32_PREPROCESS) {
  2722. NormalRNG rng(128.f);
  2723. float epsilon = 0.001;
  2724. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2725. #define cb(name) \
  2726. check_conv_bias_preprocess(args, handle(), &rng, epsilon, \
  2727. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  2728. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  2729. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  2730. #if MEGDNN_AARCH64
  2731. #if __ARM_FEATURE_DOTPROD
  2732. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  2733. #else
  2734. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  2735. #endif
  2736. #elif MEGDNN_ARMV7
  2737. #if __ARM_FEATURE_DOTPROD
  2738. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  2739. #endif
  2740. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  2741. #endif
  2742. #undef cb
  2743. }
  2744. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  2745. UniformIntRNG rng{-50, 50};
  2746. float epsilon = 0.001;
  2747. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2748. std::vector<conv_bias::TestArg> args_nchw44 = get_nchw44_conv_bias_args(
  2749. {1}, 1, true, true, true, false, false, false, false, true);
  2750. #define cb(name) \
  2751. checker_conv_bias(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2752. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2753. #define cb_nchw44(name) \
  2754. checker_conv_bias(args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, \
  2755. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, name);
  2756. #if MEGDNN_AARCH64
  2757. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2758. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2759. #elif MEGDNN_ARMV7
  2760. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2761. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2762. cb_nchw44("CONV1x1:ARMV7_INT8X8X16_MK4_K8X8X4:48");
  2763. #endif
  2764. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  2765. #undef cb
  2766. #undef cb_nchw44
  2767. std::vector<conv_bias::TestArg> gemv_args;
  2768. for (auto&& arg : args)
  2769. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2770. gemv_args.emplace_back(arg);
  2771. }
  2772. checker_conv_bias(gemv_args, handle(), &rng, epsilon, dtype::Int8{},
  2773. dtype::Int8{}, dtype::Int16{}, dtype::Int16{},
  2774. "CONV1x1_GEMV");
  2775. }
  2776. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16_PREPROCESS) {
  2777. UniformIntRNG rng{-50, 50};
  2778. float epsilon = 0.001;
  2779. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2780. #define cb(name) \
  2781. check_conv_bias_preprocess(args, handle(), &rng, epsilon, dtype::Int8{}, \
  2782. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  2783. name);
  2784. #if MEGDNN_AARCH64
  2785. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  2786. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  2787. cb("CONV1x1:ARM_COMMON_INT8X8X16:24");//!add nopack test
  2788. #elif MEGDNN_ARMV7
  2789. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  2790. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  2791. cb("CONV1x1:ARM_COMMON_INT8X8X16:24");//!add nopack test
  2792. #endif
  2793. #undef cb
  2794. }
  2795. #endif
  2796. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  2797. using namespace conv_bias;
  2798. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2799. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2800. #if MEGDNN_AARCH64
  2801. #if __ARM_FEATURE_DOTPROD
  2802. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2803. #else
  2804. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2805. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2806. #endif
  2807. #elif MEGDNN_ARMV7
  2808. #if __ARM_FEATURE_DOTPROD
  2809. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2810. #endif
  2811. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2812. #endif
  2813. #if MEGDNN_ARMV7
  2814. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2815. #endif
  2816. #undef cb
  2817. std::vector<conv_bias::TestArg> gemv_args;
  2818. for (auto&& arg : args)
  2819. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2820. gemv_args.emplace_back(arg);
  2821. }
  2822. checker_conv_bias_mul_int8x8x32(gemv_args, handle(), "CONV1x1_GEMV");
  2823. }
  2824. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_PREPROCESS) {
  2825. using namespace conv_bias;
  2826. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  2827. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2828. #if MEGDNN_AARCH64
  2829. #if __ARM_FEATURE_DOTPROD
  2830. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  2831. #else
  2832. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  2833. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  2834. #endif
  2835. #elif MEGDNN_ARMV7
  2836. #if __ARM_FEATURE_DOTPROD
  2837. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  2838. #endif
  2839. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  2840. #endif
  2841. #if MEGDNN_ARMV7
  2842. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  2843. #endif
  2844. #undef cb
  2845. }
  2846. #ifndef __ARM_FEATURE_DOTPROD
  2847. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  2848. using namespace conv_bias;
  2849. std::vector<conv_bias::TestArg> args =
  2850. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2851. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  2852. #if MEGDNN_AARCH64
  2853. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2854. #elif MEGDNN_ARMV7
  2855. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2856. #endif
  2857. #undef cb
  2858. UniformIntRNG rng{-50, 50};
  2859. float epsilon = 0.001;
  2860. #define cb(name) \
  2861. checker_conv_bias(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2862. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2863. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2864. dtype::QuantizedS8(60.25f), name);
  2865. #if MEGDNN_AARCH64
  2866. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2867. #elif MEGDNN_ARMV7
  2868. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2869. #endif
  2870. #undef cb
  2871. }
  2872. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4_PREPROCESS) {
  2873. using namespace conv_bias;
  2874. std::vector<conv_bias::TestArg> args =
  2875. get_nchw44_conv_bias_args({1}, 1, true, true, true);
  2876. #define cb(name) checker_conv_bias_int8x8x32_preprocess(args, handle(), name);
  2877. #if MEGDNN_AARCH64
  2878. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2879. #elif MEGDNN_ARMV7
  2880. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2881. #endif
  2882. #undef cb
  2883. UniformIntRNG rng{-50, 50};
  2884. float epsilon = 0.001;
  2885. #define cb(name) \
  2886. check_conv_bias_preprocess(get_nchw44_conv_bias_args({1}, 1, true, false, false), \
  2887. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  2888. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  2889. dtype::QuantizedS8(60.25f), name);
  2890. #if MEGDNN_AARCH64
  2891. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  2892. #elif MEGDNN_ARMV7
  2893. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  2894. #endif
  2895. #undef cb
  2896. }
  2897. #endif
  2898. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  2899. using namespace conv_bias;
  2900. std::vector<conv_bias::TestArg> args =
  2901. get_nchw44_conv_bias_args({1}, 1, true, false, false);
  2902. UniformIntRNG rng{-50, 50};
  2903. float epsilon = 0.001;
  2904. std::vector<conv_bias::TestArg> gemv_args;
  2905. for (auto&& arg : args)
  2906. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2907. gemv_args.emplace_back(arg);
  2908. }
  2909. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2910. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2911. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2912. "CONV1x1_GEMV");
  2913. }
  2914. #ifdef __ARM_FEATURE_DOTPROD
  2915. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  2916. using namespace conv_bias;
  2917. std::vector<conv_bias::TestArg> args =
  2918. get_nchw44_conv_bias_args({1}, 1, true, false, false, false, true);
  2919. UniformIntRNG rng{-50, 50};
  2920. float epsilon = 0.001;
  2921. std::vector<conv_bias::TestArg> gemv_args;
  2922. for (auto&& arg : args)
  2923. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  2924. gemv_args.emplace_back(arg);
  2925. }
  2926. checker_conv_bias(gemv_args, handle(), &rng, epsilon,
  2927. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  2928. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  2929. "CONV1x1_GEMV");
  2930. }
  2931. #endif
  2932. // vim: syntax=cpp.doxygen

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