[STF] sharded core #10957
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
jrhemstad
Description
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 themhas 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_gpuMGMN) |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
DeviceReduceruns
BlockReducerunsWarpReduce.What this PR adds
A new sibling capability
cudax/include/cuda/experimental/__sharded/(public umbrella
cuda/experimental/sharded.cuh, namespacecuda::experimental::sharded), peer to__multi_gpu, matching theladder 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 mathsharded_array<T>: allocation from explicit specs or from aplace_group(even split or explicit sizes); adoption of existingbuffers under the two-word rule (
adopt= zero-copy view, caller oweslifetime;
from_*= owned storage by copy);allocate_like; hosttransfer;
slicewith place correspondence preserved;each_shardvisitation with exec-place activation;
copy_betweenfor arbitraryre-sharding
allocate_contiguous): shards becomeviews into ONE contiguous VA range whose physical pages are owned per
place (VMM via
places::localized_array). Logical shard boundariesare exact; physical ownership snaps to the allocation granularity.
contiguous_data()hands the whole array to unmodified single-pointerconsumers. 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).or not — a zero size at allocation keeps an empty shard in position
(both
allocateandallocate_contiguous), the same shapecompaction leaves behind; every
(group, data)algorithm pairsshards with places by index.
contiguous_backing_supported(device)is the public capability query behind
allocate_contiguous'sthrow-on-unsupported contract;
release()refuses the VMM backing(a mapping cannot be handed over through raw pointers).
fork_from(cudaStream_t)/join_into(cudaStream_t)— ordering declarations (notsynchronizations) 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 oneshard in its execution context (and
sync()iterates it).Algorithm tier (native, per-place CUB + combine)
fill,sequence,iota,tabulate,generate,for_each,transform(in-place / unary /binary)
reduce/sum/min/max: per-placecub::DeviceReducethrough thegroup's environments, then a combine of the P partials
inclusive_scan/exclusive_scan: per-placecub::DeviceScan, hostprefix 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 boundarycrosses empty shards);
count/count_if;histogram_evencopy_if/filter/remove_if(per-place in-placecub::DeviceSelect::If, stable per-shard compaction, sizes/offsetsupdated, capacities kept);
unique(std::uniquesemantics acrossshard boundaries, O(1) boundary trim against the previous non-empty
shard)
(
std::invalid_argument, array untouched)Every algorithm takes
(place_group&, containers...); temporaries comefrom each shard's own place. Conventions follow the reviewed layer
style: internals in
reserved,_CCCL_HOST_APIon the publicalgorithm surface,
_CCCL_HOST_DEVICE_APIon the device-callableshard<T>members.The CUDA-graph-capture contract (stated in
sharded.rst, enforced, tested)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.
host data or synchronizes throws
std::runtime_errorunder an activecapture, detected via the new safe query
places::stream_in_capture(stream)(one shared guard,places::check_not_capturing) before any CUDA call — so thecapture stays valid and keeps accepting supported work (under
global-mode capture, the first illegal call would otherwise both
error and invalidate the capture).
slice(host-only bookkeeping) are usableduring capture;
place_groupconstruction records nothing.place_memory_resourceallocation isdeliberately 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/hostroundtrips/
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
uniqueruns, and therefuse-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 overby_locality_domains()).Verified on a 2-locality-domain GB300 node (sm_103a, CUDA 13.4):
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_gpucommunicator concept (thebridge between the two rungs),
sharded::sortwith one engine per rung,a row-partitioned sparse tier, and Python bindings.
Checklist
(
docs/cudax/sharded.rst, including the graph-capture section).🤖 Generated with Claude Code