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

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