← Back to Pull requests

[STF] sharded core #10957

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Aug 23, 2026 20:17 UTC
Author

Description

Stacked on #10956 (place_group). The base is that PR's CI branch (pull-request/10956), so this diff shows exactly this PR's own 4 commits (containers / algorithms / fork-join / capture contract). Once #10956 merges, the base will be retargeted to main — the diff is unchanged by that.

Motivation

CUB's structural invariant is that the primitive at scope N runs scope
N−1's primitive locally and combines using what scope N shares: warp
(registers/shuffles) → block (shared memory) → device (global memory).
Above the device, CCCL today offers the multi-process ranks rung
(__multi_gpu: nothing shared, message passing). One rung between them
has no programming surface: several places INSIDE one process — locality
domains, green-context places, devices-as-places — which still share one
virtual address space with placed pages. Users who partition data across
locality domains today hand-roll per-place allocation, per-place kernel
dispatch, per-place CUB calls and the cross-place combine, plus all the
stream ordering between them.

The framing: CUB's cooperation-scope ladder, extended

CUB's structural invariant: the primitive at scope N = scope N−1's
primitive run locally + a combine using what scope N shares.

| scope | what is shared | combine mechanism | primitives |
|---|---|---|---|
| warp | registers | shuffles | WarpReduce, WarpScan, ... |
| block | shared memory | smem staging | BlockReduce, BlockScan, ... |
| device | global memory | global staging | DeviceReduce, DeviceScan, ... |
| places (one process) | one VA, placed pages | in-place fold over the shared address space | sharded algorithms — this PR (__sharded) |
| ranks (multi-process / multi-node) | nothing | message passing | communicator algorithms (__multi_gpu MGMN) |

Each rung owns its combine. Sharded containers exist exactly at the
highest rung that still shares an address space; where nothing is
shared, the MGMN communicator algorithms take over. The two surfaces are
scoped by rung and compose: hierarchical multi-process +
placed-per-process is ordinary rung nesting, the same way DeviceReduce
runs BlockReduce runs WarpReduce.

What this PR adds

A new sibling capability cudax/include/cuda/experimental/__sharded/
(public umbrella cuda/experimental/sharded.cuh, namespace
cuda::experimental::sharded), peer to __multi_gpu, matching the
ladder 1:1. It builds only on the places layer and place_group
(#10956).

Container tier

  • shard<T>: one placed piece — data/size/capacity/global_offset +

  • data_place/exec_place/reference stream + global↔local index math
  • sharded_array<T>: allocation from explicit specs or from a

  • place_group (even split or explicit sizes); adoption of existing
    buffers under the two-word rule (adopt = zero-copy view, caller owes
    lifetime; from_* = owned storage by copy); allocate_like; host
    transfer; slice with place correspondence preserved; each_shard
    visitation with exec-place activation; copy_between for arbitrary
    re-sharding
  • Contiguous backing contract (allocate_contiguous): shards become

  • views into ONE contiguous VA range whose physical pages are owned per
    place (VMM via places::localized_array). Logical shard boundaries
    are exact; physical ownership snaps to the allocation granularity.
    contiguous_data() hands the whole array to unmodified single-pointer
    consumers. Shard sizes are fixed: size-mutating operations refuse
    such arrays (documented and enforced with a throw). One VA also
    means one physical home per byte — the container holds partitioned
    data only; replicated operands belong to the binding tier (STF
    logical_data).
  • Place correspondence invariant: one shard per group place, empty

  • or not — a zero size at allocation keeps an empty shard in position
    (both allocate and allocate_contiguous), the same shape
    compaction leaves behind; every (group, data) algorithm pairs
    shards with places by index. contiguous_backing_supported(device)
    is the public capability query behind allocate_contiguous's
    throw-on-unsupported contract; release() refuses the VMM backing
    (a mapping cannot be handed over through raw pointers).
  • Stream composition: fork_from(cudaStream_t) /

  • join_into(cudaStream_t) — ordering declarations (not
    synchronizations) bridging a caller stream and the per-shard streams
    via a container-owned lazy event pool; correct for adopted arrays with
    foreign streams; capture-safe. sync(shard_idx) synchronizes one
    shard in its execution context (and sync() iterates it).

    Algorithm tier (native, per-place CUB + combine)

  • Elementwise (no cross-place stage): fill, sequence, iota,

  • tabulate, generate, for_each, transform (in-place / unary /
    binary)
  • reduce/sum/min/max: per-place cub::DeviceReduce through the

  • group's environments, then a combine of the P partials
  • inclusive_scan/exclusive_scan: per-place cub::DeviceScan, host

  • prefix of the P shard totals, in-place prefix fold over the shared
    address space. Init and identity are distinct: inclusive custom-op
    scans need no identity (the prefix chain folds the preceding
    non-empty shards' totals), custom-op exclusive scans take init AND
    identity explicitly (locals run with the identity; the init seeds the
    global sequence exactly once); no equality requirement on the value
    type
  • adjacent_difference (aliasing refused; the predecessor boundary

  • crosses empty shards); count/count_if; histogram_even
  • copy_if/filter/remove_if (per-place in-place

  • cub::DeviceSelect::If, stable per-shard compaction, sizes/offsets
    updated, capacities kept); unique (std::unique semantics across
    shard boundaries, O(1) boundary trim against the previous non-empty
    shard)
  • Size-mutators enforce the contiguous-backing contract

  • (std::invalid_argument, array untouched)

    Every algorithm takes (place_group&, containers...); temporaries come
    from each shard's own place. Conventions follow the reviewed layer
    style: internals in reserved, _CCCL_HOST_API on the public
    algorithm surface, _CCCL_HOST_DEVICE_API on the device-callable
    shard<T> members.

    The CUDA-graph-capture contract (stated in sharded.rst, enforced, tested)

  • Captures: the non-blocking elementwise family — pure per-shard

  • kernel launches — with the standard fork/join idiom
    (fork_from/join_into). Pinned by tests: per-place (green-context)
    SM confinement survives inside the instantiated graph (SM-id
    check across two locality domains); replays recompute from current
    contents; cross-stream dependencies inside capture work; contiguous
    arrays are transparent to capture and per-shard stages compose with
    whole-array kernels in one graph.
  • Refuses cleanly: everything that allocates containers, transfers

  • host data or synchronizes throws std::runtime_error under an active
    capture, detected via the new safe query
    places::stream_in_capture(stream) (one shared guard,
    places::check_not_capturing) before any CUDA call — so the
    capture stays valid and keeps accepting supported work (under
    global-mode capture, the first illegal call would otherwise both
    error and invalidate the capture).
  • Benign: adoption and slice (host-only bookkeeping) are usable

  • during capture; place_group construction records nothing.
  • Graph-owned memory: place_memory_resource allocation is

  • deliberately left capturable (a graph mem-alloc node from the place's
    pool); both the balanced-pair and the unfreed-allocation shapes are
    pinned by tests. The documented user contract stays simple: allocate
    outside capture; capture computation only.

    Tests

    cudax/test/sharded/: containers (allocation/index math/host
    roundtrips/copy_between/adoption+slicing/contract throws), contiguous
    (exact boundaries, per-shard writes read by one whole-range kernel
    through the base pointer, and the reverse), elementwise + reduce/scan vs
    host references over locality domains, count/histogram, compaction
    (incl. empty-result shards, boundary-straddling unique runs, and the
    refuse-on-contiguous negative tests), fork/join (eager
    producer→fork→consumers→join→reader with one host sync, adopted-array
    over foreign streams, capture instantiate+relaunch, degenerate no-ops),
    in-place value mutation, external-stream lifecycle, and the 5
    graph-capture suites ({elementwise_pipeline, reduce_scan_capture,
    must_not_capture, graph_owned_memory, contiguous_capture}). Example:
    cudax/examples/places/sharded_reduce.cu (256M elements over
    by_locality_domains()).

    Verified on a 2-locality-domain GB300 node (sm_103a, CUDA 13.4):

    cmake --preset=cudax -DCMAKE_CUDA_ARCHITECTURES=103a -Dcudax_ENABLE_NCCL=OFF
    ninja -C build/cudax cudax.test.sharded cudax.test.places cudax.example.places
    ctest --test-dir build/cudax -R "cudax\.test\.(places|sharded)"
    

    Launch build tally: 30/30 places+sharded ctest green (17 places + 8 sharded + 5 graph-capture suites); every intermediate commit compiles standalone.

    Sequenced next

    Prepared as follow-ups in this series: a
    places-scoped model of the __multi_gpu communicator concept (the
    bridge between the two rungs), sharded::sort with one engine per rung,
    a row-partitioned sparse tier, and Python bindings.

    Checklist

  • New or existing tests cover these changes.

  • The documentation is up to date with these changes

  • (docs/cudax/sharded.rst, including the graph-capture section).

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jrhemstad Review duration: 87009m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #10957"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 59% (MEDIUM) · Higher = larger blast radius
    59%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 32.6% · Safe to merge
    32.6%
    Repository