# FindCUDAToolkit

Added in version 3.17.

Finds the NVIDIA CUDA toolkit and the associated libraries, but does not require the `CUDA` language be enabled for a given project:

    find_package(CUDAToolkit [<version>] [QUIET] [REQUIRED] [EXACT] [...])

This module does not search for the NVIDIA CUDA Samples.

Added in version 3.19: QNX support.

## Search Behavior

The CUDA Toolkit search behavior uses the following order:

1. If the `CUDA` language has been enabled we will use the directory containing the compiler as the first search location for `nvcc`.

2. If the variable `CMAKE_CUDA_COMPILER` or the environment variable `CUDACXX` is defined, it will be used as the path to the `nvcc` executable.

3. 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` or the appropriate `version.txt` or `version.json` file can be found underneath the specified directory.

4. If the CUDA_PATH environment variable is defined, it will be searched for `nvcc`.

5. 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.

6. 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.

7. 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.

## Arguments

`[<version>]`

  The `[<version>]` argument requests a version with which the package found should be compatible. See find_package version format for more details.

## Options

`REQUIRED`

  If specified, configuration will error if a suitable CUDA Toolkit is not found.

`QUIET`

  If specified, the search for a suitable CUDA Toolkit will not produce any messages.

`EXACT`

  If specified, the CUDA Toolkit is considered found only if the exact `VERSION` specified is recovered.

## Imported Targets

An imported target named `CUDA::toolkit` is provided.

This module provides Imported Targets for each of the following libraries that are part of the CUDAToolkit:

- CUDA Runtime Library

- CUDA Driver Library

- cuBLAS

- cuDLA

- cuFile

- cuFFT

- cuRAND

- cuSOLVER

- cuSPARSE

- cuPTI

- NPP

- nvBLAS

- nvGRAPH

- nvJPEG

- nvidia-ML

- nvPTX Compiler

- nvRTC

- nvJitLink

- nvFatBin

- nvToolsExt

- nvtx3

- OpenCL

- cuLIBOS

- cufilt

### CUDA Runtime Library

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:

- `CUDA::cudart`

- `CUDA::cudart_static`

### CUDA Driver Library

The CUDA Driver library (cuda) are used by applications that use calls such as cuMemAlloc, and cuMemFree.

Targets Created:

- `CUDA::cuda_driver`

### cuBLAS

The CUDA Basic Linear Algebra Subroutine library.

Targets Created:

- `CUDA::cublas`

- `CUDA::cublas_static`

- `CUDA::cublasLt` starting in CUDA 10.1

- `CUDA::cublasLt_static` starting in CUDA 10.1

### cuDLA

Added in version 3.27.

The NVIDIA Tegra Deep Learning Accelerator library.

Targets Created:

- `CUDA::cudla` starting in CUDA 11.6

### cuFile

Added in version 3.25.

The NVIDIA GPUDirect Storage cuFile library.

Targets Created:

- `CUDA::cuFile` starting in CUDA 11.4

- `CUDA::cuFile_static` starting in CUDA 11.4

- `CUDA::cuFile_rdma` starting in CUDA 11.4

- `CUDA::cuFile_rdma_static` starting in CUDA 11.4

### cuFFT

The CUDA Fast Fourier Transform library.

Targets Created:

- `CUDA::cufft`

- `CUDA::cufftw`

- `CUDA::cufft_static`

- `CUDA::cufft_static_nocallback` starting in CUDA 9.2, requires CMake 3.23+

- `CUDA::cufftw_static`

### cuRAND

The CUDA random number generation library.

Targets Created:

- `CUDA::curand`

- `CUDA::curand_static`

### cuSOLVER

A GPU accelerated linear system solver library.

Targets Created:

- `CUDA::cusolver`

- `CUDA::cusolver_static`

### cuSPARSE

The CUDA sparse matrix library.

Targets Created:

- `CUDA::cusparse`

- `CUDA::cusparse_static`

### cupti

The NVIDIA CUDA Profiling Tools Interface.

Targets Created:

- `CUDA::cupti`

- `CUDA::cupti_static`

Added in version 3.27:

- `CUDA::nvperf_host` starting in CUDA 10.2

- `CUDA::nvperf_host_static` starting in CUDA 10.2

- `CUDA::nvperf_target` starting in CUDA 10.2

- `CUDA::pcsamplingutil` starting in CUDA 11.3

### NPP

The NVIDIA 2D Image and Signal Processing Performance Primitives libraries.

Targets Created:

- nppc:

  - `CUDA::nppc`

  - `CUDA::nppc_static`

- nppial: Arithmetic and logical operation functions in nppi_arithmetic_and_logical_operations.h

  - `CUDA::nppial`

  - `CUDA::nppial_static`

- nppicc: Color conversion and sampling functions in nppi_color_conversion.h

  - `CUDA::nppicc`

  - `CUDA::nppicc_static`

- nppicom: JPEG compression and decompression functions in nppi_compression_functions.h Removed starting in CUDA 11.0, use nvJPEG instead.

  - `CUDA::nppicom`

  - `CUDA::nppicom_static`

- nppidei: Data exchange and initialization functions in nppi_data_exchange_and_initialization.h

  - `CUDA::nppidei`

  - `CUDA::nppidei_static`

- nppif: Filtering and computer vision functions in nppi_filter_functions.h

  - `CUDA::nppif`

  - `CUDA::nppif_static`

- nppig: Geometry transformation functions found in nppi_geometry_transforms.h

  - `CUDA::nppig`

  - `CUDA::nppig_static`

- nppim: Morphological operation functions found in nppi_morphological_operations.h

  - `CUDA::nppim`

  - `CUDA::nppim_static`

- nppist: Statistics and linear transform in nppi_statistics_functions.h and nppi_linear_transforms.h

  - `CUDA::nppist`

  - `CUDA::nppist_static`

- nppisu: Memory support functions in nppi_support_functions.h

  - `CUDA::nppisu`

  - `CUDA::nppisu_static`

- nppitc: Threshold and compare operation functions in nppi_threshold_and_compare_operations.h

  - `CUDA::nppitc`

  - `CUDA::nppitc_static`

- npps:

  - `CUDA::npps`

  - `CUDA::npps_static`

### nvBLAS

The GPU-accelerated drop-in BLAS library. This is a shared library only.

Targets Created:

- `CUDA::nvblas`

### nvGRAPH

A GPU-accelerated graph analytics library. Removed starting in CUDA 11.0

Targets Created:

- `CUDA::nvgraph`

- `CUDA::nvgraph_static`

### nvJPEG

A GPU-accelerated JPEG codec library. Introduced in CUDA 10.

Targets Created:

- `CUDA::nvjpeg`

- `CUDA::nvjpeg_static`

### nvPTX Compiler

Added in version 3.25.

The PTX Compiler APIs. These are a set of APIs which can be used to compile a PTX program into GPU assembly code. Introduced in CUDA 11.1 This is a static library only.

Targets Created:

- `CUDA::nvptxcompiler_static` starting in CUDA 11.1

### nvRTC

A runtime compilation library for CUDA.

Targets Created:

- `CUDA::nvrtc`

Added in version 3.26:

- `CUDA::nvrtc_builtins`

- `CUDA::nvrtc_static` starting in CUDA 11.5

- `CUDA::nvrtc_builtins_static` starting in CUDA 11.5

### nvJitLink

The JIT Link APIs.

Targets Created:

- `CUDA::nvJitLink` starting in CUDA 12.0

- `CUDA::nvJitLink_static` starting in CUDA 12.0

### nvFatBin

Added in version 3.30.

The Fatbin Creator APIs.

Targets Created:

- `CUDA::nvfatbin` starting in CUDA 12.4

- `CUDA::nvfatbin_static` starting in CUDA 12.4

### nvidia-ML

The NVIDIA Management Library.

Targets Created:

- `CUDA::nvml`

- `CUDA::nvml_static` starting in CUDA 12.4

Added in version 3.31: Added `CUDA::nvml_static`.

### nvToolsExt

Deprecated since version 3.25: With CUDA 10.0+, use nvtx3. Starting in CUDA 12.9 the nvToolsExt library no longer exists

The legacy NVIDIA Tools Extension. This is a shared library only.

Targets Created:

- `CUDA::nvToolsExt`

### nvtx3

Added in version 3.25.

The header-only NVIDIA Tools Extension library. Introduced in CUDA 10.0.

Targets created:

- `CUDA::nvtx3`

- `CUDA::nvtx3_interop`

  Added in version 4.1.

  This is provided by CUDA 12.9 and above for use by languages that cannot consume C++ header-only libraries, such as `Fortran`.

### OpenCL

The NVIDIA Open Computing Language library. This is a shared library only.

Targets Created:

- `CUDA::OpenCL`

### cuLIBOS

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:

- `CUDA::culibos`

Note: direct usage of this target by consumers should not be necessary.

### bin2c

Added in version 4.3.

A utility that converts binary files to C files containing byte arrays.

Target Created:

- `CUDA::bin2c`

### compute-sanitizer

Added in version 4.4.

The NVIDIA Compute Sanitizer library, which allows the tracing of CUDA runtime and driver calls.

Target Created:

- `CUDA::sanitizer`

### cufilt

Added in version 4.4.

The cu++filt binary utility also provides a static library for demangling CUDA C++ symbols.

Targets Created:

- `CUDA::cufilt` starting in CUDA 11.4

## Result Variables

This module defines the following variables:

`CUDAToolkit_FOUND`

  A boolean specifying whether or not the CUDA Toolkit was found.

`CUDAToolkit_VERSION`

  The exact version of the CUDA Toolkit found (as reported by `nvcc --version`, `version.txt`, or `version.json`).

`CUDAToolkit_VERSION_MAJOR`

  The major version of the CUDA Toolkit.

`CUDAToolkit_VERSION_MINOR`

  The minor version of the CUDA Toolkit.

`CUDAToolkit_VERSION_PATCH`

  The patch version of the CUDA Toolkit.

`CUDAToolkit_BIN_DIR`

  The path to the CUDA Toolkit library directory that contains the CUDA executable `nvcc`.

`CUDAToolkit_INCLUDE_DIRS`

  List of paths to all the CUDA Toolkit folders containing header files required to compile a project linking against CUDA.

`CUDAToolkit_LIBRARY_DIR`

  The path to the CUDA Toolkit library directory that contains the CUDA Runtime library `cudart`.

`CUDAToolkit_LIBRARY_ROOT`

  Added in version 3.18.

  The path to the CUDA Toolkit directory containing the nvvm directory and either version.txt or version.json.

`CUDAToolkit_TARGET_DIR`

  The path to the CUDA Toolkit directory including the target architecture when cross-compiling. When not cross-compiling this will be equivalent to the parent directory of `CUDAToolkit_BIN_DIR`.

`CUDAToolkit_NVCC_EXECUTABLE`

  The path to the NVIDIA CUDA compiler `nvcc`. Note that this path may not be the same as `CMAKE_CUDA_COMPILER`. `nvcc` must be found to determine the CUDA Toolkit version as well as determining other features of the Toolkit. This variable is set for the convenience of modules that depend on this one.