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.

eye.cpp.hip 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * \file dnn/src/rocm/eye/eye.cpp.hip
  3. *
  4. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  5. *
  6. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  7. *
  8. * Unless required by applicable law or agreed to in writing,
  9. * software distributed under the License is distributed on an
  10. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. */
  12. #include "hcc_detail/hcc_defs_prologue.h"
  13. #include "hip_header.h"
  14. #include "megdnn/dtype.h"
  15. #include "src/rocm/eye/eye.h.hip"
  16. #include "src/rocm/utils.h.hip"
  17. namespace {
  18. template <typename T>
  19. __global__ void kernel(T* dst, uint32_t m, uint32_t n, int k) {
  20. int32_t i = threadIdx.x + blockIdx.x * blockDim.x;
  21. int32_t x = i % n;
  22. int32_t y = i / n;
  23. if (i < m * n) {
  24. dst[i] = (y + k == x);
  25. }
  26. }
  27. } // anonymous namespace
  28. namespace megdnn {
  29. namespace rocm {
  30. namespace eye {
  31. template <typename T>
  32. void exec_internal(T* dst, size_t m, size_t n, int k, hipStream_t stream) {
  33. hipLaunchKernelGGL((kernel<T>), dim3(DIVUP(m * n, NR_THREADS)),
  34. dim3(NR_THREADS), 0, stream, dst, m, n, k);
  35. after_kernel_launch();
  36. }
  37. #define INST(T) \
  38. template void exec_internal<T>(T*, size_t, size_t, int, hipStream_t);
  39. #define cb(DType) INST(typename DTypeTrait<DType>::ctype)
  40. MEGDNN_FOREACH_COMPUTING_DTYPE(cb)
  41. cb(::megdnn::dtype::Bool)
  42. } // namespace eye
  43. } // namespace rocm
  44. } // namespace megdnn
  45. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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