From ff8c0e9c10cbd777466d7316abfb671a5eddc947 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Mar 2022 21:01:56 -0400 Subject: 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 --- Modules/CUDA/architectures.cmake | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'Modules/CUDA') 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]+") -- cgit v1.2.1