You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conv_bias_multi_thread_conv1x1.cpp 16 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /**
  2. * \file dnn/test/arm_common/conv_bias_multi_thread_conv1x1.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/dtype.h"
  13. #include "test/arm_common/fixture.h"
  14. #include "test/common/benchmarker.h"
  15. #include "test/common/conv_bias.h"
  16. #include "test/arm_common/cpuinfo_help.h"
  17. using namespace megdnn;
  18. using namespace test;
  19. using namespace conv_bias;
  20. #if MGB_ENABLE_DOT
  21. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_CONV1x1_QUANTIZEDSYM_MK4_DOT) {
  22. UniformIntRNG rng{-50, 50};
  23. #define cb(name) \
  24. checker_conv_bias_common( \
  25. get_nchw44_conv_bias_args({1}, QUAN_NLMODE, ONLY_BR_BIASMODE, 1, \
  26. true, false, true), \
  27. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  28. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  29. dtype::QuantizedS8(60.25f), name); \
  30. checker_conv_bias_common( \
  31. get_nchw44_conv_bias_args({1}, ONLY_IDENTITY_NLMODE, \
  32. ONLY_NO_BIASMODE, 1, true, false, true), \
  33. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  34. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  35. checker_conv_bias_common( \
  36. get_nchw44_conv_bias_args({1}, ONLY_IDENTITY_NLMODE, \
  37. ONLY_NO_BIASMODE, 1, true, false, true), \
  38. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), \
  39. dtype::Int32(), {}, name);
  40. float epsilon = 0.001;
  41. #if MEGDNN_AARCH64
  42. cb("CONV1x1:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD");
  43. #elif MEGDNN_ARMV7
  44. cb("CONV1x1:AARCH32_INT8_MK4_8X4X4_DOTPROD");
  45. #endif
  46. #undef cb
  47. }
  48. #endif
  49. // clang-format on
  50. /***************************** Conv1x1 Algo Test ***********************/
  51. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  52. using namespace conv_bias;
  53. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  54. #if MEGDNN_AARCH64
  55. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  56. #elif MEGDNN_ARMV7
  57. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  58. #endif
  59. std::vector<conv_bias::TestArg> gemv_args;
  60. for (auto&& arg : args)
  61. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  62. gemv_args.emplace_back(arg);
  63. }
  64. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  65. }
  66. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  67. using namespace conv_bias;
  68. std::vector<conv_bias::TestArg> args =
  69. get_nchw44_conv_bias_args({1},FULL_NLMODE,ALL_BIASMODE, 1, true);
  70. #if MEGDNN_AARCH64
  71. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  72. #elif MEGDNN_ARMV7
  73. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  74. #endif
  75. std::vector<conv_bias::TestArg> gemv_args;
  76. for (auto&& arg : args)
  77. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  78. gemv_args.emplace_back(arg);
  79. }
  80. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  81. }
  82. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  83. using namespace conv_bias;
  84. std::vector<conv_bias::TestArg> args =
  85. get_nchw44_conv_bias_args({1},FULL_NLMODE,ALL_BIASMODE, 1, true);
  86. std::vector<conv_bias::TestArg> args_of_4;
  87. for (auto&& arg : args) {
  88. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  89. args_of_4.push_back(arg);
  90. }
  91. }
  92. #if MEGDNN_AARCH64
  93. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  94. #elif MEGDNN_ARMV7
  95. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  96. #endif
  97. }
  98. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  99. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  100. using namespace conv_bias;
  101. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  102. NormalRNG rng(1);
  103. #if MEGDNN_AARCH64
  104. checker_conv_bias_common(args, handle(), &rng, 0.03, dtype::Float16{},
  105. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  106. "CONV1x1:AARCH64_F16_K8X24X1:48");
  107. #elif MEGDNN_ARMV7
  108. checker_conv_bias_common(args, handle(), &rng, 0.03, dtype::Float16{},
  109. dtype::Float16{}, dtype::Float16{}, dtype::Float16{},
  110. "CONV1x1:AARCH32_F16_K4X16X1:24");
  111. #endif
  112. std::vector<conv_bias::TestArg> gemv_args;
  113. for (auto&& arg : args)
  114. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  115. gemv_args.emplace_back(arg);
  116. }
  117. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  118. }
  119. #endif
  120. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  121. UniformIntRNG rng{-50, 50};
  122. float epsilon = 0.001;
  123. std::vector<conv_bias::TestArg> args =
  124. get_conv_bias_1x1_args(false, false, true, true);
  125. #define cb(name) \
  126. checker_conv_bias_common( \
  127. args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  128. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  129. dtype::QuantizedS8(60.25f), name);
  130. #if MEGDNN_AARCH64
  131. #if MGB_ENABLE_DOT
  132. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  133. #else
  134. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  135. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  136. #endif
  137. #elif MEGDNN_ARMV7
  138. epsilon = 1;
  139. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  140. #endif
  141. #undef cb
  142. std::vector<conv_bias::TestArg> gemv_args;
  143. for (auto&& arg : args)
  144. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  145. gemv_args.emplace_back(arg);
  146. }
  147. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon,
  148. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  149. dtype::QuantizedS32(6.25f),
  150. dtype::QuantizedS8(60.25f), "CONV1x1_GEMV");
  151. }
  152. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  153. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  154. UniformIntRNG rng{-50, 50};
  155. std::vector<conv_bias::TestArg> args =
  156. get_conv_bias_1x1_args(false, false, true, true);
  157. #define cb(name) \
  158. checker_conv_bias_common(args, handle(), &rng, epsilon, \
  159. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  160. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  161. dtype::QuantizedS32(1.2 * 1.3), \
  162. dtype::Quantized8Asymm(50.3f, (uint8_t)120), \
  163. name);
  164. float epsilon = 0.001;
  165. #if MEGDNN_AARCH64
  166. #if MGB_ENABLE_DOT
  167. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  168. #else
  169. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  170. #endif
  171. #elif MEGDNN_ARMV7
  172. epsilon = 1;
  173. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  174. #endif
  175. #undef cb
  176. std::vector<conv_bias::TestArg> gemv_args;
  177. for (auto&& arg : args)
  178. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  179. gemv_args.emplace_back(arg);
  180. }
  181. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon,
  182. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  183. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  184. dtype::QuantizedS32(1.2 * 1.3),
  185. dtype::Quantized8Asymm(50.3f, (uint8_t)120),
  186. "CONV1x1_GEMV");
  187. }
  188. #endif
  189. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  190. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUINT8x8x32) {
  191. NormalRNG rng(128.f);
  192. float epsilon = 0.001;
  193. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(true, true);
  194. #define cb(name) \
  195. checker_conv_bias_common(args, handle(), &rng, epsilon, \
  196. dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  197. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  198. dtype::QuantizedS32(1.2 * 1.3), {}, name);
  199. #if MEGDNN_AARCH64
  200. #if MGB_ENABLE_DOT
  201. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:24");
  202. #else
  203. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:48");
  204. #endif
  205. #elif MEGDNN_ARMV7
  206. #if MGB_ENABLE_DOT
  207. cb("CONV1x1:AARCH32_QUINT8_K4X8X4:48");
  208. #endif
  209. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:24");
  210. #endif
  211. #undef cb
  212. std::vector<conv_bias::TestArg> gemv_args;
  213. for (auto&& arg : args)
  214. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  215. gemv_args.emplace_back(arg);
  216. }
  217. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon,
  218. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  219. dtype::Quantized8Asymm(1.3f, (uint8_t)129),
  220. dtype::QuantizedS32(1.2 * 1.3), {},
  221. "CONV1x1_GEMV");
  222. }
  223. TEST_F(ARM_COMMON_MULTI_THREADS, CONVBIAS_1X1_S1_INT8x8x16) {
  224. UniformIntRNG rng{-50, 50};
  225. float epsilon = 0.001;
  226. std::vector<conv_bias::TestArg> args =
  227. get_conv_bias_1x1_args(false, true, false, false);
  228. std::vector<conv_bias::TestArg> args_nchw44 = get_nchw44_conv_bias_args(
  229. {1},ONLY_IDENTITY_NLMODE,BR_AND_BIAS_BIASMODE, 1, true);
  230. #define cb(name) \
  231. checker_conv_bias_common(args, handle(), &rng, epsilon, dtype::Int8{}, \
  232. dtype::Int8{}, dtype::Int16{}, dtype::Int16{}, \
  233. name);
  234. #define cb_nchw44(name) \
  235. checker_conv_bias_common(args_nchw44, handle(), &rng, epsilon, \
  236. dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, \
  237. dtype::Int16{}, name);
  238. #if MEGDNN_AARCH64
  239. cb("CONV1x1:AARCH64_INT8X8X16_K8X8X8:24");
  240. cb("CONV1x1:AARCH64_INT8X8X16_K4X4X16:24");
  241. cb_nchw44("CONV1x1:AARCH64_INT8X8X16_MK4_4X4X8:48");
  242. cb_nchw44("CONV1x1:AARCH64_INT8X8X16_MK4_16X12X4:48");
  243. #elif MEGDNN_ARMV7
  244. cb("CONV1x1:ARMV7_INT8X8X16_K4X8X8:24");
  245. cb("CONV1x1:ARMV7_INT8X8X16_K4X2X16:48");
  246. cb_nchw44("CONV1x1:ARMV7_INT8X8X16_MK4_K8X8X4:48");
  247. #endif
  248. cb("CONV1x1:ARM_COMMON_INT8X8X16:48");
  249. #undef cb
  250. #undef cb_nchw44
  251. std::vector<conv_bias::TestArg> gemv_args;
  252. for (auto&& arg : args)
  253. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  254. gemv_args.emplace_back(arg);
  255. }
  256. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon, dtype::Int8{},
  257. dtype::Int8{}, dtype::Int16{}, dtype::Int16{},
  258. "CONV1x1_GEMV");
  259. }
  260. #endif
  261. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32) {
  262. using namespace conv_bias;
  263. std::vector<conv_bias::TestArg> args =
  264. get_conv_bias_1x1_args(false, true, false, false);
  265. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  266. #if MEGDNN_AARCH64
  267. #if MGB_ENABLE_DOT
  268. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:48");
  269. #else
  270. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  271. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:24");
  272. #endif
  273. #elif MEGDNN_ARMV7
  274. #if MGB_ENABLE_DOT
  275. cb("CONV1x1:AARCH32_INT8_K6X8X4:48");
  276. #endif
  277. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:24");
  278. #endif
  279. #if MEGDNN_ARMV7
  280. cb("CONV1x1:ARMV7_INT8X8X32_K4X2X16:48");
  281. #endif
  282. #undef cb
  283. std::vector<conv_bias::TestArg> gemv_args;
  284. for (auto&& arg : args)
  285. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  286. gemv_args.emplace_back(arg);
  287. }
  288. checker_conv_bias_mul_int8x8x32(gemv_args, handle(), "CONV1x1_GEMV");
  289. }
  290. //! enable none dot algo now
  291. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_MK4) {
  292. using namespace conv_bias;
  293. std::vector<conv_bias::TestArg> args =
  294. get_nchw44_conv_bias_args({1},ONLY_IDENTITY_NLMODE,ONLY_NO_BIASMODE, 1,true);
  295. #define cb(name) checker_conv_bias_mul_int8x8x32(args, handle(), name);
  296. #if MEGDNN_AARCH64
  297. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  298. #elif MEGDNN_ARMV7
  299. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  300. #endif
  301. #undef cb
  302. UniformIntRNG rng{-50, 50};
  303. float epsilon = 0.001;
  304. #define cb(name) \
  305. checker_conv_bias_common( \
  306. get_nchw44_conv_bias_args({1}, QUAN_NLMODE, BR_AND_NO_BIASMODE, 1, \
  307. true), \
  308. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  309. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  310. dtype::QuantizedS8(60.25f), name);
  311. #if MEGDNN_AARCH64
  312. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  313. #elif MEGDNN_ARMV7
  314. epsilon = 1;
  315. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  316. #endif
  317. #undef cb
  318. }
  319. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  320. using namespace conv_bias;
  321. std::vector<conv_bias::TestArg> args =
  322. get_nchw44_conv_bias_args({1},QUAN_NLMODE,BR_AND_NO_BIASMODE, 1, true);
  323. UniformIntRNG rng{-50, 50};
  324. float epsilon = 0.001;
  325. std::vector<conv_bias::TestArg> gemv_args;
  326. for (auto&& arg : args)
  327. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  328. gemv_args.emplace_back(arg);
  329. }
  330. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon,
  331. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  332. dtype::QuantizedS32(6.25f), dtype::QuantizedS8(60.25f),
  333. "CONV1x1_GEMV");
  334. }
  335. #if MGB_ENABLE_DOT
  336. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  337. using namespace conv_bias;
  338. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  339. {1}, QUAN_NLMODE, BR_AND_NO_BIASMODE, 1, true, false, true);
  340. UniformIntRNG rng{-50, 50};
  341. float epsilon = 0.001;
  342. std::vector<conv_bias::TestArg> gemv_args;
  343. for (auto&& arg : args)
  344. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  345. gemv_args.emplace_back(arg);
  346. }
  347. checker_conv_bias_common(gemv_args, handle(), &rng, epsilon,
  348. dtype::QuantizedS8(2.5f), dtype::QuantizedS8(2.5f),
  349. dtype::QuantizedS32(6.25f),
  350. dtype::QuantizedS8(60.25f), "CONV1x1_GEMV");
  351. }
  352. #endif
  353. #if MEGDNN_AARCH64
  354. #if MGB_ENABLE_CPUINFO
  355. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_MK4_PACK_F32_A55) {
  356. CpuInfoTmpReplace cpu_replace_guard(cpuinfo_uarch_cortex_a55);
  357. using namespace conv_bias;
  358. std::vector<conv_bias::TestArg> args =
  359. get_nchw44_conv_bias_args({1},FULL_NLMODE,ALL_BIASMODE, 1, true);
  360. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  361. }
  362. #endif
  363. #endif
  364. #if MEGDNN_AARCH64
  365. #if MGB_ENABLE_CPUINFO
  366. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_MK4_PACK_F32_A53) {
  367. CpuInfoTmpReplace cpu_replace_guard(cpuinfo_uarch_cortex_a53);
  368. using namespace conv_bias;
  369. std::vector<conv_bias::TestArg> args =
  370. get_nchw44_conv_bias_args({1},FULL_NLMODE,ALL_BIASMODE, 1, true);
  371. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  372. }
  373. #endif
  374. #endif
  375. // vim: syntax=cpp.doxygen

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