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

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