summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-01 13:20:16 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-09-01 13:20:23 (GMT)
commit2d723e66f14452e4c6cf51528fa72777b5d5b396 (patch)
tree3cc194ccca5d8858487e3d4b3c04c3df43c09295
parentf7fbe405131eae2e914cd5aec310e1ec2614d840 (diff)
parent01428c5560f87122999a14fe4bf3e9b186b0127e (diff)
downloadCMake-2d723e66f14452e4c6cf51528fa72777b5d5b396.zip
CMake-2d723e66f14452e4c6cf51528fa72777b5d5b396.tar.gz
CMake-2d723e66f14452e4c6cf51528fa72777b5d5b396.tar.bz2
Merge topic 'cuda_host_compiler_fail'
01428c5560 CUDA: Fail fast if CMAKE_CUDA_ARCHITECTURES doesn't work during detection 9f81aa0f69 CUDA: Fail if compiler detection using the host compiler fails Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5155
-rw-r--r--Help/release/dev/cuda-fail-fast.rst6
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake41
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake9
3 files changed, 35 insertions, 21 deletions
diff --git a/Help/release/dev/cuda-fail-fast.rst b/Help/release/dev/cuda-fail-fast.rst
new file mode 100644
index 0000000..d857eb2
--- /dev/null
+++ b/Help/release/dev/cuda-fail-fast.rst
@@ -0,0 +1,6 @@
+cuda-fail-fast
+--------------
+
+* If ``CUDA`` compiler detection fails with user-specified
+ :variable:`CMAKE_CUDA_ARCHITECTURES` or :variable:`CMAKE_CUDA_HOST_COMPILER`
+ an error is raised.
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index daca382..6bdd06b 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -189,6 +189,10 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(nvcc_test_flags "--keep --keep-dir tmp")
if(CMAKE_CUDA_HOST_COMPILER)
string(APPEND nvcc_test_flags " -ccbin=\"${CMAKE_CUDA_HOST_COMPILER}\"")
+
+ # If the user has specified a host compiler we should fail instead of trying without.
+ # Succeeding detection without may result in confusing errors later on, see #21076.
+ set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
endif()
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
if(WIN32)
@@ -202,34 +206,35 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
endif()
endif()
- # First try with the user-specified architectures.
+ # Append user-specified architectures.
if(CMAKE_CUDA_ARCHITECTURES)
- set(clang_archs "${clang_test_flags}")
- set(nvcc_archs "${nvcc_test_flags}")
-
foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
# Strip specifiers as PTX vs binary doesn't matter.
string(REGEX MATCH "[0-9]+" arch_name "${arch}")
- string(APPEND clang_archs " --cuda-gpu-arch=sm_${arch_name}")
- string(APPEND nvcc_archs " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
+ string(APPEND clang_test_flags " --cuda-gpu-arch=sm_${arch_name}")
+ string(APPEND nvcc_test_flags " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
list(APPEND tested_architectures "${arch_name}")
endforeach()
- list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_archs}")
- list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_archs}")
+ # If the user has specified architectures we'll want to fail during compiler detection if they don't work.
+ set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
endif()
- # Fallback default NVCC flags.
- list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST ${nvcc_test_flags})
-
- # Clang doesn't automatically select an architecture supported by the SDK.
- # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups).
- foreach(arch "20" "30" "52")
- list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}")
- endforeach()
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
+ if(NOT CMAKE_CUDA_ARCHITECTURES)
+ # Clang doesn't automatically select an architecture supported by the SDK.
+ # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups).
+ foreach(arch "20" "30" "52")
+ list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}")
+ endforeach()
+ endif()
- # Finally also try the default.
- list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}")
+ # If the user specified CMAKE_CUDA_ARCHITECTURES this will include all the architecture flags.
+ # Otherwise this won't include any architecture flags and we'll fallback to Clang's defaults.
+ list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}")
+ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
+ list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_test_flags}")
+ endif()
# We perform compiler identification for a second time to extract implicit linking info and host compiler for NVCC.
# We also use it to verify that CMAKE_CUDA_ARCHITECTURES and additionally on Clang that CUDA toolkit path works.
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 8724ed8..688e1d8 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -628,9 +628,12 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT}
")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}")
- #if(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL)
- # message(FATAL_ERROR "${MSG}")
- #endif()
+
+ # Some languages may know the correct/desired set of flags and want to fail right away if they don't work.
+ # This is currently only used by CUDA.
+ if(CMAKE_${lang}_COMPILER_ID_REQUIRE_SUCCESS)
+ message(FATAL_ERROR "${MSG}")
+ endif()
# No output files should be inspected.
set(COMPILER_${lang}_PRODUCED_FILES)