Files
Niko1221 2ca83480cd clean-p2: P-7 x86 tier from the specs (dot_avx2, act_avx512, kq dots; old files untouched)
New files (replacements, same interfaces):
  engine/src/quant/x86/dot_avx2_clean.cpp     table + six _opt kernels + three x4 kernels, bit-identical to the plain kernels of the TU
  engine/src/quant/x86/act_avx512_clean.cpp   AVX-512 Q8_0 / Q8_1 / Q8_K quantisers, byte-identical to the Avx2 contract
  engine/src/kernels/cpu/kq_dots_avx2.{hpp,cpp}  Q4_K / Q5_1 / Q8_0 multi-token dots, bit-identical per token to the single-token Avx2 dots

Float orders were found by black-box probing of the current kernels (tests/clean_p2/probe_*.cpp, model_*.cpp), then
confirmed on random rows. Tests: dot_avx2_verify, act_avx512_verify (needs AVX-512), kq_dots_avx2_test, plus the probes,
a manual build script for the quant layer and Windows (MSVC) drivers.
2026-12-01 01:57:16 +01:00

57 lines
2.5 KiB
C++

// probe_q6k: lane structure of the Avx2 Q6_K x Q8_K dot. Items 0..255 are product elements (bsums kept 0), items 256..271 the bias entries of the
// 16 sub-blocks (qs kept 0). Two items share an integer lane when the result is fl(D*(p1+p2)), different lanes when it is fl(D*p1)+fl(D*p2).
#include "probe_core.hpp"
static int apply(ProbeRow& r, int item, std::mt19937_64& rng) {
if (item < 256) return r.set_product(0, item, rng);
return r.set_bias_q6(0, item - 256, rng);
}
int main(int argc, char** argv) {
const int trials = argc > 1 ? atoi(argv[1]) : 30;
ProbeType* t = find_probe_type("q6_K");
const DotKernel* k = dot_kernel(t->type, Arith::Avx2, Isa::Avx2);
std::mt19937_64 rng(5);
const int n = 272;
std::vector<int> cls(n, -1);
int nc = 0, anomalies = 0;
std::vector<std::vector<char>> same(n, std::vector<char>(n, 0));
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) {
int s = 0, d = 0, x = 0;
for (int tr = 0; tr < trials; ++tr) {
ProbeRow r(*t, 1);
r.zero_bsums = true;
r.randomize_scales(rng);
const int p1 = apply(r, i, rng), p2 = apply(r, j, rng);
float o = 0;
k->fn(256, &o, r.w.data(), r.a.data());
const float D = r.D(0);
const float hs = D * (float)(p1 + p2), hd = D * (float)p1 + D * (float)p2;
const bool es = std::memcmp(&o, &hs, 4) == 0, ed = std::memcmp(&o, &hd, 4) == 0;
if (es && !ed) ++s; else if (ed && !es) ++d; else if (!es && !ed) ++x;
}
if (x > 0 || (s > 0 && d > 0)) ++anomalies;
same[i][j] = (s > 0 && d == 0 && x == 0);
}
for (int i = 0; i < n; ++i) {
if (cls[i] < 0) cls[i] = nc++;
for (int j = i + 1; j < n; ++j) if (same[i][j]) cls[j] = cls[i];
}
printf("kernel %s: %d classes, %d anomalous pairs\n", k->name, nc, anomalies);
for (int c = 0; c < nc; ++c) {
printf("lane %d: elements", c);
int run0 = -1, prev = -2;
bool in_bias = false;
for (int i = 0; i < n; ++i)
if (cls[i] == c) {
if (i >= 256 && !in_bias) { if (run0 >= 0) printf(" %d-%d", run0, prev); run0 = -1; printf(" | bias subblocks"); in_bias = true; prev = -2; }
if (i == prev + 1 && run0 >= 0) prev = i;
else { if (run0 >= 0) printf(" %d-%d", run0, prev); run0 = prev = i; }
}
if (run0 >= 0) printf(" %d-%d", run0, prev);
printf("\n");
}
return 0;
}