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.

utils.h 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * \file dnn/src/cuda/utils.h
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2020 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
  10. * implied.
  11. */
  12. #pragma once
  13. #include "megcore_cdefs.h"
  14. #include "src/common/utils.h"
  15. #include "megdnn/handle.h"
  16. #include "src/cuda/handle.h"
  17. #include "src/cuda/utils.cuh"
  18. #include "src/cuda/cudnn_with_check.h"
  19. #include <cuda_runtime_api.h>
  20. #include <cublas_v2.h>
  21. namespace megdnn {
  22. namespace cuda {
  23. static inline HandleImpl* concrete_handle(Handle* handle) {
  24. return static_cast<cuda::HandleImpl*>(handle);
  25. }
  26. static inline cudnnHandle_t cudnn_handle(Handle* handle) {
  27. return concrete_handle(handle)->cudnn_handle();
  28. }
  29. static inline cublasHandle_t cublas_handle(Handle* handle) {
  30. return concrete_handle(handle)->cublas_handle();
  31. }
  32. static inline cudaStream_t cuda_stream(Handle* handle) {
  33. return concrete_handle(handle)->stream();
  34. }
  35. static inline megcore::AsyncErrorInfo* async_error_info(Handle* handle) {
  36. return concrete_handle(handle)->megcore_context().error_info;
  37. }
  38. static inline void CUDART_CB callback_free(cudaStream_t /* stream */,
  39. cudaError_t status, void* userData) {
  40. cuda_check(status);
  41. free(userData);
  42. }
  43. //! get property of currently active device
  44. cudaDeviceProp current_device_prop();
  45. //! check compute capability satisfied with given sm version
  46. bool is_compute_capability_required(int major, int minor);
  47. //! check compute capability equal to the given sm version
  48. bool is_compute_capability_equalto(int major, int minor);
  49. //! get the CUDNN_MAX_BATCH_X_CHANNEL_SIZE, it's just return the max size of the
  50. //! third demension
  51. size_t max_batch_x_channel_size();
  52. //! get param buffer start address at cmem[0]
  53. uint32_t param_buffer_start_address();
  54. const char* current_device_arch_name();
  55. } // namespace cuda
  56. } // namespace megdnn
  57. // vim: syntax=cpp.doxygen

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