Repository navigation
MMA: AtB/AtBt walks, mm entry points, generic KIND routing - #69
Merged
Merged
Conversation
`mma_atb` and `mma_atbt` complete `{AB, ABt, AtB, AtBt}`; every walk gets an
`mm_*` twin that starts the accumulator fresh rather than taking a `bool`; and
the walks now issue through `MmaElement::mma`/`mma_cg2`, which routes tcgen05's
`KIND` off the element instead of calling the f16-specialized wrapper.
Nothing in this repo calls the new walks, and an unused walk that is wrong is
worse than an absent one — so most of this is the check. `device-tests` runs
all four orders over one pair of logical matrices staged four ways (no TMA box
transposes) and requires the same product from each. `walk blind spots` runs on
the host and fails if the reference cannot see a dropped K plane, a permuted K
chunk or a confused MN subtile; `mma transpose control` is the same operands
under `mma_abt` and is required to *disagree*, so the transposed cases prove
their transpose bits and not merely that some walk multiplies.
Two findings. `tcgen05_mma_f16` and `tcgen05_mma_shared::<0, 1, 0>` do not
lower to the same PTX at the pinned revision — the f16 wrapper emits the
`.disable_output_lane` form with an all-zero mask, the generic one emits
`.collector::a::discard` and no mask — though `ptxas` prices them identically
(every pre-existing kernel's register count is unchanged). And `KIND` cannot be
read off an associated const at the call site: `tcgen05_mma_shared::<{ E::KIND
}, ..>` needs `generic_const_exprs`, so the routing is a trait method each impl
writes for itself.
28 of 28 device cases pass; `gemm` is still exact.
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.
What this is
The three things #12 asked for, and — because the MMA layer is the part of this
library nothing here was waiting on — a harness that can tell whether the new
walks are right.
The walks.
mma_atb([K, M]×[K, N], both transpose bits) andmma_atbt([K, M]×[N, K], transpose A only) close{AB, ABt, AtB, AtBt}. Both take their transpose bits back offOperandWalk::transposed, the waymma_walk_cg2already did, so the operandorder and the descriptor cannot disagree because only one of them is stated.
The MN-major operand is
SharedTile::mn_walk— a K=16 chunk is 16 rows, and MNpast the first 64 columns is reached through the descriptor's leading offset,
so one instruction covers a 128-wide MN rather than one per stacked subtile.
mmentry points.mm_abt,mm_ab,mm_atb,mm_atbt,mm_walk_cg2—the same instruction, with the accumulator-init invariant moved out of a
booland into the name. The
accumulateargument stays on themma_*walks for theone caller whose choice is genuinely runtime (gemm's
k > 0, threaded throughone chain that a typed two-arm branch would duplicate).
flash_forwardpassedfalsetwice and now saysmm_abt/mm_ab.Generic
KINDrouting. The walks issue throughMmaElement::mma/mma_cg2, which each impl writes astcgen05_mma_shared::<{ Self::MMA_KIND }, CTA_GROUP, 0>. fp8 is now anElementimpl and not a second MMA layer.Why the harness is most of the diff
A walk no kernel calls emits no PTX and measures nothing, so the four orders
needed a device case each before they were worth having. Six new cases:
walk blind spotsmma ABᵀ/mma AB/mma AᵀB/mma AᵀBᵀ==on all 16384 values.mma transpose controlmma_atb's operands undermma_abt. Required to disagree — otherwise the transposed cases prove only that some walk computesAᵀ·B.Why the transposed cases cannot pass against the untransposed walk: the staged
Ais[64, 128]against[128, 64]and neither generator is symmetric inits arguments, so no operand here is its own transpose; and the control
measures it directly rather than arguing it — 4096 of 4096 values differ.
Why it cannot repeat #48:
walk blind spotsis the standing proof that thereference varies along every coordinate the walk computes, K planes included.
#48's
b_valuewas constant along K and certified a kernel that read one planeof
Bforever.What I verified, and on what
modal run modal_app.py::device_tests— 28 of 28 cases pass, the 22 thatexisted and the 6 new ones.
modal run modal_app.py::examples—gemm 512x256x256 exact, so theKIND-genericcta_group::2intrinsic computes what the f16 wrapper did.modal run modal_app.py::build— clean;device-testsclippy has nowarnings of mine.
modal run modal_app.py::gaps --features flash— exit 0, soflash_forwardstill compiles on
mm_abt/mm_ab.modal run modal_app.py::regcount, this tree againstmain— everypre-existing kernel's register count, spill and stack frame is unchanged.
The four new walk kernels cost 32 registers each, the same as
fragment_map_32x128's identical drain.cargo fmt --checkin all three crates,clippy --all-targets --locked -D warnings,cargo test --locked(67 host tests, 4 new),cargo doc -D warnings,cargo metadata --lockedin all three.Two things the issue got wrong
The generic intrinsic does not lower identically for
KIND=0. The issuecalled it "an assumption to check rather than assert", and checking it says no.
At the pinned revision
tcgen05_mma_f16emits the.disable_output_laneformwith an all-zero mask (four
mov.u32of zero);tcgen05_mma_shared::<0, 1, 0>emits
.collector::a::discardand no mask. Same semantics — an all-zerodisable mask disables nothing, and
collector::a::discardis the default — andptxasprices them the same, but they are not the same instruction and theswitch is a real change to a validated path. That is why
examplesand thewhole device suite are in the verification list rather than just
build.KINDcannot come off the const at the call site.tcgen05_mma_shared::<{ E::MMA_KIND }, ..>for a type parameterEneedsgeneric_const_exprs. An impl writingSelf::MMA_KINDfor itself is legal, sothe routing is a trait method with the const kept beside it as the thing the
method is a substitution of.
And the line estimate was low, in the place that matters.
GAPS.mdsaid"~80 lines for the missing walks"; the walks are 70 with their docs. The
harness that makes them worth having is ~420.
Closes #12