diff options
author | Henry Schreiner <hschrein@cern.ch> | 2018-04-20 04:28:20 (GMT) |
---|---|---|
committer | Henry Schreiner <hschrein@cern.ch> | 2018-04-20 13:43:50 (GMT) |
commit | 61b222f3aeddc6c34b4764c2997237c42ff3ec7d (patch) | |
tree | 8b67bbb4194022356453fec3807419dd296f0cbd | |
parent | c14497191bf4412b7b7f5241030f251373e4c0ae (diff) | |
download | CMake-61b222f3aeddc6c34b4764c2997237c42ff3ec7d.zip CMake-61b222f3aeddc6c34b4764c2997237c42ff3ec7d.tar.gz CMake-61b222f3aeddc6c34b4764c2997237c42ff3ec7d.tar.bz2 |
CUDA/select_compute_arch: Fix detection on old CUDA with new card/driver
Fix version comparisons to handle patch components. List and check
known archs for each version of CUDA so mismatching versions are not
suggested.
Fixes: #17921
-rw-r--r-- | Modules/FindCUDA/select_compute_arch.cmake | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake index 2a196c2..22c04df 100644 --- a/Modules/FindCUDA/select_compute_arch.cmake +++ b/Modules/FindCUDA/select_compute_arch.cmake @@ -17,35 +17,55 @@ # More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA # +if(CMAKE_CUDA_COMPILER_LOADED) # CUDA as a language + if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") + set(CUDA_VERSION "${CMAKE_CUDA_COMPILER_VERSION}") + endif() +endif() + +# See: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-feature-list + # This list will be used for CUDA_ARCH_NAME = All option set(CUDA_KNOWN_GPU_ARCHITECTURES "Fermi" "Kepler" "Maxwell") # This list will be used for CUDA_ARCH_NAME = Common option (enabled by default) set(CUDA_COMMON_GPU_ARCHITECTURES "3.0" "3.5" "5.0") -if(CMAKE_CUDA_COMPILER_LOADED) # CUDA as a language - if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA") - set(CUDA_VERSION "${CMAKE_CUDA_COMPILER_VERSION}") - endif() +if(CUDA_VERSION VERSION_LESS "7.0") + set(CUDA_LIMIT_GPU_ARCHITECTURE "5.2") endif() -if (CUDA_VERSION VERSION_GREATER "6.5") +# This list is used to filter CUDA archs when autodetecting +set(CUDA_ALL_GPU_ARCHITECTURES "3.0" "3.2" "3.5" "5.0") + +if(CUDA_VERSION VERSION_GREATER_EQUAL "7.0") list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Kepler+Tegra" "Kepler+Tesla" "Maxwell+Tegra") list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2") -endif () -if (CUDA_VERSION VERSION_GREATER "7.5") + if(CUDA_VERSION VERSION_LESS "8.0") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") + set(CUDA_LIMIT_GPU_ARCHITECTURE "6.0") + endif() +endif() + +if(CUDA_VERSION VERSION_GREATER_EQUAL "8.0") list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Pascal") list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1") -else() - list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") + list(APPEND CUDA_ALL_GPU_ARCHITECTURES "6.0" "6.1" "6.2") + + if(CUDA_VERSION VERSION_LESS "9.0") + list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.1+PTX") + set(CUDA_LIMIT_GPU_ARCHITECTURE "7.0") + endif() endif () -if (CUDA_VERSION VERSION_GREATER "8.5") +if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0") list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Volta") list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "7.0" "7.0+PTX") -else() - list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.1+PTX") + + if(CUDA_VERSION VERSION_LESS "10.0") + set(CUDA_LIMIT_GPU_ARCHITECTURE "8.0") + endif() endif() ################################################################################################ @@ -99,7 +119,19 @@ function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE) message(STATUS "Automatic GPU detection failed. Building for common architectures.") set(${OUT_VARIABLE} ${CUDA_COMMON_GPU_ARCHITECTURES} PARENT_SCOPE) else() - set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT} PARENT_SCOPE) + # Filter based on CUDA version supported archs + set(CUDA_GPU_DETECT_OUTPUT_FILTERED "") + separate_arguments(CUDA_GPU_DETECT_OUTPUT) + foreach(ITEM IN ITEMS ${CUDA_GPU_DETECT_OUTPUT}) + if(CUDA_LIMIT_GPU_ARCHITECTURE AND ITEM VERSION_GREATER_EQUAL CUDA_LIMIT_GPU_ARCHITECTURE) + list(GET CUDA_COMMON_GPU_ARCHITECTURES -1 NEWITEM) + string(APPEND CUDA_GPU_DETECT_OUTPUT_FILTERED " ${NEWITEM}") + else() + string(APPEND CUDA_GPU_DETECT_OUTPUT_FILTERED " ${ITEM}") + endif() + endforeach() + + set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT_FILTERED} PARENT_SCOPE) endif() endfunction() |