Repository navigation
cuda: block-FP8 projections on the Python lane matmul's FP8G kernels - #482
Conversation
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.
|
One more receipt, on the compiled code itself. The kernels' SASS ( The branch still merges cleanly onto today's |
|
Thank you, @jschmied. This is merged into main (dc308a5) with your commit as it was, and fp8_lane joins the CUDA On a GB10 the fp8-lane cases pass 12 of 12 against the Python lane matmul's bytes, from fixtures built with the |
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), andLane.matmul.tf-cuda-test fp8-lane <dir>withzig/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
mainat 041d14a, head 36549fe. Zig 0.17.0, nvcc 13.0 (-Dnvcc -Dsm=121), one DGX Spark (GB10, sm_121).tf-cuda-test fp8-laneon 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_orderandfrom_rowsbyte 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 fromzig/tests/cuda/oracle/fp8_lane.pyagainst our Python engine (0.6 line).zig build testpasses apart fromdirect_io, which fails on this machine onmaintoo (O_DIRECT on the build filesystem).tools/zig/lean_check.pyreports nothing in the new files.