Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fea/support cmake cuda architectures rapids value #327

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/command/supported_cuda_architectures_values.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

``NATIVE`` or ``""``:
When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <cmake:variable:CMAKE_CUDA_ARCHITECTURES>` or :cmake:envvar:`ENV{CUDAARCHS} <cmake:envvar:CUDAARCHS>`
will compile for all GPU architectures present on the current machine.

``RAPIDS``, ``ALL``, or no value in :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <cmake:variable:CMAKE_CUDA_ARCHITECTURES>` and :cmake:envvar:`ENV{CUDAARCHS} <cmake:envvar:CUDAARCHS>`:
When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <cmake:variable:CMAKE_CUDA_ARCHITECTURES>` or :cmake:envvar:`ENV{CUDAARCHS} <cmake:envvar:CUDAARCHS>` will compile for all supported RAPIDS GPU architectures.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 13 additions & 19 deletions rapids-cmake/cuda/init_architectures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ to include support for `ALL` and `NATIVE` to make CUDA architecture compilation
rapids_cuda_init_architectures(<project_name>)

Used before enabling the CUDA language either via :cmake:command:`project() <cmake:command:project>` to establish the
CUDA architectures to be compiled for. Parses the :cmake:envvar:`CUDAARCHS <cmake:envvar:CUDAARCHS>`, and
CUDA architectures to be compiled for. Parses the :cmake:envvar:`ENV{CUDAARCHS} <cmake:envvar:CUDAARCHS>`, and
:cmake:variable:`CMAKE_CUDA_ARCHITECTURES <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() <cmake:command:project>` call.
Expand All @@ -43,15 +43,7 @@ CUDA architectures to be compiled for. Parses the :cmake:envvar:`CUDAARCHS <cmak
``project_name``
Name of the project in the subsequent :cmake:command:`project() <cmake:command:project>` call.

``NATIVE`` or ``""``:
When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <cmake:variable:CMAKE_CUDA_ARCHITECTURES>`
will compile for all GPU architectures present on the current machine.

``ALL`` or no :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <cmake:variable:CMAKE_CUDA_ARCHITECTURES>` and
:cmake:envvar:`ENV{CUDAARCHS} <cmake:envvar:CUDAARCHS>`:
When passed as the value for :cmake:variable:`CMAKE_CUDA_ARCHITECTURES <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`:

Expand Down Expand Up @@ -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")
Expand Down
10 changes: 2 additions & 8 deletions rapids-cmake/cuda/set_architectures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions testing/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand All @@ -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 )
2 changes: 1 addition & 1 deletion testing/cuda/init_arch-all-via-env.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion testing/cuda/init_arch-all-via-undef/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion testing/cuda/init_arch-all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
32 changes: 32 additions & 0 deletions testing/cuda/init_arch-rapids-via-env.cmake
Original file line number Diff line number Diff line change
@@ -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")
32 changes: 32 additions & 0 deletions testing/cuda/init_arch-rapids.cmake
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion testing/cuda/set_arch-all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
24 changes: 24 additions & 0 deletions testing/cuda/set_arch-rapids.cmake
Original file line number Diff line number Diff line change
@@ -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")