Repository navigation
MMA walks build their own instruction descriptor - #34
Merged
Merged
Conversation
Two facts the instruction descriptor needs that its operands already know. `MmaElement::ELEMENT_TYPE` sits beside `MMA_KIND` because f16 and bf16 share kind 0 and are told apart only by the descriptor's atype/btype. `OperandWalk` carries the transpose bit its layout implies — the same fact as its chunk step and leading offset — so a kernel that picks K-major vs MN-major at runtime moves the walk and the instruction together.
Each walk requires a different transpose configuration and nothing checked the raw `u32` descriptor against it; a mismatch does not fault, it fills the accumulator with wrong numbers. The walks now take an `MmaShape` — the one field they cannot know, since it is the caller's accumulator band — and build the descriptor from their own transpose configuration plus `E::ELEMENT_TYPE`. `mma_walk_cg2` reads its bits from `OperandWalk::transposed` so a runtime layout choice stays paired, and takes `E` from the caller because a walk has erased it (#12 owns whether the walk carries it back, since routing `KIND` wants it as a type there anyway). The accumulator stays fp32: a walk names TMEM by a bare `u32`, so there is no accumulator type to read one off. First host tests of the descriptor: it is pure bit arithmetic, so the encoding is checked against the PTX field layout spelled out independently of the builder.
device-tests, gemm and flash_forward each hand-built a descriptor and relied on prose to keep it matched to the walk. All three now pass an `MmaShape`.
# Conflicts: # device-tests/src/main.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mma_abt,mma_abandmma_walk_cg2each read their operands under adifferent transpose configuration, and each took the instruction descriptor as
a raw
u32the caller assembled. Mismatching the two does not fault — the MMAreinterprets the operands and fills the accumulator with wrong numbers — and
the only thing standing between a kernel and that was a paragraph in
mma.rs'sheader. The walks now build the descriptor themselves.
The API
MmaShapeiscuda_device'sTcgen05MmaShape, re-exported fromkittens::mmaso a kernel names one thing rather than four.
Derived from the function you called. The transpose bits.
mma_abtpasses(false, false)andmma_ab(false, true)to a privatedescriptor<E>helper; neither is expressible by a caller any more.
Derived from the operands. The element type, through a new
MmaElement::ELEMENT_TYPEbesideMMA_KIND. The two are genuinely differentfields: f16 and bf16 share
KIND0 and are told apart only by the descriptor'satype/btype, so a bf16 tile under anF16descriptor was a silentmiscompute the type system can now rule out.
Tcgen05ElementTypehas exactlythree values upstream (F16/BF16/TF32), all reachable from an
MmaElement, sothe const is total rather than a bf16-shaped stub.
Left to the caller. The shape, because it names the accumulator band the
caller allocated and the CTA-group mode — nothing in the operands knows it.
mma_walk_cg2Split into the two fields rather than treated as one question:
Transpose bits: derived.
OperandWalkgained atransposeflag set byk_walk(false) /mn_walk(true) and read back throughOperandWalk::transposed. This is the case the issue is really about: gemmpicks K-major vs MN-major at runtime, so the descriptor bits are runtime
data too, and a caller-side descriptor could not be checked against the walk
even in principle. The flag is the same fact as the walk's chunk step and
leading offset, so it belongs in the walk; it costs two
ORs that hoist outof the chain.
Element: still the caller's, as
mma_walk_cg2::<Bf16, CHUNKS>. AnOperandWalkhas erased its element, and I did not force it back:as a
constto routeKIND, and a value cannot drive a const-generic;OperandWalk<E>would answer MMA: AtB/AtBt walks, mm entry points, generic KIND routing #12's open question ("whether thewalk carries the kind or the caller does") unilaterally, and MMA: AtB/AtBt walks, mm entry points, generic KIND routing #12 should
stay separable.
Since
CHUNKSis turbofished anyway, the caller has to writeEeither way,and a type parameter is what MMA: AtB/AtBt walks, mm entry points, generic KIND routing #12 will need at this call site regardless. It
is a narrower assertion than before —
Bf16, in the same vocabulary as thetiles, not descriptor bits — but it is still an assertion, and I would rather
say so than pretend the symmetry is there.
Accumulator type
Left hardcoded fp32, documented at the helper. The walks name TMEM by a bare
u32, so there is no accumulator type to derive one from; fp16 accumulation isa
.kind::f16-only mode no kernel here uses. Deriving it means giving thewalks a
TmemTileinstead of an address, which is a real refactor of everysignature and belongs with whatever issue does that — not this one.
Verified
modal run modal_app.py(B200), once, at the end: 7 of 7 cases pass.The
fragment mapcases issue realmma_abts, so a wrongly built descriptorshows up as wrong values — this is the check that the change is correct, not
just well-typed.
modal run modal_app.py::build: library clippy (--features host --all-targets), host tests, harness clippy, and realcargo oxide build --arch sm_100afor bothdevice-testsandkittens-examples.const fnbit arithmetic with nodevice intrinsic behind it, so it does test on the host. Two new cases in
mma.rs— the three shipped configurations encoded against the PTX fieldlayout written out independently of the builder, and the walks' transpose
flags. 35 tests pass.
cargo clippy --all-targets,cargo fmt --checkclean.Examples
gemm(hard requirement: it compiled before and must after) still buildsfor
sm_100a— verified throughcargo oxide build, notcargo check. Itssix-line descriptor block is one
let shape = MmaShape::M256_N128;, and thecomment that used to explain why the transpose bits were absent is now a
statement about where they come from.
flash_forward(aspirational,--features flash) updated the same way:two shapes instead of two hand-built descriptors, including the
transpose_bit had to remember for
mma_ab. Still aspirational, still blocked on thesame issues — this was never what blocked it.
examples/README.md: §9's descriptor bullet is gone, and the fix isrecorded under "what the examples confirm already works", with the cg2
element noted as the one field a caller still states. The status table is
unchanged: nothing moved between
compilesandaspirational.Closes #30