Skip to content

perf(nf12): sync split-K and per-device capability fixes from upstream - #3669

Closed
Qubitium wants to merge 1 commit into
ModelCloud:mainfrom
Qubitium:feat/nf12-splitk-geometry
Closed

Qubitium wants to merge 1 commit into
ModelCloud:mainfrom
Qubitium:feat/nf12-splitk-geometry

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Syncs three fixes from dphnAI/nf12 into the
vendored RDNA4 HIP kernels. Only gptqmodel_ext/nf12_hip/*.hip changes; the
torch binding, the C ABI and the Python layer are untouched.

  1. Split-K was over-subscribed on wide-N shapes.
  2. The wmma capability check was cached per process, not per device.
  3. A k that is not a multiple of 64 was silently truncated.

1. Split-K

pick_splits handed four K splits to any shape with at least 128 column blocks,
which includes launches that are already 6–7 waves deep. There the extra FP32
partial plane (7–28 MB written and read back) costs more than the additional
CTAs buy. A/B on gfx1201, same binary otherwise:

k × n m split 4 one K pass delta
4096×28672 16 333.6 310.2 −7.0%
4096×28672 32 362.4 321.7 −11.2%
4096×28672 64 417.2 317.9 −23.8%
5120×25600 16 363.3 375.8 +3.4%
5120×25600 32 388.1 382.0 −1.6%
5120×25600 64 433.9 385.2 −11.2%

Against dense BF16 on the R9700:

k × n m=16 m=32 m=64
4096×28672 1.14 → 1.25 1.06 → 1.24 0.96 → 1.28
5120×25600 1.21 → 1.15 1.14 → 1.15 1.04 → 1.21

Neither shape is below parity at m=16/32/64 any more. One cell gives up 3.4% and
still runs at 1.15×. 8192×57344 keeps its two-way split: it is 14 waves deep,
but there the split still wins at m=128 (2601 → 2414 µs).

Side effect: both shapes now need no split-K scratch — seven of the forty
benchmark cells split K, down from thirteen.

2. Per-device capability cache

wmma_available() captured one process-wide bool from whichever device was
current on the first call. On a host exposing both gfx1201 and gfx1250 the
second device inherits the first one's answer and is sent down a matrix-core
route it cannot run — the same class of bug as a shared scratch buffer, just in
the capability check. Now cached per device index with an atomic slot.

3. Geometry validation

The HIP entry points only checked n % 16. A k that is not a multiple of 64
was truncated by k / kSuperAtomCols: encoding a 256×96 weight produced a
matrix covering 64 of the caller's 96 columns, and the GEMM then read back as
garbage with rc=0. encode_analyze, encode, decode, unpack_bf16t,
linear_fused and linear_wmma now reject the same bad geometry the torch
binding already rejects.

Verification

Radeon AI PRO R9700 (gfx1201):

  • nf12 suites: 240 passed, 1 skipped (test_nf12_ad_codec,
    test_nf12_ad_runtime_load, test_backend_naming,
    test_quant_bits_validation, test_rocm_llc).
  • nf12_ad_wmma_workspace_bytes returns 0 for both wide shapes; 7/40 cells split.
  • 4096×28672 m=64 measures 1.28× dense BF16 through nf12_ad_hip.linear.

The 6 test_rocm_kernel_contracts::test_rocm_device_contract[NF12ADLinear]
failures also fail on upstream/main with this branch stashed; they assert
SUPPORTS_DEVICES against the ROCM_KERNELS list and are unrelated to this
change.

Credits

NF12 format, reference codec and CUDA kernels: AlpinDale,
Apache-2.0. NyoomFloat12: Liberman, Fang, Zhang, Dao and Fu — Together AI (2026).

Three fixes from dphnAI/nf12 that the vendored RDNA4 kernels had not picked up.
Only the HIP sources change; the torch binding and the C ABI are untouched.

1. pick_splits split K four ways on any shape with at least 128 column blocks,
   which includes launches already 6-7 waves deep. There the FP32 partial plane
   (7-28 MB written and read again) costs more than the extra CTAs buy. A/B on
   gfx1201, same binary otherwise:

     4096x28672  m=16  333.6 -> 310.2  (-7.0%)
     4096x28672  m=32  362.4 -> 321.7  (-11.2%)
     4096x28672  m=64  417.2 -> 317.9  (-23.8%)
     5120x25600  m=16  363.3 -> 375.8  (+3.4%)
     5120x25600  m=32  388.1 -> 382.0  (-1.6%)
     5120x25600  m=64  433.9 -> 385.2  (-11.2%)

   Against dense BF16, 4096x28672 m=64 goes 0.96x -> 1.28x and 5120x25600 m=64
   1.04x -> 1.21x, so neither is below parity at m=16/32/64 any more. One cell
   loses 3.4% and still runs at 1.15x. 8192x57344 keeps its two-way split: it is
   14 waves deep but the split still wins there at m=128.

   Those shapes now need no split-K scratch: seven of the forty benchmark cells
   split K, down from thirteen.

2. wmma_available() cached one process-wide bool captured from whichever device
   was current on the first call. On a host exposing both gfx1201 and gfx1250
   the second device inherits the first one's answer and is sent down a
   matrix-core route it cannot run. Cached per device index now, with an atomic
   slot so concurrent host threads stay safe.

3. The HIP entry points only checked n % 16. A k that is not a multiple of 64
   was truncated by k / kSuperAtomCols, so encoding a 256x96 weight produced a
   matrix covering 64 of the caller's 96 columns and the GEMM then read back as
   garbage. encode_analyze/encode/decode/unpack_bf16t/linear_fused/linear_wmma
   now reject the same bad geometry the torch binding already rejects.

Verified on R9700 (gfx1201): nf12 suites 240 passed, 1 skipped; workspace query
now returns 0 for both wide shapes; 4096x28672 m=64 measures 1.28x BF16.
The 6 test_rocm_kernel_contracts::test_rocm_device_contract[NF12ADLinear]
failures are pre-existing on upstream/main and unrelated (they assert
SUPPORTS_DEVICES against the ROCM_KERNELS list).
@Qubitium

Qubitium commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #3676, which rebases this split-K/per-device commit onto current main and adds the review fixes.

@Qubitium Qubitium closed this Nov 9, 2026
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.

1 participant