Commit Graph
6 Commits
Author SHA1 Message Date
Niko1221 0c83610e5a strata-vision own tower: no AVX2 code outside the CPU-checked kernel tiers (a CPU without AVX2 could hit an illegal instruction)
vit_cpu.cpp and vit_ref.cpp were compiled with -mavx2 -mfma in every x86 GCC build. Setup's own build on a CPU without AVX2 (STRATA_PORTABLE=OFF)
therefore contained AVX2/FMA code in VitCpu itself and in standard-library template copies (std::vector<unsigned short>::_M_fill_assign,
std::vector<std::thread>, std::function managers) that the linker keeps for the whole program. A floor build of the whole strata-vision had
64 functions with AVX instructions outside the kernel tiers (SSE4.2 floor) and 23 with AVX2/FMA (AVX floor).

- The two loops of the tower whose result depends on multiply-add contraction (the rotary of a token row, the position table's bilinear
  add) move into the tier tables (CpuOps::rope_row, pos_add), written as before, so each tier compiles them with its own flags.
- vit_cpu.cpp is compiled at the baseline.
- vit_ref.cpp (the float32 oracle) gets -march=native in native builds (STRATA_VIT_OWN_NATIVE or setup's STRATA_PORTABLE=OFF), -mavx2 -mfma
  only in the portable helper (an AVX2 floor for the whole program), the floor's flags in an older-CPU test build.
- tools/vision: STRATA_ISA_FLOOR = none (SSE4.2) / avx / avx_f16c, a test build of the program a CPU without AVX2 runs (ggml-cpu and the
  reference at that floor), as the engine's option of the same name. Empty changes nothing.
- check_floor_isa.py: objdump scan of a linked binary; every function with instructions above the floor must be kernel-tier code.

Checked (p2006, job p2006-20261111-1101-c643): AVX-512 and AVX2 tiers byte-identical before and after on all 18 pictures, both readers
(standalone reader), and 6 / 6 per tier through the portable helper's --tower own. The scalar tier changes (GCC no longer contracts its
rotary): global cosine old against new 0.99942 to 0.99999 (Qwen3.8), 1.000000 (Qwen3.6). cpu-test passes on every tier. Floor scan of
the whole strata-vision after the change: 0 functions outside the tiers at the SSE4.2 floor, 0 at the AVX floor.
2026-11-11 12:02:14 +01:00
Niko1221 54f9cc3c0c tools/vision/own: the CPU tower's attention streams less (V packed per head, 96 query rows a task, a one-vector tail tile); bit-identical; STRATA_VIT_PROF stage times
The MSVC-built CPU reader was 1.057 of mtmd-CPU's time on a 1,024-token picture (Ryzen 5 7600, 6 threads); level at 1 thread and ahead at 12, so the loss was the attention at 4,096 patches: every task (one head, 48 query rows) streamed all of the head's K and V again, V was read in place from the qkv rows (a 3,456-float stride), and the P*V product's last 8 columns (head size 72) went through a 32-wide tile and a buffer.

- V is packed per head (VP[h][j][d]) in the same pass as K^T.
- A task takes 96 query rows (kQBDefault), so K and V are streamed half as often.
- The raw-vector tiers (AVX2, AVX-512) compute a last column tile of one vector or less with a one-vector micro-kernel (the same FMA chain per lane as the two-vector one).
Every change moves only addresses, row grouping or tile width, never the order of a sum: outputs are byte-identical to 88fc47ccf.  Diagnostics: STRATA_VIT_CPU_VPACK=0, STRATA_VIT_CPU_QB=<multiple of 48>, STRATA_VIT_CPU_TAIL1=0; and STRATA_VIT_PROF=1 prints the CPU tower's stage times (stderr, off by default).

Identity, old 88fc47ccf against new, 6 pictures:
- MSVC (owner PC): AVX-512 and AVX2 tiers, Qwen3.8: 12 of 12 identical
- GCC 13.3 (Ryzen 5 5600X): scalar and AVX2 tiers, Qwen3.6 and Qwen3.8: all identical; strata-vision-own-cpu-test passes
- Apple clang (M5 Max): NEON and scalar tiers, both readers: all identical; the unit test passes
Speed, 5 alternating pairs:
- MSVC against mtmd-CPU, 6 threads: big1024 0.986 (pairs 0.968-0.998; was 1.057, pairs 1.049-1.079), code4217 0.903, tiny_64x48 0.851
- NEON new against old: big1024 0.987, code4217 0.993, tiny 1.000; 96 against 48 query rows: 1.001 (level)
- GCC AVX2 new against old (3 runs, before the 96 default): about 0.95
`--tower auto` is unchanged (it keeps mtmd for an MSVC-built x86 reader until the numbers are confirmed).
2026-11-11 03:10:23 +01:00
Niko1221 d4283e0215 tools/vision/own: the CPU tower rounds to 16 bits by default when the mmproj's weights are BF16 (off for F16), chosen from the GGUF weight type; STRATA_VIT_REF_ROUND=0/1 still overrides; unit test of the choice 2026-11-09 23:46:48 +01:00
Niko1221 aec86299d2 tools/vision/own: vectorised 16-bit rounding for STRATA_VIT_REF_ROUND on the CPU tower (round16 per ISA tier, BF16 and F16, plus a bit-exact test against the scalar tier)
NOT MEASURED YET: the build, the unit test and the ROUND speed pairs on the vectorised code are still queued on p2006 and l620 at the time of this commit.
2026-11-09 20:51:48 +01:00
Niko1221 3ea10ec5dc tools/vision/own: CPU tower keeps its 16-bit weights as panels made once at load (a product task converts a contiguous slice, no per-task transposition: small pictures no longer slower than mtmd-CPU), conv test, speed_pairs.py alternating-pairs speed test 2026-11-09 19:54:10 +01:00
Niko1221 cc4110ed42 tools/vision/own: the fast CPU tower VitCpu (kernels per ISA tier, tiled online-softmax attention, fork-join team) with its unit test; STRATA_VIT_CPU=fast selects it, the default stays VitRef 2026-11-09 19:23:03 +01:00