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.

relayout.cpp 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "test/aarch64/fixture.h"
  2. #include "test/common/benchmarker.h"
  3. #include "test/common/checker.h"
  4. #include "test/common/relayout.h"
  5. #include "test/common/rng.h"
  6. #include "test/common/task_record_check.h"
  7. namespace megdnn {
  8. namespace test {
  9. namespace {
  10. template <typename tag>
  11. class AARCH64_RELAYOUT : public AARCH64 {};
  12. TYPED_TEST_CASE(AARCH64_RELAYOUT, relayout::test_types);
  13. TYPED_TEST(AARCH64_RELAYOUT, run) {
  14. relayout::run_test<TypeParam>(this->handle());
  15. }
  16. } // namespace
  17. TEST_F(AARCH64, Relayout) {
  18. Checker<Relayout> checker(handle());
  19. std::vector<::megdnn::DType> dtype_vec;
  20. dtype_vec.push_back(dtype::Float32());
  21. dtype_vec.push_back(dtype::Int16());
  22. dtype_vec.push_back(dtype::Uint16());
  23. dtype_vec.push_back(dtype::Int8());
  24. for (auto dtype : dtype_vec) {
  25. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  26. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  27. checker.execl({src, dst});
  28. }
  29. TensorLayout src_4_3({1, 3, 112, 256}, {3, 1, 1024, 4}, dtype::Uint16());
  30. TensorLayout dst_4_3({1, 3, 112, 256}, {86016, 28672, 256, 1}, dtype::Uint16());
  31. checker.execl({src_4_3, dst_4_3});
  32. }
  33. TEST_F(AARCH64, RelayoutNonContig) {
  34. Checker<Relayout> checker(handle());
  35. std::vector<::megdnn::DType> dtype_vec;
  36. dtype_vec.push_back(dtype::Float32());
  37. dtype_vec.push_back(dtype::Int16());
  38. dtype_vec.push_back(dtype::Uint16());
  39. dtype_vec.push_back(dtype::Int8());
  40. for (auto dtype : dtype_vec) {
  41. TensorLayout src({4, 90, 15, 29}, {41760, 1, 2784, 96}, dtype);
  42. TensorLayout dst({4, 90, 15, 29}, {39150, 435, 29, 1}, dtype);
  43. checker.execl({src, dst});
  44. }
  45. }
  46. TEST_F(AARCH64, RelayoutBig) {
  47. Checker<Relayout> checker(handle());
  48. ConsecutiveRNG rng;
  49. checker.set_rng(0, &rng);
  50. int m = 512;
  51. int n = 512;
  52. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype::Float32());
  53. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype::Float32());
  54. checker.execl({src, dst});
  55. }
  56. TEST_F(AARCH64, RelayoutSplict) {
  57. Checker<Relayout> checker(handle());
  58. ConsecutiveRNG rng;
  59. checker.set_rng(0, &rng);
  60. int m = 4;
  61. for (int n : {4, 28}) {
  62. TensorLayout src({(size_t)m, (size_t)n}, {1, m}, dtype::Uint16());
  63. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype::Uint16());
  64. checker.execl({src, dst});
  65. }
  66. }
  67. TEST_F(AARCH64, RelayoutRecord) {
  68. TaskRecordChecker<Relayout> checker(0);
  69. std::vector<::megdnn::DType> dtype_vec;
  70. dtype_vec.push_back(dtype::Float32());
  71. dtype_vec.push_back(dtype::Int16());
  72. dtype_vec.push_back(dtype::Uint16());
  73. dtype_vec.push_back(dtype::Int8());
  74. for (auto dtype : dtype_vec) {
  75. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  76. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  77. checker.execl({src, dst});
  78. }
  79. }
  80. #if MEGDNN_WITH_BENCHMARK
  81. TEST_F(AARCH64, BENCHMARK_Relayout) {
  82. constexpr size_t WARM_RUNS = 100;
  83. constexpr size_t RUNS = 600;
  84. auto dtype = dtype::Float32();
  85. Benchmarker<Relayout> benchmarker_relayout(handle());
  86. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  87. benchmarker_relayout.set_times(WARM_RUNS);
  88. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  89. int m = 512;
  90. int n = 512;
  91. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype);
  92. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype);
  93. TensorLayoutArray tensor_case;
  94. tensor_case.push_back(src);
  95. tensor_case.push_back(dst);
  96. benchmarker_relayout.exec(tensor_case);
  97. benchmarker_fbk_relayout.exec(tensor_case);
  98. benchmarker_relayout.set_times(RUNS);
  99. benchmarker_fbk_relayout.set_times(RUNS);
  100. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  101. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  102. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  103. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  104. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  105. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  106. }
  107. TEST_F(AARCH64, BENCHMARK_Relayout_2) {
  108. constexpr size_t WARM_RUNS = 100;
  109. constexpr size_t RUNS = 600;
  110. auto dtype = dtype::Float32();
  111. Benchmarker<Relayout> benchmarker_relayout(handle());
  112. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  113. benchmarker_relayout.set_times(WARM_RUNS);
  114. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  115. int m = 54;
  116. int n = 28762;
  117. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  118. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  119. TensorLayoutArray tensor_case;
  120. tensor_case.push_back(src);
  121. tensor_case.push_back(dst);
  122. benchmarker_relayout.exec(tensor_case);
  123. benchmarker_fbk_relayout.exec(tensor_case);
  124. benchmarker_relayout.set_times(RUNS);
  125. benchmarker_fbk_relayout.set_times(RUNS);
  126. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  127. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  128. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  129. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  130. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  131. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  132. }
  133. #endif
  134. } // namespace test
  135. } // namespace megdnn
  136. // vim: syntax=cpp.doxygen