summaryrefslogtreecommitdiff
path: root/Modules/CUDA
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-14 21:01:56 -0400
committerBrad King <brad.king@kitware.com>2022-03-16 13:14:51 -0400
commitff8c0e9c10cbd777466d7316abfb671a5eddc947 (patch)
tree183ea8260640b9308f75faea9b3d87b84c8e3149 /Modules/CUDA
parentd1b48bfabd6157309b3056967e6e30cc0ce07983 (diff)
downloadcmake-ff8c0e9c10cbd777466d7316abfb671a5eddc947.tar.gz
ci: Clamp CUDA 'native' architecture to values supported by its toolkit
The `native` architecture compiles for the host's GPUs, but our CI jobs may may run on hosts with GPUs newer than supported by their version of the CUDA toolkit. Add an undocumented environment variable to tell CMake to clamp the native architecture to that supported by the toolkit. Without this, we may try to compile for architectures not supported by the CUDA Toolkit, which fails. Since commit d1b48bfabd (CUDA: Add support for CUDA_ARCHITECTURES=native, 2022-03-04), our CUDA 9.2 CI job fails when it runs on a CI host with a GPU architecture newer than that CUDA 9.2 supports. Clamping the architecture level fixes that. Do not document this clamp behavior publicly, at least for now. Users can be responsible for building with a CUDA toolkit recent enough to support their host's GPUs. Issue: #22375
Diffstat (limited to 'Modules/CUDA')
-rw-r--r--Modules/CUDA/architectures.cmake22
1 files changed, 21 insertions, 1 deletions
diff --git a/Modules/CUDA/architectures.cmake b/Modules/CUDA/architectures.cmake
index 521243b44e..9b1f2b50a9 100644
--- a/Modules/CUDA/architectures.cmake
+++ b/Modules/CUDA/architectures.cmake
@@ -66,7 +66,27 @@ if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
)
endif()
if(_CUDA_ARCHS_RESULT EQUAL 0)
- set(_CUDA_ARCHITECTURES_NATIVE "${_CUDA_ARCHS_OUTPUT}")
+ if("$ENV{CMAKE_CUDA_ARCHITECTURES_NATIVE_CLAMP}")
+ # Undocumented hook used by CMake's CI.
+ # Clamp native architecture to version range supported by this CUDA.
+ list(GET CMAKE_CUDA_ARCHITECTURES_ALL 0 _CUDA_ARCH_MIN)
+ list(GET CMAKE_CUDA_ARCHITECTURES_ALL -1 _CUDA_ARCH_MAX)
+ set(_CUDA_ARCHITECTURES_NATIVE "")
+ foreach(_CUDA_ARCH IN LISTS _CUDA_ARCHS_OUTPUT)
+ if(_CUDA_ARCH LESS _CUDA_ARCH_MIN)
+ set(_CUDA_ARCH "${_CUDA_ARCH_MIN}")
+ endif()
+ if(_CUDA_ARCH GREATER _CUDA_ARCH_MAX)
+ set(_CUDA_ARCH "${_CUDA_ARCH_MAX}")
+ endif()
+ list(APPEND _CUDA_ARCHITECTURES_NATIVE ${_CUDA_ARCH})
+ endforeach()
+ unset(_CUDA_ARCH)
+ unset(_CUDA_ARCH_MIN)
+ unset(_CUDA_ARCH_MAX)
+ else()
+ set(_CUDA_ARCHITECTURES_NATIVE "${_CUDA_ARCHS_OUTPUT}")
+ endif()
list(REMOVE_DUPLICATES _CUDA_ARCHITECTURES_NATIVE)
else()
if (NOT _CUDA_ARCHS_RESULT MATCHES "[0-9]+")