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.

rotate.cpp 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * \file dnn/test/cuda/rotate.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 <gtest/gtest.h>
  12. #include "megdnn.h"
  13. #include "megdnn/oprs.h"
  14. #include "test/common/benchmarker.h"
  15. #include "test/common/checker.h"
  16. #include "test/common/rotate.h"
  17. #include "test/common/tensor.h"
  18. #include "test/cuda/fixture.h"
  19. namespace megdnn {
  20. namespace test {
  21. namespace rotate {
  22. TEST_F(CUDA, ROTATE) {
  23. using namespace rotate;
  24. std::vector<TestArg> args = get_args();
  25. Checker<Rotate> checker(handle_cuda());
  26. //! test for batch size exceed CUDNN_MAX_BATCH_X_CHANNEL_SIZE
  27. Rotate::Param cur_param;
  28. for (bool clockwise : {false, true}) {
  29. cur_param.clockwise = clockwise;
  30. args.emplace_back(cur_param, TensorShape{65535, 3, 4, 1},
  31. dtype::Int32());
  32. args.emplace_back(cur_param, TensorShape{65540, 3, 4, 3},
  33. dtype::Int32());
  34. }
  35. for (auto&& arg : args) {
  36. checker.set_dtype(0, arg.dtype)
  37. .set_dtype(1, arg.dtype)
  38. .execs({arg.src, {}});
  39. }
  40. }
  41. TEST_F(CUDA, BENCHMARK_ROTATE) {
  42. auto run = [&](const TensorShapeArray& shapes) {
  43. Benchmarker<Rotate> benchmarker(handle_cuda());
  44. Benchmarker<Rotate> benchmarker_cpu(handle_naive());
  45. benchmarker.set_dtype(0, dtype::Int32());
  46. benchmarker.set_dtype(1, dtype::Int32());
  47. benchmarker_cpu.set_dtype(0, dtype::Int32());
  48. benchmarker_cpu.set_dtype(1, dtype::Int32());
  49. benchmarker.set_times(5);
  50. benchmarker_cpu.set_times(5);
  51. Rotate::Param param;
  52. #define BENCHMARK_rotate(is_clockwise) \
  53. param.clockwise = is_clockwise; \
  54. benchmarker.set_param(param); \
  55. benchmarker_cpu.set_param(param); \
  56. printf("src:%s clockwise==%d cuda vs naive\n", shape.to_string().c_str(), \
  57. is_clockwise); \
  58. benchmarker.execs({shape, {}}); \
  59. benchmarker_cpu.execs({shape, {}});
  60. for (auto&& shape : shapes) {
  61. BENCHMARK_rotate(false);
  62. BENCHMARK_rotate(true);
  63. }
  64. #undef BENCHMARK_rotate
  65. };
  66. TensorShapeArray shapes = {{3, 1001, 978, 1}, {3, 1001, 978, 3}};
  67. run(shapes);
  68. }
  69. } // namespace rotate
  70. } // namespace test
  71. } // namespace megdnn
  72. // vim: syntax=cpp.doxygen

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