diff options
author | Brad King <brad.king@kitware.com> | 2023-09-15 15:47:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-09-21 19:34:28 (GMT) |
commit | 8617c28221cac2bd89402178b25dcd47445a9349 (patch) | |
tree | 4570dd05f43aedb4d2f14c13a9c1d5e188654ad9 /Modules/Internal | |
parent | 0db0fe7958346ace0f5f01496e071c365faf3eb9 (diff) | |
download | CMake-8617c28221cac2bd89402178b25dcd47445a9349.zip CMake-8617c28221cac2bd89402178b25dcd47445a9349.tar.gz CMake-8617c28221cac2bd89402178b25dcd47445a9349.tar.bz2 |
CUDA: Factor out helper for detecting native CUDA architectures
Prepare to use it for other languages.
Diffstat (limited to 'Modules/Internal')
-rw-r--r-- | Modules/Internal/CMakeCUDAArchitecturesNative.cmake | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Modules/Internal/CMakeCUDAArchitecturesNative.cmake b/Modules/Internal/CMakeCUDAArchitecturesNative.cmake new file mode 100644 index 0000000..4185eda --- /dev/null +++ b/Modules/Internal/CMakeCUDAArchitecturesNative.cmake @@ -0,0 +1,49 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +function(cmake_cuda_architectures_native lang) + # Run the test binary to detect the native architectures. + execute_process(COMMAND "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin" + RESULT_VARIABLE archs_result + OUTPUT_VARIABLE archs_output + ERROR_VARIABLE archs_output + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(archs_result EQUAL 0) + 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_${lang}_ARCHITECTURES_ALL 0 arch_min) + list(GET CMAKE_${lang}_ARCHITECTURES_ALL -1 arch_max) + set(CMAKE_CUDA_ARCHITECTURES_NATIVE "") + foreach(arch IN LISTS archs_output) + if(arch LESS arch_min) + set(arch "${arch_min}") + endif() + if(arch GREATER arch_max) + set(arch "${arch_max}") + endif() + list(APPEND CMAKE_CUDA_ARCHITECTURES_NATIVE ${arch}) + endforeach() + unset(arch) + unset(arch_min) + unset(arch_max) + else() + set(CMAKE_CUDA_ARCHITECTURES_NATIVE "${archs_output}") + endif() + list(REMOVE_DUPLICATES CMAKE_CUDA_ARCHITECTURES_NATIVE) + list(TRANSFORM CMAKE_CUDA_ARCHITECTURES_NATIVE APPEND "-real") + else() + if(NOT archs_result MATCHES "[0-9]+") + set(archs_status " (${archs_result})") + else() + set(archs_status "") + endif() + string(REPLACE "\n" "\n " archs_output " ${archs_output}") + message(CONFIGURE_LOG + "Detecting the CUDA native architecture(s) failed with " + "the following output${archs_status}:\n${archs_output}\n\n") + endif() + + set(CMAKE_${lang}_ARCHITECTURES_NATIVE "${CMAKE_CUDA_ARCHITECTURES_NATIVE}" PARENT_SCOPE) +endfunction() |