From 8f1a4bc09d70a0f1ec9f3daa73584e1520b0dd44 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Dec 2022 13:25:47 -0500 Subject: [PATCH 1/5] rapids_cuda_init_architectures now supports "RAPIDS" value Fixes #314 --- .../detail/invoke_set_all_architectures.cmake | 2 +- rapids-cmake/cuda/init_architectures.cmake | 14 ++++---- rapids-cmake/cuda/set_architectures.cmake | 6 ++-- testing/cuda/CMakeLists.txt | 3 ++ testing/cuda/init_arch-all-via-env.cmake | 2 +- .../init_arch-all-via-undef/CMakeLists.txt | 2 +- testing/cuda/init_arch-all.cmake | 2 +- testing/cuda/init_arch-rapids-via-env.cmake | 32 +++++++++++++++++++ testing/cuda/init_arch-rapids.cmake | 32 +++++++++++++++++++ testing/cuda/set_arch-all.cmake | 2 +- testing/cuda/set_arch-rapids.cmake | 24 ++++++++++++++ ...a-all.cmake => validate-cuda-rapids.cmake} | 0 12 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 testing/cuda/init_arch-rapids-via-env.cmake create mode 100644 testing/cuda/init_arch-rapids.cmake create mode 100644 testing/cuda/set_arch-rapids.cmake rename testing/cuda/{validate-cuda-all.cmake => validate-cuda-rapids.cmake} (100%) 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..ee2de46f 100644 --- a/rapids-cmake/cuda/init_architectures.cmake +++ b/rapids-cmake/cuda/init_architectures.cmake @@ -47,7 +47,7 @@ CUDA architectures to be compiled for. Parses the :cmake:envvar:`CUDAARCHS ` will compile for all GPU architectures present on the current machine. -``ALL`` or no :cmake:variable:`CMAKE_CUDA_ARCHITECTURES ` and +``RAPIDS``, ``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. @@ -79,21 +79,21 @@ 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") + 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..5adabf99 100644 --- a/rapids-cmake/cuda/set_architectures.cmake +++ b/rapids-cmake/cuda/set_architectures.cmake @@ -44,8 +44,8 @@ directly. 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 +``RAPIDS``, or ``ALL``: + When passed RAPIDS or ALL, we will compile for all supported RAPIDS GPU architectures Result Variables ^^^^^^^^^^^^^^^^ @@ -66,7 +66,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 From 55e563619dd47f67e59391d07bc6db379920aba2 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Thu, 8 Dec 2022 16:49:25 -0500 Subject: [PATCH 2/5] improve docs around CMAKE_CUDA_ARCHITECTURES --- .../supported_cuda_architectures_values.txt | 7 +++++++ rapids-cmake/cuda/init_architectures.cmake | 14 +++----------- rapids-cmake/cuda/set_architectures.cmake | 8 +------- 3 files changed, 11 insertions(+), 18 deletions(-) create mode 100644 docs/command/supported_cuda_architectures_values.txt 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/init_architectures.cmake b/rapids-cmake/cuda/init_architectures.cmake index ee2de46f..d337398f 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. - -``RAPIDS``, ``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`: diff --git a/rapids-cmake/cuda/set_architectures.cmake b/rapids-cmake/cuda/set_architectures.cmake index 5adabf99..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. - -``RAPIDS``, or ``ALL``: - When passed RAPIDS or ALL, we will compile for all supported RAPIDS GPU architectures +.. include:: supported_cuda_architectures_values.txt Result Variables ^^^^^^^^^^^^^^^^ From 9bd76e539bf2f83ea4c731835fb0ac772f9c1e5d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 9 Dec 2022 10:01:45 -0500 Subject: [PATCH 3/5] Correct style issues found by CI --- rapids-cmake/cuda/init_architectures.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rapids-cmake/cuda/init_architectures.cmake b/rapids-cmake/cuda/init_architectures.cmake index d337398f..ab238618 100644 --- a/rapids-cmake/cuda/init_architectures.cmake +++ b/rapids-cmake/cuda/init_architectures.cmake @@ -71,7 +71,8 @@ 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 "RAPIDS" OR "$ENV{CUDAARCHS}" STREQUAL "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") From 9df2f106fd28ab6cba3f6266087eaaf8e79668fc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 13 Dec 2022 09:17:49 -0500 Subject: [PATCH 4/5] Update comment around why we disable CMAKE_CUDA_ARCHITECTURES in init --- rapids-cmake/cuda/init_architectures.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rapids-cmake/cuda/init_architectures.cmake b/rapids-cmake/cuda/init_architectures.cmake index ab238618..b860db53 100644 --- a/rapids-cmake/cuda/init_architectures.cmake +++ b/rapids-cmake/cuda/init_architectures.cmake @@ -84,8 +84,9 @@ function(rapids_cuda_init_architectures project_name) set(cuda_arch_mode "RAPIDS") endif() - # This needs to be run before enabling the CUDA language since RAPIDS supports the magic string of - # "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") From b33a3ba2abc431adc3cfa17168dbc36a95031801 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 13 Dec 2022 09:23:16 -0500 Subject: [PATCH 5/5] Correct style issues found by CI --- rapids-cmake/cuda/init_architectures.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rapids-cmake/cuda/init_architectures.cmake b/rapids-cmake/cuda/init_architectures.cmake index b860db53..53f17eae 100644 --- a/rapids-cmake/cuda/init_architectures.cmake +++ b/rapids-cmake/cuda/init_architectures.cmake @@ -84,9 +84,9 @@ function(rapids_cuda_init_architectures project_name) set(cuda_arch_mode "RAPIDS") endif() - # 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 + # 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")