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_int8.cpp 48 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. /**
  2. * \file dnn/test/cuda/conv_bias_int8.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
  10. * implied.
  11. */
  12. #include "megdnn/oprs/nn.h"
  13. #include "src/common/utils.h"
  14. #include "src/cuda/cudnn_with_check.h"
  15. #include "test/common/checker.h"
  16. #include "test/common/conv_bias.h"
  17. #include "test/cuda/benchmark.h"
  18. #include "test/cuda/fixture.h"
  19. #include "test/cuda/utils.h"
  20. #include "test/common/tensor.h"
  21. #include "test/common/workspace_wrapper.h"
  22. #include "test/cuda/conv_test_utils.h"
  23. namespace megdnn {
  24. namespace test {
  25. namespace conv{
  26. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_CUDNN_CONVOLUTION) {
  27. require_compute_capability(7, 5);
  28. conv_bias::check_conv_bias(
  29. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  30. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  31. handle_cuda(), "DEFAULT:CUDNN:ConvBiasActivation:",
  32. param::ConvBias::Format::NCHW4);
  33. }
  34. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_1x1) {
  35. require_compute_capability(6, 1);
  36. conv_bias::check_conv_bias(
  37. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  38. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  39. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  40. param::ConvBias::Format::NCHW4, conv_bias::get_int8_nchw4_args(1));
  41. }
  42. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_3x3) {
  43. require_compute_capability(6, 1);
  44. conv_bias::check_conv_bias(
  45. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  46. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  47. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  48. param::ConvBias::Format::NCHW4);
  49. }
  50. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_5x5) {
  51. require_compute_capability(6, 1);
  52. conv_bias::check_conv_bias(
  53. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  54. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  55. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  56. param::ConvBias::Format::NCHW4, conv_bias::get_int8_nchw4_args(5));
  57. }
  58. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_7x7) {
  59. require_compute_capability(6, 1);
  60. conv_bias::check_conv_bias(
  61. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  62. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  63. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  64. param::ConvBias::Format::NCHW4, conv_bias::get_int8_nchw4_args(7));
  65. }
  66. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_WITH_Z) {
  67. require_compute_capability(6, 1);
  68. Checker<ConvBiasForward> checker(handle_cuda());
  69. checker.set_before_exec_callback(
  70. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  71. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM"));
  72. UniformIntRNG rng{-3, 3};
  73. UniformIntRNG bias_rng{-50, 50};
  74. checker.set_rng(0, &rng)
  75. .set_rng(1, &rng)
  76. .set_rng(2, &bias_rng)
  77. .set_rng(3, &rng)
  78. .set_dtype(0, dtype::QuantizedS8{1.2f})
  79. .set_dtype(1, dtype::QuantizedS8{1.3f})
  80. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  81. .set_dtype(3, dtype::QuantizedS8{1.1f})
  82. .set_dtype(4, dtype::QuantizedS8{1.0f})
  83. .set_epsilon(1 + 1e-3)
  84. .set_max_avg_error(1e-1)
  85. .set_max_avg_biased_error(1e-1);
  86. param::ConvBias param;
  87. param.pad_h = param.pad_w = 1;
  88. param.stride_h = param.stride_w = 1;
  89. param.format = param::ConvBias::Format::NCHW4;
  90. checker.set_param(param).execs({{32, 4, 12, 12, 4},
  91. {16, 4, 3, 3, 4},
  92. {1, 4, 1, 1, 4},
  93. {32, 4, 12, 12, 4},
  94. {}});
  95. }
  96. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_STRIDE2_WITH_Z) {
  97. require_compute_capability(6, 1);
  98. Checker<ConvBiasForward> checker(handle_cuda());
  99. checker.set_before_exec_callback(
  100. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  101. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM"));
  102. UniformIntRNG rng{-3, 3};
  103. UniformIntRNG bias_rng{-50, 50};
  104. checker.set_rng(0, &rng)
  105. .set_rng(1, &rng)
  106. .set_rng(2, &bias_rng)
  107. .set_rng(3, &rng)
  108. .set_dtype(0, dtype::QuantizedS8{1.2f})
  109. .set_dtype(1, dtype::QuantizedS8{1.3f})
  110. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  111. .set_dtype(3, dtype::QuantizedS8{1.1f})
  112. .set_dtype(4, dtype::QuantizedS8{1.0f})
  113. .set_epsilon(1 + 1e-3)
  114. .set_max_avg_error(1e-1)
  115. .set_max_avg_biased_error(1e-1);
  116. param::ConvBias param;
  117. param.pad_h = param.pad_w = 1;
  118. param.stride_h = param.stride_w = 2;
  119. param.format = param::ConvBias::Format::NCHW4;
  120. checker.set_param(param).execs({{32, 4, 12, 12, 4},
  121. {16, 4, 3, 3, 4},
  122. {1, 4, 1, 1, 4},
  123. {32, 4, 6, 6, 4},
  124. {}});
  125. }
  126. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_CHECK_BOUNDS_1x1) {
  127. require_compute_capability(6, 1);
  128. conv_bias::check_conv_bias(
  129. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  130. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  131. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  132. param::ConvBias::Format::NCHW4,
  133. conv_bias::get_int8_nchw4_args_check_bounds(1));
  134. }
  135. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_CHECK_BOUNDS_3x3) {
  136. require_compute_capability(6, 1);
  137. conv_bias::check_conv_bias(
  138. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  139. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  140. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  141. param::ConvBias::Format::NCHW4,
  142. conv_bias::get_int8_nchw4_args_check_bounds(3));
  143. }
  144. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_CHECK_BOUNDS_5x5) {
  145. require_compute_capability(6, 1);
  146. conv_bias::check_conv_bias(
  147. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  148. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  149. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  150. param::ConvBias::Format::NCHW4,
  151. conv_bias::get_int8_nchw4_args_check_bounds(5));
  152. }
  153. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_CHECK_BOUNDS_7x7) {
  154. require_compute_capability(6, 1);
  155. conv_bias::check_conv_bias(
  156. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  157. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  158. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  159. param::ConvBias::Format::NCHW4,
  160. conv_bias::get_int8_nchw4_args_check_bounds(7));
  161. }
  162. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4) {
  163. require_compute_capability(6, 1);
  164. conv_bias::check_conv_bias(
  165. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  166. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  167. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  168. param::ConvBias::Format::CHWN4);
  169. }
  170. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_WITH_Z) {
  171. require_compute_capability(6, 1);
  172. Checker<ConvBiasForward> checker(handle_cuda());
  173. checker.set_before_exec_callback(
  174. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  175. "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM"));
  176. UniformIntRNG rng{-3, 3};
  177. UniformIntRNG bias_rng{-50, 50};
  178. checker.set_rng(0, &rng)
  179. .set_rng(1, &rng)
  180. .set_rng(2, &bias_rng)
  181. .set_rng(3, &rng)
  182. .set_dtype(0, dtype::QuantizedS8{1.2f})
  183. .set_dtype(1, dtype::QuantizedS8{1.3f})
  184. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  185. .set_dtype(3, dtype::QuantizedS8{1.1f})
  186. .set_dtype(4, dtype::QuantizedS8{1.1f})
  187. .set_epsilon(1 + 1e-3)
  188. .set_max_avg_error(1e-1)
  189. .set_max_avg_biased_error(1e-1);
  190. param::ConvBias param;
  191. param.pad_h = param.pad_w = 1;
  192. param.stride_h = param.stride_w = 1;
  193. param.format = param::ConvBias::Format::CHWN4;
  194. checker.set_param(param).execs({{4, 12, 12, 32, 4},
  195. {4, 3, 3, 16, 4},
  196. {4, 1, 1, 1, 4},
  197. {4, 12, 12, 32, 4},
  198. {}});
  199. }
  200. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_HSWISH) {
  201. require_compute_capability(6, 1);
  202. Checker<ConvBiasForward> checker(handle_cuda());
  203. checker.set_before_exec_callback(
  204. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  205. "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM"));
  206. UniformIntRNG rng{-3, 3};
  207. UniformIntRNG bias_rng{-50, 50};
  208. checker.set_rng(0, &rng)
  209. .set_rng(1, &rng)
  210. .set_rng(2, &bias_rng)
  211. .set_rng(3, &rng)
  212. .set_dtype(0, dtype::QuantizedS8{1.2f})
  213. .set_dtype(1, dtype::QuantizedS8{1.3f})
  214. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  215. .set_dtype(4, dtype::QuantizedS8{0.001f})
  216. .set_epsilon(1 + 1e-3)
  217. .set_max_avg_error(1e-1)
  218. .set_max_avg_biased_error(1e-1);
  219. param::ConvBias param;
  220. param.pad_h = param.pad_w = 1;
  221. param.stride_h = param.stride_w = 1;
  222. param.format = param::ConvBias::Format::CHWN4;
  223. param.nonlineMode = param::ConvBias::NonlineMode::H_SWISH;
  224. checker.set_param(param).execs(
  225. {{4, 12, 12, 32, 4}, {4, 3, 3, 16, 4}, {4, 1, 1, 1, 4}, {}, {}});
  226. }
  227. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_CHECK_BOUNDS) {
  228. require_compute_capability(6, 1);
  229. conv_bias::check_conv_bias(
  230. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  231. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  232. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  233. param::ConvBias::Format::CHWN4,
  234. conv_bias::get_int8_chwn4_args_check_bounds(3));
  235. }
  236. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_1x1) {
  237. require_compute_capability(6, 1);
  238. conv_bias::check_conv_bias(
  239. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  240. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  241. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  242. param::ConvBias::Format::CHWN4,
  243. conv_bias::get_int8_chwn4_small_channel_args(1));
  244. }
  245. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_3x3) {
  246. require_compute_capability(6, 1);
  247. conv_bias::check_conv_bias(
  248. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  249. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  250. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  251. param::ConvBias::Format::CHWN4,
  252. conv_bias::get_int8_chwn4_small_channel_args(3));
  253. }
  254. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_5x5) {
  255. require_compute_capability(6, 1);
  256. conv_bias::check_conv_bias(
  257. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  258. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  259. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  260. param::ConvBias::Format::CHWN4,
  261. conv_bias::get_int8_chwn4_small_channel_args(5));
  262. }
  263. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_7x7) {
  264. require_compute_capability(6, 1);
  265. conv_bias::check_conv_bias(
  266. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  267. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  268. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  269. param::ConvBias::Format::CHWN4,
  270. conv_bias::get_int8_chwn4_small_channel_args(7));
  271. }
  272. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_SMALL_CHANNEL_CHECK_BOUNDS) {
  273. require_compute_capability(6, 1);
  274. conv_bias::check_conv_bias(
  275. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  276. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  277. handle_cuda(), "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  278. param::ConvBias::Format::NCHW4,
  279. conv_bias::get_int8_nchw4_small_channel_args_check_bounds(3));
  280. }
  281. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_1x1_CHECK_BOUNDS) {
  282. require_compute_capability(6, 1);
  283. conv_bias::check_conv_bias(
  284. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  285. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  286. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  287. param::ConvBias::Format::CHWN4,
  288. conv_bias::get_int8_chwn4_small_channel_args_check_bounds(1));
  289. }
  290. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_5x5_CHECK_BOUNDS) {
  291. require_compute_capability(6, 1);
  292. conv_bias::check_conv_bias(
  293. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  294. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  295. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  296. param::ConvBias::Format::CHWN4,
  297. conv_bias::get_int8_chwn4_small_channel_args_check_bounds(5));
  298. }
  299. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL_7x7_CHECK_BOUNDS) {
  300. require_compute_capability(6, 1);
  301. conv_bias::check_conv_bias(
  302. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  303. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  304. handle_cuda(), "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  305. param::ConvBias::Format::CHWN4,
  306. conv_bias::get_int8_chwn4_small_channel_args_check_bounds(7));
  307. }
  308. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_1x1) {
  309. require_compute_capability(7, 5);
  310. conv_bias::check_conv_bias(
  311. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  312. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  313. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  314. param::ConvBias::Format::NCHW4,
  315. conv_bias::get_int8_nchw4_tensorcore_args(1));
  316. }
  317. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_3x3) {
  318. require_compute_capability(7, 5);
  319. conv_bias::check_conv_bias(
  320. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  321. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  322. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  323. param::ConvBias::Format::NCHW4,
  324. conv_bias::get_int8_nchw4_tensorcore_args(3));
  325. }
  326. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_5x5) {
  327. require_compute_capability(7, 5);
  328. conv_bias::check_conv_bias(
  329. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  330. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  331. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  332. param::ConvBias::Format::NCHW4,
  333. conv_bias::get_int8_nchw4_tensorcore_args(5));
  334. }
  335. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_7x7) {
  336. require_compute_capability(7, 5);
  337. conv_bias::check_conv_bias(
  338. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  339. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  340. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  341. param::ConvBias::Format::NCHW4,
  342. conv_bias::get_int8_nchw4_tensorcore_args(7));
  343. }
  344. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_CHECK_BOUNDS_ALGO_0) {
  345. require_compute_capability(7, 5);
  346. conv_bias::check_conv_bias(
  347. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  348. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  349. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  350. param::ConvBias::Format::NCHW4,
  351. conv_bias::get_int8_nchw4_args_check_bounds(3));
  352. }
  353. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_CHECK_BOUNDS_ALGO_1) {
  354. require_compute_capability(7, 5);
  355. conv_bias::check_conv_bias(
  356. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  357. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  358. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma8x32x16",
  359. param::ConvBias::Format::NCHW4,
  360. conv_bias::get_int8_nchw4_args_check_bounds(3));
  361. }
  362. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_CHECK_BOUNDS_ALGO_2) {
  363. require_compute_capability(7, 5);
  364. conv_bias::check_conv_bias(
  365. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  366. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  367. handle_cuda(), "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma32x8x16",
  368. param::ConvBias::Format::NCHW4,
  369. conv_bias::get_int8_nchw4_args_check_bounds(3));
  370. }
  371. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_ALGO_0) {
  372. require_compute_capability(7, 5);
  373. conv_bias::check_conv_bias(
  374. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  375. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  376. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  377. param::ConvBias::Format::CHWN4,
  378. conv_bias::get_int8_chwn4_tensorcore_args(3));
  379. }
  380. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_ALGO_1) {
  381. require_compute_capability(7, 5);
  382. conv_bias::check_conv_bias(
  383. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  384. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  385. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma32x8x16",
  386. param::ConvBias::Format::CHWN4,
  387. conv_bias::get_int8_chwn4_tensorcore_args(3));
  388. }
  389. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_ALGO_2) {
  390. require_compute_capability(7, 5);
  391. conv_bias::check_conv_bias(
  392. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  393. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  394. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma8x32x16",
  395. param::ConvBias::Format::CHWN4,
  396. conv_bias::get_int8_chwn4_tensorcore_args(3));
  397. }
  398. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_CHECK_BOUNDS_1x1) {
  399. require_compute_capability(7, 5);
  400. conv_bias::check_conv_bias(
  401. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  402. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  403. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  404. param::ConvBias::Format::CHWN4,
  405. conv_bias::get_int8_chwn4_args_check_bounds(1));
  406. }
  407. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_CHECK_BOUNDS_5x5) {
  408. require_compute_capability(7, 5);
  409. conv_bias::check_conv_bias(
  410. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  411. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  412. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  413. param::ConvBias::Format::CHWN4,
  414. conv_bias::get_int8_chwn4_args_check_bounds(5));
  415. }
  416. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_CHECK_BOUNDS_7x7) {
  417. require_compute_capability(7, 5);
  418. conv_bias::check_conv_bias(
  419. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  420. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  421. handle_cuda(), "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  422. param::ConvBias::Format::CHWN4,
  423. conv_bias::get_int8_chwn4_args_check_bounds(7));
  424. }
  425. TEST_F(CUDA, CONV_BIAS_INT8_NCHW4_TENSORCORE_WITH_Z) {
  426. require_compute_capability(7, 5);
  427. Checker<ConvBiasForward> checker(handle_cuda());
  428. checker.set_before_exec_callback(
  429. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  430. "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16"));
  431. UniformIntRNG rng{-3, 3};
  432. UniformIntRNG bias_rng{-50, 50};
  433. checker.set_rng(0, &rng)
  434. .set_rng(1, &rng)
  435. .set_rng(2, &bias_rng)
  436. .set_rng(3, &rng)
  437. .set_dtype(0, dtype::QuantizedS8{1.2f})
  438. .set_dtype(1, dtype::QuantizedS8{1.3f})
  439. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  440. .set_dtype(3, dtype::QuantizedS8{1.1f})
  441. .set_dtype(4, dtype::QuantizedS8{1.0f})
  442. .set_epsilon(1 + 1e-3)
  443. .set_max_avg_error(1e-1)
  444. .set_max_avg_biased_error(1e-1);
  445. param::ConvBias param;
  446. param.pad_h = param.pad_w = 1;
  447. param.stride_h = param.stride_w = 1;
  448. param.format = param::ConvBias::Format::NCHW4;
  449. checker.set_param(param).execs({{64, 8, 12, 12, 4},
  450. {64, 8, 3, 3, 4},
  451. {1, 16, 1, 1, 4},
  452. {64, 16, 12, 12, 4},
  453. {}});
  454. }
  455. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_TENSORCORE_WITH_Z) {
  456. require_compute_capability(7, 5);
  457. Checker<ConvBiasForward> checker(handle_cuda());
  458. checker.set_before_exec_callback(
  459. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  460. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16"));
  461. UniformIntRNG rng{-3, 3};
  462. UniformIntRNG bias_rng{-50, 50};
  463. checker.set_rng(0, &rng)
  464. .set_rng(1, &rng)
  465. .set_rng(2, &bias_rng)
  466. .set_rng(3, &rng)
  467. .set_dtype(0, dtype::QuantizedS8{1.2f})
  468. .set_dtype(1, dtype::QuantizedS8{1.3f})
  469. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  470. .set_dtype(3, dtype::QuantizedS8{1.1f})
  471. .set_dtype(4, dtype::QuantizedS8{1.0f})
  472. .set_epsilon(1 + 1e-3)
  473. .set_max_avg_error(1e-1)
  474. .set_max_avg_biased_error(1e-1);
  475. param::ConvBias param;
  476. param.pad_h = param.pad_w = 1;
  477. param.stride_h = param.stride_w = 1;
  478. param.format = param::ConvBias::Format::CHWN4;
  479. checker.set_param(param).execs({{8, 12, 12, 64, 4},
  480. {8, 3, 3, 64, 4},
  481. {16, 1, 1, 1, 4},
  482. {16, 12, 12, 64, 4},
  483. {}});
  484. }
  485. TEST_F(CUDA,
  486. CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_CHECK_BOUNDS_ALGO_0) {
  487. require_compute_capability(7, 5);
  488. conv_bias::check_conv_bias(
  489. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  490. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  491. handle_cuda(),
  492. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma16x16x16",
  493. param::ConvBias::Format::CHWN4,
  494. conv_bias::get_int8_chwn4_args_check_bounds(3));
  495. }
  496. TEST_F(CUDA,
  497. CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_CHECK_BOUNDS_ALGO_1) {
  498. require_compute_capability(7, 5);
  499. conv_bias::check_conv_bias(
  500. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  501. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  502. handle_cuda(),
  503. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma8x32x16",
  504. param::ConvBias::Format::CHWN4,
  505. conv_bias::get_int8_chwn4_args_check_bounds(3));
  506. }
  507. TEST_F(CUDA,
  508. CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_CHECK_BOUNDS_ALGO_2) {
  509. require_compute_capability(7, 5);
  510. conv_bias::check_conv_bias(
  511. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  512. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  513. handle_cuda(),
  514. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma32x8x16",
  515. param::ConvBias::Format::CHWN4,
  516. conv_bias::get_int8_chwn4_args_check_bounds(3));
  517. }
  518. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_ALGO_0) {
  519. require_compute_capability(7, 5);
  520. conv_bias::check_conv_bias(
  521. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  522. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  523. handle_cuda(),
  524. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma16x16x16",
  525. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  526. }
  527. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_ALGO_1) {
  528. require_compute_capability(7, 5);
  529. conv_bias::check_conv_bias(
  530. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  531. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  532. handle_cuda(),
  533. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma8x32x16",
  534. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  535. }
  536. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_REFORMAT_FILTER_TENSORCORE_ALGO_2) {
  537. require_compute_capability(7, 5);
  538. conv_bias::check_conv_bias(
  539. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  540. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  541. handle_cuda(),
  542. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_REORDER_FILTER_mma32x8x16",
  543. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  544. }
  545. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_ALGO_0) {
  546. require_compute_capability(7, 5);
  547. conv_bias::check_conv_bias(
  548. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  549. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  550. handle_cuda(),
  551. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma16x16x16",
  552. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  553. }
  554. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_ALGO_1) {
  555. require_compute_capability(7, 5);
  556. conv_bias::check_conv_bias(
  557. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  558. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  559. handle_cuda(),
  560. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma8x32x16",
  561. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  562. }
  563. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_ALGO_2) {
  564. require_compute_capability(7, 5);
  565. conv_bias::check_conv_bias(
  566. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  567. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.3f},
  568. handle_cuda(),
  569. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma32x8x16",
  570. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(3));
  571. }
  572. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_1x1) {
  573. require_compute_capability(7, 5);
  574. conv_bias::check_conv_bias(
  575. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  576. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  577. handle_cuda(),
  578. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma16x16x16",
  579. param::ConvBias::Format::CHWN4, conv_bias::get_int8_chwn4_args(1));
  580. }
  581. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_5x5) {
  582. require_compute_capability(7, 5);
  583. conv_bias::check_conv_bias(
  584. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  585. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  586. handle_cuda(),
  587. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma16x16x16",
  588. param::ConvBias::Format::CHWN4,
  589. conv_bias::get_int8_chwn4_args_small_batch(5));
  590. }
  591. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_7x7) {
  592. require_compute_capability(7, 5);
  593. conv_bias::check_conv_bias(
  594. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  595. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  596. handle_cuda(),
  597. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma16x16x16",
  598. param::ConvBias::Format::CHWN4,
  599. conv_bias::get_int8_chwn4_args_small_batch(7));
  600. }
  601. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_5x5_ALGO_1) {
  602. require_compute_capability(7, 5);
  603. conv_bias::check_conv_bias(
  604. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  605. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  606. handle_cuda(),
  607. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma32x8x16",
  608. param::ConvBias::Format::CHWN4,
  609. conv_bias::get_int8_chwn4_args_small_batch(5));
  610. }
  611. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_5x5_ALGO_2) {
  612. require_compute_capability(7, 5);
  613. conv_bias::check_conv_bias(
  614. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  615. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  616. handle_cuda(),
  617. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma8x32x16",
  618. param::ConvBias::Format::CHWN4,
  619. conv_bias::get_int8_chwn4_args_small_batch(5));
  620. }
  621. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_1x1_ALGO_1) {
  622. require_compute_capability(7, 5);
  623. conv_bias::check_conv_bias(
  624. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  625. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  626. handle_cuda(),
  627. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma32x8x16",
  628. param::ConvBias::Format::CHWN4,
  629. conv_bias::get_int8_chwn4_args_small_batch(1));
  630. }
  631. TEST_F(CUDA, CONV_BIAS_INT8_CHWN4_UNROLL_WIDTH_TENSORCORE_1x1_ALGO_2) {
  632. require_compute_capability(7, 5);
  633. conv_bias::check_conv_bias(
  634. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  635. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.1f},
  636. handle_cuda(),
  637. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_UNROLL_WIDTH_mma8x32x16",
  638. param::ConvBias::Format::CHWN4,
  639. conv_bias::get_int8_chwn4_args_small_batch(1));
  640. }
  641. TEST_F(CUDA, FALLBACK_CONV_QS8) {
  642. require_compute_capability_eq(7, 5);
  643. Checker<ConvBiasForward> checker(handle_cuda());
  644. auto check = [&checker](const std::string&& algo,
  645. const std::string&& sub_algo) {
  646. checker.set_before_exec_callback(
  647. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  648. {algo.c_str(), {sub_algo.c_str()}}));
  649. UniformIntRNG rng{-3, 3};
  650. UniformIntRNG bias_rng{-50, 50};
  651. checker.set_rng(0, &rng)
  652. .set_rng(1, &rng)
  653. .set_rng(2, &bias_rng)
  654. .set_rng(3, &rng)
  655. .set_dtype(0, dtype::QuantizedS8{1.2f})
  656. .set_dtype(1, dtype::QuantizedS8{1.3f})
  657. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  658. .set_dtype(3, dtype::QuantizedS8{19.990229f})
  659. .set_dtype(4, dtype::QuantizedS8{19.990228f})
  660. .set_epsilon(1e-3)
  661. .set_max_avg_error(1e-1)
  662. .set_max_avg_biased_error(1e-3);
  663. param::ConvBias param;
  664. param.pad_h = param.pad_w = 1;
  665. param.stride_h = param.stride_w = 2;
  666. param.format = param::ConvBias::Format::NCHW;
  667. checker.set_param(param).execs({{16, 15, 14, 14},
  668. {28, 15, 3, 3},
  669. {1, 28, 1, 1},
  670. {16, 28, 7, 7},
  671. {}});
  672. checker.set_param(param).execs({{16, 32, 14, 14},
  673. {32, 32, 3, 3},
  674. {1, 32, 1, 1},
  675. {},
  676. {}});
  677. };
  678. check("FALLBACK_CONV_NCHW_QS8", "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM");
  679. }
  680. TEST_F(CUDA, FALLBACK_CONV_QS8_F32) {
  681. require_compute_capability_eq(7, 5);
  682. Checker<ConvBiasForward> checker(handle_cuda());
  683. auto check = [&checker](const std::string&& algo,
  684. const std::string&& sub_algo) {
  685. checker.set_before_exec_callback(
  686. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  687. {algo.c_str(), {sub_algo.c_str()}}));
  688. UniformIntRNG rng{-3, 3};
  689. UniformFloatRNG bias_rng{-50.f, 50.f};
  690. checker.set_rng(0, &rng)
  691. .set_rng(1, &rng)
  692. .set_rng(2, &bias_rng)
  693. .set_rng(3, &rng)
  694. .set_dtype(0, dtype::QuantizedS8{1.2f})
  695. .set_dtype(1, dtype::QuantizedS8{1.3f})
  696. .set_dtype(2, dtype::Float32{})
  697. .set_dtype(3, dtype::Float32{})
  698. .set_dtype(4, dtype::Float32{})
  699. .set_epsilon(1e-3)
  700. .set_max_avg_error(1e-1)
  701. .set_max_avg_biased_error(1e-3);
  702. param::ConvBias param;
  703. param.pad_h = param.pad_w = 1;
  704. param.stride_h = param.stride_w = 2;
  705. param.format = param::ConvBias::Format::NCHW;
  706. checker.set_param(param).execs({{16, 15, 14, 14},
  707. {28, 15, 3, 3},
  708. {1, 28, 1, 1},
  709. {16, 28, 7, 7},
  710. {}});
  711. checker.set_param(param).execs({{16, 32, 14, 14},
  712. {32, 32, 3, 3},
  713. {1, 32, 1, 1},
  714. {},
  715. {}});
  716. };
  717. check("FALLBACK_CONV_NCHW_QS8", "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM");
  718. }
  719. TEST_F(CUDA, CUTLASS_CONV_BIAS_INT8_WEIGHT_PREPROCESS) {
  720. require_compute_capability(6, 1);
  721. Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
  722. handle_cuda());
  723. auto check = [&checker](const std::string& algo) {
  724. checker.set_before_exec_callback(
  725. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(algo.c_str()));
  726. UniformIntRNG rng{-16, 16};
  727. UniformIntRNG bias_rng{-50, 50};
  728. UniformIntRNG const_rng{1, 1};
  729. checker.set_rng(0, &rng)
  730. .set_rng(1, &rng)
  731. .set_rng(2, &bias_rng)
  732. .set_rng(3, &rng)
  733. .set_dtype(0, dtype::QuantizedS8{1.2f})
  734. .set_dtype(1, dtype::QuantizedS8{1.3f})
  735. .set_dtype(2, dtype::QuantizedS32{1.2f * 1.3f})
  736. .set_dtype(3, dtype::QuantizedS8{1.3f})
  737. .set_dtype(4, dtype::QuantizedS8{1.0f})
  738. .set_epsilon(1 + 1e-3)
  739. .set_max_avg_error(1e-1)
  740. .set_max_avg_biased_error(1e-3);
  741. param::ConvBias param;
  742. param.pad_h = param.pad_w = 1;
  743. param.stride_h = param.stride_w = 2;
  744. param.format = param::ConvBias::Format::NCHW4;
  745. checker.set_param(param).execs({{16, 4, 14, 14, 4},
  746. {16, 4, 3, 3, 4},
  747. {1, 4, 1, 1, 4},
  748. {},
  749. {}});
  750. };
  751. check("INT8_NCHW4_DOTPROD_IMPLICIT_GEMM_128X32X32_64X32X32");
  752. check("INT8_NCHW4_DOTPROD_IMPLICIT_GEMM_16X64X8_16X64X8");
  753. }
  754. #if CUDA_VERSION >= 10020
  755. /// \note: we only check several cases and block sizes in megdnn_test, the
  756. /// full testcases are written in cutlass repository
  757. TEST_F(CUDA, CUTLASS_CONV_BIAS_INT8_NCHW32_IMMA) {
  758. require_compute_capability_eq(7, 5);
  759. Checker<ConvBiasForward> checker(handle_cuda());
  760. auto check = [&checker](const std::string& algo) {
  761. checker.set_before_exec_callback(
  762. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(algo.c_str()));
  763. UniformIntRNG rng{-8, 8};
  764. UniformIntRNG bias_rng{-50, 50};
  765. UniformIntRNG const_rng{1, 1};
  766. // use scale that are all integers to avoid rouding error
  767. checker.set_rng(0, &rng)
  768. .set_rng(1, &rng)
  769. .set_rng(2, &bias_rng)
  770. .set_rng(3, &rng)
  771. .set_dtype(0, dtype::QuantizedS8{6.0f})
  772. .set_dtype(1, dtype::QuantizedS8{1.0f})
  773. .set_dtype(2, dtype::QuantizedS32{6.0f})
  774. .set_dtype(3, dtype::QuantizedS8{1.0f})
  775. .set_dtype(4, dtype::QuantizedS8{6.0f})
  776. .set_epsilon(1e-3);
  777. param::ConvBias param;
  778. param.pad_h = param.pad_w = 1;
  779. param.stride_h = param.stride_w = 1;
  780. param.format = param::ConvBias::Format::NCHW32;
  781. checker.set_param(param).execs({{16, 16, 7, 7, 32},
  782. {512, 16, 3, 3, 32},
  783. {1, 16, 1, 1, 32},
  784. {},
  785. {}});
  786. param.nonlineMode = param::ConvBias::NonlineMode::RELU;
  787. checker.set_param(param).execs({{16, 16, 7, 7, 32},
  788. {512, 16, 1, 1, 32},
  789. {1, 16, 1, 1, 32},
  790. {},
  791. {}});
  792. param.nonlineMode = param::ConvBias::NonlineMode::H_SWISH;
  793. checker.set_param(param).execs({{16, 16, 7, 7, 32},
  794. {512, 16, 3, 3, 32},
  795. {1, 16, 1, 1, 32},
  796. {},
  797. {}});
  798. // use non integer scale
  799. param.nonlineMode = param::ConvBias::NonlineMode::H_SWISH;
  800. checker.set_dtype(0, dtype::QuantizedS8{1.1f})
  801. .set_dtype(1, dtype::QuantizedS8{1.2f})
  802. .set_dtype(2, dtype::QuantizedS32{1.1f * 1.2f})
  803. .set_dtype(3, dtype::QuantizedS8{1.1f})
  804. .set_dtype(4, dtype::QuantizedS8{6.0f})
  805. .set_epsilon(1 + 1e-3)
  806. .set_max_avg_error(1e-1)
  807. .set_max_avg_biased_error(1e-1)
  808. .execs({{16, 16, 7, 7, 32},
  809. {512, 16, 3, 3, 32},
  810. {1, 16, 1, 1, 32},
  811. {16, 16, 7, 7, 32},
  812. {}});
  813. };
  814. std::string algo = ConvBias::algo_name<ConvBias::DirectParam>(
  815. "INT8_NCHW32_IMMA_IMPLICIT_GEMM_256X128X64_64X64X64",
  816. ConvBias::DirectParam{});
  817. check(algo);
  818. algo = ConvBias::algo_name<ConvBias::DirectParam>(
  819. "INT8_NCHW32_IMMA_IMPLICIT_GEMM_32X64X64_32X16X64",
  820. ConvBias::DirectParam{});
  821. check(algo);
  822. }
  823. #endif
  824. TEST_F(CUDA, CUTLASS_CONV_BIAS_INT8_NCHW4_NCHW) {
  825. require_compute_capability(6, 1);
  826. using namespace conv_bias;
  827. Checker<ConvBiasForward> checker(handle_cuda());
  828. UniformIntRNG int_rng{-3, 3};
  829. UniformFloatRNG float_rng{-50, 50};
  830. ConvBias::Param param;
  831. param.format = ConvBias::Param::Format::NCHW4_NCHW;
  832. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  833. checker.set_before_exec_callback(
  834. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  835. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM"));
  836. checker.set_dtype(0, dtype::QuantizedS8(1.9980618f))
  837. .set_dtype(1, dtype::QuantizedS8(1.9980927f))
  838. .set_dtype(2, dtype::Float32())
  839. .set_dtype(3, dtype::Float32())
  840. .set_dtype(4, dtype::Float32())
  841. .set_rng(0, &int_rng)
  842. .set_rng(1, &int_rng)
  843. .set_rng(2, &float_rng)
  844. .set_rng(3, &float_rng)
  845. .set_param(param);
  846. auto opr = handle_cuda()->create_operator<ConvBias>();
  847. auto run = [&](const TensorShapeArray& shapes) {
  848. opr->param() = param;
  849. TensorLayout dst_layout;
  850. opr->deduce_layout({shapes[0], dtype::Float32()},
  851. {shapes[1], dtype::Float32()}, {}, {}, dst_layout);
  852. checker.execs({shapes[0], shapes[1], shapes[2], dst_layout, {}});
  853. };
  854. run({{16, 4, 23, 40, 4}, {20, 4, 3, 3, 4}, {1, 20, 1, 1}});
  855. run({{16, 4, 92, 160, 4}, {24, 4, 3, 3, 4}, {1, 24, 1, 1}});
  856. run({{16, 4, 92, 160, 4}, {20, 4, 3, 3, 4}, {1, 20, 1, 1}});
  857. run({{16, 4, 92, 160, 4}, {16, 4, 3, 3, 4}, {1, 16, 1, 1}});
  858. run({{16, 4, 92, 160, 4}, {8, 4, 3, 3, 4}, {1, 8, 1, 1}});
  859. run({{16, 4, 46, 80, 4}, {4, 4, 3, 3, 4}, {1, 4, 1, 1}});
  860. }
  861. TEST_F(CUDA, CUTLASS_CONV_BIAS_INT8_NCHW4_NCHW32) {
  862. require_compute_capability(6, 1);
  863. using namespace conv_bias;
  864. Checker<ConvBiasForward> checker(handle_cuda());
  865. UniformIntRNG int_rng{-3, 3};
  866. UniformIntRNG bias_rng{-50, 50};
  867. ConvBias::Param param;
  868. param.format = ConvBias::Param::Format::NCHW4_NCHW32;
  869. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  870. checker.set_before_exec_callback(
  871. conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
  872. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM"));
  873. checker.set_dtype(0, dtype::QuantizedS8(1.9980618f))
  874. .set_dtype(1, dtype::QuantizedS8(1.9980927f))
  875. .set_dtype(2, dtype::QuantizedS32(1.9980618f * 1.9980927f))
  876. .set_dtype(3, dtype::QuantizedS8(1.9980618f))
  877. .set_dtype(4, dtype::QuantizedS8(1.9980618f))
  878. .set_rng(0, &int_rng)
  879. .set_rng(1, &int_rng)
  880. .set_rng(2, &bias_rng)
  881. .set_rng(3, &int_rng)
  882. .set_param(param);
  883. auto run = [&](const TensorShapeArray& shapes) {
  884. checker.execs({shapes[0], shapes[1], shapes[2], {}, {}});
  885. };
  886. run({{16, 4, 23, 40, 4}, {32, 4, 3, 3, 4}, {1, 1, 1, 1, 32}});
  887. run({{16, 4, 92, 160, 4}, {32, 4, 3, 3, 4}, {1, 1, 1, 1, 32}});
  888. run({{16, 4, 46, 80, 4}, {32, 4, 3, 3, 4}, {1, 1, 1, 1, 32}});
  889. }
  890. #if CUDA_VERSION >= 10020
  891. TEST_F(CUDA, CUTLASS_CONV_BIAS_INT8_NCHW32_NCHW4) {
  892. require_compute_capability(7, 5);
  893. using namespace conv_bias;
  894. Checker<ConvBiasForward> checker(handle_cuda());
  895. UniformIntRNG int_rng{-3, 3};
  896. UniformIntRNG bias_rng{-50, 50};
  897. ConvBias::Param param;
  898. param.format = ConvBias::Param::Format::NCHW32_NCHW4;
  899. param.nonlineMode = ConvBias::Param::NonlineMode::IDENTITY;
  900. checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<
  901. ConvBiasForward>(
  902. ConvBias::algo_name<ConvBias::DirectParam>(
  903. "INT8_NCHW32_IMMA_IMPLICIT_GEMM_256X128X64_64X64X64",
  904. ConvBias::DirectParam{})
  905. .c_str()));
  906. checker.set_dtype(0, dtype::QuantizedS8(1.9980618f))
  907. .set_dtype(1, dtype::QuantizedS8(1.9980927f))
  908. .set_dtype(2, dtype::QuantizedS32(1.9980618f * 1.9980927f))
  909. .set_dtype(3, dtype::QuantizedS8(1.9980618f))
  910. .set_dtype(4, dtype::QuantizedS8(1.9980618f))
  911. .set_rng(0, &int_rng)
  912. .set_rng(1, &int_rng)
  913. .set_rng(2, &bias_rng)
  914. .set_rng(3, &int_rng)
  915. .set_param(param);
  916. auto run = [&](const TensorShapeArray& shapes) {
  917. checker.execs({shapes[0], shapes[1], shapes[2], {}, {}});
  918. };
  919. run({{16, 2, 23, 40, 32}, {20, 2, 3, 3, 32}, {1, 5, 1, 1, 4}});
  920. run({{16, 1, 92, 160, 32}, {24, 1, 3, 3, 32}, {1, 6, 1, 1, 4}});
  921. run({{16, 2, 46, 80, 32}, {4, 2, 3, 3, 32}, {1, 1, 1, 1, 4}});
  922. }
  923. #endif
  924. #if MEGDNN_WITH_BENCHMARK
  925. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_CHWN4) {
  926. require_compute_capability(6, 1);
  927. benchmark_target_algo(
  928. handle_cuda(), get_resnet50_bench_args(), dtype::QuantizedS8{1.2f},
  929. dtype::QuantizedS8{1.3f}, dtype::QuantizedS32{1.2f * 1.3f},
  930. dtype::QuantizedS8{1.0f}, "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  931. param::ConvBias::Format::CHWN4);
  932. }
  933. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_NCHW4) {
  934. require_compute_capability(6, 1);
  935. benchmark_target_algo(
  936. handle_cuda(), get_resnet50_bench_args(), dtype::QuantizedS8{1.2f},
  937. dtype::QuantizedS8{1.3f}, dtype::QuantizedS32{1.2f * 1.3f},
  938. dtype::QuantizedS8{1.0f}, "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM",
  939. param::ConvBias::Format::NCHW4);
  940. }
  941. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_CHWN4_TENSORCORE) {
  942. require_compute_capability(7, 5);
  943. benchmark_target_algo_with_cudnn_tsc(
  944. handle_cuda(), get_resnet50_bench_args(256),
  945. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  946. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f},
  947. "INT8_CHWN4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  948. param::ConvBias::Format::CHWN4);
  949. }
  950. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_CHWN4_TENSORCORE_ALL_ALGO) {
  951. require_compute_capability(7, 5);
  952. benchmark_target_algo_with_cudnn_tsc(
  953. handle_cuda(), get_resnet50_bench_args(256),
  954. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  955. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f}, nullptr,
  956. param::ConvBias::Format::CHWN4);
  957. }
  958. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_CHWN4_DET_ALL_ALGO) {
  959. require_compute_capability(7, 5);
  960. benchmark_target_algo_with_cudnn_tsc(
  961. handle_cuda(), get_detection_bench_args(), dtype::QuantizedS8{1.2f},
  962. dtype::QuantizedS8{1.3f}, dtype::QuantizedS32{1.2f * 1.3f},
  963. dtype::QuantizedS8{1.0f}, nullptr, param::ConvBias::Format::CHWN4);
  964. }
  965. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_NCHW4_TENSORCORE) {
  966. require_compute_capability(7, 5);
  967. benchmark_target_algo_with_cudnn_tsc(
  968. handle_cuda(), get_resnet50_bench_args(256),
  969. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  970. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f},
  971. "INT8_NCHW4_IMMA_IMPLICIT_GEMM_mma16x16x16",
  972. param::ConvBias::Format::NCHW4);
  973. }
  974. TEST_F(CUDA, BENCHMARK_CONV_BIAS_INT8_CHWN4_SMALL_CHANNEL) {
  975. require_compute_capability(6, 1);
  976. std::vector<BenchArgs> args;
  977. args.push_back(BenchArgs{64, 4, 224, 224, 64, 7, 2});
  978. benchmark_target_algo(
  979. handle_cuda(), args, dtype::QuantizedS8{1.2f},
  980. dtype::QuantizedS8{1.3f}, dtype::QuantizedS32{1.2f * 1.3f},
  981. dtype::QuantizedS8{1.0f}, "INT8_CHWN4_DOTPROD_IMPLICIT_GEMM",
  982. param::ConvBias::Format::CHWN4);
  983. }
  984. #if CUDA_VERSION >= 10020
  985. TEST_F(CUDA, BENCHMARK_CUTLASS_CONV_BIAS_INT8_NCHW32) {
  986. require_compute_capability(7, 5);
  987. benchmark_target_algo_with_cudnn_tsc(
  988. handle_cuda(), get_resnet50_bench_args(256),
  989. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  990. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f},
  991. "DIRECT:INT8_NCHW32_IMMA_IMPLICIT_GEMM",
  992. param::ConvBias::Format::NCHW32);
  993. }
  994. #endif
  995. TEST_F(CUDA, BENCHMARK_CUTLASS_CONV_BIAS_INT8_NCHW4) {
  996. require_compute_capability(6, 1);
  997. benchmark_target_algo(
  998. handle_cuda(), get_resnet50_bench_args(64),
  999. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  1000. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f},
  1001. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM", param::ConvBias::Format::NCHW4);
  1002. }
  1003. TEST_F(CUDA, BENCHMARK_SASS_CONV_BIAS_INT8_NCHW4_DET_FIRST) {
  1004. require_compute_capability(6, 1);
  1005. std::string algo = ConvBias::algo_name<ConvBias::DirectParam>(
  1006. "SASS_INT8_NCHW4_DOTPROD_IMPLICIT_GEMM_128X32_64",
  1007. ConvBias::DirectParam{});
  1008. benchmark_target_algo(handle_cuda(), get_det_first_bench_args(16),
  1009. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  1010. dtype::QuantizedS32{1.2f * 1.3f},
  1011. dtype::QuantizedS8{1.0f}, algo.c_str(),
  1012. param::ConvBias::Format::NCHW4);
  1013. }
  1014. TEST_F(CUDA, BENCHMARK_CUTLASS_CONV_BIAS_INT8_NCHW4_DET_FIRST) {
  1015. require_compute_capability(6, 1);
  1016. benchmark_target_algo(
  1017. handle_cuda(), get_det_first_bench_args(16),
  1018. dtype::QuantizedS8{1.2f}, dtype::QuantizedS8{1.3f},
  1019. dtype::QuantizedS32{1.2f * 1.3f}, dtype::QuantizedS8{1.0f},
  1020. "INT8_NCHW4_DOTPROD_IMPLICIT_GEMM_16", param::ConvBias::Format::NCHW4);
  1021. }
  1022. #endif
  1023. }
  1024. } // namespace test
  1025. } // namespace megdnn
  1026. // vim: syntax=cpp.doxygen

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