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.

local.cpp 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * \file dnn/test/cuda/local.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/local.h"
  14. #include "test/cuda/local/local.h"
  15. #include <cuda_runtime_api.h>
  16. #include "megcore_cuda.h"
  17. namespace megdnn {
  18. namespace test {
  19. TEST_F(CUDA, LOCAL_FORWARD)
  20. {
  21. auto args = local::get_args_for_cuda();
  22. for (auto &&arg: args) {
  23. Checker<LocalForward> checker(handle_cuda());
  24. cudaStream_t stream;
  25. ASSERT_EQ(megcoreSuccess,
  26. megcoreGetCUDAStream(handle_cuda()->megcore_computing_handle(),
  27. &stream));
  28. pollute_shared_mem(stream);
  29. checker.set_param(arg.param).exec(TensorShapeArray{
  30. arg.sshape(), arg.fshape(), arg.dshape()});
  31. }
  32. }
  33. TEST_F(CUDA, LOCAL_BACKWARD_DATA)
  34. {
  35. using namespace local;
  36. //std::vector<TestArg> args;
  37. //args.emplace_back(param::Convolution{
  38. // param::Convolution::Mode::CROSS_CORRELATION,
  39. // 1, 1, 1, 1},
  40. // 64, 16, 8, 7, 16, 8, 7, 3, 3);
  41. auto args = local::get_args_bwd_data_for_cuda();
  42. for (auto &&arg: args) {
  43. Checker<LocalBackwardData> checker(handle_cuda());
  44. cudaStream_t stream;
  45. ASSERT_EQ(megcoreSuccess,
  46. megcoreGetCUDAStream(handle_cuda()->megcore_computing_handle(),
  47. &stream));
  48. pollute_shared_mem(stream);
  49. checker.set_param(arg.param).exec(TensorShapeArray{
  50. arg.fshape(), arg.dshape(), arg.sshape()});
  51. }
  52. }
  53. TEST_F(CUDA, LOCAL_BACKWARD_FILTER)
  54. {
  55. using namespace local;
  56. //std::vector<TestArg> args;
  57. //args.emplace_back(param::Convolution{
  58. // param::Convolution::Mode::CROSS_CORRELATION,
  59. // 1, 1, 1, 1},
  60. // 64, 16, 8, 7, 16, 8, 7, 3, 3);
  61. auto args = local::get_args_bwd_filter_for_cuda();
  62. for (auto &&arg: args) {
  63. Checker<LocalBackwardFilter> checker(handle_cuda());
  64. cudaStream_t stream;
  65. ASSERT_EQ(megcoreSuccess,
  66. megcoreGetCUDAStream(handle_cuda()->megcore_computing_handle(),
  67. &stream));
  68. pollute_shared_mem(stream);
  69. checker.set_param(arg.param).exec(TensorShapeArray{
  70. arg.sshape(), arg.dshape(), arg.fshape()});
  71. }
  72. }
  73. } // namespace test
  74. } // namespace megdnn
  75. // vim: syntax=cpp.doxygen

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