Repository navigation
ggml-hrx: an opt-in prefill path over the repacked q6_k tiles (engine #856) - #250
Conversation
…gml-org#856) At -ngl 99 a weight can be resident twice: the loader's stored-layout buffer plus the repacked copy the decode path builds on first use. Issue ggml-org#856 measured that as 5.9 GiB of GTT for a 2.38 GiB model. The two copies exist because the consumers disagree about layout: decode reads the repacked tiles, prefill decodes the stored rows. This adds a second prefill kernel that reads the repacked tiles, so both consumers can share ONE resident layout: - the prefill body gains a layout selector (0 = stored rows, unchanged and still the default; 1 = repacked tiles), and the existing kernels pass 0, so their behaviour is untouched; - the mapping is exact rather than approximate: prefill covers a 32-channel group as two 16-wide halves, which is one packed (group, half) pair, and a prefill workgroup covers 128 output channels against 64 rows per packed tile, so tile = (channel_tile*2 + (row > 63)) * quant_block_count + quant_block with the in-tile row at row mod 64; - the packed read mirrors the decode kernel's own arithmetic (int8 code x per-half int8 scale x per-row f16 d); - the new symbol is exported, registered in the corpus manifest (exports 147 -> 148) and therefore in the generated catalog; - selection is opt-in behind GGML_HRX_Q6K_PACKED_PREFILL=1 at the single call site that already hands the f16 prefill kernel to the builder. Unset is the shipped behaviour, so this cannot change anything until someone asks for it. Measured on Qwen3-4B-Q4_K_M, one binary, both arms in one hold, with each arm logging which layout it read (the selection is logged, because a dispatch histogram cannot distinguish the two - the registration name is the same): | cell | stored (default) | repacked (=1) | ratio | |---|---:|---:|---:| | prefill pp512 | 3,159.57 +/- 12.20 tok/s | 3,217.45 +/- 21.09 | 1.018x | | decode tg32 | 75.87 +/- 0.46 tok/s | 78.18 +/- 0.45 | 1.031x | | PPL 8x512 | 15.0931 +/- 1.18508 | 15.0931 +/- 1.18508 | identical | So it is speed-neutral within a few percent and numerically identical. An earlier single-repeat run suggested 1.57x on prefill; that was a cold-start artifact - the stored arm alone moved from 1,809.92 at one repeat to 3,159.57 at five - and is not claimed here. The value of the change is the resident copy, not throughput. Default stays off. Flipping it needs the GTT accounting from the issue's own BO census, which is measured separately. Refs engine ggml-org#856.
|
#250 ready for review at 63addbb (engine ggml-org#856 kernel half: opt-in prefill over the repacked q6_k tiles so prefill and decode can share one resident layout; stored path unchanged and every existing kernel still passes layout=0; measured speed-neutral 1.018x prefill / 1.031x decode at 5 repeats with PPL identical 15.0931, selection logged per arm; an earlier 1.57x single-repeat figure is withdrawn as a cold-start artifact); 3 files, +215/-9, CI build is the first check at the exact head |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 63addbb88bd4e38d40cc48cfa2a933b177621619
The important question for an "opt-in second path" PR is whether the default path changes, and the answer is no by construction: the discriminator is a compile-time constant per export, so the branch folds away.
export("ggml_mul_mat_q6_k_f32_wmma_prefill_wave32") -> %weight_layout = index.constant 0
export("ggml_mul_mat_q6_k_f16_wmma_prefill_wave32") -> %weight_layout = index.constant 0 (today's path, unchanged)
export("ggml_mul_mat_q6_k_f16_wmma_prefill_from_packed") -> %weight_layout = index.constant 1 (new, opt-in)
so %is_packed = index.cmp eq, %weight_layout, %c1 is false at compile time for both existing kernels and the scf.if never reaches the device. The body gained a parameter but the two shipped entry points instantiate it with a literal — that is the right way to add a layout variant: one template, three specialisations, no runtime branch in the hot loop.
The packed mapping is stated exactly enough to check against the decode kernel's own convention: "prefill covers 32 channels per call as two 16-wide halves, which is one packed (group,half) pair; and a prefill workgroup covers 128 output channels against 64 rows per packed tile, so tile = channel_tile*2 + (row >= 64) and the in-tile row is row & 63" — with %tile_half = row > 63 ? 1 : 0, %tile_lo = channel_tile * 2. That is a 1:1 restatement of the mapping, not a hand-wave, and it is the part a reviewer cannot otherwise verify without the device.
The manifest entry is structurally identical to its sibling (same key set, same family, same source, workload_parameters: [token_count]), so nothing new is required of the loader.
The logging decision is the right one and the reason is measured, which is worth keeping: a dispatch histogram prints registration names, and this knob swaps the kernel ref inside one registration — "a run with the knob on looks identical to one with it off (measured 2026-11-08, which is why this line exists)", and it logs at ERROR because the CLI's sink drops WARN and below. That is the difference between an opt-in flag that can be validated and one that produced "inconclusive" last time.
And the PR does not claim the win: "the stored path stays the default until PPL and tok/s are measured against it." Correct — the motivation (one resident copy of a q6_k weight instead of two) is a memory claim, and the speed claim has to be measured.
Not run: the kernel (needs the Loom toolchain and an HRX device, plus the PPL/tok/s A/B the PR defers). What I verified above is the IR-level constant folding, the manifest entry's shape against its sibling, and the registration swap point.
ISA citations for the claims this kernel rests onPer the owner's 2026-11-08 reference (
RDNA 3.5 caveat (gfx1151) handled by measurement rather than assumption: gfx1151 is RDNA 3.5 and this guide is RDNA3. Every number in the PR body was measured on gfx1151 — PPL 15.0931 in both arms and the five-repeat tok/s rows — so any 3.5 difference in these instructions is inside the measurement rather than something I am reasoning about. The compiled target is |
Refs engine ggml-org#856 (weights resident twice in GTT at
-ngl 99). The engine-side accounting for this is tracked separately; this PRis the kernel half — a prefill path that can read the same layout decode already uses.
At
-ngl 99a weight can be resident twice: the loader's stored-layout buffer plus the repacked copy the decode path builds onfirst use. The two exist because the consumers disagree about layout. This adds a second prefill kernel that reads the repacked
tiles, so both consumers can share one resident layout.
What it does
0= stored rows (unchanged, and what every existing kernel still passes),1=repacked tiles — plus a sibling exported kernel for
1;GGML_HRX_Q6K_PACKED_PREFILL=1at the single call site that already hands the f16 prefillkernel to the builder. Unset is the shipped behaviour.
Measured (Qwen3-4B-Q4_K_M, one binary, both arms in one hold, five repeats; each arm logs which layout it read, because a
dispatch histogram cannot tell the two apart — the registration name is identical either way):
=1)Speed-neutral within a few percent, numerically identical, and the point of the change is the resident copy rather than
throughput. A single-repeat run earlier suggested 1.57x on prefill; that was a cold-start artifact — the stored arm alone
moved from 1,809.92 at one repeat to 3,159.57 at five — and it is explicitly not claimed here.
Default stays off. Flipping it wants the GTT before/after from the issue's own BO census, which is a separate measurement;
this PR only makes the option exist and proves it does not cost speed or accuracy.
Verification status, stated plainly: built and exercised at
6bf216283(the base my rig is on), and applied cleanly tob970d85bawhere this branch starts; the CI build is the first check at the exact PR head. Nothing here changes behaviour unlessthe env var is set, so the risk of the PR itself is confined to code that cannot run by default.