Skip to content

Commit

Permalink
Add rapids_cpm_cccl feature. (#495)
Browse files Browse the repository at this point in the history
This PR adds a new function `rapids_cpm_cccl` that adds CCCL from the new monorepo. This will eventually replace `rapids_cpm_thrust` and `rapids_cpm_libcudacxx`.

Authors:
  - Bradley Dice (https://github.com/bdice)
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Robert Maynard (https://github.com/robertmaynard)

URL: #495
  • Loading branch information
bdice authored Dec 7, 2023
1 parent 2969d42 commit c3b7afc
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 10 deletions.
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": 0
},
"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
119 changes: 119 additions & 0 deletions rapids-cmake/cpm/cccl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#=============================================================================
# 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.

When `BUILD_EXPORT_SET` is specified the generated build export set dependency
file will automatically call `thrust_create_target(CCCL::Thrust FROM_OPTIONS)`.

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

.. code-block:: cmake

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

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

Result Targets
^^^^^^^^^^^^^^
CCCL::CCCL target will be created
CCCL::Thrust target will be created
CCCL::libcudacxx target will be created
CCCL::CUB target will be created
libcudacxx::libcudacxx 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)
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)

# Ensure for CMake 3.24+ that the CCCL::Thrust target exists:
# https://github.com/NVIDIA/cccl/pull/1182
set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL ON)

include("${rapids-cmake-dir}/cpm/find.cmake")
rapids_cpm_find(CCCL ${version} ${ARGN}
GLOBAL_TARGETS CCCL CCCL::CCCL CCCL::Thrust CCCL::CUB CCCL::libcudacxx
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})

if(CCCL_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")
rapids_export_find_package_root(BUILD CCCL "${CCCL_SOURCE_DIR}/cmake"
EXPORT_SET ${_RAPIDS_BUILD_EXPORT_SET})
rapids_export_find_package_root(INSTALL CCCL
[=[${CMAKE_CURRENT_LIST_DIR}/../../rapids/cmake/cccl]=]
EXPORT_SET ${_RAPIDS_INSTALL_EXPORT_SET} CONDITION to_install)
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(BUILD_EXPORT_SET test)
rapids_cpm_cccl(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()
54 changes: 54 additions & 0 deletions testing/cpm/cpm_cccl-simple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#=============================================================================
# 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 CCCL::CCCL)
message(FATAL_ERROR "Expected CCCL::CUB not to exist")
endif()
if(TARGET CCCL::CUB)
message(FATAL_ERROR "Expected CCCL::CUB not to exist")
endif()
if(TARGET CCCL::libcudacxx)
message(FATAL_ERROR "Expected CCCL::libcudacxx not to exist")
endif()
if(TARGET CCCL::Thrust)
message(FATAL_ERROR "Expected CCCL::Thrust not to exist")
endif()
if(TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx not to exist")
endif()

rapids_cpm_cccl()
if(NOT TARGET CCCL::CCCL)
message(FATAL_ERROR "Expected CCCL::CUB target to exist")
endif()
if(NOT TARGET CCCL::CUB)
message(FATAL_ERROR "Expected CCCL::CUB target to exist")
endif()
if(NOT TARGET CCCL::libcudacxx)
message(FATAL_ERROR "Expected CCCL::libcudacxx target to exist")
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0 AND NOT TARGET CCCL::Thrust)
message(FATAL_ERROR "Expected CCCL::Thrust target to exist")
endif()
if(NOT TARGET libcudacxx::libcudacxx)
message(FATAL_ERROR "Expected libcudacxx::libcudacxx target to exist")
endif()

rapids_cpm_cccl()
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

0 comments on commit c3b7afc

Please sign in to comment.