Repository navigation
perf: retile router fp32 kernels for D=3072 (#44) - #52
Merged
Merged
Conversation
The three fp32 router matmuls ran ~30x off bandwidth-bound at D=3072 because their launch geometry, not precision, was wrong (issue #44): - forward.router.logits launched eight threads per token, each striding the full D row; both occupancy and coalescing were wrecked. - backward.router.input ran one thread per (token, d), re-reading the E-wide dlogits row from HBM per output element. - backward.router.weight kept its D=1536-era 2x8-tile/16-partition geometry, which under-coalesces X and under-fills the SMs at D=3072. forward.router.logits now uses a register-tiled fp32 skinny GEMM (router_gemm_impl): a [BM=32, BN=8] output tile loads the router weight once per BK step and reuses it across the token tile, so the weight streams from L2 instead of being re-read per token; BN=8 matches the routed expert width, so the skinny dimension carries no tile padding. backward.router.input (dx-write-bound) is one block per token row: the 32-byte gate row is staged once in shared and broadcast, and the lanes stride D with coalesced dx writes instead of re-reading the gate row per output (routing the skinny GEMM here regressed it by breaking the wide coalesced dx write). backward.router.weight keeps its deterministic fixed-order reduction but is re-sized to 8 coalesced D-rows x 8 token partitions per block. The router stays fp32 end-to-end; routing decisions are unchanged (ops and model parity gates green).
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.
Closes #44.
The three fp32 router matmuls ran ~30× off bandwidth-bound at
D=3072because their launch geometry, not precision, was wrong. The router
stays fp32 end-to-end (SPEC 8b) and routing decisions are unchanged.
What changed
forward.router.logits— replaced the eight-threads-per-token launch(each striding the full
Drow) with a register-tiled skinny fp32 GEMM(
router_gemm_impl). A[BM=32, BN=8]output tile loads the router weightonce per
BKstep and reuses it across the token tile, so the weightstreams from L2 instead of being re-read per token;
BN=8matches therouted expert width, so the skinny dimension carries no tile padding.
backward.router.input(dxis write-bound) — one block per tokenrow, staging the 32-byte gate row once in shared and broadcasting it while
lanes stride
Dwith coalesceddxwrites, instead of a per-(token,d)serial dot that re-read the gate row from HBM. (Routing the skinny GEMM
here instead regressed it by breaking the wide coalesced write.)
backward.router.weight— kept its deterministic, atomic-freefixed-order reduction but re-sized the D=1536-era
2×8-tile/16-partitiongeometry to 8 coalesced
D-rows × 8 token partitions per block forD=3072.Before / after (B200, §10.1,
L=12 B=12 T=2048 D=3072 E=8, same-container A/B vsmain)forward.router.logitsbackward.router.weightbackward.router.inputParity (routing decisions unchanged)
./run.sh ops:./run.sh model:Caveats / follow-ups
backward.router.inputandbackward.router.weightremainL2-weight-bandwidth bound (still ~15–20× off the pure-HBM floor). A full
skinny-GEMM weight-reuse pass for both — without the per-block staging
overhead that hurt the tiled input variant here — is the next lever if
these spans stay on the profile hot list.