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.

add_update.h.hip 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. *
  3. * \file dnn/src/rocm/add_update/add_update.h.hip
  4. *
  5. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  6. *
  7. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  8. *
  9. * Unless required by applicable law or agreed to in writing,
  10. * software distributed under the License is distributed on an
  11. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. */
  13. #pragma once
  14. #include "hip_header.h"
  15. #include "src/rocm/elemwise_helper.h.hip"
  16. #if MEGDNN_CC_HOST
  17. #include "megdnn/oprs.h"
  18. #endif
  19. namespace megdnn {
  20. namespace rocm {
  21. template<typename ctype>
  22. struct AddUpdateKernOp {
  23. ctype *dst;
  24. ctype alpha, beta, bias;
  25. __device__ void operator() (uint32_t idx, ctype delta) {
  26. dst[idx] = dst[idx] * alpha + delta * beta + bias;
  27. }
  28. #if MEGDNN_CC_HOST
  29. AddUpdateKernOp(const TensorND &dest, const AddUpdate::Param &param):
  30. dst{dest.ptr<ctype>()},
  31. alpha(param.alpha), beta(param.beta), bias(param.bias)
  32. {
  33. }
  34. #endif
  35. };
  36. template<typename ctype>
  37. struct AddUpdateKernOpNonContig {
  38. ctype alpha, beta, bias;
  39. __device__ void operator() (uint32_t /*idx*/, ctype &dst, ctype delta) {
  40. dst = dst * alpha + delta * beta + bias;
  41. }
  42. #if MEGDNN_CC_HOST
  43. AddUpdateKernOpNonContig(const AddUpdate::Param &param):
  44. alpha(param.alpha), beta(param.beta), bias(param.bias)
  45. {
  46. }
  47. #endif
  48. };
  49. }
  50. }
  51. // vim: ft=cpp syntax=cpp.doxygen

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