From d81953b3e0f55f5ea8fb240886ba28aa7ebc15c9 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Wed, 25 Jan 2023 15:40:04 -0500 Subject: [PATCH 01/14] Initial build system updates for monorepo. --- .gitmodules | 6 - CMakeLists.txt | 20 ++- cmake/ThrustBuildCompilerTargets.cmake | 16 +- cmake/ThrustBuildTargetList.cmake | 10 +- cmake/ThrustCompilerHacks.cmake | 118 ++------------- cmake/ThrustCudaConfig.cmake | 202 ++----------------------- cmake/ThrustHeaderTesting.cmake | 4 + cmake/ThrustInstallRules.cmake | 33 ---- cmake/ThrustUtilities.cmake | 31 +++- dependencies/cub | 1 - dependencies/libcudacxx | 1 - examples/CMakeLists.txt | 17 +-- internal/benchmark/CMakeLists.txt | 1 + testing/CMakeLists.txt | 12 +- testing/async/CMakeLists.txt | 6 +- testing/cuda/CMakeLists.txt | 5 +- testing/unittest/CMakeLists.txt | 5 +- thrust/cmake/thrust-config.cmake | 5 +- 18 files changed, 83 insertions(+), 410 deletions(-) delete mode 160000 dependencies/cub delete mode 160000 dependencies/libcudacxx diff --git a/.gitmodules b/.gitmodules index 0bb39f302..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "cub"] - path = dependencies/cub - url = ../cub.git -[submodule "libcudacxx"] - path = dependencies/libcudacxx - url = ../libcudacxx.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 967ebf53a..956178c0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,19 @@ # 3.15 is the minimum for including the project with add_subdirectory. -# 3.17 for building the project's standalone tests/examples/etc. -# 3.18.3 for C++17 + CUDA +# 3.21 is the minimum for the developer build. cmake_minimum_required(VERSION 3.15) -# Remove this when we use the new CUDA_ARCHITECTURES properties with both -# nvcc and nvc++. -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) - cmake_policy(SET CMP0104 OLD) -endif() - project(Thrust NONE) # Determine whether Thrust is the top-level project or included into # another project via add_subdirectory() -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(THRUST_TOPLEVEL_PROJECT ON) +if(DEFINED CCCL_TOPLEVEL_PROJECT) + set(THRUST_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) else() - set(THRUST_TOPLEVEL_PROJECT OFF) + if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") + set(THRUST_TOPLEVEL_PROJECT ON) + else() + set(THRUST_TOPLEVEL_PROJECT OFF) + endif() endif() ## thrust_fix_clang_nvcc_build_for @@ -38,6 +35,7 @@ endfunction() # This must be done before any languages are enabled: if (THRUST_TOPLEVEL_PROJECT) + cmake_minimum_required(VERSION 3.21) include(cmake/ThrustCompilerHacks.cmake) endif() diff --git a/cmake/ThrustBuildCompilerTargets.cmake b/cmake/ThrustBuildCompilerTargets.cmake index aed0ec170..0dd29984a 100644 --- a/cmake/ThrustBuildCompilerTargets.cmake +++ b/cmake/ThrustBuildCompilerTargets.cmake @@ -110,20 +110,12 @@ function(thrust_build_compiler_targets) append_option_if_available("-diag-disable=11076" cxx_compile_options) endif() - if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - # Today: - # * NVCC accepts CUDA C++ in .cu files but not .cpp files. - # * NVC++ accepts CUDA C++ in .cpp files but not .cu files. - # TODO: This won't be necessary in the future. - list(APPEND cxx_compile_options -cppsuffix=cu) - endif() - add_library(thrust.compiler_interface INTERFACE) foreach (cxx_option IN LISTS cxx_compile_options) target_compile_options(thrust.compiler_interface INTERFACE $<$:${cxx_option}> - $<$,$>:${cxx_option}> + $<$,$>:${cxx_option}> # TODO will this work with the new nvc++ recipe? # Only use -Xcompiler with NVCC, not NVC++. # # CMake can't split genexs, so this can't be formatted better :( @@ -144,12 +136,8 @@ function(thrust_build_compiler_targets) target_compile_options(thrust.compiler_interface INTERFACE # If using CUDA w/ NVCC... $<$,$>:-Xcudafe=--display_error_number> - ) - - # Tell NVCC to be quiet about deprecated GPU targets: - target_compile_options(thrust.compiler_interface INTERFACE - # If using CUDA w/ NVCC... $<$,$>:-Wno-deprecated-gpu-targets> + $<$:-diag-suppress 128> ) # This is kept separate for Github issue #1174. diff --git a/cmake/ThrustBuildTargetList.cmake b/cmake/ThrustBuildTargetList.cmake index f4adaf546..061fbf6d7 100644 --- a/cmake/ThrustBuildTargetList.cmake +++ b/cmake/ThrustBuildTargetList.cmake @@ -95,15 +95,7 @@ function(thrust_set_target_properties target_name host device dialect prefix) RUNTIME_OUTPUT_DIRECTORY "${THRUST_EXECUTABLE_OUTPUT_DIR}" ) - # CMake still emits errors about empty CUDA_ARCHITECTURES when CMP0104 - # is set to OLD. This suppresses the errors for good. - if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) - set_target_properties(${target_name} - PROPERTIES - CUDA_ARCHITECTURES OFF - ) - endif() - + # TODO is this still needed? if ("CUDA" STREQUAL "${device}" AND "NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") set_target_properties(${target_name} PROPERTIES diff --git a/cmake/ThrustCompilerHacks.cmake b/cmake/ThrustCompilerHacks.cmake index 5f7b0d98e..1eeafa775 100644 --- a/cmake/ThrustCompilerHacks.cmake +++ b/cmake/ThrustCompilerHacks.cmake @@ -1,110 +1,16 @@ -# Set up compiler paths and apply temporary hacks to support NVC++. # This file must be included before enabling any languages. -# Temporary hacks to make NVC++ work; this requires you to define -# `CMAKE_CUDA_COMPILER_ID=NVCXX and `CMAKE_CUDA_COMPILER_FORCED=ON`. -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - # If using NVC++, don't set CXX compiler - if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "") - unset(CMAKE_CXX_COMPILER CACHE) - message(FATAL_ERROR "You are using NVC++ as your CUDA C++ compiler, but have" - " specified a different ISO C++ compiler; NVC++ acts as both, so please" - " unset the CMAKE_CXX_COMPILER variable." - ) - endif() - - # We don't set CMAKE_CUDA_HOST_COMPILER for NVC++; if we do, CMake tries to - # pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to NVC++, which it doesn't - # understand. - if (NOT "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "") - unset(CMAKE_CUDA_HOST_COMPILER CACHE) - message(FATAL_ERROR "You are using NVC++ as your CUDA C++ compiler, but have" - " specified a different host ISO C++ compiler; NVC++ acts as both, so" - " please unset the CMAKE_CUDA_HOST_COMPILER variable." - ) - endif() - - set(CMAKE_CXX_COMPILER "${CMAKE_CUDA_COMPILER}") - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -stdpar") - set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${CMAKE_CUDA_COMPILER}") - set(CMAKE_CUDA_LINK_EXECUTABLE - " -o ") - - # Setup CMAKE_CXX_LIBRARY_ARCHITECTURE on Debian/Ubuntu so that find_package - # works properly. - if (EXISTS /etc/debian_version) - if (NOT CMAKE_CXX_LIBRARY_ARCHITECTURE) - file(GLOB files_in_lib RELATIVE /lib /lib/*-linux-gnu* ) - foreach (file ${files_in_lib}) - if ("${file}" MATCHES "${CMAKE_LIBRARY_ARCHITECTURE_REGEX}") - set(CMAKE_CXX_LIBRARY_ARCHITECTURE ${file}) - break() - endif() - endforeach() - endif() - if (NOT CMAKE_LIBRARY_ARCHITECTURE) - set(CMAKE_LIBRARY_ARCHITECTURE ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) - endif() - endif() -endif() - -# We don't set CMAKE_CUDA_HOST_COMPILER for NVC++; if we do, CMake tries to -# pass `-ccbin ${CMAKE_CUDA_HOST_COMPILER}` to NVC++, which it doesn't -# understand. -if ((NOT "NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")) - if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR +if (NOT ("${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "" OR "${CMAKE_CUDA_HOST_COMPILER}" STREQUAL "${CMAKE_CXX_COMPILER}")) - set(tmp "${CMAKE_CUDA_HOST_COMPILER}") - unset(CMAKE_CUDA_HOST_COMPILER CACHE) - message(FATAL_ERROR - "For convenience, Thrust's test harness uses CMAKE_CXX_COMPILER for the " - "CUDA host compiler. Refusing to overwrite specified " - "CMAKE_CUDA_HOST_COMPILER -- please reconfigure without setting this " - "variable. Currently:\n" - "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n" - "CMAKE_CUDA_HOST_COMPILER=${tmp}" - ) - endif () - set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}") -endif () - -# Temporary hacks to make NVC++ work; this requires you to define -# `CMAKE_CUDA_COMPILER_ID=NVCXX and `CMAKE_CUDA_COMPILER_FORCED=ON`. -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - # Need 3.17 for the properties used below. - cmake_minimum_required(VERSION 3.17) - - set(CMAKE_CUDA_STANDARD_DEFAULT 03) - - set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03") - set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03") - set(CMAKE_CUDA03_STANDARD__HAS_FULL_SUPPORT TRUE) - set_property(GLOBAL PROPERTY CMAKE_CUDA03_KNOWN_FEATURES) - - set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11") - set(CMAKE_CUDA11_STANDARD__HAS_FULL_SUPPORT TRUE) - set_property(GLOBAL PROPERTY CMAKE_CUDA11_KNOWN_FEATURES) - - set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14") - set(CMAKE_CUDA14_STANDARD__HAS_FULL_SUPPORT TRUE) - set_property(GLOBAL PROPERTY CMAKE_CUDA14_KNOWN_FEATURES) - - set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17") - set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") - set(CMAKE_CUDA17_STANDARD__HAS_FULL_SUPPORT TRUE) - set_property(GLOBAL PROPERTY CMAKE_CUDA17_KNOWN_FEATURES) - - include(Internal/FeatureTesting) - include(Compiler/CMakeCommonCompilerMacros) - cmake_record_cuda_compile_features() - - set(CMAKE_CUDA_COMPILE_FEATURES - ${CMAKE_CUDA03_COMPILE_FEATURES} - ${CMAKE_CUDA11_COMPILE_FEATURES} - ${CMAKE_CUDA14_COMPILE_FEATURES} - ${CMAKE_CUDA17_COMPILE_FEATURES} - ${CMAKE_CUDA20_COMPILE_FEATURES} + set(tmp "${CMAKE_CUDA_HOST_COMPILER}") + unset(CMAKE_CUDA_HOST_COMPILER CACHE) + message(FATAL_ERROR + "For convenience, Thrust's test harness uses CMAKE_CXX_COMPILER for the " + "CUDA host compiler. Refusing to overwrite specified " + "CMAKE_CUDA_HOST_COMPILER -- please reconfigure without setting this " + "variable. Currently:\n" + "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n" + "CMAKE_CUDA_HOST_COMPILER=${tmp}" ) -endif() +endif () +set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}") diff --git a/cmake/ThrustCudaConfig.cmake b/cmake/ThrustCudaConfig.cmake index a585c7910..f71c59540 100644 --- a/cmake/ThrustCudaConfig.cmake +++ b/cmake/ThrustCudaConfig.cmake @@ -1,200 +1,24 @@ enable_language(CUDA) -set(THRUST_KNOWN_COMPUTE_ARCHS 50 52 53 60 61 62 70 72 75 80 86) - -if (NVIDIA STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER 11.7) - list(APPEND THRUST_KNOWN_COMPUTE_ARCHS 90) - endif() - if (CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 12.0) - list(APPEND THRUST_KNOWN_COMPUTE_ARCHS 35 37) - endif() -else() - list(APPEND THRUST_KNOWN_COMPUTE_ARCHS 35 37 90) -endif() - -# Split CUDA_FLAGS into 3 parts: -# -# THRUST_CUDA_FLAGS_BASE: Common CUDA flags for all targets. -# THRUST_CUDA_FLAGS_RDC: Additional CUDA flags for targets compiled with RDC. -# THRUST_CUDA_FLAGS_NO_RDC: Additional CUDA flags for targets compiled without RDC. # -# This is necessary because CUDA SMs 5.3, 6.2, and 7.2 do not support RDC, but -# we want to always build some targets (e.g. testing/cuda/*) with RDC. -# We work around this by building the "always RDC" targets without support for -# those SMs. This requires two sets of CUDA_FLAGS. +# Architecture options: # -# Enabling any of those SMs along with the ENABLE_RDC options will result in a -# configuration error. -# -# Because of how CMake handles the CMAKE_CUDA_FLAGS variables, every target -# generated in a given directory will use the same value for CMAKE_CUDA_FLAGS, -# which is determined at the end of the directory's scope. This means caution -# should be used when trying to build different targets with different flags, -# since they might not behave as expected. This will improve with CMake 3.18, -# which add the DEVICE_LINK genex, fixing the issue with using per-target -# CUDA_FLAGS: https://gitlab.kitware.com/cmake/cmake/-/issues/18265 -set(THRUST_CUDA_FLAGS_BASE "${CMAKE_CUDA_FLAGS}") -set(THRUST_CUDA_FLAGS_RDC) -set(THRUST_CUDA_FLAGS_NO_RDC) - -# Archs that don't support RDC: -set(no_rdc_archs 53 62 72) - -# Find the highest arch: -list(SORT THRUST_KNOWN_COMPUTE_ARCHS) -list(LENGTH THRUST_KNOWN_COMPUTE_ARCHS max_idx) -math(EXPR max_idx "${max_idx} - 1") -list(GET THRUST_KNOWN_COMPUTE_ARCHS ${max_idx} highest_arch) - -option(THRUST_AUTO_DETECT_COMPUTE_ARCHS - "If ON, compute architectures for all GPUs in the current system are enabled and all other compute architectures are disabled." - OFF -) - -if (THRUST_AUTO_DETECT_COMPUTE_ARCHS) - if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - message(STATUS "Thrust: Using NVC++ builtin automatic compute architecture detection.") - else() - set(detect_compute_archs_source ${Thrust_SOURCE_DIR}/cmake/detect_compute_archs.cu) - set(detect_compute_archs_exe ${PROJECT_BINARY_DIR}/detect_compute_archs) - set(detect_compute_archs_error_log ${PROJECT_BINARY_DIR}/detect_compute_archs.stderr.log) - execute_process( - COMMAND ${CMAKE_CUDA_COMPILER} - -std=c++11 - -o ${detect_compute_archs_exe} - --run - ${detect_compute_archs_source} - OUTPUT_VARIABLE detected_archs - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_FILE ${detect_compute_archs_error_log}) - if ("NONE" STREQUAL "${detected_archs}") - set(detected_message " none") - else() - foreach (arch IN LISTS detected_archs) - string(APPEND detected_message " sm_${arch}") - endforeach() - endif() - message(STATUS "Thrust: Automatically detected compute architectures:${detected_message}") - endif() -endif() - -set(option_init OFF) -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(option_init ON) -endif() -option(THRUST_DISABLE_ARCH_BY_DEFAULT - "If ON, then all compute architectures are disabled on the initial CMake run." - ${option_init} -) - -set(option_init ON) -if (THRUST_DISABLE_ARCH_BY_DEFAULT OR THRUST_AUTO_DETECT_COMPUTE_ARCHS) - set(option_init OFF) -endif() - -set(num_archs_enabled 0) -foreach (arch IN LISTS THRUST_KNOWN_COMPUTE_ARCHS) - set(this_option_init ${option_init}) - - if (${arch} IN_LIST detected_archs) - set(this_option_init ON) - endif() - option(THRUST_ENABLE_COMPUTE_${arch} - "Enable code generation for tests for sm_${arch}" - ${this_option_init} - ) +# Create a new arch list that only contains arches that support CDP: +set(THRUST_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}) +set(THRUST_CUDA_ARCHITECTURES_RDC ${THRUST_CUDA_ARCHITECTURES}) +list(FILTER THRUST_CUDA_ARCHITECTURES_RDC EXCLUDE REGEX "53|62|72|90") - if (NOT THRUST_ENABLE_COMPUTE_${arch}) - continue() - endif() +message(STATUS "THRUST_CUDA_ARCHITECTURES: ${THRUST_CUDA_ARCHITECTURES}") +message(STATUS "THRUST_CUDA_ARCHITECTURES_RDC: ${THRUST_CUDA_ARCHITECTURES_RDC}") - math(EXPR num_archs_enabled "${num_archs_enabled} + 1") +option(THRUST_ENABLE_RDC_TESTS "Enable tests that require separable compilation." ON) +option(THRUST_FORCE_RDC "Enable separable compilation on all targets that support it." OFF) - if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - if (NOT ${num_archs_enabled} EQUAL 1) - message(FATAL_ERROR - "NVCXX does not support compilation for multiple device architectures " - "at once." - ) - endif() - set(arch_flag "-gpu=cc${arch}") - elseif ("Clang" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(arch_flag "--cuda-gpu-arch=sm_${arch}") - else() - set(arch_flag "-gencode arch=compute_${arch},code=sm_${arch}") - endif() - - string(APPEND compute_message " sm_${arch}") - string(APPEND THRUST_CUDA_FLAGS_NO_RDC " ${arch_flag}") - if (NOT arch IN_LIST no_rdc_archs) - string(APPEND THRUST_CUDA_FLAGS_RDC " ${arch_flag}") - endif() -endforeach() - -if (NOT "NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - option(THRUST_ENABLE_COMPUTE_FUTURE - "Enable code generation for tests for compute_${highest_arch}" - ${option_init} - ) - if (THRUST_ENABLE_COMPUTE_FUTURE) - string(APPEND THRUST_CUDA_FLAGS_BASE - " -gencode arch=compute_${highest_arch},code=compute_${highest_arch}" - ) - string(APPEND compute_message " compute_${highest_arch}") - endif() -endif() - -message(STATUS "Thrust: Explicitly enabled compute architectures:${compute_message}") - -# RDC is off by default in NVCC and on by default in NVC++. Turning off RDC -# isn't currently supported by NVC++. So, we default to RDC off for NVCC and -# RDC on for NVC++. -set(option_init OFF) -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(option_init ON) -endif() - -option(THRUST_ENABLE_TESTS_WITH_RDC - "Build all Thrust tests with RDC; tests that require RDC are not affected by this option." - ${option_init} -) - -option(THRUST_ENABLE_EXAMPLES_WITH_RDC - "Build all Thrust examples with RDC; examples which require RDC are not affected by this option." - ${option_init} -) - -# Check for RDC/SM compatibility and error/warn if necessary -foreach (sm IN LISTS no_rdc_archs) - set(sm_opt THRUST_ENABLE_COMPUTE_${sm}) - if (${sm_opt}) - foreach (opt IN ITEMS TESTS EXAMPLES) - set(rdc_opt THRUST_ENABLE_${opt}_WITH_RDC) - if (${rdc_opt}) - message(FATAL_ERROR - "${rdc_opt} is incompatible with ${sm_opt}, since sm_${sm} does not " - "support RDC." - ) - endif() - endforeach() - - message(NOTICE - "sm_${sm} does not support RDC. Targets that require RDC will be built " - "without support for this architecture." - ) - endif() -endforeach() - - -# -# Clang CUDA options +# +# Clang CUDA options # if ("Clang" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(THRUST_CUDA_FLAGS_BASE "${THRUST_CUDA_FLAGS_BASE} -Wno-unknown-cuda-version -Xclang=-fcuda-allow-variadic-functions") -endif() - + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-unknown-cuda-version -Xclang=-fcuda-allow-variadic-functions") +endif () -# By default RDC is not used: -set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_NO_RDC}") diff --git a/cmake/ThrustHeaderTesting.cmake b/cmake/ThrustHeaderTesting.cmake index 3b3e00ca8..ad438b0f8 100644 --- a/cmake/ThrustHeaderTesting.cmake +++ b/cmake/ThrustHeaderTesting.cmake @@ -125,6 +125,10 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) ) thrust_clone_target_properties(${headertest_target} ${thrust_target}) + if ("CUDA" STREQUAL "${config_device}") + thrust_configure_cuda_target(${headertest_target} RDC ${THRUST_FORCE_RDC}) + endif() + # Disable macro checks on TBB; the TBB atomic implementation uses `I` and # our checks will issue false errors. if ("TBB" IN_LIST config_systems) diff --git a/cmake/ThrustInstallRules.cmake b/cmake/ThrustInstallRules.cmake index 98e72e196..0898d3964 100644 --- a/cmake/ThrustInstallRules.cmake +++ b/cmake/ThrustInstallRules.cmake @@ -23,36 +23,3 @@ configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in" @ONLY) install(FILES "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake" DESTINATION "${install_location}") - -# Depending on how Thrust is configured, libcudacxx and CUB's CMake scripts may -# or may not be include()'d, so force include their install rules when requested. -# By default, these projects are installed alongside Thrust. This is controlled by -# THRUST_INSTALL_CUB_HEADERS and THRUST_INSTALL_LIBCUDACXX_HEADERS. -option(THRUST_INSTALL_CUB_HEADERS "Include CUB headers when installing." ON) -if (THRUST_INSTALL_CUB_HEADERS) - # Use a function to limit scope of the CUB_*_DIR vars: - function(_thrust_install_cub_headers) - # Fake these for the logic in CUBInstallRules.cmake: - set(CUB_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/cub/") - set(CUB_BINARY_DIR "${Thrust_BINARY_DIR}/cub-config/") - set(CUB_ENABLE_INSTALL_RULES ON) - set(CUB_IN_THRUST OFF) - include("${Thrust_SOURCE_DIR}/dependencies/cub/cmake/CubInstallRules.cmake") - endfunction() - - _thrust_install_cub_headers() -endif() - -option(THRUST_INSTALL_LIBCUDACXX_HEADERS "Include libcudacxx headers when installing." ON) -if (THRUST_INSTALL_LIBCUDACXX_HEADERS) - # Use a function to limit scope of the libcudacxx_*_DIR vars: - function(_thrust_install_libcudacxx_headers) - # Fake these for the logic in libcudacxxInstallRules.cmake: - set(libcudacxx_SOURCE_DIR "${Thrust_SOURCE_DIR}/dependencies/libcudacxx/") - set(libcudacxx_BINARY_DIR "${Thrust_BINARY_DIR}/libcudacxx-config/") - set(libcudacxx_ENABLE_INSTALL_RULES ON) - include("${Thrust_SOURCE_DIR}/dependencies/libcudacxx/cmake/libcudacxxInstallRules.cmake") - endfunction() - - _thrust_install_libcudacxx_headers() -endif() diff --git a/cmake/ThrustUtilities.cmake b/cmake/ThrustUtilities.cmake index 6bbb1200a..8dd53fb31 100644 --- a/cmake/ThrustUtilities.cmake +++ b/cmake/ThrustUtilities.cmake @@ -11,15 +11,32 @@ function(thrust_wrap_cu_in_cpp cpp_file_var cu_file thrust_target) set(${cpp_file_var} "${cpp_file}" PARENT_SCOPE) endfunction() -# Enable RDC for a CUDA target. Encapsulates compiler hacks: -function(thrust_enable_rdc_for_cuda_target target_name) - if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") +# thrust_configure_cuda_target( RDC ) +# +# Configures `target_name` with the appropriate CUDA architectures and RDC state. +function(thrust_configure_cuda_target target_name) + set(options) + set(one_value_args RDC) + set(multi_value_args) + cmake_parse_arguments(thrust_cuda "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) + + if (thrust_cuda_UNPARSED_ARGUMENTS) + message(AUTHOR_WARNING + "Unrecognized arguments passed to thrust_configure_cuda_target: " + ${thrust_cuda_UNPARSED_ARGUMENTS}) + endif() + + if (NOT DEFINED thrust_cuda_RDC) + message(AUTHOR_WARNING "RDC option required for thrust_configure_cuda_target.") + endif() + + if (thrust_cuda_RDC) set_target_properties(${target_name} PROPERTIES - COMPILE_FLAGS "-gpu=rdc" - ) + CUDA_ARCHITECTURES "${THRUST_CUDA_ARCHITECTURES_RDC}" + CUDA_SEPARABLE_COMPILATION ON) else() set_target_properties(${target_name} PROPERTIES - CUDA_SEPARABLE_COMPILATION ON - ) + CUDA_ARCHITECTURES "${THRUST_CUDA_ARCHITECTURES}" + CUDA_SEPARABLE_COMPILATION OFF) endif() endfunction() diff --git a/dependencies/cub b/dependencies/cub deleted file mode 160000 index b87c35632..000000000 --- a/dependencies/cub +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b87c356329631a5b6ce7bfa25a38843808d5c600 diff --git a/dependencies/libcudacxx b/dependencies/libcudacxx deleted file mode 160000 index 55dd2c993..000000000 --- a/dependencies/libcudacxx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 55dd2c99346baa3a14949a0f7e9c41865e434eda diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 306ecb7a3..bf16c09c1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -51,14 +51,6 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) add_dependencies(${config_prefix}.all ${config_meta_target}) endforeach() -# Update flags to reflect RDC options. See note in ThrustCudaConfig.cmake -- -# these flag variables behave unintuitively: -if (THRUST_ENABLE_EXAMPLES_WITH_RDC) - set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_RDC}") -else() - set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_NO_RDC}") -endif() - ## thrust_add_example # # Add an example executable and register it with ctest. @@ -97,6 +89,10 @@ function(thrust_add_example target_name_var example_name example_src thrust_targ thrust_clone_target_properties(${example_target} ${thrust_target}) thrust_fix_clang_nvcc_build_for(${example_target}) + if ("CUDA" STREQUAL "${config_device}") + thrust_configure_cuda_target(${example_target} RDC ${THRUST_FORCE_RDC}) + endif() + # Add to the active configuration's meta target add_dependencies(${config_meta_target} ${example_target}) @@ -106,11 +102,6 @@ function(thrust_add_example target_name_var example_name example_src thrust_targ endif() add_dependencies(${example_meta_target} ${example_target}) - if ("CUDA" STREQUAL "${config_device}" AND - THRUST_ENABLE_EXAMPLES_WITH_RDC) - thrust_enable_rdc_for_cuda_target(${example_target}) - endif() - if (NOT "Clang" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") target_compile_definitions(${example_target} PRIVATE THRUST_EXAMPLE_DEVICE_SIDE) endif() diff --git a/internal/benchmark/CMakeLists.txt b/internal/benchmark/CMakeLists.txt index 8c59747b8..5fbd365da 100644 --- a/internal/benchmark/CMakeLists.txt +++ b/internal/benchmark/CMakeLists.txt @@ -23,6 +23,7 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) target_link_libraries(${bench_target} PRIVATE ${thrust_target}) target_include_directories(${bench_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") thrust_clone_target_properties(${bench_target} ${thrust_target}) + thrust_configure_cuda_target(${bench_target} RDC ${THRUST_FORCE_RDC}) thrust_fix_clang_nvcc_build_for(${bench_target}) add_dependencies(thrust.all.bench ${bench_target}) diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 0f0749c4e..7f212b324 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -6,14 +6,6 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) add_dependencies(${config_prefix}.all ${config_meta_target}) endforeach() -# Update flags to reflect RDC options. See note in ThrustCudaConfig.cmake -- -# these flag variables behave unintuitively: -if (THRUST_ENABLE_TESTS_WITH_RDC) - set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_RDC}") -else() - set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_NO_RDC}") -endif() - # Generate testing framework libraries: add_subdirectory(unittest) @@ -154,8 +146,8 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) thrust_add_test(test_target ${test_name} "${test_src}" ${thrust_target}) - if (THRUST_ENABLE_TESTS_WITH_RDC AND ("CUDA" STREQUAL "${config_device}")) - thrust_enable_rdc_for_cuda_target(${test_target}) + if ("CUDA" STREQUAL "${config_device}") + thrust_configure_cuda_target(${test_target} RDC ${THRUST_FORCE_RDC}) endif() endforeach() endforeach() diff --git a/testing/async/CMakeLists.txt b/testing/async/CMakeLists.txt index 00d50f097..1fec596f1 100644 --- a/testing/async/CMakeLists.txt +++ b/testing/async/CMakeLists.txt @@ -40,6 +40,7 @@ function(thrust_add_async_test_dir algo_name) foreach(thrust_target IN LISTS cuda_configs) thrust_get_target_property(config_prefix ${thrust_target} PREFIX) + thrust_get_target_property(config_device ${thrust_target} DEVICE) # Per-algorithm, per-config metatarget: thrust.[config].test.async.[algo].all set(algo_config_meta_target ${config_prefix}.test.async.${algo_name}.all) @@ -51,10 +52,9 @@ function(thrust_add_async_test_dir algo_name) string(PREPEND test_name async.${algo_name}.) thrust_add_test(test_target ${test_name} "${test_src}" ${thrust_target}) - if(THRUST_ENABLE_TESTS_WITH_RDC) - thrust_enable_rdc_for_cuda_target(${test_target}) + if ("CUDA" STREQUAL "${config_device}") + thrust_configure_cuda_target(${test_target} RDC ${THRUST_FORCE_RDC}) endif() - add_dependencies(${algo_config_meta_target} ${test_target}) endforeach() endforeach() diff --git a/testing/cuda/CMakeLists.txt b/testing/cuda/CMakeLists.txt index 8fe4a4be7..151abc53d 100644 --- a/testing/cuda/CMakeLists.txt +++ b/testing/cuda/CMakeLists.txt @@ -26,10 +26,11 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) # both device-side behaviors -- the CDP kernel launch with RDC, and the # serial fallback path without RDC. thrust_add_test(seq_test_target ${test_name}.cdp_0 "${test_src}" ${thrust_target}) + thrust_configure_cuda_target(${seq_test_target} RDC OFF) - if (THRUST_ENABLE_TESTS_WITH_RDC) + if (THRUST_ENABLE_RDC_TESTS) thrust_add_test(cdp_test_target ${test_name}.cdp_1 "${test_src}" ${thrust_target}) - thrust_enable_rdc_for_cuda_target(${cdp_test_target}) + thrust_configure_cuda_target(${cdp_test_target} RDC ON) endif() endforeach() endforeach() diff --git a/testing/unittest/CMakeLists.txt b/testing/unittest/CMakeLists.txt index 4c0eb66cb..ec1f851a3 100644 --- a/testing/unittest/CMakeLists.txt +++ b/testing/unittest/CMakeLists.txt @@ -18,7 +18,8 @@ foreach(thrust_target IN LISTS THRUST_TARGETS) target_link_libraries(${framework_target} PUBLIC ${thrust_target}) target_include_directories(${framework_target} PRIVATE "${Thrust_SOURCE_DIR}/testing") thrust_clone_target_properties(${framework_target} ${thrust_target}) - thrust_fix_clang_nvcc_build_for(${framework_target}) - + if ("CUDA" STREQUAL "${config_device}") + thrust_configure_cuda_target(${framework_target} RDC ${THRUST_FORCE_RDC}) + endif() endforeach() diff --git a/thrust/cmake/thrust-config.cmake b/thrust/cmake/thrust-config.cmake index fe88a961c..edfc00ec4 100644 --- a/thrust/cmake/thrust-config.cmake +++ b/thrust/cmake/thrust-config.cmake @@ -699,9 +699,8 @@ if (NOT TARGET Thrust::libcudacxx) ${_THRUST_QUIET_FLAG} 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 + "${_THRUST_INCLUDE_DIR}/../libcudacxx" # Source layout + "${_THRUST_CMAKE_DIR}/.." # Install layout ) # A second required search allows externally packaged to be used and fails if From 0ab6a282d82599aae0158d704763f721666d225a Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Fri, 26 May 2023 11:16:38 -0400 Subject: [PATCH 02/14] Update CMake option docs. --- docs/github_pages/setup/cmake_options.md | 38 +++++------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/docs/github_pages/setup/cmake_options.md b/docs/github_pages/setup/cmake_options.md index b62faddeb..ed7e6bb44 100644 --- a/docs/github_pages/setup/cmake_options.md +++ b/docs/github_pages/setup/cmake_options.md @@ -99,37 +99,13 @@ The CMake options are divided into these categories: ## CUDA Specific CMake Options -- `THRUST_INCLUDE_CUB_CMAKE={ON, OFF}` - - If enabled, the CUB project will be built as part of Thrust. Default is - `OFF`. - - This adds CUB tests, etc. Useful for working on both CUB and Thrust - simultaneously. - - CUB configurations will be generated for each C++ dialect targeted by - the current Thrust build. -- `THRUST_INSTALL_CUB_HEADERS={ON, OFF}` - - If enabled, the CUB project's headers will be installed through Thrust's - installation rules. Default is `ON`. - - This option depends on `THRUST_ENABLE_INSTALL_RULES`. -- `THRUST_ENABLE_COMPUTE_XX={ON, OFF}` - - Controls the targeted CUDA architecture(s) - - Multiple options may be selected when using NVCC as the CUDA compiler. - - Valid values of `XX` are: - `{35, 37, 50, 52, 53, 60, 61, 62, 70, 72, 75, 80}` - - Default value depends on `THRUST_DISABLE_ARCH_BY_DEFAULT`: -- `THRUST_ENABLE_COMPUTE_FUTURE={ON, OFF}` - - If enabled, CUDA objects will target the most recent virtual architecture - in addition to the real architectures specified by the - `THRUST_ENABLE_COMPUTE_XX` options. - - Default value depends on `THRUST_DISABLE_ARCH_BY_DEFAULT`: -- `THRUST_DISABLE_ARCH_BY_DEFAULT={ON, OFF}` - - When `ON`, all `THRUST_ENABLE_COMPUTE_*` options are initially `OFF`. - - Default: `OFF` (meaning all architectures are enabled by default) -- `THRUST_ENABLE_TESTS_WITH_RDC={ON, OFF}` - - Whether to enable Relocatable Device Code when building tests. - Default is `OFF`. -- `THRUST_ENABLE_EXAMPLES_WITH_RDC={ON, OFF}` - - Whether to enable Relocatable Device Code when building examples. - Default is `OFF`. +- `THRUST_ENABLE_RDC_TESTS={ON, OFF}` + - Enable tests that require separable compilation. + - Default is `ON`. +- `THRUST_FORCE_RDC={ON, OFF}` + - Enable separable compilation on all targets that are agnostic of RDC. + - Targets that explicitly require RDC to be enabled or disabled will ignore this setting. + - Default is `OFF`. ## TBB Specific CMake Options From 2e495b9e277c46286604e5fa6755c301e66aae0c Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Thu, 1 Jun 2023 12:18:47 -0400 Subject: [PATCH 03/14] Allow TOPLEVEL_PROJECT logic to be force enabled. --- CMakeLists.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 956178c0a..e78d46212 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,14 +6,9 @@ project(Thrust NONE) # Determine whether Thrust is the top-level project or included into # another project via add_subdirectory() -if(DEFINED CCCL_TOPLEVEL_PROJECT) - set(THRUST_TOPLEVEL_PROJECT ${CCCL_TOPLEVEL_PROJECT}) -else() - if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") - set(THRUST_TOPLEVEL_PROJECT ON) - else() - set(THRUST_TOPLEVEL_PROJECT OFF) - endif() +if (CCCL_TOPLEVEL_PROJECT OR + "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") + set(THRUST_TOPLEVEL_PROJECT ON) endif() ## thrust_fix_clang_nvcc_build_for From c34e0fbd41f61a3ceaa2d6602e7bf2833f43ba0e Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Thu, 1 Jun 2023 17:02:48 -0400 Subject: [PATCH 04/14] Version lock Thrust to other CCCL components. --- thrust/cmake/thrust-config.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thrust/cmake/thrust-config.cmake b/thrust/cmake/thrust-config.cmake index edfc00ec4..20c483919 100644 --- a/thrust/cmake/thrust-config.cmake +++ b/thrust/cmake/thrust-config.cmake @@ -78,7 +78,7 @@ cmake_minimum_required(VERSION 3.15) # Minimum supported libcudacxx version: -set(thrust_libcudacxx_version 1.8.0) +set(thrust_libcudacxx_version "${Thrust_VERSION}") ################################################################################ # User variables and APIs. Users can rely on these: From e62f9fc6a168fd78fb12085a62ab67751676df39 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Fri, 2 Jun 2023 22:09:40 -0400 Subject: [PATCH 05/14] Remove leftover RDC flag tomfoolery. --- testing/cuda/CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/testing/cuda/CMakeLists.txt b/testing/cuda/CMakeLists.txt index 151abc53d..e65a5fc1b 100644 --- a/testing/cuda/CMakeLists.txt +++ b/testing/cuda/CMakeLists.txt @@ -4,14 +4,6 @@ file(GLOB test_srcs *.cu *.cpp ) -# These tests always build with RDC, so make sure that the sm_XX flags are -# compatible. See note in ThrustCudaConfig.cmake. -# TODO once we're using CUDA_ARCHITECTURES, we can setup non-rdc fallback -# tests to build for non-rdc arches. But for now, all files in a given directory -# must build with the same `CMAKE_CUDA_FLAGS` due to CMake constraints around -# how CUDA_FLAGS works. -set(CMAKE_CUDA_FLAGS "${THRUST_CUDA_FLAGS_BASE} ${THRUST_CUDA_FLAGS_RDC}") - foreach(thrust_target IN LISTS THRUST_TARGETS) thrust_get_target_property(config_device ${thrust_target} DEVICE) if (NOT config_device STREQUAL "CUDA") From 4b5d403007c334698f325fa56f7b64334a629ca8 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 12:34:58 -0400 Subject: [PATCH 06/14] Remove temporary warning suppression. --- cmake/ThrustBuildCompilerTargets.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/ThrustBuildCompilerTargets.cmake b/cmake/ThrustBuildCompilerTargets.cmake index 0dd29984a..aa9540d2d 100644 --- a/cmake/ThrustBuildCompilerTargets.cmake +++ b/cmake/ThrustBuildCompilerTargets.cmake @@ -137,7 +137,6 @@ function(thrust_build_compiler_targets) # If using CUDA w/ NVCC... $<$,$>:-Xcudafe=--display_error_number> $<$,$>:-Wno-deprecated-gpu-targets> - $<$:-diag-suppress 128> ) # This is kept separate for Github issue #1174. From fb5226098372db44d2aa34492ad92b27ce43dff6 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 13:28:50 -0400 Subject: [PATCH 07/14] Add `LANGUAGES` keyword to CMake project calls. --- CMakeLists.txt | 2 +- examples/cmake/add_subdir/CMakeLists.txt | 2 +- testing/cmake/test_install/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e78d46212..7c06d8cee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # 3.21 is the minimum for the developer build. cmake_minimum_required(VERSION 3.15) -project(Thrust NONE) +project(Thrust LANGUAGES NONE) # Determine whether Thrust is the top-level project or included into # another project via add_subdirectory() diff --git a/examples/cmake/add_subdir/CMakeLists.txt b/examples/cmake/add_subdir/CMakeLists.txt index 96283699f..576f1df22 100644 --- a/examples/cmake/add_subdir/CMakeLists.txt +++ b/examples/cmake/add_subdir/CMakeLists.txt @@ -13,7 +13,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) cmake_policy(SET CMP0104 OLD) endif() -project(ThrustAddSubDirExample CXX) +project(ThrustAddSubDirExample LANGUAGES CXX) # Add required Thrust systems to THRUST_REQUIRED_SYSTEMS. # Options are: CPP, CUDA, TBB or OMP. diff --git a/testing/cmake/test_install/CMakeLists.txt b/testing/cmake/test_install/CMakeLists.txt index 30cf8405c..6947fe2c1 100644 --- a/testing/cmake/test_install/CMakeLists.txt +++ b/testing/cmake/test_install/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.15) -project(ThrustTestInstall CXX CUDA) +project(ThrustTestInstall LANGUAGES CXX CUDA) # This will eventually get deleted recursively -- keep that in mind if modifying set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install_prefix/") From fe29d3e91fd4d5030985c888030948ce1bab0e20 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 13:31:44 -0400 Subject: [PATCH 08/14] Simplify some genexes and update compiler ID where needed. --- cmake/ThrustBuildCompilerTargets.cmake | 16 ++++++++-------- testing/cuda/stream_per_thread.cmake | 4 ++-- thrust/cmake/thrust-config.cmake | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmake/ThrustBuildCompilerTargets.cmake b/cmake/ThrustBuildCompilerTargets.cmake index aa9540d2d..1e32a52fe 100644 --- a/cmake/ThrustBuildCompilerTargets.cmake +++ b/cmake/ThrustBuildCompilerTargets.cmake @@ -115,13 +115,13 @@ function(thrust_build_compiler_targets) foreach (cxx_option IN LISTS cxx_compile_options) target_compile_options(thrust.compiler_interface INTERFACE $<$:${cxx_option}> - $<$,$>:${cxx_option}> # TODO will this work with the new nvc++ recipe? + $<$:${cxx_option}> # Only use -Xcompiler with NVCC, not NVC++. # # CMake can't split genexs, so this can't be formatted better :( # This is: # if (using CUDA and CUDA_COMPILER is NVCC) add -Xcompiler=opt: - $<$,$>:-Xcompiler=${cxx_option}> + $<$:-Xcompiler=${cxx_option}> ) endforeach() @@ -135,14 +135,14 @@ function(thrust_build_compiler_targets) # Display warning numbers from nvcc cudafe errors: target_compile_options(thrust.compiler_interface INTERFACE # If using CUDA w/ NVCC... - $<$,$>:-Xcudafe=--display_error_number> - $<$,$>:-Wno-deprecated-gpu-targets> + $<$:-Xcudafe=--display_error_number> + $<$:-Wno-deprecated-gpu-targets> ) # This is kept separate for Github issue #1174. add_library(thrust.promote_cudafe_warnings INTERFACE) target_compile_options(thrust.promote_cudafe_warnings INTERFACE - $<$,$>:-Xcudafe=--promote_warnings> + $<$:-Xcudafe=--promote_warnings> ) # Some of our unit tests unconditionally throw exceptions, and compilers will @@ -153,7 +153,7 @@ function(thrust_build_compiler_targets) if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(thrust.silence_unreachable_code_warnings INTERFACE $<$:/wd4702> - $<$,$>:-Xcompiler=/wd4702> + $<$:-Xcompiler=/wd4702> ) endif() @@ -167,11 +167,11 @@ function(thrust_build_compiler_targets) # THRUST_IF_CONSTEXPR to address these warnings. target_compile_options(thrust.compiler_interface_cpp11 INTERFACE $<$:/wd4127> - $<$,$>:-Xcompiler=/wd4127> + $<$:-Xcompiler=/wd4127> ) target_compile_options(thrust.compiler_interface_cpp14 INTERFACE $<$:/wd4127> - $<$,$>:-Xcompiler=/wd4127> + $<$:-Xcompiler=/wd4127> ) endif() diff --git a/testing/cuda/stream_per_thread.cmake b/testing/cuda/stream_per_thread.cmake index 2cea2f938..45e2ff457 100644 --- a/testing/cuda/stream_per_thread.cmake +++ b/testing/cuda/stream_per_thread.cmake @@ -1,13 +1,13 @@ # This test should always use per-thread streams on NVCC. set_target_properties(${test_target} PROPERTIES COMPILE_OPTIONS - $<$,$>:--default-stream=per-thread> + $<$:--default-stream=per-thread> ) thrust_fix_clang_nvcc_build_for(${test_target}) # NVC++ does not have an equivalent option, and will always # use the global stream by default. -if (CMAKE_CUDA_COMPILER_ID STREQUAL "Feta") +if (CMAKE_CUDA_COMPILER_ID STREQUAL "NVHPC") set_tests_properties(${test_target} PROPERTIES WILL_FAIL ON) endif() diff --git a/thrust/cmake/thrust-config.cmake b/thrust/cmake/thrust-config.cmake index 20c483919..74f703d08 100644 --- a/thrust/cmake/thrust-config.cmake +++ b/thrust/cmake/thrust-config.cmake @@ -609,7 +609,7 @@ function(thrust_fixup_omp_target omp_target) get_target_property(opts ${omp_target} INTERFACE_COMPILE_OPTIONS) if (opts MATCHES "\\$<\\$:([^>]*)>") target_compile_options(${omp_target} INTERFACE - $<$,$>:-Xcompiler=${CMAKE_MATCH_1}> + $<$:-Xcompiler=${CMAKE_MATCH_1}> ) endif() endfunction() From d9990fde4813afa7b37061b7139c5b888e1c62a1 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 13:33:35 -0400 Subject: [PATCH 09/14] Remove unnecessary NVC++ tweaks. --- cmake/ThrustBuildTargetList.cmake | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cmake/ThrustBuildTargetList.cmake b/cmake/ThrustBuildTargetList.cmake index 061fbf6d7..d3834fa01 100644 --- a/cmake/ThrustBuildTargetList.cmake +++ b/cmake/ThrustBuildTargetList.cmake @@ -94,14 +94,6 @@ function(thrust_set_target_properties target_name host device dialect prefix) LIBRARY_OUTPUT_DIRECTORY "${THRUST_LIBRARY_OUTPUT_DIR}" RUNTIME_OUTPUT_DIRECTORY "${THRUST_EXECUTABLE_OUTPUT_DIR}" ) - - # TODO is this still needed? - if ("CUDA" STREQUAL "${device}" AND - "NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set_target_properties(${target_name} PROPERTIES - CUDA_RESOLVE_DEVICE_SYMBOLS OFF - ) - endif() endif() endfunction() From 6ffb1616e1ed870869e35a89d938d0db4a1ee95c Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 14:33:20 -0400 Subject: [PATCH 10/14] Add guards against unsupported arch options. --- cmake/ThrustCudaConfig.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmake/ThrustCudaConfig.cmake b/cmake/ThrustCudaConfig.cmake index f71c59540..fc6eaf926 100644 --- a/cmake/ThrustCudaConfig.cmake +++ b/cmake/ThrustCudaConfig.cmake @@ -4,6 +4,17 @@ enable_language(CUDA) # Architecture options: # +# Since we have to filter the arch list based on target features, we don't +# currently support the convenience arch flags: +if ("all" IN_LIST CMAKE_CUDA_ARCHITECTURES OR + "all-major" IN_LIST CMAKE_CUDA_ARCHITECTURES OR + "native" IN_LIST CMAKE_CUDA_ARCHITECTURES) + message(FATAL_ERROR + "The Thrust dev build requires an explicit list of architectures in CMAKE_CUDA_ARCHITECTURES. " + "The convenience flags of 'all', 'all-major', and 'native' are not supported.\n" + "CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}") +endif() + # Create a new arch list that only contains arches that support CDP: set(THRUST_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}) set(THRUST_CUDA_ARCHITECTURES_RDC ${THRUST_CUDA_ARCHITECTURES}) From 7657c7f5b481ab432a2481ee6a2b189df830cf50 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Mon, 5 Jun 2023 14:40:08 -0400 Subject: [PATCH 11/14] Turn on PIC for RDC targets. --- cmake/ThrustUtilities.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/ThrustUtilities.cmake b/cmake/ThrustUtilities.cmake index 8dd53fb31..3b9828dea 100644 --- a/cmake/ThrustUtilities.cmake +++ b/cmake/ThrustUtilities.cmake @@ -33,6 +33,7 @@ function(thrust_configure_cuda_target target_name) if (thrust_cuda_RDC) set_target_properties(${target_name} PROPERTIES CUDA_ARCHITECTURES "${THRUST_CUDA_ARCHITECTURES_RDC}" + POSITION_INDEPENDENT_CODE ON CUDA_SEPARABLE_COMPILATION ON) else() set_target_properties(${target_name} PROPERTIES From 7d9ad9866df77b76e3e95f2be773983f5d86fa7d Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Tue, 6 Jun 2023 17:15:03 -0400 Subject: [PATCH 12/14] Update more CUDA compiler id checks. --- examples/cmake/CMakeLists.txt | 8 -------- testing/cmake/CMakeLists.txt | 8 -------- testing/unittest_static_assert.cmake | 2 +- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/examples/cmake/CMakeLists.txt b/examples/cmake/CMakeLists.txt index 25d2a2f95..42ff63d2a 100644 --- a/examples/cmake/CMakeLists.txt +++ b/examples/cmake/CMakeLists.txt @@ -2,14 +2,6 @@ thrust_update_system_found_flags() set(extra_cmake_flags) -# Need to pass these when testing NVC++. -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(extra_cmake_flags - -D "CMAKE_CUDA_COMPILER_ID=${CMAKE_CUDA_COMPILER_ID}" - -D "CMAKE_CUDA_COMPILER_FORCED=${CMAKE_CUDA_COMPILER_FORCED}" - ) -endif() - if (THRUST_CPP_FOUND AND THRUST_CUDA_FOUND) # Do a basic check of the cmake/ThrustAddSubdir.cmake mechanism: add_test( diff --git a/testing/cmake/CMakeLists.txt b/testing/cmake/CMakeLists.txt index 71798de75..6e8206813 100644 --- a/testing/cmake/CMakeLists.txt +++ b/testing/cmake/CMakeLists.txt @@ -2,14 +2,6 @@ thrust_update_system_found_flags() set(extra_cmake_flags) -# Need to pass these when testing NVC++. -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") - set(extra_cmake_flags - -D "CMAKE_CUDA_COMPILER_ID=${CMAKE_CUDA_COMPILER_ID}" - -D "CMAKE_CUDA_COMPILER_FORCED=${CMAKE_CUDA_COMPILER_FORCED}" - ) -endif() - if (THRUST_CPP_FOUND AND THRUST_CUDA_FOUND) # Test that we can use `find_package` on an installed Thrust: add_test( diff --git a/testing/unittest_static_assert.cmake b/testing/unittest_static_assert.cmake index a8a96f2bd..7902b49a3 100644 --- a/testing/unittest_static_assert.cmake +++ b/testing/unittest_static_assert.cmake @@ -5,6 +5,6 @@ target_link_libraries(${test_target} PRIVATE thrust.silence_unreachable_code_war # The machinery behind this test is not compatible with NVC++. # See https://github.com/NVIDIA/thrust/issues/1397 -if ("NVCXX" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") +if ("NVHPC" STREQUAL "${CMAKE_CUDA_COMPILER_ID}") set_tests_properties(${test_target} PROPERTIES DISABLED True) endif() From 6b373afd9f022c7ff4bd142c7d7f309d7262cb57 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Tue, 6 Jun 2023 18:55:17 -0400 Subject: [PATCH 13/14] Move dev build toggle to the cccl project level. This allows the install rules to be generated for all projects even when the dev builds are disabled. --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c06d8cee..650daf0e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,7 @@ project(Thrust LANGUAGES NONE) # Determine whether Thrust is the top-level project or included into # another project via add_subdirectory() -if (CCCL_TOPLEVEL_PROJECT OR - "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}") set(THRUST_TOPLEVEL_PROJECT ON) endif() From d5ccadeda9716c9f74cbc2a0fb1cfb230b7f3dc4 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Wed, 7 Jun 2023 10:36:59 -0400 Subject: [PATCH 14/14] Remove install tests from Thrust/CUB. These are now handled at the CCCL level, using newer and more robust techniques. --- testing/cmake/CMakeLists.txt | 21 ----- testing/cmake/test_install/CMakeLists.txt | 110 ---------------------- 2 files changed, 131 deletions(-) delete mode 100644 testing/cmake/test_install/CMakeLists.txt diff --git a/testing/cmake/CMakeLists.txt b/testing/cmake/CMakeLists.txt index 6e8206813..294e0e5d4 100644 --- a/testing/cmake/CMakeLists.txt +++ b/testing/cmake/CMakeLists.txt @@ -1,24 +1,3 @@ -thrust_update_system_found_flags() - -set(extra_cmake_flags) - -if (THRUST_CPP_FOUND AND THRUST_CUDA_FOUND) - # Test that we can use `find_package` on an installed Thrust: - add_test( - NAME thrust.test.cmake.test_install - COMMAND "${CMAKE_COMMAND}" - --log-level=VERBOSE - -G "${CMAKE_GENERATOR}" - -S "${CMAKE_CURRENT_SOURCE_DIR}/test_install" - -B "${CMAKE_CURRENT_BINARY_DIR}/test_install" - -D "THRUST_BINARY_DIR=${Thrust_BINARY_DIR}" - -D "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - -D "CMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}" - -D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - ${extra_cmake_flags} - ) -endif() - # Check source code for issues that can be found by pattern matching: add_test( NAME thrust.test.cmake.check_source_files diff --git a/testing/cmake/test_install/CMakeLists.txt b/testing/cmake/test_install/CMakeLists.txt deleted file mode 100644 index 6947fe2c1..000000000 --- a/testing/cmake/test_install/CMakeLists.txt +++ /dev/null @@ -1,110 +0,0 @@ -# Test that an installation of the project can be located by find_package() call -# with appropriate prefix settings. -# -# Expects THRUST_BINARY_DIR to be set to an existing thrust build directory. - -cmake_minimum_required(VERSION 3.15) - -project(ThrustTestInstall LANGUAGES CXX CUDA) - -# This will eventually get deleted recursively -- keep that in mind if modifying -set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install_prefix/") - -function(do_manual_install) - # Inspired by the VTK-m install tests, we can just glob up all of the - # cmake_install.cmake, include (ie. run) them, and they'll effectively - # install the project into the current value of CMAKE_INSTALL_PREFIX. - - # Gather all of the install files from Thrust's root: - file(GLOB_RECURSE install_files - LIST_DIRECTORIES False - "${THRUST_BINARY_DIR}/cmake_install.cmake" - ) - - message(STATUS "Locating install files...") - foreach (install_file IN LISTS install_files) - message(STATUS " * ${install_file}") - endforeach() - - message(STATUS "Building install tree...") - foreach(install_file IN LISTS install_files) - include("${install_file}") - endforeach() -endfunction() - -function(do_cleanup) - message(STATUS "Removing ${CMAKE_INSTALL_PREFIX}") - file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}") -endfunction() - -function(assert_boolean var_name expect) - if (expect) - if (NOT ${var_name}) - message(FATAL_ERROR "'${var_name}' is false, expected true.") - endif() - else() - if (${var_name}) - message(FATAL_ERROR "'${var_name}' is true, expected false.") - endif() - endif() -endfunction() - -function(assert_target target_name) - if (NOT TARGET "${target_name}") - message(FATAL_ERROR "Target '${target_name}' not defined.") - endif() -endfunction() - -function(find_installed_project) - set(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}") - find_package(Thrust CONFIG COMPONENTS CPP CUDA) - - if (NOT Thrust_FOUND) - message(FATAL_ERROR - "find_package(Thrust) failed. " - "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" - ) - endif() - - # Test some internal config vars to check that this is the expected install: - # TODO The cmake_path (3.19) command will provide more robust ways to do this - - # Escape regex special characters in the install prefix, see - # https://gitlab.kitware.com/cmake/cmake/-/issues/18580 - string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" - prefix_regex - "${CMAKE_INSTALL_PREFIX}" - ) - if (NOT _THRUST_INCLUDE_DIR MATCHES "^${prefix_regex}") - message(FATAL_ERROR - "Found Thrust in unexpected location: " - " * _THRUST_INCLUDE_DIR=${_THRUST_INCLUDE_DIR} " - " * ExpectedPrefix=${CMAKE_INSTALL_DIR}" - ) - endif() - if (NOT _CUB_INCLUDE_DIR MATCHES "^${prefix_regex}") - message(FATAL_ERROR - "Found CUB in unexpected location: " - " * _CUB_INCLUDE_DIR=${_CUB_INCLUDE_DIR} " - " * ExpectedPrefix=${CMAKE_INSTALL_DIR}" - ) - endif() - - thrust_create_target(Thrust) - assert_target(Thrust) - assert_target(CUB::CUB) - assert_target(Thrust::CPP::Host) - assert_target(Thrust::CUDA::Device) - - thrust_update_system_found_flags() - assert_boolean(THRUST_CPP_FOUND TRUE) - assert_boolean(THRUST_CUDA_FOUND TRUE) - assert_boolean(THRUST_OMP_FOUND FALSE) - assert_boolean(THRUST_TBB_FOUND FALSE) - -endfunction() - -do_cleanup() # Prepare for new installation -do_manual_install() -find_installed_project() -do_cleanup() # Clean up if successful