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.

query_blocksize_impl.cu 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * \file dnn/src/cuda/query_blocksize_impl.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 "src/cuda/query_blocksize.cuh"
  12. #include "src/cuda/utils.cuh"
  13. using namespace megdnn;
  14. using namespace cuda;
  15. /*
  16. * Note: cudaOccupancyMaxPotentialBlockSizeVariableSMem is only available when
  17. * compiled by nvcc, but it is implemented as a __host__ __device__ function. So
  18. * we implement a device wrapper
  19. */
  20. namespace {
  21. struct SmemGetterWrapper {
  22. SmemGetter getter;
  23. __device__ __host__ int operator()(int block_size) const {
  24. #if __CUDA_ARCH__
  25. // device func should never be called
  26. int* ptr = 0;
  27. *ptr = 23;
  28. #else
  29. if (getter.func) {
  30. return getter.func(block_size, getter.user_data);
  31. }
  32. #endif
  33. return 0;
  34. }
  35. };
  36. } // anonymous namespace
  37. LaunchConfig cuda::detail::query_launch_config_for_kernel_uncached(
  38. const void* kern, const SmemGetter& smem) {
  39. SmemGetterWrapper s;
  40. s.getter = smem;
  41. LaunchConfig ret;
  42. cuda_check(cudaOccupancyMaxPotentialBlockSizeVariableSMem(
  43. &ret.grid_size, &ret.block_size, kern, s));
  44. return ret;
  45. }
  46. // vim: ft=cpp syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

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