This script locates the NVIDIA CUDA toolkit and the associated libraries, but does not require the CUDA language be enabled for a given project. This module does not search for the NVIDIA CUDA Samples.
Finding the CUDA Toolkit requires finding the nvcc executable, which is searched for in the following order:
If the CUDA language has been enabled we will use the directory containing the compiler as the first search location for nvcc.
If the CUDAToolkit_ROOT cmake configuration variable (e.g., -DCUDAToolkit_ROOT=/some/path) or environment variable is defined, it will be searched. If both an environment variable and a configuration variable are specified, the configuration variable takes precedence.
The directory specified here must be such that the executable nvcc can be found underneath the directory specified by CUDAToolkit_ROOT. If CUDAToolkit_ROOT is specified, but no nvcc is found underneath, this package is marked as not found. No subsequent search attempts are performed.
If the CUDA_PATH environment variable is defined, it will be searched.
The user’s path is searched for nvcc using find_program(). If this is found, no subsequent search attempts are performed. Users are responsible for ensuring that the first nvcc to show up in the path is the desired path in the event that multiple CUDA Toolkits are installed.
On Unix systems, if the symbolic link /usr/local/cuda exists, this is used. No subsequent search attempts are performed. No default symbolic link location exists for the Windows platform.
The platform specific default install locations are searched. If exactly one candidate is found, this is used. The default CUDA Toolkit install locations searched are:
Platform | Search Pattern |
---|---|
macOS | /Developer/NVIDIA/CUDA-X.Y |
Other Unix | /usr/local/cuda-X.Y |
Windows | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y |
Where X.Y would be a specific version of the CUDA Toolkit, such as /usr/local/cuda-9.0 or C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
Note
When multiple CUDA Toolkits are installed in the default location of a system (e.g., both /usr/local/cuda-9.0 and /usr/local/cuda-10.0 exist but the /usr/local/cuda symbolic link does not exist), this package is marked as not found.
There are too many factors involved in making an automatic decision in the presence of multiple CUDA Toolkits being installed. In this situation, users are encouraged to either (1) set CUDAToolkit_ROOT or (2) ensure that the correct nvcc executable shows up in $PATH for find_program() to find.
An imported target named CUDA::toolkit is provided.
This module defines IMPORTED targets for each of the following libraries that are part of the CUDAToolkit:
The CUDA Runtime library (cudart) are what most applications will typically need to link against to make any calls such as cudaMalloc, and cudaFree.
Targets Created:
The CUDA Driver library (cuda) are used by applications that use calls such as cuMemAlloc, and cuMemFree. This is generally used by advanced
Targets Created:
The cuBLAS library.
Targets Created:
The cuFFT library.
Targets Created:
The NPP libraries.
Targets Created:
The nvGRAPH library. Removed starting in CUDA 11.0
Targets Created:
The nvJPEG library. Introduced in CUDA 10.
Targets Created:
The nvRTC (Runtime Compilation) library. This is a shared library only.
Targets Created:
The NVIDIA Management Library. This is a shared library only.
Targets Created:
The NVIDIA Tools Extension. This is a shared library only.
Targets Created:
The cuLIBOS library is a backend thread abstraction layer library which is static only. The CUDA::cublas_static, CUDA::cusparse_static, CUDA::cufft_static, CUDA::curand_static, and (when implemented) NPP libraries all automatically have this dependency linked.
Target Created:
Note: direct usage of this target by consumers should not be necessary.