Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the thrust dispatch mechanisms configurable #2310

Merged
merged 13 commits into from
Aug 30, 2024
11 changes: 11 additions & 0 deletions docs/thrust/cmake_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ Generic CMake Options
- If true, installation rules will be generated for thrust. Default
is ``ON``.

- ``THRUST_DISPATCH_TYPE={Dynamic, Force32bit, Force64bit}``

- Allows the user to force Thrust to use a specific size for the offset type. Default
is ``Dynamic``.
- ``Dynamic`` lets thrust choose the index type based on input size, allowing
miscco marked this conversation as resolved.
Show resolved Hide resolved
large inputs and optimal performance at the cost of increased compile time and binary size
miscco marked this conversation as resolved.
Show resolved Hide resolved
- ``Force32bit`` forces Thrust to use a 32bit offset type. This improves compile time and
miscco marked this conversation as resolved.
Show resolved Hide resolved
binary size but limits the input size.
- ``Force32bit`` forces Thrust to use a 64bit offset type. This improves compile time and
miscco marked this conversation as resolved.
Show resolved Hide resolved
binary size and allow large input sizes. However, it might degrade runtime performance
miscco marked this conversation as resolved.
Show resolved Hide resolved

Single Config CMake Options
---------------------------

Expand Down
4 changes: 4 additions & 0 deletions thrust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ option(THRUST_ENABLE_TESTING "Build Thrust testing suite." "ON")
option(THRUST_ENABLE_EXAMPLES "Build Thrust examples." "ON")
option(THRUST_ENABLE_BENCHMARKS "Build Thrust runtime benchmarks." "${CCCL_ENABLE_BENCHMARKS}")

# Allow the user to optionally select offset type dispatch to fixed 32 or 64 bit types
set(THRUST_DISPATCH_TYPE "Dynamic" CACHE STRING "Select thrust offset type dispatch." FORCE)
miscco marked this conversation as resolved.
Show resolved Hide resolved
set_property(CACHE THRUST_DISPATCH_TYPE PROPERTY STRINGS "Dynamic" "Force32bit" "Force64bit")

# Check if we're actually building anything before continuing. If not, no need
# to search for deps, etc. This is a common approach for packagers that just
# need the install rules. See GH issue NVIDIA/thrust#1211.
Expand Down
6 changes: 6 additions & 0 deletions thrust/cmake/ThrustBuildCompilerTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ function(thrust_build_compiler_targets)
)
endforeach()

if (THRUST_DISPATCH_TYPE STREQUAL "Force32bit")
list(APPEND cxx_compile_definitions "THRUST_FORCE_32BIT_OFFSET_TYPE")
miscco marked this conversation as resolved.
Show resolved Hide resolved
elseif (THRUST_DISPATCH_TYPE STREQUAL "Force64bit")
list(APPEND cxx_compile_definitions "THRUST_FORCE_64BIT_OFFSET_TYPE")
miscco marked this conversation as resolved.
Show resolved Hide resolved
endif()

foreach (cxx_definition IN LISTS cxx_compile_definitions)
# Add these for both CUDA and CXX targets:
target_compile_definitions(thrust.compiler_interface INTERFACE
Expand Down
13 changes: 13 additions & 0 deletions thrust/cmake/ThrustHeaderTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ foreach(thrust_target IN LISTS THRUST_TARGETS)
"CUB_WRAPPED_NAMESPACE=wrapped_cub")
thrust_add_header_test(${thrust_target} base "${header_definitions}")

# We need to ensure that the different dispatch mechanisms work
set(header_definitions
"THRUST_WRAPPED_NAMESPACE=wrapped_thrust"
"CUB_WRAPPED_NAMESPACE=wrapped_cub"
"THRUST_FORCE_32BIT_OFFSET_TYPE")
thrust_add_header_test(${thrust_target} offset_32 "${header_definitions}")

set(header_definitions
"THRUST_WRAPPED_NAMESPACE=wrapped_thrust"
"CUB_WRAPPED_NAMESPACE=wrapped_cub"
"THRUST_FORCE_64BIT_OFFSET_TYPE")
thrust_add_header_test(${thrust_target} offset_64 "${header_definitions}")

thrust_get_target_property(config_device ${thrust_target} DEVICE)
if ("CUDA" STREQUAL "${config_device}")
# Check that BF16 support can be disabled
Expand Down
Loading
Loading