native experts: gate the AVX2 multi-token kernels on cpu_avx2_ok() (#394)
native_gu_rows() tested cpu_avx512_ok() before the AVX-512 kernel but not cpu_avx2_ok() before the AVX2 one, and native_down_rows() had the same asymmetry for its two multi-token kernels (kq256 and the IQ4_NL one). On a CPU without AVX2 a verify window of two or more tokens took an /arch:AVX2 path and died with 0xC000001D. With the gates it falls through to ggml-cpu's vec_dot, which covers every native type for any nt. A CPU with AVX2 takes exactly the paths it took before. (Cherry-picked from #394's 0083bb7 without its generate.cpp part; the startup gate is reworked for the opt-in STRATA_ISA_FLOOR build in a later commit.)
This commit is contained in:
1 parent
d072203bf9
commit
0f476b4553
1 file changed
+13
-3
@@ -84,7 +84,14 @@ void native_gu_rows(const NativeFmt& f, const uint8_t* blob, const void* const*
|
||||
// AVX-2 kernel, STRATA_NO_IQ256 drops the AVX-2 kernel; ggml-cpu's single-token vec_dot is reached only with
|
||||
// both set (and on a CPU without AVX-512, STRATA_NO_IQ512 changes nothing).
|
||||
static const bool avx512 = cpu_avx512_ok() && std::getenv("STRATA_NO_IQ512") == nullptr;
|
||||
static const bool avx2 = std::getenv("STRATA_NO_IQ256") == nullptr;
|
||||
// STRATA_NO_IQ256 drops the AVX-2 kernel. cpu_avx2_ok() is ALSO required: iq_avx2.cpp and kq_avx2.cpp
|
||||
// are compiled /arch:AVX2 and use AVX2 and FMA3, so calling them on a CPU without either is an
|
||||
// illegal instruction, not a slow path. The gate sat next to `avx512` above, which does test
|
||||
// cpu_avx512_ok(), and that asymmetry is what let a pre-Haswell CPU reach iq256_gu_rows.
|
||||
// Without it this falls through to ggml-cpu's vec_dot below, which is compiled for whatever
|
||||
// baseline the build selected (AVX1 here) and covers the same types - IQ2_XXS and IQ2_S among
|
||||
// them. That path loops over tokens itself, so it is correct for any `nt`, not just one.
|
||||
static const bool avx2 = cpu_avx2_ok() && std::getenv("STRATA_NO_IQ256") == nullptr;
|
||||
// #152: from how many tokens the multi-token kernels run (ggml's vec_dot below that). The default 2 is the
|
||||
// measured-fastest rule, but a token's expert rows then round differently alone than in a group, so greedy output
|
||||
// can depend on how many drafts a verify window held. STRATA_IQ_MT_MIN=1 (opt-in, 0.1.30) uses the multi-token
|
||||
@@ -133,11 +140,14 @@ void native_down_rows(const NativeFmt& f, const uint8_t* blob, const void* const
|
||||
static const bool iq4nl_mt = std::getenv("STRATA_NO_IQ4NL") == nullptr;
|
||||
static const int mt_min = [] { const char* e = std::getenv("STRATA_IQ_MT_MIN"); return e ? std::atoi(e) : 2; }();
|
||||
static const bool kq = [] { const char* v = std::getenv("STRATA_KQ256"); return v != nullptr && std::atoi(v) != 0; }();
|
||||
if (kq && nt >= 2 && (f.d_type == 7 || f.d_type == 8)) { // Q5_1 / Q8_0 down: bit-exact, any group size
|
||||
// Both multi-token kernels below are /arch:AVX2 translation units (kq_avx2.cpp and iq_avx2.cpp),
|
||||
// so a CPU without AVX2 has to reach ggml-cpu's vec_dot instead - same reasoning as the gate/up
|
||||
// rows above, where `avx512` tested cpu_avx512_ok() and `avx2` did not.
|
||||
if (cpu_avx2_ok() && kq && nt >= 2 && (f.d_type == 7 || f.d_type == 8)) { // Q5_1 / Q8_0 down: bit-exact, any group size
|
||||
kq256_rows(f.d_type, blob + f.down_off, f.d_row, (int) f.n_ff, hq, nt, out, r0, r1);
|
||||
return;
|
||||
}
|
||||
if (nt >= mt_min && f.d_type == 20 && iq4nl_mt) { // #152: the same rule as the gate/up rows
|
||||
if (cpu_avx2_ok() && nt >= mt_min && f.d_type == 20 && iq4nl_mt) { // #152: the same rule as the gate/up rows
|
||||
iq4nl256_down_rows(blob + f.down_off, f.d_row, (int) f.n_ff, hq, nt, out, r0, r1);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user