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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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-2020 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_epsilon(1e-3).set_param(arg.param);
  32. for (bool need_statistic : {false, true})
  33. checker.exec({
  34. arg.src,
  35. arg.param_shape, // bn_scale
  36. arg.param_shape, // bn_bias
  37. need_statistic ? arg.param_shape
  38. : TensorShape({0}), // mean
  39. need_statistic ? arg.param_shape
  40. : TensorShape({0}), // variance
  41. arg.param_shape, // batch_mean
  42. arg.param_shape, // batch_inv_variance
  43. {} // 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 < 8; ++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(7, arg.dtype); // dx
  58. checker.set_epsilon(1e-3).set_param(arg.param).exec(
  59. {arg.src, arg.src, arg.param_shape, arg.param_shape,
  60. arg.param_shape, arg.param_shape, arg.param_shape, arg.src});
  61. }
  62. }
  63. } // namespace test
  64. } // namespace megdnn
  65. // vim: syntax=cpp.doxygen

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