From e4ed23fc173b5effcae7890598bce29ba2832f56 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 2 Oct 2026 22:01:46 +0200 Subject: [PATCH] IQ4_XS's AVX-2 kernel on AVX-2 CPUs only; native_expert_parity skips the AVX-512 check it has no kernel for (#415 follow-up) - The engine's `avx2` switch is on for AVX-512 CPUs too, so the widened gate sent an AVX-512 CPU's IQ4_XS gate/up rows to the new AVX-2 kernel instead of ggml-cpu: other rounding on CPUs that #415 did not mean to change. A format with only an AVX-2 kernel now takes it on CPUs without AVX-512; everything else is dispatched as before. - native_expert_parity ran its AVX-512 check for IQ4_XS on an AVX-512 CPU: iq512_rows has no case for it, so the rows stayed zero and the check failed. Each check runs only for the formats its kernel implements; the AVX-2 one runs on AVX-512 CPUs too, so this PC tests the new kernel. --- src/kernels/cpu/native_expert.cpp | 8 +++++--- src/kernels/native_expert_parity.cpp | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/kernels/cpu/native_expert.cpp b/src/kernels/cpu/native_expert.cpp index 22c9579c..0903761e 100644 --- a/src/kernels/cpu/native_expert.cpp +++ b/src/kernels/cpu/native_expert.cpp @@ -98,9 +98,11 @@ void native_gu_rows(const NativeFmt& f, const uint8_t* blob, const void* const* kq256_gu_rows(f.gu_type, blob, f.gu_row, f.up_off, (int) f.n_embd, act, nt, ff, r0, r1); return; } - if (nt >= mt_min && (iq512_supported(f.gu_type) || iq256_supported(f.gu_type))) { - // each kernel only for the formats it implements: IQ4_XS has an AVX-2 one and no AVX-512 one, and - // falling through an empty switch would leave ff unwritten instead of falling back to ggml-cpu. + // A format with only an AVX-2 kernel (IQ4_XS, #415) takes it on AVX-2 CPUs only: an AVX-512 CPU keeps ggml-cpu for + // it, as before (its rows would round differently). Each kernel only for the formats it implements: falling + // through an empty switch would leave ff unwritten instead of falling back to ggml-cpu. + static const bool cpu512 = cpu_avx512_ok(); + if (nt >= mt_min && (iq512_supported(f.gu_type) || (!cpu512 && iq256_supported(f.gu_type)))) { if (avx512 && iq512_supported(f.gu_type)) { iq512_gu_rows(f.gu_type, blob, f.gu_row, f.up_off, (int) f.n_embd, act, nt, ff, r0, r1); return; diff --git a/src/kernels/native_expert_parity.cpp b/src/kernels/native_expert_parity.cpp index e0868100..0183f01b 100644 --- a/src/kernels/native_expert_parity.cpp +++ b/src/kernels/native_expert_parity.cpp @@ -145,8 +145,9 @@ int check_blob(const cpu::NativeFmt& f, const std::vector& blob, int se tag, us1, 2.0 * f.up_off / us1 / 1e3, usg, 2.0 * f.up_off / usg / 1e3); std::printf(" gate+up %d tokens one thread: %s %.0f us vs ggml %d x %.0f us\n", NT, tag, usn, NT, usg); }; - if (cpu::cpu_avx512_ok()) check("avx512", true); // guarded: the binary runs on AVX-2 CPUs too - check("avx2", false); + // guarded: the binary runs on AVX-2 CPUs too, and IQ4_XS has no AVX-512 kernel (an empty switch) + if (cpu::cpu_avx512_ok() && cpu::iq512_supported(f.gu_type)) check("avx512", true); + if (cpu::iq256_supported(f.gu_type)) check("avx2", false); } for (int k = 0; k < NT; ++k) { cpu::native_quant_h(f, ff[k].data(), hq[k].data());