Repository navigation
docs(avx2-repack-design): Phase 4 dispatcher closeout — no new code (re-scoped, on-disk format intentionally not added) - #18
Merged
Conversation
Phase 4 was originally scoped to add three pieces: 1. Full dispatcher (runtime ISA selection) 2. On-disk repack converter (--repack-q1-g128-avx2 flag in llama-quantize, new GGML_TYPE_Q1_0_G128_AVX2 enum) 3. Cross-arch fallback testing Item (3) was completed in PR #14. This doc closes out (1) and (2). (1) is already infrastructure-complete via GGML_CPU_ALL_VARIANTS=ON + GGML_BACKEND_DL=ON. The build produces per-ISA shared libraries (ggml-cpu-haswell.so, ggml-cpu-alderlake.so, ggml-cpu-skylakex.so, etc.) and the runtime backend loader picks the most capable variant the host CPU supports. Verified via disassembly: $ objdump -d build-variants/bin/libggml-cpu-haswell.so | grep -c vpdpbusd 0 $ objdump -d build-variants/bin/libggml-cpu-alderlake.so | grep -c vpdpbusd 506 Kernel A from PR #13 lands in the haswell variant (no vpdpbusd); Kernel B from PR #17 lands in the alderlake variant (506 vpdpbusd inlined into the public dispatchers). The runtime gate at repack.cpp:3702 (avx2 && !avx512) routes correctly per variant. (2) is intentionally not implemented. The equivalent upstream pattern (GGML_TYPE_Q4_0_4_4 / _4_8 / _8_8) was deprecated and removed upstream because: (a) on-disk size is identical to the unrepacked format -- no storage win; (b) the runtime repack is ~1 ms per tensor, negligible vs model load; (c) each enum entry forces every backend (cuda, metal, vk, ...) to add a code path for a CPU-only optimisation. Adopting the deprecated pattern on prism purely to mirror the original Phase 4 plan would re-introduce the costs upstream already paid down. Decision #1 of 03-design-brief.md ("no on-disk GGUF format changes") was right at the start. This closes the AVX2 repack project. Status table at the bottom of the doc summarises all 7+1 phases / PRs. Note: a full GGML_CPU_ALL_VARIANTS build hits a pre-existing GCC 11.4 break in arch/x86/quants.c:682 (_mm512_setr_epi8 not declared in <immintrin.h> for GCC < 12) that blocks the AVX-512 variants (skylakex / cascadelake / icelake / cannonlake / cooperlake / zen4 / sapphirerapids). This is unrelated to the repack work and already tracked in 04-cross-arch-validation.md. The verification above was constrained to the haswell + alderlake variants (where my work lands); the rest of the dispatcher infrastructure is upstream code that has been in production for years.
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…uild paragraph Devin Review caught that lines 201-205 of 07-phase4-dispatcher.md contradicted the routing table earlier in the same doc (lines 58-65 and 86-94). Skylake-X has AVX-512, so it routes to the existing single-row AVX-512 vec_dot, not Kernel A. Zen 4 also has AVX-512, so it also routes to vec_dot, not Kernel B. Corrected mapping: Kernel A → Zen 3 (haswell variant) Kernel B → Alder Lake (alderlake variant) vec_dot → Skylake-X / Cascade Lake / Zen 4 / Sapphire Rapids This matches the per-variant routing table at the top of the doc and the analysis at lines 86-94.
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.
Make sure to read the contributing guidelines before submitting a PR
Summary
Phase 4 of the Q1_0_g128 AVX2 repack project is doc-only. The runtime dispatcher is already infrastructure-complete via the existing
GGML_CPU_ALL_VARIANTS+GGML_BACKEND_DLmachinery. The on-disk repack converter is intentionally not added because the equivalent upstream pattern (GGML_TYPE_Q4_0_4_4/_4_8/_8_8) was deprecated and removed.This is the closeout for the multi-phase AVX2 repack work. After this PR, all originally planned phases are either delivered or intentionally re-scoped with documented rationale, and there is no further AVX2-repack work in the queue.
What I expected to do vs. what I found
Expected (from prior session plan): port a runtime dispatcher into
cpu.c, register aGGML_TYPE_Q1_0_G128_AVX2enum, plumb a--repack-q1-g128-avx2flag inllama-quantize. Estimated 2-3 days.Actual investigation result:
ggml/src/CMakeLists.txt:307-385registers per-ISA backend variants (ggml-cpu-haswell.so,ggml-cpu-alderlake.so,ggml-cpu-skylakex.so,ggml-cpu-zen4.so,ggml-cpu-sapphirerapids.so, etc.), each compiled with a different ISA flag set. The runtime backend loader inspects the host CPU at process start and picks the most-capable variant the host supports.__AVX2__) and PR ggml-cpu(repack): AVX-VNNI Kernel B for Q1_0_g128 4×4 repack (SDE-validated, no real-hardware perf) #17 (__AVXVNNI__) drops cleanly into this system: each variant gets exactly the right kernel for its ISA, no source-level changes required.repack.cpp:3702-3712(avx2 && !avx512) registers the 4×4 repack only on AVX2-without-AVX-512 hosts, which correctly prefers the existing single-row AVX-512vec_dotpath on AVX-512 hosts. No code change needed there either.GGML_TYPE_*enum +--repack-*flag) was deprecated upstream in PR #10446 for distribution-complexity / maintenance reasons. Adding it on prism purely to mirror the original Phase 4 plan would re-introduce costs upstream already paid down. Decision Add GGML_TYPE_Q2_0 ternary 2-bit quantization (block size 128) #1 of03-design-brief.mdalready said "no on-disk GGUF format changes".So Phase 4's actual work is verify + document, not code.
Verification (this VM, AMD EPYC 7763 / Zen 3)
AVX2 + FMA + F16C + BMI2) gets Kernel A only — 0vpdpbusdinstructions, matches expected (no__AVXVNNI__defined in this variant's compile environment).AVX2 + FMA + F16C + BMI2 + AVX_VNNI) gets Kernel B — 506vpdpbusdinstructions inlined into the public dispatchers, matches the SDE-validated PR ggml-cpu(repack): AVX-VNNI Kernel B for Q1_0_g128 4×4 repack (SDE-validated, no real-hardware perf) #17 disassembly.Per-variant kernel routing table (from the doc):
__AVXVNNI____AVX512F__haswellalderlakeskylakex/cascadelake/icelake/zen4/sapphirerapidsvec_dotNote on the GCC 11.4 /
_mm512_setr_epi8issueA full
GGML_CPU_ALL_VARIANTS=ONbuild hits a pre-existing GCC 11.4 break inarch/x86/quants.c:682(_mm512_setr_epi8not declared in<immintrin.h>for GCC < 12) blocking the AVX-512 variants. This is unrelated to the repack work — it predates Phase 1 and was already flagged in PR #14's04-cross-arch-validation.md. The verification above is constrained to thehaswell+alderlakevariants where this PR's referenced kernels live. Fixing the AVX-512 build break is a separate follow-up tracked in PR #14's doc.Files changed
docs/avx2-repack-design/07-phase4-dispatcher.md— new (+253 LOC). Contains:_mm512_setr_epi8fix).What this closes
After this PR merges, the multi-phase AVX2 repack project is complete as scoped by
03-design-brief.md:Review & Testing Checklist for Human
docs/avx2-repack-design/07-phase4-dispatcher.md. Sanity-check the per-variant routing table.cmake -B build-variants -G Ninja -DGGML_CPU_ALL_VARIANTS=ON -DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF && cmake --build build-variants -j --target ggml-cpu-haswell ggml-cpu-alderlake && objdump -d build-variants/bin/libggml-cpu-{haswell,alderlake}.so | grep -c vpdpbusd.Notes
AGENTS.md/CONTRIBUTING.mdpreamble for the prism private fork, this design document was prepared with AI assistance under explicit authorisation from @kennguy3n. Verification numbers (vpdpbusd-count disassembly check) were captured from live build artefacts in this session. Not intended for upstreamggml-org/llama.cpp.Link to Devin session: https://uney.devinenterprise.com/sessions/576d78b01f9b4389b375033162f7b7b4