quant: AVX-512 arm for matmul_i3 (fmt=5 int3-g64) - #661
Merged
Conversation
β¦ask64 Full 64-value groups decode in one 512-bit iteration (dot_i3g64_avx512): the 16B low plane goes through an extended variant of matmul_i2's SSE unpack (adds the unpackhi stages + lane inserts) and the 8B high plane loads directly into a mask register driving a masked +4 on the low-plane bytes. Per-group partial accumulation with post-group scaling is preserved (fma reordered within a group only, like the NEON arm); partial tail groups and non-AVX-512 builds keep the scalar loop. Compile-time gate mirrors the existing dispatch (__AVX512F__ && __AVX512BW__, no build flag changes), and the arm carries the same runtime layer as the file's existing AVX-512 path: I3_AVX512 env kill-switch (g_i3_avx512, default on) and an I3_AVX512_TEST startup selftest against the scalar decode on a fixed all-lanes-asymmetric group, wired at the I4_ACC512 site. test_int3: add I=33 and I=7 shapes (single sub-group rows exercise the scalar-only fallback under every vector arm); CHECK failures now report the failing (I,S,O) tuple.
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.
Authored by Fable 5 in Claude Code, analysis in partnership with @monotophic
(We/our = the joint work; me/my = @monotophic's own hardware and containers).
What this is
The follow-up the code asked for:
matmul_i3's comment reads "x86 staysscalar for now (follow-up)" β this adds the x86 vector arm, gated
__AVX512F__ && __AVX512BW__. The int3-g64 group geometry maps naturally ontoAVX-512: one full 64-value group per iteration β the 16B low plane through an
extended variant of matmul_i2's SSE unpack, the 8B high plane loaded directly
as a
__mmask64driving a masked +4, four sign-extend/convert/FMA chunks,one reduce per group. The per-group structure is preserved exactly: FMA
reorder is confined WITHIN a group; the cross-group
acc += a*srow[g]chainstays in scalar order. Partial tails and non-AVX-512 builds keep the scalar
loop; NEON is untouched (the two arms are an
#if/#elifchain).Runtime envelope mirrors the existing i4 AVX-512 precedent:
I3_AVX512=0kill-switch and an
I3_AVX512_TESTstartup selftest that compares the vectorarm against the scalar decode on a fixed group and hard-fails on mismatch.
The selftest compares EXACTLY (
!=on floats) by construction: every term isan integer with any partial sum bounded by 8320 < 2^24, so f32 summation is
order-invariant there β the compare is exact-by-design, not tolerance-lite.
Measured (Zen 5 / Strix Halo, GLM-5.2 744B real int3-g64 container)
two prompts Γ two reps, interleaved.
all four pairs β rep-stable.
vs f32 reference (discipline: 2e-4), adversarial patterns + lane probes.
each fail it on silicon (
578/961/1425 != 1034).Capstone matrix
colibri.obyte-identical, base vs branchFuller instrument/result table
-mavx512f -mavx512bw,-march=x86-64-v4,and a znver5-like +VL/DQ/VNNI set β zero warnings under
-Wall -Wextra.byte-identity vs base proves the gate compiles to nothing off-x86.
integers exact in f32 under any grouping; Ξ£x β 0 so uniform bias can't cancel.
shapes I β {7,33,64,65,100,128,192,255} Γ O β {1,7} Γ S β {1,4}, hostile
scales Β±1e18/Β±1e-18, 256-point lane-permutation probe β all clean on Zen 5.
MTP=0,--cap 96 --ram 90 --ngen 64 --temp 0, samecontainer/profile both arms,
I3_AVX512=0vs1, reps interleaved.Sibling work: #654 landed AVX2 for fmt=6 this week ("fmt=6 was 92% of decode
on a scalar kernel") β same class of win; this PR covers fmt=5's version of
that gap. VNNI/IDOT composition stays out of scope per the kernel's own note
(int8 activations don't compose with per-group accumulation without a
restructure); the Zen 5 host is instrumented for that follow-up when wanted.
Durable vs current-state: kernel, gate, and runtime envelope are durable;
all tok/s figures are calibrations at (Zen 5 Strix Halo, GLM-5.2 744B
int3-g64 container, dev fa599e0-era, 2026-07-28) and re-derive with host or
container.