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.

roi_pooling.cpp 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * \file dnn/test/cuda/roi_pooling.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 implied.
  10. */
  11. #include "test/cuda/fixture.h"
  12. #include "test/common/checker.h"
  13. #include "test/common/roi_pooling.h"
  14. namespace megdnn {
  15. namespace test {
  16. TEST_F(CUDA, ROI_POOLING_FORWARD)
  17. {
  18. size_t N = 10, C = 3, IH = 102, IW = 108, spatial_scale = 100;
  19. size_t OH = 12, OW = 13, M = 7;
  20. ROIPoolingRNG rng(N);
  21. using Param = ROIPooling::Param;
  22. Param param;
  23. param.scale = spatial_scale;
  24. Checker<ROIPoolingForward> checker(handle_cuda());
  25. auto run = [&](DType dtype) {
  26. for (auto mode: {Param::Mode::MAX, Param::Mode::AVERAGE}) {
  27. param.mode = mode;
  28. checker.set_param(param).
  29. set_rng(1, &rng).
  30. set_dtype(0, dtype).
  31. set_dtype(1, dtype).
  32. set_dtype(2, dtype).
  33. set_dtype(3, dtype::Int32()).
  34. execs({{N, C, IH, IW}, {M, 5}, {M, C, OH, OW}, {M, C, OH, OW}});
  35. }
  36. };
  37. run(dtype::Float32());
  38. run(dtype::Float16());
  39. }
  40. TEST_F(CUDA, ROI_POOLING_BACKWARD)
  41. {
  42. size_t N = 10, C = 3, IH = 102, IW = 108, spatial_scale = 100;
  43. size_t OH = 12, OW = 13, M = 7;
  44. ROIPoolingRNG rng(N);
  45. UniformIntRNG index_rng(0, OH*OW-1);
  46. using Param = ROIPooling::Param;
  47. Param param;
  48. param.scale = spatial_scale;
  49. Checker<ROIPoolingBackward> checker(handle_cuda());
  50. checker.set_epsilon(1e-2);
  51. auto run = [&](DType dtype) {
  52. for (auto mode: {Param::Mode::MAX, Param::Mode::AVERAGE}) {
  53. param.mode = mode;
  54. checker.set_param(param).
  55. set_dtype(0, dtype).
  56. set_dtype(1, dtype).
  57. set_dtype(2, dtype).
  58. set_dtype(4, dtype).
  59. set_dtype(3, dtype::Int32()).
  60. set_rng(2, &rng).
  61. set_rng(3, &index_rng).
  62. execs({{M, C, OH, OW},
  63. {N, C, IH, IW},
  64. {M, 5},
  65. {M, C, OH, OW},
  66. {N, C, IH, IW}});
  67. }
  68. };
  69. run(dtype::Float32());
  70. run(dtype::Float16());
  71. }
  72. } // namespace test
  73. } // namespace megdnn
  74. // vim: syntax=cpp.doxygen

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