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.

bn.cpp 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * \file dnn/test/rocm/bn.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
  10. * implied.
  11. */
  12. #include "test/rocm/fixture.h"
  13. #include "megdnn/opr_param_defs.h"
  14. #include "megdnn/oprs.h"
  15. #include "test/common/bn.h"
  16. #include "test/common/checker.h"
  17. #include "test/common/rng.h"
  18. #include "test/common/tensor.h"
  19. #include "test/common/workspace_wrapper.h"
  20. namespace megdnn {
  21. namespace test {
  22. TEST_F(ROCM, BN_FORWARD) {
  23. using namespace batch_normalization;
  24. std::vector<TestArg> args = get_args();
  25. Checker<BNForward> checker(handle_rocm());
  26. for (auto&& arg : args) {
  27. for (int i = 0; i < 8; ++i) {
  28. checker.set_dtype(i, dtype::Float32());
  29. }
  30. checker.set_dtype(0, arg.dtype);
  31. checker.set_dtype(8, arg.dtype);
  32. checker.set_epsilon(1e-3).set_param(arg.param);
  33. for (bool need_statistic : {false, true})
  34. checker.exec({
  35. arg.src,
  36. arg.param_shape, // bn_scale
  37. arg.param_shape, // bn_bias
  38. need_statistic ? arg.param_shape : TensorShape({0}), // mean
  39. need_statistic ? arg.param_shape : TensorShape({0}), // variance
  40. arg.param_shape, // batch_mean
  41. arg.param_shape, // batch_inv_variance
  42. {0}, // reserve
  43. arg.src // dst
  44. });
  45. }
  46. }
  47. TEST_F(ROCM, BN_BACKWARD) {
  48. using namespace batch_normalization;
  49. std::vector<TestArg> args = get_args();
  50. Checker<BNBackward> checker(handle_rocm());
  51. for (auto&& arg : args) {
  52. for (int i = 0; i < 9; ++i) {
  53. checker.set_dtype(i, dtype::Float32());
  54. }
  55. checker.set_dtype(0, arg.dtype) // x
  56. .set_dtype(1, arg.dtype) // dy
  57. .set_dtype(8, arg.dtype); // dx
  58. checker.set_epsilon(1e-3).set_param(arg.param).exec(
  59. {arg.src,
  60. arg.src,
  61. arg.param_shape,
  62. arg.param_shape,
  63. arg.param_shape,
  64. {0},
  65. arg.param_shape,
  66. arg.param_shape,
  67. arg.src});
  68. }
  69. }
  70. } // namespace test
  71. } // namespace megdnn
  72. // vim: syntax=cpp.doxygen