[PR #4951] [CLOSED] [Engine] CPU: add AVX-VNNI vpdpbusd path for 256-bit NVFP4 expert rows #5261

Closed
opened 2026-11-07 16:33:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4951
Author: @utombords
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: pr/avx-vnni-nvfp4


📝 Commits (2)

  • a22c26f check_isa_guard: read AVX-VNNI at all, and read file names as names
  • 9698b50 nvfp4: vpdpbusd for the AVX-2 rows where the CPU has AVX-VNNI

📊 Changes

10 files changed (+320 additions, -96 deletions)

View changed files

📝 CMakeLists.txt (+4 -1)
📝 docs/DETAILS.md (+1 -0)
📝 docs/NVFP4.md (+17 -1)
📝 include/strata/kernels/cpu/nvfp4_avx2.hpp (+13 -0)
📝 src/kernels/cpu/nvfp4_avx2.cpp (+74 -79)
➕ src/kernels/cpu/nvfp4_avx2_rows.inl (+105 -0)
📝 src/kernels/cpu/nvfp4_avx512_parity.cpp (+37 -3)
📝 sycl/CMakeLists.txt (+2 -1)
📝 tools/check_isa_guard.py (+37 -11)
📝 tools/test_check_isa_guard.py (+30 -0)

📄 Description

Problem and result

CPUs that have AVX-VNNI (CPUID.07H.01H:EAX[4]) without AVX-512 (Intel 12th–14th Gen, Core Ultra / Arrow Lake, Sierra Forest) run the 256-bit NVFP4 CPU expert rows in src/kernels/cpu/nvfp4_avx2.cpp. While q2_avx2.cpp and iq_avx2.cpp already compile an AVX-VNNI copy of their row kernels (*_rows.inl), nvfp4_avx2.cpp still ran the two-instruction vpmaddubsw + vpmaddwd(ones) pair on those CPUs instead of single-instruction vpdpbusd.

In addition, tools/check_isa_guard.py had two bugs on the ELF path: binutils 2.42 prints VEX-encoded AVX-VNNI instructions as {vex} vpdpbusd ... (so the parser read {vex} as the mnemonic and missed all 321 vpdp* instructions in libstrata_kernels_cpu.a), and WIDE_OBJECTS was matched as a substring (native_expert.cpp.o matched expert.cpp.o).

With these two commits:

  1. tools/check_isa_guard.py strips leading {vex} / {evex} markers before reading the mnemonic and matches object filenames as exact basenames (<name>.o / <name>.obj).
  2. src/kernels/cpu/nvfp4_avx2.cpp includes nvfp4_avx2_rows.inl twice—into namespace plain (STRATA_ROWS_VNNI 0, no target attribute) and namespace vnni (STRATA_ROWS_VNNI 1, target("avxvnni") on GCC/Clang)—and dispatches at runtime behind cpu_avxvnni_ok() and STRATA_NO_NVFP4_VNNI.
  3. nvfp4_avx512_parity checks both avx2+vnni and avx2+plain separately for bit-exact equality against ggml-cpu, and adds --bw THREADS TOKENS avx2plain|avx2vnni.
  4. On an Intel Core Ultra 9 285K (Arrow Lake, clean boot, 3 interleaved pairs), single P-core time for 1536 experts drops from 334.8 ms to 225.8 ms at 1 token (12.7 -> 18.8 GB/s, +48.3%), 611.3 ms to 530.8 ms at 4 tokens (+15.2%), and 1177.1 ms to 1011.0 ms at 8 tokens (+16.4%), with 0 bit differences against ggml-cpu. End-to-end (tools/strata_bench.py, 3 runs, warm RAM, RTX 5070 Ti + 15 CPU workers), short chat decode moves from 57.7 tok/s (52.0–80.3) to 59.1 tok/s (50.4–85.5, +2.4% median) while full-pool multi-turn decode stays DRAM-bound (67.8 vs 67.2 tok/s).

none

Approach

  • Follow the exact dual-inclusion .inl structure used in q2_avx2.cpp (q2_avx2_rows.inl) and iq_avx2.cpp (iq_avx2_rows.inl): nvfp4_avx2_rows.inl is included in namespace plain and namespace vnni, both inside the anonymous namespace so no weak/COMDAT symbol can leak to callers.
  • Both copies produce identical integer sums and float accumulation order: doubled E2M1 magnitudes are at most 12 (kvalues_fp4) against Q8_0 activations in [-127, 127], so a vpmaddubsw pair reaches at most 2 * 12 * 127 = 3048 in int16 (<= 32767) and 6096 in int32, which cannot saturate and equals vpdpbusd bit for bit.
  • Add STRATA_NO_NVFP4_VNNI=1 so this kernel can be switched back to the vpmaddubsw + vpmaddwd pair independently of STRATA_NO_AVXVNNI=1 (which also switches q2_avx2 and iq_avx2).

Validation

Passed:

  • Windows 11 / Intel Core Ultra 9 285K (Arrow Lake, 8P + 16E, native AVX2 + AVX-VNNI, no AVX-512) / MSVC 19.44.35229, on 870aedd9 (v0.2.8) and c62d5e3a (v0.2.9 / engine 0.1.55):
    • nvfp4_avx512_parity.exe:
      avx2       random blocks, n 2560  worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      avx2       random blocks, n 640   worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      avx2+vnni  random blocks, n 2560  worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      avx2+vnni  random blocks, n 640   worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      avx2+plain random blocks, n 2560  worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      avx2+plain random blocks, n 640   worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal
      RESULT: parity OK
      
    • dumpbin /disasm nvfp4_avx2.cpp.obj: 0 vpdpbusd instructions in plain::*, 0 vpmaddubsw instructions in vnni::*.
    • nvfp4_avx512_parity.exe --bw (1536 experts, P-core 0 pinned for 1-thread runs, 3 interleaved pairs on clean boot; 24 threads for full pool):
      avx2+plain  threads 1   tokens 1  prefetch 2048: 334.8 ms median (333.8-335.7) -> 12.7 GB/s, 218.0 us/expert/thread
      avx2+vnni   threads 1   tokens 1  prefetch 2048: 225.8 ms median (224.4-227.4) -> 18.8 GB/s, 147.0 us/expert/thread  (+48.3%)
      avx2+plain  threads 1   tokens 2  prefetch 2048: 372.9 ms median (370.1-373.7) -> 11.4 GB/s, 242.8 us/expert/thread
      avx2+vnni   threads 1   tokens 2  prefetch 2048: 363.7 ms median (363.1-365.5) -> 11.7 GB/s, 236.8 us/expert/thread  (+2.5%)
      avx2+plain  threads 1   tokens 4  prefetch 2048: 611.3 ms median (608.1-613.2) ->  6.9 GB/s, 398.0 us/expert/thread
      avx2+vnni   threads 1   tokens 4  prefetch 2048: 530.8 ms median (530.6-532.0) ->  8.0 GB/s, 345.6 us/expert/thread  (+15.2%)
      avx2+plain  threads 1   tokens 8  prefetch 2048: 1177.1 ms median (1171.5-1184.7) -> 3.6 GB/s, 766.3 us/expert/thread
      avx2+vnni   threads 1   tokens 8  prefetch 2048: 1011.0 ms median (1007.5-1015.6) -> 4.2 GB/s, 658.2 us/expert/thread  (+16.4%)
      avx2+plain  threads 24  tokens 1  prefetch 2048:  53.5 ms for 1536 experts -> 79.4 GB/s, 835.9 us/expert/thread
      avx2+vnni   threads 24  tokens 1  prefetch 2048:  53.7 ms for 1536 experts -> 79.1 GB/s, 839.4 us/expert/thread
      
    • python tools/strata_bench.py --runs 3 (qwen3.8-flash-next-nvfp4-nvfp4-BF16, RTX 5070 Ti 16 GB + --pool-workers 15, warm RAM):
      • STRATA_NO_NVFP4_VNNI=1 (avx2+plain): chat decode 57.70 tok/s (52.00-80.30, n=9), TTFT 0.92 s; 4K prompt 1702.50 tok/s; 16K prompt 2700.90 tok/s; agent decode 67.80 tok/s (n=15).
      • Default (avx2+vnni): chat decode 59.10 tok/s (50.40-85.50, n=9, +2.4% median, +6.5% peak), TTFT 0.91 s; 4K prompt 1702.00 tok/s; 16K prompt 2698.00 tok/s; agent decode 67.20 tok/s (n=15).
  • Linux (x86_64 host without AVX-VNNI) / GCC + binutils 2.42 + Intel SDE 10.13.1, on 64f69fa and 870aedd9:
    • python3 -m unittest tools.test_check_isa_guard: 13 tests (10 existing + 2 in commit 1 + 1 in commit 2), OK.
    • python3 tools/check_isa_guard.py build/libstrata_kernels_cpu.a: 321 functions, 113 hold wide-ISA instructions, 0 not allowed (exit 0; before commit 1: 0 hold wide-ISA instructions due to {vex} prefix).
    • objdump -d nvfp4_avx2.cpp.o: vpdpbusd appears only in the eight vnni::row_dot<1..8> instantiations (2 each) and nowhere else (0 in plain::* and public entry points); built with -DSTRATA_AVXVNNI=0, 0 vpdpbusd in the object.
    • sde64 -future -- ./be_vnni 6: 216 trials, 648 forced comparisons (plain vs vnni vs auto), 0 mismatches; sde64 -- ./be_vnni 6 auto on host CPUID without AVX-VNNI exits 0 with no SDE-ERROR.

Failed:

  • none observed

Not run:

  • sycl/CMakeLists.txt build with Intel oneAPI icpx (the one-line STRATA_AVXVNNI property addition in sycl/CMakeLists.txt mirrors q2_avx2.cpp directly, but no SYCL toolchain was installed on the test machine).

Limits

  • At high thread counts (threads = 24, tokens = 1), the NVFP4 rows are DRAM-bandwidth bound (79.4 GB/s vs 79.1 GB/s), so vpdpbusd improves per-core latency and few-worker / few-token windows rather than peak memory bandwidth.

🔄 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/4951 **Author:** [@utombords](https://github.com/utombords) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/avx-vnni-nvfp4` --- ### 📝 Commits (2) - [`a22c26f`](https://github.com/Niko1221/Strata/commit/a22c26fd9eb92285a73fd255c1bce9d2a3b1a3ec) check_isa_guard: read AVX-VNNI at all, and read file names as names - [`9698b50`](https://github.com/Niko1221/Strata/commit/9698b50b980509b450ee231b2a2eda2c84566be1) nvfp4: vpdpbusd for the AVX-2 rows where the CPU has AVX-VNNI ### 📊 Changes **10 files changed** (+320 additions, -96 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -1) 📝 `docs/DETAILS.md` (+1 -0) 📝 `docs/NVFP4.md` (+17 -1) 📝 `include/strata/kernels/cpu/nvfp4_avx2.hpp` (+13 -0) 📝 `src/kernels/cpu/nvfp4_avx2.cpp` (+74 -79) ➕ `src/kernels/cpu/nvfp4_avx2_rows.inl` (+105 -0) 📝 `src/kernels/cpu/nvfp4_avx512_parity.cpp` (+37 -3) 📝 `sycl/CMakeLists.txt` (+2 -1) 📝 `tools/check_isa_guard.py` (+37 -11) 📝 `tools/test_check_isa_guard.py` (+30 -0) </details> ### 📄 Description <!-- PR Title: [Engine] nvfp4: vpdpbusd for the AVX2 rows where the CPU has AVX-VNNI --> <!-- Commits: 0001 + 0002 --> ## Problem and result CPUs that have AVX-VNNI (`CPUID.07H.01H:EAX[4]`) without AVX-512 (Intel 12th–14th Gen, Core Ultra / Arrow Lake, Sierra Forest) run the 256-bit NVFP4 CPU expert rows in `src/kernels/cpu/nvfp4_avx2.cpp`. While `q2_avx2.cpp` and `iq_avx2.cpp` already compile an AVX-VNNI copy of their row kernels (`*_rows.inl`), `nvfp4_avx2.cpp` still ran the two-instruction `vpmaddubsw` + `vpmaddwd(ones)` pair on those CPUs instead of single-instruction `vpdpbusd`. In addition, `tools/check_isa_guard.py` had two bugs on the ELF path: `binutils 2.42` prints VEX-encoded AVX-VNNI instructions as `{vex} vpdpbusd ...` (so the parser read `{vex}` as the mnemonic and missed all 321 `vpdp*` instructions in `libstrata_kernels_cpu.a`), and `WIDE_OBJECTS` was matched as a substring (`native_expert.cpp.o` matched `expert.cpp.o`). With these two commits: 1. `tools/check_isa_guard.py` strips leading `{vex}` / `{evex}` markers before reading the mnemonic and matches object filenames as exact basenames (`<name>.o` / `<name>.obj`). 2. `src/kernels/cpu/nvfp4_avx2.cpp` includes `nvfp4_avx2_rows.inl` twice—into `namespace plain` (`STRATA_ROWS_VNNI 0`, no target attribute) and `namespace vnni` (`STRATA_ROWS_VNNI 1`, `target("avxvnni")` on GCC/Clang)—and dispatches at runtime behind `cpu_avxvnni_ok()` and `STRATA_NO_NVFP4_VNNI`. 3. `nvfp4_avx512_parity` checks both `avx2+vnni` and `avx2+plain` separately for bit-exact equality against `ggml-cpu`, and adds `--bw THREADS TOKENS avx2plain|avx2vnni`. 4. On an Intel Core Ultra 9 285K (Arrow Lake, clean boot, 3 interleaved pairs), single P-core time for 1536 experts drops from `334.8 ms` to `225.8 ms` at 1 token (`12.7` -> `18.8 GB/s`, `+48.3%`), `611.3 ms` to `530.8 ms` at 4 tokens (`+15.2%`), and `1177.1 ms` to `1011.0 ms` at 8 tokens (`+16.4%`), with `0` bit differences against `ggml-cpu`. End-to-end (`tools/strata_bench.py`, 3 runs, warm RAM, RTX 5070 Ti + 15 CPU workers), short chat decode moves from `57.7 tok/s` (`52.0–80.3`) to `59.1 tok/s` (`50.4–85.5`, `+2.4%` median) while full-pool multi-turn decode stays DRAM-bound (`67.8` vs `67.2 tok/s`). ## Related discussion none ## Approach - Follow the exact dual-inclusion `.inl` structure used in `q2_avx2.cpp` (`q2_avx2_rows.inl`) and `iq_avx2.cpp` (`iq_avx2_rows.inl`): `nvfp4_avx2_rows.inl` is included in `namespace plain` and `namespace vnni`, both inside the anonymous namespace so no weak/COMDAT symbol can leak to callers. - Both copies produce identical integer sums and float accumulation order: doubled E2M1 magnitudes are at most `12` (`kvalues_fp4`) against Q8_0 activations in `[-127, 127]`, so a `vpmaddubsw` pair reaches at most `2 * 12 * 127 = 3048` in `int16` (`<= 32767`) and `6096` in `int32`, which cannot saturate and equals `vpdpbusd` bit for bit. - Add `STRATA_NO_NVFP4_VNNI=1` so this kernel can be switched back to the `vpmaddubsw` + `vpmaddwd` pair independently of `STRATA_NO_AVXVNNI=1` (which also switches `q2_avx2` and `iq_avx2`). ## Validation **Passed:** - **Windows 11 / Intel Core Ultra 9 285K (Arrow Lake, 8P + 16E, native AVX2 + AVX-VNNI, no AVX-512) / MSVC 19.44.35229, on `870aedd9` (v0.2.8) and `c62d5e3a` (v0.2.9 / engine 0.1.55)**: - `nvfp4_avx512_parity.exe`: ```text avx2 random blocks, n 2560 worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal avx2 random blocks, n 640 worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal avx2+vnni random blocks, n 2560 worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal avx2+vnni random blocks, n 640 worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal avx2+plain random blocks, n 2560 worst |mine - ggml| / max|ggml| = 0.00e+00 over 1280 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal avx2+plain random blocks, n 640 worst |mine - ggml| / max|ggml| = 0.00e+00 over 2560 rows x 1..9 tokens, 0 beyond 1e-5, 0 not bit-equal RESULT: parity OK ``` - `dumpbin /disasm nvfp4_avx2.cpp.obj`: `0` `vpdpbusd` instructions in `plain::*`, `0` `vpmaddubsw` instructions in `vnni::*`. - `nvfp4_avx512_parity.exe --bw` (1536 experts, P-core 0 pinned for 1-thread runs, 3 interleaved pairs on clean boot; 24 threads for full pool): ```text avx2+plain threads 1 tokens 1 prefetch 2048: 334.8 ms median (333.8-335.7) -> 12.7 GB/s, 218.0 us/expert/thread avx2+vnni threads 1 tokens 1 prefetch 2048: 225.8 ms median (224.4-227.4) -> 18.8 GB/s, 147.0 us/expert/thread (+48.3%) avx2+plain threads 1 tokens 2 prefetch 2048: 372.9 ms median (370.1-373.7) -> 11.4 GB/s, 242.8 us/expert/thread avx2+vnni threads 1 tokens 2 prefetch 2048: 363.7 ms median (363.1-365.5) -> 11.7 GB/s, 236.8 us/expert/thread (+2.5%) avx2+plain threads 1 tokens 4 prefetch 2048: 611.3 ms median (608.1-613.2) -> 6.9 GB/s, 398.0 us/expert/thread avx2+vnni threads 1 tokens 4 prefetch 2048: 530.8 ms median (530.6-532.0) -> 8.0 GB/s, 345.6 us/expert/thread (+15.2%) avx2+plain threads 1 tokens 8 prefetch 2048: 1177.1 ms median (1171.5-1184.7) -> 3.6 GB/s, 766.3 us/expert/thread avx2+vnni threads 1 tokens 8 prefetch 2048: 1011.0 ms median (1007.5-1015.6) -> 4.2 GB/s, 658.2 us/expert/thread (+16.4%) avx2+plain threads 24 tokens 1 prefetch 2048: 53.5 ms for 1536 experts -> 79.4 GB/s, 835.9 us/expert/thread avx2+vnni threads 24 tokens 1 prefetch 2048: 53.7 ms for 1536 experts -> 79.1 GB/s, 839.4 us/expert/thread ``` - `python tools/strata_bench.py --runs 3` (`qwen3.8-flash-next-nvfp4-nvfp4-BF16`, RTX 5070 Ti 16 GB + `--pool-workers 15`, warm RAM): - `STRATA_NO_NVFP4_VNNI=1` (`avx2+plain`): chat decode `57.70 tok/s` (`52.00-80.30`, `n=9`), TTFT `0.92 s`; 4K prompt `1702.50 tok/s`; 16K prompt `2700.90 tok/s`; agent decode `67.80 tok/s` (`n=15`). - Default (`avx2+vnni`): chat decode `59.10 tok/s` (`50.40-85.50`, `n=9`, `+2.4%` median, `+6.5%` peak), TTFT `0.91 s`; 4K prompt `1702.00 tok/s`; 16K prompt `2698.00 tok/s`; agent decode `67.20 tok/s` (`n=15`). - **Linux (x86_64 host without AVX-VNNI) / GCC + binutils 2.42 + Intel SDE 10.13.1, on `64f69fa` and `870aedd9`**: - `python3 -m unittest tools.test_check_isa_guard`: `13` tests (`10` existing + `2` in commit 1 + `1` in commit 2), `OK`. - `python3 tools/check_isa_guard.py build/libstrata_kernels_cpu.a`: `321` functions, `113` hold wide-ISA instructions, `0` not allowed (exit `0`; before commit 1: `0` hold wide-ISA instructions due to `{vex}` prefix). - `objdump -d nvfp4_avx2.cpp.o`: `vpdpbusd` appears only in the eight `vnni::row_dot<1..8>` instantiations (`2` each) and nowhere else (`0` in `plain::*` and public entry points); built with `-DSTRATA_AVXVNNI=0`, `0` `vpdpbusd` in the object. - `sde64 -future -- ./be_vnni 6`: `216` trials, `648` forced comparisons (`plain` vs `vnni` vs auto), `0` mismatches; `sde64 -- ./be_vnni 6 auto` on host CPUID without AVX-VNNI exits `0` with no `SDE-ERROR`. **Failed:** - none observed **Not run:** - `sycl/CMakeLists.txt` build with Intel oneAPI `icpx` (the one-line `STRATA_AVXVNNI` property addition in `sycl/CMakeLists.txt` mirrors `q2_avx2.cpp` directly, but no SYCL toolchain was installed on the test machine). ## Limits - At high thread counts (`threads = 24`, `tokens = 1`), the NVFP4 rows are DRAM-bandwidth bound (`79.4 GB/s` vs `79.1 GB/s`), so `vpdpbusd` improves per-core latency and few-worker / few-token windows rather than peak memory bandwidth. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:53 +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#5261
No description provided.