Skip to content

Commit 80d60df

Browse files
authored
[backport] Allow building with CCCL that's newer than CTK (dmlc#10624, dmlc#10633) (dmlc#10640)
1 parent 61e0371 commit 80d60df

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ if(USE_CUDA)
224224
add_subdirectory(${PROJECT_SOURCE_DIR}/gputreeshap)
225225

226226
find_package(CUDAToolkit REQUIRED)
227+
find_package(CCCL CONFIG)
228+
if(NOT CCCL_FOUND)
229+
message(STATUS "Standalone CCCL not found. Attempting to use CCCL from CUDA Toolkit...")
230+
find_package(CCCL CONFIG
231+
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
232+
if(NOT CCCL_FOUND)
233+
message(STATUS "Could not locate CCCL from CUDA Toolkit. Using Thrust and CUB from CUDA Toolkit...")
234+
find_package(libcudacxx CONFIG REQUIRED
235+
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
236+
find_package(CUB CONFIG REQUIRED
237+
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
238+
find_package(Thrust CONFIG REQUIRED
239+
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
240+
thrust_create_target(Thrust HOST CPP DEVICE CUDA)
241+
add_library(CCCL::CCCL INTERFACE IMPORTED GLOBAL)
242+
target_link_libraries(CCCL::CCCL INTERFACE libcudacxx::libcudacxx CUB::CUB Thrust)
243+
endif()
244+
endif()
227245
endif()
228246

229247
if(FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND

cmake/Utils.cmake

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,24 @@ function(xgboost_set_cuda_flags target)
108108
target_compile_definitions(${target} PRIVATE -DXGBOOST_USE_NVTX=1)
109109
endif()
110110

111+
# Use CCCL we find before CUDA Toolkit to make sure we get newer headers as intended
112+
# The CUDA Toolkit includes its own copy of CCCL that often lags the latest releases
113+
# (and would be picked up otherwise)
114+
if(BUILD_STATIC_LIB)
115+
# If the downstream user is statically linking with libxgboost, it needs to
116+
# explicitly link with CCCL and CUDA runtime.
117+
target_link_libraries(${target}
118+
PUBLIC CCCL::CCCL CUDA::cudart_static)
119+
else()
120+
# If the downstream user is dynamically linking with libxgboost, it does not
121+
# need to link with CCCL and CUDA runtime.
122+
target_link_libraries(${target}
123+
PRIVATE CCCL::CCCL CUDA::cudart_static)
124+
endif()
111125
target_compile_definitions(${target} PRIVATE -DXGBOOST_USE_CUDA=1)
112126
target_include_directories(
113127
${target} PRIVATE
114-
${xgboost_SOURCE_DIR}/gputreeshap
115-
${xgboost_SOURCE_DIR}/rabit/include
116-
${CUDAToolkit_INCLUDE_DIRS})
128+
${xgboost_SOURCE_DIR}/gputreeshap)
117129

118130
if(MSVC)
119131
target_compile_options(${target} PRIVATE
@@ -240,7 +252,6 @@ macro(xgboost_target_link_libraries target)
240252

241253
if(USE_CUDA)
242254
xgboost_set_cuda_flags(${target})
243-
target_link_libraries(${target} PUBLIC CUDA::cudart_static)
244255
endif()
245256

246257
if(PLUGIN_RMM)

tests/buildkite/build-cuda-with-rmm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ command_wrapper="tests/ci_build/ci_build.sh gpu_build_rockylinux8 --build-arg "`
2222

2323
echo "--- Build libxgboost from the source"
2424
$command_wrapper tests/ci_build/build_via_cmake.sh \
25-
-DCMAKE_PREFIX_PATH="/opt/grpc;/opt/rmm" \
25+
-DCMAKE_PREFIX_PATH="/opt/grpc;/opt/rmm;/opt/rmm/lib64/rapids/cmake" \
2626
-DUSE_CUDA=ON \
2727
-DUSE_OPENMP=ON \
2828
-DHIDE_CXX_SYMBOLS=ON \

0 commit comments

Comments
 (0)