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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. namespace megdnn {
  17. namespace test {
  18. namespace {
  19. template <typename tag>
  20. class AARCH64_RELAYOUT : public AARCH64 {};
  21. TYPED_TEST_CASE(AARCH64_RELAYOUT, relayout::test_types);
  22. TYPED_TEST(AARCH64_RELAYOUT, run) {
  23. relayout::run_test<TypeParam>(this->handle());
  24. }
  25. } // namespace
  26. TEST_F(AARCH64, Relayout) {
  27. Checker<Relayout> checker(handle());
  28. std::vector<::megdnn::DType> dtype_vec;
  29. dtype_vec.push_back(dtype::Float32());
  30. dtype_vec.push_back(dtype::Int16());
  31. dtype_vec.push_back(dtype::Uint16());
  32. dtype_vec.push_back(dtype::Int8());
  33. for (auto dtype : dtype_vec) {
  34. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  35. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  36. checker.execl({src, dst});
  37. }
  38. }
  39. TEST_F(AARCH64, RelayoutBig) {
  40. Checker<Relayout> checker(handle());
  41. ConsecutiveRNG rng;
  42. checker.set_rng(0, &rng);
  43. int m = 512;
  44. int n = 512;
  45. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype::Float32());
  46. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype::Float32());
  47. checker.execl({src, dst});
  48. }
  49. #if MEGDNN_WITH_BENCHMARK
  50. TEST_F(AARCH64, BENCHMARK_Relayout) {
  51. constexpr size_t WARM_RUNS = 100;
  52. constexpr size_t RUNS = 600;
  53. auto dtype = dtype::Float32();
  54. Benchmarker<Relayout> benchmarker_relayout(handle());
  55. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  56. benchmarker_relayout.set_times(WARM_RUNS);
  57. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  58. int m = 512;
  59. int n = 512;
  60. TensorLayout src({(size_t)m, (size_t)n}, {1, n}, dtype);
  61. TensorLayout dst({(size_t)m, (size_t)n}, {n, 1}, dtype);
  62. TensorLayoutArray tensor_case;
  63. tensor_case.push_back(src);
  64. tensor_case.push_back(dst);
  65. benchmarker_relayout.exec(tensor_case);
  66. benchmarker_fbk_relayout.exec(tensor_case);
  67. benchmarker_relayout.set_times(RUNS);
  68. benchmarker_fbk_relayout.set_times(RUNS);
  69. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  70. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  71. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  72. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  73. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  74. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  75. }
  76. TEST_F(AARCH64, BENCHMARK_Relayout_2) {
  77. constexpr size_t WARM_RUNS = 100;
  78. constexpr size_t RUNS = 600;
  79. auto dtype = dtype::Float32();
  80. Benchmarker<Relayout> benchmarker_relayout(handle());
  81. Benchmarker<Relayout> benchmarker_fbk_relayout(fallback_handle());
  82. benchmarker_relayout.set_times(WARM_RUNS);
  83. benchmarker_fbk_relayout.set_times(WARM_RUNS);
  84. int m = 54;
  85. int n = 28762;
  86. TensorLayout src({1, 54, 112, 256}, {54, 1, 16384, 64}, dtype);
  87. TensorLayout dst({1, 54, 112, 256}, {1548288, 28672, 256, 1}, dtype);
  88. TensorLayoutArray tensor_case;
  89. tensor_case.push_back(src);
  90. tensor_case.push_back(dst);
  91. benchmarker_relayout.exec(tensor_case);
  92. benchmarker_fbk_relayout.exec(tensor_case);
  93. benchmarker_relayout.set_times(RUNS);
  94. benchmarker_fbk_relayout.set_times(RUNS);
  95. auto used = benchmarker_relayout.exec(tensor_case) / RUNS;
  96. auto fbk_used = benchmarker_fbk_relayout.exec(tensor_case) / RUNS;
  97. float bw = 2.f * m * n * 1e-6 / used * dtype.size();
  98. float fbk_bw = 2.f * m * n * 1e-6 / fbk_used * dtype.size();
  99. printf("run: %s -> %s , %f GB/s, fbk %f GB/s, speedup %f\n",
  100. src.to_string().c_str(), dst.to_string().c_str(), bw, fbk_bw, bw / fbk_bw);
  101. }
  102. #endif
  103. } // namespace test
  104. } // namespace megdnn
  105. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台