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.

opr_impl.cpp 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * \file dnn/src/cuda/mask_conv/opr_impl.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 "src/cuda/mask_conv/opr_impl.h"
  12. #include "./mask_conv.cuh"
  13. #include "src/cuda/utils.h"
  14. namespace megdnn {
  15. namespace cuda {
  16. MaskConvForwardImpl::MaskConvForwardImpl(Handle* handle)
  17. : MaskConvForward(handle) {
  18. m_conv_opr = static_cast<HandleImpl*>(handle)
  19. ->create_operator<ConvolutionForward>();
  20. }
  21. void MaskConvForwardImpl::exec(_megdnn_tensor_in src, _megdnn_tensor_in filter,
  22. _megdnn_tensor_in mask, _megdnn_tensor_out dst,
  23. _megdnn_workspace workspace) {
  24. megdnn_assert(dst.layout.dtype.enumv() == DTypeTrait<dtype::Float32>::enumv,
  25. "Mask conv only support Float32 dtype.");
  26. m_conv_opr->exec(src, filter, dst, nullptr, workspace);
  27. auto stream = cuda_stream(handle());
  28. #define cb(DType) \
  29. if (mask.layout.dtype == DType()) { \
  30. using ctype = typename DTypeTrait<DType>::ctype; \
  31. mask_conv::set_zero_by_mask_proxy<ctype>( \
  32. dst.ptr<float>(), mask.ptr<ctype>(), dst.layout[0], \
  33. dst.layout[1], dst.layout[2], dst.layout[3], stream); \
  34. return; \
  35. }
  36. MEGDNN_FOREACH_COMPUTING_DTYPE_INT(cb)
  37. #undef cb
  38. megdnn_assert_internal(0);
  39. }
  40. void MaskPropagateImpl::exec(_megdnn_tensor_in src, _megdnn_tensor_out dst,
  41. _megdnn_workspace) {
  42. auto stream = cuda_stream(handle());
  43. #define cb(DType) \
  44. if (src.layout.dtype == DType()) { \
  45. using ctype = typename DTypeTrait<DType>::ctype; \
  46. mask_conv::mask_propagate_exec_proxy<ctype>( \
  47. src.ptr<ctype>(), dst.ptr<ctype>(), src.layout[0], \
  48. src.layout[1], dst.layout[0], dst.layout[1], param().kernel_h, \
  49. param().kernel_w, param().stride_h, param().stride_w, \
  50. param().pad_h, param().pad_w, param().dilate_h, \
  51. param().dilate_w, stream); \
  52. return; \
  53. }
  54. MEGDNN_FOREACH_COMPUTING_DTYPE_INT(cb);
  55. #undef cb
  56. megdnn_assert_internal(0);
  57. }
  58. } // namespace cuda
  59. } // namespace megdnn

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