mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #930] [CLOSED] cpu: IQ3_S / IQ2_S AVX2 decode without the per-index shift/mask/or (1.07-1.6x per row) #2920
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2920
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/930
Author: @sanastasiou
Created: 10/5/2026
Status: ❌ Closed
Base:
main← Head:perf/avx2-iq3s-iq2s-decode📝 Commits (10+)
fa16567setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459)749d957setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)5a30024calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)9f60d13serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)eb8da1d/metrics: each request's speculative draft counts, and their sums in the totals (#457)6a09387setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)d6a91e2docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)d8d4ad3Merge branch 'f-135-eng' into rel-0.1.357b600d5Merge branch 'f-135-small' into rel-0.1.35d9ab843Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it📊 Changes
1 file changed (+87 additions, -19 deletions)
View changed files
📝
src/kernels/cpu/iq_avx2.cpp(+87 -19)📄 Description
The AVX2 multi-token kernels in
src/kernels/cpu/iq_avx2.cppare compute-bound on the codebook decode, not on the per-token arithmetic: a hot (in-cache) and a cold (256 MiB) working set measure the same ns/row. This PR makes the IQ3_S and IQ2_S decode cheaper. The arithmetic is untouched (vpsignb,vpmaddubsw,vpmaddwd, exact int32 per QK_K block), so the results are bit-identical.What changes (one file, IQ3_S and IQ2_S only)
qhbyte indexes a compile-time table that spreads its high bits one per index byte. Onepunpcklbwputs them next to the 8 low index bytes, so each lookup is a 16-bit load plus the grid load instead of a shift, a mask and an or per index.vpbroadcastdfrom memory, a load uop) and expanded with ONEpshufb, instead ofsgn_vec's twopshufb+vinserti128. On Intel cores those are three uops on the single shuffle port.(2s+1)vectors come from compile-time tables: one load instead of shift/or/broadcast.constexpr(likeEvenSigns), so the AVX2 TU still has no static constructor (#391).static_asserts pin the table layout.STRATA_IQ256_GATHERpath becomes its own instantiation, chosen once per call iniq256_rows/iq256_gu_rows. With the check left insidedecode(), the branch sat in the innermost loop and made the new IQ3_S decode 25-35 % slower at nt=2-3 (default path, Zen 3).Measured (ns per row of all nt tokens, hot, one pinned thread, best of 3 rounds with base and PR alternated; base =
main@6f32ec0; the kernels compiled with-march=haswell):On the i7-7700,
main's IQ3_S at nt=2 is slower than at nt=3. This reproduced on two cores and two runs; with this PR the curve is monotonic again.I have not measured end to end in the engine, and I have not measured on a Haswell Xeon. The Kaby Lake core has the same single-shuffle-port layout, so I expect Haswell to land in the same range, but that is not measured. Numbers from an E5 v3 owner (#913) would close that gap.
Tests
tests/target if useful) compiles this exactiq_avx2.cppand checksiq256_rowsagainst ggml's_genericreferences and a float64 oracle.strata_iq256subset: 180 tests, pass on Zen 2 and Kaby Lake.STRATA_IQ256_GATHER=1.static_assert.cmake -DSTRATA_WERROR=ON -DSTRATA_BUILD_TESTS=ONbuilds clean.expert_multi_testfails on this Zen 3 box because it requires AVX-512 ("this CPU cannot run the expert kernel"), not because of this change.native_expert_parityneeds CUDA plus the llama.cpp oracle and does not cover the IQ formats; I did not run it.zmm; this is checked by disassembly.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.