[PR #1701] [CLOSED] cpu: q2_avx1 - the Q2_0 rows and the Q8_1 quantizer for CPUs with AVX but no AVX2 (fixes #1699) #3619

Closed
opened 2026-11-07 15:29:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1701
Author: @nashcap
Created: 10/9/2026
Status: ❌ Closed

Base: main ← Head: q2-avx1-rung


📝 Commits (1)

  • 4b2c04f cpu: q2_avx1 - the Q2_0 rows and the Q8_1 quantizer for CPUs with AVX but no AVX2 (fixes #1699)

📊 Changes

6 files changed (+348 additions, -14 deletions)

View changed files

📝 CMakeLists.txt (+9 -1)
📝 include/strata/kernels/cpu/expert.hpp (+8 -0)
📝 include/strata/kernels/cpu/expert_layout.hpp (+3 -0)
📝 src/kernels/cpu/expert_layout.cpp (+11 -2)
➕ src/kernels/cpu/q2_avx1.cpp (+294 -0)
📝 src/kernels/cpu/q2_bitplane_parity.cpp (+23 -11)

📄 Description

Fixes #1699

q2_rows_any and act_quant_any (expert_layout.cpp) had two rungs - AVX-512 and AVX2 - and the else branch checked nothing: an AVX-only CPU (Sandy Bridge through Ivy Bridge Xeons, the #623/#1375 class) was handed AVX2 code and died with SIGILL. On a clean v0.1.41 tree an E5-2470 v2 kills both pool_tasks_test and q2_bitplane_parity at the first frame (act_quant_q8_1_avx2+123), and any future caller of the dispatchers inherits the trap.

The fix

The third rung, src/kernels/cpu/q2_avx1.cpp, in the containment pattern the repo already uses for kq_avx1.cpp/iq_avx1.cpp: its own translation unit compiled -msse4.2 -mavx -mno-avx2 -mno-fma -mno-f16c (a #error guard keeps AVX2/FMA/F16C out of the object even on a -march=native host), called only behind cpu_avx1_ok() && !cpu_avx2_ok(). The AVX-2 and AVX-512 paths are untouched, so nothing changes on any CPU that has AVX2.

  • 128-bit integer lanes (maddubs/madd are SSSE3/SSE2), 256-bit float accumulation, software fp16 scale conversion (no F16C).
  • The legacy row kernel keeps the AVX-2 kernel's lane pairing and reduction tree exactly; the only difference is its FMA becoming a mul+add (last bits, unavoidable without FMA).
  • The bit-plane kernel and its image builder port as-is (the image builder is already pure SSE2/SSSE3).
  • q2_bitplane_parity now tests the AVX-2 pair where the CPU has AVX2 and the AVX1 pair below it, and skips cleanly (pass) without AVX.

Measured on the hardware from the issue

E5-2470 v2 (Ivy Bridge, AVX only), v0.1.41 + this commit:

  • pool_tasks_test: 168 bitwise comparisons passed (SIGILL before)
  • q2_bitplane_parity: PASS (SIGILL before)
  • iq_multi_parity, router_dot_parity, dequant_s2_parity, expert_layout_test, q8k_quant_parity: unchanged, pass

Independent of #1697 (the i-quant AVX1 kernels); either can merge first.


🔄 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/1701 **Author:** [@nashcap](https://github.com/nashcap) **Created:** 10/9/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `q2-avx1-rung` --- ### 📝 Commits (1) - [`4b2c04f`](https://github.com/Niko1221/Strata/commit/4b2c04f0ebf88284f3765fbc1a8a6830378d8f04) cpu: q2_avx1 - the Q2_0 rows and the Q8_1 quantizer for CPUs with AVX but no AVX2 (fixes #1699) ### 📊 Changes **6 files changed** (+348 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -1) 📝 `include/strata/kernels/cpu/expert.hpp` (+8 -0) 📝 `include/strata/kernels/cpu/expert_layout.hpp` (+3 -0) 📝 `src/kernels/cpu/expert_layout.cpp` (+11 -2) ➕ `src/kernels/cpu/q2_avx1.cpp` (+294 -0) 📝 `src/kernels/cpu/q2_bitplane_parity.cpp` (+23 -11) </details> ### 📄 Description ## Fixes #1699 `q2_rows_any` and `act_quant_any` (expert_layout.cpp) had two rungs - AVX-512 and AVX2 - and the `else` branch checked nothing: an AVX-only CPU (Sandy Bridge through Ivy Bridge Xeons, the #623/#1375 class) was handed AVX2 code and died with SIGILL. On a clean v0.1.41 tree an E5-2470 v2 kills both `pool_tasks_test` and `q2_bitplane_parity` at the first frame (`act_quant_q8_1_avx2+123`), and any future caller of the dispatchers inherits the trap. ## The fix The third rung, `src/kernels/cpu/q2_avx1.cpp`, in the containment pattern the repo already uses for `kq_avx1.cpp`/`iq_avx1.cpp`: its own translation unit compiled `-msse4.2 -mavx -mno-avx2 -mno-fma -mno-f16c` (a `#error` guard keeps AVX2/FMA/F16C out of the object even on a `-march=native` host), called only behind `cpu_avx1_ok() && !cpu_avx2_ok()`. The AVX-2 and AVX-512 paths are untouched, so nothing changes on any CPU that has AVX2. - 128-bit integer lanes (`maddubs`/`madd` are SSSE3/SSE2), 256-bit float accumulation, software fp16 scale conversion (no F16C). - The legacy row kernel keeps the AVX-2 kernel's lane pairing and reduction tree exactly; the only difference is its FMA becoming a mul+add (last bits, unavoidable without FMA). - The bit-plane kernel and its image builder port as-is (the image builder is already pure SSE2/SSSE3). - `q2_bitplane_parity` now tests the AVX-2 pair where the CPU has AVX2 and the AVX1 pair below it, and skips cleanly (pass) without AVX. ## Measured on the hardware from the issue E5-2470 v2 (Ivy Bridge, AVX only), v0.1.41 + this commit: - `pool_tasks_test`: 168 bitwise comparisons passed (SIGILL before) - `q2_bitplane_parity`: PASS (SIGILL before) - `iq_multi_parity`, `router_dot_parity`, `dequant_s2_parity`, `expert_layout_test`, `q8k_quant_parity`: unchanged, pass Independent of #1697 (the i-quant AVX1 kernels); either can merge first. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:29:35 +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#3619
No description provided.