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.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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
  39. : TensorShape({0}), // mean
  40. need_statistic ? arg.param_shape
  41. : TensorShape({0}), // variance
  42. arg.param_shape, // batch_mean
  43. arg.param_shape, // batch_inv_variance
  44. {0}, // reserve
  45. arg.src // dst
  46. });
  47. }
  48. }
  49. TEST_F(ROCM, BN_BACKWARD) {
  50. using namespace batch_normalization;
  51. std::vector<TestArg> args = get_args();
  52. Checker<BNBackward> checker(handle_rocm());
  53. for (auto&& arg : args) {
  54. for (int i = 0; i < 9; ++i) {
  55. checker.set_dtype(i, dtype::Float32());
  56. }
  57. checker.set_dtype(0, arg.dtype) // x
  58. .set_dtype(1, arg.dtype) // dy
  59. .set_dtype(8, arg.dtype); // dx
  60. checker.set_epsilon(1e-3).set_param(arg.param).exec(
  61. {arg.src, arg.src, arg.param_shape, arg.param_shape,
  62. arg.param_shape, {0}, arg.param_shape, arg.param_shape,
  63. arg.src});
  64. }
  65. }
  66. } // namespace test
  67. } // namespace megdnn
  68. // vim: syntax=cpp.doxygen

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台