[PR #622] [CLOSED] iq: gather the AVX2 codebook from the grid table (STRATA_IQ256_GATHER) #2725

Closed
opened 2026-11-04 02:02:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/622
Author: @yannickloth
Created: 10/3/2026
Status: ❌ Closed

Base: main ← Head: perf/iq-gateup


📝 Commits (10+)

  • 6dd890c bench: sm_86 baseline for the A3000 tuning work, and a fixed-prompt e2e harness
  • 19242c6 native head: report the cudaHostAlloc error, not just "cannot pin N MiB"
  • c37b5cb bench: add the A3000 A/B harness
  • 7c802dd bench/a3000-tune.sh: stop/start systemd user unit, do not overwrite nix-managed engine
  • 67de86c bench/a3000-tune.sh: drop sudo prlimit, document systemd DefaultLimitMEMLOCK
  • 4d64dac bench/a3000-tune.sh: correct the memlock docs, skip A when the 0.1.18 backup is missing
  • f78b931 bench/a3000-tune.sh: 44 GiB hugepage pool (the arena is 39.97 GiB, not 34)
  • dd63ba8 bench/a3000-tune.sh: drop the A arm (the 0.1.18 backup engine is gone)
  • 0605f8a Merge upstream v0.1.38 (99f3dbd) into perf/am47
  • f9371cf iq: gather the AVX2 codebook from the grid table (STRATA_IQ256_GATHER)

📊 Changes

5 files changed (+231 additions, -5 deletions)

View changed files

➕ bench/a3000-tune.sh (+97 -0)
➕ bench/e2e.sh (+49 -0)
➕ bench/results/2026-09-28-am47-baseline/README.md (+60 -0)
📝 src/core/native_head.cpp (+4 -2)
📝 src/kernels/cpu/iq_avx2.cpp (+21 -3)

📄 Description

What

Add an opt-in AVX2 gather for the two IQ3 gate/up codebooks, the mirror of the AVX-512 kernels' existing STRATA_IQ_GATHER.

STRATA_IQ256_GATHER=1 replaces the scalar _mm256_set_epi32 grid assembly in Fmt32<18> (IQ3_XXS, iq3xxs_grid) and Fmt32<21> (IQ3_S, iq3s_grid) with one _mm256_i32gather_epi32. Default off; the engine is unchanged unless the variable is set.

Why

The AVX2 multi-token kernel (iq_avx2.cpp) is the path for the non-AVX-512 CPUs this engine targets (Intel Core 12th-14th gen, Core Ultra, Zen 2/3). P4 measured i-quant gate/up as the largest CPU term, and this file documents it as codebook-lookup bound. A scratch build that substitutes a constant for the grid vector shows the grid assembly is ~half the single-core kernel:

format full grid bypassed speedup
IQ3_XXS (18) 248 us, 5.1 GB/s 130 us, 9.7 GB/s 1.91x
IQ3_S (21) 357 us, 4.0 GB/s 140 us, 10.0 GB/s 2.55x

IQ3_XXS + IQ3_S are 19 of 48 layers and ~58% of the gate/up lookup work on the Swift 1.5 IQ3_XXS pack, so this is where a runtime decode change can matter.

Numbers (i7-12850HX, Alder Lake, no AVX-512; RTX A3000; engine 0.1.38)

Isolated native_expert_parity --synthetic, one thread, pinned to a P-core, weights L2-resident, gate+up one token:

format scalar gather speedup
IQ3_XXS 245 us, 5.13 GB/s 185 us, 6.77 GB/s 1.32x
IQ3_S 334 us, 4.21 GB/s 250 us, 5.64 GB/s 1.34x

Serve A/B, same binary, bench/e2e.sh, fixed prompt, interleaved, decode_tok_s from /metrics (off / on): 36.4/36.8, 36.9/37.0, 36.5/36.9, 37.1/37.1, 35.9/36.9 — median 36.5/36.9, mean 36.56/36.94 (+1.0%), on ≥ off 5/5.

The deterministic --stats pool is flat (gate/up off 9.756 / on 9.773 ms/round): at 15 workers the pool is not decode-bound enough for the gather to move the whole token, so this is a per-core win that compounds with other work, not a structural one.

Parity

  • A direct same-binary output dump, scalar vs gather, is bit-identical for all five gate/up formats (cmp clean; 7680 bytes each).
  • native_expert_parity stays green with the switch on and off (same rel ≈ 3.1e-08 against ggml's vec_dot), width invariance 0 rows.
  • The AVX-512 path is untouched. IQ2_XXS / IQ2_XS / IQ2_S use 64-bit grids, where an AVX2 i64gather measured a wash (IQ2_XXS 184→185 us, IQ2_S 246→284 us), and are unchanged.

Caveats

  • AVX2 gather throughput is microarchitecture-dependent, which is why this is opt-in exactly like the AVX-512 STRATA_IQ_GATHER (that one measured 3-5% slower on Zen 4). It should not be defaulted on.
  • Measurement caveat: pin the harness thread or use the engine A/B; unpinned isolated runs are bimodal on this host.

Full write-up with the raw runs: #616 (and the plan's P7). Model/config: Swift 1.5 IQ3_XXS pack, --adapt-every 1 --pool-workers 15, fixed prompt hit_rate 0.5509.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/622 **Author:** [@yannickloth](https://github.com/yannickloth) **Created:** 10/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/iq-gateup` --- ### 📝 Commits (10+) - [`6dd890c`](https://github.com/Niko1221/Strata/commit/6dd890ce8de8ceb38a480b9bfa205b9cc5974b8c) bench: sm_86 baseline for the A3000 tuning work, and a fixed-prompt e2e harness - [`19242c6`](https://github.com/Niko1221/Strata/commit/19242c6756729a45272a30f948b3dd7d4b2b0ade) native head: report the cudaHostAlloc error, not just "cannot pin N MiB" - [`c37b5cb`](https://github.com/Niko1221/Strata/commit/c37b5cb4b6076b86bed3971a9eb2a0f5911df674) bench: add the A3000 A/B harness - [`7c802dd`](https://github.com/Niko1221/Strata/commit/7c802ddb5e2a1e2cc9d5c800f2aa58ed7a532c88) bench/a3000-tune.sh: stop/start systemd user unit, do not overwrite nix-managed engine - [`67de86c`](https://github.com/Niko1221/Strata/commit/67de86c774f7ead0543a9efb9656683aca921f92) bench/a3000-tune.sh: drop sudo prlimit, document systemd DefaultLimitMEMLOCK - [`4d64dac`](https://github.com/Niko1221/Strata/commit/4d64dacc5272614e5622958b6cf185e2a595c6c8) bench/a3000-tune.sh: correct the memlock docs, skip A when the 0.1.18 backup is missing - [`f78b931`](https://github.com/Niko1221/Strata/commit/f78b93108237c88d930b7938a95056c767c33e8c) bench/a3000-tune.sh: 44 GiB hugepage pool (the arena is 39.97 GiB, not 34) - [`dd63ba8`](https://github.com/Niko1221/Strata/commit/dd63ba8a8ebe33b21f05c8ba6bd9b14d379a4f01) bench/a3000-tune.sh: drop the A arm (the 0.1.18 backup engine is gone) - [`0605f8a`](https://github.com/Niko1221/Strata/commit/0605f8a11eeebce0da54bdf702f05e1a2dd6f1b2) Merge upstream v0.1.38 (99f3dbd) into perf/am47 - [`f9371cf`](https://github.com/Niko1221/Strata/commit/f9371cfd98a1ecaaf6cdbed6f63ff4dec8f15ec7) iq: gather the AVX2 codebook from the grid table (STRATA_IQ256_GATHER) ### 📊 Changes **5 files changed** (+231 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `bench/a3000-tune.sh` (+97 -0) ➕ `bench/e2e.sh` (+49 -0) ➕ `bench/results/2026-09-28-am47-baseline/README.md` (+60 -0) 📝 `src/core/native_head.cpp` (+4 -2) 📝 `src/kernels/cpu/iq_avx2.cpp` (+21 -3) </details> ### 📄 Description ## What Add an opt-in AVX2 gather for the two IQ3 gate/up codebooks, the mirror of the AVX-512 kernels' existing `STRATA_IQ_GATHER`. `STRATA_IQ256_GATHER=1` replaces the scalar `_mm256_set_epi32` grid assembly in `Fmt32<18>` (IQ3_XXS, `iq3xxs_grid`) and `Fmt32<21>` (IQ3_S, `iq3s_grid`) with one `_mm256_i32gather_epi32`. Default **off**; the engine is unchanged unless the variable is set. ## Why The AVX2 multi-token kernel (`iq_avx2.cpp`) is the path for the non-AVX-512 CPUs this engine targets (Intel Core 12th-14th gen, Core Ultra, Zen 2/3). P4 measured i-quant gate/up as the largest CPU term, and this file documents it as codebook-lookup bound. A scratch build that substitutes a constant for the grid vector shows the grid assembly is ~half the single-core kernel: | format | full | grid bypassed | speedup | | --- | ---: | ---: | ---: | | IQ3_XXS (18) | 248 us, 5.1 GB/s | 130 us, 9.7 GB/s | 1.91x | | IQ3_S (21) | 357 us, 4.0 GB/s | 140 us, 10.0 GB/s | 2.55x | IQ3_XXS + IQ3_S are 19 of 48 layers and ~58% of the gate/up lookup work on the Swift 1.5 IQ3_XXS pack, so this is where a runtime decode change can matter. ## Numbers (i7-12850HX, Alder Lake, no AVX-512; RTX A3000; engine 0.1.38) Isolated `native_expert_parity --synthetic`, one thread, pinned to a P-core, weights L2-resident, gate+up one token: | format | scalar | gather | speedup | | --- | ---: | ---: | ---: | | IQ3_XXS | 245 us, 5.13 GB/s | 185 us, 6.77 GB/s | 1.32x | | IQ3_S | 334 us, 4.21 GB/s | 250 us, 5.64 GB/s | 1.34x | Serve A/B, same binary, `bench/e2e.sh`, fixed prompt, interleaved, `decode_tok_s` from `/metrics` (off / on): 36.4/36.8, 36.9/37.0, 36.5/36.9, 37.1/37.1, 35.9/36.9 — median 36.5/36.9, mean **36.56/36.94 (+1.0%), on ≥ off 5/5**. The deterministic `--stats` pool is flat (gate/up off 9.756 / on 9.773 ms/round): at 15 workers the pool is not decode-bound enough for the gather to move the whole token, so this is a per-core win that compounds with other work, not a structural one. ## Parity - A direct same-binary output dump, scalar vs gather, is **bit-identical** for all five gate/up formats (`cmp` clean; 7680 bytes each). - `native_expert_parity` stays green with the switch on and off (same `rel ≈ 3.1e-08` against ggml's `vec_dot`), width invariance 0 rows. - The AVX-512 path is untouched. IQ2_XXS / IQ2_XS / IQ2_S use 64-bit grids, where an AVX2 `i64gather` measured a wash (IQ2_XXS 184→185 us, IQ2_S 246→284 us), and are unchanged. ## Caveats - AVX2 gather throughput is microarchitecture-dependent, which is why this is opt-in exactly like the AVX-512 `STRATA_IQ_GATHER` (that one measured 3-5% slower on Zen 4). It should not be defaulted on. - Measurement caveat: pin the harness thread or use the engine A/B; unpinned isolated runs are bimodal on this host. Full write-up with the raw runs: #616 (and the plan's P7). Model/config: Swift 1.5 IQ3_XXS pack, `--adapt-every 1 --pool-workers 15`, fixed prompt `hit_rate 0.5509`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:40 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2725
No description provided.