mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Two new tiers on the CpuOps contract (cpu_tier.h: no standard-library code in the tier files), for the CPUs below AVX2 that setup builds for (STRATA_ISA_FLOOR none / avx): Nehalem / Westmere and the Pentium / Celeron / Atom parts without AVX (sse41), Sandy / Ivy Bridge and AMD's AVX CPUs before Excavator (avx). - cpu_kernels_sse41.cpp: 6 x 8 register tile on __m128; cpu_kernels_avx.cpp: 6 x 16 on __m256 (-msse4.1 / -mavx; MSVC /arch:AVX). - No FMA on these CPUs: every product term is a multiply then an add, in the k order of every tier. The SSE4.1 tier's products are bit-identical to the scalar tier's on x86 (unit test). - F16 weights are converted in integer code, bit exact, without F16C (Sandy Bridge has none); the 16-bit rounding equals the scalar tier's bit for bit; exp is the Cephes polynomial of the AVX2 tier with separate multiply and add; the one-vector tail product as in AVX2 / AVX-512. - Dispatch: Isa ranks scalar < sse41 < avx < avx2 < avx512 (Neon apart); the probe reads SSE4.1 and AVX (with the OS ymm state); STRATA_FORCE_ISA takes sse41 and avx. - own_reader_supported keeps `auto` on mtmd for every x86 tier below AVX2 (the line reads `< Avx2` instead of `== Scalar`): behaviour unchanged until the gate. - strata-vision-own-cpu-test runs every tier the CPU has, capped by STRATA_FORCE_ISA, and adds the rotary / position-add kernels and the SSE4.1 = scalar product check. Checked: cpu-test on z440 (Haswell-EP) with each tier forced (scalar, sse41, avx, avx2): all passed; under qemu-user -cpu Westmere the cpu-test picks sse41 and passes, and strata-vision --tower own / mtmd / auto and strata-vision-own read Qwen3.8 and Qwen3.6 pictures with no illegal instruction (z440 job z440-20261111-1105-4195).
26 lines
1.1 KiB
C++
26 lines
1.1 KiB
C++
// tools/vision/own/cpu_ops.cpp - the dispatcher of the CPU tower's kernel tiers and the tiers' out-of-line library helpers (ISA-neutral, no special compile flags)
|
|
#include "cpu_kernels.h"
|
|
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
|
|
namespace strata_vit {
|
|
|
|
const CpuOps& cpu_ops(quant::Isa isa) {
|
|
if (isa == quant::Isa::Neon) return quant::isa_ok(quant::Isa::Neon) ? cpu_ops_neon() : cpu_ops_scalar();
|
|
if (isa == quant::Isa::Avx512 && quant::isa_ok(quant::Isa::Avx512)) return cpu_ops_avx512();
|
|
if (isa >= quant::Isa::Avx2 && quant::isa_ok(quant::Isa::Avx2)) return cpu_ops_avx2(); // (Neon was handled above: it ranks outside x86)
|
|
if (isa >= quant::Isa::Avx && quant::isa_ok(quant::Isa::Avx)) return cpu_ops_avx();
|
|
if (isa >= quant::Isa::Sse41 && quant::isa_ok(quant::Isa::Sse41)) return cpu_ops_sse41();
|
|
return cpu_ops_scalar();
|
|
}
|
|
|
|
float cpu_tier_expf(float x) { return std::exp(x); }
|
|
|
|
bool cpu_tier_one_vector_tail() {
|
|
static const bool on = [] { const char* e = std::getenv("STRATA_VIT_CPU_TAIL1"); return !(e && std::atoi(e) == 0); }();
|
|
return on;
|
|
}
|
|
|
|
} // namespace strata_vit
|