← Back to Pull requests

cub::DeviceTransform: runtime min_bytes_in_flight override through the environment #11857

Open
caugonnet opened this pull request with 291 lines diff across 4 files
View on GitHub
caugonnet caugonnet commented on Oct 05, 2026 11:55 UTC
Author

Description

cub::DeviceTransform sizes its tiles from the policy's min_bytes_in_flight: the dispatch grows items-per-thread until occupancy × tile_bytes reaches 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)});
`

  • cuda::execution::min_bytes_in_flight(bytes) is an env property next to get_stream. A value <= 0 means "use the tuning's value", so an absent property and min_bytes_in_flight(0) behave identically to today.

  • DeviceTransform'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.

  • The value never reaches device code: items per thread is already a kernel argument, so the kernel, its template arguments and its launch bounds are unchanged for every value.

  • Per-call cost is unchanged. The async path used to cache one (items per thread, occupancy) 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 most max_items_per_thread - min_items_per_thread + 1 entries, 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

  • New or existing tests cover these changes: two cases in catch2_test_device_transform_env_api.cu, 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).

  • The documentation is up to date with these changes: a paragraph and a literalinclude in the Tuning section of device_transform.cuh`.
  • 🤖 Generated with Claude Code

    Diff: 291 lines (+248 / -43) across 4 files Reviewer: caugonnet Review duration: 48289m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.62) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.62 · 291 lines diff across 4 files
    0.62
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.93 · 5 substantive comment(s)
    0.93
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.340
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    6 items
    copy-pr-bot[bot] copy-pr-bot[bot] commented on Oct 05, 2026 11:55 UTC
    Bot

    This pull request requires additional validation before any workflows can run on NVIDIA's runners.

    Pull request vetters can view their responsibilities here.

    Contributors can view more details about this message here.

    caugonnet caugonnet commented on code on Oct 05, 2026 12:27 UTC
    Code Review
    cub/test/catch2_test_device_transform_env_api.cu:1
    @@ -61,6 +64,95 @@ CUB_TEST("cub::DeviceTransform::Transform accepts a custom policy selector", "[t
       REQUIRE(d_output == expected);
     }
     
    +CUB_TEST("cub::DeviceTransform::Transform accepts a runtime min_bytes_in_flight override",
    +         "[transform][env]",
    +         CUB_SMALL)
    +{
    +  // example-begin transform-min-bytes-in-flight
    +  auto d_input  = thrust::device_vector<int>{1, 2, 3, 4, 5, 6, 7};
    +  auto d_output = thrust::device_vector<int>(7, thrust::no_init);
    +
    +  // Ask the dispatch to keep at least 192 KiB per SM in flight when sizing the tiles. Unlike a policy selector, this

    we need to be careful that the machine can accomodate such a request, regardless of performance

    caugonnet caugonnet commented on Oct 05, 2026 12:52 UTC
    Author

    pre-commit.ci autofix

    bernhardmgruber bernhardmgruber commented on Oct 05, 2026 14:01 UTC
    Contributor

    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.

    caugonnet caugonnet commented on Oct 06, 2026 09:23 UTC
    Author

    @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 :

  • open an issue to make sure we have methods to provide a (static) parameter, which might already be doable with the current tune infrastructure,

  • open an issue about having finer grain tuning to cope with different SM counts,

  • close this PR
  • Reviewers
    Assignees
    caugonnet caugonnet
    Labels
    risk: low confidence: 81% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.4% (MEDIUM) · Higher = larger blast radius
    62.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81% · Lower = rushed or shallow review
    81%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 11.8% · Safe to merge
    11.8%
    Repository