[PR #1824] [CLOSED] cpu: Q2_0 rows on AVX-only CPUs (q2_avx1.cpp) instead of ggml-cpu's scalar dot #3702

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1824
Author: @xrip
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: pr/avx1-q2-rows


📝 Commits (1)

  • 394b500 cpu: Q2_0 rows on AVX-only CPUs (q2_avx1.cpp) instead of ggml-cpu's scalar dot

📊 Changes

6 files changed (+341 additions, -7 deletions)

View changed files

📝 CMakeLists.txt (+10 -1)
📝 include/strata/kernels/cpu/expert.hpp (+6 -0)
📝 include/strata/kernels/cpu/expert_layout.hpp (+4 -4)
📝 src/kernels/cpu/expert_layout.cpp (+70 -2)
➕ src/kernels/cpu/q2_avx1.cpp (+85 -0)
➕ src/kernels/cpu/q2_avx1_parity.cpp (+166 -0)

📄 Description

What

The older-CPU build (STRATA_ISA_FLOOR=avx) on an AVX-only CPU (Sandy / Ivy Bridge, Xeon E5 v1/v2): a native pack's
Q2_0 expert rows run on a new AVX kernel (src/kernels/cpu/q2_avx1.cpp) instead of ggml-cpu's Q2_0 vec_dot, which
is scalar on x86. Bitwise the same results as the scalar reference. AVX2 / AVX-512 CPUs and CPUs without AVX run the
same code as before.

Why

In the IQ3_XXS pack, Q2_0 is the down projection of 30 of the 48 layers, so on these CPUs most CPU expert work went
through a scalar loop.

Change

  • q2_native_kernels() also accepts an AVX-only CPU (cpu_avx1_ok()).
  • q2_rows_any: AVX-512 -> AVX2 -> AVX1 (new) -> scalar. act_quant_any uses a scalar Q8_1 quantizer without AVX2.
  • q2_0_gguf_rows_multi_avx1: compiled with -mavx / /arch:AVX only (no FMA). The 2-bit codes are unpacked once
    per block for all tokens; SSSE3 maddubs / madd integer dots (exact: a pair sums to at most 762, no saturation);
    an exact half -> float; the float steps in the scalar order, so the bits equal q2_0_gguf_rows_multi_scalar.
  • The router lookahead keeps 0.1.41's kq_avx1.cpp.
  • New test q2_avx1_parity (ctest; exit 77 without AVX).

Measured

2x Xeon E5-2670 v2 (Ivy Bridge-EP), GCC 14.2:

  • q2_avx1_parity: bitwise equal to the scalar reference for all 65,536 half scales and 216 random cases (1-12
    tokens, partial row ranges, padded and unaligned rows, edge and zero-scale activations).
  • One expert's down rows (2560 x 640) on one core:
    tokens scalar AVX1
    1 3.86 ms 0.41 ms (9.4x)
    4 13.2 ms 0.78 ms (16.9x)

Measured on a fork based on 0.1.38. On current main (0.1.41) it was checked on a Ryzen 7 5700X with
STRATA_FORCE_ISA=avx: q2_avx1_parity passes (12.5x over scalar at 1 token), and so do all CPU tests.

🤖 Generated with Claude Code


🔄 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/1824 **Author:** [@xrip](https://github.com/xrip) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/avx1-q2-rows` --- ### 📝 Commits (1) - [`394b500`](https://github.com/Niko1221/Strata/commit/394b500b2fdd70e826ef17dec27740508e200041) cpu: Q2_0 rows on AVX-only CPUs (q2_avx1.cpp) instead of ggml-cpu's scalar dot ### 📊 Changes **6 files changed** (+341 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -1) 📝 `include/strata/kernels/cpu/expert.hpp` (+6 -0) 📝 `include/strata/kernels/cpu/expert_layout.hpp` (+4 -4) 📝 `src/kernels/cpu/expert_layout.cpp` (+70 -2) ➕ `src/kernels/cpu/q2_avx1.cpp` (+85 -0) ➕ `src/kernels/cpu/q2_avx1_parity.cpp` (+166 -0) </details> ### 📄 Description ## What The older-CPU build (`STRATA_ISA_FLOOR=avx`) on an AVX-only CPU (Sandy / Ivy Bridge, Xeon E5 v1/v2): a native pack's Q2_0 expert rows run on a new AVX kernel (`src/kernels/cpu/q2_avx1.cpp`) instead of ggml-cpu's Q2_0 `vec_dot`, which is scalar on x86. Bitwise the same results as the scalar reference. AVX2 / AVX-512 CPUs and CPUs without AVX run the same code as before. ## Why In the IQ3_XXS pack, Q2_0 is the down projection of 30 of the 48 layers, so on these CPUs most CPU expert work went through a scalar loop. ## Change - `q2_native_kernels()` also accepts an AVX-only CPU (`cpu_avx1_ok()`). - `q2_rows_any`: AVX-512 -> AVX2 -> **AVX1 (new)** -> scalar. `act_quant_any` uses a scalar Q8_1 quantizer without AVX2. - `q2_0_gguf_rows_multi_avx1`: compiled with `-mavx` / `/arch:AVX` only (no FMA). The 2-bit codes are unpacked once per block for all tokens; SSSE3 `maddubs` / `madd` integer dots (exact: a pair sums to at most 762, no saturation); an exact half -> float; the float steps in the scalar order, so the bits equal `q2_0_gguf_rows_multi_scalar`. - The router lookahead keeps 0.1.41's `kq_avx1.cpp`. - New test `q2_avx1_parity` (ctest; exit 77 without AVX). ## Measured 2x Xeon E5-2670 v2 (Ivy Bridge-EP), GCC 14.2: - `q2_avx1_parity`: bitwise equal to the scalar reference for all 65,536 half scales and 216 random cases (1-12 tokens, partial row ranges, padded and unaligned rows, edge and zero-scale activations). - One expert's down rows (2560 x 640) on one core: | tokens | scalar | AVX1 | |---:|---:|---:| | 1 | 3.86 ms | 0.41 ms (9.4x) | | 4 | 13.2 ms | 0.78 ms (16.9x) | Measured on a fork based on 0.1.38. On current `main` (0.1.41) it was checked on a Ryzen 7 5700X with `STRATA_FORCE_ISA=avx`: `q2_avx1_parity` passes (12.5x over scalar at 1 token), and so do all CPU tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:09 +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#3702
No description provided.