Skip to content

CUDA sm_120a: FP8 MMA through the full-rate mxf8f6f4 kind with unit scales, 5% to 8% faster TFQ5 prompt on an RTX 5060 Ti - #5988

Open
joshuaswarren wants to merge 5 commits into
ashhart:mainfrom
joshuaswarren:w7s/sm120-mxf8-fp8
Open

joshuaswarren wants to merge 5 commits into
ashhart:mainfrom
joshuaswarren:w7s/sm120-mxf8-fp8

Conversation

@joshuaswarren

Copy link
Copy Markdown
Contributor

Refs #5651.

On GeForce Blackwell (consumer sm_120) the plain e4m3 x e4m3 -> f32 MMA runs at half rate. Issuing the same m16n8k32 tile through kind::mxf8f6f4.block_scale.scale_vec::1X with unit e8m0 scales (0x7F) is the same arithmetic on the full-rate pipe: 1.98x raw MMA throughput on a 5060 Ti, and every FP32 output bit-identical, including e4m3 subnormals and NaN bytes, signed zero, subnormal/NaN/Inf accumulators, and chained accumulation.

What changes and why it is safe

  • zig/kernels/cuda/mma4.cuh (mma_fp8, consumed by ck_lane) and zig/kernels/cuda/common/tfq5_mma.cuh (mma_e4m3_v): under __CUDA_ARCH_FEAT_SM120_ALL/SM121_ALL emit the block-scaled instruction with unit scales; sm_89-110 keep the plain form. No other operands change; the accumulator contract is unchanged.
  • zig/build/cuda_kernels.zig: mark tfq5 and ck_lane arch_specific so their sm_120/sm_121 images build as sm_120a/sm_121a and the feature macro is live. This is the same mechanism ck_experts already uses for the block-scaled FP4 MMA. sm_80-110 images are unaffected.

Measurements (GeForce RTX 5060 Ti, sm_120, CUDA 13.5, -Dsm=120)

Raw MMA loop, alternating arms, median of 3 (interleaved):

form G-MMA/s
plain e4m3.f32 13.2
mxf8f6f4 unit-scale 26.3

Ratio 1.983x.

zig build tfq5-bench -Dsm=120 pf8(M=512), ABBA (2 interleaved pairs), median:

shape main (TF) this head (TF) gain
down_4096x14336 K=2.0bpw 40.0 42.7 +6.8%
down_4096x14336 K=3.0bpw 38.0 40.9 +7.6%
down_4096x14336 K=4.0bpw 39.1 41.2 +5.4%
gate_14336x4096 K=2.0bpw 45.6 48.8 +7.0%
gate_14336x4096 K=3.0bpw 43.5 46.4 +6.7%
gate_14336x4096 K=4.0bpw 44.6 46.9 +5.2%
sq_4096x4096 K=2.0bpw 38.9 41.7 +7.2%
sq_4096x4096 K=3.0bpw 37.3 39.9 +7.0%
sq_4096x4096 K=4.0bpw 38.5 40.5 +5.2%

pf16 and decode columns are unchanged (dec and pf16 medians identical to 0.1 TF). The MMA is not the dominant share of this GEMM, so the end gain lands at 5-8% rather than the raw 1.98x.

Exactness: a standalone harness runs both instruction forms on identical operands: 67,108,864 comparisons across random e4m3 patterns, subnormal-only lanes, NaN bytes, +-0/subnormal/NaN/Inf f32 accumulators and up to 4 chained MMAs, with 0 mismatches.

zig build tfq5-contract -Dsm=120: all PASS at this diff (pf8 cosine >= 0.994 vs CPU reference, all 8 rates, MoE and TP=2/4 parity), with cosines identical to main's run.

Checks on this head

  • zig fmt --check zig/build/cuda_kernels.zig clean; tools/pr_check.py 0 new lean findings (advisory warnings unchanged from base).
  • cuobjdump on the built fatbin: tfq5.1.sm_120a.cubin and ck_lane.1.sm_120a.cubin images are emitted, so the gated instruction is the one that ran.

Not covered

  • RTX PRO (workstation sm_120) and GB10 (sm_121): the substituted instruction is the same math and expected equal, but I have neither card, so timings are unmeasured.
  • End-to-end served-token hashes: kernel-level parity is proven above; a whole-checkpoint serve leg is not yet run.
  • CHANGELOG.md: left for Ash.

…it e8m0 scales

GeForce Blackwell runs the plain e4m3.f32 MMA at half rate. The
block-scaled mxf8f6f4 form with unit scales is bit-identical on the
full-rate pipe. Applies to tfq5's mma_e4m3_v and ck_lane's mma_fp8;
both kernels are marked arch_specific so their sm_120/121 images build
as sm_120a/121a, the same mechanism ck_experts uses for the FP4 mma.
The block-scaled mxf8f6f4 instruction at mma4.cuh:39 is a third asm
form with its own operand layout; record its fingerprint with count 1
like the file's other two entries.
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

CI fix at e9c863c: the zig job failed cuda_common_check on the new mxf8f6f4 block — allowlist entry added for its fingerprint with count 1, like the file's other two asm forms. python3 tools/zig/cuda_common_check.py: 62 local copies, 0 violations. Pre-push overlap reports a 1-file conflict with #1443 and #1442 (the allowlist JSON); the entry is append-only, so the merge resolves by keeping both sides.

@joshuaswarren joshuaswarren reopened this Dec 2, 2026
@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 2, 2026
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Performance receipt required (kind:perf)

Adds a unit-scale mxf8f6f4 block-scaled FP8 MMA path for sm_120/sm_121 in the TFQ5 and ck_lane kernels, replacing the half-rate plain e4m3 MMA on GeForce Blackwell, and marks those kernels arch_specific so they build as sm_120a/sm_121a. Claims 5-8% TFQ5 prefill gains with bit-identical outputs and a 1.98x raw MMA throughput ratio.

  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [NIT] zig/kernels/cuda/mma4.cuh: The mma4.cuh inline asm string ends with a trailing '\n' while the tfq5_mma.cuh copy does not; harmless but inconsistent between the two near-identical blocks. Suggested fix: Optionally drop the trailing '\n' in mma4.cuh for consistency; no functional impact.
  • Synthena

…art#5988)

The sm_120-only preprocessor branch leaves every other target compiling
the unchanged >=890 path, so the serving identity holds by explicit
extension (prefix=0).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Performance receipt required (kind:perf)

Adds a unit-scale mxf8f6f4 block-scaled FP8 MMA path for sm_120/sm_121 in mma4.cuh and tfq5_mma.cuh, and marks tfq5/ck_lane arch_specific so sm_120a/sm_121a images build with the feature macro. Claims 5-8% TFQ5 prompt gains on an RTX 5060 Ti with bit-identical outputs.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [WARNING] zig/kernels/cuda/mma4.cuh: The block-scaled mxf8f6f4 PTX form requires sm_120a/sm_121a target features; if any consumer of mma_fp8 is compiled for a non-a variant of sm_120/sm_121 (or the feature macro is not defined because the build does not pass the 'a' suffix), the guard silently falls through to the plain path or fails to compile. Suggested fix: Confirm the arch_specific mechanism emits sm_120a/sm_121a for every kernel that includes mma4.cuh (not just tfq5/ck_lane), or add a static assert on __CUDA_ARCH_FEAT_SM120_ALL inside the branch.
  • Synthena

@ashhart ashhart added synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 5, 2026
@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Thanks, @joshuaswarren. The feature guards and architecture-specific consumers are correct; the earlier generic target warning is closed.

The current catalog has both an architecture-specific and a plain tfq5 entry, producing the same artifact names. We'll remove the duplicate, add catalog coverage, refresh the raw source identity and correct the SM121 wording ourselves.

The reported primitive comparisons and timings remain credited as reported results. The supplied material does not include their comparison harness, served hashes or a verified performance receipt. Please attach those artifacts if available; exact primitive and served qualification remain required before landing. The existing cosine check cannot substitute for bit equality.

  • Synthena

The catalog kept the plain tfq5 row next to the new arch-specific one, so
an sm_120 or sm_121 build scheduled tfq5 twice into the same
fatbin/tfq5.fatbin and registered fatbin_tfq5 twice. The plain row is
gone; the arch-specific row stays.

A catalog test now asserts each kernel name appears once, and that the
actual tfq5 and ck_lane rows build sm_120a and sm_121a and plain sm_89.
The two changed catalog comments fit in 120 columns.

mma4.cuh's raw identity row now carries its measured bytes; its approved
row's note says the new branch is taken on sm_120 and sm_121 (SM120_ALL or
SM121_ALL), not sm_120 only.
@ashhart

ashhart commented Dec 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @joshuaswarren. This head already removes the duplicate TFQ catalog entry, adds uniqueness/profile coverage and refreshes the source identity. The feature-guard and architecture-target questions remain closed, including the SM121 branch.

We'll handle current-main integration and the release note. The primitive comparisons and timings remain credited as reported results. The comparison harness, raw results, served hashes and verified performance receipt are still absent from the supplied material; please attach them if available. Exact primitive and served qualification remains required before landing, and the cosine check cannot substitute for bit equality. No rebase is needed.

  • Synthena

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:perf Classified by Synthena as performance improvement synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants