Repository navigation
feat(access): derive tile shape from a target transaction width - #545
Conversation
9348cb2 to
1b0995e
Compare
|
Turned the Since asserting |
|
An addition to the "Scope — what this does not claim" section, from inventorying CCCL 13.2.27's headers. The scope note says a plan describes the shape a width needs, not a width the kernel is guaranteed to get, because touching individual lanes lets the optimiser split the local apart and load the lanes separately. That is still accurate. What I did not know when writing it is that CUB does not treat this as a dead end — it changes the layout instead of fighting the optimiser.
So there are two layouts, not one: striped for the read (coalesced, and vectorizable precisely because nothing decomposes it there) and blocked for the arithmetic (one thread's items contiguous), bridged by an exchange. The decomposition that defeats a widened load happens after the exchange, on registers that never came from a wide load instruction. That does not change what this module computes — the arithmetic relating width, element size and launch shape is the same either way, and |
min_extent(other) only required other to divide elems_per_block, never that elems_per_thread divides other. That admitted shape-impossible extents on a strided operand: plan::<f16>(TXN_128, 128) gives 8 elements per thread, yet min_extent(4) returned Some(256) even though a row of 4 f16 (8 bytes) cannot hold one thread's 16-byte access. CUTLASS enforces exactly this divisibility (the access width divides the contiguous extent). Add the missing check, returning None in the module's own no-silent- rounding idiom, and reword the doc from the contiguous-tile model (which would admit lcm-based extents the function refuses, e.g. other=48 at 512 elems/block) to the strided model the function actually implements. Also carry the contributor's follow-up from PR NVIDIA#512 into the Scope note: the width is unreachable only through a direct blocked load; CUB's BLOCK_LOAD_VECTORIZE reaches it by loading striped with wide loads and exchanging through shared memory into the blocked layout. That exchange primitive does not exist in cuda-oxide yet, so the note records the gap as a missing layout change rather than an alignment dead end.
Give the new access module an in-repo consumer: a const assertion in the vectorization example derives f32x4_view_copy's shape from access::plan::<f32>(TXN_128, N) instead of restating it by hand - one 4-element quad per thread, F32x4's 16-byte alignment, and the flat N * 4 buffer moved in exactly one block-wide pass. A shape drift now fails at compile time. N is hoisted to module scope so the plan and the launch share the same thread count.
|
Thanks, Two commits on top:
The vectorization example now derives its shape through Merging. |
Transaction width is a consequence of element alignment, so a kernel cannot request it. That makes the useful question the inverted one — given the width I want, what must the tile shape be? This adds the
constarithmetic for that direction.Why
The
gemm_solexample already does this derivation by hand, in a comment (crates/rustc-codegen-cuda/examples/gemm_sol/src/main.rs:313):A 128-bit transaction of f16 is 8 elements, 128 rows move 1024 elements per group, and run against a
K = 32tile that forcesM >= 1024 / 32 = 32— which is how CUTLASS states the constraint for a row-major A operand at 128 threads and 8-element access. Every step is arithmetic on width, element size, and launch shape, so it can be computed rather than re-reasoned per kernel. A test reproduces exactly that derivation, so the module's stated justification cannot drift from its code.API
plan::<T>(txn_bytes, threads)min_extent(other)fits_tile/passes_for_tilewidest::<T>(tile_elems, threads)Everything is
const, so a plan can drive aconstgeneric or sit in aconst {}assertion and turn a tile shape that cannot reach the intended width into a compile error rather than a silent narrowing.Scope — what this does not claim
It answers "what shape does this width need", not "will I get this width". Measured on sm_86 with the element type 16-byte aligned throughout:
So alignment is a necessary condition and, for loads, not a sufficient one: touching individual lanes lets the optimiser split the local apart and load the lanes separately whatever the alignment. Stores have no such condition. A plan therefore describes the shape a width needs, not a width the kernel is guaranteed to get — the data has to move as whole elements as well. The module docs say this, and point at the
vectorizationexample for the alignment half.Verification
fmt --check,clippy --workspace --all-targets -D warnings,RUSTDOCFLAGS='-D warnings' cargo doc, andcargo test -p cuda-deviceclean onnightly-2026-04-03.