Skip to content

Commit

Permalink
Misc cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
alliepiper committed Nov 15, 2024
1 parent b09c887 commit d826b67
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
45 changes: 34 additions & 11 deletions lib/cmake/thrust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ If using Thrust from the CCCL sources, this would be
$ cmake . -DThrust_DIR=<CCCL git repo root>/thrust/thrust/cmake/
```

#### Large Array (>2^32 element) Handling: `DISPATCH`

The `DISPATCH` option allows users to select the tradeoff of compile-time / binary-size
vs. performance vs. scalability when given large inputs with greater than 2^32 elements.
This currently only applies when DEVICE=CUDA.

- `Dynamic` Compiles each kernel twice, once for 32-bit offsets and again for 64-bit offsets,
and chooses dynamically using the input size at runtime.
This significantly increases compile-time and binary-size, but provides optimal performance
for small input sizes while also supporting 64-bit indexed workloads.
- `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 may degrade runtime performance
for 32-bit indexed workloads.

#### TBB / OpenMP

To explicitly specify host/device systems, `HOST` and `DEVICE` arguments can be
Expand All @@ -56,33 +72,40 @@ host system, but will find and use TBB or OpenMP for the device system.

To allow a Thrust target to be configurable easily via `cmake-gui` or
`ccmake`, pass the `FROM_OPTIONS` flag to `thrust_create_target`. This will add
`THRUST_HOST_SYSTEM` and `THRUST_DEVICE_SYSTEM` options to the CMake cache that
allow selection from the systems supported by this version of Thrust.
`THRUST_HOST_SYSTEM`, `THRUST_DEVICE_SYSTEM`, and `THRUST_DISPATCH_TYPE` options
to the CMake cache that allow selection from the systems supported by this version
of Thrust.

```cmake
thrust_create_target(Thrust FROM_OPTIONS
[HOST_OPTION <option name>]
[DEVICE_OPTION <option name>]
[DISPATCH_OPTION <option name>]
[HOST_OPTION_DOC <doc string>]
[DEVICE_OPTION_DOC <doc string>]
[DISPATCH_OPTION_DOC <doc string>]
[HOST <default host system name>]
[DEVICE <default device system name>]
[DISPATCH <default device system name>]
[ADVANCED]
)
```

The optional arguments have sensible defaults, but may be configured per
`thrust_create_target` call:

| Argument | Default | Description |
|---------------------|-------------------------|---------------------------------|
| `HOST_OPTION` | `THRUST_HOST_SYSTEM` | Name of cache option for host |
| `DEVICE_OPTION` | `THRUST_DEVICE_SYSTEM` | Name of cache option for device |
| `HOST_OPTION_DOC` | Thrust's host system. | Docstring for host option |
| `DEVICE_OPTION_DOC` | Thrust's device system. | Docstring for device option |
| `HOST` | `CPP` | Default host system |
| `DEVICE` | `CUDA` | Default device system |
| `ADVANCED` | *N/A* | Mark cache options advanced |
| Argument | Default | Description |
|-----------------------|-------------------------|-----------------------------------|
| `HOST_OPTION` | `THRUST_HOST_SYSTEM` | Name of cache option for host |
| `DEVICE_OPTION` | `THRUST_DEVICE_SYSTEM` | Name of cache option for device |
| `DISPATCH_OPTION` | `THRUST_DISPATCH_TYPE` | Name of cache option for dispatch |
| `HOST_OPTION_DOC` | Thrust's host system. | Docstring for host option |
| `DEVICE_OPTION_DOC` | Thrust's device system. | Docstring for device option |
| `DISPATCH_OPTION_DOC` | Thrust's dispatch type. | Docstring for dispatch option |
| `HOST` | `CPP` | Default host system |
| `DEVICE` | `CUDA` | Default device system |
| `DISPATCH` | `Dispatch` | Default dispatch type |
| `ADVANCED` | *N/A* | Mark cache options advanced |

### Specifying Thrust Version Requirements

Expand Down
17 changes: 2 additions & 15 deletions lib/cmake/thrust/thrust-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#
# Provided by NVIDIA under the same license as the associated Thrust library.
#
# Reply-To: Allison Piper <[email protected]>
#
# *****************************************************************************
# ** The following is a short reference to using Thrust from CMake. **
# ** For more details, see the README.md in the same directory as this file. **
Expand Down Expand Up @@ -62,18 +60,7 @@
# IGNORE_CUB_VERSION # Skip configure-time and compile-time CUB version checks
# )
#
# # DISPATCH options [Advanced]:
# #
# # Controls how Thrust handles large (>2^32 element) inputs. The default is `Dynamic`.
# # This only applies when DEVICE=CUDA.
# #
# # - `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.
# # DISPATCH options (See README):
# thrust_create_target(TargetName DISPATCH Dynamic)
# thrust_create_target(TargetName DISPATCH Force32bit)
# thrust_create_target(TargetName DISPATCH Force64bit)
Expand Down Expand Up @@ -188,7 +175,7 @@ function(thrust_create_target target_name)
_thrust_set_if_undefined(TCT_DISPATCH Dynamic)
_thrust_set_if_undefined(TCT_HOST_OPTION THRUST_HOST_SYSTEM)
_thrust_set_if_undefined(TCT_DEVICE_OPTION THRUST_DEVICE_SYSTEM)
_thrust_set_if_undefined(TCT_DISPATCH_OPTION THRUST_DISPATCH_TYPE)
_thrust_set_if_undefined(TCT_DISPATCH_TYPE THRUST_DISPATCH_TYPE)
_thrust_set_if_undefined(TCT_HOST_OPTION_DOC "Thrust host system: ${THRUST_HOST_SYSTEM_OPTIONS}")
_thrust_set_if_undefined(TCT_DEVICE_OPTION_DOC "Thrust device system: ${THRUST_DEVICE_SYSTEM_OPTIONS}")
_thrust_set_if_undefined(TCT_DISPATCH_OPTION_DOC "Thrust dispatch type: ${THRUST_DISPATCH_TYPE_OPTIONS}")
Expand Down

0 comments on commit d826b67

Please sign in to comment.