Skip to content

cuda: block-FP8 projections on the Python lane matmul's FP8G kernels - #482

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-fp8-lane
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-fp8-lane

Conversation

@jschmied

@jschmied jschmied commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What this changes

The Zig CUDA engine reads MLX 4-bit only. Block FP8 (128 x 128 e4m3, fp32 weight_scale_inv) is how most official FP8 checkpoints ship, and Flash Next's NVFP4 exports carry such layers too. This PR adds it model-free:

  • zig/kernels/cuda/fp8_lane.cu: the device code of the Python lane matmul (nvfp4/qmmf.cu, lines 14-298, comments and ATen dropped, the same arithmetic), with the FP8G instances the Python host launches named: row tiles 16, 32 and 64, each with and without a cluster, the fused prompt kernel, and the slice reduce.
  • zig/src/cuda/fp8.zig: the Python host's choice of kernel from the shapes alone (split_k, bucket, fused from 256 rows, slices meeting in a cluster on sm_90 on), the repack into the kernel's fragment order and scale tiles (_fragment_order, from_rows), and Lane.matmul.
  • tf-cuda-test fp8-lane <dir> with zig/tests/cuda/oracle/fp8_lane.py: random block-FP8 weights and bf16 rows through the Python kernel, then through ours.

No family uses it yet; Kolibri-1 (#481) is the first.

Receipt

  • Environment: base main at 041d14a, head 36549fe. Zig 0.17.0, nvcc 13.0 (-Dnvcc -Dsm=121), one DGX Spark (GB10, sm_121).
  • Exactness: tf-cuda-test fp8-lane on Kolibri-1's two projection shapes, o [2560, 6144] (8 slices) and qkv [7168, 2560] (2 slices), each at 1, 3, 17, 40 and 300 rows: 12 of 12 PASS. The repacked codes and scale tiles equal _fragment_order and from_rows byte for byte, and every output equals the Python kernel's bf16 bytes. The rows cover every launched path: tiles of 16, 32 and 64 with cluster slices, and the fused prompt kernel at 300 rows. Run on the branch's own build (-Dnvcc -Dsm=121); the fixtures come from zig/tests/cuda/oracle/fp8_lane.py against our Python engine (0.6 line).
  • Host tests: zig build test passes apart from direct_io, which fails on this machine on main too (O_DIRECT on the build filesystem).
  • tools/zig/lean_check.py reports nothing in the new files.
  • Not run: other GPUs; the reduce path (no sm_90-less GPU here; on the GB10 the slices always meet in a cluster).

zig/kernels/cuda/fp8_lane.cu is the device code of nvfp4/qmmf.cu (lines 14-298,
comments and ATen dropped) with the FP8G instances the Python host launches
named. zig/src/cuda/fp8.zig picks the kernel from the shapes as the Python host
does (split_k, bucket, fused from 256 rows, cluster slices on sm_90 on), repacks
codes and scales as _fragment_order and from_rows do, and launches it.
tf-cuda-test fp8-lane checks repack and output bytes against the Python kernel
(zig/tests/cuda/oracle/fp8_lane.py). Model-free.
@jschmied

jschmied commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

One more receipt, on the compiled code itself. The kernels' SASS (cuobjdump -sass, sm_121, CUDA 13.0 V13.0.88) equals the Python extension's build of nvfp4/qmmf.cu for every kernel this PR adds: the six row-tile instances (16, 32 and 64 rows, plain and cluster), the fused kernel and the reduce kernel, 8 of 8. Kernels are matched by name and template arguments, with namespaces ignored, the same way oracle/sass_compare.py does it. The tf_fp8_lane namespace and the explicit instantiations don't change any instruction.

The branch still merges cleanly onto today's main.

@ashhart ashhart mentioned this pull request Oct 10, 2026
@ashhart
ashhart merged commit dc308a5 into ashhart:main Oct 10, 2026
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. This is merged into main (dc308a5) with your commit as it was, and fp8_lane joins the CUDA
kernel set in the next release.

On a GB10 the fp8-lane cases pass 12 of 12 against the Python lane matmul's bytes, from fixtures built with the
python-0.6 engine: both of Kolibri-1's shapes, the repack, then 1, 3, 17, 40 and 300 rows, which covers every row
tile on the cluster path and the fused prompt kernel. The fatbin also builds for sm_86. Two things are still open.
No model uses the module yet, so Kolibri-1 (#481) will be its first consumer, and the reduce path that GPUs before
sm_90 take hasn't run on hardware here. We'll check it on an Ampere card when something uses it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants