From fc0846eccb5e45623bf549c363ddbac697a81e0f Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 24 Jan 2022 18:08:43 -0500 Subject: [PATCH] WIP: Prep for libcudacxx dependency. --- dependencies/cub | 2 +- dependencies/libcudacxx | 2 +- thrust/cmake/thrust-config.cmake | 134 +++++++++++++++++++++++-------- 3 files changed, 103 insertions(+), 35 deletions(-) diff --git a/dependencies/cub b/dependencies/cub index 21315e1e4f..3cf3cf0f1b 160000 --- a/dependencies/cub +++ b/dependencies/cub @@ -1 +1 @@ -Subproject commit 21315e1e4f3df36ff9d3af5a664689d55e5af635 +Subproject commit 3cf3cf0f1be79ea62a55d4482ddbd841fb5f0942 diff --git a/dependencies/libcudacxx b/dependencies/libcudacxx index c5cc60d893..71ec8663fd 160000 --- a/dependencies/libcudacxx +++ b/dependencies/libcudacxx @@ -1 +1 @@ -Subproject commit c5cc60d893a702624cf4e8d41fb9ba2bd4ec0013 +Subproject commit 71ec8663fdf1219f60dc0de3a41fb13c5a185e31 diff --git a/thrust/cmake/thrust-config.cmake b/thrust/cmake/thrust-config.cmake index 50e84ce748..b4ebcdc568 100644 --- a/thrust/cmake/thrust-config.cmake +++ b/thrust/cmake/thrust-config.cmake @@ -37,14 +37,15 @@ # [ADVANCED] # Optionally mark options as advanced # ) # -# # Use a custom TBB, CUB, and/or OMP +# # Use a custom TBB, CUB, libcudacxx, and/or OMP # # (Note that once set, these cannot be changed. This includes COMPONENT # # preloading and lazy lookups in thrust_create_target) # find_package(Thrust REQUIRED) # thrust_set_CUB_target(MyCUBTarget) # MyXXXTarget contains an existing # thrust_set_TBB_target(MyTBBTarget) # interface to XXX for Thrust to use. +# thrust_set_libcudacxx_target(MyLibcudacxxTarget) # thrust_set_OMP_target(MyOMPTarget) -# thrust_create_target(ThrustWithMyCUB DEVICE CUDA) +# thrust_create_target(ThrustWithMyCUBAndLibcudacxx DEVICE CUDA) # thrust_create_target(ThrustWithMyTBB DEVICE TBB) # thrust_create_target(ThrustWithMyOMP DEVICE OMP) # @@ -85,19 +86,21 @@ cmake_minimum_required(VERSION 3.15) set(THRUST_HOST_SYSTEM_OPTIONS CPP OMP TBB CACHE INTERNAL "Valid Thrust host systems." + FORCE ) set(THRUST_DEVICE_SYSTEM_OPTIONS CUDA CPP OMP TBB CACHE INTERNAL "Valid Thrust device systems" + FORCE ) # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670 -set(THRUST_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} CACHE INTERNAL "") -set(THRUST_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MAJOR} CACHE INTERNAL "") -set(THRUST_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL "") -set(THRUST_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "") -set(THRUST_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "") -set(THRUST_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "") +set(THRUST_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} CACHE INTERNAL "" FORCE) +set(THRUST_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MAJOR} CACHE INTERNAL "" FORCE) +set(THRUST_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL "" FORCE) +set(THRUST_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "" FORCE) +set(THRUST_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "" FORCE) +set(THRUST_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "" FORCE) function(thrust_create_target target_name) thrust_debug("Assembling target ${target_name}. Options: ${ARGN}" internal) @@ -109,7 +112,7 @@ function(thrust_create_target target_name) IGNORE_DEPRECATED_COMPILER IGNORE_DEPRECATED_CPP_11 IGNORE_DEPRECATED_CPP_DIALECT - ) + ) set(keys DEVICE DEVICE_OPTION @@ -117,13 +120,13 @@ function(thrust_create_target target_name) HOST HOST_OPTION HOST_OPTION_DOC - ) + ) cmake_parse_arguments(TCT "${options}" "${keys}" "" ${ARGN}) if (TCT_UNPARSED_ARGUMENTS) message(AUTHOR_WARNING "Unrecognized arguments passed to thrust_create_target: " ${TCT_UNPARSED_ARGUMENTS} - ) + ) endif() # Check that the main Thrust internal target is available @@ -133,7 +136,7 @@ function(thrust_create_target target_name) message(AUTHOR_WARNING "The `thrust_create_target` function was called outside the scope of the " "thrust targets. Call find_package again to recreate targets." - ) + ) endif() _thrust_set_if_undefined(TCT_HOST CPP) @@ -145,12 +148,14 @@ function(thrust_create_target target_name) if (NOT TCT_HOST IN_LIST THRUST_HOST_SYSTEM_OPTIONS) message(FATAL_ERROR - "Requested HOST=${TCT_HOST}; must be one of ${THRUST_HOST_SYSTEM_OPTIONS}") + "Requested HOST=${TCT_HOST}; must be one of ${THRUST_HOST_SYSTEM_OPTIONS}" + ) endif() if (NOT TCT_DEVICE IN_LIST THRUST_DEVICE_SYSTEM_OPTIONS) message(FATAL_ERROR - "Requested DEVICE=${TCT_DEVICE}; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS}") + "Requested DEVICE=${TCT_DEVICE}; must be one of ${THRUST_DEVICE_SYSTEM_OPTIONS}" + ) endif() if (TCT_FROM_OPTIONS) @@ -172,7 +177,7 @@ function(thrust_create_target target_name) # We can just create an INTERFACE IMPORTED target here instead of going # through _thrust_declare_interface_alias as long as we aren't hanging any - # Thrust/CUB include paths on ${target_name}. + # Thrust/CUB include paths directly on ${target_name}. add_library(${target_name} INTERFACE IMPORTED) target_link_libraries(${target_name} INTERFACE @@ -346,14 +351,17 @@ function(thrust_debug_internal_targets) _thrust_debug_backend_targets(CPP "Thrust ${THRUST_VERSION}") - _thrust_debug_backend_targets(CUDA "CUB ${THRUST_CUB_VERSION}") - thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION}") + _thrust_debug_backend_targets(OMP "${THRUST_OMP_VERSION}") + thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION}") _thrust_debug_backend_targets(TBB "${THRUST_TBB_VERSION}") thrust_debug_target(TBB:tbb "${THRUST_TBB_VERSION}") - _thrust_debug_backend_targets(OMP "${THRUST_OMP_VERSION}") - thrust_debug_target(OpenMP::OpenMP_CXX "${THRUST_OMP_VERSION}") + _thrust_debug_backend_targets(CUDA + "CUB ${THRUST_CUB_VERSION} libcudacxx ${THRUST_libcudacxx_VERSION}" + ) + thrust_debug_target(CUB::CUB "${THRUST_CUB_VERSION}") + thrust_debug_target(libcudacxx::libcudacxx "${THRUST_libcudacxx_VERSION}") endfunction() ################################################################################ @@ -434,18 +442,37 @@ function(_thrust_setup_system backend) endif() endfunction() -# Use the provided cub_target for the CUDA backend. If Thrust::CUDA already +# Use the provided cub_target for the CUDA backend. If Thrust::CUB already # exists, this call has no effect. function(thrust_set_CUB_target cub_target) - if (NOT TARGET Thrust::CUDA) + if (NOT TARGET Thrust::CUB) thrust_debug("Setting CUB target to ${cub_target}" internal) # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670 - set(THRUST_CUB_VERSION ${CUB_VERSION} CACHE INTERNAL "CUB version used by Thrust") - _thrust_declare_interface_alias(Thrust::CUDA _Thrust_CUDA) - target_link_libraries(_Thrust_CUDA INTERFACE Thrust::Thrust ${cub_target}) + set(THRUST_CUB_VERSION ${CUB_VERSION} CACHE INTERNAL + "CUB version used by Thrust" + FORCE + ) + _thrust_declare_interface_alias(Thrust::CUB _Thrust_CUB) + target_link_libraries(_Thrust_CUB INTERFACE ${cub_target}) thrust_debug_target(${cub_target} "${THRUST_CUB_VERSION}" internal) - thrust_debug_target(Thrust::CUDA "CUB ${THRUST_CUB_VERSION}" internal) - _thrust_setup_system(CUDA) + thrust_debug_target(Thrust::CUB "CUB ${THRUST_CUB_VERSION}" internal) + endif() +endfunction() + +# Use the provided libcudacxx_target for the CUDA backend. If Thrust::libcudacxx +# already exists, this call has no effect. +function(thrust_set_libcudacxx_target libcudacxx_target) + if (NOT TARGET Thrust::libcudacxx) + thrust_debug("Setting libcudacxx target to ${libcudacxx_target}" internal) + # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670 + set(THRUST_libcudacxx_VERSION ${libcudacxx_VERSION} CACHE INTERNAL + "libcudacxx version used by Thrust" + FORCE + ) + _thrust_declare_interface_alias(Thrust::libcudacxx _Thrust_libcudacxx) + target_link_libraries(_Thrust_libcudacxx INTERFACE ${libcudacxx_target}) + thrust_debug_target(${libcudacxx_target} "${THRUST_libcudacxx_VERSION}" internal) + thrust_debug_target(Thrust::libcudacxx "libcudacxx ${THRUST_libcudacxx_VERSION}" internal) endif() endfunction() @@ -455,7 +482,10 @@ function(thrust_set_TBB_target tbb_target) if (NOT TARGET Thrust::TBB) thrust_debug("Setting TBB target to ${tbb_target}" internal) # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670 - set(THRUST_TBB_VERSION ${TBB_VERSION} CACHE INTERNAL "TBB version used by Thrust") + set(THRUST_TBB_VERSION ${TBB_VERSION} CACHE INTERNAL + "TBB version used by Thrust" + FORCE + ) _thrust_declare_interface_alias(Thrust::TBB _Thrust_TBB) target_link_libraries(_Thrust_TBB INTERFACE Thrust::Thrust ${tbb_target}) thrust_debug_target(${tbb_target} "${THRUST_TBB_VERSION}" internal) @@ -470,7 +500,10 @@ function(thrust_set_OMP_target omp_target) if (NOT TARGET Thrust::OMP) thrust_debug("Setting OMP target to ${omp_target}" internal) # Workaround cmake issue #20670 https://gitlab.kitware.com/cmake/cmake/-/issues/20670 - set(THRUST_OMP_VERSION ${OpenMP_CXX_VERSION} CACHE INTERNAL "OpenMP version used by Thrust") + set(THRUST_OMP_VERSION ${OpenMP_CXX_VERSION} CACHE INTERNAL + "OpenMP version used by Thrust" + FORCE + ) _thrust_declare_interface_alias(Thrust::OMP _Thrust_OMP) target_link_libraries(_Thrust_OMP INTERFACE Thrust::Thrust ${omp_target}) thrust_debug_target(${omp_target} "${THRUST_OMP_VERSION}" internal) @@ -495,9 +528,29 @@ endfunction() # #20670 -- otherwise variables like CUB_VERSION, etc won't be in the caller's # scope. macro(_thrust_find_CUDA required) - if (NOT TARGET Thrust::CUDA) + # Find libcudacxx first to ensure that CUB finds the same package. + if (NOT TARGET Thrust::libcudacxx) + thrust_debug("Searching for libcudacxx ${required}" internal) + find_package(libcudacxx 1.7.999 CONFIG + ${_THRUST_QUIET_FLAG} + ${required} + NO_DEFAULT_PATH # Only check the explicit HINTS below: + HINTS + "${_THRUST_INCLUDE_DIR}/dependencies/libcudacxx" # Source layout (GitHub) + "${_THRUST_INCLUDE_DIR}/../libcudacxx" # Source layout (Perforce) + "${_THRUST_CMAKE_DIR}/.." # Install layout + ) + + if (TARGET libcudacxx::libcudacxx) + thrust_set_libcudacxx_target(libcudacxx::libcudacxx) + else() + thrust_debug("libcudacxx not found!" internal) + endif() + endif() + + if (NOT TARGET Thrust::CUB) thrust_debug("Searching for CUB ${required}" internal) - find_package(CUB CONFIG + find_package(CUB ${THRUST_VERSION} EXACT CONFIG ${_THRUST_QUIET_FLAG} ${required} NO_DEFAULT_PATH # Only check the explicit HINTS below: @@ -513,6 +566,17 @@ macro(_thrust_find_CUDA required) thrust_debug("CUB not found!" internal) endif() endif() + + if (NOT TARGET Thrust::CUDA) + _thrust_declare_interface_alias(Thrust::CUDA _Thrust_CUDA) + _thrust_setup_system(CUDA) + target_link_libraries(_Thrust_CUDA INTERFACE + Thrust::Thrust + Thrust::CUB + Thrust::libcudacxx + ) + thrust_debug_target(Thrust::CUDA "" internal) + endif() endmacro() # This must be a macro instead of a function to ensure that backends passed to @@ -619,14 +683,17 @@ endmacro() # if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) - set(_THRUST_QUIET ON CACHE INTERNAL "Quiet mode enabled for Thrust find_package calls.") - set(_THRUST_QUIET_FLAG "QUIET" CACHE INTERNAL "") + set(_THRUST_QUIET ON CACHE INTERNAL "Quiet mode enabled for Thrust find_package calls." FORCE) + set(_THRUST_QUIET_FLAG "QUIET" CACHE INTERNAL "" FORCE) else() unset(_THRUST_QUIET CACHE) unset(_THRUST_QUIET_FLAG CACHE) endif() -set(_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Location of thrust-config.cmake") +set(_THRUST_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL + "Location of thrust-config.cmake" + FORCE +) # Internal target that actually holds the Thrust interface. Used by all other Thrust targets. if (NOT TARGET Thrust::Thrust) @@ -634,6 +701,7 @@ if (NOT TARGET Thrust::Thrust) # Pull in the include dir detected by thrust-config-version.cmake set(_THRUST_INCLUDE_DIR "${_THRUST_VERSION_INCLUDE_DIR}" CACHE INTERNAL "Location of Thrust headers." + FORCE ) unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear tmp variable from cache target_include_directories(_Thrust_Thrust INTERFACE "${_THRUST_INCLUDE_DIR}")