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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. /**
  2. * \file dnn/test/cuda/conv_bias.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 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 implied.
  10. */
  11. #include "megdnn/dtype.h"
  12. #include "test/cuda/fixture.h"
  13. #include "megdnn/opr_param_defs.h"
  14. #include "megdnn/oprs.h"
  15. #include "src/cuda/handle.h"
  16. #include "test/common/benchmarker.h"
  17. #include "test/common/checker.h"
  18. #include "test/common/conv_bias.h"
  19. #include "test/common/rng.h"
  20. #include "test/common/tensor.h"
  21. #include "test/common/workspace_wrapper.h"
  22. #include "test/cuda/utils.h"
  23. using namespace megdnn;
  24. using namespace test;
  25. using namespace conv_bias;
  26. namespace {
  27. #if CUDA_VERSION >= 10000
  28. void test_conv_bias_forward_wmma_int4_nchw8(Handle* handle_cuda, size_t fh) {
  29. require_compute_capability(7, 5);
  30. using namespace conv_bias;
  31. Checker<ConvBiasForward> checker(handle_cuda);
  32. UniformIntRNG int_rng{0, 8};
  33. ConvBias::Param param;
  34. param.format = ConvBias::Param::Format::NCHW8;
  35. using NonlineMode = ConvBias::Param::NonlineMode;
  36. for (NonlineMode mode : {NonlineMode::RELU}) {
  37. for (size_t batch : {1}) {
  38. for (size_t ic : {128, 32}) {
  39. for (size_t oc : {32}) {
  40. for (int ph : {static_cast<int>(fh / 2), 0}) {
  41. for (size_t ih : {8, 9, 13, 15, 16}) {
  42. for (size_t iw : {8, 16, 24, 32, 40}) {
  43. param.nonlineMode = mode;
  44. param.stride_h = param.stride_w = 1;
  45. param.pad_h = param.pad_w = ph;
  46. checker.set_dtype(0,
  47. dtype::Quantized4Asymm(
  48. 1.3f, (uint8_t)(1)))
  49. .set_dtype(1,
  50. dtype::Quantized4Asymm(
  51. 1.3f, (uint8_t)(2)))
  52. .set_dtype(2, dtype::QuantizedS32(1.3f *
  53. 1.3f))
  54. .set_dtype(4, dtype::QuantizedS32(1.3f *
  55. 1.3f))
  56. .set_rng(0, &int_rng)
  57. .set_rng(1, &int_rng)
  58. .set_rng(2, &int_rng)
  59. .set_param(param);
  60. if (!ph)
  61. iw += 2 * (fh / 2);
  62. size_t oh = infer_conv_shape(ih, fh, 1, ph);
  63. size_t ow = infer_conv_shape(iw, fh, 1, ph);
  64. if (ow % 8 != 0)
  65. continue;
  66. checker.execs({{batch, ic / 8, ih, iw, 8},
  67. {oc, ic / 8, fh, fh, 8},
  68. {1, oc / 8, 1, 1, 8},
  69. {},
  70. {}});
  71. checker.execs({{batch, ic / 8, ih, iw, 8},
  72. {oc, ic / 8, fh, fh, 8},
  73. {batch, oc / 8, oh, ow, 8},
  74. {},
  75. {}});
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. #endif
  85. } // namespace
  86. #if CUDNN_VERSION >= 7400
  87. TEST_F(CUDA, CONV_BIAS_FORWARD_F32) {
  88. using namespace conv_bias;
  89. std::vector<TestArg> args = get_args();
  90. Checker<ConvBiasForward> checker(handle_cuda());
  91. NormalRNG default_rng;
  92. for (auto&& arg : args) {
  93. checker.set_dtype(0, dtype::Float32())
  94. .set_dtype(1, dtype::Float32())
  95. .set_dtype(2, dtype::Float32())
  96. .set_rng(0, &default_rng)
  97. .set_rng(1, &default_rng)
  98. .set_rng(2, &default_rng)
  99. .set_epsilon(1e-3)
  100. .set_param(arg.param)
  101. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  102. }
  103. }
  104. TEST_F(CUDA, CONV_BIAS_FORWARD_BF16) {
  105. using namespace conv_bias;
  106. std::vector<TestArg> args = get_args();
  107. Checker<ConvBiasForward> checker(handle_cuda());
  108. checker.set_before_exec_callback(
  109. AlgoChecker<ConvBiasForward>(ExecutionPolicyAlgoName{
  110. "CONVBIAS_BFLOAT16", {{"MATMUL", {}}}}));
  111. NormalRNG default_rng;
  112. for (auto&& arg : args) {
  113. arg.param.compute_mode = param::Convolution::ComputeMode::FLOAT32;
  114. checker.set_dtype(0, dtype::BFloat16())
  115. .set_dtype(1, dtype::BFloat16())
  116. .set_dtype(2, dtype::BFloat16())
  117. .set_dtype(3, dtype::BFloat16())
  118. .set_dtype(4, dtype::BFloat16())
  119. .set_rng(0, &default_rng)
  120. .set_rng(1, &default_rng)
  121. .set_rng(2, &default_rng)
  122. .set_epsilon(2e-2)
  123. .set_param(arg.param)
  124. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  125. }
  126. }
  127. TEST_F(CUDA, CONV_BIAS_FORWARD_QS8) {
  128. require_compute_capability(6, 1);
  129. UniformIntRNG int_rng{-50, 50};
  130. Checker<ConvBiasForward> checker(handle_cuda());
  131. ConvBias::Param param;
  132. param.format = ConvBias::Param::Format::NHWC;
  133. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  134. {
  135. auto src_shape = TensorShape{20, 224, 224, 4};
  136. auto filter_shape = TensorShape{24, 1, 1, 4};
  137. auto bias_shape = TensorShape{1, 1, 1, 24};
  138. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  139. .set_dtype(1, dtype::QuantizedS8(2.5f))
  140. .set_dtype(2, dtype::QuantizedS32(6.25f))
  141. .set_dtype(4, dtype::QuantizedS8(60.25f))
  142. .set_rng(0, &int_rng)
  143. .set_rng(1, &int_rng)
  144. .set_rng(2, &int_rng)
  145. .set_param(param)
  146. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  147. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  148. .set_dtype(1, dtype::QuantizedS8(2.5f))
  149. .set_dtype(2, dtype::QuantizedS32(6.25f))
  150. .set_dtype(4, dtype::QuantizedS8(40.25f))
  151. .set_rng(0, &int_rng)
  152. .set_rng(1, &int_rng)
  153. .set_rng(2, &int_rng)
  154. .set_param(param)
  155. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  156. }
  157. {
  158. auto src_shape = TensorShape{20, 224, 224, 4};
  159. auto filter_shape = TensorShape{24, 1, 1, 4};
  160. auto bias_shape = TensorShape{1, 1, 1, 24};
  161. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  162. .set_dtype(1, dtype::QuantizedS8(2.5f))
  163. .set_dtype(2, dtype::QuantizedS32(6.25f))
  164. .set_dtype(4, dtype::QuantizedS8(60.25f))
  165. .set_rng(0, &int_rng)
  166. .set_rng(1, &int_rng)
  167. .set_rng(2, &int_rng)
  168. .set_param(param)
  169. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  170. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  171. .set_dtype(1, dtype::QuantizedS8(2.5f))
  172. .set_dtype(2, dtype::QuantizedS32(6.25f))
  173. .set_dtype(4, dtype::QuantizedS8(40.25f))
  174. .set_rng(0, &int_rng)
  175. .set_rng(1, &int_rng)
  176. .set_rng(2, &int_rng)
  177. .set_param(param)
  178. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  179. }
  180. {
  181. param.sparse = ConvBias::Param::Sparse::GROUP;
  182. auto src_shape = TensorShape{20, 224, 224, 16};
  183. auto filter_shape = TensorShape{4, 4, 1, 1, 4};
  184. auto bias_shape = TensorShape{1, 1, 1, 16};
  185. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  186. .set_dtype(1, dtype::QuantizedS8(2.5f))
  187. .set_dtype(2, dtype::QuantizedS32(6.25f))
  188. .set_dtype(4, dtype::QuantizedS8(60.25f))
  189. .set_rng(0, &int_rng)
  190. .set_rng(1, &int_rng)
  191. .set_rng(2, &int_rng)
  192. .set_param(param)
  193. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  194. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  195. .set_dtype(1, dtype::QuantizedS8(2.5f))
  196. .set_dtype(2, dtype::QuantizedS32(6.25f))
  197. .set_dtype(4, dtype::QuantizedS8(40.25f))
  198. .set_rng(0, &int_rng)
  199. .set_rng(1, &int_rng)
  200. .set_rng(2, &int_rng)
  201. .set_param(param)
  202. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  203. }
  204. }
  205. TEST_F(CUDA, CONV_BIAS_NCHW_QS8) {
  206. //! not support NonlineMode::SIGMOID and NonlineMode::H_SWISH
  207. require_compute_capability(6, 1);
  208. Checker<ConvBiasForward> checker(handle_cuda());
  209. UniformIntRNG int_rng{-128, 127};
  210. using NonlineMode = ConvBias::Param::NonlineMode;
  211. ConvBias::Param param;
  212. param.format = ConvBias::Param::Format::NCHW;
  213. checker.set_dtype(0, dtype::QuantizedS8(1.f))
  214. .set_dtype(1, dtype::QuantizedS8(1.f))
  215. .set_dtype(2, dtype::QuantizedS32(1.f))
  216. .set_dtype(3, dtype::QuantizedS8(1.f))
  217. .set_dtype(4, dtype::QuantizedS8(1.f))
  218. .set_rng(0, &int_rng)
  219. .set_rng(1, &int_rng)
  220. .set_rng(2, &int_rng)
  221. .set_rng(3, &int_rng);
  222. for (NonlineMode mode : {NonlineMode::RELU,
  223. NonlineMode::IDENTITY, NonlineMode::H_SWISH}) {
  224. for (size_t g : {1, 2}) {
  225. for (size_t b : {2}) {
  226. for (size_t ic : {6, 16}) {
  227. for (size_t oc : {4}) {
  228. for (size_t fh : {1, 3}) {
  229. for (int ph : {static_cast<int>(fh / 2)}) {
  230. for (int sh : {1, 2}) {
  231. size_t ih = 16, iw = 16;
  232. param.nonlineMode = mode;
  233. param.stride_h = param.stride_w = sh;
  234. param.pad_h = param.pad_w = ph;
  235. param.sparse =
  236. ConvBias::Param::Sparse::DENSE;
  237. checker.set_param(param)
  238. .execs({{b, ic / 2, ih, iw},
  239. {oc, ic / 2, fh, fh},
  240. {1, oc, 1, 1},
  241. {},
  242. {}});
  243. param.sparse =
  244. ConvBias::Param::Sparse::GROUP;
  245. checker.set_param(param)
  246. .execs({{b, ic, ih, iw},
  247. {g, oc/g, ic/g, fh, fh},
  248. {1, oc, 1, 1},
  249. {},
  250. {}});
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. for (NonlineMode mode : {NonlineMode::RELU,
  260. NonlineMode::IDENTITY, NonlineMode::H_SWISH}) {
  261. for (size_t g : {13}) {
  262. for (size_t b : {1, 2}) {
  263. for (size_t ic : {13}) {
  264. for (size_t oc : {13}) {
  265. for (size_t fh : {1, 3}) {
  266. for (int ph : {static_cast<int>(fh / 2)}) {
  267. for (int sh : {1, 2}) {
  268. size_t ih = 16, iw = 16;
  269. param.nonlineMode = mode;
  270. param.stride_h = param.stride_w = sh;
  271. param.pad_h = param.pad_w = ph;
  272. param.sparse =
  273. ConvBias::Param::Sparse::GROUP;
  274. checker.set_param(param)
  275. .execs({{b, ic, ih, iw},
  276. {g, oc/g, ic/g, fh, fh},
  277. {1, oc, 1, 1},
  278. {},
  279. {}});
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. {
  289. size_t ih = 16, iw = 16, b = 1, oc = 14, ic = 14;
  290. size_t fh = 3, sh = 1, ph = 1;
  291. param.nonlineMode = NonlineMode::IDENTITY;
  292. param.stride_h = param.stride_w = sh;
  293. param.pad_h = param.pad_w = ph;
  294. param.sparse = ConvBias::Param::Sparse::DENSE;
  295. checker.set_param(param).execs(
  296. {{b, ic, ih, iw}, {oc, ic, fh, fh}, {}, {}, {}});
  297. }
  298. }
  299. TEST_F(CUDA, CONV_BIAS_NCHW_QS8_FUSE_Z) {
  300. require_compute_capability(6, 1);
  301. Checker<ConvBiasForward> checker(handle_cuda());
  302. UniformIntRNG int_rng{-128, 127};
  303. using NonlineMode = ConvBias::Param::NonlineMode;
  304. ConvBias::Param param;
  305. param.format = ConvBias::Param::Format::NCHW;
  306. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  307. .set_dtype(1, dtype::QuantizedS8(2.5f))
  308. .set_dtype(2, dtype::QuantizedS32(6.25f))
  309. .set_dtype(3, dtype::QuantizedS8(0.25f))
  310. .set_dtype(4, dtype::QuantizedS8(0.25f))
  311. .set_rng(0, &int_rng)
  312. .set_rng(1, &int_rng)
  313. .set_rng(2, &int_rng)
  314. .set_rng(3, &int_rng);
  315. for (NonlineMode mode :
  316. {NonlineMode::RELU, NonlineMode::IDENTITY, NonlineMode::H_SWISH}) {
  317. for (size_t b : {2}) {
  318. for (size_t ic : {6, 16}) {
  319. for (size_t oc : {4}) {
  320. for (size_t fh : {1, 3}) {
  321. for (int ph : {static_cast<int>(fh / 2)}) {
  322. for (int sh : {1, 2}) {
  323. size_t ih = 16, iw = 16;
  324. param.nonlineMode = mode;
  325. param.stride_h = param.stride_w = sh;
  326. param.pad_h = param.pad_w = ph;
  327. param.sparse = ConvBias::Param::Sparse::DENSE;
  328. const size_t oh = (ih - fh + 2 * ph) / sh + 1;
  329. const size_t ow = (iw - fh + 2 * ph) / sh + 1;
  330. checker.set_param(param).execs(
  331. {{b, ic, ih, iw},
  332. {oc, ic, fh, fh},
  333. {1, oc, 1, 1},
  334. {b, oc, oh, ow},
  335. {}});
  336. }
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. #if MEGDNN_WITH_BENCHMARK
  345. TEST_F(CUDA, BENCHMARK_CONV_BIAS_NCHW4_INT8) {
  346. require_compute_capability(6, 1);
  347. Benchmarker<ConvBiasForward> bencher(handle_cuda());
  348. bencher.set_display(false);
  349. ConvBias::Param param_nchw;
  350. param_nchw.format = ConvBias::Param::Format::NCHW;
  351. ConvBias::Param param_nchw4;
  352. param_nchw4.format = ConvBias::Param::Format::NCHW4;
  353. auto i8_min = std::numeric_limits<int8_t>().min();
  354. auto i8_max = std::numeric_limits<int8_t>().max();
  355. UniformIntRNG int_rng{i8_min, i8_max};
  356. param_nchw.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  357. auto run_bench = [&](size_t b, size_t ci, size_t hi, size_t wi,
  358. size_t co, size_t fh, size_t fw, size_t sh,
  359. size_t sw, size_t nr_times) {
  360. param_nchw.pad_h = fh / 2;
  361. param_nchw.pad_w = fw / 2;
  362. param_nchw.stride_h = sh;
  363. param_nchw.stride_w = sw;
  364. param_nchw4.pad_h = fh / 2;
  365. param_nchw4.pad_w = fh / 2;
  366. param_nchw4.stride_h = sh;
  367. param_nchw4.stride_w = sw;
  368. bencher.set_times(nr_times)
  369. .set_dtype(0, dtype::QuantizedS8(2.5f))
  370. .set_dtype(1, dtype::QuantizedS8(2.5f))
  371. .set_dtype(2, dtype::QuantizedS32(6.25f))
  372. .set_dtype(4, dtype::QuantizedS8(0.35f))
  373. .set_rng(0, &int_rng)
  374. .set_rng(1, &int_rng)
  375. .set_rng(2, &int_rng);
  376. bencher.set_param(param_nchw);
  377. size_t ho = infer_conv_shape(hi, fh, sh, param_nchw.pad_h);
  378. size_t wo = infer_conv_shape(wi, fw, sw, param_nchw.pad_w);
  379. TensorShape inp{b, ci, hi, wi}, kern{co, ci, fh, fw},
  380. out{b, co, ho, wo};
  381. auto time_in_ms = bencher.execs(
  382. {inp, kern, {1, co, 1, 1}, {}, out}) / nr_times;
  383. auto ops_nchw = 2.0 * b * co * ho * wo * ci * fh * fw /
  384. (time_in_ms * 1e-3) * 1e-12;
  385. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops "
  386. "(NCHW)\n",
  387. inp.to_string().c_str(), kern.to_string().c_str(),
  388. out.to_string().c_str(), time_in_ms, ops_nchw);
  389. bencher.set_param(param_nchw4);
  390. decltype(ops_nchw) ops_nchw4;
  391. {
  392. TensorShape inp{b, ci / 4, hi, wi, 4},
  393. kern{co, ci / 4, fh, fw, 4}, out{b, co / 4, ho, wo, 4};
  394. auto time_in_ms = bencher.execs(
  395. {inp, kern, {1, co / 4, 1, 1, 4}, {}, out}) / nr_times;
  396. ops_nchw4 = 2.0 * b * co * ho * wo * ci * fh * fw /
  397. (time_in_ms * 1e-3) * 1e-12;
  398. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops "
  399. "(NCHW4)\n",
  400. inp.to_string().c_str(), kern.to_string().c_str(),
  401. out.to_string().c_str(), time_in_ms, ops_nchw4);
  402. }
  403. printf("speedup: %.2fx\n", ops_nchw4 / ops_nchw);
  404. };
  405. // resnet-50
  406. // bottleneck-1
  407. // proj
  408. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  409. run_bench(1, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  410. run_bench(1, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  411. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  412. // bottleneck-2
  413. // proj
  414. run_bench(1, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  415. run_bench(1, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  416. run_bench(1, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  417. run_bench(1, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  418. // bottleneck-3
  419. // proj
  420. run_bench(1, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  421. run_bench(1, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  422. run_bench(1, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  423. run_bench(1, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  424. // bottleneck-4
  425. // proj
  426. run_bench(1, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  427. run_bench(1, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  428. run_bench(1, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  429. run_bench(1, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  430. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  431. run_bench(32, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  432. run_bench(32, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  433. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  434. run_bench(32, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  435. run_bench(32, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  436. run_bench(32, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  437. run_bench(32, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  438. run_bench(32, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  439. run_bench(32, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  440. run_bench(32, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  441. run_bench(32, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  442. run_bench(32, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  443. run_bench(32, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  444. run_bench(32, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  445. run_bench(32, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  446. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  447. run_bench(256, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  448. run_bench(256, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  449. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  450. run_bench(256, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  451. run_bench(256, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  452. run_bench(256, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  453. run_bench(256, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  454. run_bench(256, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  455. run_bench(256, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  456. run_bench(256, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  457. run_bench(256, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  458. run_bench(256, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  459. run_bench(256, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  460. run_bench(256, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  461. run_bench(256, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  462. }
  463. #endif
  464. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW4) {
  465. require_compute_capability(6, 1);
  466. using namespace conv_bias;
  467. Checker<ConvBiasForward> checker(handle_cuda());
  468. UniformIntRNG int_rng{-5, 5};
  469. ConvBias::Param param;
  470. param.format = ConvBias::Param::Format::NCHW4;
  471. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  472. checker.set_dtype(0, dtype::QuantizedS8(0.5f))
  473. .set_dtype(1, dtype::QuantizedS8(0.5f))
  474. .set_dtype(2, dtype::QuantizedS32(0.25f))
  475. .set_dtype(3, dtype::QuantizedS8(0.13f))
  476. .set_dtype(4, dtype::QuantizedS8(0.35f))
  477. .set_rng(0, &int_rng)
  478. .set_rng(1, &int_rng)
  479. .set_rng(2, &int_rng)
  480. .set_rng(3, &int_rng)
  481. .set_param(param);
  482. auto opr = handle_cuda()->create_operator<ConvBias>();
  483. auto run = [&](const TensorShapeArray& shapes) {
  484. opr->param() = param;
  485. TensorLayout dst_layout;
  486. opr->deduce_layout({shapes[0], dtype::Float32()},
  487. {shapes[1], dtype::Float32()}, {}, {}, dst_layout);
  488. checker.execs({shapes[0], shapes[1], shapes[2], dst_layout, {}});
  489. };
  490. run({{1, 4, 4, 4, 4}, {4, 4, 3, 3, 4}, {1, 1, 1, 1, 4}});
  491. run({{1, 4, 4, 4, 4}, {260, 4, 3, 3, 4}, {1, 65, 1, 1, 4}});
  492. run({{20, 1, 24, 24, 4}, {24, 1, 2, 2, 4}, {1, 6, 1, 1, 4}});
  493. run({{20, 2, 24, 24, 4}, {24, 2, 3, 3, 4}, {1, 6, 1, 1, 4}});
  494. param.sparse = ConvBias::Param::Sparse::GROUP;
  495. checker.set_param(param);
  496. run({{1, 4, 24, 24, 4}, {4, 4, 1, 1, 1, 4}, {1, 4, 1, 1, 4}});
  497. run({{20, 8, 24, 24, 4}, {4, 24, 2, 2, 2, 4}, {1, 24, 1, 1, 4}});
  498. run({{1, 3, 24, 24, 4}, {3, 8, 1, 3, 3, 4}, {1, 6, 1, 1, 4}});
  499. param.pad_h = param.pad_w = 1;
  500. param.stride_h = param.stride_w = 2;
  501. checker.set_param(param);
  502. run({{10, 16, 28, 28, 4}, {8, 8, 2, 3, 3, 4}, {1, 16, 1, 1, 4}});
  503. // case which cudnn not supported
  504. param.sparse = ConvBias::Param::Sparse::DENSE;
  505. param.pad_h = param.pad_w = 1;
  506. param.stride_h = param.stride_w = 1;
  507. checker.set_param(param);
  508. checker.exec({{1, 4, 2, 2, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  509. }
  510. //! FIXME: conv kernel of cudnn for NCHW4_NCHW tensor format causes illegal
  511. //! memory access errors, so we have to disable this test here.
  512. #if 0
  513. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW4_NCHW) {
  514. require_compute_capability(6, 1);
  515. using namespace conv_bias;
  516. Checker<ConvBiasForward> checker(handle_cuda());
  517. UniformIntRNG int_rng{-3, 3};
  518. UniformFloatRNG float_rng{-50, 50};
  519. ConvBias::Param param;
  520. param.format = ConvBias::Param::Format::NCHW4_NCHW;
  521. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  522. checker.set_dtype(0, dtype::QuantizedS8(1.9980618f))
  523. .set_dtype(1, dtype::QuantizedS8(1.9980927f))
  524. .set_dtype(2, dtype::Float32())
  525. .set_dtype(3, dtype::Float32())
  526. .set_dtype(4, dtype::Float32())
  527. .set_rng(0, &int_rng)
  528. .set_rng(1, &int_rng)
  529. .set_rng(2, &float_rng)
  530. .set_rng(3, &float_rng)
  531. .set_param(param);
  532. auto opr = handle_cuda()->create_operator<ConvBias>();
  533. auto run = [&](const TensorShapeArray& shapes) {
  534. opr->param() = param;
  535. TensorLayout dst_layout;
  536. opr->deduce_layout({shapes[0], dtype::Float32()},
  537. {shapes[1], dtype::Float32()}, {}, {}, dst_layout);
  538. checker.execs({shapes[0], shapes[1], shapes[2], dst_layout, {}});
  539. };
  540. run({{1, 4, 4, 4, 4}, {4, 4, 3, 3, 4}, {1, 4, 1, 1}});
  541. run({{20, 1, 24, 24, 4}, {24, 1, 2, 2, 4}, {1, 24, 1, 1}});
  542. run({{20, 2, 24, 24, 4}, {24, 2, 3, 3, 4}, {1, 24, 1, 1}});
  543. param.sparse = ConvBias::Param::Sparse::GROUP;
  544. param.nonlineMode = ConvBias::Param::NonlineMode::RELU;
  545. checker.set_param(param);
  546. run({{1, 4, 24, 24, 4}, {4, 4, 1, 1, 1, 4}, {1, 16, 1, 1}});
  547. run({{20, 8, 24, 24, 4}, {4, 24, 2, 2, 2, 4}, {1, 96, 1, 1}});
  548. run({{1, 3, 24, 24, 4}, {3, 8, 1, 3, 3, 4}, {1, 24, 1, 1}});
  549. param.pad_h = param.pad_w = 1;
  550. param.stride_h = param.stride_w = 2;
  551. checker.set_param(param);
  552. run({{10, 16, 28, 28, 4}, {8, 8, 2, 3, 3, 4}, {1, 64, 1, 1}});
  553. // case which cudnn not supported
  554. param.sparse = ConvBias::Param::Sparse::DENSE;
  555. param.pad_h = param.pad_w = 1;
  556. param.stride_h = param.stride_w = 1;
  557. param.nonlineMode = ConvBias::Param::NonlineMode::H_SWISH;
  558. checker.set_param(param);
  559. checker.exec({{1, 4, 2, 2, 4}, {16, 4, 3, 3, 4}, {1, 16, 1, 1}, {}, {}});
  560. }
  561. #endif
  562. #endif
  563. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE) {
  564. Checker<ConvBiasForward> checker(handle_cuda());
  565. std::vector<TestArg> args = get_chanwise_args();
  566. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  567. ConvBiasForward::algo_name<ConvBias::DirectParam>("CHANNEL_WISE",
  568. {})
  569. .c_str()));
  570. for (auto dtype : std::vector<DType>{dtype::Float32(), dtype::Float16()}) {
  571. checker.set_dtype(0, dtype)
  572. .set_dtype(1, dtype)
  573. .set_dtype(2, dtype)
  574. .set_dtype(3, dtype)
  575. .set_dtype(4, dtype);
  576. if (dtype.enumv() == DTypeEnum::Float16)
  577. checker.set_epsilon(2e-2);
  578. for (auto&& arg : args) {
  579. checker.set_param(arg.param).execs(
  580. {arg.src, arg.filter, arg.bias, {}, {}});
  581. }
  582. }
  583. }
  584. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE_SMALL) {
  585. Checker<ConvBiasForward> checker(handle_cuda());
  586. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  587. ConvBiasForward::algo_name<ConvBias::DirectParam>(
  588. "CHANNEL_WISE_SMALL", {})
  589. .c_str()));
  590. param::ConvBias cur_param;
  591. using NLMode = param::ConvBias::NonlineMode;
  592. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  593. cur_param.sparse = ConvBias::Param::Sparse::GROUP;
  594. for (auto nlmode :
  595. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  596. cur_param.nonlineMode = nlmode;
  597. for (auto dtype : std::vector<DType> {
  598. dtype::Float32(),
  599. #if CUDA_VERSION >= 9000
  600. dtype::Float16()
  601. #endif
  602. }) {
  603. checker.set_dtype(0, dtype)
  604. .set_dtype(1, dtype)
  605. .set_dtype(2, dtype)
  606. .set_dtype(3, dtype)
  607. .set_dtype(4, dtype);
  608. if (dtype.enumv() == DTypeEnum::Float16)
  609. checker.set_epsilon(2e-2);
  610. for (uint32_t s : {1}) {
  611. for (uint32_t f : {1, 3, 5, 7}) {
  612. cur_param.pad_h = cur_param.pad_w = f / 2;
  613. cur_param.stride_h = cur_param.stride_w = s;
  614. checker.set_param(cur_param).execs({{2, 3, 16, 16},
  615. {3, 1, 1, f, f},
  616. {1, 3, 1, 1},
  617. {},
  618. {}});
  619. }
  620. }
  621. cur_param.pad_h = cur_param.pad_w = 1;
  622. cur_param.stride_h = cur_param.stride_w = 1;
  623. checker.set_param(cur_param)
  624. .execs({{2, 3, 3, 16},
  625. {3, 1, 1, 3, 3},
  626. {1, 3, 1, 1},
  627. {},
  628. {}})
  629. .execs({{2, 3, 8, 3},
  630. {3, 1, 1, 3, 3},
  631. {1, 3, 1, 1},
  632. {},
  633. {}});
  634. }
  635. }
  636. }
  637. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE_8x8x32) {
  638. require_compute_capability(6, 1);
  639. Checker<ConvBiasForward> checker(handle_cuda());
  640. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  641. ConvBiasForward::algo_name<ConvBias::DirectParam>(
  642. "CHANNEL_WISE_8X8X32", {})
  643. .c_str()));
  644. param::ConvBias cur_param;
  645. using NLMode = param::ConvBias::NonlineMode;
  646. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  647. cur_param.sparse = ConvBias::Param::Sparse::GROUP;
  648. cur_param.format = ConvBias::Param::Format::NHWC;
  649. UniformIntRNG rng(-4, 4);
  650. checker.set_dtype(0, dtype::Int8{})
  651. .set_dtype(1, dtype::Int8{})
  652. .set_dtype(2, dtype::Int32{})
  653. .set_dtype(4, dtype::Int32{})
  654. .set_rng(0, &rng)
  655. .set_rng(1, &rng)
  656. .set_rng(2, &rng);
  657. for (auto nlmode : {NLMode::IDENTITY, NLMode::RELU}) {
  658. cur_param.nonlineMode = nlmode;
  659. for (uint32_t s : {1, 2}) {
  660. for (uint32_t f : {1, 3, 5, 7}) {
  661. for (uint32_t g : {4, 8}) {
  662. cur_param.pad_h = cur_param.pad_w = f / 2;
  663. cur_param.stride_h = cur_param.stride_w = s;
  664. checker.set_param(cur_param).execs({{2, 9, 16, g},
  665. {g, 1, f, f, 1},
  666. {1, 1, 1, g},
  667. {},
  668. {}});
  669. }
  670. }
  671. }
  672. }
  673. }
  674. TEST_F(CUDA, CONV_BIAS_FORWARD_CUDNN_CONVOLUTION) {
  675. using namespace conv_bias;
  676. std::vector<TestArg> args = get_args();
  677. Checker<ConvBiasForward> checker(handle_cuda());
  678. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  679. ConvBiasForward::algo_name<ConvBias::DefaultParam>(
  680. "CUDNN:Convolution", {})
  681. .c_str()));
  682. NormalRNG default_rng;
  683. for (auto&& arg : args) {
  684. checker.set_dtype(0, dtype::Float32())
  685. .set_dtype(1, dtype::Float32())
  686. .set_dtype(2, dtype::Float32())
  687. .set_rng(0, &default_rng)
  688. .set_rng(1, &default_rng)
  689. .set_rng(2, &default_rng)
  690. .set_epsilon(1e-3)
  691. .set_param(arg.param)
  692. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  693. }
  694. //! noncontiguous case
  695. {
  696. param::ConvBias param;
  697. param.pad_h = param.pad_w = 1;
  698. checker.set_param(param).execl(TensorLayoutArray{
  699. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  700. {{16, 16, 3, 3}, {144, 9, 3, 1}, dtype::Float32()},
  701. {{}, {}, dtype::Float32()},
  702. {{}, {}, dtype::Float32()},
  703. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  704. });
  705. }
  706. }
  707. TEST_F(CUDA, CONV_BIAS_FORWARD_INPLACE_MATMUL) {
  708. using namespace conv_bias;
  709. std::vector<TestArg> args = get_args();
  710. Checker<ConvBiasForward> checker(handle_cuda());
  711. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  712. ConvBiasForward::algo_name<ConvBias::MatmulParam>("INPLACE_MATMUL",
  713. {})
  714. .c_str()));
  715. param::ConvBias cur_param;
  716. using NLMode = param::ConvBias::NonlineMode;
  717. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  718. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  719. NormalRNG default_rng;
  720. checker.set_dtype(0, dtype::Float32())
  721. .set_dtype(1, dtype::Float32())
  722. .set_dtype(2, dtype::Float32())
  723. .set_rng(0, &default_rng)
  724. .set_rng(1, &default_rng)
  725. .set_rng(2, &default_rng)
  726. .set_epsilon(1e-3);
  727. for (auto nlmode :
  728. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  729. cur_param.nonlineMode = nlmode;
  730. for (uint32_t s : {1}) {
  731. for (uint32_t f : {1, 3, 5, 7}) {
  732. cur_param.pad_h = cur_param.pad_w = f / 2;
  733. cur_param.stride_h = cur_param.stride_w = s;
  734. checker.set_param(cur_param).execs(
  735. {{2, 4, 16, 16}, {4, 4, f, f}, {1, 4, 1, 1}, {}, {}});
  736. }
  737. }
  738. cur_param.pad_h = cur_param.pad_w = 1;
  739. cur_param.stride_h = cur_param.stride_w = 1;
  740. checker.set_param(cur_param)
  741. .execs({{2, 3, 3, 16}, {5, 3, 3, 3}, {1, 5, 1, 1}, {}, {}})
  742. .execs({{2, 2, 8, 3}, {3, 2, 3, 3}, {1, 3, 1, 1}, {}, {}});
  743. }
  744. //! noncontiguous case
  745. {
  746. param::ConvBias param;
  747. param.pad_h = param.pad_w = 1;
  748. checker.set_param(param).execl(TensorLayoutArray{
  749. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  750. {{16, 16, 3, 3}, {144, 9, 3, 1}, dtype::Float32()},
  751. {{}, {}, dtype::Float32()},
  752. {{}, {}, dtype::Float32()},
  753. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  754. });
  755. }
  756. }
  757. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL) {
  758. using namespace conv_bias;
  759. std::vector<TestArg> args = get_args();
  760. Checker<ConvBiasForward> checker(handle_cuda());
  761. checker.set_before_exec_callback(
  762. AlgoChecker<ConvBiasForward>(ExecutionPolicyAlgoName{
  763. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  764. "MATMUL", {})
  765. .c_str(),
  766. {{"CUBLAS", {}}}}));
  767. param::ConvBias cur_param;
  768. using NLMode = param::ConvBias::NonlineMode;
  769. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  770. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  771. NormalRNG default_rng;
  772. checker.set_dtype(0, dtype::Float32())
  773. .set_dtype(1, dtype::Float32())
  774. .set_dtype(2, dtype::Float32())
  775. .set_rng(0, &default_rng)
  776. .set_rng(1, &default_rng)
  777. .set_rng(2, &default_rng)
  778. .set_epsilon(1e-3);
  779. for (auto nlmode :
  780. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  781. cur_param.nonlineMode = nlmode;
  782. for (uint32_t s : {1}) {
  783. for (uint32_t f : {1, 3, 5, 7}) {
  784. cur_param.pad_h = cur_param.pad_w = f / 2;
  785. cur_param.stride_h = cur_param.stride_w = s;
  786. checker.set_param(cur_param).execs(
  787. {{2, 4, 16, 16}, {4, 4, f, f}, {1, 4, 1, 1}, {}, {}});
  788. }
  789. }
  790. cur_param.pad_h = cur_param.pad_w = 0;
  791. cur_param.stride_h = cur_param.stride_w = 1;
  792. checker.set_param(cur_param)
  793. .execs({{2, 3, 3, 16}, {5, 3, 3, 3}, {1, 5, 1, 1}, {}, {}})
  794. .execs({{2, 2, 8, 3}, {3, 2, 3, 3}, {1, 3, 1, 1}, {}, {}});
  795. }
  796. //! noncontiguous case
  797. {
  798. param::ConvBias param;
  799. param.pad_h = param.pad_w = 1;
  800. checker.set_param(param).execl(TensorLayoutArray{
  801. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  802. {{16, 16, 3, 3}, {144, 9, 3, 1}, dtype::Float32()},
  803. {{}, {}, dtype::Float32()},
  804. {{}, {}, dtype::Float32()},
  805. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  806. });
  807. }
  808. }
  809. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL_8x8x32) {
  810. require_compute_capability(6, 1);
  811. Checker<ConvBiasForward> checker(handle_cuda());
  812. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  813. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  814. "MATMUL8X8X32", {})
  815. .c_str()));
  816. param::ConvBias cur_param;
  817. using NLMode = param::ConvBias::NonlineMode;
  818. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  819. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  820. cur_param.format = param::ConvBias::Format::NHWC;
  821. UniformIntRNG rng{-100, 100};
  822. UniformIntRNG bias_rng{-1000, 1000};
  823. checker.set_rng(0, &rng)
  824. .set_rng(1, &rng)
  825. .set_rng(2, &bias_rng)
  826. .set_rng(3, &rng)
  827. .set_dtype(0, dtype::QuantizedS8{1.2f})
  828. .set_dtype(1, dtype::QuantizedS8{1.3f})
  829. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  830. .set_dtype(3, dtype::QuantizedS8{1.1f})
  831. .set_dtype(4, dtype::QuantizedS8{1.0f})
  832. .set_epsilon(1);
  833. for (auto nlmode : {NLMode::IDENTITY, NLMode::RELU}) {
  834. cur_param.nonlineMode = nlmode;
  835. for (uint32_t s : {1}) {
  836. for (uint32_t f : {1, 3, 5, 7}) {
  837. cur_param.pad_h = cur_param.pad_w = f / 2;
  838. cur_param.stride_h = cur_param.stride_w = s;
  839. checker.set_param(cur_param).execs(
  840. {{2, 16, 16, 4}, {4, f, f, 4}, {1, 1, 1, 4}, {}, {}});
  841. }
  842. }
  843. cur_param.pad_h = cur_param.pad_w = 0;
  844. cur_param.stride_h = cur_param.stride_w = 1;
  845. checker.set_param(cur_param)
  846. .execs({{2, 3, 16, 3}, {5, 3, 3, 3}, {1, 1, 1, 5}, {}, {}})
  847. .execs({{2, 8, 3, 2}, {3, 3, 3, 2}, {1, 1, 1, 3}, {}, {}});
  848. }
  849. //! noncontiguous case
  850. {
  851. param::ConvBias param;
  852. param.pad_h = param.pad_w = 1;
  853. param.format = param::ConvBias::Format::NHWC;
  854. checker.set_param(param).execl(TensorLayoutArray{
  855. {{2, 7, 7, 16}, {1568, 224, 32, 1}, dtype::QuantizedS8{1.2f}},
  856. {{16, 3, 3, 16}, {144, 48, 16, 1}, dtype::QuantizedS8{1.3f}},
  857. {{}, {}, dtype::QuantizedS32{1.2f * 1.3f}},
  858. {{}, {}, dtype::QuantizedS8{1.1f}},
  859. {{2, 7, 7, 16},
  860. {1568, 224, 32, 1},
  861. dtype::QuantizedS32{1.2f * 1.3f}},
  862. });
  863. }
  864. }
  865. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL_NCHW4) {
  866. require_compute_capability(6, 1);
  867. Checker<ConvBiasForward> checker(handle_cuda());
  868. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  869. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  870. "MATMUL8X8X32", {})
  871. .c_str()));
  872. UniformIntRNG int_rng{-127, 127};
  873. ConvBias::Param param;
  874. param.format = ConvBias::Param::Format::NCHW4;
  875. using NLMode = ConvBias::Param::NonlineMode;
  876. checker.set_dtype(0, dtype::QuantizedS8(0.5f))
  877. .set_dtype(1, dtype::QuantizedS8(0.5f))
  878. .set_dtype(2, dtype::QuantizedS32(0.25f))
  879. .set_dtype(4, dtype::QuantizedS8(0.35f))
  880. .set_rng(0, &int_rng)
  881. .set_rng(1, &int_rng)
  882. .set_rng(2, &int_rng);
  883. param.sparse = Convolution::Param::Sparse::DENSE;
  884. param.nonlineMode = NLMode::IDENTITY;
  885. param.pad_h = param.pad_w = 1;
  886. param.stride_h = param.stride_w = 1;
  887. checker.set_param(param);
  888. checker.exec(
  889. {{8, 4, 10, 10, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  890. checker.exec({{1, 4, 2, 2, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  891. checker.exec(
  892. {{8, 64, 12, 12, 4}, {256, 64, 3, 3, 4}, {1, 64, 1, 1, 4}, {}, {}});
  893. //! noncontiguous case
  894. {
  895. param::ConvBias param;
  896. param.pad_h = param.pad_w = 1;
  897. param.format = ConvBias::Param::Format::NCHW4;
  898. checker.set_param(param).execl(TensorLayoutArray{
  899. {{2, 4, 7, 7, 4}, {1568, 196, 28, 4, 1}, dtype::QuantizedS8{1.2f}},
  900. {{16, 4, 3, 3, 4}, {144, 36, 12, 4, 1}, dtype::QuantizedS8{1.3f}},
  901. {{}, {}, dtype::QuantizedS32{1.2f * 1.3f}},
  902. {{}, {}, dtype::QuantizedS8{1.1f}},
  903. {{2, 4, 7, 7, 4},
  904. {1568, 196, 28, 4, 1},
  905. dtype::QuantizedS32{1.2f * 1.3f}},
  906. });
  907. }
  908. }
  909. TEST_F(CUDA, CONV_BIAS_FORWARD_BATCHED_MATMUL) {
  910. using namespace conv_bias;
  911. std::vector<TestArg> args = get_args_1x1();
  912. Checker<ConvBiasForward> checker(handle_cuda());
  913. NormalRNG default_rng;
  914. checker.set_dtype(0, dtype::Float32())
  915. .set_dtype(1, dtype::Float32())
  916. .set_dtype(2, dtype::Float32())
  917. .set_rng(0, &default_rng)
  918. .set_rng(1, &default_rng)
  919. .set_rng(2, &default_rng)
  920. .set_epsilon(1e-3);
  921. checker.set_before_exec_callback(
  922. AlgoChecker<ConvBiasForward>(ExecutionPolicyAlgoName{
  923. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  924. "BATCHED_MATMUL", {})
  925. .c_str(),
  926. {{"CUBLAS", {}}}}));
  927. for (auto&& arg : args) {
  928. checker.set_param(arg.param);
  929. checker.execs({arg.src, arg.filter, arg.bias, {}, {}});
  930. }
  931. //! noncontiguous case
  932. {
  933. param::ConvBias param;
  934. checker.set_param(param).execl(TensorLayoutArray{
  935. {{2, 16, 7, 7}, {1568, 49, 7, 1}, dtype::Float32()},
  936. {{16, 16, 1, 1}, {16, 1, 1, 1}, dtype::Float32()},
  937. {{}, {}, dtype::Float32()},
  938. {{}, {}, dtype::Float32()},
  939. {{2, 16, 7, 7}, {784, 49, 7, 1}, dtype::Float32()},
  940. });
  941. }
  942. }
  943. TEST_F(CUDA, CONV_BIAS_FORWARD_GROUP) {
  944. using NLMode = ConvBias::Param::NonlineMode;
  945. bool is_int_available = false;
  946. if (megdnn::test::check_compute_capability(6, 1)) {
  947. is_int_available = true;
  948. } else {
  949. is_int_available = false;
  950. }
  951. auto run = [&](size_t N, size_t IC, size_t IH, size_t IW, size_t FH,
  952. size_t FW, size_t OC, size_t PH, size_t PW, size_t SH,
  953. size_t SW, size_t DH, size_t DW, size_t group, NLMode mode) {
  954. {
  955. // float case
  956. Checker<ConvBiasForward> checker(handle_cuda());
  957. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<
  958. ConvBias>(ExecutionPolicyAlgoName{
  959. ConvBiasForward::algo_name<ConvBiasForward::DirectParam>(
  960. "CUDA:GROUP_CONV", {})
  961. .c_str(),
  962. {{"CUDNN", {}}}}));
  963. ConvBias::Param param;
  964. param.sparse = ConvBias::Param::Sparse::GROUP;
  965. param.nonlineMode = mode;
  966. param.pad_h = PH;
  967. param.pad_w = PW;
  968. param.stride_h = SH;
  969. param.stride_w = SW;
  970. param.dilate_h = DH;
  971. param.dilate_w = DW;
  972. auto ICg = IC / group;
  973. auto OCg = OC / group;
  974. checker.set_param(param).exec({{N, IC, IH, IW},
  975. {group, OCg, ICg, FH, FW},
  976. {1, OCg * group, 1, 1},
  977. {},
  978. {}});
  979. }
  980. if (is_int_available) {
  981. // int 8x8x32 case
  982. Checker<ConvBiasForward> checker(handle_cuda());
  983. ConvBias::Param param;
  984. param.sparse = Convolution::Param::Sparse::GROUP;
  985. param.format = Convolution::Param::Format::NHWC;
  986. param.nonlineMode = NLMode::IDENTITY;
  987. param.pad_h = PH;
  988. param.pad_w = PW;
  989. param.stride_h = SH;
  990. param.stride_w = SW;
  991. param.dilate_h = DH;
  992. param.dilate_w = DW;
  993. auto ICg = IC / group;
  994. auto OCg = OC / group;
  995. UniformIntRNG rng(-4, 4);
  996. checker.set_param(param)
  997. .set_dtype(0, dtype::QuantizedS8(0.5f))
  998. .set_dtype(1, dtype::QuantizedS8(0.5f))
  999. .set_dtype(2, dtype::QuantizedS32(0.25f))
  1000. .set_dtype(3, dtype::QuantizedS8(0.13f))
  1001. .set_dtype(4, dtype::QuantizedS8(0.35f))
  1002. .set_rng(0, &rng)
  1003. .set_rng(1, &rng)
  1004. .set_rng(2, &rng)
  1005. .exec({{N, IH, IW, IC},
  1006. {group, OCg, FH, FW, ICg},
  1007. {1, 1, 1, OCg * group},
  1008. {},
  1009. {}});
  1010. }
  1011. };
  1012. for (NLMode nlmode :
  1013. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  1014. // normal case
  1015. run(2, 64, 7, 7, 3, 3, 32, 0, 0, 1, 1, 1, 1, 2, nlmode);
  1016. // padded case
  1017. run(2, 32, 7, 7, 3, 3, 64, 1, 1, 1, 1, 1, 1, 4, nlmode);
  1018. // strided case
  1019. run(2, 32, 7, 7, 3, 3, 64, 0, 0, 2, 2, 1, 1, 8, nlmode);
  1020. // dilated case
  1021. run(2, 32, 7, 7, 3, 3, 64, 0, 0, 1, 1, 2, 2, 8, nlmode);
  1022. }
  1023. }
  1024. #if CUDA_VERSION >= 10000
  1025. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_1) {
  1026. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 3);
  1027. }
  1028. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_2) {
  1029. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 5);
  1030. }
  1031. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_3) {
  1032. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 7);
  1033. }
  1034. #if MEGDNN_WITH_BENCHMARK
  1035. TEST_F(CUDA, BENCHMARK_CONV_BIAS_QUANTIZED4x4x32) {
  1036. require_compute_capability(7, 5);
  1037. Benchmarker<ConvBiasForward> bencher(handle_cuda());
  1038. UniformIntRNG int_rng{0, 8};
  1039. ConvBias::Param param;
  1040. param.format = ConvBias::Param::Format::NCHW8;
  1041. param.stride_h = param.stride_w = 1;
  1042. using NonlineMode = ConvBias::Param::NonlineMode;
  1043. param.nonlineMode = NonlineMode::RELU;
  1044. auto run_bench = [&](size_t batch, size_t ci, size_t hi, size_t wi,
  1045. size_t co, size_t fh, size_t fw, size_t nr_times) {
  1046. param.pad_h = fh / 2;
  1047. param.pad_w = fw / 2;
  1048. bencher.set_param(param)
  1049. .set_dtype(0, dtype::Quantized4Asymm(1.3f, (uint8_t)(1)))
  1050. .set_dtype(1, dtype::Quantized4Asymm(1.3f, (uint8_t)(2)))
  1051. .set_dtype(2, dtype::QuantizedS32(1.3f * 1.3f))
  1052. .set_dtype(4, dtype::QuantizedS32(1.3f * 1.3f))
  1053. .set_rng(0, &int_rng)
  1054. .set_rng(1, &int_rng)
  1055. .set_rng(2, &int_rng);
  1056. bencher.set_times(nr_times);
  1057. size_t ho = infer_conv_shape(hi, fh, 1, param.pad_h);
  1058. size_t wo = infer_conv_shape(wi, fw, 1, param.pad_w);
  1059. TensorShape inp{batch, ci / 8, hi, wi, 8}, kern{co, ci / 8, fh, fw, 8},
  1060. out{batch, co / 8, ho, wo, 8};
  1061. auto time_in_ms =
  1062. bencher.execs({inp, kern, {1, co / 8, 1, 1, 8}, {}, out}) /
  1063. nr_times;
  1064. auto ops = 2.0 * batch * co * ho * wo * ci * fh * fw /
  1065. (time_in_ms * 1e-3) * 1e-12;
  1066. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops\n",
  1067. inp.to_string().c_str(), kern.to_string().c_str(),
  1068. out.to_string().c_str(), time_in_ms, ops);
  1069. };
  1070. run_bench(256, 256, 16, 16, 256, 3, 3, 1000);
  1071. run_bench(1, 32, 224, 224, 64, 7, 7, 1000);
  1072. run_bench(1, 8192, 64, 64, 4096, 3, 3, 1000);
  1073. run_bench(1, 256, 64, 64, 256, 3, 3, 1000);
  1074. run_bench(1, 64, 128, 128, 64, 3, 3, 1000);
  1075. run_bench(1, 512, 32, 32, 512, 3, 3, 1000);
  1076. run_bench(1, 1024, 16, 16, 1024, 3, 3, 1000);
  1077. run_bench(1, 64, 56, 56, 64, 3, 3, 1000);
  1078. run_bench(1, 128, 32, 32, 128, 3, 3, 1000);
  1079. run_bench(1, 256, 16, 16, 256, 3, 3, 1000);
  1080. run_bench(1, 512, 8, 8, 512, 3, 3, 1000);
  1081. run_bench(32, 32, 224, 224, 64, 7, 7, 1000);
  1082. run_bench(32, 64, 56, 56, 64, 3, 3, 1000);
  1083. run_bench(32, 128, 32, 32, 128, 3, 3, 1000);
  1084. run_bench(32, 256, 16, 16, 256, 3, 3, 1000);
  1085. run_bench(32, 512, 8, 8, 512, 3, 3, 1000);
  1086. run_bench(256, 32, 224, 224, 64, 7, 7, 1000);
  1087. run_bench(256, 64, 56, 56, 64, 3, 3, 1000);
  1088. run_bench(256, 128, 32, 32, 128, 3, 3, 1000);
  1089. run_bench(256, 256, 16, 16, 256, 3, 3, 1000);
  1090. run_bench(256, 512, 8, 8, 512, 3, 3, 1000);
  1091. }
  1092. #endif
  1093. #endif
  1094. TEST_F(CUDA, CONV_BIAS_FORWARD_DILATED) {
  1095. require_compute_capability(6, 0);
  1096. auto run = [&](size_t N, size_t IC, size_t IH, size_t IW, size_t FH,
  1097. size_t FW, size_t OC, size_t PH, size_t PW, size_t SH,
  1098. size_t SW, size_t DH, size_t DW) {
  1099. {
  1100. // float case
  1101. Checker<ConvBiasForward> checker(handle_cuda());
  1102. ConvBias::Param param;
  1103. param.sparse = ConvBias::Param::Sparse::DENSE;
  1104. param.pad_h = PH;
  1105. param.pad_w = PW;
  1106. param.stride_h = SH;
  1107. param.stride_w = SW;
  1108. param.dilate_h = DH;
  1109. param.dilate_w = DW;
  1110. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  1111. checker.set_param(param).exec(
  1112. {{N, IC, IH, IW}, {OC, IC, FH, FW}, {1, OC, 1, 1}, {}, {}});
  1113. }
  1114. };
  1115. // dilated case
  1116. run(2, 8, 7, 7, 3, 3, 4, 0, 0, 1, 1, 2, 2);
  1117. }
  1118. #if CUDNN_VERSION >= 7500
  1119. TEST_F(CUDA, CONV_BIAS_FORWARD_TENSORCORE_INT8) {
  1120. require_compute_capability(7, 5);
  1121. using namespace conv_bias;
  1122. Checker<ConvBiasForward> checker(handle_cuda());
  1123. auto opr = handle_cuda()->create_operator<ConvBias>();
  1124. auto i8_min = std::numeric_limits<int8_t>().min();
  1125. auto i8_max = std::numeric_limits<int8_t>().max();
  1126. UniformIntRNG int_rng{i8_min, i8_max};
  1127. ConvBias::Param param;
  1128. param.format = ConvBias::Param::Format::NCHW32;
  1129. using NonlineMode = ConvBias::Param::NonlineMode;
  1130. for (NonlineMode mode : {NonlineMode::IDENTITY, NonlineMode::RELU}) {
  1131. for (size_t batch : {2}) {
  1132. for (size_t ic : {64, 32}) {
  1133. for (size_t oc : {32}) {
  1134. for (size_t fh : {3, 5, 7}) {
  1135. for (int ph : {static_cast<int>(fh / 2), 0}) {
  1136. for (int sh : {1, 2}) {
  1137. for (size_t ih : {9, 11, 12, 13, 16}) {
  1138. for (size_t iw : {8, 27, 32, 40}) {
  1139. param.nonlineMode = mode;
  1140. param.stride_h = param.stride_w = sh;
  1141. param.pad_h = param.pad_w = ph;
  1142. opr->param() = param;
  1143. TensorLayout dst_layout;
  1144. opr->deduce_layout(
  1145. {{batch, ic / 32, ih, iw, 32},
  1146. dtype::Float32()},
  1147. {{oc, ic / 32, fh, fh, 32},
  1148. dtype::Float32()},
  1149. {}, {}, dst_layout);
  1150. checker.set_dtype(0, dtype::QuantizedS8(
  1151. 1.3f))
  1152. .set_dtype(1,
  1153. dtype::QuantizedS8(
  1154. 1.3f))
  1155. .set_dtype(2,
  1156. dtype::QuantizedS32(
  1157. 1.3f * 1.3f))
  1158. .set_dtype(3,
  1159. dtype::QuantizedS8(
  1160. 1.7f))
  1161. .set_dtype(4,
  1162. dtype::QuantizedS8(
  1163. 1.2f * 1.2f))
  1164. .set_rng(0, &int_rng)
  1165. .set_rng(1, &int_rng)
  1166. .set_rng(2, &int_rng)
  1167. .set_rng(3, &int_rng)
  1168. .set_epsilon(1 + 1e-3)
  1169. .set_param(param)
  1170. .execs({{batch, ic / 32, ih, iw,
  1171. 32},
  1172. {oc, ic / 32, fh, fh,
  1173. 32},
  1174. {1, oc / 32, 1, 1, 32},
  1175. dst_layout,
  1176. {}});
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. }
  1187. #if MEGDNN_WITH_BENCHMARK
  1188. TEST_F(CUDA, BENCHMARK_CONV_BIAS_FORWARD_TENSORCORE_INT8) {
  1189. require_compute_capability(7, 5);
  1190. Benchmarker<ConvBiasForward> bencher(handle_cuda());
  1191. bencher.set_display(false);
  1192. ConvBias::Param param;
  1193. param.format = ConvBias::Param::Format::NCHW32;
  1194. ConvBias::Param param_without_tensorcore;
  1195. param_without_tensorcore.format = ConvBias::Param::Format::NCHW4;
  1196. auto i8_min = std::numeric_limits<int8_t>().min();
  1197. auto i8_max = std::numeric_limits<int8_t>().max();
  1198. UniformIntRNG int_rng{i8_min, i8_max};
  1199. using NonlineMode = ConvBias::Param::NonlineMode;
  1200. param.nonlineMode = NonlineMode::IDENTITY;
  1201. auto run_bench = [&](size_t batch, size_t ci, size_t hi, size_t wi,
  1202. size_t co, size_t fh, size_t fw, size_t sh, size_t sw,
  1203. size_t nr_times) {
  1204. param.pad_h = fh / 2;
  1205. param.pad_w = fw / 2;
  1206. param.stride_h = sh;
  1207. param.stride_w = sw;
  1208. param_without_tensorcore.pad_h = fh / 2;
  1209. param_without_tensorcore.pad_w = fw / 2;
  1210. param_without_tensorcore.stride_h = sh;
  1211. param_without_tensorcore.stride_w = sw;
  1212. bencher.set_param(param)
  1213. .set_dtype(0, dtype::QuantizedS8(1.3f))
  1214. .set_dtype(1, dtype::QuantizedS8(1.3f))
  1215. .set_dtype(2, dtype::QuantizedS32(1.3f * 1.3f))
  1216. .set_dtype(4, dtype::QuantizedS8(1.2f))
  1217. .set_rng(0, &int_rng)
  1218. .set_rng(1, &int_rng)
  1219. .set_rng(2, &int_rng);
  1220. bencher.set_times(nr_times);
  1221. size_t ho = infer_conv_shape(hi, fh, sh, param.pad_h);
  1222. size_t wo = infer_conv_shape(wi, fw, sw, param.pad_w);
  1223. TensorShape inp{batch, ci / 32, hi, wi, 32},
  1224. kern{co, ci / 32, fh, fw, 32}, out{batch, co / 32, ho, wo, 32};
  1225. auto time_in_ms =
  1226. bencher.execs({inp, kern, {1, co / 32, 1, 1, 32}, {}, out}) /
  1227. nr_times;
  1228. auto ops = 2.0 * batch * co * ho * wo * ci * fh * fw /
  1229. (time_in_ms * 1e-3) * 1e-12;
  1230. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops "
  1231. "(TensorCore)",
  1232. inp.to_string().c_str(), kern.to_string().c_str(),
  1233. out.to_string().c_str(), time_in_ms, ops);
  1234. decltype(ops) ops_without_tensorcore;
  1235. bencher.set_param(param_without_tensorcore);
  1236. {
  1237. TensorShape inp{batch, ci / 4, hi, wi, 4},
  1238. kern{co, ci / 4, fh, fw, 4}, out{batch, co / 4, ho, wo, 4};
  1239. auto time_in_ms =
  1240. bencher.execs({inp, kern, {1, co / 4, 1, 1, 4}, {}, out}) /
  1241. nr_times;
  1242. ops_without_tensorcore = 2.0 * batch * co * ho * wo * ci * fh * fw /
  1243. (time_in_ms * 1e-3) * 1e-12;
  1244. printf(", time: %.2fms perf: %.2f Tops (without TensorCore) ",
  1245. time_in_ms, ops_without_tensorcore);
  1246. }
  1247. printf("speedup: %.2fx\n", ops / ops_without_tensorcore);
  1248. };
  1249. // resnet-50
  1250. // bottleneck-1
  1251. // proj
  1252. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1253. run_bench(1, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  1254. run_bench(1, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  1255. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1256. // bottleneck-2
  1257. // proj
  1258. run_bench(1, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  1259. run_bench(1, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  1260. run_bench(1, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  1261. run_bench(1, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  1262. // bottleneck-3
  1263. // proj
  1264. run_bench(1, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  1265. run_bench(1, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  1266. run_bench(1, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  1267. run_bench(1, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  1268. // bottleneck-4
  1269. // proj
  1270. run_bench(1, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  1271. run_bench(1, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  1272. run_bench(1, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  1273. run_bench(1, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  1274. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1275. run_bench(32, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  1276. run_bench(32, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  1277. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1278. run_bench(32, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  1279. run_bench(32, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  1280. run_bench(32, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  1281. run_bench(32, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  1282. run_bench(32, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  1283. run_bench(32, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  1284. run_bench(32, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  1285. run_bench(32, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  1286. run_bench(32, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  1287. run_bench(32, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  1288. run_bench(32, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  1289. run_bench(32, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  1290. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1291. run_bench(256, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  1292. run_bench(256, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  1293. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  1294. run_bench(256, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  1295. run_bench(256, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  1296. run_bench(256, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  1297. run_bench(256, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  1298. run_bench(256, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  1299. run_bench(256, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  1300. run_bench(256, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  1301. run_bench(256, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  1302. run_bench(256, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  1303. run_bench(256, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  1304. run_bench(256, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  1305. run_bench(256, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  1306. }
  1307. #endif
  1308. #endif
  1309. // vim: syntax=cpp.doxygen

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