1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

CUDA: Initialize CMAKE_CUDA_ARCHITECTURES using $ENV{CUDAARCHS}

NVCC's default architecture may be newer than the one supported by the
machine's GPU.
In such cases it's useful to have an environment variable for initializing
CMAKE_CUDA_ARCHITECTURES to avoid specifying it for every invocation.
This commit is contained in:
Raul Tambre
2020-11-24 19:21:36 +02:00
parent 8187bd2f4b
commit c4ae9384ff
5 changed files with 26 additions and 1 deletions

13
Help/envvar/CUDAARCHS.rst Normal file
View File

@@ -0,0 +1,13 @@
CUDAARCHS
---------
.. versionadded:: 3.20
.. include:: ENV_VAR.txt
Value used to initialize :variable:`CMAKE_CUDA_ARCHITECTURES` on the first
configuration if it's not already defined. Subsequent runs will use the value
stored in the cache.
This is a semicolon-separated list of architectures as described in
:prop_tgt:`CUDA_ARCHITECTURES`.

View File

@@ -56,6 +56,7 @@ Environment Variables for Languages
/envvar/CC
/envvar/CFLAGS
/envvar/CSFLAGS
/envvar/CUDAARCHS
/envvar/CUDACXX
/envvar/CUDAFLAGS
/envvar/CUDAHOSTCXX

View File

@@ -0,0 +1,6 @@
cuda-archs-env
--------------
* The :envvar:`CUDAARCHS` environment variable was added for initializing
:variable:`CMAKE_CUDA_ARCHITECTURES`. Useful in cases where the compiler
default is unsuitable for the machine's GPU.

View File

@@ -5,7 +5,8 @@ CMAKE_CUDA_ARCHITECTURES
Default value for :prop_tgt:`CUDA_ARCHITECTURES` property of targets.
This is initialized as follows depending on :variable:`CMAKE_CUDA_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>`:
Initialized by the :envvar:`CUDAARCHS` environment variable if set.
Otherwise as follows depending on :variable:`CMAKE_CUDA_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>`:
- For ``Clang``: the oldest architecture that works.

View File

@@ -47,6 +47,10 @@ if(NOT $ENV{CUDAHOSTCXX} STREQUAL "")
endif()
endif()
if(NOT "$ENV{CUDAARCHS}" STREQUAL "")
set(CMAKE_CUDA_ARCHITECTURES "$ENV{CUDAARCHS}" CACHE STRING "CUDA architectures")
endif()
# Build a small source file to identify the compiler.
if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(CMAKE_CUDA_COMPILER_ID_RUN 1)