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.9 kB

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