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

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