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

Add rapids_cpm_cccl feature. #495

Merged
merged 15 commits into from
Dec 7, 2023
Merged
9 changes: 9 additions & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
}
},

"rapids_cpm_cccl": {
"pargs": {
"nargs": 2
},
"kwargs": {
"BUILD_EXPORT_SET": 1,
"INSTALL_EXPORT_SET": 1
}
},
"rapids_cpm_cuco": {
"pargs": {
"nargs": 0
Expand Down
8 changes: 3 additions & 5 deletions conda/recipes/rapids_core_dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#=============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,6 @@ include(${rapids-cmake-dir}/cpm/init.cmake)
rapids_cpm_init()

# Download all source packages
include(${rapids-cmake-dir}/cpm/libcudacxx.cmake)
include(${rapids-cmake-dir}/cpm/thrust.cmake)
include(${rapids-cmake-dir}/cpm/cccl.cmake)
set(CPM_DOWNLOAD_ALL "ON")
rapids_cpm_libcudacxx(INSTALL_EXPORT_SET rapids-dependencies)
rapids_cpm_thrust(NAMESPACE temp INSTALL_EXPORT_SET rapids-dependencies)
rapids_cpm_cccl(NAMESPACE temp INSTALL_EXPORT_SET rapids-dependencies)
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ package uses :ref:`can be found here. <cpm_versions>`
.. toctree::
:titlesonly:

/packages/rapids_cpm_cccl
/packages/rapids_cpm_cuco
/packages/rapids_cpm_fmt
/packages/rapids_cpm_gbench
Expand Down
1 change: 1 addition & 0 deletions docs/packages/rapids_cpm_cccl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cpm/cccl.cmake
136 changes: 136 additions & 0 deletions rapids-cmake/cpm/cccl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#=============================================================================
# Copyright (c) 2023, 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:
rapids_cpm_cccl
---------------

.. versionadded:: v24.02.00

Allow projects to find or build `CCCL` via `CPM` with built-in
tracking of these dependencies for correct export support.

Uses the version of CCCL :ref:`specified in the version file <cpm_versions>` for consistency
across all RAPIDS projects.

.. code-block:: cmake

rapids_cpm_cccl( NAMESPACE <namespace>
[BUILD_EXPORT_SET <export-name>]
[INSTALL_EXPORT_SET <export-name>]
[<CPM_ARGS> ...])

``NAMESPACE``
The namespace that the CCCL target will be constructed into.

.. |PKG_NAME| replace:: CCCL
.. include:: common_package_args.txt

# TODO How should this be updated for CCCL?
.. versionadded:: v23.12.00
When `BUILD_EXPORT_SET` is specified the generated build export set dependency
file will automatically call `thrust_create_target(<namespace>::Thrust FROM_OPTIONS)`.

When `INSTALL_EXPORT_SET` is specified the generated install export set dependency
file will automatically call `thrust_create_target(<namespace>::Thrust FROM_OPTIONS)`.

Result Targets
^^^^^^^^^^^^^^
<namespace>::CCCL target will be created

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`CCCL_SOURCE_DIR` is set to the path to the source directory of CCCL.
:cmake:variable:`CCCL_BINARY_DIR` is set to the path to the build directory of CCCL.
:cmake:variable:`CCCL_ADDED` is set to a true value if CCCL has not been added before.
:cmake:variable:`CCCL_VERSION` is set to the version of CCCL specified by the versions.json.

#]=======================================================================]
# cmake-lint: disable=R0915
function(rapids_cpm_cccl NAMESPACE namespaces_name)
bdice marked this conversation as resolved.
Show resolved Hide resolved
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cpm.cccl")

include("${rapids-cmake-dir}/cpm/detail/package_details.cmake")
rapids_cpm_package_details(CCCL version repository tag shallow exclude)

set(to_install OFF)
if(INSTALL_EXPORT_SET IN_LIST ARGN AND NOT exclude)
set(to_install ON)
# Make sure we install CCCL into the `include/rapids` subdirectory instead of the default
include(GNUInstallDirs)
set(CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/rapids")
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/rapids")
endif()

include("${rapids-cmake-dir}/cpm/detail/generate_patch_command.cmake")
rapids_cpm_generate_patch_command(CCCL ${version} patch_command)

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(CCCL ${version} ${ARGN}
GLOBAL_TARGETS ${namespaces_name}::CCCL
CPM_ARGS FIND_PACKAGE_ARGUMENTS EXACT
GIT_REPOSITORY ${repository}
GIT_TAG ${tag}
GIT_SHALLOW ${shallow}
PATCH_COMMAND ${patch_command}
EXCLUDE_FROM_ALL ${exclude}
OPTIONS "CCCL_ENABLE_INSTALL_RULES ${to_install}")

include("${rapids-cmake-dir}/cpm/detail/display_patch_status.cmake")
rapids_cpm_display_patch_status(CCCL)

set(options)
set(one_value BUILD_EXPORT_SET INSTALL_EXPORT_SET)
set(multi_value)
cmake_parse_arguments(_RAPIDS "${options}" "${one_value}" "${multi_value}" ${ARGN})

# TODO how to update this for CCCL?
bdice marked this conversation as resolved.
Show resolved Hide resolved
set(post_find_code "if(NOT TARGET ${namespaces_name}::Thrust)"
" thrust_create_target(${namespaces_name}::Thrust FROM_OPTIONS)" "endif()")

if(Thrust_SOURCE_DIR)
# Store where CMake can find the Thrust-config.cmake that comes part of Thrust source code
include("${rapids-cmake-dir}/export/find_package_root.cmake")
bdice marked this conversation as resolved.
Show resolved Hide resolved
include("${rapids-cmake-dir}/export/detail/post_find_package_code.cmake")
rapids_export_find_package_root(BUILD Thrust "${Thrust_SOURCE_DIR}/cmake"
EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
rapids_export_post_find_package_code(BUILD Thrust "${post_find_code}" EXPORT_SET
${_RAPIDS_BUILD_EXPORT_SET})

rapids_export_find_package_root(INSTALL Thrust
[=[${CMAKE_CURRENT_LIST_DIR}/../../rapids/cmake/thrust]=]
EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install)
rapids_export_post_find_package_code(INSTALL Thrust "${post_find_code}" EXPORT_SET
${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install)
endif()

# Check for the existence of thrust_create_target so we support fetching Thrust with DOWNLOAD_ONLY
if(NOT TARGET ${namespaces_name}::Thrust AND COMMAND thrust_create_target)
bdice marked this conversation as resolved.
Show resolved Hide resolved
thrust_create_target(${namespaces_name}::Thrust FROM_OPTIONS)
set_target_properties(${namespaces_name}::Thrust PROPERTIES IMPORTED_NO_SYSTEM ON)
if(TARGET _Thrust_Thrust)
set_target_properties(_Thrust_Thrust PROPERTIES IMPORTED_NO_SYSTEM ON)
endif()
endif()

# Propagate up variables that CPMFindPackage provides
set(CCCL_SOURCE_DIR "${CCCL_SOURCE_DIR}" PARENT_SCOPE)
set(CCCL_BINARY_DIR "${CCCL_BINARY_DIR}" PARENT_SCOPE)
set(CCCL_ADDED "${CCCL_ADDED}" PARENT_SCOPE)
set(CCCL_VERSION ${version} PARENT_SCOPE)

endfunction()
15 changes: 10 additions & 5 deletions rapids-cmake/cpm/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"git_url" : "https://github.com/google/benchmark.git",
"git_tag" : "v${version}"
},
"CCCL" : {
"version" : "2.2.0",
"git_url" : "https://github.com/NVIDIA/cccl.git",
"git_tag" : "v${version}"
},
"cuco" : {
"version" : "0.0.1",
"git_shallow" : false,
Expand Down Expand Up @@ -73,11 +78,11 @@
"git_url" : "https://github.com/gabime/spdlog.git",
"git_tag" : "v${version}",
"patches" : [
{
"file" : "spdlog/nvcc_constexpr_fix.diff",
"issue" : "Fix constexpr mismatch between spdlog and fmt [https://github.com/gabime/spdlog/issues/2856]",
"fixed_in" : "1.13"
}
{
"file" : "spdlog/nvcc_constexpr_fix.diff",
"issue" : "Fix constexpr mismatch between spdlog and fmt [https://github.com/gabime/spdlog/issues/2856]",
"fixed_in" : "1.13"
}
]
},
"Thrust" : {
Expand Down
3 changes: 3 additions & 0 deletions testing/cpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ add_cmake_config_test( cpm_generate_patch_command-invalid.cmake )
add_cmake_config_test( cpm_generate_patch_command-override.cmake )
add_cmake_config_test( cpm_generate_patch_command-current_json_dir.cmake )

add_cmake_config_test( cpm_cccl-simple.cmake )
add_cmake_config_test( cpm_cccl-export.cmake )

add_cmake_config_test( cpm_cuco-simple.cmake )
add_cmake_config_test( cpm_cuco-export.cmake )
add_cmake_config_test( cpm_cuco-libcudacxx-no-install-export.cmake )
Expand Down
32 changes: 32 additions & 0 deletions testing/cpm/cpm_cccl-export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#=============================================================================
# Copyright (c) 2023, 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}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/cccl.cmake)

rapids_cpm_init()

rapids_cpm_cccl(NAMESPACE A BUILD_EXPORT_SET test)
rapids_cpm_cccl(NAMESPACE B INSTALL_EXPORT_SET test2)

get_target_property(packages rapids_export_build_test PACKAGE_NAMES)
if(NOT CCCL IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_cccl failed to record CCCL needs to be exported")
endif()

get_target_property(packages rapids_export_install_test2 PACKAGE_NAMES)
if(NOT CCCL IN_LIST packages)
message(FATAL_ERROR "rapids_cpm_cccl failed to record CCCL needs to be exported")
endif()
41 changes: 41 additions & 0 deletions testing/cpm/cpm_cccl-simple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#=============================================================================
# Copyright (c) 2023, 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}/cpm/init.cmake)
include(${rapids-cmake-dir}/cpm/cccl.cmake)

rapids_cpm_init()

if(TARGET test::Thrust)
message(FATAL_ERROR "Expected test::Thrust not to exist")
endif()
if(TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx not to exist")
endif()

rapids_cpm_cccl(NAMESPACE test)
if(NOT TARGET test::Thrust)
message(FATAL_ERROR "Expected test::Thrust target to exist")
endif()
if(NOT TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx target to exist")
endif()

rapids_cpm_cccl(NAMESPACE test)

rapids_cpm_cccl(NAMESPACE test2)
if(NOT TARGET test2::Thrust)
message(FATAL_ERROR "Expected test2::Thrust target to exist")
endif()
2 changes: 2 additions & 0 deletions testing/utils/fill_cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ project(fill_cache LANGUAGES CXX)

include(${rapids-cmake-dir}/cpm/init.cmake)

include(${rapids-cmake-dir}/cpm/cccl.cmake)
include(${rapids-cmake-dir}/cpm/cuco.cmake)
include(${rapids-cmake-dir}/cpm/gbench.cmake)
include(${rapids-cmake-dir}/cpm/gtest.cmake)
Expand All @@ -36,6 +37,7 @@ set(CPM_SOURCE_CACHE "${CMAKE_BINARY_DIR}")

# Download all source packages
set(CPM_DOWNLOAD_ALL "ON")
rapids_cpm_cccl(DOWNLOAD_ONLY ON)
rapids_cpm_cuco(DOWNLOAD_ONLY ON)
rapids_cpm_gbench(DOWNLOAD_ONLY ON)
rapids_cpm_gtest(DOWNLOAD_ONLY ON)
Expand Down
Loading