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.

images2neibs.cpp 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * \file dnn/test/cuda/images2neibs.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 implied.
  10. */
  11. #include "test/cuda/fixture.h"
  12. #include "test/common/checker.h"
  13. #include "test/common/images2neibs.h"
  14. #include "test/common/rng.h"
  15. #include "test/cuda/benchmark.h"
  16. namespace megdnn {
  17. namespace test {
  18. TEST_F(CUDA, IMAGES2NEIBS_FORWARD)
  19. {
  20. auto args = images2neibs::get_args();
  21. for (auto &&arg: args) {
  22. Checker<Images2NeibsForward> checker(handle_cuda());
  23. checker.set_param(arg.param).set_dtype(0, dtype::Float32()).
  24. exec(TensorShapeArray{
  25. arg.ishape, {}});
  26. checker.set_param(arg.param).set_dtype(0, dtype::Float16()).
  27. exec(TensorShapeArray{
  28. arg.ishape, {}});
  29. }
  30. }
  31. #if MEGDNN_WITH_BENCHMARK
  32. TEST_F(CUDA, BENCHMARK_IMAGES2NEIBS_FORWARD)
  33. {
  34. auto args = images2neibs::get_benchmark_args();
  35. for (auto &&arg: args) {
  36. CUBenchmarker<Images2NeibsForward> bencher(handle_cuda());
  37. bencher.set_param(arg.param).set_dtype(0, dtype::Float32()).
  38. exec(TensorShapeArray{
  39. arg.ishape, {}});
  40. }
  41. }
  42. #endif
  43. TEST_F(CUDA, IMAGES2NEIBS_BACKWARD)
  44. {
  45. UniformFloatRNG rng(0, 1);
  46. auto args = images2neibs::get_args();
  47. for (auto &&arg: args) {
  48. Checker<Images2NeibsBackward> checker(handle_cuda());
  49. checker.set_epsilon(1e-2);
  50. checker.set_rng(0, &rng);
  51. TensorLayout ilayout = TensorLayout(arg.ishape, dtype::Float32());
  52. TensorLayout olayout;
  53. {
  54. auto opr = handle_cuda()->create_operator<Images2Neibs>();
  55. opr->param() = arg.param;
  56. opr->deduce_layout(ilayout, olayout);
  57. }
  58. auto set_dtype = [&checker](DType dtype)
  59. {
  60. checker.set_dtype(0, dtype).
  61. set_dtype(1, dtype);
  62. };
  63. set_dtype(dtype::Float32());
  64. checker.set_param(arg.param).exec(TensorShapeArray{
  65. olayout, ilayout});
  66. set_dtype(dtype::Float16());
  67. checker.set_param(arg.param).exec(TensorShapeArray{
  68. olayout, ilayout});
  69. }
  70. }
  71. } // namespace test
  72. } // namespace megdnn
  73. // vim: syntax=cpp.doxygen

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