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
13 changes: 13 additions & 0 deletions docs/thrust/cmake_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ 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
large inputs and optimal performance at the cost of increased compile time and binary size,
as Thrust will compile each kernel twice, once for 32 bit and once for 64 bit.
- ``Force32bit`` forces Thrust to use a 32 bit offset type. This improves compile time and
binary size but limits the input size.
- ``Force64bit`` forces Thrust to use a 64 bit offset type. This improves compile time and
binary size and allows large input sizes. However, it might degrade runtime performance.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FORCE here means that a user can't override the value

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option is not visible to users consuming our CMake packages (e.g. CPM, find_package(CCCL), add_subdirectory(...), etc). They're only visible in the developer build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this option to be usable when consuming CCCL from libcudf. That was the purpose of introducing this, in #1958.

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_32_BIT_OFFSET_TYPE")
elseif (THRUST_DISPATCH_TYPE STREQUAL "Force64bit")
list(APPEND cxx_compile_definitions "THRUST_FORCE_64_BIT_OFFSET_TYPE")
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_32_BIT_OFFSET_TYPE")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These header tests are linked to the interface targets built in ThrustBuildCompilerTargets.cmake, which already may have these options set, potentially to conflicting values.

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_64_BIT_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