Commit Graph
2 Commits
Author SHA1 Message Date
Niko1221 e5af60da09 quant layer: AVX2 and AVX tiers (ggml's x86 dots and Q8_0/Q8_1/Q8_K quantizers ported), dequantizers; bit-exact against ggml-cpu in all three flavours
x86 tiers of the layer, one translation unit per flavour compiled with that flavour's instruction-set flags, so the #if __AVX2__ / __AVX__ branches of
ggml's own x86 code (arch/x86/quants.c at the pin, ported to C++ in x86_helpers.inc, x86_dots.inc, x86_act.inc) select what ggml-cpu selects:
- Arith::Avx2 (dot_avx2.cpp, act_avx2.cpp: -mavx2 -mfma -mf16c): the release flavour.  21 dot types + Q2_0 (generic code under this contract, as in ggml),
  Q8_0 / Q8_1 round-half-even quantizers, Q8_K quantizer in AVX2 (the engine's q8k_quant_avx2 moved into the layer, byte-identical to the scalar _ref).
- Arith::Avx (dot_avx.cpp, act_avx.cpp: -mavx, AVX2/FMA/F16C off, #error if they leak in): the STRATA_ISA_FLOOR=avx flavour.
- -ffp-contract=fast on the tier files (ggml-cpu is gnu11 C, which contracts; this is -std=c++20) and STRATA_NOFUSE on the one scalar tail ggml's GCC does
  not fuse (IQ4_NL), found by the oracle test; STRATA_QUANT_AVX2_EXTRA is a cache variable for such experiments.
- dequant.hpp / dequant.cpp: ggml's dequantize_row_* for the 22 types the host side reads back; quantize_q4_0_ref was already in.
- quant_parity covers dequant_row and quantize_q4_0_ref against ggml-base's to_float and ggml_quantize_chunk(Q4_0) too.

Oracle (tests/quant/run_oracle.sh avx2 avx none), 15065 / 15065 / 14489 comparisons, 0 differences, on boston (AVX2 host) and p2006 (AVX-512 host,
the AVX-512 hardware is not used yet).  The Windows (MSVC) run is still to do.
2026-11-09 04:26:42 +01:00
Niko1221 8a2b0f5f00 quant layer: type table, CPU probe, Q8_0/Q8_1/Q8_K/Q4_0 reference quantizers, Generic-contract dots for every pool type, self-checks, ggml oracle test
New static library strata_quant (include/strata/quant/, src/quant/), no ggml dependency: block layouts and codebooks come from the quant header.
- types.hpp: ggml's type ids and block geometry (type_info, row_bytes), activation type per weight type; unknown ids answer nullptr.
- isa.hpp: Isa (hardware) and Arith (arithmetic contract: Generic, Avx, Avx2, Neon), Caps probe with the STRATA_FORCE_ISA cap, default_arith().
- act.hpp / dot.hpp: kernel tables with best-kernel lookup per (type, contract, hardware); references: ggml's _ref quantizers and _generic dots
  ported to C++ (22 dot types: Q2_0, Q4_0/1, Q5_0/1, Q8_0, IQ4_NL, MXFP4, NVFP4, Q2_K..Q6_K, IQ1_S/M, IQ2_XXS/XS/S, IQ3_XXS/S, IQ4_XS).
- selfcheck.hpp: every kernel against the reference on exact synthetic data (powers-of-two scales, small activations), once per process.
- tests/quant/quant_parity.cpp (the only program that links ggml-cpu) compares the layer with ggml-cpu bit for bit; run_oracle.sh builds it in the
  three flavours (portable AVX2, STRATA_ISA_FLOOR=avx, none).  Generic tier vs the none flavour: 13825 comparisons, 0 differences
  (Q4_0 excluded there: ggml's SSE4.2 flavour has an SSSE3 branch that is not the generic C code).
2026-11-09 04:11:27 +01:00