Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 9065dda

Browse files
committed
WIP: Prep for libcudacxx dependency.
1 parent 5159454 commit 9065dda

File tree

4 files changed

+135
-55
lines changed

4 files changed

+135
-55
lines changed

cmake/ThrustInstallRules.cmake

+29-20
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,35 @@ configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in"
2323
install(FILES "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake"
2424
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust")
2525

26-
# Depending on how Thrust is configured, CUB's CMake scripts may or may not be
27-
# included, so maintain a set of CUB install rules in both projects. By default
28-
# CUB headers are installed alongside Thrust -- this may be disabled by turning
29-
# off THRUST_INSTALL_CUB_HEADERS.
30-
option(THRUST_INSTALL_CUB_HEADERS "Include cub headers when installing." ON)
26+
# Depending on how Thrust is configured, libcudacxx and CUB's CMake scripts may
27+
# or may not be include()'d, so force include their install rules when requested.
28+
# By default, these projects are installed alongside Thrust. This is controlled by
29+
# THRUST_INSTALL_CUB_HEADERS and THRUST_INSTALL_LIBCUDACXX_HEADERS.
30+
option(THRUST_INSTALL_CUB_HEADERS "Include CUB headers when installing." ON)
3131
if (THRUST_INSTALL_CUB_HEADERS)
32-
install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub"
33-
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
34-
FILES_MATCHING
35-
PATTERN "*.cuh"
36-
)
32+
# Use a function to limit scope of the CUB_*_DIR vars:
33+
function(_thrust_install_cub_headers)
34+
# Fake these for the logic in CUBInstallRules.cmake:
35+
set(CUB_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/cub/")
36+
set(CUB_BINARY_DIR "${Thrust_BINARY_DIR}/cub-config/")
37+
set(CUB_ENABLE_INSTALL_RULES ON)
38+
set(CUB_IN_THRUST OFF)
39+
include("${Thrust_SOURCE_DIR}/dependencies/cub/cmake/CubInstallRules.cmake")
40+
endfunction()
3741

38-
# Need to configure a file to store THRUST_INSTALL_HEADER_INFIX
39-
install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/"
40-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub"
41-
PATTERN cub-header-search EXCLUDE
42-
)
43-
configure_file("${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake.in"
44-
"${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake"
45-
@ONLY)
46-
install(FILES "${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake"
47-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub")
42+
_thrust_install_cub_headers()
43+
endif()
44+
45+
option(THRUST_INSTALL_LIBCUDACXX_HEADERS "Include libcudacxx headers when installing." ON)
46+
if (THRUST_INSTALL_LIBCUDACXX_HEADERS)
47+
# Use a function to limit scope of the libcudacxx_*_DIR vars:
48+
function(_thrust_install_libcudacxx_headers)
49+
# Fake these for the logic in libcudacxxInstallRules.cmake:
50+
set(libcudacxx_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/libcudacxx/")
51+
set(libcudacxx_BINARY_DIR "${Thrust_BINARY_DIR}/libcudacxx-config/")
52+
set(libcudacxx_ENABLE_INSTALL_RULES ON)
53+
include("${Thrust_SOURCE_DIR}/dependencies/libcudacxx/cmake/libcudacxxInstallRules.cmake")
54+
endfunction()
55+
56+
_thrust_install_libcudacxx_headers()
4857
endif()

dependencies/libcudacxx

Submodule libcudacxx updated 56 files

thrust/cmake/thrust-config.cmake

+104-33
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
# [ADVANCED] # Optionally mark options as advanced
3838
# )
3939
#
40-
# # Use a custom TBB, CUB, and/or OMP
40+
# # Use a custom TBB, CUB, libcudacxx, and/or OMP
4141
# # (Note that once set, these cannot be changed. This includes COMPONENT
4242
# # preloading and lazy lookups in thrust_create_target)
4343
# find_package(Thrust REQUIRED)
4444
# thrust_set_CUB_target(MyCUBTarget) # MyXXXTarget contains an existing
4545
# thrust_set_TBB_target(MyTBBTarget) # interface to XXX for Thrust to use.
46+
# thrust_set_libcudacxx_target(MyLibcudacxxTarget)
4647
# thrust_set_OMP_target(MyOMPTarget)
47-
# thrust_create_target(ThrustWithMyCUB DEVICE CUDA)
48+
# thrust_create_target(ThrustWithMyCUBAndLibcudacxx DEVICE CUDA)
4849
# thrust_create_target(ThrustWithMyTBB DEVICE TBB)
4950
# thrust_create_target(ThrustWithMyOMP DEVICE OMP)
5051
#
@@ -77,6 +78,9 @@
7778

7879
cmake_minimum_required(VERSION 3.15)
7980

81+
# Minimum libcudacxx version:
82+
set(thrust_libcudacxx_version 999.0.0) # FIXME: Change this to a real version once we have one that works.
83+
8084
################################################################################
8185
# User variables and APIs. Users can rely on these:
8286
#
@@ -85,19 +89,21 @@ cmake_minimum_required(VERSION 3.15)
8589
set(THRUST_HOST_SYSTEM_OPTIONS
8690
CPP OMP TBB
8791
CACHE INTERNAL "Valid Thrust host systems."
92+
FORCE
8893
)
8994
set(THRUST_DEVICE_SYSTEM_OPTIONS
9095
CUDA CPP OMP TBB
9196
CACHE INTERNAL "Valid Thrust device systems"
97+
FORCE
9298
)
9399

94100
# Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
95-
set(THRUST_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} CACHE INTERNAL "")
96-
set(THRUST_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MAJOR} CACHE INTERNAL "")
97-
set(THRUST_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL "")
98-
set(THRUST_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "")
99-
set(THRUST_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "")
100-
set(THRUST_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "")
101+
set(THRUST_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} CACHE INTERNAL "" FORCE)
102+
set(THRUST_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MAJOR} CACHE INTERNAL "" FORCE)
103+
set(THRUST_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL "" FORCE)
104+
set(THRUST_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "" FORCE)
105+
set(THRUST_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "" FORCE)
106+
set(THRUST_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "" FORCE)
101107

102108
function(thrust_create_target target_name)
103109
thrust_debug("Assembling target ${target_name}. Options: ${ARGN}" internal)
@@ -109,21 +115,21 @@ function(thrust_create_target target_name)
109115
IGNORE_DEPRECATED_COMPILER
110116
IGNORE_DEPRECATED_CPP_11
111117
IGNORE_DEPRECATED_CPP_DIALECT
112-
)
118+
)
113119
set(keys
114120
DEVICE
115121
DEVICE_OPTION
116122
DEVICE_OPTION_DOC
117123
HOST
118124
HOST_OPTION
119125
HOST_OPTION_DOC
120-
)
126+
)
121127
cmake_parse_arguments(TCT "${options}" "${keys}" "" ${ARGN})
122128
if (TCT_UNPARSED_ARGUMENTS)
123129
message(AUTHOR_WARNING
124130
"Unrecognized arguments passed to thrust_create_target: "
125131
${TCT_UNPARSED_ARGUMENTS}
126-
)
132+
)
127133
endif()
128134

129135
# Check that the main Thrust internal target is available
@@ -133,7 +139,7 @@ function(thrust_create_target target_name)
133139
message(AUTHOR_WARNING
134140
"The `thrust_create_target` function was called outside the scope of the "
135141
"thrust targets. Call find_package again to recreate targets."
136-
)
142+
)
137143
endif()
138144

139145
_thrust_set_if_undefined(TCT_HOST CPP)
@@ -145,12 +151,14 @@ function(thrust_create_target target_name)
145151

146152
if (NOT TCT_HOST IN_LIST THRUST_HOST_SYSTEM_OPTIONS)
147153
message(FATAL_ERROR
148-
"Requested HOST=${TCT_HOST}; must be one of ${THRUST_HOST_SYSTEM_OPTIONS}")
154+
"Requested HOST=${TCT_HOST}; must be one of ${THRUST_HOST_SYSTEM_OPTIONS}"
155+
)
149156
endif()
150157

151158
if (NOT TCT_DEVICE IN_LIST THRUST_DEVICE_SYSTEM_OPTIONS)
152159
message(FATAL_ERROR
153-
"Requested DEVICE=${TCT_DEVICE}; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS}")
160+
"Requested DEVICE=${TCT_DEVICE}; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS}"
161+
)
154162
endif()
155163

156164
if (TCT_FROM_OPTIONS)
@@ -172,7 +180,7 @@ function(thrust_create_target target_name)
172180

173181
# We can just create an INTERFACE IMPORTED target here instead of going
174182
# through _thrust_declare_interface_alias as long as we aren't hanging any
175-
# Thrust/CUB include paths on ${target_name}.
183+
# Thrust/CUB include paths directly on ${target_name}.
176184
add_library(${target_name} INTERFACE IMPORTED)
177185
target_link_libraries(${target_name}
178186
INTERFACE
@@ -346,14 +354,17 @@ function(thrust_debug_internal_targets)
346354

347355
_thrust_debug_backend_targets(CPP "Thrust ${THRUST_VERSION}")
348356

349-
_thrust_debug_backend_targets(CUDA "CUB ${THRUST_CUB_VERSION}")
350-
thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION}")
357+
_thrust_debug_backend_targets(OMP "${THRUST_OMP_VERSION}")
358+
thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION}")
351359

352360
_thrust_debug_backend_targets(TBB "${THRUST_TBB_VERSION}")
353361
thrust_debug_target(TBB:tbb "${THRUST_TBB_VERSION}")
354362

355-
_thrust_debug_backend_targets(OMP "${THRUST_OMP_VERSION}")
356-
thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION}")
363+
_thrust_debug_backend_targets(CUDA
364+
"CUB ${THRUST_CUB_VERSION} libcudacxx ${THRUST_libcudacxx_VERSION}"
365+
)
366+
thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION}")
367+
thrust_debug_target(libcudacxx::libcudacxx "${THRUST_libcudacxx_VERSION}")
357368
endfunction()
358369

359370
################################################################################
@@ -434,18 +445,37 @@ function(_thrust_setup_system backend)
434445
endif()
435446
endfunction()
436447

437-
# Use the provided cub_target for the CUDA backend. If Thrust::CUDA already
448+
# Use the provided cub_target for the CUDA backend. If Thrust::CUB already
438449
# exists, this call has no effect.
439450
function(thrust_set_CUB_target cub_target)
440-
if (NOT TARGET Thrust::CUDA)
451+
if (NOT TARGET Thrust::CUB)
441452
thrust_debug("Setting CUB target to ${cub_target}" internal)
442453
# Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
443-
set(THRUST_CUB_VERSION ${CUB_VERSION} CACHE INTERNAL "CUB version used by Thrust")
444-
_thrust_declare_interface_alias(Thrust::CUDA _Thrust_CUDA)
445-
target_link_libraries(_Thrust_CUDA INTERFACE Thrust::Thrust ${cub_target})
454+
set(THRUST_CUB_VERSION ${CUB_VERSION} CACHE INTERNAL
455+
"CUB version used by Thrust"
456+
FORCE
457+
)
458+
_thrust_declare_interface_alias(Thrust::CUB _Thrust_CUB)
459+
target_link_libraries(_Thrust_CUB INTERFACE ${cub_target})
446460
thrust_debug_target(${cub_target} "${THRUST_CUB_VERSION}" internal)
447-
thrust_debug_target(Thrust::CUDA "CUB ${THRUST_CUB_VERSION}" internal)
448-
_thrust_setup_system(CUDA)
461+
thrust_debug_target(Thrust::CUB "CUB ${THRUST_CUB_VERSION}" internal)
462+
endif()
463+
endfunction()
464+
465+
# Use the provided libcudacxx_target for the CUDA backend. If Thrust::libcudacxx
466+
# already exists, this call has no effect.
467+
function(thrust_set_libcudacxx_target libcudacxx_target)
468+
if (NOT TARGET Thrust::libcudacxx)
469+
thrust_debug("Setting libcudacxx target to ${libcudacxx_target}" internal)
470+
# Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
471+
set(THRUST_libcudacxx_VERSION ${libcudacxx_VERSION} CACHE INTERNAL
472+
"libcudacxx version used by Thrust"
473+
FORCE
474+
)
475+
_thrust_declare_interface_alias(Thrust::libcudacxx _Thrust_libcudacxx)
476+
target_link_libraries(_Thrust_libcudacxx INTERFACE ${libcudacxx_target})
477+
thrust_debug_target(${libcudacxx_target} "${THRUST_libcudacxx_VERSION}" internal)
478+
thrust_debug_target(Thrust::libcudacxx "libcudacxx ${THRUST_libcudacxx_VERSION}" internal)
449479
endif()
450480
endfunction()
451481

@@ -455,7 +485,10 @@ function(thrust_set_TBB_target tbb_target)
455485
if (NOT TARGET Thrust::TBB)
456486
thrust_debug("Setting TBB target to ${tbb_target}" internal)
457487
# Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
458-
set(THRUST_TBB_VERSION ${TBB_VERSION} CACHE INTERNAL "TBB version used by Thrust")
488+
set(THRUST_TBB_VERSION ${TBB_VERSION} CACHE INTERNAL
489+
"TBB version used by Thrust"
490+
FORCE
491+
)
459492
_thrust_declare_interface_alias(Thrust::TBB _Thrust_TBB)
460493
target_link_libraries(_Thrust_TBB INTERFACE Thrust::Thrust ${tbb_target})
461494
thrust_debug_target(${tbb_target} "${THRUST_TBB_VERSION}" internal)
@@ -470,7 +503,10 @@ function(thrust_set_OMP_target omp_target)
470503
if (NOT TARGET Thrust::OMP)
471504
thrust_debug("Setting OMP target to ${omp_target}" internal)
472505
# Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
473-
set(THRUST_OMP_VERSION ${OpenMP_CXX_VERSION} CACHE INTERNAL "OpenMP version used by Thrust")
506+
set(THRUST_OMP_VERSION ${OpenMP_CXX_VERSION} CACHE INTERNAL
507+
"OpenMP version used by Thrust"
508+
FORCE
509+
)
474510
_thrust_declare_interface_alias(Thrust::OMP _Thrust_OMP)
475511
target_link_libraries(_Thrust_OMP INTERFACE Thrust::Thrust ${omp_target})
476512
thrust_debug_target(${omp_target} "${THRUST_OMP_VERSION}" internal)
@@ -495,9 +531,29 @@ endfunction()
495531
# #20670 -- otherwise variables like CUB_VERSION, etc won't be in the caller's
496532
# scope.
497533
macro(_thrust_find_CUDA required)
498-
if (NOT TARGET Thrust::CUDA)
534+
# Find libcudacxx first to ensure that CUB finds the same package.
535+
if (NOT TARGET Thrust::libcudacxx)
536+
thrust_debug("Searching for libcudacxx ${required}" internal)
537+
find_package(libcudacxx 999.0.0 CONFIG # FIXME: Put this at the real version once ready
538+
${_THRUST_QUIET_FLAG}
539+
${required}
540+
NO_DEFAULT_PATH # Only check the explicit HINTS below:
541+
HINTS
542+
"${_THRUST_INCLUDE_DIR}/dependencies/libcudacxx" # Source layout (GitHub)
543+
"${_THRUST_INCLUDE_DIR}/../libcudacxx" # Source layout (Perforce)
544+
"${_THRUST_CMAKE_DIR}/.." # Install layout
545+
)
546+
547+
if (TARGET libcudacxx::libcudacxx)
548+
thrust_set_libcudacxx_target(libcudacxx::libcudacxx)
549+
else()
550+
thrust_debug("libcudacxx not found!" internal)
551+
endif()
552+
endif()
553+
554+
if (NOT TARGET Thrust::CUB)
499555
thrust_debug("Searching for CUB ${required}" internal)
500-
find_package(CUB CONFIG
556+
find_package(CUB ${THRUST_VERSION} EXACT CONFIG
501557
${_THRUST_QUIET_FLAG}
502558
${required}
503559
NO_DEFAULT_PATH # Only check the explicit HINTS below:
@@ -513,6 +569,17 @@ macro(_thrust_find_CUDA required)
513569
thrust_debug("CUB not found!" internal)
514570
endif()
515571
endif()
572+
573+
if (NOT TARGET Thrust::CUDA)
574+
_thrust_declare_interface_alias(Thrust::CUDA _Thrust_CUDA)
575+
_thrust_setup_system(CUDA)
576+
target_link_libraries(_Thrust_CUDA INTERFACE
577+
Thrust::Thrust
578+
Thrust::CUB
579+
Thrust::libcudacxx
580+
)
581+
thrust_debug_target(Thrust::CUDA "" internal)
582+
endif()
516583
endmacro()
517584

518585
# This must be a macro instead of a function to ensure that backends passed to
@@ -619,21 +686,25 @@ endmacro()
619686
#
620687

621688
if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
622-
set(_THRUST_QUIET ON CACHE INTERNAL "Quiet mode enabled for Thrust find_package calls.")
623-
set(_THRUST_QUIET_FLAG "QUIET" CACHE INTERNAL "")
689+
set(_THRUST_QUIET ON CACHE INTERNAL "Quiet mode enabled for Thrust find_package calls." FORCE)
690+
set(_THRUST_QUIET_FLAG "QUIET" CACHE INTERNAL "" FORCE)
624691
else()
625692
unset(_THRUST_QUIET CACHE)
626693
unset(_THRUST_QUIET_FLAG CACHE)
627694
endif()
628695

629-
set(_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Location of thrust-config.cmake")
696+
set(_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL
697+
"Location of thrust-config.cmake"
698+
FORCE
699+
)
630700

631701
# Internal target that actually holds the Thrust interface. Used by all other Thrust targets.
632702
if (NOT TARGET Thrust::Thrust)
633703
_thrust_declare_interface_alias(Thrust::Thrust _Thrust_Thrust)
634704
# Pull in the include dir detected by thrust-config-version.cmake
635705
set(_THRUST_INCLUDE_DIR "${_THRUST_VERSION_INCLUDE_DIR}"
636706
CACHE INTERNAL "Location of Thrust headers."
707+
FORCE
637708
)
638709
unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear tmp variable from cache
639710
target_include_directories(_Thrust_Thrust INTERFACE "${_THRUST_INCLUDE_DIR}")

0 commit comments

Comments
 (0)