| 27 | namespace cuda { |
| 28 | |
| 29 | HandleImpl::HandleImpl(megcoreComputingHandle_t comp_handle) |
| 30 | : HandleImplHelper(comp_handle, HandleType::CUDA) { |
| 31 | // Get megcore device handle |
| 32 | megcoreDeviceHandle_t dev_handle; |
| 33 | megcoreGetDeviceHandle(comp_handle, &dev_handle); |
| 34 | int dev_id; |
| 35 | megcoreGetDeviceID(dev_handle, &dev_id); |
| 36 | if (dev_id < 0) { |
| 37 | cuda_check(cudaGetDevice(&dev_id)); |
| 38 | } |
| 39 | m_device_id = dev_id; |
| 40 | m_device_prop = get_device_prop(dev_id); |
| 41 | // Get stream from MegCore computing handle. |
| 42 | megdnn_assert( |
| 43 | CUDNN_VERSION == cudnnGetVersion(), |
| 44 | "cudnn version mismatch: compiled with %d; detected %zu at runtime, may " |
| 45 | "caused by customized environment, for example LD_LIBRARY_PATH on LINUX " |
| 46 | "and PATH on Windows!!", |
| 47 | CUDNN_VERSION, cudnnGetVersion()); |
| 48 | #if CUDA_VERSION >= 10010 |
| 49 | megdnn_assert( |
| 50 | cublasLtGetVersion() >= 10010, |
| 51 | "cuda library version is too low to run cublasLt"); |
| 52 | #endif |
| 53 | #if CUDNN_VERSION >= 8000 |
| 54 | if (!MGB_GETENV("CUDA_CACHE_PATH")) { |
| 55 | megdnn_log_warn(R"( |
| 56 | Cudnn8 will jit ptx code with cache. You can set |
| 57 | CUDA_CACHE_MAXSIZE and CUDA_CACHE_PATH environment var to avoid repeat jit(very slow). |
| 58 | For example `export CUDA_CACHE_MAXSIZE=2147483647` and `export CUDA_CACHE_PATH=/data/.cuda_cache`)"); |
| 59 | } |
| 60 | #endif |
| 61 | cudnn_check(cudnnCreate(&m_cudnn_handle)); |
| 62 | cublas_check(cublasCreate(&m_cublas_handle)); |
| 63 | #if CUDA_VERSION >= 10010 |
| 64 | cublas_check(cublasLtCreate(&m_cublasLt_handle)); |
| 65 | #endif |
| 66 | megcore::getCUDAContext(comp_handle, &m_megcore_context); |
| 67 | |
| 68 | // Set stream for cuDNN and cublas handles. |
| 69 | cudnn_check(cudnnSetStream(m_cudnn_handle, stream())); |
| 70 | cublas_check(cublasSetStream(m_cublas_handle, stream())); |
| 71 | |
| 72 | // Note that all cublas scalars (alpha, beta) and scalar results such as dot |
| 73 | // output resides at device side. |
| 74 | cublas_check(cublasSetPointerMode(m_cublas_handle, CUBLAS_POINTER_MODE_DEVICE)); |
| 75 | |
| 76 | // init const scalars |
| 77 | cuda_check(cudaMalloc((void**)&m_const_scalars, sizeof(ConstScalars))); |
| 78 | ConstScalars const_scalars_val; |
| 79 | const_scalars_val.init(); |
| 80 | cuda_check(cudaMemcpyAsync( |
| 81 | m_const_scalars, &const_scalars_val, sizeof(ConstScalars), |
| 82 | cudaMemcpyHostToDevice, stream())); |
| 83 | cuda_check(cudaStreamSynchronize(stream())); |
| 84 | |
| 85 | // check tk1 |
| 86 | m_is_tegra_k1 = (strcmp(m_device_prop->name, "GK20A") == 0); |
nothing calls this directly
no test coverage detected