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.

powc.cpp 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "test/common/powc.h"
  2. #include "test/common/task_record_check.h"
  3. #include "test/fallback/fixture.h"
  4. using namespace megdnn;
  5. using namespace test;
  6. TEST_F(FALLBACK, POW_C_F32) {
  7. run_powc_test(handle(), dtype::Float32{});
  8. }
  9. TEST_F(FALLBACK, POW_C_F32_RECORD) {
  10. TaskRecordChecker<PowC> checker(1);
  11. auto dtype = dtype::Float32{};
  12. checker.set_dtype(0, dtype);
  13. float dt_val_max;
  14. if (dtype == dtype::Float32{}) {
  15. dt_val_max = DTypeTrait<dt_float32>::max();
  16. } else {
  17. megdnn_assert(dtype == dtype::Float16{});
  18. dt_val_max = DTypeTrait<dt_float16>::max();
  19. checker.set_epsilon(1e-2);
  20. }
  21. dt_val_max /= 4;
  22. for (float exp :
  23. {0.f, 1.f / 3.f, 1.f / 3.f + 0.01f, .5f, 1.f, 1.2f, 2.f, 3.f, 4.f, 7.f, 8.f}) {
  24. float rng_max =
  25. exp ? std::pow(dt_val_max, std::min(1.f / exp, 1.f)) : dt_val_max;
  26. bool allow_neg;
  27. {
  28. auto d = exp - std::floor(exp);
  29. if (d >= .1f) {
  30. allow_neg = false;
  31. } else {
  32. allow_neg = true;
  33. }
  34. }
  35. UniformFloatRNG rng0{-rng_max, rng_max}, rng1{0.f, rng_max};
  36. checker.set_rng(0, allow_neg ? &rng0 : &rng1);
  37. checker.set_param(exp);
  38. checker.execs({TensorShape{23, 34}, {}});
  39. if (::testing::Test::HasFailure()) {
  40. printf("failed for %g\n", exp);
  41. return;
  42. }
  43. UniformFloatNonZeroRNG rng2{1.f / rng_max, dt_val_max};
  44. UniformFloatRNG rng3{1.f / rng_max, dt_val_max};
  45. if (allow_neg) {
  46. checker.set_rng(0, &rng2);
  47. } else {
  48. checker.set_rng(0, &rng3);
  49. }
  50. checker.set_param(-exp);
  51. checker.execs({TensorShape{3, 7, 2}, {}});
  52. if (::testing::Test::HasFailure()) {
  53. printf("failed for %g\n", -exp);
  54. return;
  55. }
  56. // non contig
  57. TensorLayout layout{{4, 9}, dtype};
  58. layout.stride[0] *= 3;
  59. layout.stride[1] *= 2;
  60. checker.execl({layout, {}});
  61. if (::testing::Test::HasFailure()) {
  62. printf("failed for %g noncontig\n", -exp);
  63. return;
  64. }
  65. }
  66. }
  67. #if !MEGDNN_DISABLE_FLOAT16
  68. TEST_F(FALLBACK, POW_C_F16) {
  69. run_powc_test(handle(), dtype::Float16{});
  70. }
  71. #endif
  72. // vim: syntax=cpp.doxygen