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.

sliding_window_transpose.cpp 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * \file dnn/test/cuda/sliding_window_transpose.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/sliding_window_transpose.h"
  14. #include "test/common/rng.h"
  15. #include "test/cuda/benchmark.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(CUDA, SLIDINGWINDOWTRANSPOSE_FORWARD)
  19. {
  20. UniformFloatRNG rng(0, 1);
  21. auto args = sliding_window_transpose::get_args();
  22. for (auto &&arg: args) {
  23. Checker<SlidingWindowTransposeForward> checker(handle_cuda());
  24. checker.set_rng(0, &rng);
  25. checker.set_epsilon(1e-2);
  26. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  27. TensorLayout olayout;
  28. {
  29. auto opr = handle_cuda()->create_operator<SlidingWindowTransposeForward>();
  30. opr->param() = arg.param;
  31. opr->deduce_layout(ilayout, olayout);
  32. }
  33. auto set_dtype = [&checker](DType dtype)
  34. {
  35. checker.set_dtype(0, dtype).
  36. set_dtype(1, dtype);
  37. };
  38. set_dtype(dtype::Float32());
  39. checker.set_param(arg.param).exec(TensorShapeArray{
  40. ilayout, olayout});
  41. set_dtype(dtype::Float16());
  42. checker.set_param(arg.param).exec(TensorShapeArray{
  43. ilayout, olayout});
  44. }
  45. }
  46. #if MEGDNN_WITH_BENCHMARK
  47. TEST_F(CUDA, BENCHMARK_SLIDINGWINDOWTRANSPOSE_FORWARD)
  48. {
  49. auto args = sliding_window_transpose::get_benchmark_args();
  50. for (auto &&arg: args) {
  51. CUBenchmarker<SlidingWindowTransposeForward> bencher(handle_cuda());
  52. bencher.set_param(arg.param).set_dtype(0, dtype::Float32()).
  53. exec(TensorShapeArray{
  54. arg.ishape, {}});
  55. }
  56. }
  57. #endif
  58. TEST_F(CUDA, SLIDINGWINDOWTRANSPOSE_BACKWARD)
  59. {
  60. UniformFloatRNG rng(0, 1);
  61. auto args = sliding_window_transpose::get_args();
  62. for (auto &&arg: args) {
  63. Checker<SlidingWindowTransposeBackward> checker(handle_cuda());
  64. // checker.set_epsilon(1e-2);
  65. checker.set_rng(0, &rng);
  66. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  67. TensorLayout olayout;
  68. {
  69. auto opr = handle_cuda()->create_operator<SlidingWindowTranspose>();
  70. opr->param() = arg.param;
  71. opr->deduce_layout(ilayout, olayout);
  72. }
  73. auto set_dtype = [&checker](DType dtype)
  74. {
  75. checker.set_dtype(0, dtype).
  76. set_dtype(1, dtype);
  77. };
  78. set_dtype(dtype::Float32());
  79. checker.set_param(arg.param).exec(TensorShapeArray{
  80. olayout, ilayout});
  81. set_dtype(dtype::Float16());
  82. checker.set_param(arg.param).exec(TensorShapeArray{
  83. olayout, ilayout});
  84. }
  85. }
  86. } // namespace test
  87. } // namespace megdnn
  88. // vim: syntax=cpp.doxygen

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