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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. TEST_F(CPU, BENCHMARK_RELAYOUT_CV) {
  29. relayout::run_cv_benchmark(handle());
  30. }
  31. TEST_F(CPU, BENCHMARK_RELAYOUT) {
  32. // Check if invoke fallback if it's not satisfied cv.
  33. using namespace relayout;
  34. std::vector<TestArg> args;
  35. args.emplace_back(TensorLayout({1, 8, 3, 64, 64},
  36. {64 * 64 * 3, 64 * 8, 64 * 64, 64, 1},
  37. dtype::Float32()),
  38. TensorLayout({1, 8, 3, 64, 64}, dtype::Float32()));
  39. auto handle_naive = create_cpu_handle(2);
  40. Benchmarker<Relayout> benchmarker(handle());
  41. Benchmarker<Relayout> benchmarker_naive(handle_naive.get());
  42. benchmarker_naive.set_times(1);
  43. benchmarker.set_times(1);
  44. for (auto &&arg : args) {
  45. float cpu_time = benchmarker.execl({arg.src, arg.dst});
  46. float naive_time = benchmarker_naive.execl({arg.src, arg.dst});
  47. ASSERT_LE(cpu_time * 5, naive_time);
  48. }
  49. }
  50. // vim: syntax=cpp.doxygen

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