Commit Graph
3 Commits
Author SHA1 Message Date
Niko1221 6213c0839c CPU expert pool and the DeepSeek CPU lane on the quant layer: -DSTRATA_OWN_CPU_QUANT (default ON on x86, OFF on arm64), ggml-cpu out of the pool
pool_quant.hpp (include/strata/kernels/cpu/) is the one place that knows both worlds: Tr (a weight type's dot, its activation format, an activation type's
quantizer), traits(), row_size_of(), blck_size_of(), flavour_avx2() / flavour_f16c() / flavour_avx512(), to_float(), fp16_bits().  With STRATA_OWN_CPU_QUANT
they are the quant layer's (each kernel passes its self-check once before it is handed out; the contract is default_arith(): Avx2 on any CPU with
AVX2+FMA+F16C, i.e. what the shipped ggml-cpu gives, AVX-512 CPUs included); without it they are ggml-cpu's type traits, exactly as before.
- src/kernels/cpu/native_expert.cpp: the traits calls, ggml_row_size / ggml_blck_size, ggml_cpu_has_*, ggml_cpu_init and the six first-use checks of the
  own rows now go through pool_quant.hpp (the checks compare with the layer's dot instead of ggml's).  Hot loops call Tr::dot (a function pointer).
- src/dsv41/ds4_gg_cpu.cpp (the DeepSeek lane, also compiled into the Metal host): the same, plus to_float for the embedding rows.  Types 10-14, 19, 20, 23
  and every activation quantizer there come from the layer on x86.
- strata/quant/fp16.hpp: the scalar fp16 conversions, public (internal.hpp used to hold them).
- CMake: option STRATA_OWN_CPU_QUANT; strata_kernels_cpu links strata_quant and defines it PUBLIC.  ggml-cpu / ggml-base stay linked for the tests that use
  them as the oracle; with the option on, the pool calls no ggml-cpu function, so a static link pulls none of its objects (nm check in the gates).
- iq_avx1_parity calls ggml_cpu_init itself now (native_fmt used to do it for the oracle's fp16 table).
- native_fmt's two error strings name the library: "native experts: <ggml-cpu | the quant layer> has no dot product for type N" (unchanged text in the ggml build).

cpu-check-native preset, p2006 (AVX-512 host), own mode: 101 tests, 0 failures (6 skipped by design); boston (AVX2): 101 tests, 0 failures in both the own and the ggml build.
2026-11-09 04:42:55 +01:00
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