From b43b36c8547fe25d90d22870e091d0aa0c26ade9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 2 Sep 2022 16:52:27 -0400 Subject: [PATCH 1/2] Introduce rapids_cuda_patch_toolkit Allows rapids-cmake patch CUDAToolkit to fix missing cublas and cusolver dependencies. https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7633 --- README.md | 1 + docs/api.rst | 1 + docs/command/rapids_cuda_patch_toolkit.rst | 1 + rapids-cmake/cuda/patch_toolkit.cmake | 52 +++++++++++++++++++ rapids-cmake/find/package.cmake | 5 ++ testing/cuda/CMakeLists.txt | 4 +- .../cuda/patch_toolkit-nested/CMakeLists.txt | 40 ++++++++++++++ .../subdir/CMakeLists.txt | 28 ++++++++++ testing/cuda/patch_toolkit.cmake | 37 +++++++++++++ testing/find/CMakeLists.txt | 2 + .../find_package-cudatoolkit-patching.cmake | 33 ++++++++++++ 11 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 docs/command/rapids_cuda_patch_toolkit.rst create mode 100644 rapids-cmake/cuda/patch_toolkit.cmake create mode 100644 testing/cuda/patch_toolkit-nested/CMakeLists.txt create mode 100644 testing/cuda/patch_toolkit-nested/subdir/CMakeLists.txt create mode 100644 testing/cuda/patch_toolkit.cmake create mode 100644 testing/find/find_package-cudatoolkit-patching.cmake diff --git a/README.md b/README.md index 1ca6053e..92a8fc81 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ The most commonly used function are: - `rapids_cuda_init_architectures()` handles initialization of `CMAKE_CUDA_ARCHITECTURE`. MUST BE CALLED BEFORE `PROJECT()` - `rapids_cuda_init_runtime()` handles initialization of `CMAKE_CUDA_RUNTIME_LIBRARY`. +- `rapids_cuda_patch_toolkit()` corrects bugs in the CUDAToolkit module that are being upstreamed. ### cython diff --git a/docs/api.rst b/docs/api.rst index 2bb18497..5383108e 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -95,6 +95,7 @@ require. rapids_cuda_init_architectures rapids_cuda_init_runtime rapids_cuda_set_architectures [Advanced] + rapids_cuda_patch_toolkit Export Set Generation diff --git a/docs/command/rapids_cuda_patch_toolkit.rst b/docs/command/rapids_cuda_patch_toolkit.rst new file mode 100644 index 00000000..ad49a11e --- /dev/null +++ b/docs/command/rapids_cuda_patch_toolkit.rst @@ -0,0 +1 @@ +.. cmake-module:: ../../rapids-cmake/cuda/patch_toolkit.cmake diff --git a/rapids-cmake/cuda/patch_toolkit.cmake b/rapids-cmake/cuda/patch_toolkit.cmake new file mode 100644 index 00000000..da0b6842 --- /dev/null +++ b/rapids-cmake/cuda/patch_toolkit.cmake @@ -0,0 +1,52 @@ +#============================================================================= +# 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_guard(GLOBAL) + +#[=======================================================================[.rst: + +--------------------------------- + +.. versionadded:: v22.10.00 + +Corrects missing dependencies in the CUDA toolkit + + .. code-block:: cmake + + rapids_cuda_patch_toolkit( ) + +For CMake versions 3.23.1-3, and 3.24.1 the dependencies +of cublas and cusolver targets are incorrect. This module must be called +from the same CMakeLists.txt as the first `find_project(CUDAToolkit)` to +patch the targets. + +.. note:: + :cmake:command:`rapids_cpm_find` will automatically call this module + when asked to find the CUDAToolkit. + +#]=======================================================================] +function(rapids_cuda_patch_toolkit) + list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cuda.patch_toolkit") + + get_directory_property(itargets IMPORTED_TARGETS) + if(CUDA::cublas_static IN_LIST itargets) + target_link_libraries(CUDA::cublas INTERFACE CUDA::cublasLt) + target_link_libraries(CUDA::cusparse INTERFACE CUDA::cublas) + + target_link_libraries(CUDA::cublas_static INTERFACE CUDA::cublasLt_static) + target_link_libraries(CUDA::cusolver_static INTERFACE CUDA::cusolver_lapack_static) + target_link_libraries(CUDA::cusparse_static INTERFACE CUDA::cublas_static) + endif() +endfunction() diff --git a/rapids-cmake/find/package.cmake b/rapids-cmake/find/package.cmake index 03dd183e..d1f26c05 100644 --- a/rapids-cmake/find/package.cmake +++ b/rapids-cmake/find/package.cmake @@ -122,6 +122,11 @@ macro(rapids_find_package name) # OPTIONAL find packages if(${${name}_FOUND}) + if(${name} STREQUAL "CUDAToolkit") + include("${rapids-cmake-dir}/cuda/patch_toolkit.cmake") + rapids_cuda_patch_toolkit() + endif() + set(_rapids_extra_info) if(_RAPIDS_GLOBAL_TARGETS) list(APPEND _rapids_extra_info "GLOBAL_TARGETS" ${_RAPIDS_GLOBAL_TARGETS}) diff --git a/testing/cuda/CMakeLists.txt b/testing/cuda/CMakeLists.txt index 08dffd35..061b640d 100644 --- a/testing/cuda/CMakeLists.txt +++ b/testing/cuda/CMakeLists.txt @@ -27,8 +27,10 @@ add_cmake_config_test( init_arch-native.cmake ) add_cmake_config_test( init_arch-native-via-empty-str ) add_cmake_config_test( init_arch-user.cmake ) +add_cmake_config_test( patch_toolkit.cmake ) +add_cmake_config_test( patch_toolkit-nested ) + 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 ) - diff --git a/testing/cuda/patch_toolkit-nested/CMakeLists.txt b/testing/cuda/patch_toolkit-nested/CMakeLists.txt new file mode 100644 index 00000000..1eb91344 --- /dev/null +++ b/testing/cuda/patch_toolkit-nested/CMakeLists.txt @@ -0,0 +1,40 @@ +#============================================================================= +# 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. +#============================================================================= + +cmake_minimum_required(VERSION 3.23.1) +project(rapids-project LANGUAGES CUDA) + +include(${rapids-cmake-dir}/cuda/patch_toolkit.cmake) + +function(verify_links_to target library) + get_target_property(link_libs ${target} INTERFACE_LINK_LIBRARIES) + if(NOT ${library} IN_LIST link_libs) + message(FATAL_ERROR "${target} doesn't link to ${library}") + endif() +endfunction() + +find_package(CUDAToolkit) +rapids_cuda_patch_toolkit() + +add_subdirectory(subdir) + +if(TARGET CUDA::cublas_static) + verify_links_to(CUDA::cublas CUDA::cublasLt) + verify_links_to(CUDA::cusparse CUDA::cublas) + verify_links_to(CUDA::cublas_static CUDA::cublasLt_static) + verify_links_to(CUDA::cusparse_static CUDA::cublas_static) + verify_links_to(CUDA::cusolver_static CUDA::cusolver_lapack_static) +endif() diff --git a/testing/cuda/patch_toolkit-nested/subdir/CMakeLists.txt b/testing/cuda/patch_toolkit-nested/subdir/CMakeLists.txt new file mode 100644 index 00000000..4cb8ad18 --- /dev/null +++ b/testing/cuda/patch_toolkit-nested/subdir/CMakeLists.txt @@ -0,0 +1,28 @@ +#============================================================================= +# 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/patch_toolkit.cmake) + +rapids_cuda_patch_toolkit() +find_package(CUDAToolkit) +rapids_cuda_patch_toolkit() + +if(TARGET CUDA::cublas_static) + verify_links_to(CUDA::cublas CUDA::cublasLt) + verify_links_to(CUDA::cusparse CUDA::cublas) + verify_links_to(CUDA::cublas_static CUDA::cublasLt_static) + verify_links_to(CUDA::cusparse_static CUDA::cublas_static) + verify_links_to(CUDA::cusolver_static CUDA::cusolver_lapack_static) +endif() diff --git a/testing/cuda/patch_toolkit.cmake b/testing/cuda/patch_toolkit.cmake new file mode 100644 index 00000000..0e60c53a --- /dev/null +++ b/testing/cuda/patch_toolkit.cmake @@ -0,0 +1,37 @@ +#============================================================================= +# 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/patch_toolkit.cmake) + +function(verify_links_to target library) + get_target_property(link_libs ${target} INTERFACE_LINK_LIBRARIES) + if(NOT ${library} IN_LIST link_libs) + message(FATAL_ERROR "${target} doesn't link to ${library}") + endif() +endfunction() + +# Verify we can call before find_package +rapids_cuda_patch_toolkit() + +find_package(CUDAToolkit) +rapids_cuda_patch_toolkit() + +if(TARGET CUDA::cublas_static) + verify_links_to(CUDA::cublas CUDA::cublasLt) + verify_links_to(CUDA::cusparse CUDA::cublas) + verify_links_to(CUDA::cublas_static CUDA::cublasLt_static) + verify_links_to(CUDA::cusparse_static CUDA::cublas_static) + verify_links_to(CUDA::cusolver_static CUDA::cusolver_lapack_static) +endif() diff --git a/testing/find/CMakeLists.txt b/testing/find/CMakeLists.txt index 635884b1..f6f080e1 100644 --- a/testing/find/CMakeLists.txt +++ b/testing/find/CMakeLists.txt @@ -20,6 +20,8 @@ add_cmake_config_test( find_package-no-variable-leak.cmake ) add_cmake_config_test( find_package-build.cmake ) add_cmake_config_test( find_package-install.cmake ) +add_cmake_config_test( find_package-cudatoolkit-patching.cmake ) + # The inverse of `find_package-optional-failed` is the # above two tests. # The inverse of `find_package-required-found` is always diff --git a/testing/find/find_package-cudatoolkit-patching.cmake b/testing/find/find_package-cudatoolkit-patching.cmake new file mode 100644 index 00000000..0fae511f --- /dev/null +++ b/testing/find/find_package-cudatoolkit-patching.cmake @@ -0,0 +1,33 @@ +#============================================================================= +# 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}/find/package.cmake) + +function(verify_links_to target library) + get_target_property(link_libs ${target} INTERFACE_LINK_LIBRARIES) + if(NOT ${library} IN_LIST link_libs) + message(FATAL_ERROR "${target} doesn't link to ${library}") + endif() +endfunction() + +rapids_find_package(CUDAToolkit) + +if(TARGET CUDA::cublas_static) + verify_links_to(CUDA::cublas CUDA::cublasLt) + verify_links_to(CUDA::cusparse CUDA::cublas) + verify_links_to(CUDA::cublas_static CUDA::cublasLt_static) + verify_links_to(CUDA::cusparse_static CUDA::cublas_static) + verify_links_to(CUDA::cusolver_static CUDA::cusolver_lapack_static) +endif() From 1964f5dbfa9f30c2ad8d918d2e61d899d5c3c5cc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 6 Sep 2022 16:09:58 -0400 Subject: [PATCH 2/2] correct ordering of commands in docs --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index 5383108e..1ee07376 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -94,8 +94,8 @@ require. rapids_cuda_init_architectures rapids_cuda_init_runtime - rapids_cuda_set_architectures [Advanced] rapids_cuda_patch_toolkit + rapids_cuda_set_architectures [Advanced] Export Set Generation