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

Introduce rapids_cuda_patch_toolkit #260

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The most commonly used function are:

- `rapids_cuda_init_architectures(<project_name>)` handles initialization of `CMAKE_CUDA_ARCHITECTURE`. MUST BE CALLED BEFORE `PROJECT()`
- `rapids_cuda_init_runtime(<mode>)` handles initialization of `CMAKE_CUDA_RUNTIME_LIBRARY`.
- `rapids_cuda_patch_toolkit()` corrects bugs in the CUDAToolkit module that are being upstreamed.

### cython

Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require.
rapids_cuda_init_architectures </command/rapids_cuda_init_architectures>
rapids_cuda_init_runtime </command/rapids_cuda_init_runtime>
rapids_cuda_set_architectures [Advanced] </command/rapids_cuda_set_architectures>
rapids_cuda_patch_toolkit </command/rapids_cuda_patch_toolkit>


Export Set Generation
Expand Down
1 change: 1 addition & 0 deletions docs/command/rapids_cuda_patch_toolkit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cuda/patch_toolkit.cmake
52 changes: 52 additions & 0 deletions rapids-cmake/cuda/patch_toolkit.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions rapids-cmake/find/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 3 additions & 1 deletion testing/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

40 changes: 40 additions & 0 deletions testing/cuda/patch_toolkit-nested/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions testing/cuda/patch_toolkit-nested/subdir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
37 changes: 37 additions & 0 deletions testing/cuda/patch_toolkit.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions testing/find/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions testing/find/find_package-cudatoolkit-patching.cmake
Original file line number Diff line number Diff line change
@@ -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()