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.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * \file dnn/src/rocm/add_update/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 "hcc_detail/hcc_defs_prologue.h"
  12. #include "./opr_impl.h"
  13. #include "src/rocm/add_update/add_update.h.hip"
  14. #include "src/common/utils.h"
  15. using namespace megdnn;
  16. using namespace rocm;
  17. void AddUpdateForwardImpl::exec(_megdnn_tensor_inout dest,
  18. _megdnn_tensor_in delta) {
  19. check_exec(dest.layout, delta.layout);
  20. if (!dest.layout.is_contiguous()) {
  21. return exec_noncontig(dest, delta);
  22. }
  23. ElemwiseOpParamN<1> param;
  24. param[0] = delta;
  25. param[0].layout = param[0].layout.broadcast(dest.layout);
  26. param.init_from_given_tensor();
  27. auto stream = hip_stream(handle());
  28. switch (dest.layout.dtype.enumv()) {
  29. #define cb(_dt) \
  30. case DTypeTrait<_dt>::enumv: { \
  31. using ctype = DTypeTrait<_dt>::ctype; \
  32. return run_elemwise<AddUpdateKernOp<ctype>, ctype, 1>( \
  33. param, stream, {dest, m_param}); \
  34. }
  35. MEGDNN_FOREACH_COMPUTING_DTYPE(cb)
  36. #undef cb
  37. default:
  38. megdnn_throw("unsupported dtype for AddUpdate");
  39. }
  40. }
  41. void AddUpdateForwardImpl::exec_noncontig(_megdnn_tensor_inout dest,
  42. _megdnn_tensor_in delta) {
  43. ElemwiseOpParamN<2> param = make_param(dest, delta);
  44. auto stream = hip_stream(handle());
  45. switch (dest.layout.dtype.enumv()) {
  46. #define cb(_dt) \
  47. case DTypeTrait<_dt>::enumv: { \
  48. using ctype = DTypeTrait<_dt>::ctype; \
  49. return run_elemwise<AddUpdateKernOpNonContig<ctype>, ctype, 2>( \
  50. param, stream, {m_param}); \
  51. }
  52. MEGDNN_FOREACH_COMPUTING_DTYPE(cb)
  53. #undef cb
  54. default:
  55. megdnn_throw("unsupported dtype for AddUpdate");
  56. }
  57. }
  58. // vim: syntax=cpp.doxygen

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