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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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-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 implied.
  10. */
  11. #include "test/cuda/fixture.h"
  12. #include "megdnn/opr_param_defs.h"
  13. #include "megdnn/oprs.h"
  14. #include "src/cuda/handle.h"
  15. #include "test/common/benchmarker.h"
  16. #include "test/common/checker.h"
  17. #include "test/common/conv_bias.h"
  18. #include "test/common/rng.h"
  19. #include "test/common/tensor.h"
  20. #include "test/common/workspace_wrapper.h"
  21. #include "test/cuda/utils.h"
  22. using namespace megdnn;
  23. using namespace test;
  24. using namespace conv_bias;
  25. namespace {
  26. #if CUDA_VERSION >= 10000
  27. void test_conv_bias_forward_wmma_int4_nchw8(Handle* handle_cuda, size_t fh) {
  28. require_compute_capability(7, 5);
  29. using namespace conv_bias;
  30. Checker<ConvBiasForward> checker(handle_cuda);
  31. UniformIntRNG int_rng{0, 8};
  32. ConvBias::Param param;
  33. param.format = ConvBias::Param::Format::NCHW8;
  34. using NonlineMode = ConvBias::Param::NonlineMode;
  35. for (NonlineMode mode : {NonlineMode::RELU}) {
  36. for (size_t batch : {1}) {
  37. for (size_t ic : {128, 32}) {
  38. for (size_t oc : {32}) {
  39. for (int ph : {static_cast<int>(fh / 2), 0}) {
  40. for (size_t ih : {8, 9, 13, 15, 16}) {
  41. for (size_t iw : {8, 16, 24, 32, 40}) {
  42. param.nonlineMode = mode;
  43. param.stride_h = param.stride_w = 1;
  44. param.pad_h = param.pad_w = ph;
  45. checker.set_dtype(0,
  46. dtype::Quantized4Asymm(
  47. 1.3f, (uint8_t)(1)))
  48. .set_dtype(1,
  49. dtype::Quantized4Asymm(
  50. 1.3f, (uint8_t)(2)))
  51. .set_dtype(2, dtype::QuantizedS32(1.3f *
  52. 1.3f))
  53. .set_dtype(4, dtype::QuantizedS32(1.3f *
  54. 1.3f))
  55. .set_rng(0, &int_rng)
  56. .set_rng(1, &int_rng)
  57. .set_rng(2, &int_rng)
  58. .set_param(param);
  59. if (!ph)
  60. iw += 2 * (fh / 2);
  61. size_t oh = infer_conv_shape(ih, fh, 1, ph);
  62. size_t ow = infer_conv_shape(iw, fh, 1, ph);
  63. if (ow % 8 != 0)
  64. continue;
  65. checker.execs({{batch, ic / 8, ih, iw, 8},
  66. {oc, ic / 8, fh, fh, 8},
  67. {1, oc / 8, 1, 1, 8},
  68. {},
  69. {}});
  70. checker.execs({{batch, ic / 8, ih, iw, 8},
  71. {oc, ic / 8, fh, fh, 8},
  72. {batch, oc / 8, oh, ow, 8},
  73. {},
  74. {}});
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. #endif
  84. } // namespace
  85. #if CUDNN_VERSION >= 7400
  86. TEST_F(CUDA, CONV_BIAS_FORWARD_F32) {
  87. using namespace conv_bias;
  88. std::vector<TestArg> args = get_args();
  89. Checker<ConvBiasForward> checker(handle_cuda());
  90. NormalRNG default_rng;
  91. for (auto&& arg : args) {
  92. checker.set_dtype(0, dtype::Float32())
  93. .set_dtype(1, dtype::Float32())
  94. .set_dtype(2, dtype::Float32())
  95. .set_rng(0, &default_rng)
  96. .set_rng(1, &default_rng)
  97. .set_rng(2, &default_rng)
  98. .set_epsilon(1e-3)
  99. .set_param(arg.param)
  100. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  101. }
  102. }
  103. TEST_F(CUDA, CONV_BIAS_FORWARD_QS8) {
  104. require_compute_capability(6, 1);
  105. UniformIntRNG int_rng{-50, 50};
  106. Checker<ConvBiasForward> checker(handle_cuda());
  107. ConvBias::Param param;
  108. param.format = ConvBias::Param::Format::NHWC;
  109. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  110. {
  111. auto src_shape = TensorShape{20, 224, 224, 4};
  112. auto filter_shape = TensorShape{24, 1, 1, 4};
  113. auto bias_shape = TensorShape{1, 1, 1, 24};
  114. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  115. .set_dtype(1, dtype::QuantizedS8(2.5f))
  116. .set_dtype(2, dtype::QuantizedS32(6.25f))
  117. .set_dtype(4, dtype::QuantizedS8(60.25f))
  118. .set_rng(0, &int_rng)
  119. .set_rng(1, &int_rng)
  120. .set_rng(2, &int_rng)
  121. .set_param(param)
  122. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  123. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  124. .set_dtype(1, dtype::QuantizedS8(2.5f))
  125. .set_dtype(2, dtype::QuantizedS32(6.25f))
  126. .set_dtype(4, dtype::QuantizedS8(40.25f))
  127. .set_rng(0, &int_rng)
  128. .set_rng(1, &int_rng)
  129. .set_rng(2, &int_rng)
  130. .set_param(param)
  131. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  132. }
  133. {
  134. auto src_shape = TensorShape{20, 224, 224, 4};
  135. auto filter_shape = TensorShape{24, 1, 1, 4};
  136. auto bias_shape = TensorShape{1, 1, 1, 24};
  137. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  138. .set_dtype(1, dtype::QuantizedS8(2.5f))
  139. .set_dtype(2, dtype::QuantizedS32(6.25f))
  140. .set_dtype(4, dtype::QuantizedS8(60.25f))
  141. .set_rng(0, &int_rng)
  142. .set_rng(1, &int_rng)
  143. .set_rng(2, &int_rng)
  144. .set_param(param)
  145. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  146. checker.set_dtype(0, dtype::QuantizedS8(2.5f))
  147. .set_dtype(1, dtype::QuantizedS8(2.5f))
  148. .set_dtype(2, dtype::QuantizedS32(6.25f))
  149. .set_dtype(4, dtype::QuantizedS8(40.25f))
  150. .set_rng(0, &int_rng)
  151. .set_rng(1, &int_rng)
  152. .set_rng(2, &int_rng)
  153. .set_param(param)
  154. .execs({src_shape, filter_shape, bias_shape, {}, {}});
  155. }
  156. {
  157. param.sparse = ConvBias::Param::Sparse::GROUP;
  158. auto src_shape = TensorShape{20, 224, 224, 16};
  159. auto filter_shape = TensorShape{4, 4, 1, 1, 4};
  160. auto bias_shape = TensorShape{1, 1, 1, 16};
  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. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW4) {
  182. require_compute_capability(6, 1);
  183. using namespace conv_bias;
  184. Checker<ConvBiasForward> checker(handle_cuda());
  185. UniformIntRNG int_rng{-5, 5};
  186. ConvBias::Param param;
  187. param.format = ConvBias::Param::Format::NCHW4;
  188. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  189. checker.set_dtype(0, dtype::QuantizedS8(0.5f))
  190. .set_dtype(1, dtype::QuantizedS8(0.5f))
  191. .set_dtype(2, dtype::QuantizedS32(0.25f))
  192. .set_dtype(3, dtype::QuantizedS8(0.13f))
  193. .set_dtype(4, dtype::QuantizedS8(0.35f))
  194. .set_rng(0, &int_rng)
  195. .set_rng(1, &int_rng)
  196. .set_rng(2, &int_rng)
  197. .set_rng(3, &int_rng)
  198. .set_param(param);
  199. auto opr = handle_cuda()->create_operator<ConvBias>();
  200. auto run = [&](const TensorShapeArray& shapes) {
  201. opr->param() = param;
  202. TensorLayout dst_layout;
  203. opr->deduce_layout({shapes[0], dtype::Float32()},
  204. {shapes[1], dtype::Float32()}, {}, {}, dst_layout);
  205. checker.execs({shapes[0], shapes[1], shapes[2], dst_layout, {}});
  206. };
  207. run({{1, 4, 4, 4, 4}, {4, 4, 3, 3, 4}, {1, 1, 1, 1, 4}});
  208. run({{20, 1, 24, 24, 4}, {24, 1, 2, 2, 4}, {1, 6, 1, 1, 4}});
  209. run({{20, 2, 24, 24, 4}, {24, 2, 3, 3, 4}, {1, 6, 1, 1, 4}});
  210. param.sparse = ConvBias::Param::Sparse::GROUP;
  211. checker.set_param(param);
  212. run({{1, 4, 24, 24, 4}, {4, 4, 1, 1, 1, 4}, {1, 4, 1, 1, 4}});
  213. run({{20, 8, 24, 24, 4}, {4, 24, 2, 2, 2, 4}, {1, 24, 1, 1, 4}});
  214. run({{1, 3, 24, 24, 4}, {3, 8, 1, 3, 3, 4}, {1, 6, 1, 1, 4}});
  215. param.pad_h = param.pad_w = 1;
  216. param.stride_h = param.stride_w = 2;
  217. checker.set_param(param);
  218. run({{10, 16, 28, 28, 4}, {8, 8, 2, 3, 3, 4}, {1, 16, 1, 1, 4}});
  219. // case which cudnn not supported
  220. param.sparse = ConvBias::Param::Sparse::DENSE;
  221. param.pad_h = param.pad_w = 1;
  222. param.stride_h = param.stride_w = 1;
  223. checker.set_param(param);
  224. checker.exec({{1, 4, 2, 2, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  225. }
  226. #endif
  227. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE) {
  228. Checker<ConvBiasForward> checker(handle_cuda());
  229. std::vector<TestArg> args = get_chanwise_args();
  230. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  231. ConvBiasForward::algo_name<ConvBias::DirectParam>("CHANNEL_WISE",
  232. {})
  233. .c_str()));
  234. for (auto dtype : std::vector<DType>{dtype::Float32(), dtype::Float16()}) {
  235. checker.set_dtype(0, dtype)
  236. .set_dtype(1, dtype)
  237. .set_dtype(2, dtype)
  238. .set_dtype(3, dtype)
  239. .set_dtype(4, dtype);
  240. if (dtype.enumv() == DTypeEnum::Float16)
  241. checker.set_epsilon(2e-2);
  242. for (auto&& arg : args) {
  243. checker.set_param(arg.param).execs(
  244. {arg.src, arg.filter, arg.bias, {}, {}});
  245. }
  246. }
  247. }
  248. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE_SMALL) {
  249. Checker<ConvBiasForward> checker(handle_cuda());
  250. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  251. ConvBiasForward::algo_name<ConvBias::DirectParam>(
  252. "CHANNEL_WISE_SMALL", {})
  253. .c_str()));
  254. param::ConvBias cur_param;
  255. using NLMode = param::ConvBias::NonlineMode;
  256. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  257. cur_param.sparse = ConvBias::Param::Sparse::GROUP;
  258. for (auto nlmode :
  259. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  260. cur_param.nonlineMode = nlmode;
  261. for (auto dtype : std::vector<DType> {
  262. dtype::Float32(),
  263. #if CUDA_VERSION >= 9000
  264. dtype::Float16()
  265. #endif
  266. }) {
  267. checker.set_dtype(0, dtype)
  268. .set_dtype(1, dtype)
  269. .set_dtype(2, dtype)
  270. .set_dtype(3, dtype)
  271. .set_dtype(4, dtype);
  272. if (dtype.enumv() == DTypeEnum::Float16)
  273. checker.set_epsilon(2e-2);
  274. for (uint32_t s : {1}) {
  275. for (uint32_t f : {1, 3, 5, 7}) {
  276. cur_param.pad_h = cur_param.pad_w = f / 2;
  277. cur_param.stride_h = cur_param.stride_w = s;
  278. checker.set_param(cur_param).execs({{2, 3, 16, 16},
  279. {3, 1, 1, f, f},
  280. {1, 3, 1, 1},
  281. {},
  282. {}});
  283. }
  284. }
  285. cur_param.pad_h = cur_param.pad_w = 1;
  286. cur_param.stride_h = cur_param.stride_w = 1;
  287. checker.set_param(cur_param)
  288. .execs({{2, 3, 3, 16},
  289. {3, 1, 1, 3, 3},
  290. {1, 3, 1, 1},
  291. {},
  292. {}})
  293. .execs({{2, 3, 8, 3},
  294. {3, 1, 1, 3, 3},
  295. {1, 3, 1, 1},
  296. {},
  297. {}});
  298. }
  299. }
  300. }
  301. TEST_F(CUDA, CONV_BIAS_FORWARD_CHANWISE_8x8x32) {
  302. require_compute_capability(6, 1);
  303. Checker<ConvBiasForward> checker(handle_cuda());
  304. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  305. ConvBiasForward::algo_name<ConvBias::DirectParam>(
  306. "CHANNEL_WISE_8X8X32", {})
  307. .c_str()));
  308. param::ConvBias cur_param;
  309. using NLMode = param::ConvBias::NonlineMode;
  310. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  311. cur_param.sparse = ConvBias::Param::Sparse::GROUP;
  312. cur_param.format = ConvBias::Param::Format::NHWC;
  313. UniformIntRNG rng(-4, 4);
  314. checker.set_dtype(0, dtype::Int8{})
  315. .set_dtype(1, dtype::Int8{})
  316. .set_dtype(2, dtype::Int32{})
  317. .set_dtype(4, dtype::Int32{})
  318. .set_rng(0, &rng)
  319. .set_rng(1, &rng)
  320. .set_rng(2, &rng);
  321. for (auto nlmode : {NLMode::IDENTITY, NLMode::RELU}) {
  322. cur_param.nonlineMode = nlmode;
  323. for (uint32_t s : {1, 2}) {
  324. for (uint32_t f : {1, 3, 5, 7}) {
  325. for (uint32_t g : {4, 8}) {
  326. cur_param.pad_h = cur_param.pad_w = f / 2;
  327. cur_param.stride_h = cur_param.stride_w = s;
  328. checker.set_param(cur_param).execs({{2, 9, 16, g},
  329. {g, 1, f, f, 1},
  330. {1, 1, 1, g},
  331. {},
  332. {}});
  333. }
  334. }
  335. }
  336. }
  337. }
  338. TEST_F(CUDA, CONV_BIAS_FORWARD_CUDNN_CONVOLUTION) {
  339. using namespace conv_bias;
  340. std::vector<TestArg> args = get_args();
  341. Checker<ConvBiasForward> checker(handle_cuda());
  342. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  343. ConvBiasForward::algo_name<ConvBias::DefaultParam>(
  344. "CUDNN:Convolution", {})
  345. .c_str()));
  346. NormalRNG default_rng;
  347. for (auto&& arg : args) {
  348. checker.set_dtype(0, dtype::Float32())
  349. .set_dtype(1, dtype::Float32())
  350. .set_dtype(2, dtype::Float32())
  351. .set_rng(0, &default_rng)
  352. .set_rng(1, &default_rng)
  353. .set_rng(2, &default_rng)
  354. .set_epsilon(1e-3)
  355. .set_param(arg.param)
  356. .execs({arg.src, arg.filter, arg.bias, {}, {}});
  357. }
  358. }
  359. TEST_F(CUDA, CONV_BIAS_FORWARD_INPLACE_MATMUL) {
  360. using namespace conv_bias;
  361. std::vector<TestArg> args = get_args();
  362. Checker<ConvBiasForward> checker(handle_cuda());
  363. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  364. ConvBiasForward::algo_name<ConvBias::MatmulParam>("INPLACE_MATMUL",
  365. {})
  366. .c_str()));
  367. param::ConvBias cur_param;
  368. using NLMode = param::ConvBias::NonlineMode;
  369. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  370. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  371. NormalRNG default_rng;
  372. checker.set_dtype(0, dtype::Float32())
  373. .set_dtype(1, dtype::Float32())
  374. .set_dtype(2, dtype::Float32())
  375. .set_rng(0, &default_rng)
  376. .set_rng(1, &default_rng)
  377. .set_rng(2, &default_rng)
  378. .set_epsilon(1e-3);
  379. for (auto nlmode :
  380. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  381. cur_param.nonlineMode = nlmode;
  382. for (uint32_t s : {1}) {
  383. for (uint32_t f : {1, 3, 5, 7}) {
  384. cur_param.pad_h = cur_param.pad_w = f / 2;
  385. cur_param.stride_h = cur_param.stride_w = s;
  386. checker.set_param(cur_param).execs(
  387. {{2, 4, 16, 16}, {4, 4, f, f}, {1, 4, 1, 1}, {}, {}});
  388. }
  389. }
  390. cur_param.pad_h = cur_param.pad_w = 1;
  391. cur_param.stride_h = cur_param.stride_w = 1;
  392. checker.set_param(cur_param)
  393. .execs({{2, 3, 3, 16}, {5, 3, 3, 3}, {1, 5, 1, 1}, {}, {}})
  394. .execs({{2, 2, 8, 3}, {3, 2, 3, 3}, {1, 3, 1, 1}, {}, {}});
  395. }
  396. }
  397. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL) {
  398. using namespace conv_bias;
  399. std::vector<TestArg> args = get_args();
  400. Checker<ConvBiasForward> checker(handle_cuda());
  401. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  402. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>("MATMUL",
  403. {})
  404. .c_str()));
  405. param::ConvBias cur_param;
  406. using NLMode = param::ConvBias::NonlineMode;
  407. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  408. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  409. NormalRNG default_rng;
  410. checker.set_dtype(0, dtype::Float32())
  411. .set_dtype(1, dtype::Float32())
  412. .set_dtype(2, dtype::Float32())
  413. .set_rng(0, &default_rng)
  414. .set_rng(1, &default_rng)
  415. .set_rng(2, &default_rng)
  416. .set_epsilon(1e-3);
  417. for (auto nlmode :
  418. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  419. cur_param.nonlineMode = nlmode;
  420. for (uint32_t s : {1}) {
  421. for (uint32_t f : {1, 3, 5, 7}) {
  422. cur_param.pad_h = cur_param.pad_w = f / 2;
  423. cur_param.stride_h = cur_param.stride_w = s;
  424. checker.set_param(cur_param).execs(
  425. {{2, 4, 16, 16}, {4, 4, f, f}, {1, 4, 1, 1}, {}, {}});
  426. }
  427. }
  428. cur_param.pad_h = cur_param.pad_w = 0;
  429. cur_param.stride_h = cur_param.stride_w = 1;
  430. checker.set_param(cur_param)
  431. .execs({{2, 3, 3, 16}, {5, 3, 3, 3}, {1, 5, 1, 1}, {}, {}})
  432. .execs({{2, 2, 8, 3}, {3, 2, 3, 3}, {1, 3, 1, 1}, {}, {}});
  433. }
  434. }
  435. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL_8x8x32) {
  436. require_compute_capability(6, 1);
  437. Checker<ConvBiasForward> checker(handle_cuda());
  438. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  439. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  440. "MATMUL8X8X32", {})
  441. .c_str()));
  442. param::ConvBias cur_param;
  443. using NLMode = param::ConvBias::NonlineMode;
  444. cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
  445. cur_param.sparse = ConvBias::Param::Sparse::DENSE;
  446. cur_param.format = param::ConvBias::Format::NHWC;
  447. UniformIntRNG rng{-100, 100};
  448. UniformIntRNG bias_rng{-1000, 1000};
  449. checker.set_rng(0, &rng)
  450. .set_rng(1, &rng)
  451. .set_rng(2, &bias_rng)
  452. .set_rng(3, &rng)
  453. .set_dtype(0, dtype::QuantizedS8{1.2f})
  454. .set_dtype(1, dtype::QuantizedS8{1.3f})
  455. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  456. .set_dtype(3, dtype::QuantizedS8{1.1f})
  457. .set_dtype(4, dtype::QuantizedS8{1.0f})
  458. .set_epsilon(1);
  459. for (auto nlmode : {NLMode::IDENTITY, NLMode::RELU}) {
  460. cur_param.nonlineMode = nlmode;
  461. for (uint32_t s : {1}) {
  462. for (uint32_t f : {1, 3, 5, 7}) {
  463. cur_param.pad_h = cur_param.pad_w = f / 2;
  464. cur_param.stride_h = cur_param.stride_w = s;
  465. checker.set_param(cur_param).execs(
  466. {{2, 16, 16, 4}, {4, f, f, 4}, {1, 1, 1, 4}, {}, {}});
  467. }
  468. }
  469. cur_param.pad_h = cur_param.pad_w = 0;
  470. cur_param.stride_h = cur_param.stride_w = 1;
  471. checker.set_param(cur_param)
  472. .execs({{2, 3, 16, 3}, {5, 3, 3, 3}, {1, 1, 1, 5}, {}, {}})
  473. .execs({{2, 8, 3, 2}, {3, 3, 3, 2}, {1, 1, 1, 3}, {}, {}});
  474. }
  475. }
  476. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL_NCHW4) {
  477. require_compute_capability(6, 1);
  478. Checker<ConvBiasForward> checker(handle_cuda());
  479. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
  480. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  481. "MATMUL8X8X32", {})
  482. .c_str()));
  483. UniformIntRNG int_rng{-127, 127};
  484. ConvBias::Param param;
  485. param.format = ConvBias::Param::Format::NCHW4;
  486. using NLMode = ConvBias::Param::NonlineMode;
  487. checker.set_dtype(0, dtype::QuantizedS8(0.5f))
  488. .set_dtype(1, dtype::QuantizedS8(0.5f))
  489. .set_dtype(2, dtype::QuantizedS32(0.25f))
  490. .set_dtype(4, dtype::QuantizedS8(0.35f))
  491. .set_rng(0, &int_rng)
  492. .set_rng(1, &int_rng)
  493. .set_rng(2, &int_rng);
  494. param.sparse = Convolution::Param::Sparse::DENSE;
  495. param.nonlineMode = NLMode::IDENTITY;
  496. param.pad_h = param.pad_w = 1;
  497. param.stride_h = param.stride_w = 1;
  498. checker.set_param(param);
  499. checker.exec(
  500. {{8, 4, 10, 10, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  501. checker.exec({{1, 4, 2, 2, 4}, {16, 4, 3, 3, 4}, {1, 4, 1, 1, 4}, {}, {}});
  502. checker.exec(
  503. {{8, 64, 12, 12, 4}, {256, 64, 3, 3, 4}, {1, 64, 1, 1, 4}, {}, {}});
  504. }
  505. TEST_F(CUDA, CONV_BIAS_FORWARD_MATMUL_1x1) {
  506. using namespace conv_bias;
  507. std::vector<TestArg> args = get_args_1x1();
  508. Checker<ConvBiasForward> checker(handle_cuda());
  509. NormalRNG default_rng;
  510. checker.set_dtype(0, dtype::Float32())
  511. .set_dtype(1, dtype::Float32())
  512. .set_dtype(2, dtype::Float32())
  513. .set_rng(0, &default_rng)
  514. .set_rng(1, &default_rng)
  515. .set_rng(2, &default_rng)
  516. .set_epsilon(1e-3);
  517. for (auto&& arg : args) {
  518. checker.set_param(arg.param);
  519. checker.set_before_exec_callback(
  520. conv_bias::ConvBiasAlgoChecker<ConvBias>(
  521. ConvBiasForward::algo_name<
  522. ConvBiasForward::MatmulParam>("MATMUL1X1", {})
  523. .c_str()));
  524. checker.execs({arg.src, arg.filter, arg.bias, {}, {}});
  525. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<
  526. ConvBias>(
  527. ConvBiasForward::algo_name<ConvBiasForward::MatmulParam>(
  528. "BATCHEDMATMUL", {})
  529. .c_str()));
  530. checker.execs({arg.src, arg.filter, arg.bias, {}, {}});
  531. }
  532. }
  533. TEST_F(CUDA, CONV_BIAS_FORWARD_GROUP) {
  534. using NLMode = ConvBias::Param::NonlineMode;
  535. bool is_int_available = false;
  536. if (megdnn::test::check_compute_capability((6), (0))) {
  537. is_int_available = true;
  538. } else {
  539. is_int_available = false;
  540. }
  541. auto run = [&](size_t N, size_t IC, size_t IH, size_t IW, size_t FH,
  542. size_t FW, size_t OC, size_t PH, size_t PW, size_t SH,
  543. size_t SW, size_t DH, size_t DW, size_t group, NLMode mode) {
  544. {
  545. // float case
  546. Checker<ConvBiasForward> checker(handle_cuda());
  547. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<
  548. ConvBias>(
  549. ConvBiasForward::algo_name<ConvBiasForward::DirectParam>(
  550. "CUDA:GROUP_CONV", {})
  551. .c_str()));
  552. ConvBias::Param param;
  553. param.sparse = ConvBias::Param::Sparse::GROUP;
  554. param.nonlineMode = mode;
  555. param.pad_h = PH;
  556. param.pad_w = PW;
  557. param.stride_h = SH;
  558. param.stride_w = SW;
  559. param.dilate_h = DH;
  560. param.dilate_w = DW;
  561. auto ICg = IC / group;
  562. auto OCg = OC / group;
  563. checker.set_param(param).exec({{N, IC, IH, IW},
  564. {group, OCg, ICg, FH, FW},
  565. {1, OCg * group, 1, 1},
  566. {},
  567. {}});
  568. }
  569. if (is_int_available) {
  570. // int 8x8x32 case
  571. Checker<ConvBiasForward> checker(handle_cuda());
  572. ConvBias::Param param;
  573. param.sparse = Convolution::Param::Sparse::GROUP;
  574. param.format = Convolution::Param::Format::NHWC;
  575. param.nonlineMode = NLMode::IDENTITY;
  576. param.pad_h = PH;
  577. param.pad_w = PW;
  578. param.stride_h = SH;
  579. param.stride_w = SW;
  580. param.dilate_h = DH;
  581. param.dilate_w = DW;
  582. auto ICg = IC / group;
  583. auto OCg = OC / group;
  584. UniformIntRNG rng(-4, 4);
  585. checker.set_param(param)
  586. .set_dtype(0, dtype::QuantizedS8(0.5f))
  587. .set_dtype(1, dtype::QuantizedS8(0.5f))
  588. .set_dtype(2, dtype::QuantizedS32(0.25f))
  589. .set_dtype(3, dtype::QuantizedS8(0.13f))
  590. .set_dtype(4, dtype::QuantizedS8(0.35f))
  591. .set_rng(0, &rng)
  592. .set_rng(1, &rng)
  593. .set_rng(2, &rng)
  594. .exec({{N, IH, IW, IC},
  595. {group, OCg, FH, FW, ICg},
  596. {1, 1, 1, OCg * group},
  597. {},
  598. {}});
  599. }
  600. };
  601. for (NLMode nlmode :
  602. {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
  603. // normal case
  604. run(2, 64, 7, 7, 3, 3, 32, 0, 0, 1, 1, 1, 1, 2, nlmode);
  605. // padded case
  606. run(2, 32, 7, 7, 3, 3, 64, 1, 1, 1, 1, 1, 1, 4, nlmode);
  607. // strided case
  608. run(2, 32, 7, 7, 3, 3, 64, 0, 0, 2, 2, 1, 1, 8, nlmode);
  609. // dilated case
  610. run(2, 32, 7, 7, 3, 3, 64, 0, 0, 1, 1, 2, 2, 8, nlmode);
  611. }
  612. }
  613. #if CUDA_VERSION >= 10000
  614. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_1) {
  615. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 3);
  616. }
  617. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_2) {
  618. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 5);
  619. }
  620. TEST_F(CUDA, CONV_BIAS_FORWARD_NCHW8_PART_3) {
  621. test_conv_bias_forward_wmma_int4_nchw8(handle_cuda(), 7);
  622. }
  623. #if MEGDNN_WITH_BENCHMARK
  624. TEST_F(CUDA, BENCHMARK_CONV_BIAS_QUANTIZED4x4x32) {
  625. require_compute_capability(7, 5);
  626. Benchmarker<ConvBiasForward> bencher(handle_cuda());
  627. UniformIntRNG int_rng{0, 8};
  628. ConvBias::Param param;
  629. param.format = ConvBias::Param::Format::NCHW8;
  630. param.stride_h = param.stride_w = 1;
  631. using NonlineMode = ConvBias::Param::NonlineMode;
  632. param.nonlineMode = NonlineMode::RELU;
  633. auto run_bench = [&](size_t batch, size_t ci, size_t hi, size_t wi,
  634. size_t co, size_t fh, size_t fw, size_t nr_times) {
  635. param.pad_h = fh / 2;
  636. param.pad_w = fw / 2;
  637. bencher.set_param(param)
  638. .set_dtype(0, dtype::Quantized4Asymm(1.3f, (uint8_t)(1)))
  639. .set_dtype(1, dtype::Quantized4Asymm(1.3f, (uint8_t)(2)))
  640. .set_dtype(2, dtype::QuantizedS32(1.3f * 1.3f))
  641. .set_dtype(4, dtype::QuantizedS32(1.3f * 1.3f))
  642. .set_rng(0, &int_rng)
  643. .set_rng(1, &int_rng)
  644. .set_rng(2, &int_rng);
  645. bencher.set_times(nr_times);
  646. size_t ho = infer_conv_shape(hi, fh, 1, param.pad_h);
  647. size_t wo = infer_conv_shape(wi, fw, 1, param.pad_w);
  648. TensorShape inp{batch, ci / 8, hi, wi, 8}, kern{co, ci / 8, fh, fw, 8},
  649. out{batch, co / 8, ho, wo, 8};
  650. auto time_in_ms =
  651. bencher.execs({inp, kern, {1, co / 8, 1, 1, 8}, {}, out}) /
  652. nr_times;
  653. auto ops = 2.0 * batch * co * ho * wo * ci * fh * fw /
  654. (time_in_ms * 1e-3) * 1e-12;
  655. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops\n",
  656. inp.to_string().c_str(), kern.to_string().c_str(),
  657. out.to_string().c_str(), time_in_ms, ops);
  658. };
  659. run_bench(256, 256, 16, 16, 256, 3, 3, 1000);
  660. run_bench(1, 32, 224, 224, 64, 7, 7, 1000);
  661. run_bench(1, 8192, 64, 64, 4096, 3, 3, 1000);
  662. run_bench(1, 256, 64, 64, 256, 3, 3, 1000);
  663. run_bench(1, 64, 128, 128, 64, 3, 3, 1000);
  664. run_bench(1, 512, 32, 32, 512, 3, 3, 1000);
  665. run_bench(1, 1024, 16, 16, 1024, 3, 3, 1000);
  666. run_bench(1, 64, 56, 56, 64, 3, 3, 1000);
  667. run_bench(1, 128, 32, 32, 128, 3, 3, 1000);
  668. run_bench(1, 256, 16, 16, 256, 3, 3, 1000);
  669. run_bench(1, 512, 8, 8, 512, 3, 3, 1000);
  670. run_bench(32, 32, 224, 224, 64, 7, 7, 1000);
  671. run_bench(32, 64, 56, 56, 64, 3, 3, 1000);
  672. run_bench(32, 128, 32, 32, 128, 3, 3, 1000);
  673. run_bench(32, 256, 16, 16, 256, 3, 3, 1000);
  674. run_bench(32, 512, 8, 8, 512, 3, 3, 1000);
  675. run_bench(256, 32, 224, 224, 64, 7, 7, 1000);
  676. run_bench(256, 64, 56, 56, 64, 3, 3, 1000);
  677. run_bench(256, 128, 32, 32, 128, 3, 3, 1000);
  678. run_bench(256, 256, 16, 16, 256, 3, 3, 1000);
  679. run_bench(256, 512, 8, 8, 512, 3, 3, 1000);
  680. }
  681. #endif
  682. #endif
  683. TEST_F(CUDA, CONV_BIAS_FORWARD_DILATED) {
  684. require_compute_capability(6, 0);
  685. auto run = [&](size_t N, size_t IC, size_t IH, size_t IW, size_t FH,
  686. size_t FW, size_t OC, size_t PH, size_t PW, size_t SH,
  687. size_t SW, size_t DH, size_t DW) {
  688. {
  689. // float case
  690. Checker<ConvBiasForward> checker(handle_cuda());
  691. ConvBias::Param param;
  692. param.sparse = ConvBias::Param::Sparse::DENSE;
  693. param.pad_h = PH;
  694. param.pad_w = PW;
  695. param.stride_h = SH;
  696. param.stride_w = SW;
  697. param.dilate_h = DH;
  698. param.dilate_w = DW;
  699. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  700. checker.set_param(param).exec(
  701. {{N, IC, IH, IW}, {OC, IC, FH, FW}, {1, OC, 1, 1}, {}, {}});
  702. }
  703. };
  704. // dilated case
  705. run(2, 8, 7, 7, 3, 3, 4, 0, 0, 1, 1, 2, 2);
  706. }
  707. #if CUDNN_VERSION >= 7500
  708. TEST_F(CUDA, CONV_BIAS_FORWARD_TENSORCORE_INT8) {
  709. require_compute_capability(7, 5);
  710. using namespace conv_bias;
  711. Checker<ConvBiasForward> checker(handle_cuda());
  712. auto opr = handle_cuda()->create_operator<ConvBias>();
  713. auto i8_min = std::numeric_limits<int8_t>().min();
  714. auto i8_max = std::numeric_limits<int8_t>().max();
  715. UniformIntRNG int_rng{i8_min, i8_max};
  716. ConvBias::Param param;
  717. param.format = ConvBias::Param::Format::NCHW32;
  718. using NonlineMode = ConvBias::Param::NonlineMode;
  719. for (NonlineMode mode : {NonlineMode::IDENTITY, NonlineMode::RELU}) {
  720. for (size_t batch : {2}) {
  721. for (size_t ic : {64, 32}) {
  722. for (size_t oc : {32}) {
  723. for (size_t fh : {3, 5, 7}) {
  724. for (int ph : {static_cast<int>(fh / 2), 0}) {
  725. for (int sh : {1, 2}) {
  726. for (size_t ih : {9, 11, 12, 13, 16}) {
  727. for (size_t iw : {8, 27, 32, 40}) {
  728. param.nonlineMode = mode;
  729. param.stride_h = param.stride_w = sh;
  730. param.pad_h = param.pad_w = ph;
  731. opr->param() = param;
  732. TensorLayout dst_layout;
  733. opr->deduce_layout(
  734. {{batch, ic / 32, ih, iw, 32},
  735. dtype::Float32()},
  736. {{oc, ic / 32, fh, fh, 32},
  737. dtype::Float32()},
  738. {}, {}, dst_layout);
  739. checker.set_dtype(0, dtype::QuantizedS8(
  740. 1.3f))
  741. .set_dtype(1,
  742. dtype::QuantizedS8(
  743. 1.3f))
  744. .set_dtype(2,
  745. dtype::QuantizedS32(
  746. 1.3f * 1.3f))
  747. .set_dtype(3,
  748. dtype::QuantizedS8(
  749. 1.7f))
  750. .set_dtype(4,
  751. dtype::QuantizedS8(
  752. 1.2f * 1.2f))
  753. .set_rng(0, &int_rng)
  754. .set_rng(1, &int_rng)
  755. .set_rng(2, &int_rng)
  756. .set_rng(3, &int_rng)
  757. .set_epsilon(1 + 1e-3)
  758. .set_param(param)
  759. .execs({{batch, ic / 32, ih, iw,
  760. 32},
  761. {oc, ic / 32, fh, fh,
  762. 32},
  763. {1, oc / 32, 1, 1, 32},
  764. dst_layout,
  765. {}});
  766. }
  767. }
  768. }
  769. }
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. #if MEGDNN_WITH_BENCHMARK
  777. TEST_F(CUDA, BENCHMARK_CONV_BIAS_FORWARD_TENSORCORE_INT8) {
  778. require_compute_capability(7, 5);
  779. Benchmarker<ConvBiasForward> bencher(handle_cuda());
  780. bencher.set_display(false);
  781. ConvBias::Param param;
  782. param.format = ConvBias::Param::Format::NCHW32;
  783. ConvBias::Param param_without_tensorcore;
  784. param_without_tensorcore.format = ConvBias::Param::Format::NCHW4;
  785. auto i8_min = std::numeric_limits<int8_t>().min();
  786. auto i8_max = std::numeric_limits<int8_t>().max();
  787. UniformIntRNG int_rng{i8_min, i8_max};
  788. using NonlineMode = ConvBias::Param::NonlineMode;
  789. param.nonlineMode = NonlineMode::IDENTITY;
  790. auto run_bench = [&](size_t batch, size_t ci, size_t hi, size_t wi,
  791. size_t co, size_t fh, size_t fw, size_t sh, size_t sw,
  792. size_t nr_times) {
  793. param.pad_h = fh / 2;
  794. param.pad_w = fw / 2;
  795. param.stride_h = sh;
  796. param.stride_w = sw;
  797. param_without_tensorcore.pad_h = fh / 2;
  798. param_without_tensorcore.pad_w = fw / 2;
  799. param_without_tensorcore.stride_h = sh;
  800. param_without_tensorcore.stride_w = sw;
  801. bencher.set_param(param)
  802. .set_dtype(0, dtype::QuantizedS8(1.3f))
  803. .set_dtype(1, dtype::QuantizedS8(1.3f))
  804. .set_dtype(2, dtype::QuantizedS32(1.3f * 1.3f))
  805. .set_dtype(4, dtype::QuantizedS8(1.2f))
  806. .set_rng(0, &int_rng)
  807. .set_rng(1, &int_rng)
  808. .set_rng(2, &int_rng);
  809. bencher.set_times(nr_times);
  810. size_t ho = infer_conv_shape(hi, fh, sh, param.pad_h);
  811. size_t wo = infer_conv_shape(wi, fw, sw, param.pad_w);
  812. TensorShape inp{batch, ci / 32, hi, wi, 32},
  813. kern{co, ci / 32, fh, fw, 32}, out{batch, co / 32, ho, wo, 32};
  814. auto time_in_ms =
  815. bencher.execs({inp, kern, {1, co / 32, 1, 1, 32}, {}, out}) /
  816. nr_times;
  817. auto ops = 2.0 * batch * co * ho * wo * ci * fh * fw /
  818. (time_in_ms * 1e-3) * 1e-12;
  819. printf("inp=%s, kern=%s, out=%s, time: %.2fms, perf: %.2f Tops "
  820. "(TensorCore)",
  821. inp.to_string().c_str(), kern.to_string().c_str(),
  822. out.to_string().c_str(), time_in_ms, ops);
  823. decltype(ops) ops_without_tensorcore;
  824. bencher.set_param(param_without_tensorcore);
  825. {
  826. TensorShape inp{batch, ci / 4, hi, wi, 4},
  827. kern{co, ci / 4, fh, fw, 4}, out{batch, co / 4, ho, wo, 4};
  828. auto time_in_ms =
  829. bencher.execs({inp, kern, {1, co / 4, 1, 1, 4}, {}, out}) /
  830. nr_times;
  831. ops_without_tensorcore = 2.0 * batch * co * ho * wo * ci * fh * fw /
  832. (time_in_ms * 1e-3) * 1e-12;
  833. printf(", time: %.2fms perf: %.2f Tops (without TensorCore) ",
  834. time_in_ms, ops_without_tensorcore);
  835. }
  836. printf("speedup: %.2fx\n", ops / ops_without_tensorcore);
  837. };
  838. // resnet-50
  839. // bottleneck-1
  840. // proj
  841. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  842. run_bench(1, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  843. run_bench(1, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  844. run_bench(1, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  845. // bottleneck-2
  846. // proj
  847. run_bench(1, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  848. run_bench(1, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  849. run_bench(1, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  850. run_bench(1, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  851. // bottleneck-3
  852. // proj
  853. run_bench(1, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  854. run_bench(1, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  855. run_bench(1, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  856. run_bench(1, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  857. // bottleneck-4
  858. // proj
  859. run_bench(1, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  860. run_bench(1, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  861. run_bench(1, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  862. run_bench(1, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  863. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  864. run_bench(32, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  865. run_bench(32, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  866. run_bench(32, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  867. run_bench(32, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  868. run_bench(32, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  869. run_bench(32, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  870. run_bench(32, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  871. run_bench(32, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  872. run_bench(32, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  873. run_bench(32, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  874. run_bench(32, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  875. run_bench(32, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  876. run_bench(32, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  877. run_bench(32, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  878. run_bench(32, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  879. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  880. run_bench(256, 64, 56, 56, 64, 1, 1, 1, 1, 1000);
  881. run_bench(256, 64, 56, 56, 64, 3, 3, 1, 1, 1000);
  882. run_bench(256, 64, 56, 56, 256, 1, 1, 1, 1, 1000);
  883. run_bench(256, 256, 56, 56, 512, 1, 1, 2, 2, 1000);
  884. run_bench(256, 256, 56, 56, 128, 1, 1, 2, 2, 1000);
  885. run_bench(256, 128, 28, 28, 128, 3, 3, 1, 1, 1000);
  886. run_bench(256, 128, 28, 28, 512, 1, 1, 1, 1, 1000);
  887. run_bench(256, 512, 28, 28, 1024, 1, 1, 2, 2, 1000);
  888. run_bench(256, 512, 28, 28, 256, 1, 1, 2, 2, 1000);
  889. run_bench(256, 256, 14, 14, 256, 3, 3, 1, 1, 1000);
  890. run_bench(256, 256, 14, 14, 1024, 1, 1, 1, 1, 1000);
  891. run_bench(256, 1024, 14, 14, 2048, 1, 1, 2, 2, 1000);
  892. run_bench(256, 1024, 14, 14, 512, 1, 1, 2, 2, 1000);
  893. run_bench(256, 512, 7, 7, 512, 3, 3, 1, 1, 1000);
  894. run_bench(256, 512, 7, 7, 2048, 1, 1, 1, 1, 1000);
  895. }
  896. #endif
  897. #endif
  898. // vim: syntax=cpp.doxygen

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