summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-02 12:52:11 +0000
committerKitware Robot <kwrobot@kitware.com>2022-03-02 07:52:17 -0500
commit04a7200c7561509a83c34f2af45b2d091ae59248 (patch)
treead51e5ff4b9fb3ba5c66965b89cc3a3c455bef42
parentf0f4390325aaf627fe100f9c53afb9087f68cbd1 (diff)
parent2796d6eeca3d2507f12bc10db82a945a773419a2 (diff)
downloadcmake-04a7200c7561509a83c34f2af45b2d091ae59248.tar.gz
Merge topic 'cuda-arch-all' into release-3.23
2796d6eeca CUDA: Fix CMAKE_CUDA_ARCHITECTURES=all/all-major with NVCC 11.5+ e450d55552 Help: Update CUDA_ARCHITECTURES docs for generic all/all-major support fe64c49e72 CUDA: Simplify CMAKE_CUDA_ARCHITECTURES special value logic Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !7026
-rw-r--r--Help/prop_tgt/CUDA_ARCHITECTURES.rst18
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake43
-rw-r--r--Source/cmGeneratorTarget.cxx26
3 files changed, 45 insertions, 42 deletions
diff --git a/Help/prop_tgt/CUDA_ARCHITECTURES.rst b/Help/prop_tgt/CUDA_ARCHITECTURES.rst
index 41e5ae45f3..191f78f005 100644
--- a/Help/prop_tgt/CUDA_ARCHITECTURES.rst
+++ b/Help/prop_tgt/CUDA_ARCHITECTURES.rst
@@ -20,17 +20,19 @@ variable if it is set when a target is created.
The ``CUDA_ARCHITECTURES`` target property must be set to a non-empty value on targets
that compile CUDA sources, or it is an error. See policy :policy:`CMP0104`.
-.. versionadded:: 3.23
+The ``CUDA_ARCHITECTURES`` may be set to one of the following special values:
- The ``CUDA_ARCHITECTURES`` may be set to the following special keywords:
+``all``
+ .. versionadded:: 3.23
- ``all``
- Requires NVIDIA 11.5+. Will compile for all supported major and minor real
- architectures, and the highest major virtual architecture.
+ Compile for all supported major and minor real architectures,
+ and the highest major virtual architecture.
- ``all-major``
- Requires NVIDIA 11.5+. Will compile for all supported major real
- architectures, and the highest major virtual architecture.
+``all-major``
+ .. versionadded:: 3.23
+
+ Compile for all supported major real architectures, and the highest
+ major virtual architecture.
Examples
^^^^^^^^
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index c21d62291c..f491c798da 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -272,26 +272,25 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
endif()
endif()
- # Detect explicit architectures and add them during detection.
- if(DEFINED CMAKE_CUDA_ARCHITECTURES AND NOT "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all" AND NOT "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major")
- set(architectures_explicit TRUE)
- set(architectures_test ${CMAKE_CUDA_ARCHITECTURES})
- endif()
-
- # For sufficiently new NVCC we can just use the all and all-major flags.
- # For VS we don't test since we can't figure out the version this early (see #23161).
- # For others select based on version.
- if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.5)
- if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all")
- string(APPEND nvcc_test_flags " -arch=all")
- elseif("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major")
- string(APPEND nvcc_test_flags " -arch=all-major")
- endif()
- elseif(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
- if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all")
- set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL})
- elseif("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "all-major")
- set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR})
+ if(DEFINED CMAKE_CUDA_ARCHITECTURES)
+ if(CMAKE_CUDA_ARCHITECTURES MATCHES "^(all|all-major)$")
+ # For sufficiently new NVCC we can just use the all and all-major flags.
+ # For VS we don't test since we can't figure out the version this early (see #23161).
+ # For others select based on version.
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.5)
+ string(APPEND nvcc_test_flags " -arch=${CMAKE_CUDA_ARCHITECTURES}")
+ set(architectures_tested "${CMAKE_CUDA_ARCHITECTURES}")
+ elseif(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ if(CMAKE_CUDA_ARCHITECTURES STREQUAL "all")
+ set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL})
+ elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "all-major")
+ set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR})
+ endif()
+ endif()
+ else()
+ # Explicit architectures. Test them during detection.
+ set(architectures_explicit TRUE)
+ set(architectures_test ${CMAKE_CUDA_ARCHITECTURES})
endif()
endif()
@@ -632,7 +631,7 @@ if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
message(FATAL_ERROR "Failed to detect a default CUDA architecture.\n\nCompiler output:\n${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
endif()
endif()
-else()
+elseif(NOT "${architectures_tested}" MATCHES "^(all|all-major)$")
# Sort since order mustn't matter.
list(SORT architectures_detected)
list(SORT architectures_tested)
@@ -673,6 +672,8 @@ unset(_CUDA_TARGET_DIR)
unset(_CUDA_TARGET_NAME)
unset(architectures_explicit)
+unset(architectures_detected)
+unset(architectures_tested)
set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX")
set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX")
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index afcac5cbcb..63cf2ec0ea 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -3447,22 +3447,22 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const
this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
// Check for special modes: `all`, `all-major`.
- if (compiler == "NVIDIA" &&
- cmSystemTools::VersionCompare(
- cmSystemTools::OP_GREATER_EQUAL,
- this->Makefile->GetDefinition("CMAKE_CUDA_COMPILER_VERSION"),
- "11.5")) {
- if (property == "all" || property == "all-major") {
+ if (property == "all" || property == "all-major") {
+ if (compiler == "NVIDIA" &&
+ cmSystemTools::VersionCompare(
+ cmSystemTools::OP_GREATER_EQUAL,
+ this->Makefile->GetDefinition("CMAKE_CUDA_COMPILER_VERSION"),
+ "11.5")) {
flags = cmStrCat(flags, " -arch=", property);
return;
}
- }
-
- if (property == "all") {
- property = *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL");
- } else if (property == "all-major") {
- property =
- *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR");
+ if (property == "all") {
+ property =
+ *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL");
+ } else if (property == "all-major") {
+ property =
+ *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR");
+ }
}
struct CudaArchitecture