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.

matrix_mul.cpp 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /**
  2. * \file dnn/test/arm_common/matrix_mul.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 "test/arm_common/fixture.h"
  13. #include "test/common/benchmarker.h"
  14. #include "test/common/checker.h"
  15. #include "test/common/matrix_mul.h"
  16. #include "test/common/rng.h"
  17. #include "test/common/task_record_check.h"
  18. #if MGB_ENABLE_CPUINFO
  19. #include "cpuinfo.h"
  20. #endif
  21. using namespace megdnn;
  22. using namespace test;
  23. TEST_F(ARM_COMMON, MATRIX_MUL_INT8x8x32) {
  24. matrix_mul::check_matrix_mul(
  25. dtype::Int8{}, dtype::Int8{}, dtype::Int32{}, handle());
  26. }
  27. TEST_F(ARM_COMMON, MATRIX_MUL_INT8x8x16) {
  28. matrix_mul::check_matrix_mul(
  29. dtype::Int8{}, dtype::Int8{}, dtype::Int16{}, handle());
  30. }
  31. TEST_F(ARM_COMMON, MATRIX_MUL_QUINT8) {
  32. matrix_mul::check_matrix_mul(
  33. dtype::Quantized8Asymm(1.2f, (uint8_t)127),
  34. dtype::Quantized8Asymm(1.3f, (uint8_t)129), {}, handle());
  35. }
  36. TEST_F(ARM_COMMON, MATRIX_MUL_FP32) {
  37. Checker<MatrixMul> checker(handle());
  38. using Param = MatrixMul::Param;
  39. auto run = [&](size_t M, size_t K, size_t N) {
  40. Param param;
  41. param.transposeA = false;
  42. param.transposeB = false;
  43. TensorShape A, B;
  44. A = TensorShape{M, K};
  45. B = TensorShape{K, N};
  46. checker.set_param(param)
  47. .set_dtype(0, dtype::Float32())
  48. .set_dtype(1, dtype::Float32())
  49. .set_dtype(2, dtype::Float32())
  50. .execs({A, B, {}});
  51. };
  52. checker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_F32_GEMV"));
  53. // M < 8
  54. for (size_t M : {1, 2, 3, 4, 5, 6, 7})
  55. for (size_t K : {7, 1024, 2048})
  56. for (size_t N : {7, 1024, 2056})
  57. run(M, K, N);
  58. // M = 8,K = 1, 2
  59. for (size_t M : {8})
  60. for (size_t K : {1, 2})
  61. for (size_t N : {7, 1024, 2056})
  62. run(M, K, N);
  63. // N = 1
  64. for (size_t M : {1, 2, 3, 4, 5, 6, 7})
  65. for (size_t K : {7, 1024, 2048})
  66. for (size_t N : {1})
  67. run(M, K, N);
  68. }
  69. #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
  70. TEST_F(ARM_COMMON, MATRIX_MUL_FP16) {
  71. Checker<MatrixMul> checker(handle());
  72. checker.set_epsilon(1e-2);
  73. NormalRNG rng(2.f);
  74. checker.set_rng(0, &rng).set_rng(1, &rng);
  75. using Param = MatrixMul::Param;
  76. auto args = matrix_mul::get_matmul_args_no_mask();
  77. for (auto& arg : args) {
  78. size_t m = arg.m, n = arg.n, k = arg.k;
  79. Param param;
  80. param.transposeA = false;
  81. param.transposeB = false;
  82. TensorShape A, B;
  83. A = TensorShape{m, k};
  84. B = TensorShape{k, n};
  85. checker.set_param(param)
  86. .set_dtype(0, dtype::Float16())
  87. .set_dtype(1, dtype::Float16())
  88. .set_dtype(2, dtype::Float16())
  89. .execs({A, B, {}});
  90. }
  91. }
  92. TEST_F(ARM_COMMON, MATRIX_MUL_FP16_TEST) {
  93. Checker<MatrixMul> checker(handle());
  94. using Param = MatrixMul::Param;
  95. checker.set_epsilon(1e-2);
  96. NormalRNG rng(2.f);
  97. checker.set_rng(0, &rng).set_rng(1, &rng);
  98. auto run = [&](size_t M, size_t K, size_t N) {
  99. Param param;
  100. param.transposeA = false;
  101. param.transposeB = false;
  102. TensorShape A, B;
  103. A = TensorShape{M, K};
  104. B = TensorShape{K, N};
  105. checker.set_param(param)
  106. .set_dtype(0, dtype::Float16())
  107. .set_dtype(1, dtype::Float16())
  108. .set_dtype(2, dtype::Float16())
  109. .execs({A, B, {}});
  110. };
  111. checker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_F16_GEMV"));
  112. // M = 1, 2, 3, 4
  113. for (size_t M : {1, 2, 3, 4})
  114. for (size_t K : {7, 512, 1024})
  115. for (size_t N : {13, 1024, 2048})
  116. run(M, K, N);
  117. // N = 1
  118. for (size_t M : {1, 2, 3, 4})
  119. for (size_t K : {7, 512, 1024})
  120. for (size_t N : {1})
  121. run(M, K, N);
  122. }
  123. #endif
  124. TEST_F(ARM_COMMON, QINT8x8x32_GEMV) {
  125. Checker<MatrixMul> checker(handle());
  126. using Param = MatrixMul::Param;
  127. checker.set_before_exec_callback(
  128. AlgoChecker<MatrixMul>("ARM_COMMON_INT8X8X32_GEMV"));
  129. std::unique_ptr<RNG> rng = std::make_unique<UniformIntRNG>(-127, 127);
  130. checker.set_rng(0, rng.get()).set_rng(1, rng.get());
  131. auto run = [&](size_t M, size_t K, size_t N) {
  132. Param param;
  133. param.transposeA = false;
  134. param.transposeB = false;
  135. TensorShape A, B;
  136. A = TensorShape{M, K};
  137. B = TensorShape{K, N};
  138. checker.set_param(param)
  139. .set_dtype(0, dtype::QuantizedS8(2.5f))
  140. .set_dtype(1, dtype::QuantizedS8(2.5f))
  141. .set_dtype(2, dtype::QuantizedS32(6.25f))
  142. .execs({A, B, {}});
  143. };
  144. // N = 1
  145. for (size_t M : {1, 10, 16, 33, 64})
  146. for (size_t K : {7, 512, 1024})
  147. for (size_t N : {1})
  148. run(M, K, N);
  149. }
  150. TEST_F(ARM_COMMON, QINT8x8x32_GEMV_MK4) {
  151. Checker<MatrixMul> checker(handle());
  152. using Param = MatrixMul::Param;
  153. checker.set_before_exec_callback(
  154. AlgoChecker<MatrixMul>("ARM_COMMON_INT8X8X32_GEMV_MK4"));
  155. std::unique_ptr<RNG> rng = std::make_unique<UniformIntRNG>(-127, 127);
  156. checker.set_rng(0, rng.get()).set_rng(1, rng.get());
  157. auto run = [&](size_t M, size_t K, size_t N) {
  158. MEGDNN_MARK_USED_VAR(N);
  159. Param param;
  160. param.format = param::MatrixMul::Format::MK4;
  161. param.transposeA = false;
  162. param.transposeB = false;
  163. TensorShape A, B;
  164. A = TensorShape{M / 4, K / 4, 4, 4};
  165. B = TensorShape{K / 4, 1, 4};
  166. checker.set_param(param)
  167. .set_dtype(0, dtype::QuantizedS8(2.5f))
  168. .set_dtype(1, dtype::QuantizedS8(2.5f))
  169. .set_dtype(2, dtype::QuantizedS32(6.25f))
  170. .execs({A, B, {}});
  171. };
  172. // N = 1
  173. for (size_t M : {4, 16, 128, 1024})
  174. for (size_t K : {4, 8, 12, 16, 20, 24, 256, 1024})
  175. run(M, K, 1);
  176. }
  177. #if MGB_ENABLE_DOT
  178. TEST_F(ARM_COMMON, QINT8x8x32_GEMV_MK4_DOT) {
  179. Checker<MatrixMul> checker(handle());
  180. using Param = MatrixMul::Param;
  181. checker.set_before_exec_callback(
  182. AlgoChecker<MatrixMul>("ARM_COMMON_INT8X8X32_GEMV_MK4_DOT"));
  183. std::unique_ptr<RNG> rng = std::make_unique<UniformIntRNG>(-127, 127);
  184. checker.set_rng(0, rng.get()).set_rng(1, rng.get());
  185. auto run = [&](size_t M, size_t K, size_t N) {
  186. Param param;
  187. param.format = param::MatrixMul::Format::MK4_DOT;
  188. param.transposeA = false;
  189. param.transposeB = false;
  190. TensorShape A, B;
  191. A = TensorShape{M / 4, K / 4, 4, 4};
  192. B = TensorShape{K / 4, 1, 4};
  193. checker.set_param(param)
  194. .set_dtype(0, dtype::QuantizedS8(2.5f))
  195. .set_dtype(1, dtype::QuantizedS8(2.5f))
  196. .set_dtype(2, dtype::QuantizedS32(6.25f))
  197. .execs({A, B, {}});
  198. };
  199. // N = 1
  200. for (size_t M : {4, 16, 128, 1024})
  201. for (size_t K : {4, 8, 12, 16, 20, 24, 256, 1024})
  202. run(M, K, 1);
  203. }
  204. #endif
  205. TEST_F(ARM_COMMON, QINT8x8x32_GEVM) {
  206. Checker<MatrixMul> checker(handle());
  207. using Param = MatrixMul::Param;
  208. checker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_GEVM"));
  209. std::unique_ptr<RNG> rng = std::make_unique<UniformIntRNG>(-127, 127);
  210. checker.set_rng(0, rng.get()).set_rng(1, rng.get());
  211. auto run = [&](size_t M, size_t K, size_t N) {
  212. Param param;
  213. param.transposeA = false;
  214. param.transposeB = true;
  215. TensorShape A, B;
  216. A = TensorShape{M, K};
  217. B = TensorShape{N, K};
  218. checker.set_param(param)
  219. .set_dtype(0, dtype::QuantizedS8(2.5f))
  220. .set_dtype(1, dtype::QuantizedS8(2.5f))
  221. .set_dtype(2, dtype::QuantizedS32(6.25f))
  222. .execs({A, B, {}});
  223. };
  224. // M = 1
  225. for (size_t N : {1, 10, 16, 33, 64})
  226. for (size_t K : {7, 512, 1024})
  227. for (size_t M : {1})
  228. run(M, K, N);
  229. }
  230. TEST_F(ARM_COMMON, FP32_GEVM) {
  231. Checker<MatrixMul> checker(handle());
  232. using Param = MatrixMul::Param;
  233. checker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_GEVM"));
  234. checker.set_epsilon(1e-2);
  235. auto run = [&](size_t M, size_t K, size_t N) {
  236. Param param;
  237. param.transposeA = false;
  238. param.transposeB = true;
  239. TensorShape A, B;
  240. A = TensorShape{M, K};
  241. B = TensorShape{N, K};
  242. checker.set_param(param).execs({A, B, {}});
  243. };
  244. // M = 1
  245. for (size_t M : {1})
  246. for (size_t K : {1000, 4096})
  247. for (size_t N : {1000, 4096})
  248. run(M, K, N);
  249. }
  250. TEST_F(ARM_COMMON, MATRIX_MUL_RECORD) {
  251. TaskRecordChecker<MatrixMul> checker(0);
  252. checker.set_epsilon(1e-2);
  253. NormalRNG rng(2.f);
  254. checker.set_rng(0, &rng).set_rng(1, &rng);
  255. using Param = MatrixMul::Param;
  256. auto args = matrix_mul::get_matmul_args_no_mask();
  257. for (auto& arg : args) {
  258. size_t m = arg.m, n = arg.n, k = arg.k;
  259. Param param;
  260. param.transposeA = false;
  261. param.transposeB = false;
  262. TensorShape A, B;
  263. A = TensorShape{m, k};
  264. B = TensorShape{k, n};
  265. checker.set_param(param)
  266. .set_dtype(0, dtype::Float32())
  267. .set_dtype(1, dtype::Float32())
  268. .set_dtype(2, dtype::Float32())
  269. .execs({A, B, {}});
  270. }
  271. }
  272. #if MEGDNN_WITH_BENCHMARK
  273. TEST_F(ARM_COMMON, BENCHMARK_SGEMV) {
  274. int exec_times = 10;
  275. Benchmarker<MatrixMul> benchmarker(handle());
  276. benchmarker.set_times(exec_times);
  277. auto run = [&](size_t M, size_t K, size_t N) {
  278. printf("SGEMV: (%zu, %zu, %zu)\n", M, K, N);
  279. benchmarker.set_dtype(0, dtype::Float32()).set_dtype(1, dtype::Float32());
  280. auto time = benchmarker.exec({{M, K}, {K, N}, {}}) / exec_times;
  281. auto computations = 2.f * M * K * N * 1e-6;
  282. auto perf = computations / time;
  283. printf("gemv fp32, Performance is %f Gflops\n", perf);
  284. };
  285. printf("warm up:\n");
  286. for (int i = 0; i < 50; i++) {
  287. benchmarker.set_dtype(0, dtype::Float32())
  288. .set_dtype(1, dtype::Float32())
  289. .set_display(false)
  290. .exec({{2, 1024}, {1024, 512}, {}});
  291. benchmarker.set_display(true);
  292. }
  293. // run gemv
  294. for (size_t M : {1, 2, 4, 8})
  295. for (size_t K : {1024, 1536, 2048})
  296. for (size_t N : {512, 1024})
  297. run(M, K, N);
  298. for (size_t M : {4, 64, 1024, 4096})
  299. for (size_t K : {128, 256, 1024, 4096})
  300. run(M, K, 1);
  301. }
  302. TEST_F(ARM_COMMON, BENCHMARK_SGEMV_FP32) {
  303. int exec_times = 50;
  304. Benchmarker<MatrixMul> benchmarker(handle());
  305. benchmarker.set_times(exec_times);
  306. benchmarker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_F32_GEMV"));
  307. auto run = [&](size_t M, size_t K, size_t N) {
  308. printf("SGEMV: (%zu, %zu, %zu)\n", M, K, N);
  309. benchmarker.set_dtype(0, dtype::Float32())
  310. .set_dtype(1, dtype::Float32())
  311. .set_dtype(2, dtype::Float32());
  312. auto time = benchmarker.exec({{M, K}, {K, N}, {}}) / exec_times;
  313. auto computations = 2 * M * K * N * 1e-6;
  314. auto perf = computations / time;
  315. printf("gemv fp32, Performance is %f Gflops\n", perf);
  316. };
  317. printf("warm up:\n");
  318. for (int i = 0; i < 50; i++) {
  319. benchmarker.set_dtype(0, dtype::Float32())
  320. .set_dtype(1, dtype::Float32())
  321. .set_display(false)
  322. .exec({{2, 1024}, {1024, 512}, {}});
  323. benchmarker.set_display(true);
  324. }
  325. // run gemv
  326. run(12, 48, 1);
  327. run(48, 12, 1);
  328. run(32, 128, 1);
  329. run(128, 32, 1);
  330. run(64, 256, 1);
  331. run(256, 64, 1);
  332. run(128, 512, 1);
  333. run(512, 128, 1);
  334. run(256, 1024, 1);
  335. run(1024, 256, 1);
  336. }
  337. TEST_F(ARM_COMMON, BENCHMARK_SGEMV_MK4) {
  338. int exec_times = 10;
  339. using Param = MatrixMul::Param;
  340. Param param;
  341. param.format = param::MatrixMul::Format::MK4;
  342. param.transposeA = false;
  343. param.transposeB = false;
  344. Benchmarker<MatrixMul> benchmarker(handle());
  345. benchmarker.set_times(exec_times);
  346. benchmarker.set_dtype(0, dtype::Float32())
  347. .set_dtype(1, dtype::Float32())
  348. .set_param(param);
  349. auto run = [&](size_t M, size_t K) {
  350. printf("SGEMV_MK4: (%zu, %zu, 1)\n", M, K);
  351. TensorShape A, B;
  352. A = TensorShape{M / 4, K / 4, 4, 4};
  353. B = TensorShape{K / 4, 1, 4};
  354. auto time = benchmarker.exec({A, B, {}}) / exec_times;
  355. auto computations = 2.f * M * K * 1e-6;
  356. auto perf = computations / time;
  357. printf("gemv mk4 fp32, Performance is %f Gflops\n", perf);
  358. };
  359. printf("warm up:\n");
  360. for (int i = 0; i < 50; i++) {
  361. benchmarker.set_dtype(0, dtype::Float32())
  362. .set_dtype(1, dtype::Float32())
  363. .set_dtype(2, dtype::Float32())
  364. .set_display(false)
  365. .exec({{4, 256, 4, 4}, {256, 1, 4}, {}});
  366. }
  367. // run gemv mk4
  368. for (size_t M : {4, 64, 1024, 4096})
  369. for (size_t K : {128, 1024, 4096})
  370. run(M, K);
  371. }
  372. TEST_F(ARM_COMMON, BENCHMARK_SGEMV_FP16) {
  373. int exec_times = 50;
  374. Benchmarker<MatrixMul> benchmarker(handle());
  375. benchmarker.set_times(exec_times);
  376. benchmarker.set_before_exec_callback(AlgoChecker<MatrixMul>("ARM_COMMON_F16_GEMV"));
  377. auto run = [&](size_t M, size_t K, size_t N) {
  378. printf("SGEMV_FP16: (%zu, %zu, %zu)\n", M, K, N);
  379. benchmarker.set_dtype(0, dtype::Float16())
  380. .set_dtype(1, dtype::Float16())
  381. .set_dtype(2, dtype::Float16());
  382. auto time = benchmarker.exec({{M, K}, {K, N}, {}}) / exec_times;
  383. auto computations = 2 * M * K * N * 1e-6;
  384. auto perf = computations / time;
  385. printf("gemv fp16, Performance is %f Gflops\n", perf);
  386. };
  387. printf("warm up:\n");
  388. for (int i = 0; i < 50; i++) {
  389. benchmarker.set_dtype(0, dtype::Float16())
  390. .set_dtype(1, dtype::Float16())
  391. .set_dtype(2, dtype::Float16())
  392. .set_display(false)
  393. .exec({{2, 1024}, {1024, 512}, {}});
  394. benchmarker.set_display(true);
  395. }
  396. // run gemv
  397. for (size_t M : {1, 2, 3, 4})
  398. for (size_t K : {1024, 1536, 2048})
  399. for (size_t N : {512, 1024})
  400. run(M, K, N);
  401. }
  402. TEST_F(ARM_COMMON, BENCHMARK_SGEMM) {
  403. int exec_times = 10;
  404. Benchmarker<MatrixMul> benchmarker(handle());
  405. benchmarker.set_times(exec_times);
  406. float mod = 1000 * exec_times / 1e9;
  407. auto run = [&](size_t M, size_t K, size_t N) {
  408. float time = 1.f, perf = 1.f;
  409. printf("SGEMM: (%zu, %zu, %zu)\n", M, K, N);
  410. benchmarker.set_dtype(0, dtype::Float32()).set_dtype(1, dtype::Float32());
  411. time = benchmarker.exec({{M, K}, {K, N}, {}});
  412. perf = 2.f * M * K * N / time * mod;
  413. printf("gemm, Performance is %f Gflops\n", perf);
  414. };
  415. printf("warm up:\n");
  416. for (int i = 0; i < 50; i++) {
  417. benchmarker.set_dtype(0, dtype::Float32())
  418. .set_dtype(1, dtype::Float32())
  419. .set_display(false)
  420. .exec({{2, 1024}, {1024, 512}, {}});
  421. benchmarker.set_display(true);
  422. }
  423. run(256, 12 * 24, 256);
  424. //////////////////////// gemv //////////////////////////
  425. for (size_t M : {8, 64, 112, 256}) {
  426. for (size_t K : {8, 64, 112, 256}) {
  427. run(M, 1, K);
  428. }
  429. }
  430. //////////////////////// gemm //////////////////////////
  431. for (size_t M : {8, 64, 112, 256}) {
  432. for (size_t K : {8, 16, 32, 64, 112, 256}) {
  433. for (size_t N : {8, 64, 112, 256}) {
  434. run(M, N, K);
  435. }
  436. }
  437. }
  438. }
  439. TEST_F(ARM_COMMON, BENCHMARK_MATRIX_MUL_INT8x8x32) {
  440. constexpr size_t RUNS = 50;
  441. param::MatrixMul param;
  442. Benchmarker<MatrixMul> benchmarker_int(handle());
  443. benchmarker_int.set_times(RUNS)
  444. .set_dtype(0, dtype::Int8{})
  445. .set_dtype(1, dtype::Int8{})
  446. .set_dtype(2, dtype::Int32{})
  447. .set_param(param)
  448. .set_display(false);
  449. Benchmarker<MatrixMul> benchmarker_float(handle());
  450. benchmarker_float.set_display(false).set_times(RUNS);
  451. auto run = [&](size_t M, size_t N, size_t K) {
  452. auto int_used = benchmarker_int.exec({{M, K}, {K, N}, {}}) / RUNS;
  453. auto float_used = benchmarker_float.exec({{M, K}, {K, N}, {}}) / RUNS;
  454. float computations = 2.f * M * K * N * 1e-6;
  455. printf("run: {%zu{M} %zu{K} %zu{N}} float: %f ms %f Gflops int: %f ms "
  456. "%f Gflops speedup: %f\n",
  457. M, K, N, float_used, computations / float_used, int_used,
  458. computations / int_used, float_used / int_used);
  459. };
  460. run(256, 12 * 24, 256);
  461. //////////////////////// gemv //////////////////////////
  462. for (size_t M : {8, 64, 112, 256}) {
  463. for (size_t K : {8, 64, 112, 256}) {
  464. run(M, 1, K);
  465. }
  466. }
  467. //////////////////////// gemm //////////////////////////
  468. for (size_t M : {8, 64, 112, 256}) {
  469. for (size_t K : {8, 16, 32, 64, 112, 256}) {
  470. for (size_t N : {8, 64, 112, 256}) {
  471. run(M, N, K);
  472. }
  473. }
  474. }
  475. }
  476. TEST_F(ARM_COMMON, BENCHMARK_MATRIX_MUL_QUINT8) {
  477. constexpr size_t RUNS = 50;
  478. param::MatrixMul param;
  479. Benchmarker<MatrixMul> benchmarker_int(handle());
  480. benchmarker_int.set_times(RUNS)
  481. .set_dtype(0, dtype::Quantized8Asymm(1.2f, (uint8_t)127))
  482. .set_dtype(1, dtype::Quantized8Asymm(1.3f, (uint8_t)129))
  483. .set_dtype(2, {})
  484. .set_param(param)
  485. .set_display(false);
  486. Benchmarker<MatrixMul> benchmarker_float(handle());
  487. benchmarker_float.set_display(false).set_times(RUNS);
  488. auto run = [&](size_t M, size_t N, size_t K) {
  489. auto int_used = benchmarker_int.exec({{M, K}, {K, N}, {}}) / RUNS;
  490. auto float_used = benchmarker_float.exec({{M, K}, {K, N}, {}}) / RUNS;
  491. float computations = 2.f * M * K * N * 1e-6;
  492. printf("run: {%zu{M} %zu{K} %zu{N}} float: %f ms %f Gflops int: %f ms "
  493. "%f Gflops speedup: %f\n",
  494. M, K, N, float_used, computations / float_used, int_used,
  495. computations / int_used, float_used / int_used);
  496. };
  497. run(256, 12 * 24, 256);
  498. for (size_t M : {8, 64, 112, 256}) {
  499. for (size_t K : {8, 64, 112, 256}) {
  500. for (size_t N : {8, 64, 112, 256}) {
  501. run(M, N, K);
  502. }
  503. }
  504. }
  505. }
  506. TEST_F(ARM_COMMON, BENCHMARK_TRANSPOSED_MATRIX_MUL_QUINT8) {
  507. constexpr size_t RUNS = 50;
  508. param::MatrixMul param;
  509. param.transposeA = param.transposeB = true;
  510. Benchmarker<MatrixMul> benchmarker_int(handle());
  511. benchmarker_int.set_times(RUNS)
  512. .set_dtype(0, dtype::Quantized8Asymm(1.2f, (uint8_t)127))
  513. .set_dtype(1, dtype::Quantized8Asymm(1.3f, (uint8_t)129))
  514. .set_dtype(2, {})
  515. .set_param(param)
  516. .set_display(false);
  517. Benchmarker<MatrixMul> benchmarker_float(handle());
  518. benchmarker_float.set_param(param).set_display(false).set_times(RUNS);
  519. auto run = [&](size_t M, size_t N, size_t K) {
  520. auto int_used = benchmarker_int.exec({{K, M}, {N, K}, {}}) / RUNS;
  521. auto float_used = benchmarker_float.exec({{K, M}, {N, K}, {}}) / RUNS;
  522. float computations = 2.f * M * K * N * 1e-6;
  523. printf("run: {%zu{M} %zu{K} %zu{N}} float: %f ms %f Gflops int: %f ms "
  524. "%f Gflops speedup: %f\n",
  525. M, K, N, float_used, computations / float_used, int_used,
  526. computations / int_used, float_used / int_used);
  527. };
  528. run(256, 12 * 24, 256);
  529. for (size_t M : {8, 64, 112, 256}) {
  530. for (size_t K : {8, 64, 112, 256}) {
  531. for (size_t N : {8, 64, 112, 256}) {
  532. run(M, N, K);
  533. }
  534. }
  535. }
  536. }
  537. #endif
  538. // vim: syntax=cpp.doxygen