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.cu 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * \file dnn/src/cuda/eye/eye.cu
  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 "megdnn/dtype.h"
  12. #include "src/cuda/eye/eye.cuh"
  13. #include "src/cuda/utils.cuh"
  14. namespace {
  15. template <typename T>
  16. __global__ void kernel(T* dst, uint32_t m, uint32_t n, int k) {
  17. int32_t i = threadIdx.x + blockIdx.x * blockDim.x;
  18. int32_t x = i % n;
  19. int32_t y = i / n;
  20. if (i < m * n) {
  21. dst[i] = (y + k == x);
  22. }
  23. }
  24. } // anonymous namespace
  25. namespace megdnn {
  26. namespace cuda {
  27. namespace eye {
  28. template <typename T>
  29. void exec_internal(T* dst, size_t m, size_t n, int k, cudaStream_t stream) {
  30. kernel<T><<<DIVUP(m * n, NR_THREADS), NR_THREADS, 0, stream>>>(dst, m, n, k);
  31. after_kernel_launch();
  32. }
  33. #define INST(T) template void exec_internal<T>(T*, size_t, size_t, int, cudaStream_t);
  34. #define cb(DType) INST(typename DTypeTrait<DType>::ctype)
  35. MEGDNN_FOREACH_COMPUTING_DTYPE(cb)
  36. cb(::megdnn::dtype::Bool)
  37. } // namespace eye
  38. } // namespace cuda
  39. } // namespace megdnn
  40. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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