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.

linspace.cpp.hip 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * \file src/rocm/linspace/linspace.cpp.hip
  3. *
  4. * This file is part of MegDNN, a deep neural network run-time library
  5. * developed by Megvii.
  6. *
  7. * \copyright Copyright (c) 2014-2019 Megvii Inc. All rights reserved.
  8. */
  9. #include "hcc_detail/hcc_defs_prologue.h"
  10. #include "./linspace.h.hip"
  11. #include "src/rocm/utils.h.hip"
  12. #include "megdnn/dtype.h"
  13. namespace {
  14. template <typename T>
  15. __global__ void kernel(T *dst, double start, double step, uint32_t n)
  16. {
  17. uint32_t i = threadIdx.x + blockIdx.x * blockDim.x;
  18. if (i < n) {
  19. dst[i] = T(start + step*i);
  20. }
  21. }
  22. } // anonymous namespace
  23. namespace megdnn {
  24. namespace rocm {
  25. namespace linspace {
  26. template <typename T>
  27. void exec_internal(T *dst, double start, double step, size_t n,
  28. hipStream_t stream)
  29. {
  30. uint32_t threads = NR_THREADS;
  31. uint32_t blocks = DIVUP(n, threads);
  32. hipLaunchKernelGGL(kernel,
  33. dim3(blocks), dim3(threads), 0, stream,
  34. dst, start, step, n);
  35. after_kernel_launch();
  36. }
  37. #define INST(T) template void exec_internal<T>(T *dst, \
  38. double start, double step, size_t n, hipStream_t stream);
  39. #define cb(DType) INST(typename DTypeTrait<DType>::ctype)
  40. MEGDNN_FOREACH_COMPUTING_DTYPE(cb)
  41. } // namespace linspace
  42. } // namespace rocm
  43. } // namespace megdnn
  44. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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