Fuse dispatch for the legacy interleaved CQ4 GEMV#712
Closed
ncylich wants to merge 1 commit into
Closed
Conversation
Replace the legacy IL GEMV's three-pass dispatch (pool-parallel Hadamard + cv wait, serial int8 quantize, static parallel_ranges + cv wait) with the panel driver's single fused dispatch: group-stolen phase A behind a spin barrier, dynamic 16-block-chunk stealing in phase B, main thread as worker 0 with a spin-join, shared CACTUS_GEMV_SB_PER_THREAD budget. The IL micro-kernel is unchanged. M4 kernel: kv_proj 44.7 -> 158.2 GF, o_proj 59.2 -> 188.4 GF. E2E decode on legacy bundles: gemma-4-e2b-it +19%, qwen3-1.7b +42%, lfm2-350m +26%, reaching panel-NEON parity on the unchanged file format. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
Collaborator
Author
|
Consolidating the stack into a single PR per review preference — this work now lives in #709. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third mode of the panel-format campaign (stacked on #710, which stacks on #709): the panel GEMV driver's dispatch retrofitted onto the unchanged legacy interleaved micro-kernel, so legacy-format bundles get the modern scheduling with zero file-format change.
What changes
cactus_quant_4bit_gemv_interleavedpreviously paid three passes per call: a pool-parallel Hadamard transform with a condition-variable join, a serial per-group int8 quantize on the main thread, then a second static-partition dispatch with another cv join. It now runs the panel driver's structure in one dispatch:cactus_quant_gemv_sb_per_thread()(CACTUS_GEMV_SB_PER_THREAD)The 7-op inner loop, activation quantization math, and numerics are unchanged. CQ4
INTERLEAVED_4ROWonly (the production legacy format); 1–3-bit wrappers untouched.Tests
Existing IL oracle test (
matmul_cq4_il[file], N=192) only exercises the serial path; addedmatmul_cq4_il_mt[file](N=4164 → 1041 blocks → 66 chunks incl. a 1-block tail) to engage the multi-thread fused worker, phase-A stealing, and 4-chunk grabs. 36/36 matmul tests pass.Results
M4 kernel level (Gemma shapes, alternating best-of-5):
M4 E2E, legacy bundles (~1k-token prompt + 32 decode, alternating cycles, coherent output):
On-device, legacy bundles (#698 harness, 512+32 spec, 3 alternating rounds, devices powered, Thermal Status 0):
Dispatch overhead is a fixed per-call cost, so the win scales with call rate: largest for small models on fast cores, parity (no regression) where slow cores already sit at the DRAM roofline. Decode-side this mode matches or beats the panel path on every phone case measured (the IL inner loop is 7 ops/32 weights vs the panel's 9, which matters on Cortex-X4-class issue width); the panel format keeps its structural wins — M>1 GEMM without the per-call expansion tax, SME2 zero-copy, no runtime cache.
With this, the engine has three coherent modes: fused-IL NEON on legacy bundles (best phone decode), panel NEON (portable prefill/TTFT), panel + SME2 (M-class frontier).