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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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}, dtype::Int32());
  31. args.emplace_back(cur_param, TensorShape{65540, 3, 4, 3}, dtype::Int32());
  32. }
  33. for (auto&& arg : args) {
  34. checker.set_dtype(0, arg.dtype).set_dtype(1, arg.dtype).execs({arg.src, {}});
  35. }
  36. }
  37. #if MEGDNN_WITH_BENCHMARK
  38. TEST_F(CUDA, BENCHMARK_ROTATE) {
  39. auto run = [&](const TensorShapeArray& shapes) {
  40. Benchmarker<Rotate> benchmarker(handle_cuda());
  41. Benchmarker<Rotate> benchmarker_cpu(handle_naive());
  42. benchmarker.set_dtype(0, dtype::Int32());
  43. benchmarker.set_dtype(1, dtype::Int32());
  44. benchmarker_cpu.set_dtype(0, dtype::Int32());
  45. benchmarker_cpu.set_dtype(1, dtype::Int32());
  46. benchmarker.set_times(5);
  47. benchmarker_cpu.set_times(5);
  48. Rotate::Param param;
  49. #define BENCHMARK_rotate(is_clockwise) \
  50. param.clockwise = is_clockwise; \
  51. benchmarker.set_param(param); \
  52. benchmarker_cpu.set_param(param); \
  53. printf("src:%s clockwise==%d cuda vs naive\n", shape.to_string().c_str(), \
  54. is_clockwise); \
  55. benchmarker.execs({shape, {}}); \
  56. benchmarker_cpu.execs({shape, {}});
  57. for (auto&& shape : shapes) {
  58. BENCHMARK_rotate(false);
  59. BENCHMARK_rotate(true);
  60. }
  61. #undef BENCHMARK_rotate
  62. };
  63. TensorShapeArray shapes = {{3, 1001, 978, 1}, {3, 1001, 978, 3}};
  64. run(shapes);
  65. }
  66. #endif
  67. } // namespace rotate
  68. } // namespace test
  69. } // namespace megdnn
  70. // vim: syntax=cpp.doxygen