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.

warp_affine.cpp 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "test/common/warp_affine.h"
  2. #include "include/megdnn/thin/small_vector.h"
  3. #include "test/common/benchmarker.h"
  4. #include "test/common/checker.h"
  5. #include "test/cuda/fixture.h"
  6. namespace megdnn {
  7. namespace test {
  8. // FIXME test WARP_PERSPECTIVE_CV failed here
  9. #if 0
  10. TEST_F(CUDA, WARP_AFFINE_CV)
  11. {
  12. using namespace warp_affine;
  13. std::vector<TestArg> args = get_cv_args();
  14. Checker<WarpAffine> checker(handle_cuda());
  15. for (auto &&arg: args) {
  16. if (arg.src[3] == 2) continue;
  17. checker.set_param(arg.param)
  18. .set_epsilon(1 + 1e-3)
  19. .set_dtype(0, dtype::Uint8())
  20. .set_dtype(1, dtype::Float32())
  21. .set_dtype(2, dtype::Uint8())
  22. .execs({arg.src, arg.trans, arg.dst});
  23. }
  24. for (auto &&arg: args) {
  25. if (arg.src[3] == 2) continue;
  26. checker.set_param(arg.param)
  27. .set_dtype(0, dtype::Float32())
  28. .set_dtype(1, dtype::Float32())
  29. .set_dtype(2, dtype::Float32())
  30. .execs({arg.src, arg.trans, arg.dst});
  31. }
  32. }
  33. #endif
  34. TEST_F(CUDA, WARP_AFFINE) {
  35. //! NCHW
  36. for (auto dtype : std::vector<DType>{dtype::Float32()}) {
  37. for (auto bmode :
  38. {WarpAffine::BorderMode::WRAP, WarpAffine::BorderMode::REFLECT,
  39. WarpAffine::BorderMode::CONSTANT, WarpAffine::BorderMode::REPLICATE,
  40. WarpAffine::BorderMode::CONSTANT}) {
  41. Checker<WarpAffine> checker(handle_cuda());
  42. NormalRNG rng;
  43. checker.set_rng(1, &rng);
  44. WarpAffine::Param param;
  45. param.border_val = 0.3f;
  46. param.border_mode = bmode;
  47. param.imode = param::WarpAffine::InterpolationMode::LINEAR;
  48. param.format = param::WarpAffine::Format::NCHW;
  49. checker.set_param(param);
  50. checker.set_dtype(0, dtype);
  51. checker.set_dtype(1, dtype);
  52. checker.set_dtype(2, dtype);
  53. checker.execs({{2, 3, 10, 11}, {2, 2, 3}, {2, 3, 11, 12}});
  54. checker.execs({{22, 3, 10, 11}, {22, 2, 3}, {22, 3, 11, 12}});
  55. }
  56. }
  57. //! NHWC
  58. for (auto dtype : std::vector<DType>{dtype::Float32()}) {
  59. for (auto bmode :
  60. {WarpAffine::BorderMode::WRAP, WarpAffine::BorderMode::REFLECT,
  61. WarpAffine::BorderMode::CONSTANT, WarpAffine::BorderMode::REPLICATE,
  62. WarpAffine::BorderMode::CONSTANT}) {
  63. Checker<WarpAffine> checker(handle_cuda());
  64. NormalRNG rng;
  65. checker.set_rng(1, &rng);
  66. WarpAffine::Param param;
  67. param.format = param::WarpAffine::Format::NHWC;
  68. param.border_val = 0.3f;
  69. param.border_mode = bmode;
  70. param.imode = param::WarpAffine::InterpolationMode::LINEAR;
  71. checker.set_param(param);
  72. checker.set_dtype(0, dtype);
  73. checker.set_dtype(1, dtype);
  74. checker.set_dtype(2, dtype);
  75. checker.execs({{2, 3, 10, 11}, {2, 2, 3}, {2, 12, 11, 11}});
  76. checker.execs({{22, 3, 10, 12}, {22, 2, 3}, {22, 3, 11, 12}});
  77. }
  78. }
  79. }
  80. #if MEGDNN_WITH_BENCHMARK
  81. TEST_F(CUDA, WARP_AFFINE_BENCHMARK) {
  82. const size_t RUNS = 50;
  83. Benchmarker<WarpAffine> benchmark(handle_cuda());
  84. benchmark.set_display(false);
  85. benchmark.set_times(RUNS);
  86. using Param = param::WarpAffine;
  87. Param param;
  88. auto run = [&benchmark, &param](TensorShape src, TensorShape mat, TensorShape dst) {
  89. benchmark.set_param(param);
  90. auto used = benchmark.execs({src, mat, dst});
  91. printf("src: %s dst: %s used: %.2f ms %.2f Gflops\n", src.to_string().c_str(),
  92. dst.to_string().c_str(), used,
  93. //! 8 mul + 3 add
  94. 11 * dst.total_nr_elems() / (used / RUNS) / 1e6);
  95. };
  96. run({1, 100, 100, 1}, {1, 2, 3}, {1, 112, 112, 1});
  97. run({512, 100, 100, 1}, {512, 2, 3}, {512, 112, 112, 1});
  98. }
  99. #endif
  100. } // namespace test
  101. } // namespace megdnn
  102. // vim: syntax=cpp.doxygen