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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. }
  40. TEST_F(AARCH64, RelayoutNonContig) {
  41. Checker<Relayout> checker(handle());
  42. std::vector<::megdnn::DType> dtype_vec;
  43. dtype_vec.push_back(dtype::Float32());
  44. dtype_vec.push_back(dtype::Int16());
  45. dtype_vec.push_back(dtype::Uint16());
  46. dtype_vec.push_back(dtype::Int8());
  47. for (auto dtype : dtype_vec) {
  48. TensorLayout src({4, 90, 15, 29}, {41760, 1, 2784, 96}, dtype);
  49. TensorLayout dst({4, 90, 15, 29}, {39150, 435, 29, 1}, dtype);
  50. checker.execl({src, dst});
  51. }
  52. }
  53. TEST_F(AARCH64, RelayoutBig) {
  54. Checker<Relayout> checker(handle());
  55. ConsecutiveRNG rng;
  56. checker.set_rng(0, &rng);
  57. int m = 512;
  58. int n = 512;
  59. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype::Float32());
  60. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype::Float32());
  61. checker.execl({src, dst});
  62. }
  63. TEST_F(AARCH64, RelayoutSplict) {
  64. Checker<Relayout> checker(handle());
  65. ConsecutiveRNG rng;
  66. checker.set_rng(0, &rng);
  67. int m = 4;
  68. for (int n : {4, 28}) {
  69. TensorLayout src({(size_t)m, (size_t)n}, {1, m}, dtype::Uint16());
  70. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype::Uint16());
  71. checker.execl({src, dst});
  72. }
  73. }
  74. TEST_F(AARCH64, RelayoutRecord) {
  75. TaskRecordChecker<Relayout> checker(0);
  76. std::vector<::megdnn::DType> dtype_vec;
  77. dtype_vec.push_back(dtype::Float32());
  78. dtype_vec.push_back(dtype::Int16());
  79. dtype_vec.push_back(dtype::Uint16());
  80. dtype_vec.push_back(dtype::Int8());
  81. for (auto dtype : dtype_vec) {
  82. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  83. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  84. checker.execl({src, dst});
  85. }
  86. }
  87. #if MEGDNN_WITH_BENCHMARK
  88. TEST_F(AARCH64, BENCHMARK_Relayout) {
  89. constexpr size_t WARM_RUNS = 100;
  90. constexpr size_t RUNS = 600;
  91. auto dtype = dtype::Float32();
  92. Benchmarker<Relayout> benchmarker_relayout(handle());
  93. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  94. benchmarker_relayout.set_times(WARM_RUNS);
  95. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  96. int m = 512;
  97. int n = 512;
  98. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype);
  99. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype);
  100. TensorLayoutArray tensor_case;
  101. tensor_case.push_back(src);
  102. tensor_case.push_back(dst);
  103. benchmarker_relayout.exec(tensor_case);
  104. benchmarker_fbk_relayout.exec(tensor_case);
  105. benchmarker_relayout.set_times(RUNS);
  106. benchmarker_fbk_relayout.set_times(RUNS);
  107. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  108. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  109. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  110. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  111. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  112. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  113. }
  114. TEST_F(AARCH64, BENCHMARK_Relayout_2) {
  115. constexpr size_t WARM_RUNS = 100;
  116. constexpr size_t RUNS = 600;
  117. auto dtype = dtype::Float32();
  118. Benchmarker<Relayout> benchmarker_relayout(handle());
  119. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  120. benchmarker_relayout.set_times(WARM_RUNS);
  121. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  122. int m = 54;
  123. int n = 28762;
  124. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  125. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  126. TensorLayoutArray tensor_case;
  127. tensor_case.push_back(src);
  128. tensor_case.push_back(dst);
  129. benchmarker_relayout.exec(tensor_case);
  130. benchmarker_fbk_relayout.exec(tensor_case);
  131. benchmarker_relayout.set_times(RUNS);
  132. benchmarker_fbk_relayout.set_times(RUNS);
  133. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  134. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  135. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  136. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  137. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  138. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  139. }
  140. #endif
  141. } // namespace test
  142. } // namespace megdnn
  143. // vim: syntax=cpp.doxygen