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.

flip.cpp 2.7 kB

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