Files
Strata/include/strata/quant/dequant.hpp
T
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

20 lines
821 B
C++

// include/strata/quant/dequant.hpp - one row of blocks -> floats (own-stack phase 2).
//
// For the host-side readers of a quantized tensor: the --mtp-q4 requantizer (Q8_0 and the draft head's format), the DeepSeek embedding rows. The same
// arithmetic as ggml's `dequantize_row_*`, scalar; not a hot path.
#pragma once
#include <cstdint>
#include "strata/quant/types.hpp"
namespace strata::quant {
/// True for the types dequant_row() handles: Q2_0, Q4_0/1, Q5_0/1, Q8_0, MXFP4, NVFP4, Q2_K..Q6_K, IQ1_S/M, IQ2_XXS/XS/S, IQ3_XXS/S, IQ4_NL/XS.
bool can_dequant(Type t) noexcept;
/// n elements (a whole number of the type's blocks) of the row at `src` -> dst. False (nothing written) for a type it does not handle.
bool dequant_row(Type t, const void* src, float* dst, int64_t n);
} // namespace strata::quant