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.cpp 95 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327
  1. /**
  2. * \file dnn/test/arm_common/conv_bias.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #include "megdnn/dtype.h"
  13. #include "test/arm_common/fixture.h"
  14. #include "megdnn/opr_param_defs.h"
  15. #include "megdnn/oprs.h"
  16. #include "src/fallback/conv_bias/common.h"
  17. #include "test/common/benchmarker.h"
  18. #include "test/common/checker.h"
  19. #include "test/common/conv_bias.h"
  20. #include "test/common/rng.h"
  21. #include "test/common/tensor.h"
  22. #include "test/common/workspace_wrapper.h"
  23. using namespace megdnn;
  24. using namespace test;
  25. using namespace conv_bias;
  26. //! TODO this algo current does not support multithread
  27. TEST_F(ARM_COMMON, CONVBIAS_INT8_INT8_INT16_STRIDE2F2) {
  28. checker_conv_bias_int8x8x16(get_conv_bias_args({2}, 2, true, true, true),
  29. handle(), "I8816STRD2F2");
  30. }
  31. TEST_F(ARM_COMMON, CONV_BIAS_MATMUL) {
  32. using namespace conv_bias;
  33. std::vector<TestArg> args = get_quantized_args();
  34. Checker<ConvBiasForward> checker(handle());
  35. checker.set_before_exec_callback(
  36. conv_bias::ConvBiasAlgoChecker<ConvBias>("S8MATMUL"));
  37. #if MEGDNN_ARMV7
  38. checker.set_epsilon(1);
  39. #endif
  40. UniformIntRNG rng{-50, 50};
  41. for (auto&& arg : args) {
  42. if (arg.bias.ndim == 4 && arg.bias[2] != 1 && arg.bias[3] != 1)
  43. continue;
  44. checker.set_dtype(0, dtype::QuantizedS8(0.41113496f))
  45. .set_dtype(1, dtype::QuantizedS8(0.01887994f))
  46. .set_dtype(2, dtype::QuantizedS32(0.41113496f * 0.01887994f))
  47. .set_dtype(4, dtype::QuantizedS8(0.49550694f))
  48. .set_rng(0, &rng)
  49. .set_rng(1, &rng)
  50. .set_rng(2, &rng)
  51. .set_param(arg.param)
  52. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  53. }
  54. }
  55. #define CONV_BIAS_MATMUL_QU8_MODE(MODE) \
  56. using namespace conv_bias; \
  57. std::vector<TestArg> args = get_quantized_args_with_nlmode(MODE); \
  58. Checker<ConvBiasForward> checker(handle()); \
  59. checker.set_before_exec_callback( \
  60. conv_bias::ConvBiasAlgoChecker<ConvBias>("QU8MATMUL")); \
  61. UniformIntRNG rng{0, 127}; \
  62. for (auto&& arg : args) { \
  63. if (arg.bias.ndim == 4 && arg.bias[2] != 1 && arg.bias[3] != 1) \
  64. continue; \
  65. checker.set_dtype(0, dtype::Quantized8Asymm( \
  66. 2.5f, static_cast<uint8_t>(127))) \
  67. .set_dtype(1, dtype::Quantized8Asymm( \
  68. 2.7f, static_cast<uint8_t>(126))) \
  69. .set_dtype(2, dtype::QuantizedS32(6.75f)) \
  70. .set_dtype(4, dtype::Quantized8Asymm( \
  71. 60.25f, static_cast<uint8_t>(125))) \
  72. .set_rng(0, &rng) \
  73. .set_rng(1, &rng) \
  74. .set_rng(2, &rng) \
  75. .set_param(arg.param) \
  76. .execs({arg.src, arg.filter, arg.bias, {}, {}}); \
  77. }
  78. #define MODE_STR(mode) param::ConvBias::NonlineMode::mode
  79. #define CB_TEST(MODE) \
  80. TEST_F(ARM_COMMON, CONV_BIAS_MATMUL_QU8_##MODE) { \
  81. CONV_BIAS_MATMUL_QU8_MODE(MODE_STR(MODE)); \
  82. }
  83. CB_TEST(IDENTITY);
  84. CB_TEST(RELU);
  85. CB_TEST(H_SWISH);
  86. #undef MODE_STR
  87. #undef CB_TEST
  88. #undef CONV_BIAS_MATMUL_QU8_MODE
  89. #if MEGDNN_WITH_BENCHMARK
  90. static void benchmark_convbias(Handle* handle, std::string int_name,
  91. std::string float_name, bool is_fp32 = false) {
  92. constexpr size_t RUNS = 30;
  93. Benchmarker<ConvBias> benchmarker_int(handle);
  94. benchmarker_int.set_times(RUNS)
  95. .set_dtype(0, dtype::QuantizedS8(2.5))
  96. .set_dtype(1, dtype::QuantizedS8(2.5))
  97. .set_dtype(2, dtype::QuantizedS32(6.25))
  98. .set_dtype(4, dtype::QuantizedS8(60.25))
  99. .set_display(false);
  100. benchmarker_int.set_before_exec_callback(
  101. conv_bias::ConvBiasAlgoChecker<ConvBias>(int_name.c_str()));
  102. Benchmarker<ConvBias> benchmarker_float(handle);
  103. benchmarker_float.set_display(false).set_times(RUNS);
  104. benchmarker_float.set_before_exec_callback(
  105. conv_bias::ConvBiasAlgoChecker<ConvBias>(float_name.c_str()));
  106. Benchmarker<ConvBias> benchmarker_nchw44(handle);
  107. if (is_fp32) {
  108. benchmarker_nchw44.set_times(RUNS)
  109. .set_dtype(0, dtype::Float32())
  110. .set_dtype(1, dtype::Float32())
  111. .set_dtype(2, dtype::Float32())
  112. .set_dtype(4, dtype::Float32())
  113. .set_display(false);
  114. } else {
  115. benchmarker_nchw44.set_times(RUNS)
  116. .set_dtype(0, dtype::QuantizedS8(2.5))
  117. .set_dtype(1, dtype::QuantizedS8(2.5))
  118. .set_dtype(2, dtype::QuantizedS32(6.25))
  119. .set_dtype(4, dtype::QuantizedS8(60.25))
  120. .set_display(false);
  121. }
  122. auto nchw44_algo_regx = ".*(DIRECT|NCHW_NCHW44).*";
  123. #if __ARM_FEATURE_DOTPROD
  124. if (!is_fp32) {
  125. nchw44_algo_regx = ".*DOT.*";
  126. }
  127. #endif
  128. benchmarker_nchw44.set_before_exec_callback(
  129. conv_bias::ConvBiasAlgoChecker<ConvBias>(nchw44_algo_regx));
  130. auto run = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  131. size_t FS, size_t stride, bool input_nchw = false) {
  132. param::ConvBias param;
  133. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  134. param.stride_h = stride;
  135. param.stride_w = stride;
  136. param.pad_h = FS / 2;
  137. param.pad_w = FS / 2;
  138. auto OH = (H + 2 * param.pad_h - FS) /
  139. static_cast<size_t>(param.stride_h) +
  140. 1;
  141. auto OW = (W + 2 * param.pad_w - FS) /
  142. static_cast<size_t>(param.stride_w) +
  143. 1;
  144. TensorShape src({N, IC, H, W}), filter({OC, IC, FS, FS}),
  145. bias({1, OC, 1, 1}), dst({N, OC, OH, OW});
  146. param.format = param::ConvBias::Format::NCHW;
  147. auto int_used = benchmarker_int.set_param(param).exec(
  148. {src, filter, bias, {}, dst}) /
  149. RUNS;
  150. auto float_used = benchmarker_float.set_param(param).exec(
  151. {src, filter, bias, {}, dst}) /
  152. RUNS;
  153. param.format = param::ConvBias::Format::NCHW44;
  154. src = {N, IC / 4, H, W, 4};
  155. filter = {OC / 4, IC / 4, FS, FS, 4, 4};
  156. if (input_nchw) {
  157. src = {N, IC, H, W};
  158. filter = {OC / 4, FS, FS, IC, 4};
  159. }
  160. bias = {1, OC / 4, 1, 1, 4};
  161. dst = {N, OC / 4, OH, OW, 4};
  162. auto int_nchw44_used = benchmarker_nchw44.set_param(param).exec(
  163. {src, filter, bias, {}, dst}) /
  164. RUNS;
  165. float computations = IC * (FS * FS) * dst.total_nr_elems() * 2 * 1e-6;
  166. printf("run: %s %s %s->%s \n", src.to_string().c_str(),
  167. filter.to_string().c_str(), bias.to_string().c_str(),
  168. dst.to_string().c_str());
  169. printf("float: %f ms %f Gflops, ", float_used,
  170. computations / float_used);
  171. printf("int_nchw: %f ms %f Gflops, ", int_used,
  172. computations / int_used);
  173. auto speed_up = int_used / int_nchw44_used;
  174. if (is_fp32) {
  175. speed_up = float_used / int_nchw44_used;
  176. printf("fp32_nchw44: %f ms %f Gflops %f speedup, ", int_nchw44_used,
  177. computations / int_nchw44_used, speed_up);
  178. } else {
  179. printf("int_nchw44: %f ms %f Gflops %f speedup, ", int_nchw44_used,
  180. computations / int_nchw44_used, speed_up);
  181. }
  182. printf("\n");
  183. };
  184. if (is_fp32) {
  185. run(1, 1, 4, 112, 112, 2, 2, true);
  186. run(1, 3, 32, 224, 224, 3, 2, true);
  187. run(1, 3, 64, 224, 224, 7, 2, true);
  188. run(1, 1, 4, 112, 112, 2, 1, true);
  189. run(1, 3, 32, 224, 224, 3, 1, true);
  190. run(1, 3, 64, 224, 224, 3, 1, true);
  191. run(1, 3, 64, 224, 224, 7, 1, true);
  192. run(1, 64, 128, 56, 56, 3, 2, false);
  193. run(1, 128, 256, 28, 28, 3, 2, false);
  194. run(1, 256, 512, 14, 14, 3, 2, false);
  195. run(1, 128, 128, 28, 28, 3, 1, false);
  196. run(1, 256, 256, 14, 14, 3, 1, false);
  197. run(1, 512, 512, 7, 7, 3, 1, false);
  198. } else {
  199. run(1, 1, 4, 112, 112, 2, 2, true);
  200. run(1, 3, 32, 224, 224, 3, 2, true);
  201. run(1, 3, 32, 224, 224, 5, 2, true);
  202. run(1, 3, 64, 224, 224, 7, 2, true);
  203. run(1, 1, 4, 112, 112, 2, 1, true);
  204. run(1, 3, 32, 224, 224, 3, 1, true);
  205. run(1, 3, 32, 224, 224, 5, 1, true);
  206. run(1, 3, 64, 224, 224, 7, 1, true);
  207. run(1, 64, 128, 56, 56, 3, 2, false);
  208. run(1, 128, 256, 28, 28, 3, 2, false);
  209. run(1, 256, 512, 14, 14, 3, 2, false);
  210. run(1, 128, 128, 28, 28, 3, 1, false);
  211. run(1, 256, 256, 14, 14, 3, 1, false);
  212. run(1, 512, 512, 7, 7, 3, 1, false);
  213. for (size_t stride : {1}) {
  214. printf("stride %zu\n", stride);
  215. for (size_t filter_size : {2, 3, 5, 7}) {
  216. for (size_t img_size : {32}) {
  217. for (size_t channel : {8, 16, 32, 64, 128, 256}) {
  218. run(1, channel, channel, img_size, img_size,
  219. filter_size, stride, false);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_NCHW44) {
  227. #if MEGDNN_AARCH64
  228. benchmark_convbias(handle(), "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16:384",
  229. "IM2COLMATMUL:AARCH64_F32K8X12X1:192", true);
  230. benchmark_convbias(handle(), "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16:384",
  231. "IM2COLMATMUL:AARCH64_F32K8X12X1:192", false);
  232. #else
  233. benchmark_convbias(handle(), "IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8:384",
  234. "IM2COLMATMUL:ARMV7_F32:192", true);
  235. benchmark_convbias(handle(), "IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8:384",
  236. "IM2COLMATMUL:ARMV7_F32:192", false);
  237. #endif
  238. }
  239. TEST_F(ARM_COMMON_MULTI_THREADS, BENCHMARK_CONVBIAS_NCHW44) {
  240. #if MEGDNN_AARCH64
  241. benchmark_convbias(handle(), "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16:384",
  242. "IM2COLMATMUL:AARCH64_F32K8X12X1:192", true);
  243. benchmark_convbias(handle(), "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16:384",
  244. "IM2COLMATMUL:AARCH64_F32K8X12X1:192", false);
  245. #else
  246. benchmark_convbias(handle(), "IM2COLMATMUL:ARMV7_INT8X8X32_K4X8X8:384",
  247. "IM2COLMATMUL:ARMV7_F32:192", true);
  248. benchmark_convbias(handle(), "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16:384",
  249. "IM2COLMATMUL:ARMV7_F32:192", false);
  250. #endif
  251. }
  252. #endif
  253. TEST_F(ARM_COMMON, CONV_BIAS_MATMUL_QS8) {
  254. using namespace conv_bias;
  255. std::vector<TestArg> args = get_quantized_args();
  256. Checker<ConvBiasForward> checker(handle());
  257. checker.set_before_exec_callback(
  258. conv_bias::ConvBiasAlgoChecker<ConvBias>("S8MATMUL"));
  259. #if MEGDNN_ARMV7
  260. checker.set_epsilon(1);
  261. #endif
  262. UniformIntRNG rng{0, 255};
  263. for (auto&& arg : args) {
  264. if (arg.bias.ndim == 4 && arg.bias[2] != 1 && arg.bias[3] != 1)
  265. continue;
  266. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  267. .set_dtype(1, dtype::QuantizedS8(2.7f))
  268. .set_dtype(2, dtype::QuantizedS32(6.75f))
  269. .set_dtype(4, dtype::QuantizedS8(60.25f))
  270. .set_rng(0, &rng)
  271. .set_rng(1, &rng)
  272. .set_rng(2, &rng)
  273. .set_param(arg.param)
  274. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  275. }
  276. }
  277. #if MEGDNN_ARMV7
  278. TEST_F(ARM_COMMON, CONV_BIAS_RESCALE_OP) {
  279. using namespace conv_bias;
  280. Checker<ConvBias> checker(handle());
  281. checker.set_before_exec_callback(
  282. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("S8MATMUL"));
  283. checker.set_epsilon(1).set_max_avg_error(1e-2).set_max_avg_biased_error(
  284. 1e-3);
  285. UniformIntRNG rng{-128, 127};
  286. checker.set_dtype(0, dtype::QuantizedS8(0.41113496f))
  287. .set_dtype(1, dtype::QuantizedS8(0.01887994f))
  288. .set_dtype(2, dtype::QuantizedS32(0.41113496f * 0.01887994f))
  289. .set_dtype(4, dtype::QuantizedS8(0.49550694f))
  290. .set_rng(0, &rng)
  291. .set_rng(1, &rng)
  292. .set_rng(2, &rng);
  293. param::ConvBias param;
  294. param.stride_h = 1;
  295. param.stride_w = 1;
  296. param.pad_h = 0;
  297. param.pad_w = 0;
  298. param.nonlineMode = NonlineMode::IDENTITY;
  299. //! Unary op
  300. checker.set_param(param).exec({TensorShape{2, 1, 128, 128},
  301. TensorShape{16, 1, 2, 2},
  302. TensorShape{},
  303. TensorShape{},
  304. {}});
  305. //! Binary op
  306. checker.set_param(param).exec({TensorShape{2, 1, 128, 128},
  307. TensorShape{16, 1, 2, 2},
  308. TensorShape{1, 16, 1, 1},
  309. TensorShape{},
  310. {}});
  311. }
  312. #endif
  313. #if MEGDNN_WITH_BENCHMARK
  314. void benchmark_im2col(const char* algo_name, const char* im2col_name,
  315. Handle* handle, size_t kernel, size_t pack_size = 1) {
  316. auto&& args = get_winograd_benchmark_args(kernel, pack_size);
  317. using namespace conv_bias;
  318. constexpr size_t RUN = 10;
  319. Benchmarker<ConvBias> benchmark(handle);
  320. benchmark.set_display(false);
  321. benchmark.set_times(RUN);
  322. Benchmarker<ConvBias> benchmark_im2col(handle);
  323. benchmark_im2col.set_display(false);
  324. benchmark_im2col.set_times(RUN);
  325. for (auto&& arg : args) {
  326. TensorLayout dst_layout;
  327. auto opr = handle->create_operator<ConvBias>();
  328. opr->param() = arg.param;
  329. opr->deduce_layout({arg.src, dtype::Float32()},
  330. {arg.filter, dtype::Float32()},
  331. {arg.bias, dtype::Float32()}, {}, dst_layout);
  332. //! dst.nr_elems * IC * FH * FW * 2
  333. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  334. arg.filter[2] * arg.filter[3] * 2.0 /
  335. (1024 * 1024 * 1024) * 1e3;
  336. benchmark.set_param(arg.param);
  337. auto used = algo_benchmark<ConvBias>(benchmark,
  338. {arg.src, arg.filter, {}, {}, {}},
  339. algo_name) /
  340. RUN;
  341. benchmark_im2col.set_param(arg.param);
  342. auto used_im2col =
  343. algo_benchmark<ConvBias>(benchmark_im2col,
  344. {arg.src, arg.filter, {}, {}, {}},
  345. im2col_name) /
  346. RUN;
  347. printf("%s %s: normal: %f ms %f Gflops im2col: %f ms %f GFlops "
  348. "speedup: "
  349. "%f\n",
  350. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  351. used, computations / used, used_im2col,
  352. computations / used_im2col, used / used_im2col);
  353. }
  354. }
  355. void benchmark_im2col_single_algo(const char* im2col_name, Handle* handle,
  356. size_t kernel, size_t pack_size = 1) {
  357. std::vector<conv_bias::TestArg> args;
  358. auto pack = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  359. size_t p) {
  360. if (ic % pack_size != 0 || oc % pack_size != 0)
  361. return;
  362. if (w + 2 * p < kernel || h + 2 * p < kernel)
  363. return;
  364. param::ConvBias param;
  365. param.stride_h = 1;
  366. param.stride_w = 1;
  367. param.pad_h = p;
  368. param.pad_w = p;
  369. args.push_back(conv_bias::TestArg{param,
  370. TensorShape{1, ic, h, w},
  371. TensorShape{oc, ic, kernel, kernel},
  372. {1, oc, 1, 1}});
  373. };
  374. pack(1, 64, 100, 100, kernel, 1);
  375. pack(8, 64, 100, 100, kernel, 1);
  376. pack(16, 64, 100, 100, kernel, 1);
  377. pack(32, 64, 100, 100, kernel, 1);
  378. pack(64, 64, 100, 100, kernel, 1);
  379. pack(128, 64, 100, 100, kernel, 1);
  380. pack(256, 64, 100, 100, kernel, 1);
  381. pack(512, 64, 100, 100, kernel, 1);
  382. pack(1024, 64, 100, 100, kernel, 1);
  383. pack(1, 64, 10, 10, kernel, 1);
  384. pack(8, 64, 10, 10, kernel, 1);
  385. pack(16, 64, 10, 10, kernel, 1);
  386. pack(32, 64, 10, 10, kernel, 1);
  387. pack(64, 64, 10, 10, kernel, 1);
  388. pack(128, 64, 10, 10, kernel, 1);
  389. pack(256, 64, 10, 10, kernel, 1);
  390. pack(512, 64, 10, 10, kernel, 1);
  391. pack(1024, 64, 10, 10, kernel, 1);
  392. pack(1, 16, 10, 10, kernel, 1);
  393. pack(8, 16, 10, 10, kernel, 1);
  394. pack(16, 16, 10, 10, kernel, 1);
  395. pack(32, 16, 10, 10, kernel, 1);
  396. pack(64, 16, 10, 10, kernel, 1);
  397. pack(128, 16, 10, 10, kernel, 1);
  398. pack(256, 16, 10, 10, kernel, 1);
  399. pack(512, 16, 10, 10, kernel, 1);
  400. pack(1024, 16, 10, 10, kernel, 1);
  401. using namespace conv_bias;
  402. constexpr size_t RUN = 20;
  403. Benchmarker<ConvBias> benchmark_im2col(handle);
  404. benchmark_im2col.set_display(false);
  405. benchmark_im2col.set_times(RUN);
  406. for (auto&& arg : args) {
  407. TensorLayout dst_layout;
  408. auto opr = handle->create_operator<ConvBias>();
  409. opr->param() = arg.param;
  410. opr->deduce_layout({arg.src, dtype::Float32()},
  411. {arg.filter, dtype::Float32()},
  412. {arg.bias, dtype::Float32()}, {}, dst_layout);
  413. //! dst.nr_elems * IC * FH * FW * 2
  414. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  415. arg.filter[2] * arg.filter[3] * 2.0 /
  416. (1024 * 1024 * 1024) * 1e3;
  417. benchmark_im2col.set_param(arg.param);
  418. auto used_im2col =
  419. algo_benchmark<ConvBias>(benchmark_im2col,
  420. {arg.src, arg.filter, {}, {}, {}},
  421. im2col_name) /
  422. RUN;
  423. printf("%s %s: im2col: %f ms %f GFlops \n", arg.src.to_string().c_str(),
  424. arg.filter.to_string().c_str(), used_im2col,
  425. computations / used_im2col);
  426. }
  427. }
  428. void BENCHMARK_IM2COL_NCHW44_VS_NCHW(const char* algo_name,
  429. const char* im2col_name, Handle* handle,
  430. size_t kernel, size_t pack_size = 1) {
  431. auto&& args = get_winograd_benchmark_args(kernel, pack_size);
  432. using namespace conv_bias;
  433. constexpr size_t RUN = 10;
  434. Benchmarker<ConvBias> benchmark(handle);
  435. benchmark.set_display(false);
  436. benchmark.set_times(RUN);
  437. benchmark.set_dtype(0, dtype::Int8());
  438. benchmark.set_dtype(1, dtype::Int8());
  439. benchmark.set_dtype(2, dtype::Int32());
  440. benchmark.set_dtype(4, dtype::Int32());
  441. Benchmarker<ConvBias> benchmark_im2col(handle);
  442. benchmark_im2col.set_display(false);
  443. benchmark_im2col.set_times(RUN);
  444. benchmark_im2col.set_dtype(0, dtype::Int8());
  445. benchmark_im2col.set_dtype(1, dtype::Int8());
  446. benchmark_im2col.set_dtype(2, dtype::Int32());
  447. benchmark_im2col.set_dtype(4, dtype::Int32());
  448. for (auto&& arg : args) {
  449. TensorLayout dst_layout;
  450. auto opr = handle->create_operator<ConvBias>();
  451. opr->param() = arg.param;
  452. opr->deduce_layout({arg.src, dtype::Float32()},
  453. {arg.filter, dtype::Float32()},
  454. {arg.bias, dtype::Float32()}, {}, dst_layout);
  455. //! dst.nr_elems * IC * FH * FW * 2
  456. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  457. arg.filter[2] * arg.filter[3] * 2.0 /
  458. (1024 * 1024 * 1024) * 1e3;
  459. std::vector<conv_bias::TestArg> nchw44param;
  460. benchmark.set_param(arg.param);
  461. auto used = algo_benchmark<ConvBias>(benchmark,
  462. {arg.src, arg.filter, {}, {}, {}},
  463. algo_name) /
  464. RUN;
  465. arg.param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  466. arg.param.format = param::ConvBias::Format::NCHW44;
  467. benchmark_im2col.set_param(arg.param);
  468. nchw44param.push_back(conv_bias::TestArg{
  469. arg.param,
  470. TensorShape{arg.src.shape[0], arg.src.shape[1] / 4, arg.src[2],
  471. arg.src.shape[3], 4},
  472. TensorShape{arg.filter.shape[0] / 4, arg.filter.shape[1] / 4,
  473. kernel, kernel, 4, 4},
  474. TensorShape{}});
  475. auto used_im2col =
  476. algo_benchmark<ConvBias>(
  477. benchmark_im2col,
  478. {nchw44param[0].src, nchw44param[0].filter, {}, {}, {}},
  479. im2col_name) /
  480. RUN;
  481. printf("nchw44 shape src %s filter %s\n",
  482. nchw44param[0].src.to_string().c_str(),
  483. nchw44param[0].filter.to_string().c_str());
  484. printf("%s %s: normal: %f ms %f Gflops im2col: %f ms %f GFlops "
  485. "speedup: "
  486. "%f\n",
  487. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  488. used, computations / used, used_im2col,
  489. computations / used_im2col, used / used_im2col);
  490. }
  491. }
  492. #if MEGDNN_AARCH64
  493. TEST_F(ARM_COMMON, BENCHMARK_NCHW_VS_NCHW44_INT8x8x32) {
  494. printf("=========================compare "
  495. "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16, "
  496. "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16 \n");
  497. BENCHMARK_IM2COL_NCHW44_VS_NCHW("IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16",
  498. "IM2COLMATMUL:AARCH64_INT8X8X32_MK4_4X4X16",
  499. handle(), 3, 4);
  500. }
  501. #endif
  502. TEST_F(ARM_COMMON, BENCHMARK_GROUP_CONVBIAS_QUANTIZED) {
  503. constexpr size_t RUNS = 50;
  504. param::ConvBias param;
  505. param.sparse = param::ConvBias::Sparse::GROUP;
  506. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  507. Benchmarker<ConvBias> benchmarker_int(handle());
  508. benchmarker_int.set_times(RUNS)
  509. .set_dtype(0, dtype::QuantizedS8(2.5f))
  510. .set_dtype(1, dtype::QuantizedS8(2.5f))
  511. .set_dtype(2, dtype::QuantizedS32(6.25f))
  512. .set_dtype(4, dtype::QuantizedS8(40.25f))
  513. .set_display(false);
  514. Benchmarker<ConvBias> benchmarker_float(handle());
  515. benchmarker_float.set_display(false).set_times(RUNS);
  516. auto run = [&](size_t N, size_t GROUP, size_t IC, size_t OC, size_t H,
  517. size_t W, size_t FS, size_t STRD) {
  518. megdnn_assert(IC % GROUP == 0 && OC % GROUP == 0);
  519. TensorShape src({N, IC, H, W}),
  520. filter({GROUP, OC / GROUP, IC / GROUP, FS, FS}),
  521. bias({1, OC, 1, 1}), dst({N, OC, H / STRD, W / STRD});
  522. param.pad_h = FS / 2;
  523. param.pad_w = FS / 2;
  524. param.stride_h = STRD;
  525. param.stride_w = STRD;
  526. auto int_used = benchmarker_int.set_param(param).exec(
  527. {src, filter, bias, {}, dst}) /
  528. RUNS;
  529. auto float_used = benchmarker_float.set_param(param).exec(
  530. {src, filter, bias, {}, dst}) /
  531. RUNS;
  532. float computations = (IC / GROUP * FS * FS * dst.total_nr_elems() * 2 +
  533. dst.total_nr_elems()) *
  534. 1e-6;
  535. printf("run: %s %s %s->%s \nfloat: %f ms %f Gflops int: %f ms "
  536. "%f Gflops speedup: %f\n",
  537. src.to_string().c_str(), filter.to_string().c_str(),
  538. bias.to_string().c_str(), dst.to_string().c_str(), float_used,
  539. computations / float_used, int_used, computations / int_used,
  540. float_used / int_used);
  541. };
  542. run(1, 1, 28, 28, 28, 28, 3, 1);
  543. run(1, 68, 68, 68, 14, 14, 3, 2);
  544. run(1, 96, 96, 96, 14, 14, 3, 2);
  545. run(1, 100, 100, 100, 7, 7, 3, 1);
  546. }
  547. #endif
  548. #if MEGDNN_WITH_BENCHMARK
  549. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_MATMUL) {
  550. constexpr size_t RUNS = 10;
  551. param::ConvBias param;
  552. param.stride_h = 1;
  553. param.stride_w = 1;
  554. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  555. Benchmarker<ConvBias> benchmarker(handle()), benchmarker_fused(handle());
  556. benchmarker.set_times(RUNS)
  557. .set_dtype(0, dtype::QuantizedS8(2.5f))
  558. .set_dtype(1, dtype::QuantizedS8(2.5f))
  559. .set_dtype(2, dtype::QuantizedS32(6.25f))
  560. .set_dtype(4, dtype::QuantizedS8(40.25f))
  561. .set_display(false);
  562. benchmarker_fused.set_times(RUNS)
  563. .set_dtype(0, dtype::QuantizedS8(2.5f))
  564. .set_dtype(1, dtype::QuantizedS8(2.5f))
  565. .set_dtype(2, dtype::QuantizedS32(6.25f))
  566. .set_dtype(4, dtype::QuantizedS8(40.25f))
  567. .set_display(false);
  568. benchmarker_fused.set_before_exec_callback(
  569. conv_bias::ConvBiasAlgoChecker<ConvBias>("S8MATMUL"));
  570. auto run = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
  571. size_t FS) {
  572. TensorShape src({N, IC, H, W}), filter({OC, IC, FS, FS}),
  573. bias({1, OC, 1, 1}), dst({N, OC, H, W});
  574. param.pad_h = FS / 2;
  575. param.pad_w = FS / 2;
  576. auto default_used = benchmarker.set_param(param).exec(
  577. {src, filter, bias, {}, dst}) /
  578. RUNS;
  579. auto fused_used = benchmarker_fused.set_param(param).exec(
  580. {src, filter, bias, {}, dst}) /
  581. RUNS;
  582. float computations =
  583. IC * (FS * FS + 1) * dst.total_nr_elems() * 2 * 1e-6;
  584. printf("run: %s %s %s->%s \ndefault: %f ms %f Gflops fused: %f ms "
  585. "%f Gflops speedup: %f\n",
  586. src.to_string().c_str(), filter.to_string().c_str(),
  587. bias.to_string().c_str(), dst.to_string().c_str(), default_used,
  588. computations / default_used, fused_used,
  589. computations / fused_used, default_used / fused_used);
  590. };
  591. run(1, 128, 128, 32, 32, 3);
  592. for (size_t IC : {36, 48}) {
  593. for (size_t OC : {36, 48, 64}) {
  594. for (size_t size : {56, 128, 256}) {
  595. for (size_t FS : {1, 3, 5}) {
  596. run(1, IC, OC, size, size, FS);
  597. }
  598. }
  599. }
  600. }
  601. }
  602. #endif
  603. #if MEGDNN_WITH_BENCHMARK
  604. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F23) {
  605. #if MEGDNN_AARCH64
  606. benchmark_winograd("WINOGRAD:AARCH64_F32:1:2", handle(), 3);
  607. #else
  608. benchmark_winograd("WINOGRAD:ARMV7_F32_:1:2", handle(), 3);
  609. #endif
  610. }
  611. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F23_4x4) {
  612. #if MEGDNN_AARCH64
  613. benchmark_winograd("WINOGRAD:AARCH64_F32_MK4_4x16:4:2", handle(), 3, 4);
  614. #else
  615. benchmark_winograd("WINOGRAD:ARMV7_F32_MK4_4x8:4:2", handle(), 3, 4);
  616. #endif
  617. }
  618. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F63) {
  619. #if MEGDNN_AARCH64
  620. benchmark_winograd("WINOGRAD:AARCH64_F32K8X12X1:1:6", handle(), 3);
  621. #else
  622. benchmark_winograd("WINOGRAD:ARMV7_F32:1:6", handle(), 3);
  623. #endif
  624. }
  625. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F63_4x4) {
  626. #if MEGDNN_AARCH64
  627. benchmark_winograd("WINOGRAD:AARCH64_F32_MK4_4x16:4:6", handle(), 3, 4);
  628. #else
  629. benchmark_winograd("WINOGRAD:ARMV7_F32_MK4_4x8:4:6", handle(), 3, 4);
  630. #endif
  631. }
  632. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F54) {
  633. #if MEGDNN_AARCH64
  634. benchmark_winograd("WINOGRAD:AARCH64_F32K8X12X1:1:5", handle(), 4);
  635. #else
  636. benchmark_winograd("WINOGRAD:ARMV7_F32:1:5", handle(), 4);
  637. #endif
  638. }
  639. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F45) {
  640. #if MEGDNN_AARCH64
  641. benchmark_winograd("WINOGRAD:AARCH64_F32K8X12X1:1:4", handle(), 5);
  642. #else
  643. benchmark_winograd("WINOGRAD:ARMV7_F32:1:4", handle(), 5);
  644. #endif
  645. }
  646. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  647. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F16_F23) {
  648. #if MEGDNN_AARCH64
  649. benchmark_winograd_fp16("WINOGRAD:AARCH64_F32_MK4_4x16:4:2",
  650. "WINOGRAD:AARCH64_F16_K8X24X1:1:6", handle(), 3, 4);
  651. #else
  652. benchmark_winograd_fp16("WINOGRAD:ARMV7_F32:1:2",
  653. "WINOGRAD:AARCH32_F16_K4X16X1:1:2", handle(), 3);
  654. #endif
  655. }
  656. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F16_F45) {
  657. #if MEGDNN_AARCH64
  658. benchmark_winograd_fp16("WINOGRAD:AARCH64_F32K8X12X1:1:4",
  659. "WINOGRAD:AARCH64_F16_K8X24X1:1:4", handle(), 5);
  660. #else
  661. benchmark_winograd_fp16("WINOGRAD:ARMV7_F32:1:4",
  662. "WINOGRAD:AARCH32_F16_K4X16X1:1:4", handle(), 5);
  663. #endif
  664. }
  665. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F16_F63) {
  666. #if MEGDNN_AARCH64
  667. benchmark_winograd_fp16("WINOGRAD:AARCH64_F32K8X12X1:1:6",
  668. "WINOGRAD:AARCH64_F16_K8X24X1:1:6", handle(), 3);
  669. #else
  670. benchmark_winograd_fp16("WINOGRAD:ARMV7_F32:1:6",
  671. "WINOGRAD:AARCH32_F16_K4X16X1:1:6", handle(), 3);
  672. #endif
  673. }
  674. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F16_F23_8x8) {
  675. #if MEGDNN_AARCH64
  676. benchmark_winograd_fp16("WINOGRAD:AARCH64_F32_MK4_4x16:4:2",
  677. "WINOGRAD:AARCH64_F16_MK8_8X8:8:2", handle(), 3, 8);
  678. #else
  679. benchmark_winograd_fp16("WINOGRAD:ARMV7_F32_MK4_4x8:4:2",
  680. "WINOGRAD:AARCH32_F16_MK8_4X8:8:2", handle(), 3, 8);
  681. #endif
  682. }
  683. #endif
  684. void benchmark_winograd_nchw_vs_nchw44(const char* algo_name, Handle* handle) {
  685. using namespace conv_bias;
  686. using NLMode = param::ConvBias::NonlineMode;
  687. std::vector<conv_bias::TestArg> args_nchw44;
  688. std::vector<conv_bias::TestArg> args_nchw;
  689. auto pack = [&](size_t n, size_t oc, size_t ic, size_t h, size_t w,
  690. size_t group, NLMode nlmode) {
  691. param::ConvBias param;
  692. param.format = param::ConvBias::Format::NCHW44;
  693. param.stride_h = 1;
  694. param.stride_w = 1;
  695. param.pad_h = 1;
  696. param.pad_w = 1;
  697. param.nonlineMode = nlmode;
  698. if (group == 1) {
  699. param.sparse = param::ConvBias::Sparse::DENSE;
  700. args_nchw44.emplace_back(param, TensorShape{n, ic / 4, h, w, 4},
  701. TensorShape{oc / 4, ic / 4, 3, 3, 4, 4},
  702. TensorShape{});
  703. param.format = param::ConvBias::Format::NCHW;
  704. args_nchw.emplace_back(param, TensorShape{n, ic, h, w},
  705. TensorShape{oc, ic, 3, 3}, TensorShape{});
  706. } else {
  707. auto oc_per_group = oc / group;
  708. auto ic_per_group = ic / group;
  709. param.sparse = param::ConvBias::Sparse::GROUP;
  710. args_nchw44.emplace_back(param,
  711. TensorShape{n, ic_per_group / 4, h, w, 4},
  712. TensorShape{group, oc_per_group / 4,
  713. ic_per_group / 4, 3, 3, 4, 4},
  714. TensorShape{});
  715. param.format = param::ConvBias::Format::NCHW;
  716. args_nchw.emplace_back(
  717. param, TensorShape{n, ic, h, w},
  718. TensorShape{group, oc_per_group, ic_per_group, 3, 3},
  719. TensorShape{});
  720. }
  721. };
  722. std::vector<NLMode> nonlinemode = {NLMode::IDENTITY};
  723. for (auto nlmode : nonlinemode)
  724. for (size_t n : {1, 2})
  725. for (size_t group = 1; group <= 2; ++group) {
  726. pack(n, 512, 512, 15, 15, group, nlmode);
  727. pack(n, 512, 256, 15, 15, group, nlmode);
  728. pack(n, 256, 256, 29, 29, group, nlmode);
  729. pack(n, 256, 128, 29, 29, group, nlmode);
  730. pack(n, 128, 128, 57, 57, group, nlmode);
  731. pack(n, 128, 64, 57, 57, group, nlmode);
  732. pack(n, 24, 24, 224, 224, group, nlmode);
  733. pack(n, 64, 24, 123, 123, group, nlmode);
  734. pack(n, 64, 64, 56, 56, group, nlmode);
  735. pack(n, 128, 128, 28, 28, group, nlmode);
  736. pack(n, 256, 256, 14, 14, group, nlmode);
  737. pack(n, 512, 512, 7, 7, group, nlmode);
  738. }
  739. using namespace conv_bias;
  740. constexpr size_t RUN = 10;
  741. Benchmarker<ConvBias> benchmark_winograd_nchw(handle);
  742. benchmark_winograd_nchw.set_display(false);
  743. benchmark_winograd_nchw.set_times(RUN);
  744. Benchmarker<ConvBias> benchmark_winograd_nchw44(handle);
  745. benchmark_winograd_nchw44.set_display(false);
  746. benchmark_winograd_nchw44.set_times(RUN);
  747. std::string winograd_nchw_algo_name = ssprintf("WINOGRAD:%s", algo_name);
  748. std::string winograd_nchw44_algo_name =
  749. ssprintf("WINOGRAD_NCHW44:%s", algo_name);
  750. for (size_t i = 0; i < args_nchw.size(); ++i) {
  751. auto arg_nchw = args_nchw[i];
  752. auto arg_nchw44 = args_nchw44[i];
  753. TensorLayout dst_layout;
  754. auto opr = handle->create_operator<ConvBias>();
  755. opr->param() = arg_nchw.param;
  756. opr->deduce_layout({arg_nchw.src, dtype::Float32()},
  757. {arg_nchw.filter, dtype::Float32()},
  758. {arg_nchw.bias, dtype::Float32()}, {}, dst_layout);
  759. //! dst.nr_elems * IC * FH * FW * 2
  760. float computations = dst_layout.total_nr_elems() * arg_nchw.filter[1] *
  761. arg_nchw.filter[2] * arg_nchw.filter[3] * 2.0 /
  762. (1024 * 1024 * 1024) * 1e3;
  763. benchmark_winograd_nchw.set_param(arg_nchw.param);
  764. auto nchw_used = algo_benchmark<ConvBias>(
  765. benchmark_winograd_nchw,
  766. {arg_nchw.src, arg_nchw.filter, {}, {}, {}},
  767. winograd_nchw_algo_name.c_str()) /
  768. RUN;
  769. benchmark_winograd_nchw44.set_param(arg_nchw44.param);
  770. auto nchw44_used =
  771. algo_benchmark<ConvBias>(
  772. benchmark_winograd_nchw44,
  773. {arg_nchw44.src, arg_nchw44.filter, {}, {}, {}},
  774. winograd_nchw44_algo_name.c_str()) /
  775. RUN;
  776. printf("%s %s: nchw: %f ms %f Gflops nchw44: %f ms %f GFlops "
  777. "speedup: "
  778. "%f\n",
  779. arg_nchw.src.to_string().c_str(),
  780. arg_nchw.filter.to_string().c_str(), nchw_used,
  781. computations / nchw_used, nchw44_used,
  782. computations / nchw44_used, nchw_used / nchw44_used);
  783. }
  784. }
  785. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F23_MK4_NCHW_VS_NCHW44) {
  786. #if MEGDNN_AARCH64
  787. benchmark_winograd_nchw_vs_nchw44("AARCH64_F32_MK4_4x16:4:2", handle());
  788. #else
  789. benchmark_winograd_nchw_vs_nchw44("ARMV7_F32_MK4_4x8:4:2", handle());
  790. #endif
  791. }
  792. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F63_MK4_NCHW_VS_NCHW44) {
  793. #if MEGDNN_AARCH64
  794. benchmark_winograd_nchw_vs_nchw44("AARCH64_F32_MK4_4x16:4:6", handle());
  795. #else
  796. benchmark_winograd_nchw_vs_nchw44("ARMV7_F32_MK4_4x8:4:6", handle());
  797. #endif
  798. }
  799. TEST_F(ARM_COMMON, BENCHMARK_CONVBIAS_WINOGRAD_F23_8x8) {
  800. auto benchmark_winograd_quantized = [](const char* algo_name_fp32,
  801. const char* algo_name_quantized,
  802. Handle* handle, size_t kernel) {
  803. auto&& args = get_winograd_benchmark_args(kernel);
  804. using namespace conv_bias;
  805. constexpr size_t RUN = 10;
  806. Benchmarker<ConvBias> benchmark(handle);
  807. benchmark.set_display(false);
  808. benchmark.set_times(RUN);
  809. Benchmarker<ConvBias> benchmark_winograd(handle);
  810. benchmark_winograd.set_display(false).set_times(RUN);
  811. benchmark_winograd.set_dtype(0, dtype::QuantizedS8(2.5f))
  812. .set_dtype(1, dtype::QuantizedS8(2.5f))
  813. .set_dtype(2, dtype::QuantizedS32(6.25f))
  814. .set_dtype(4, dtype::QuantizedS8(60.25f));
  815. for (auto&& arg : args) {
  816. TensorLayout dst_layout;
  817. auto opr = handle->create_operator<ConvBias>();
  818. opr->param() = arg.param;
  819. opr->deduce_layout({arg.src, dtype::Float32()},
  820. {arg.filter, dtype::Float32()},
  821. {arg.bias, dtype::Float32()}, {}, dst_layout);
  822. //! dst.nr_elems * IC * FH * FW * 2
  823. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  824. arg.filter[2] * arg.filter[3] * 2.0 /
  825. (1024 * 1024 * 1024) * 1e3;
  826. benchmark.set_param(arg.param);
  827. auto used = algo_benchmark<ConvBias>(
  828. benchmark, {arg.src, arg.filter, {}, {}, {}},
  829. algo_name_fp32) /
  830. RUN;
  831. benchmark_winograd.set_param(arg.param);
  832. auto used_winograd =
  833. algo_benchmark<ConvBias>(benchmark_winograd,
  834. {arg.src, arg.filter, {}, {}, {}},
  835. algo_name_quantized) /
  836. RUN;
  837. printf("%s %s: normal: %f ms %f Gflops winograd: %f ms %f GFlops "
  838. "speedup: "
  839. "%f\n",
  840. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  841. used, computations / used, used_winograd,
  842. computations / used_winograd, used / used_winograd);
  843. }
  844. };
  845. #if MEGDNN_AARCH64
  846. benchmark_winograd_quantized("WINOGRAD:AARCH64_F32_MK4_4x16:4:2",
  847. "WINOGRAD:AARCH64_INT16X16X32_MK8_8X8:8:2",
  848. handle(), 3);
  849. #else
  850. benchmark_winograd_quantized("WINOGRAD:ARMV7_F32_MK4_4x8:4:2",
  851. "WINOGRAD:ARMV7_INT16X16X32_MK8_4X8:8:2",
  852. handle(), 3);
  853. #endif
  854. }
  855. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_INT8_STRIDE1) {
  856. // have to remove preferred restrict in usable func before run the benchmark
  857. using namespace conv_bias;
  858. std::vector<TestArg> args;
  859. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  860. size_t p, NonlineMode nonline_mode) {
  861. if (w + 2 * p < kernel || h + 2 * p < kernel)
  862. return;
  863. param::ConvBias param;
  864. param.stride_h = 1;
  865. param.stride_w = 1;
  866. param.pad_h = p;
  867. param.pad_w = p;
  868. param.nonlineMode = nonline_mode;
  869. //! channel bias
  870. args.emplace_back(param, TensorShape{2, ic, h, w},
  871. TensorShape{oc, ic, kernel, kernel},
  872. TensorShape{1, oc, 1, 1});
  873. };
  874. for (size_t kernel : {2, 3, 5, 7})
  875. for (size_t ic : {1, 8, 16, 32})
  876. for (size_t oc : {1, 8, 16, 32})
  877. for (size_t p : {1})
  878. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  879. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  880. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  881. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  882. }
  883. constexpr size_t RUN = 50;
  884. Benchmarker<ConvBias> benchmark0(handle());
  885. benchmark0.set_dtype(0, dtype::QuantizedS8(2.5f))
  886. .set_dtype(1, dtype::QuantizedS8(2.5f))
  887. .set_dtype(2, dtype::QuantizedS32(6.25f))
  888. .set_dtype(4, dtype::QuantizedS8(60.25f));
  889. benchmark0.set_display(false);
  890. benchmark0.set_times(RUN);
  891. benchmark0.set_before_exec_callback(
  892. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("S8STRD1"));
  893. Benchmarker<ConvBias> benchmark1(handle());
  894. benchmark1.set_dtype(0, dtype::QuantizedS8(2.5f))
  895. .set_dtype(1, dtype::QuantizedS8(2.5f))
  896. .set_dtype(2, dtype::QuantizedS32(6.25f))
  897. .set_dtype(4, dtype::QuantizedS8(60.25f));
  898. benchmark1.set_display(false);
  899. benchmark1.set_times(RUN);
  900. for (auto&& arg : args) {
  901. TensorLayout dst_layout;
  902. auto opr = handle()->create_operator<ConvBias>();
  903. opr->param() = arg.param;
  904. opr->deduce_layout({arg.src, dtype::Int8()},
  905. {arg.filter, dtype::Int8()},
  906. {arg.bias, dtype::Int32()}, {}, dst_layout);
  907. //! dst.nr_elems * IC * FH * FW * 2
  908. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  909. arg.filter[2] * arg.filter[3] * 2.0 /
  910. (1024 * 1024 * 1024) * 1e3;
  911. auto used0 = benchmark0.set_param(arg.param).exec(
  912. {arg.src, arg.filter, arg.bias, {}, {}}) /
  913. RUN;
  914. auto used1 = benchmark1.set_param(arg.param).exec(
  915. {arg.src, arg.filter, arg.bias, {}, {}}) /
  916. RUN;
  917. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  918. "speedup: %f\n",
  919. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  920. used0, computations / used0, used1, computations / used1,
  921. used1 / used0);
  922. }
  923. }
  924. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_INT8_STRIDE2) {
  925. // have to remove preferred restrict in usable func before run the benchmark
  926. using namespace conv_bias;
  927. std::vector<TestArg> args;
  928. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  929. size_t p, NonlineMode nonline_mode) {
  930. if (w + 2 * p < kernel || h + 2 * p < kernel)
  931. return;
  932. param::ConvBias param;
  933. param.stride_h = 2;
  934. param.stride_w = 2;
  935. param.pad_h = p;
  936. param.pad_w = p;
  937. param.nonlineMode = nonline_mode;
  938. //! channel bias
  939. args.emplace_back(param, TensorShape{2, ic, h, w},
  940. TensorShape{oc, ic, kernel, kernel},
  941. TensorShape{1, oc, 1, 1});
  942. };
  943. for (size_t kernel : {2, 3, 5, 7})
  944. for (size_t ic : {1, 8, 16, 32})
  945. for (size_t oc : {1, 8, 16, 32})
  946. for (size_t p : {1})
  947. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  948. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  949. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  950. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  951. }
  952. constexpr size_t RUN = 50;
  953. Benchmarker<ConvBias> benchmark0(handle());
  954. benchmark0.set_dtype(0, dtype::QuantizedS8(2.5f))
  955. .set_dtype(1, dtype::QuantizedS8(2.5f))
  956. .set_dtype(2, dtype::QuantizedS32(6.25f))
  957. .set_dtype(4, dtype::QuantizedS8(60.25f));
  958. benchmark0.set_display(false);
  959. benchmark0.set_times(RUN);
  960. benchmark0.set_before_exec_callback(
  961. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("S8STRD2"));
  962. Benchmarker<ConvBias> benchmark1(handle());
  963. benchmark1.set_dtype(0, dtype::QuantizedS8(2.5f))
  964. .set_dtype(1, dtype::QuantizedS8(2.5f))
  965. .set_dtype(2, dtype::QuantizedS32(6.25f))
  966. .set_dtype(4, dtype::QuantizedS8(60.25f));
  967. benchmark1.set_display(false);
  968. benchmark1.set_times(RUN);
  969. for (auto&& arg : args) {
  970. TensorLayout dst_layout;
  971. auto opr = handle()->create_operator<ConvBias>();
  972. opr->param() = arg.param;
  973. opr->deduce_layout({arg.src, dtype::Int8()},
  974. {arg.filter, dtype::Int8()},
  975. {arg.bias, dtype::Int32()}, {}, dst_layout);
  976. //! dst.nr_elems * IC * FH * FW * 2
  977. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  978. arg.filter[2] * arg.filter[3] * 2.0 /
  979. (1024 * 1024 * 1024) * 1e3;
  980. auto used0 = benchmark0.set_param(arg.param).exec(
  981. {arg.src, arg.filter, arg.bias, {}, {}}) /
  982. RUN;
  983. auto used1 = benchmark1.set_param(arg.param).exec(
  984. {arg.src, arg.filter, arg.bias, {}, {}}) /
  985. RUN;
  986. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  987. "speedup: %f\n",
  988. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  989. used0, computations / used0, used1, computations / used1,
  990. used1 / used0);
  991. }
  992. }
  993. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_QUINT8_STRIDE1) {
  994. // have to remove preferred restrict in usable func before run the benchmark
  995. using namespace conv_bias;
  996. std::vector<TestArg> args;
  997. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  998. size_t p, NonlineMode nonline_mode) {
  999. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1000. return;
  1001. param::ConvBias param;
  1002. param.stride_h = 1;
  1003. param.stride_w = 1;
  1004. param.pad_h = p;
  1005. param.pad_w = p;
  1006. param.nonlineMode = nonline_mode;
  1007. //! channel bias
  1008. args.emplace_back(param, TensorShape{2, ic, h, w},
  1009. TensorShape{oc, ic, kernel, kernel},
  1010. TensorShape{1, oc, 1, 1});
  1011. };
  1012. for (size_t kernel : {2, 3, 5, 7})
  1013. for (size_t ic : {1, 8, 16, 32})
  1014. for (size_t oc : {1, 8, 16, 32})
  1015. for (size_t p : {1})
  1016. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1017. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1018. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1019. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1020. }
  1021. constexpr size_t RUN = 50;
  1022. Benchmarker<ConvBias> benchmark0(handle());
  1023. benchmark0
  1024. .set_dtype(0,
  1025. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1026. .set_dtype(1,
  1027. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1028. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1029. .set_dtype(4,
  1030. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1031. benchmark0.set_display(false);
  1032. benchmark0.set_times(RUN);
  1033. benchmark0.set_before_exec_callback(
  1034. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("QU8STRD1"));
  1035. Benchmarker<ConvBias> benchmark1(handle());
  1036. benchmark1
  1037. .set_dtype(0,
  1038. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1039. .set_dtype(1,
  1040. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1041. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1042. .set_dtype(4,
  1043. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1044. benchmark1.set_display(false);
  1045. benchmark1.set_times(RUN);
  1046. for (auto&& arg : args) {
  1047. TensorLayout dst_layout;
  1048. auto opr = handle()->create_operator<ConvBias>();
  1049. opr->param() = arg.param;
  1050. opr->deduce_layout({arg.src, dtype::Int8()},
  1051. {arg.filter, dtype::Int8()},
  1052. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1053. //! dst.nr_elems * IC * FH * FW * 2
  1054. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1055. arg.filter[2] * arg.filter[3] * 2.0 /
  1056. (1024 * 1024 * 1024) * 1e3;
  1057. auto used0 = benchmark0.set_param(arg.param).exec(
  1058. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1059. RUN;
  1060. auto used1 = benchmark1.set_param(arg.param).exec(
  1061. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1062. RUN;
  1063. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1064. "speedup: %f\n",
  1065. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1066. used0, computations / used0, used1, computations / used1,
  1067. used1 / used0);
  1068. }
  1069. }
  1070. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_QUINT8_STRIDE2) {
  1071. // have to remove preferred restrict in usable func before run the benchmark
  1072. using namespace conv_bias;
  1073. std::vector<TestArg> args;
  1074. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1075. size_t p, NonlineMode nonline_mode) {
  1076. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1077. return;
  1078. param::ConvBias param;
  1079. param.stride_h = 2;
  1080. param.stride_w = 2;
  1081. param.pad_h = p;
  1082. param.pad_w = p;
  1083. param.nonlineMode = nonline_mode;
  1084. //! channel bias
  1085. args.emplace_back(param, TensorShape{2, ic, h, w},
  1086. TensorShape{oc, ic, kernel, kernel},
  1087. TensorShape{1, oc, 1, 1});
  1088. };
  1089. for (size_t kernel : {2, 3, 5, 7})
  1090. for (size_t ic : {1, 8, 16, 32})
  1091. for (size_t oc : {1, 8, 16, 32})
  1092. for (size_t p : {1})
  1093. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1094. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1095. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1096. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1097. }
  1098. constexpr size_t RUN = 50;
  1099. Benchmarker<ConvBias> benchmark0(handle());
  1100. benchmark0
  1101. .set_dtype(0,
  1102. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1103. .set_dtype(1,
  1104. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1105. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1106. .set_dtype(4,
  1107. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1108. benchmark0.set_display(false);
  1109. benchmark0.set_times(RUN);
  1110. benchmark0.set_before_exec_callback(
  1111. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("QU8STRD2"));
  1112. Benchmarker<ConvBias> benchmark1(handle());
  1113. benchmark1
  1114. .set_dtype(0,
  1115. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1116. .set_dtype(1,
  1117. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1118. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1119. .set_dtype(4,
  1120. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1121. benchmark1.set_display(false);
  1122. benchmark1.set_times(RUN);
  1123. for (auto&& arg : args) {
  1124. TensorLayout dst_layout;
  1125. auto opr = handle()->create_operator<ConvBias>();
  1126. opr->param() = arg.param;
  1127. opr->deduce_layout({arg.src, dtype::Int8()},
  1128. {arg.filter, dtype::Int8()},
  1129. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1130. //! dst.nr_elems * IC * FH * FW * 2
  1131. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1132. arg.filter[2] * arg.filter[3] * 2.0 /
  1133. (1024 * 1024 * 1024) * 1e3;
  1134. auto used0 = benchmark0.set_param(arg.param).exec(
  1135. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1136. RUN;
  1137. auto used1 = benchmark1.set_param(arg.param).exec(
  1138. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1139. RUN;
  1140. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1141. "speedup: %f\n",
  1142. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1143. used0, computations / used0, used1, computations / used1,
  1144. used1 / used0);
  1145. }
  1146. }
  1147. TEST_F(ARM_COMMON, BENCHMARK_CHANNEL_WISE_F32_STRIDE1_NCHW44) {
  1148. // have to remove preferred restrict in usable func before run the benchmark
  1149. using namespace conv_bias;
  1150. param::ConvBias param;
  1151. param.stride_h = 1;
  1152. param.stride_w = 1;
  1153. param.pad_h = 1;
  1154. param.pad_w = 1;
  1155. param.nonlineMode = NonlineMode::RELU;
  1156. param.sparse = param::ConvBias::Sparse::GROUP;
  1157. constexpr size_t RUN = 50;
  1158. Benchmarker<ConvBias> benchmark0(handle());
  1159. benchmark0.set_display(false);
  1160. benchmark0.set_param(param);
  1161. benchmark0.set_times(RUN);
  1162. benchmark0.set_before_exec_callback(
  1163. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1164. "F32STRD1_LARGE_GROUP"));
  1165. auto opr = handle()->create_operator<ConvBias>();
  1166. opr->param() = param;
  1167. param.format = param::ConvBias::Format::NCHW44;
  1168. Benchmarker<ConvBias> benchmark1(handle());
  1169. benchmark1.set_display(false);
  1170. benchmark1.set_param(param);
  1171. benchmark1.set_times(RUN);
  1172. benchmark1.set_before_exec_callback(
  1173. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1174. "F32_CHANNEL_WISE_NCHW44"));
  1175. auto run = [&](size_t group, size_t w, size_t h, size_t kernel) {
  1176. TensorLayout dst_layout;
  1177. opr->deduce_layout({{1, group * 4, h, w}, dtype::Int8()},
  1178. {{group * 4, 1, 1, kernel, kernel}, dtype::Int8()},
  1179. {{1, group * 4, 1, 1}, dtype::Int32()}, {},
  1180. dst_layout);
  1181. //! dst.nr_elems * IC * FH * FW * 2
  1182. float computations = dst_layout.total_nr_elems() * kernel * kernel *
  1183. 2.0 / (1024 * 1024 * 1024) * 1e3;
  1184. auto used0 = benchmark0.exec({{1, group * 4, h, w},
  1185. {group * 4, 1, 1, kernel, kernel},
  1186. {1, group * 4, 1, 1},
  1187. {},
  1188. {}}) /
  1189. RUN;
  1190. auto used1 = benchmark1.exec({{1, group, h, w, 4},
  1191. {group, 1, 1, kernel, kernel, 4},
  1192. {1, group, 1, 1, 4},
  1193. {},
  1194. {}}) /
  1195. RUN;
  1196. printf("group/h/w/kernel:%zu,%zu,%zu,%zu: nchw: %f ms %f Gflops "
  1197. "nchw44: "
  1198. "%f ms %f GFlops "
  1199. "speedup: %f\n",
  1200. group, h, w, kernel, used0, computations / used0, used1,
  1201. computations / used1, used0 / used1);
  1202. };
  1203. for (size_t group : {8, 16, 32, 64}) {
  1204. for (size_t kerenl : {2, 3, 5}) {
  1205. run(group, 112, 112, kerenl);
  1206. run(group, 56, 56, kerenl);
  1207. run(group, 48, 48, kerenl);
  1208. run(group, 28, 28, kerenl);
  1209. run(group, 14, 14, kerenl);
  1210. }
  1211. }
  1212. run(8, 112, 112, 3);
  1213. run(32, 56, 56, 3);
  1214. run(64, 28, 28, 3);
  1215. run(128, 14, 14, 3);
  1216. }
  1217. TEST_F(ARM_COMMON, BENCHMARK_CHANNEL_WISE_F32_STRIDE2_NCHW44) {
  1218. // have to remove preferred restrict in usable func before run the benchmark
  1219. using namespace conv_bias;
  1220. param::ConvBias param;
  1221. param.stride_h = 2;
  1222. param.stride_w = 2;
  1223. param.pad_h = 1;
  1224. param.pad_w = 1;
  1225. param.nonlineMode = NonlineMode::RELU;
  1226. param.sparse = param::ConvBias::Sparse::GROUP;
  1227. constexpr size_t RUN = 50;
  1228. Benchmarker<ConvBias> benchmark0(handle());
  1229. benchmark0.set_display(false);
  1230. benchmark0.set_param(param);
  1231. benchmark0.set_times(RUN);
  1232. benchmark0.set_before_exec_callback(
  1233. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1234. "F32STRD2_LARGE_GROUP"));
  1235. auto opr = handle()->create_operator<ConvBias>();
  1236. opr->param() = param;
  1237. param.format = param::ConvBias::Format::NCHW44;
  1238. Benchmarker<ConvBias> benchmark1(handle());
  1239. benchmark1.set_display(false);
  1240. benchmark1.set_param(param);
  1241. benchmark1.set_times(RUN);
  1242. benchmark1.set_before_exec_callback(
  1243. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1244. "F32_CHANNEL_WISE_NCHW44"));
  1245. auto run = [&](size_t group, size_t w, size_t h, size_t kernel) {
  1246. TensorLayout dst_layout;
  1247. opr->deduce_layout({{1, group * 4, h, w}, dtype::Int8()},
  1248. {{group * 4, 1, 1, kernel, kernel}, dtype::Int8()},
  1249. {{1, group * 4, 1, 1}, dtype::Int32()}, {},
  1250. dst_layout);
  1251. //! dst.nr_elems * IC * FH * FW * 2
  1252. float computations = dst_layout.total_nr_elems() * kernel * kernel *
  1253. 2.0 / (1024 * 1024 * 1024) * 1e3;
  1254. auto used0 = benchmark0.exec({{1, group * 4, h, w},
  1255. {group * 4, 1, 1, kernel, kernel},
  1256. {1, group * 4, 1, 1},
  1257. {},
  1258. {}}) /
  1259. RUN;
  1260. auto used1 = benchmark1.exec({{1, group, h, w, 4},
  1261. {group, 1, 1, kernel, kernel, 4},
  1262. {1, group, 1, 1, 4},
  1263. {},
  1264. {}}) /
  1265. RUN;
  1266. printf("group/h/w/kernel:%zu,%zu,%zu,%zu: nchw: %f ms %f Gflops "
  1267. "nchw44: "
  1268. "%f ms %f GFlops "
  1269. "speedup: %f\n",
  1270. group, h, w, kernel, used0, computations / used0, used1,
  1271. computations / used1, used0 / used1);
  1272. };
  1273. for (size_t group : {8, 16, 32, 64}) {
  1274. for (size_t kerenl : {2, 3, 5}) {
  1275. run(group, 112, 112, kerenl);
  1276. run(group, 56, 56, kerenl);
  1277. run(group, 48, 48, kerenl);
  1278. run(group, 28, 28, kerenl);
  1279. run(group, 14, 14, kerenl);
  1280. }
  1281. }
  1282. run(8, 112, 112, 3);
  1283. run(32, 56, 56, 3);
  1284. run(64, 28, 28, 3);
  1285. run(128, 14, 14, 3);
  1286. }
  1287. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_QINT8_STRIDE1_NCHW44) {
  1288. // have to remove preferred restrict in usable func before run the benchmark
  1289. using namespace conv_bias;
  1290. param::ConvBias param;
  1291. param.stride_h = 1;
  1292. param.stride_w = 1;
  1293. param.pad_h = 1;
  1294. param.pad_w = 1;
  1295. param.nonlineMode = NonlineMode::RELU;
  1296. param.sparse = param::ConvBias::Sparse::GROUP;
  1297. constexpr size_t RUN = 50;
  1298. Benchmarker<ConvBias> benchmark0(handle());
  1299. benchmark0.set_dtype(0, dtype::QuantizedS8(0.2f))
  1300. .set_dtype(1, dtype::QuantizedS8(0.2f))
  1301. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1302. .set_dtype(4, dtype::QuantizedS8(1.4f));
  1303. benchmark0.set_display(false);
  1304. benchmark0.set_param(param);
  1305. benchmark0.set_times(RUN);
  1306. benchmark0.set_before_exec_callback(
  1307. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1308. "S8STRD1_LARGE_GROUP"));
  1309. auto opr = handle()->create_operator<ConvBias>();
  1310. opr->param() = param;
  1311. param.format = param::ConvBias::Format::NCHW44;
  1312. Benchmarker<ConvBias> benchmark1(handle());
  1313. benchmark1.set_dtype(0, dtype::QuantizedS8(0.2f))
  1314. .set_dtype(1, dtype::QuantizedS8(0.2f))
  1315. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1316. .set_dtype(4, dtype::QuantizedS8(1.4f));
  1317. benchmark1.set_display(false);
  1318. benchmark1.set_param(param);
  1319. benchmark1.set_times(RUN);
  1320. benchmark1.set_before_exec_callback(
  1321. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  1322. "S8_CHAN_WISE_STRD1_NCHW44"));
  1323. auto run = [&](size_t group, size_t w, size_t h, size_t kernel) {
  1324. TensorLayout dst_layout;
  1325. opr->deduce_layout({{1, group * 4, h, w}, dtype::Int8()},
  1326. {{group * 4, 1, 1, kernel, kernel}, dtype::Int8()},
  1327. {{1, group * 4, 1, 1}, dtype::Int32()}, {},
  1328. dst_layout);
  1329. //! dst.nr_elems * IC * FH * FW * 2
  1330. float computations = dst_layout.total_nr_elems() * kernel * kernel *
  1331. 2.0 / (1024 * 1024 * 1024) * 1e3;
  1332. auto used0 = benchmark0.exec({{1, group * 4, h, w},
  1333. {group * 4, 1, 1, kernel, kernel},
  1334. {1, group * 4, 1, 1},
  1335. {},
  1336. {}}) /
  1337. RUN;
  1338. auto used1 = benchmark1.exec({{1, group, h, w, 4},
  1339. {group, 1, 1, kernel, kernel, 4},
  1340. {1, group, 1, 1, 4},
  1341. {},
  1342. {}}) /
  1343. RUN;
  1344. printf("group/h/w/kernel:%zu,%zu,%zu,%zu: nchw: %f ms %f Gflops "
  1345. "nchw44: "
  1346. "%f ms %f GFlops "
  1347. "speedup: %f\n",
  1348. group, h, w, kernel, used0, computations / used0, used1,
  1349. computations / used1, used0 / used1);
  1350. };
  1351. for (size_t group : {8, 16, 32, 64, 128}) {
  1352. for (size_t kerenl : {2, 3, 5}) {
  1353. run(group, 112, 112, kerenl);
  1354. run(group, 56, 56, kerenl);
  1355. run(group, 48, 48, kerenl);
  1356. run(group, 28, 28, kerenl);
  1357. run(group, 14, 14, kerenl);
  1358. }
  1359. }
  1360. }
  1361. #endif
  1362. #if __ARM_FEATURE_DOTPROD
  1363. #if MEGDNN_WITH_BENCHMARK
  1364. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_INT8_STRIDE1_WITHDOTPROD) {
  1365. // have to remove preferred restrict in usable func before run the benchmark
  1366. using namespace conv_bias;
  1367. std::vector<TestArg> args;
  1368. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1369. size_t p, NonlineMode nonline_mode) {
  1370. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1371. return;
  1372. param::ConvBias param;
  1373. param.stride_h = 1;
  1374. param.stride_w = 1;
  1375. param.pad_h = p;
  1376. param.pad_w = p;
  1377. param.nonlineMode = nonline_mode;
  1378. //! channel bias
  1379. args.emplace_back(param, TensorShape{2, ic, h, w},
  1380. TensorShape{oc, ic, kernel, kernel},
  1381. TensorShape{1, oc, 1, 1});
  1382. };
  1383. for (size_t kernel : {2, 3, 5, 7})
  1384. for (size_t ic : {1, 8, 16, 32})
  1385. for (size_t oc : {1, 8, 16, 32})
  1386. for (size_t p : {1})
  1387. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1388. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1389. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1390. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1391. }
  1392. constexpr size_t RUN = 50;
  1393. Benchmarker<ConvBias> benchmark0(handle());
  1394. benchmark0.set_dtype(0, dtype::QuantizedS8(2.5f))
  1395. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1396. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1397. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1398. benchmark0.set_display(false);
  1399. benchmark0.set_times(RUN);
  1400. benchmark0.set_before_exec_callback(
  1401. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("ARMDOTS8STRD1"));
  1402. Benchmarker<ConvBias> benchmark1(handle());
  1403. benchmark1.set_dtype(0, dtype::QuantizedS8(2.5f))
  1404. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1405. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1406. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1407. benchmark1.set_display(false);
  1408. benchmark1.set_times(RUN);
  1409. for (auto&& arg : args) {
  1410. TensorLayout dst_layout;
  1411. auto opr = handle()->create_operator<ConvBias>();
  1412. opr->param() = arg.param;
  1413. opr->deduce_layout({arg.src, dtype::Int8()},
  1414. {arg.filter, dtype::Int8()},
  1415. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1416. //! dst.nr_elems * IC * FH * FW * 2
  1417. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1418. arg.filter[2] * arg.filter[3] * 2.0 /
  1419. (1024 * 1024 * 1024) * 1e3;
  1420. auto used0 = benchmark0.set_param(arg.param).exec(
  1421. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1422. RUN;
  1423. auto used1 = benchmark1.set_param(arg.param).exec(
  1424. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1425. RUN;
  1426. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1427. "speedup: %f\n",
  1428. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1429. used0, computations / used0, used1, computations / used1,
  1430. used1 / used0);
  1431. }
  1432. }
  1433. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_INT8_STRIDE2_WITHDOTPROD) {
  1434. // have to remove preferred restrict in usable func before run the benchmark
  1435. using namespace conv_bias;
  1436. std::vector<TestArg> args;
  1437. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1438. size_t p, NonlineMode nonline_mode) {
  1439. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1440. return;
  1441. param::ConvBias param;
  1442. param.stride_h = 2;
  1443. param.stride_w = 2;
  1444. param.pad_h = p;
  1445. param.pad_w = p;
  1446. param.nonlineMode = nonline_mode;
  1447. //! channel bias
  1448. args.emplace_back(param, TensorShape{2, ic, h, w},
  1449. TensorShape{oc, ic, kernel, kernel},
  1450. TensorShape{1, oc, 1, 1});
  1451. };
  1452. for (size_t kernel : {2, 3, 5, 7})
  1453. for (size_t ic : {1, 8, 16, 32})
  1454. for (size_t oc : {1, 8, 16, 32})
  1455. for (size_t p : {1})
  1456. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1457. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1458. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1459. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1460. }
  1461. constexpr size_t RUN = 50;
  1462. Benchmarker<ConvBias> benchmark0(handle());
  1463. benchmark0.set_dtype(0, dtype::QuantizedS8(2.5f))
  1464. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1465. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1466. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1467. benchmark0.set_display(false);
  1468. benchmark0.set_times(RUN);
  1469. benchmark0.set_before_exec_callback(
  1470. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("ARMDOTS8STRD2"));
  1471. Benchmarker<ConvBias> benchmark1(handle());
  1472. benchmark1.set_dtype(0, dtype::QuantizedS8(2.5f))
  1473. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1474. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1475. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1476. benchmark1.set_display(false);
  1477. benchmark1.set_times(RUN);
  1478. for (auto&& arg : args) {
  1479. TensorLayout dst_layout;
  1480. auto opr = handle()->create_operator<ConvBias>();
  1481. opr->param() = arg.param;
  1482. opr->deduce_layout({arg.src, dtype::Int8()},
  1483. {arg.filter, dtype::Int8()},
  1484. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1485. //! dst.nr_elems * IC * FH * FW * 2
  1486. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1487. arg.filter[2] * arg.filter[3] * 2.0 /
  1488. (1024 * 1024 * 1024) * 1e3;
  1489. auto used0 = benchmark0.set_param(arg.param).exec(
  1490. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1491. RUN;
  1492. auto used1 = benchmark1.set_param(arg.param).exec(
  1493. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1494. RUN;
  1495. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1496. "speedup: %f\n",
  1497. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1498. used0, computations / used0, used1, computations / used1,
  1499. used1 / used0);
  1500. }
  1501. }
  1502. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_QUINT8_STRIDE1_WITHDOTPROD) {
  1503. // have to remove preferred restrict in usable func before run the benchmark
  1504. using namespace conv_bias;
  1505. std::vector<TestArg> args;
  1506. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1507. size_t p, NonlineMode nonline_mode) {
  1508. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1509. return;
  1510. param::ConvBias param;
  1511. param.stride_h = 1;
  1512. param.stride_w = 1;
  1513. param.pad_h = p;
  1514. param.pad_w = p;
  1515. param.nonlineMode = nonline_mode;
  1516. //! channel bias
  1517. args.emplace_back(param, TensorShape{2, ic, h, w},
  1518. TensorShape{oc, ic, kernel, kernel},
  1519. TensorShape{1, oc, 1, 1});
  1520. };
  1521. // clang-format off
  1522. for (size_t kernel : {2, 3, 5, 7})
  1523. for (size_t ic : {1, 8, 16, 32})
  1524. for (size_t oc : {1, 8, 16, 32})
  1525. for (size_t p : {1})
  1526. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1527. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1528. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1529. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1530. }
  1531. // clang-format on
  1532. constexpr size_t RUN = 50;
  1533. Benchmarker<ConvBias> benchmark0(handle());
  1534. benchmark0
  1535. .set_dtype(0,
  1536. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1537. .set_dtype(1,
  1538. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1539. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1540. .set_dtype(4,
  1541. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1542. benchmark0.set_display(false);
  1543. benchmark0.set_times(RUN);
  1544. benchmark0.set_before_exec_callback(
  1545. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("ARMDOTU8STRD1"));
  1546. Benchmarker<ConvBias> benchmark1(handle());
  1547. benchmark1
  1548. .set_dtype(0,
  1549. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1550. .set_dtype(1,
  1551. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1552. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1553. .set_dtype(4,
  1554. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1555. benchmark1.set_display(false);
  1556. benchmark1.set_times(RUN);
  1557. for (auto&& arg : args) {
  1558. TensorLayout dst_layout;
  1559. auto opr = handle()->create_operator<ConvBias>();
  1560. opr->param() = arg.param;
  1561. opr->deduce_layout({arg.src, dtype::Int8()},
  1562. {arg.filter, dtype::Int8()},
  1563. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1564. //! dst.nr_elems * IC * FH * FW * 2
  1565. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1566. arg.filter[2] * arg.filter[3] * 2.0 /
  1567. (1024 * 1024 * 1024) * 1e3;
  1568. auto used0 = benchmark0.set_param(arg.param).exec(
  1569. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1570. RUN;
  1571. auto used1 = benchmark1.set_param(arg.param).exec(
  1572. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1573. RUN;
  1574. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1575. "speedup: %f\n",
  1576. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1577. used0, computations / used0, used1, computations / used1,
  1578. used1 / used0);
  1579. }
  1580. }
  1581. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_QUINT8_STRIDE2_WITHDOTPROD) {
  1582. // have to remove preferred restrict in usable func before run the benchmark
  1583. using namespace conv_bias;
  1584. std::vector<TestArg> args;
  1585. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1586. size_t p, NonlineMode nonline_mode) {
  1587. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1588. return;
  1589. param::ConvBias param;
  1590. param.stride_h = 2;
  1591. param.stride_w = 2;
  1592. param.pad_h = p;
  1593. param.pad_w = p;
  1594. param.nonlineMode = nonline_mode;
  1595. //! channel bias
  1596. args.emplace_back(param, TensorShape{2, ic, h, w},
  1597. TensorShape{oc, ic, kernel, kernel},
  1598. TensorShape{1, oc, 1, 1});
  1599. };
  1600. // clang-format off
  1601. for (size_t kernel : {2, 3, 5, 7})
  1602. for (size_t ic : {1, 8, 16, 32})
  1603. for (size_t oc : {1, 8, 16, 32})
  1604. for (size_t p : {1})
  1605. for (NonlineMode nonline_mode : {NonlineMode::RELU}) {
  1606. run(oc, ic, 56, 56, kernel, p, nonline_mode);
  1607. run(oc, ic, 128, 128, kernel, p, nonline_mode);
  1608. run(oc, ic, 256, 256, kernel, p, nonline_mode);
  1609. }
  1610. // clang-format on
  1611. constexpr size_t RUN = 50;
  1612. Benchmarker<ConvBias> benchmark0(handle());
  1613. benchmark0
  1614. .set_dtype(0,
  1615. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1616. .set_dtype(1,
  1617. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1618. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1619. .set_dtype(4,
  1620. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1621. benchmark0.set_display(false);
  1622. benchmark0.set_times(RUN);
  1623. benchmark0.set_before_exec_callback(
  1624. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("ARMDOTU8STRD2"));
  1625. Benchmarker<ConvBias> benchmark1(handle());
  1626. benchmark1
  1627. .set_dtype(0,
  1628. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(100)))
  1629. .set_dtype(1,
  1630. dtype::Quantized8Asymm(0.2f, static_cast<uint8_t>(120)))
  1631. .set_dtype(2, dtype::QuantizedS32(0.04f))
  1632. .set_dtype(4,
  1633. dtype::Quantized8Asymm(1.4f, static_cast<uint8_t>(110)));
  1634. benchmark1.set_display(false);
  1635. benchmark1.set_times(RUN);
  1636. for (auto&& arg : args) {
  1637. TensorLayout dst_layout;
  1638. auto opr = handle()->create_operator<ConvBias>();
  1639. opr->param() = arg.param;
  1640. opr->deduce_layout({arg.src, dtype::Int8()},
  1641. {arg.filter, dtype::Int8()},
  1642. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1643. //! dst.nr_elems * IC * FH * FW * 2
  1644. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1645. arg.filter[2] * arg.filter[3] * 2.0 /
  1646. (1024 * 1024 * 1024) * 1e3;
  1647. auto used0 = benchmark0.set_param(arg.param).exec(
  1648. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1649. RUN;
  1650. auto used1 = benchmark1.set_param(arg.param).exec(
  1651. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1652. RUN;
  1653. printf("%s %s: conv_bias: %f ms %f Gflops conv_elem: %f ms %f GFlops "
  1654. "speedup: %f\n",
  1655. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1656. used0, computations / used0, used1, computations / used1,
  1657. used1 / used0);
  1658. }
  1659. }
  1660. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_INT8_STRIDE1_WITHDOTPROD_NCHW44_DOT) {
  1661. using namespace conv_bias;
  1662. std::vector<TestArg> args;
  1663. auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel,
  1664. size_t p, size_t stride, NonlineMode nonline_mode) {
  1665. if (w + 2 * p < kernel || h + 2 * p < kernel)
  1666. return;
  1667. param::ConvBias param;
  1668. param.stride_h = stride;
  1669. param.stride_w = stride;
  1670. param.pad_h = p;
  1671. param.pad_w = p;
  1672. param.nonlineMode = nonline_mode;
  1673. param.format = param::ConvBias::Format::NCHW44_DOT;
  1674. //! channel bias
  1675. args.emplace_back(param, TensorShape{1, ic/4, h, w, 4},
  1676. TensorShape{oc/4, ic/4, kernel, kernel, 4, 4},
  1677. TensorShape{1, oc/4, 1, 1, 4});
  1678. };
  1679. for (size_t stride : {1, 2})
  1680. for (size_t kernel : {2, 3, 5, 7})
  1681. for(size_t oc : {64})
  1682. for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
  1683. run(oc, oc, 56, 56, kernel, kernel / 2, stride, nonline_mode);
  1684. }
  1685. constexpr size_t RUN = 50;
  1686. Benchmarker<ConvBias> benchmark0(handle());
  1687. benchmark0.set_dtype(0, dtype::QuantizedS8(2.5f))
  1688. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1689. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1690. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1691. benchmark0.set_display(false);
  1692. benchmark0.set_times(RUN);
  1693. benchmark0.set_before_exec_callback(
  1694. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("ARMDOTS8DIRECT_NCHW44"));
  1695. Benchmarker<ConvBias> benchmark1(handle());
  1696. benchmark1.set_dtype(0, dtype::QuantizedS8(2.5f))
  1697. .set_dtype(1, dtype::QuantizedS8(2.5f))
  1698. .set_dtype(2, dtype::QuantizedS32(6.25f))
  1699. .set_dtype(4, dtype::QuantizedS8(60.25f));
  1700. benchmark1.set_display(false);
  1701. benchmark1.set_times(RUN);
  1702. for (auto&& arg : args) {
  1703. TensorLayout dst_layout;
  1704. auto opr = handle()->create_operator<ConvBias>();
  1705. opr->param() = arg.param;
  1706. opr->deduce_layout({arg.src, dtype::Int8()},
  1707. {arg.filter, dtype::Int8()},
  1708. {arg.bias, dtype::Int32()}, {}, dst_layout);
  1709. //! dst.nr_elems * IC * FH * FW * 2
  1710. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  1711. arg.filter[2] * arg.filter[3] * 8.0 /
  1712. (1024 * 1024 * 1024) * 1e3;
  1713. auto used0 = benchmark0.set_param(arg.param).exec(
  1714. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1715. RUN;
  1716. auto used1 = benchmark1.set_param(arg.param).exec(
  1717. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1718. RUN;
  1719. printf("%s %s: Direct use: %f ms %f Gflops normal: %f ms %f GFlops "
  1720. "speedup: %f\n",
  1721. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1722. used0, computations / used0, used1, computations / used1,
  1723. used1 / used0);
  1724. }
  1725. }
  1726. #endif
  1727. #endif
  1728. /*====================== BENCHMARK CONV1X1 ===========================*/
  1729. #if MEGDNN_WITH_BENCHMARK
  1730. namespace {
  1731. std::vector<conv_bias::TestArg> get_conv_bias_1x1_benchmark_args(
  1732. size_t pack_size = 1) {
  1733. using namespace conv_bias;
  1734. std::vector<TestArg> args;
  1735. param::ConvBias param;
  1736. param.stride_h = 1;
  1737. param.stride_w = 1;
  1738. param.pad_h = 0;
  1739. param.pad_w = 0;
  1740. param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1741. auto bench_case = [&](size_t OC, size_t IC, size_t H, size_t W) {
  1742. if (pack_size == 1)
  1743. args.emplace_back(param, TensorShape{1, IC, H, W},
  1744. TensorShape{OC, IC, 1, 1}, TensorShape{});
  1745. else {
  1746. if (pack_size == 4)
  1747. param.format = param::ConvBias::Format::NCHW44;
  1748. args.emplace_back(param,
  1749. TensorShape{1, IC / pack_size, H, W, pack_size},
  1750. TensorShape{OC / pack_size, IC / pack_size, 1, 1,
  1751. pack_size, pack_size},
  1752. TensorShape{});
  1753. }
  1754. };
  1755. //! MobileNetV1
  1756. bench_case(64, 32, 112, 112);
  1757. bench_case(128, 64, 56, 56);
  1758. bench_case(128, 128, 56, 56);
  1759. bench_case(256, 128, 28, 28);
  1760. bench_case(256, 256, 28, 28);
  1761. bench_case(512, 256, 14, 14);
  1762. bench_case(512, 512, 14, 14);
  1763. bench_case(1024, 512, 7, 7);
  1764. bench_case(1024, 1024, 7, 7);
  1765. //! MobileNetV2
  1766. bench_case(16, 32, 112, 112);
  1767. bench_case(96, 16, 112, 112);
  1768. bench_case(144, 24, 56, 56);
  1769. bench_case(192, 32, 28, 28);
  1770. bench_case(384, 64, 28, 28);
  1771. bench_case(576, 96, 14, 14);
  1772. bench_case(960, 160, 7, 7);
  1773. bench_case(320, 960, 7, 7);
  1774. bench_case(1280, 320, 7, 7);
  1775. //! MobileNetV3-Large
  1776. bench_case(64, 16, 112, 112);
  1777. bench_case(72, 24, 56, 56);
  1778. bench_case(120, 40, 28, 28);
  1779. bench_case(240, 40, 28, 28);
  1780. bench_case(200, 80, 14, 14);
  1781. bench_case(184, 80, 14, 14);
  1782. bench_case(480, 80, 14, 14);
  1783. bench_case(672, 112, 14, 14);
  1784. //! MobileNetV3-Small
  1785. bench_case(72, 16, 56, 56);
  1786. bench_case(88, 24, 28, 28);
  1787. bench_case(96, 24, 28, 28);
  1788. bench_case(240, 40, 14, 14);
  1789. bench_case(120, 40, 14, 14);
  1790. bench_case(144, 48, 14, 14);
  1791. bench_case(288, 48, 14, 14);
  1792. bench_case(576, 96, 7, 7);
  1793. //! resnet50
  1794. bench_case(256, 64, 56, 56);
  1795. bench_case(512, 128, 28, 28);
  1796. bench_case(1024, 256, 14, 14);
  1797. bench_case(2048, 512, 7, 7);
  1798. return args;
  1799. }
  1800. void benchmark_conv1x1(const char* matmul_algo_name, Handle* handle,
  1801. DType stype, DType matmul_dtype, DType bias_type,
  1802. DType conv_dtype) {
  1803. using namespace conv_bias;
  1804. std::vector<TestArg> conv_bias_1x1_args =
  1805. get_conv_bias_1x1_benchmark_args();
  1806. constexpr size_t RUNS = 50;
  1807. param::MatrixMul param;
  1808. param.transposeA = false;
  1809. param.transposeB = false;
  1810. Benchmarker<MatrixMul> benchmark_matmul(handle);
  1811. benchmark_matmul.set_before_exec_callback(
  1812. AlgoChecker<MatrixMul>(matmul_algo_name));
  1813. benchmark_matmul.set_times(RUNS)
  1814. .set_dtype(0, stype)
  1815. .set_dtype(1, stype)
  1816. .set_dtype(2, matmul_dtype)
  1817. .set_param(param)
  1818. .set_display(false);
  1819. std::string conv1x1_algo_name = ssprintf("CONV1x1:%s:24", matmul_algo_name);
  1820. Benchmarker<ConvBias> benchmark_conv1x1(handle);
  1821. benchmark_conv1x1.set_before_exec_callback(
  1822. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1823. conv1x1_algo_name.c_str()));
  1824. benchmark_conv1x1.set_times(RUNS)
  1825. .set_dtype(0, stype)
  1826. .set_dtype(1, stype)
  1827. .set_dtype(2, bias_type)
  1828. .set_dtype(4, conv_dtype)
  1829. .set_display(false);
  1830. for (auto&& arg : conv_bias_1x1_args) {
  1831. size_t IC = arg.src[1];
  1832. size_t OH = arg.src[2];
  1833. size_t OW = arg.src[3];
  1834. size_t OC = arg.filter[0];
  1835. size_t M = OC;
  1836. size_t K = IC;
  1837. size_t N = OH * OW;
  1838. float computations = M * N * K * 2.f / (1024 * 1024 * 1024) * 1e3;
  1839. TensorShape A, B;
  1840. A = TensorShape{M, K};
  1841. B = TensorShape{K, N};
  1842. auto conv1x1_used = benchmark_conv1x1.set_param(arg.param).exec(
  1843. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1844. RUNS;
  1845. auto matmul_used = benchmark_matmul.exec({A, B, {}}) / RUNS;
  1846. printf("%s %s:\n matmul: %f ms %f Gflops\nconv1x1: %f ms %f GFlops "
  1847. "speedup: "
  1848. "%f\n",
  1849. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1850. matmul_used, computations / matmul_used, conv1x1_used,
  1851. computations / conv1x1_used, matmul_used / conv1x1_used);
  1852. }
  1853. }
  1854. } // namespace
  1855. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_S1_F32) {
  1856. #if MEGDNN_AARCH64
  1857. benchmark_conv1x1("AARCH64_F32K8X12X1", handle(), dtype::Float32{},
  1858. dtype::Float32{}, dtype::Float32{}, dtype::Float32{});
  1859. #else
  1860. benchmark_conv1x1("ARMV7_F32", handle(), dtype::Float32{}, dtype::Float32{},
  1861. dtype::Float32{}, dtype::Float32{});
  1862. #endif
  1863. }
  1864. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  1865. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_S1_F16) {
  1866. #if MEGDNN_AARCH64
  1867. benchmark_conv1x1("AARCH64_F16_K8X24X1", handle(), dtype::Float16{},
  1868. dtype::Float16{}, dtype::Float16{}, dtype::Float16{});
  1869. #else
  1870. benchmark_conv1x1("AARCH32_F16_K4X16X1", handle(), dtype::Float16{},
  1871. dtype::Float16{}, dtype::Float16{}, dtype::Float16{});
  1872. #endif
  1873. }
  1874. #endif
  1875. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_S1_QUANTIZEDSYM) {
  1876. dtype::QuantizedS8 stype(2.5f);
  1877. dtype::QuantizedS32 dtype(6.25f);
  1878. #if MEGDNN_AARCH64
  1879. #if __ARM_FEATURE_DOTPROD
  1880. benchmark_conv1x1("AARCH64_INT8X8X32_K8X12X4_DOTPROD", handle(), stype,
  1881. dtype, dtype, dtype);
  1882. #else
  1883. benchmark_conv1x1("AARCH64_INT8X8X32_K8X8X8", handle(), stype, dtype, dtype,
  1884. dtype);
  1885. benchmark_conv1x1("AARCH64_INT8X8X32_K4X4X16", handle(), stype, dtype,
  1886. dtype, dtype);
  1887. #endif
  1888. #elif MEGDNN_ARMV7
  1889. benchmark_conv1x1("ARMV7_INT8X8X32_K4X8X8", handle(), stype, dtype, dtype,
  1890. dtype);
  1891. #endif
  1892. }
  1893. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_S1_QUANTIZEDASYM) {
  1894. dtype::Quantized8Asymm stype(1.2f, (uint8_t)125);
  1895. dtype::QuantizedS32 dtype(1.2 * 1.2);
  1896. #if MEGDNN_AARCH64
  1897. #if __ARM_FEATURE_DOTPROD
  1898. benchmark_conv1x1("AARCH64_QUINT8_K8X8X4_DOTPROD", handle(), stype, dtype,
  1899. dtype, dtype);
  1900. #else
  1901. benchmark_conv1x1("AARCH64_QUINT8_K8X8X8", handle(), stype, dtype, dtype,
  1902. dtype);
  1903. #endif
  1904. #elif MEGDNN_ARMV7
  1905. benchmark_conv1x1("ARMV7_QUINT8_K4X8X8", handle(), stype, dtype, dtype,
  1906. dtype);
  1907. #endif
  1908. }
  1909. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_S1_INT8x8x16) {
  1910. #if MEGDNN_AARCH64
  1911. benchmark_conv1x1("AARCH64_INT8X8X16_K8X8X8", handle(), dtype::Int8{},
  1912. dtype::Int16{}, dtype::Int16{}, dtype::Int16{});
  1913. benchmark_conv1x1("AARCH64_INT8X8X16_K4X4X16", handle(), dtype::Int8{},
  1914. dtype::Int16{}, dtype::Int16{}, dtype::Int16{});
  1915. #elif MEGDNN_ARMV7
  1916. benchmark_conv1x1("ARMV7_INT8X8X16_K4X8X8", handle(), dtype::Int8{},
  1917. dtype::Int16{}, dtype::Int16{}, dtype::Int16{});
  1918. benchmark_conv1x1("ARMV7_INT8X8X16_K4X2X16", handle(), dtype::Int8{},
  1919. dtype::Int16{}, dtype::Int16{}, dtype::Int16{});
  1920. #endif
  1921. }
  1922. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_CONV1X1_GEMV_FP32) {
  1923. using namespace conv_bias;
  1924. std::vector<conv_bias::TestArg> args;
  1925. param::ConvBias conv_param;
  1926. conv_param.stride_h = 1;
  1927. conv_param.stride_w = 1;
  1928. conv_param.pad_h = 0;
  1929. conv_param.pad_w = 0;
  1930. conv_param.nonlineMode = param::ConvBias::NonlineMode::IDENTITY;
  1931. auto run = [&](size_t M, size_t K){
  1932. args.emplace_back(conv_param, TensorShape{1, K, 1, 1},
  1933. TensorShape{M, K, 1, 1}, TensorShape{});
  1934. };
  1935. for (size_t M : {4, 64, 1024, 4096})
  1936. for (size_t K : {128, 256, 1024, 4096})
  1937. run(M, K);
  1938. constexpr size_t RUNS = 50;
  1939. param::MatrixMul param;
  1940. param.transposeA = false;
  1941. param.transposeB = false;
  1942. Benchmarker<MatrixMul> benchmark_matmul(handle());
  1943. benchmark_matmul.set_before_exec_callback(
  1944. AlgoChecker<MatrixMul>("ARM_COMMON_F32_GEMV"));
  1945. benchmark_matmul.set_times(RUNS)
  1946. .set_dtype(0, dtype::Float32{})
  1947. .set_dtype(1, dtype::Float32{})
  1948. .set_dtype(2, dtype::Float32{})
  1949. .set_param(param)
  1950. .set_display(false);
  1951. Benchmarker<ConvBias> benchmark_conv1x1(handle());
  1952. benchmark_conv1x1.set_before_exec_callback(
  1953. conv_bias::ConvBiasAlgoChecker<ConvBias>("CONV1x1_GEMV"));
  1954. benchmark_conv1x1.set_times(RUNS)
  1955. .set_dtype(0, dtype::Float32{})
  1956. .set_dtype(1, dtype::Float32{})
  1957. .set_dtype(2, dtype::Float32{})
  1958. .set_dtype(4, dtype::Float32{})
  1959. .set_display(false);
  1960. std::cout << "warm up:\n";
  1961. for (int i = 0; i < 50; i++) {
  1962. benchmark_matmul.exec({{1, 1024}, {1024, 512}, {}});
  1963. benchmark_matmul.set_display(true);
  1964. }
  1965. for (auto&& arg : args) {
  1966. size_t IC = arg.src[1];
  1967. size_t OH = arg.src[2];
  1968. size_t OW = arg.src[3];
  1969. size_t OC = arg.filter[0];
  1970. size_t M = OC;
  1971. size_t K = IC;
  1972. size_t N = OH * OW;
  1973. float computations = M * N * K * 2.f / (1024 * 1024 * 1024) * 1e3;
  1974. TensorShape A, B;
  1975. A = TensorShape{M, K};
  1976. B = TensorShape{K, N};
  1977. auto conv1x1_used = benchmark_conv1x1.set_param(arg.param).exec(
  1978. {arg.src, arg.filter, arg.bias, {}, {}}) /
  1979. RUNS;
  1980. auto matmul_used = benchmark_matmul.exec({A, B, {}}) / RUNS;
  1981. printf("%s %s:\n gemv: %f ms %f Gflops\nconv1x1: %f ms %f GFlops "
  1982. "speedup: "
  1983. "%f\n",
  1984. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  1985. matmul_used, computations / matmul_used, conv1x1_used,
  1986. computations / conv1x1_used, matmul_used / conv1x1_used);
  1987. }
  1988. }
  1989. #ifndef __ARM_FEATURE_DOTPROD
  1990. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_1X1_S1_NCHW_VS_NCHW44_INT8x8x32) {
  1991. std::vector<TestArg> conv_bias_1x1_args_nchw44 =
  1992. get_conv_bias_1x1_benchmark_args(4);
  1993. std::vector<TestArg> conv_bias_1x1_args_nchw =
  1994. get_conv_bias_1x1_benchmark_args(1);
  1995. constexpr size_t RUNS = 50;
  1996. Benchmarker<ConvBias> benchmark_conv1x1_nchw44(handle());
  1997. benchmark_conv1x1_nchw44.set_before_exec_callback(
  1998. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  1999. "CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24"));
  2000. benchmark_conv1x1_nchw44.set_times(RUNS)
  2001. .set_dtype(0, dtype::Int8())
  2002. .set_dtype(1, dtype::Int8())
  2003. .set_dtype(2, dtype::Int32())
  2004. .set_dtype(4, dtype::Int32())
  2005. .set_display(false);
  2006. Benchmarker<ConvBias> benchmark_conv1x1_nchw(handle());
  2007. benchmark_conv1x1_nchw.set_before_exec_callback(
  2008. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  2009. "CONV1x1:AARCH64_INT8X8X32_K4X4X16:24"));
  2010. benchmark_conv1x1_nchw.set_times(RUNS)
  2011. .set_dtype(0, dtype::Int8())
  2012. .set_dtype(1, dtype::Int8())
  2013. .set_dtype(2, dtype::Int32())
  2014. .set_dtype(4, dtype::Int32())
  2015. .set_display(false);
  2016. for (size_t i = 0; i < conv_bias_1x1_args_nchw44.size(); ++i) {
  2017. auto&& arg_nchw = conv_bias_1x1_args_nchw[i];
  2018. auto&& arg_nchw44 = conv_bias_1x1_args_nchw44[i];
  2019. size_t IC = arg_nchw.src[1];
  2020. size_t OH = arg_nchw.src[2];
  2021. size_t OW = arg_nchw.src[3];
  2022. size_t OC = arg_nchw.filter[0];
  2023. size_t M = OC;
  2024. size_t K = IC;
  2025. size_t N = OH * OW;
  2026. float computations = M * N * K * 2.f / (1024 * 1024 * 1024) * 1e3;
  2027. auto conv1x1_nchw = benchmark_conv1x1_nchw.set_param(arg_nchw.param)
  2028. .exec({arg_nchw.src,
  2029. arg_nchw.filter,
  2030. arg_nchw.bias,
  2031. {},
  2032. {}}) /
  2033. RUNS;
  2034. auto conv1x1_nchw44 =
  2035. benchmark_conv1x1_nchw44.set_param(arg_nchw44.param)
  2036. .exec({arg_nchw44.src,
  2037. arg_nchw44.filter,
  2038. arg_nchw44.bias,
  2039. {},
  2040. {}}) /
  2041. RUNS;
  2042. printf("%s %s:\n conv_1x1_nchw: %f ms %f Gflops\nconv1x1_nchw44: %f ms "
  2043. "%f GFlops "
  2044. "speedup: "
  2045. "%f\n",
  2046. arg_nchw.src.to_string().c_str(),
  2047. arg_nchw.filter.to_string().c_str(), conv1x1_nchw,
  2048. computations / conv1x1_nchw, conv1x1_nchw44,
  2049. computations / conv1x1_nchw44, conv1x1_nchw / conv1x1_nchw44);
  2050. }
  2051. }
  2052. #endif
  2053. TEST_F(ARM_COMMON, BENCHMARK_CONV_BIAS_WINOGRAD_VS_IM2COL_INT8) {
  2054. auto&& args = get_winograd_benchmark_args(3, 8);
  2055. using namespace conv_bias;
  2056. constexpr size_t RUN = 10;
  2057. Benchmarker<ConvBias> benchmark_im2col(handle());
  2058. benchmark_im2col.set_display(false);
  2059. benchmark_im2col.set_times(RUN);
  2060. benchmark_im2col.set_dtype(0, dtype::QuantizedS8(2.5f))
  2061. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2062. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2063. .set_dtype(4, dtype::QuantizedS8(60.25f));
  2064. Benchmarker<ConvBias> benchmark_winograd(handle());
  2065. benchmark_winograd.set_display(false);
  2066. benchmark_winograd.set_times(RUN);
  2067. benchmark_winograd.set_dtype(0, dtype::QuantizedS8(2.5f))
  2068. .set_dtype(1, dtype::QuantizedS8(2.5f))
  2069. .set_dtype(2, dtype::QuantizedS32(6.25f))
  2070. .set_dtype(4, dtype::QuantizedS8(60.25f));
  2071. for (auto&& arg : args) {
  2072. TensorLayout dst_layout;
  2073. auto opr = handle()->create_operator<ConvBias>();
  2074. opr->param() = arg.param;
  2075. opr->deduce_layout({arg.src, dtype::Float32()},
  2076. {arg.filter, dtype::Float32()},
  2077. {arg.bias, dtype::Float32()}, {}, dst_layout);
  2078. //! dst.nr_elems * IC * FH * FW * 2
  2079. float computations = dst_layout.total_nr_elems() * arg.filter[1] *
  2080. arg.filter[2] * arg.filter[3] * 2.0 /
  2081. (1024 * 1024 * 1024) * 1e3;
  2082. benchmark_im2col.set_param(arg.param);
  2083. auto im2col_used =
  2084. algo_benchmark<ConvBias>(
  2085. benchmark_im2col, {arg.src, arg.filter, {}, {}, {}},
  2086. "IM2COLMATMUL:AARCH64_INT8X8X32_K4X4X16") /
  2087. RUN;
  2088. benchmark_winograd.set_param(arg.param);
  2089. auto winograd_used =
  2090. algo_benchmark<ConvBias>(
  2091. benchmark_winograd, {arg.src, arg.filter, {}, {}, {}},
  2092. "WINOGRAD:AARCH64_INT16X16X32_MK8_8X8:8:2") /
  2093. RUN;
  2094. printf("%s %s: im2col: %f ms %f Gflops winograd: %f ms %f GFlops "
  2095. "speedup: "
  2096. "%f\n",
  2097. arg.src.to_string().c_str(), arg.filter.to_string().c_str(),
  2098. im2col_used, computations / im2col_used, winograd_used,
  2099. computations / winograd_used, im2col_used / winograd_used);
  2100. }
  2101. }
  2102. #endif
  2103. // vim: syntax=cpp.doxygen

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