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.

reduce.cpp 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "hcc_detail/hcc_defs_prologue.h"
  2. #include "megdnn/oprs.h"
  3. #include "test/common/checker.h"
  4. #include "test/common/rng.h"
  5. #include "test/rocm/fixture.h"
  6. using namespace megdnn;
  7. using namespace test;
  8. TEST_F(ROCM, REDUCE) {
  9. using Mode = Reduce::Param::Mode;
  10. Checker<Reduce> checker(handle_rocm());
  11. UniformFloatRNG rng(-1.0f, 1.0f);
  12. checker.set_epsilon(1e-2);
  13. checker.set_rng(0, &rng);
  14. checker.set_param({Mode::SUM, 1});
  15. // 1-step
  16. checker.execs({{2, 64, 32}, {}});
  17. // 2-step
  18. checker.execs({{2, 192, 32}, {}});
  19. // 3-step
  20. checker.execs({{2, 4333, 32}, {}});
  21. // single reduce
  22. checker.execs({{2, 1, 1}, {}});
  23. checker.execs({{2, 1 + 1, 1}, {}});
  24. checker.execs({{2, 2048 + 1, 1}, {}});
  25. checker.execs({{2, 2048 * 2048 + 1, 1}, {}});
  26. checker.execs({{2, 1 + 1, 31}, {}});
  27. checker.execs({{2, 16 + 1, 31}, {}});
  28. checker.execs({{2, 16 * 16 + 1, 31}, {}});
  29. checker.execs({{2, 16 * 16 * 16 + 1, 31}, {}});
  30. checker.execs({{2, 16 * 16 * 16 * 16 + 1, 31}, {}});
  31. checker.execs({{2, 16 * 16 * 16 * 16 * 16 + 1, 31}, {}});
  32. checker.execs({{3, 256 * 256 + 1, 2}, {}});
  33. checker.execs({{3, 128 * 128 + 1, 3}, {}});
  34. checker.execs({{3, 64 * 64 + 1, 7}, {}});
  35. checker.execs({{3, 32 * 32 + 1, 15}, {}});
  36. checker.execs({{3, 512, 500}, {}});
  37. // very large reduce
  38. checker.execs({{1, 4194304, 1}, {}});
  39. auto check = [&](Reduce::Mode mode, DType src_dtype, DType dst_dtype,
  40. Reduce::DataType data_type) {
  41. for (int32_t axis : {0, 1, 2, 3}) {
  42. if (data_type == Reduce::DataType::DEFAULT &&
  43. DNN_FLOAT16_SELECT(src_dtype == dtype::Float16(), false)) {
  44. checker.set_epsilon(1e-2);
  45. } else {
  46. checker.set_epsilon(1e-3);
  47. }
  48. Reduce::Param param{mode, axis, data_type};
  49. auto dst_shape = TensorShape{2, 3, 100, 5};
  50. dst_shape[axis] = 1;
  51. checker.set_dtype(0, src_dtype)
  52. .set_dtype(1, dst_dtype)
  53. .set_param(param)
  54. .execs({{2, 3, 100, 5}, dst_shape});
  55. }
  56. };
  57. for (auto mode :
  58. {Mode::SUM, Mode::MEAN, Mode::SUM_SQR, Mode::PRODUCT, Mode::MIN, Mode::MAX}) {
  59. for (auto dtype : std::vector<DType>{
  60. DNN_INC_FLOAT16(dtype::Float16() MEGDNN_COMMA) dtype::Float32(),
  61. dtype::Int32()}) {
  62. check(mode, dtype, dtype, Reduce::DataType::DEFAULT);
  63. }
  64. #if !MEGDNN_DISABLE_FLOAT16
  65. check(mode, dtype::Float16(), dtype::Float32(),
  66. Reduce::DataType::FLOAT_O32xC32);
  67. check(mode, dtype::Float16(), dtype::Float16(),
  68. Reduce::DataType::FLOAT_O16xC32);
  69. check(mode, dtype::Float32(), dtype::Float16(),
  70. Reduce::DataType::FLOAT_O16xC32);
  71. ASSERT_THROW(
  72. check(mode, dtype::Int32(), dtype::Float16(),
  73. Reduce::DataType::FLOAT_O16xC32),
  74. MegDNNError);
  75. ASSERT_THROW(
  76. check(mode, dtype::Float16(), dtype::Float16(),
  77. Reduce::DataType::FLOAT_IO16xC32),
  78. MegDNNError);
  79. #endif
  80. }
  81. #if !MEGDNN_DISABLE_FLOAT16
  82. {
  83. // very large reduce for I16CO32
  84. Reduce::Param param{Mode::SUM_SQR, 1, Reduce::Param::DataType::FLOAT_O32xC32};
  85. checker.set_dtype(0, dtype::Float16())
  86. .set_dtype(1, dtype::Float32())
  87. .set_param(param)
  88. .execs({{1, 4194304, 1}, {1, 1, 1}});
  89. }
  90. {
  91. // large reduce_mean for O16C32
  92. Reduce::Param param{Mode::MEAN, 1, Reduce::Param::DataType::FLOAT_O16xC32};
  93. checker.set_dtype(0, dtype::Float16())
  94. .set_dtype(1, dtype::Float16())
  95. .set_param(param)
  96. .execs({{1, 65536, 5}, {1, 1, 5}});
  97. }
  98. #endif
  99. }
  100. // vim: syntax=cpp.doxygen