diff --git a/docs/command/supported_cuda_architectures_values.txt b/docs/command/supported_cuda_architectures_values.txt new file mode 100644 index 00000000..742c4242 --- /dev/null +++ b/docs/command/supported_cuda_architectures_values.txt @@ -0,0 +1,7 @@ + +``NATIVE`` or ``""``: + When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` or :cmake:envvar:`ENV{CUDAARCHS} ` + will compile for all GPU architectures present on the current machine. + +``RAPIDS``, ``ALL``, or no value in :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` and :cmake:envvar:`ENV{CUDAARCHS} `: + When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` or :cmake:envvar:`ENV{CUDAARCHS} ` will compile for all supported RAPIDS GPU architectures. diff --git a/rapids-cmake/cuda/detail/invoke_set_all_architectures.cmake b/rapids-cmake/cuda/detail/invoke_set_all_architectures.cmake index afc1cf7f..c51ebf3e 100644 --- a/rapids-cmake/cuda/detail/invoke_set_all_architectures.cmake +++ b/rapids-cmake/cuda/detail/invoke_set_all_architectures.cmake @@ -23,4 +23,4 @@ endif() # Used by rapids_cuda_init_architectures to allow the `project()` call to invoke the # rapids_cuda_set_architectures function after compiler detection # -rapids_cuda_set_architectures(ALL) +rapids_cuda_set_architectures(RAPIDS) diff --git a/rapids-cmake/cuda/init_architectures.cmake b/rapids-cmake/cuda/init_architectures.cmake index 46da41a1..53f17eae 100644 --- a/rapids-cmake/cuda/init_architectures.cmake +++ b/rapids-cmake/cuda/init_architectures.cmake @@ -29,9 +29,9 @@ to include support for `ALL` and `NATIVE` to make CUDA architecture compilation rapids_cuda_init_architectures() Used before enabling the CUDA language either via :cmake:command:`project() ` to establish the -CUDA architectures to be compiled for. Parses the :cmake:envvar:`CUDAARCHS `, and +CUDA architectures to be compiled for. Parses the :cmake:envvar:`ENV{CUDAARCHS} `, and :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` for special values -`ALL`, `NATIVE` and `""`. +`ALL`, `RAPIDS`, `NATIVE` and `""`. .. note:: Required to be called before the first :cmake:command:`project() ` call. @@ -43,15 +43,7 @@ CUDA architectures to be compiled for. Parses the :cmake:envvar:`CUDAARCHS ` call. -``NATIVE`` or ``""``: - When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` - will compile for all GPU architectures present on the current machine. - -``ALL`` or no :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` and - :cmake:envvar:`ENV{CUDAARCHS} `: - When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` - will compile for all supported RAPIDS GPU architectures. - +.. include:: supported_cuda_architectures_values.txt Example on how to properly use :cmake:command:`rapids_cuda_init_architectures`: @@ -79,21 +71,23 @@ function(rapids_cuda_init_architectures project_name) # If `CMAKE_CUDA_ARCHITECTURES` is not defined, build for all supported architectures. If # `CMAKE_CUDA_ARCHITECTURES` is set to an empty string (""), build for only the current # architecture. If `CMAKE_CUDA_ARCHITECTURES` is specified by the user, use user setting. - if(DEFINED ENV{CUDAARCHS} AND "$ENV{CUDAARCHS}" STREQUAL "ALL") - set(cuda_arch_mode "ALL") + if(DEFINED ENV{CUDAARCHS} AND ("$ENV{CUDAARCHS}" STREQUAL "RAPIDS" OR "$ENV{CUDAARCHS}" STREQUAL + "ALL")) + set(cuda_arch_mode "RAPIDS") elseif(DEFINED ENV{CUDAARCHS} AND "$ENV{CUDAARCHS}" STREQUAL "NATIVE") set(cuda_arch_mode "NATIVE") - elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") - set(cuda_arch_mode "ALL") + elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "RAPIDS" OR CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") + set(cuda_arch_mode "RAPIDS") elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "" OR CMAKE_CUDA_ARCHITECTURES STREQUAL "NATIVE") set(cuda_arch_mode "NATIVE") elseif(NOT (DEFINED ENV{CUDAARCHS} OR DEFINED CMAKE_CUDA_ARCHITECTURES)) - set(cuda_arch_mode "ALL") + set(cuda_arch_mode "RAPIDS") endif() - # This needs to be run before enabling the CUDA language since RAPIDS supports the magic string of - # "ALL" - if(cuda_arch_mode STREQUAL "ALL") + # This needs to be run before enabling the CUDA language since RAPIDS supports magic values like + # `RAPIDS`, `ALL`, and `NATIVE` which if propagated cause CMake to fail to determine the CUDA + # compiler + if(cuda_arch_mode STREQUAL "RAPIDS") set(CMAKE_CUDA_ARCHITECTURES OFF PARENT_SCOPE) set(load_file "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/detail/invoke_set_all_architectures.cmake") elseif(cuda_arch_mode STREQUAL "NATIVE") diff --git a/rapids-cmake/cuda/set_architectures.cmake b/rapids-cmake/cuda/set_architectures.cmake index 47ff3f05..36342800 100644 --- a/rapids-cmake/cuda/set_architectures.cmake +++ b/rapids-cmake/cuda/set_architectures.cmake @@ -39,13 +39,7 @@ directly. .. note:: This is automatically called by :cmake:command:`rapids_cuda_init_architectures` -``NATIVE``: - When passed NATIVE as the first parameter will compile for all - GPU architectures present on the current machine. Requires that - the CUDA language be enabled for the current CMake project. - -``ALL``: - When passed ALL will compile for all supported RAPIDS GPU architectures +.. include:: supported_cuda_architectures_values.txt Result Variables ^^^^^^^^^^^^^^^^ @@ -66,7 +60,7 @@ function(rapids_cuda_set_architectures mode) list(REMOVE_ITEM supported_archs "90") endif() - if(${mode} STREQUAL "ALL") + if(${mode} STREQUAL "RAPIDS" OR ${mode} STREQUAL "ALL") # CMake architecture list entry of "80" means to build compute and sm. What we want is for the # newest arch only to build that way while the rest built only for sm. diff --git a/testing/cuda/CMakeLists.txt b/testing/cuda/CMakeLists.txt index 14f72543..ef02de8c 100644 --- a/testing/cuda/CMakeLists.txt +++ b/testing/cuda/CMakeLists.txt @@ -27,6 +27,8 @@ add_cmake_config_test( init_arch-existing-project-flags.cmake ) add_cmake_config_test( init_arch-native.cmake ) add_cmake_config_test( init_arch-native-via-empty-str ) add_cmake_config_test( init_arch-native-via-env.cmake ) +add_cmake_config_test( init_arch-rapids.cmake ) +add_cmake_config_test( init_arch-rapids-via-env.cmake ) add_cmake_config_test( init_arch-user.cmake ) add_cmake_config_test( init_arch-user-via-env.cmake ) @@ -37,3 +39,4 @@ add_cmake_config_test( set_arch-all.cmake ) add_cmake_config_test( set_arch-existing.cmake ) add_cmake_config_test( set_arch-invalid-mode.cmake ) add_cmake_config_test( set_arch-native.cmake ) +add_cmake_config_test( set_arch-rapids.cmake ) diff --git a/testing/cuda/init_arch-all-via-env.cmake b/testing/cuda/init_arch-all-via-env.cmake index dd573a0d..5d536a51 100644 --- a/testing/cuda/init_arch-all-via-env.cmake +++ b/testing/cuda/init_arch-all-via-env.cmake @@ -29,4 +29,4 @@ if(CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") endif() -include("${rapids-cmake-testing-dir}/cuda/validate-cuda-all.cmake") +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/init_arch-all-via-undef/CMakeLists.txt b/testing/cuda/init_arch-all-via-undef/CMakeLists.txt index e330111b..f91aa583 100644 --- a/testing/cuda/init_arch-all-via-undef/CMakeLists.txt +++ b/testing/cuda/init_arch-all-via-undef/CMakeLists.txt @@ -30,4 +30,4 @@ if(CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") message(FATAL_ERROR "rapids_cuda_init_architectures didn't init CUDA_ARCHITECTURES") endif() -include("${rapids-cmake-testing-dir}/cuda/validate-cuda-all.cmake") +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/init_arch-all.cmake b/testing/cuda/init_arch-all.cmake index e8eabfd3..fc2f9acd 100644 --- a/testing/cuda/init_arch-all.cmake +++ b/testing/cuda/init_arch-all.cmake @@ -29,4 +29,4 @@ if(CMAKE_CUDA_ARCHITECTURES STREQUAL "ALL") endif() -include("${rapids-cmake-testing-dir}/cuda/validate-cuda-all.cmake") +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/init_arch-rapids-via-env.cmake b/testing/cuda/init_arch-rapids-via-env.cmake new file mode 100644 index 00000000..71929e1f --- /dev/null +++ b/testing/cuda/init_arch-rapids-via-env.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# Copyright (c) 2022, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cuda/init_architectures.cmake) + + +set(ENV{CUDAARCHS} "RAPIDS") +rapids_cuda_init_architectures(rapids-project) +project(rapids-project LANGUAGES CUDA) + +if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES should exist after calling rapids_cuda_init_architectures()") +endif() + +if(CMAKE_CUDA_ARCHITECTURES STREQUAL "RAPIDS") + message(FATAL_ERROR "rapids_cuda_init_architectures didn't init CUDA_ARCHITECTURES") +endif() + + +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/init_arch-rapids.cmake b/testing/cuda/init_arch-rapids.cmake new file mode 100644 index 00000000..f425b47b --- /dev/null +++ b/testing/cuda/init_arch-rapids.cmake @@ -0,0 +1,32 @@ +#============================================================================= +# Copyright (c) 2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cuda/init_architectures.cmake) + + +set(CMAKE_CUDA_ARCHITECTURES "RAPIDS") +rapids_cuda_init_architectures(rapids-project) +project(rapids-project LANGUAGES CUDA) + +if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES should exist after calling rapids_cuda_init_architectures()") +endif() + +if(CMAKE_CUDA_ARCHITECTURES STREQUAL "RAPIDS") + message(FATAL_ERROR "rapids_cuda_init_architectures didn't init CUDA_ARCHITECTURES") +endif() + + +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/set_arch-all.cmake b/testing/cuda/set_arch-all.cmake index 60132d8f..0e4f48eb 100644 --- a/testing/cuda/set_arch-all.cmake +++ b/testing/cuda/set_arch-all.cmake @@ -21,4 +21,4 @@ if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES should exist after calling rapids_cuda_set_architectures()") endif() -include("${rapids-cmake-testing-dir}/cuda/validate-cuda-all.cmake") +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/set_arch-rapids.cmake b/testing/cuda/set_arch-rapids.cmake new file mode 100644 index 00000000..726bdfbe --- /dev/null +++ b/testing/cuda/set_arch-rapids.cmake @@ -0,0 +1,24 @@ +#============================================================================= +# Copyright (c) 2021, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= +include(${rapids-cmake-dir}/cuda/set_architectures.cmake) + +rapids_cuda_set_architectures(RAPIDS) + +if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES should exist after calling rapids_cuda_set_architectures()") +endif() + +include("${rapids-cmake-testing-dir}/cuda/validate-cuda-rapids.cmake") diff --git a/testing/cuda/validate-cuda-all.cmake b/testing/cuda/validate-cuda-rapids.cmake similarity index 100% rename from testing/cuda/validate-cuda-all.cmake rename to testing/cuda/validate-cuda-rapids.cmake