cub::DeviceTransform: runtime min_bytes_in_flight override through the environment #11857
we need to be careful that the machine can accomodate such a request, regardless of performance
pre-commit.ci autofix
Policy selectors are stateless types, so every value instantiates a new kernel
This is correct and by design. I understand that this may not be ideal, since some tuning values aren't needed for compile-time decisions. But the design is uniform and somewhat simple.
which rules out trying values at runtime.
Can you please provide more motivation for why a compile-time value and a possible compilation of several device transform instantiations is a big blocker? If we allow a runtime value to be passed here as an extra environment property, we'll probably have users asking to add more. I would rather do a clean design for runtime-only tuning properties first.
@bernhardmgruber I agree : if we assume autotuning needs to scan a bunch of kernel variants, and that we tune a graph of kernels (not a single kernel), the cleaner/simpler strategy might be to wait for @gevtushenko 's host jit and then defer the overhead to the autotuning case (which is by far not the most common case and will absorb overheads by definition), and then once we have decided what parameters to pick it's probably ok to do that at compile time, or with a bit more of JIT. So that would keep design as simple as it needs to be.
Appropriate default tuning per number of SMs is a second (related) issue to have optimal performance out of the box on different SKUs or locality domains.
I'll :
caugonnet
Description
cub::DeviceTransformsizes its tiles from the policy'smin_bytes_in_flight: the dispatch grows items-per-thread untiloccupancy × tile_bytesreaches that target. The constant is tuned per architecture for a full-device launch. It is not the right value when a launch does not own the whole device (a stream created from a green context that owns a subset of the SMs, two SM partitions each running their own transform, …), and more generally it is the one knob an autotuner would want to turn for a memory-bound transform.Today the only way to change it is a policy selector passed through
cuda::execution::tune(...). Policy selectors are stateless types, so every value instantiates a new kernel, which rules out trying values at runtime.This PR adds a runtime override through the environment:
``
c++
`cub::DeviceTransform::Transform(
in, out, n, op,
cuda::std::execution::env{cuda::get_stream(stream), cuda::execution::min_bytes_in_flight(192 * 1024)});
is an env property next toget_stream. A value<= 0means "use the tuning's value", so an absent property andmin_bytes_in_flight(0)behave identically to today.'s env overloads read it and the dispatch uses it in place of the policy's value, in both the async (ublkcp/ldgsts) and the prefetch/vectorized paths. Only the host-side grid configuration changes; the kernel and its template arguments are untouched.result per kernel in a function-local static, which cannot work with a per-call target. Instead, the static now holds a target-independent table: the occupancy for every items-per-thread the policy allows (at mostmax_items_per_thread - min_items_per_thread + 1entries, 32 by default) plus the SM count, filled once per kernel. The per-call search for the first tile that reaches the target walks that table, which is arithmetic. For the default target the chosen configuration is identical to before. The prefetch path already cached only target-independent data.No behaviour change without the property. No performance numbers in this description; the motivating measurements (SM-partitioned launches) are available on request.
Possible follow-ups, kept out of this PR on purpose: deriving a default from the SM count the stream actually owns; bounding the items-per-thread search so that a large target cannot reduce the achieved bytes in flight through an occupancy drop (visible in the table: past the point where the SMEM tile stops fitting 7 times, occupancy falls and so does the product); and letting the property carry a compile-time constant for callers that have one.
Checklist
, one through the public API (also the documentation example), one at the dispatch level with a recording launcher factory that checks a tiny target yields at least as many blocks as the default, a huge one at most as many, and that the override does not leak into a following call, and one that alternates two different targets in both orders and checks each call launches the grid of its own target (the configuration cache keys on the target).in the Tuning section ofdevice_transform.cuh`.🤖 Generated with Claude Code