2 Commits
Author SHA1 Message Date
Niko1221 c25b0fdddd inkling2 CPU backend: AVX2 / AVX-512 / NEON dense dot, and matmul parallel over the weight rows
The q / k / v / o / gate projections of the CPU backend (matmul_f32) were `parallel for` over the activation rows with `if (M * N >= 4096)`: a one-token decode step
ran most of them on ONE thread, and a prompt read every weight row M times from memory. They are parallel over the weight rows now (threshold on M * N * K), each row is
read once and reused for all M activation rows from L1; every y[m][n] is the same dot call as before, so the result does not depend on the thread count.

The dot itself (CPU backend, attention scores, inkling2_loop.cpp's helpers) is strata::quant::sk::dot_f32, one more function of the run-time tiers: 4 accumulators of the
tier's vector width (AVX-512 / AVX2 with FMA / NEON), plain 4-accumulator C++ in the base tier (bit-identical to the sum it replaces: sk_tier_test checks it). The vector
tiers sum in lane order, so a CPU-only run differs from 0.2.20 by float rounding (SQ-10 teacher-forced KL(old||new) 4e-4, repeatable run to run).

Measured, CPU backend, SQ-10 prefill 128 / decode 8, alternating pairs: Apple M5 Max prefill 3.2 -> 7.7 ppts, decode 1.6 -> 2.5 tok/s (spread under 1 %);
Zen 4 16 threads, UD-Q2_K_XL: prefill 11.1 -> 13.0, decode 2.7 -> 4.3.
2026-11-23 20:09:19 +01:00
Niko1221 accfd7ace3 inkling2: AVX-512 for the fast lane's CPU experts, and run-time AVX2 / AVX-512 tiers for the S_K / SF4 / MX8 codecs
1. CUDA fast lane (cold experts computed on the CPU): new ink_host_avx512.cpp has the three host kernels (SF4 row, MX8 row, S1.5..S8_K sub-group) for
   AVX-512 F/DQ/BW/VL (no VNNI, so Skylake-X runs it too). The file is built with the AVX-512 flags and nothing else is; its gate, host_avx512::available(),
   is in ink_host_avx512_gate.cpp, a baseline-flag file (a compiler may use AVX-512 anywhere in a file built with -mavx512f, so the gate cannot live there):
   caps().avx512, closed by STRATA_FORCE_ISA=avx2. ink_hybrid.cuh tries AVX-512, then AVX2, then plain C++.
   ink_host_avx2.cpp unpacked the S2_K / S3_K / S5_K / S6_K fields with scalar loops (0.7 to 1.1 GB/s of weights per thread): shuffles now, integer sums exact.

2. The CPU backend and the HIP / SYCL CPU-expert lane (eval_inkling2_expert_batch -> sk_codecs.cpp) ran plain x86-64 C++: strata_quant builds sk_codecs.cpp with
   no ISA flag (its AVX2 / AVX-512 code is selected by __AVX2__ at build time). It is now compiled three times (sk_codecs_base.cpp, x86/sk_codecs_avx2.cpp,
   x86/sk_codecs_avx512.cpp) into strata::quant::sk::{base,avx2,avx512} and sk_dispatch.cpp picks the tier from caps() (AVX-512 needs VNNI there, as strata_quant's
   own tier does). A CPU without AVX2 never executes an AVX2 instruction of it, and a -march=native host cannot leak wide code into the base tier. Tier files are
   -ffp-contract=off: the integer sums are exact and the float steps are the base tier's, so every S_K result is bit-identical across tiers (the aarch64 path and the
   builds that compile sk_codecs.cpp themselves (hy4flash, Metal, the SYCL script) are unchanged). AVX2 gets vector unpackers and an abs/sign int8 dot.
   SF4 / MX8 sum in lane order, so they differ from the scalar tier by float rounding.

Tests: tests/core/ink_host_simd_test.cpp (all formats, scalar reference, AVX2 and AVX-512, F8_E4M3 decode on all 256 codes), tests/quant/sk_tier_test.cpp (tiers
against each other: S_K bit-identical, dispatcher = reported tier), benches ink_host_simd_bench / sk_tier_bench. Run on Zen 4 and Zen 5 (AVX-512 + VNNI), Zen 2 and under
qemu -cpu Nehalem / SandyBridge / IvyBridge (gates closed, nothing executed above the CPU's level), tools/check --only cmake-cpu: 160 passed.

One thread, S_K gemm of a 2304 x 2304 expert matrix, one token, base -> avx2 (Zen 4): S2_K 10x, S3_K 13x, S4_K 2.9x, S5_K 9x, S6_K 8x, S8_K 2.7x. AVX-512 over AVX2: 1.0x on
Zen 4, 1.0 to 1.7x on Zen 5 (ink_host kernels: SF4 1.57x, MX8 1.69x, S3_K 1.35x, S5_K 1.5x).
2026-11-23 19:30:30 +01:00