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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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( \
  26. {1}, QUAN_NLMODE, ONLY_BR_BIASMODE, 1, 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( \
  32. {1}, ONLY_IDENTITY_NLMODE, ONLY_NO_BIASMODE, 1, true, false, \
  33. true), \
  34. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  35. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), {}, name); \
  36. checker_conv_bias_common( \
  37. get_nchw44_conv_bias_args( \
  38. {1}, ONLY_IDENTITY_NLMODE, ONLY_NO_BIASMODE, 1, true, false, \
  39. true), \
  40. handle(), &rng, epsilon, dtype::Int8(), dtype::Int8(), dtype::Int32(), {}, \
  41. name);
  42. float epsilon = 0.001;
  43. #if MEGDNN_AARCH64
  44. cb("CONV1x1:AARCH64_INT8X8X32_MK4_8X12X4_DOTPROD");
  45. #elif MEGDNN_ARMV7
  46. cb("CONV1x1:AARCH32_INT8_MK4_8X4X4_DOTPROD");
  47. #endif
  48. #undef cb
  49. }
  50. #endif
  51. // clang-format on
  52. /***************************** Conv1x1 Algo Test ***********************/
  53. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F32) {
  54. using namespace conv_bias;
  55. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  56. #if MEGDNN_AARCH64
  57. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32K8X12X1:24");
  58. #elif MEGDNN_ARMV7
  59. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32:48");
  60. #endif
  61. std::vector<conv_bias::TestArg> gemv_args;
  62. for (auto&& arg : args)
  63. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  64. gemv_args.emplace_back(arg);
  65. }
  66. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  67. }
  68. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_PACK_F32) {
  69. using namespace conv_bias;
  70. std::vector<conv_bias::TestArg> args =
  71. get_nchw44_conv_bias_args({1}, FULL_NLMODE, ALL_BIASMODE, 1, true);
  72. #if MEGDNN_AARCH64
  73. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  74. #elif MEGDNN_ARMV7
  75. check_conv_bias(args, handle(), "CONV1x1:ARMV7_F32_MK4_PACK_4X12:24");
  76. #endif
  77. std::vector<conv_bias::TestArg> gemv_args;
  78. for (auto&& arg : args)
  79. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  80. gemv_args.emplace_back(arg);
  81. }
  82. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  83. }
  84. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_MK4_NO_PACK_F32) {
  85. using namespace conv_bias;
  86. std::vector<conv_bias::TestArg> args =
  87. get_nchw44_conv_bias_args({1}, FULL_NLMODE, ALL_BIASMODE, 1, true);
  88. std::vector<conv_bias::TestArg> args_of_4;
  89. for (auto&& arg : args) {
  90. if (arg.src.shape[2] * arg.src.shape[3] % 4 == 0) {
  91. args_of_4.push_back(arg);
  92. }
  93. }
  94. #if MEGDNN_AARCH64
  95. check_conv_bias(args_of_4, handle(), "CONV1x1:AARCH64_F32_MK4_4x16:24");
  96. #elif MEGDNN_ARMV7
  97. check_conv_bias(args_of_4, handle(), "CONV1x1:ARMV7_F32_MK4_4x8:48");
  98. #endif
  99. }
  100. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  101. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_F16) {
  102. using namespace conv_bias;
  103. std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
  104. NormalRNG rng(1);
  105. #if MEGDNN_AARCH64
  106. checker_conv_bias_common(
  107. args, handle(), &rng, 0.03, dtype::Float16{}, dtype::Float16{},
  108. dtype::Float16{}, dtype::Float16{}, "CONV1x1:AARCH64_F16_K8X24X1:48");
  109. #elif MEGDNN_ARMV7
  110. checker_conv_bias_common(
  111. args, handle(), &rng, 0.03, dtype::Float16{}, dtype::Float16{},
  112. dtype::Float16{}, dtype::Float16{}, "CONV1x1:AARCH32_F16_K4X16X1:24");
  113. #endif
  114. std::vector<conv_bias::TestArg> gemv_args;
  115. for (auto&& arg : args)
  116. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  117. gemv_args.emplace_back(arg);
  118. }
  119. check_conv_bias(gemv_args, handle(), "CONV1x1_GEMV");
  120. }
  121. #endif
  122. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDSYM) {
  123. UniformIntRNG rng{-50, 50};
  124. float epsilon = 0.001;
  125. std::vector<conv_bias::TestArg> args =
  126. get_conv_bias_1x1_args(false, false, true, true);
  127. #define cb(name) \
  128. checker_conv_bias_common( \
  129. args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  130. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  131. dtype::QuantizedS8(60.25f), name);
  132. #if MEGDNN_AARCH64
  133. #if MGB_ENABLE_DOT
  134. cb("CONV1x1:AARCH64_INT8X8X32_K8X12X4_DOTPROD:24");
  135. #else
  136. cb("CONV1x1:AARCH64_INT8X8X32_K8X8X8:24");
  137. cb("CONV1x1:AARCH64_INT8X8X32_K4X4X16:48");
  138. #endif
  139. #elif MEGDNN_ARMV7
  140. epsilon = 1;
  141. cb("CONV1x1:ARMV7_INT8X8X32_K4X8X8:48");
  142. #endif
  143. #undef cb
  144. std::vector<conv_bias::TestArg> gemv_args;
  145. for (auto&& arg : args)
  146. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  147. gemv_args.emplace_back(arg);
  148. }
  149. checker_conv_bias_common(
  150. gemv_args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f),
  151. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  152. dtype::QuantizedS8(60.25f), "CONV1x1_GEMV");
  153. }
  154. #if MEGDNN_AARCH64 || MEGDNN_ARMV7
  155. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_QUANTIZEDASYM) {
  156. UniformIntRNG rng{-50, 50};
  157. std::vector<conv_bias::TestArg> args =
  158. get_conv_bias_1x1_args(false, false, true, true);
  159. #define cb(name) \
  160. checker_conv_bias_common( \
  161. args, handle(), &rng, epsilon, dtype::Quantized8Asymm(1.2f, (uint8_t)125), \
  162. dtype::Quantized8Asymm(1.3f, (uint8_t)129), \
  163. dtype::QuantizedS32(1.2 * 1.3), \
  164. dtype::Quantized8Asymm(50.3f, (uint8_t)120), name);
  165. float epsilon = 0.001;
  166. #if MEGDNN_AARCH64
  167. #if MGB_ENABLE_DOT
  168. cb("CONV1x1:AARCH64_QUINT8_K8X8X4_DOTPROD:48");
  169. #else
  170. cb("CONV1x1:AARCH64_QUINT8_K8X8X8:24");
  171. #endif
  172. #elif MEGDNN_ARMV7
  173. epsilon = 1;
  174. cb("CONV1x1:ARMV7_QUINT8_K4X8X8:48");
  175. #endif
  176. #undef cb
  177. std::vector<conv_bias::TestArg> gemv_args;
  178. for (auto&& arg : args)
  179. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  180. gemv_args.emplace_back(arg);
  181. }
  182. checker_conv_bias_common(
  183. gemv_args, handle(), &rng, epsilon,
  184. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  185. dtype::Quantized8Asymm(1.3f, (uint8_t)129), dtype::QuantizedS32(1.2 * 1.3),
  186. dtype::Quantized8Asymm(50.3f, (uint8_t)120), "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( \
  196. args, handle(), &rng, epsilon, 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(
  218. gemv_args, handle(), &rng, epsilon,
  219. dtype::Quantized8Asymm(1.2f, (uint8_t)125),
  220. dtype::Quantized8Asymm(1.3f, (uint8_t)129), 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( \
  232. args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  233. dtype::Int16{}, dtype::Int16{}, name);
  234. #define cb_nchw44(name) \
  235. checker_conv_bias_common( \
  236. args_nchw44, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, \
  237. dtype::Int16{}, 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(
  257. gemv_args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
  258. dtype::Int16{}, dtype::Int16{}, "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 = get_nchw44_conv_bias_args(
  294. {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, true), \
  307. handle(), &rng, epsilon, dtype::QuantizedS8(2.5f), \
  308. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f), \
  309. dtype::QuantizedS8(60.25f), name);
  310. #if MEGDNN_AARCH64
  311. cb("CONV1x1:AARCH64_INT8X8X32_MK4_4X4X16:24");
  312. #elif MEGDNN_ARMV7
  313. epsilon = 1;
  314. cb("CONV1x1:ARMV7_INT8X8X32_MK4_4X2X16:24");
  315. #endif
  316. #undef cb
  317. }
  318. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44) {
  319. using namespace conv_bias;
  320. std::vector<conv_bias::TestArg> args =
  321. get_nchw44_conv_bias_args({1}, QUAN_NLMODE, BR_AND_NO_BIASMODE, 1, true);
  322. UniformIntRNG rng{-50, 50};
  323. float epsilon = 0.001;
  324. std::vector<conv_bias::TestArg> gemv_args;
  325. for (auto&& arg : args)
  326. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  327. gemv_args.emplace_back(arg);
  328. }
  329. checker_conv_bias_common(
  330. gemv_args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f),
  331. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  332. dtype::QuantizedS8(60.25f), "CONV1x1_GEMV");
  333. }
  334. #if MGB_ENABLE_DOT
  335. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_S1_INT8x8x32_NCHW44_DOT) {
  336. using namespace conv_bias;
  337. std::vector<conv_bias::TestArg> args = get_nchw44_conv_bias_args(
  338. {1}, QUAN_NLMODE, BR_AND_NO_BIASMODE, 1, true, false, true);
  339. UniformIntRNG rng{-50, 50};
  340. float epsilon = 0.001;
  341. std::vector<conv_bias::TestArg> gemv_args;
  342. for (auto&& arg : args)
  343. if (arg.src.shape[2] == 1 && arg.src.shape[3] == 1) {
  344. gemv_args.emplace_back(arg);
  345. }
  346. checker_conv_bias_common(
  347. gemv_args, handle(), &rng, epsilon, dtype::QuantizedS8(2.5f),
  348. dtype::QuantizedS8(2.5f), dtype::QuantizedS32(6.25f),
  349. dtype::QuantizedS8(60.25f), "CONV1x1_GEMV");
  350. }
  351. #endif
  352. #if MEGDNN_AARCH64
  353. #if MGB_ENABLE_CPUINFO
  354. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_MK4_PACK_F32_A55) {
  355. CpuInfoTmpReplace cpu_replace_guard(cpuinfo_uarch_cortex_a55);
  356. using namespace conv_bias;
  357. std::vector<conv_bias::TestArg> args =
  358. get_nchw44_conv_bias_args({1}, FULL_NLMODE, ALL_BIASMODE, 1, true);
  359. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  360. }
  361. #endif
  362. #endif
  363. #if MEGDNN_AARCH64
  364. #if MGB_ENABLE_CPUINFO
  365. TEST_F(ARM_COMMON_MULTI_THREADS, CONV_BIAS_1X1_MK4_PACK_F32_A53) {
  366. CpuInfoTmpReplace cpu_replace_guard(cpuinfo_uarch_cortex_a53);
  367. using namespace conv_bias;
  368. std::vector<conv_bias::TestArg> args =
  369. get_nchw44_conv_bias_args({1}, FULL_NLMODE, ALL_BIASMODE, 1, true);
  370. check_conv_bias(args, handle(), "CONV1x1:AARCH64_F32_MK4_K8X12X1:24");
  371. }
  372. #endif
  373. #endif
  374. // vim: syntax=cpp.doxygen