37
37
# [ADVANCED] # Optionally mark options as advanced
38
38
# )
39
39
#
40
- # # Use a custom TBB, CUB, and/or OMP
40
+ # # Use a custom TBB, CUB, libcudacxx, and/or OMP
41
41
# # (Note that once set, these cannot be changed. This includes COMPONENT
42
42
# # preloading and lazy lookups in thrust_create_target)
43
43
# find_package(Thrust REQUIRED)
44
44
# thrust_set_CUB_target(MyCUBTarget) # MyXXXTarget contains an existing
45
45
# thrust_set_TBB_target(MyTBBTarget) # interface to XXX for Thrust to use.
46
+ # thrust_set_libcudacxx_target(MyLibcudacxxTarget)
46
47
# thrust_set_OMP_target(MyOMPTarget)
47
- # thrust_create_target(ThrustWithMyCUB DEVICE CUDA)
48
+ # thrust_create_target(ThrustWithMyCUBAndLibcudacxx DEVICE CUDA)
48
49
# thrust_create_target(ThrustWithMyTBB DEVICE TBB)
49
50
# thrust_create_target(ThrustWithMyOMP DEVICE OMP)
50
51
#
@@ -85,19 +86,21 @@ cmake_minimum_required(VERSION 3.15)
85
86
set (THRUST_HOST_SYSTEM_OPTIONS
86
87
CPP OMP TBB
87
88
CACHE INTERNAL "Valid Thrust host systems."
89
+ FORCE
88
90
)
89
91
set (THRUST_DEVICE_SYSTEM_OPTIONS
90
92
CUDA CPP OMP TBB
91
93
CACHE INTERNAL "Valid Thrust device systems"
94
+ FORCE
92
95
)
93
96
94
97
# 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 "" )
98
+ set (THRUST_VERSION ${${CMAKE_FIND_PACKAGE_NAME} _VERSION} CACHE INTERNAL "" FORCE )
99
+ set (THRUST_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME} _VERSION_MAJOR} CACHE INTERNAL "" FORCE )
100
+ set (THRUST_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME} _VERSION_MINOR} CACHE INTERNAL "" FORCE )
101
+ set (THRUST_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME} _VERSION_PATCH} CACHE INTERNAL "" FORCE )
102
+ set (THRUST_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME} _VERSION_TWEAK} CACHE INTERNAL "" FORCE )
103
+ set (THRUST_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME} _VERSION_COUNT} CACHE INTERNAL "" FORCE )
101
104
102
105
function (thrust_create_target target_name)
103
106
thrust_debug("Assembling target ${target_name} . Options: ${ARGN} " internal )
@@ -109,21 +112,21 @@ function(thrust_create_target target_name)
109
112
IGNORE_DEPRECATED_COMPILER
110
113
IGNORE_DEPRECATED_CPP_11
111
114
IGNORE_DEPRECATED_CPP_DIALECT
112
- )
115
+ )
113
116
set (keys
114
117
DEVICE
115
118
DEVICE_OPTION
116
119
DEVICE_OPTION_DOC
117
120
HOST
118
121
HOST_OPTION
119
122
HOST_OPTION_DOC
120
- )
123
+ )
121
124
cmake_parse_arguments (TCT "${options} " "${keys} " "" ${ARGN} )
122
125
if (TCT_UNPARSED_ARGUMENTS)
123
126
message (AUTHOR_WARNING
124
127
"Unrecognized arguments passed to thrust_create_target: "
125
128
${TCT_UNPARSED_ARGUMENTS}
126
- )
129
+ )
127
130
endif ()
128
131
129
132
# Check that the main Thrust internal target is available
@@ -133,7 +136,7 @@ function(thrust_create_target target_name)
133
136
message (AUTHOR_WARNING
134
137
"The `thrust_create_target` function was called outside the scope of the "
135
138
"thrust targets. Call find_package again to recreate targets."
136
- )
139
+ )
137
140
endif ()
138
141
139
142
_thrust_set_if_undefined(TCT_HOST CPP)
@@ -145,12 +148,14 @@ function(thrust_create_target target_name)
145
148
146
149
if (NOT TCT_HOST IN_LIST THRUST_HOST_SYSTEM_OPTIONS)
147
150
message (FATAL_ERROR
148
- "Requested HOST=${TCT_HOST} ; must be one of ${THRUST_HOST_SYSTEM_OPTIONS} " )
151
+ "Requested HOST=${TCT_HOST} ; must be one of ${THRUST_HOST_SYSTEM_OPTIONS} "
152
+ )
149
153
endif ()
150
154
151
155
if (NOT TCT_DEVICE IN_LIST THRUST_DEVICE_SYSTEM_OPTIONS)
152
156
message (FATAL_ERROR
153
- "Requested DEVICE=${TCT_DEVICE} ; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS} " )
157
+ "Requested DEVICE=${TCT_DEVICE} ; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS} "
158
+ )
154
159
endif ()
155
160
156
161
if (TCT_FROM_OPTIONS)
@@ -172,7 +177,7 @@ function(thrust_create_target target_name)
172
177
173
178
# We can just create an INTERFACE IMPORTED target here instead of going
174
179
# through _thrust_declare_interface_alias as long as we aren't hanging any
175
- # Thrust/CUB include paths on ${target_name}.
180
+ # Thrust/CUB include paths directly on ${target_name}.
176
181
add_library (${target_name} INTERFACE IMPORTED )
177
182
target_link_libraries (${target_name}
178
183
INTERFACE
@@ -346,14 +351,17 @@ function(thrust_debug_internal_targets)
346
351
347
352
_thrust_debug_backend_targets(CPP "Thrust ${THRUST_VERSION} " )
348
353
349
- _thrust_debug_backend_targets(CUDA "CUB ${THRUST_CUB_VERSION } " )
350
- thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION } " )
354
+ _thrust_debug_backend_targets(OMP " ${THRUST_OMP_VERSION } " )
355
+ thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION } " )
351
356
352
357
_thrust_debug_backend_targets(TBB "${THRUST_TBB_VERSION} " )
353
358
thrust_debug_target(TBB:tbb "${THRUST_TBB_VERSION} " )
354
359
355
- _thrust_debug_backend_targets(OMP "${THRUST_OMP_VERSION} " )
356
- thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION} " )
360
+ _thrust_debug_backend_targets(CUDA
361
+ "CUB ${THRUST_CUB_VERSION} libcudacxx ${THRUST_libcudacxx_VERSION} "
362
+ )
363
+ thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION} " )
364
+ thrust_debug_target(libcudacxx::libcudacxx "${THRUST_libcudacxx_VERSION} " )
357
365
endfunction ()
358
366
359
367
################################################################################
@@ -434,18 +442,37 @@ function(_thrust_setup_system backend)
434
442
endif ()
435
443
endfunction ()
436
444
437
- # Use the provided cub_target for the CUDA backend. If Thrust::CUDA already
445
+ # Use the provided cub_target for the CUDA backend. If Thrust::CUB already
438
446
# exists, this call has no effect.
439
447
function (thrust_set_CUB_target cub_target)
440
- if (NOT TARGET Thrust::CUDA )
448
+ if (NOT TARGET Thrust::CUB )
441
449
thrust_debug("Setting CUB target to ${cub_target} " internal )
442
450
# 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} )
451
+ set (THRUST_CUB_VERSION ${CUB_VERSION} CACHE INTERNAL
452
+ "CUB version used by Thrust"
453
+ FORCE
454
+ )
455
+ _thrust_declare_interface_alias(Thrust::CUB _Thrust_CUB)
456
+ target_link_libraries (_Thrust_CUB INTERFACE ${cub_target} )
446
457
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)
458
+ thrust_debug_target(Thrust::CUB "CUB ${THRUST_CUB_VERSION} " internal )
459
+ endif ()
460
+ endfunction ()
461
+
462
+ # Use the provided libcudacxx_target for the CUDA backend. If Thrust::libcudacxx
463
+ # already exists, this call has no effect.
464
+ function (thrust_set_libcudacxx_target libcudacxx_target)
465
+ if (NOT TARGET Thrust::libcudacxx)
466
+ thrust_debug("Setting libcudacxx target to ${libcudacxx_target} " internal )
467
+ # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670
468
+ set (THRUST_libcudacxx_VERSION ${libcudacxx_VERSION} CACHE INTERNAL
469
+ "libcudacxx version used by Thrust"
470
+ FORCE
471
+ )
472
+ _thrust_declare_interface_alias(Thrust::libcudacxx _Thrust_libcudacxx)
473
+ target_link_libraries (_Thrust_libcudacxx INTERFACE ${libcudacxx_target} )
474
+ thrust_debug_target(${libcudacxx_target} "${THRUST_libcudacxx_VERSION} " internal )
475
+ thrust_debug_target(Thrust::libcudacxx "libcudacxx ${THRUST_libcudacxx_VERSION} " internal )
449
476
endif ()
450
477
endfunction ()
451
478
@@ -455,7 +482,10 @@ function(thrust_set_TBB_target tbb_target)
455
482
if (NOT TARGET Thrust::TBB)
456
483
thrust_debug("Setting TBB target to ${tbb_target} " internal )
457
484
# 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" )
485
+ set (THRUST_TBB_VERSION ${TBB_VERSION} CACHE INTERNAL
486
+ "TBB version used by Thrust"
487
+ FORCE
488
+ )
459
489
_thrust_declare_interface_alias(Thrust::TBB _Thrust_TBB)
460
490
target_link_libraries (_Thrust_TBB INTERFACE Thrust::Thrust ${tbb_target} )
461
491
thrust_debug_target(${tbb_target} "${THRUST_TBB_VERSION} " internal )
@@ -470,7 +500,10 @@ function(thrust_set_OMP_target omp_target)
470
500
if (NOT TARGET Thrust::OMP)
471
501
thrust_debug("Setting OMP target to ${omp_target} " internal )
472
502
# 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" )
503
+ set (THRUST_OMP_VERSION ${OpenMP_CXX_VERSION} CACHE INTERNAL
504
+ "OpenMP version used by Thrust"
505
+ FORCE
506
+ )
474
507
_thrust_declare_interface_alias(Thrust::OMP _Thrust_OMP)
475
508
target_link_libraries (_Thrust_OMP INTERFACE Thrust::Thrust ${omp_target} )
476
509
thrust_debug_target(${omp_target} "${THRUST_OMP_VERSION} " internal )
@@ -495,9 +528,29 @@ endfunction()
495
528
# #20670 -- otherwise variables like CUB_VERSION, etc won't be in the caller's
496
529
# scope.
497
530
macro (_thrust_find_CUDA required)
498
- if (NOT TARGET Thrust::CUDA)
531
+ # Find libcudacxx first to ensure that CUB finds the same package.
532
+ if (NOT TARGET Thrust::libcudacxx)
533
+ thrust_debug("Searching for libcudacxx ${required} " internal )
534
+ find_package (libcudacxx 1.7.999 CONFIG
535
+ ${_THRUST_QUIET_FLAG}
536
+ ${required}
537
+ NO_DEFAULT_PATH # Only check the explicit HINTS below:
538
+ HINTS
539
+ "${_THRUST_INCLUDE_DIR} /dependencies/libcudacxx" # Source layout (GitHub)
540
+ "${_THRUST_INCLUDE_DIR} /../libcudacxx" # Source layout (Perforce)
541
+ "${_THRUST_CMAKE_DIR} /.." # Install layout
542
+ )
543
+
544
+ if (TARGET libcudacxx::libcudacxx)
545
+ thrust_set_libcudacxx_target(libcudacxx::libcudacxx)
546
+ else ()
547
+ thrust_debug("libcudacxx not found!" internal )
548
+ endif ()
549
+ endif ()
550
+
551
+ if (NOT TARGET Thrust::CUB)
499
552
thrust_debug("Searching for CUB ${required} " internal )
500
- find_package (CUB CONFIG
553
+ find_package (CUB ${THRUST_VERSION} EXACT CONFIG
501
554
${_THRUST_QUIET_FLAG}
502
555
${required}
503
556
NO_DEFAULT_PATH # Only check the explicit HINTS below:
@@ -513,6 +566,17 @@ macro(_thrust_find_CUDA required)
513
566
thrust_debug("CUB not found!" internal )
514
567
endif ()
515
568
endif ()
569
+
570
+ if (NOT TARGET Thrust::CUDA)
571
+ _thrust_declare_interface_alias(Thrust::CUDA _Thrust_CUDA)
572
+ _thrust_setup_system(CUDA)
573
+ target_link_libraries (_Thrust_CUDA INTERFACE
574
+ Thrust::Thrust
575
+ Thrust::CUB
576
+ Thrust::libcudacxx
577
+ )
578
+ thrust_debug_target(Thrust::CUDA "" internal )
579
+ endif ()
516
580
endmacro ()
517
581
518
582
# This must be a macro instead of a function to ensure that backends passed to
@@ -619,21 +683,25 @@ endmacro()
619
683
#
620
684
621
685
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 "" )
686
+ set (_THRUST_QUIET ON CACHE INTERNAL "Quiet mode enabled for Thrust find_package calls." FORCE )
687
+ set (_THRUST_QUIET_FLAG "QUIET" CACHE INTERNAL "" FORCE )
624
688
else ()
625
689
unset (_THRUST_QUIET CACHE )
626
690
unset (_THRUST_QUIET_FLAG CACHE )
627
691
endif ()
628
692
629
- set (_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR} " CACHE INTERNAL "Location of thrust-config.cmake" )
693
+ set (_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR} " CACHE INTERNAL
694
+ "Location of thrust-config.cmake"
695
+ FORCE
696
+ )
630
697
631
698
# Internal target that actually holds the Thrust interface. Used by all other Thrust targets.
632
699
if (NOT TARGET Thrust::Thrust)
633
700
_thrust_declare_interface_alias(Thrust::Thrust _Thrust_Thrust)
634
701
# Pull in the include dir detected by thrust-config-version.cmake
635
702
set (_THRUST_INCLUDE_DIR "${_THRUST_VERSION_INCLUDE_DIR} "
636
703
CACHE INTERNAL "Location of Thrust headers."
704
+ FORCE
637
705
)
638
706
unset (_THRUST_VERSION_INCLUDE_DIR CACHE ) # Clear tmp variable from cache
639
707
target_include_directories (_Thrust_Thrust INTERFACE "${_THRUST_INCLUDE_DIR} " )
0 commit comments