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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * \file dnn/test/cpu/relayout.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 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/common/checker.h"
  12. #include "test/common/benchmarker.h"
  13. #include "test/common/tensor.h"
  14. #include "test/common/relayout.h"
  15. #include "test/cpu/fixture.h"
  16. #include "megdnn/basic_types.h"
  17. using namespace megdnn;
  18. using namespace test;
  19. namespace {
  20. template<typename tag>
  21. class CPU_RELAYOUT: public CPU {
  22. };
  23. TYPED_TEST_CASE(CPU_RELAYOUT, relayout::test_types);
  24. TYPED_TEST(CPU_RELAYOUT, run) {
  25. relayout::run_test<TypeParam>(this->handle());
  26. }
  27. }
  28. #if MEGDNN_WITH_BENCHMARK
  29. TEST_F(CPU, BENCHMARK_RELAYOUT_CV) {
  30. relayout::run_cv_benchmark(handle());
  31. }
  32. TEST_F(CPU, BENCHMARK_RELAYOUT) {
  33. // Check if invoke fallback if it's not satisfied cv.
  34. using namespace relayout;
  35. std::vector<TestArg> args;
  36. args.emplace_back(TensorLayout({1, 8, 3, 64, 64},
  37. {64 * 64 * 3, 64 * 8, 64 * 64, 64, 1},
  38. dtype::Float32()),
  39. TensorLayout({1, 8, 3, 64, 64}, dtype::Float32()));
  40. auto handle_naive = create_cpu_handle(2);
  41. Benchmarker<Relayout> benchmarker(handle());
  42. Benchmarker<Relayout> benchmarker_naive(handle_naive.get());
  43. benchmarker_naive.set_times(1);
  44. benchmarker.set_times(1);
  45. for (auto &&arg : args) {
  46. float cpu_time = benchmarker.execl({arg.src, arg.dst});
  47. float naive_time = benchmarker_naive.execl({arg.src, arg.dst});
  48. ASSERT_LE(cpu_time * 5, naive_time);
  49. }
  50. }
  51. #endif
  52. // vim: syntax=cpp.doxygen

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