Commit Graph
85 Commits
Author SHA1 Message Date
Niko1221 870ea9763c Merge f-own-3c 971bff01a into f-p4-int 2026-11-11 23:37:46 +01:00
Niko1221 971bff01ad strata-vision: auto picks Strata's own CPU picture reader on x86 CPUs without AVX2 too (no more exception for the scalar, SSE4.1 and AVX tiers)
Until now `auto` kept llama.cpp's reader whenever the CPU's best kernel tier was below AVX2, because the only tier there was the slow portable one. The SSE4.1 and AVX
tiers (0991006d2, 117473f64) and the run-time dispatch (0c83610e5) change that, and the owner asked for ours as the default on these CPUs ("Yes make ours the default").
`auto` now gives our tower on every CPU tier for a tower it can run (both public reader files: Qwen3.8 BF16, Qwen3.6 F16). The setting that picks llama.cpp's reader
(STRATA_VISION_TOWER=mtmd, or --tower mtmd) works as before, and --tower own as before. No new setting, no new line in a log.

What a user on such a CPU gets (p2006, Zen 4 running the forced tier, 8 threads, medians, ours / llama.cpp's reader built for the same CPU class; big1024 = 1,024 tokens,
shapes = 260 tokens; rule 1 = the lowest cosine over 18 pictures against llama.cpp's portable AVX2 reader, the bar is 0.999):

| CPU class (our tier / llama.cpp build) | model | big1024 | shapes | rule 1 minimum |
|---|---|---|---|---|
| no AVX (sse41 / SSE4.2 build) | Qwen3.8 | 25.2 s / 150.8 s (0.167) | 3.5 s / 37.1 s (0.095) | 0.999029 |
| no AVX | Qwen3.6 | 25.3 s / 123.3 s (0.205) | 3.5 s / 29.3 s (0.121) | 0.999975 |
| AVX, no F16C (avx / avx build) | Qwen3.8 | 11.8 s / 35.7 s (0.331) | 1.37 s / 8.2 s (0.167) | 0.999674 |
| AVX, no F16C | Qwen3.6 | 12.2 s / 123.1 s (0.099) | 1.41 s / 30.4 s (0.046) | 0.999975 |
| AVX with F16C (avx / avx_f16c build) | Qwen3.8 | 12.1 s / 34.8 s (0.346) | 1.34 s / 8.0 s (0.166) | 0.999674 |
| AVX with F16C | Qwen3.6 | 12.1 s / 11.6 s (1.040) | 1.39 s / 2.17 s (0.643) | 0.999975 |

The one slower cell is Qwen3.6 on a CPU with AVX and F16C, on the large picture: 1.04 of llama.cpp's time (pair ratios 1.024 to 1.056); on the 260-token picture the same
pair is 0.643. Everywhere else below AVX2 ours takes 0.05 to 0.35 of llama.cpp's time. The AVX2 and AVX-512 CPUs are not affected: they already took our tower.

The code: own_reader_supported() loses the "best tier below AVX2" rule; the CPU half is own_cpu_reader_supported(geometry, tier) (true for every tier when the tower's
operations are implemented) and the reader a setting gives is vision_tower_resolve(setting, own_ok), so the selection is unit tested for the CPU classes no AVX, AVX without F16C,
AVX with F16C, AVX2 and AVX-512 (and a CPU older than SSE4.1), for both reader files' geometry, and for the explicit setting both ways (strata-vision-own-test). cpu_caps.h gets
isa_ok_for / best_isa_for (the same two functions for a given feature set); best_isa() and isa_ok() are unchanged.

Checks run for this commit are in phaseA-tests/cleanup/RESULTS-OWN-3V.md PART H (unit and Python suites on p1006; a default start with the tier set by STRATA_FORCE_ISA on p2006;
a default start under qemu-user with the Westmere CPU model on z440).
2026-11-11 22:22:51 +01:00
Niko1221 d3abf73306 Merge f-own-3c 117473f64 into f-own-int 2026-11-11 21:40:47 +01:00
Niko1221 117473f643 strata-vision own CPU tower: the SSE4.1 tier takes its exp from the C library (the scalar tier's), so its output equals the scalar tier's byte for byte
The SSE4.1 tier used a Cephes polynomial for exp. On Qwen3.8 that gave code4217 a cosine of 0.998928 against llama.cpp's CPU reader, 0.00007 under the 0.999
bar. The tier now calls the C library's expf per lane (out of line, with the scalar tier's clamp [-87, 88]). No build switch is left behind and the polynomial
is gone from this tier.

Checks (p2006, Zen 4, 8 threads, 18 pictures, 1,024 tokens, forced sse41 tier; the AVX and AVX2 tiers are unchanged):

| | polynomial exp | libm exp |
|---|---|---|
| Qwen3.8 rule 1 minimum (against llama.cpp's portable AVX2 CPU reader) | 0.998928 (code4217, 1 miss) | 0.999029 (code4217, 0 misses) |
| Qwen3.6 rule 1 minimum | 0.999975 | 0.999975 |
| bytes against the scalar tier, 18 pictures, each model | all 18 differ | 18 of 18 identical |
| big1024 time, Qwen3.8 / Qwen3.6, 3 alternating pairs, median | 23,857 / 22,523 ms | 26,935 / 24,398 ms |
| shapes (260 tokens) time, Qwen3.8 / Qwen3.6 | 3,587 / 3,460 ms | 3,653 / 3,548 ms |
| peak resident memory | 1.16-1.18 GB | 1.16-1.18 GB |

Time per pair over libm, big1024: 0.82 to 0.98 (Qwen3.8), 0.90 to 0.96 (Qwen3.6); run-to-run spread on big1024 is about 10 percent.

The same code under qemu-user with the Westmere CPU model (no AVX, FMA or F16C, so the C library takes its non-FMA expf), z440, Qwen3.8, code4217, 12 threads:
the emulated sse41 output is byte-identical to the native sse41 output (and so to the native scalar output), rule 1 is 0.999029 in both.

Against llama.cpp's reader built for the same CPU class (p2006, 8 threads, medians; big1024 / shapes): sse41 against the SSE4.2 build, Qwen3.8 25,219 / 3,541 ms
against 150,800 / 37,149 ms, Qwen3.6 25,304 / 3,531 ms against 123,306 / 29,265 ms.
2026-11-11 21:38:56 +01:00
Niko1221 e32329cd30 Merge f-spark-s2 6d65761c4 into f-own-int
Two conflicts, both in the same place: f-own-3s rewrote the gfx1151 block of
tools/vision/own/vit_gpu.h (and its test lines in test_gguf_geometry.cpp), and
f-spark-s2 added its context-retry block right after the old lines of that block.
Resolved by keeping 3s's block whole and adding the retry block unchanged after it
(the base lines 3s replaced are dropped).
2026-11-11 21:28:45 +01:00
Niko1221 d39d20f52e Merge f-own-3c 0991006d2 into f-own-int 2026-11-11 21:28:10 +01:00
Niko1221 713148f912 Merge f-own-3s f5d3b45c5 into f-own-int 2026-11-11 21:28:09 +01:00
Niko1221 f5d3b45c57 tools/vision/own: the fused attention is the default on gfx1151 (STRATA_VIT_FA=0 turns it off)
On gfx1151 (Strix Halo) with head size <= 96, a multiple of 8, and wave 32, k_attn_fa_gfx11 now runs
unless STRATA_VIT_FA=0 is set; STRATA_VIT_FA=1 still asks for it on other gfx11 cards. The variable
is read after the default, as the HPA16 variables are. No new setting. gfx1103 and the other gfx11
cards are unchanged (they get their own gate). The register note of STRATA_VIT_FA is marked
[DRAFT, status: research].

Measured on Strix (gfx1151, Windows, build 5 of af825339a, STRATA_VIT_FA=1 against no variable),
Qwen3.8 against mtmd-CPU:
- attention on big1024 (1,024 tokens, warm): 319.6 ms -> 158.7 ms (0.50); whole picture 383 -> 320 ms,
  code4217 89 -> 80 ms;
- time against mtmd-HIP, 18 pictures, min / median / max: 0.56 / 0.66 / 0.92 -> 0.46 / 0.60 / 0.83
  (Qwen3.6: 0.56 / 0.67 / 0.91 -> 0.46 / 0.61 / 0.91);
- rule 1 and rule 2 pass on 18 of 18 pictures on both models for both arms; byte-identical over 5
  encodes and across two processes;
- longest launch 6 ms at 1,024 tokens, 17 ms at 65,536 patches (limit_4096x4096 reads 0.999693
  against the stored mtmd-CPU embedding);
- smallest token against mtmd-CPU, fused minus default, Qwen3.8: below on 6 of 18 pictures
  (code4217 -0.094 = token #47, shapes_p.gif -0.019), above on 12; token #47 of code4217 depends on
  rounding in every variant measured (its length 0.74 to 2.03; the two CPU references agree on it
  to 0.7600, on the whole picture to 0.999543; the fused kernel is near our CPU tower, the default
  near mtmd-CPU).
Jobs strix-20261111-1620-a728, -1622-31a8, -1636-6cb1, -1644-15d4; details in
phaseA-tests/cleanup/RESULTS-OWN-3V.md part F8-F9. The gate of the build as it ships follows.
2026-11-11 16:51:40 +01:00
Niko1221 6d65761c4d picture reader: allow 12 retries of the GPU context start (was 8)
The gate of the retry on a DGX Spark (4 starts counted with STRATA_VIT_PROF=1)
needed 5, 5, 5 and 6 retries, 5.4 to 6.8 s in all, about 1.1 to 1.2 s per
retry (the 1 s pause plus the failed attempt). 8 retries left a margin of 2.

Worst case when the context never comes: 12 retries, about 13 to 14.5 s of
waiting, then the reader fails as before and falls back as before.

The retry rule's test follows the constant.
2026-11-11 16:46:33 +01:00
Niko1221 805e11c3d8 Merge f-own-3c 0c83610e5 into f-own-int 2026-11-11 16:44:48 +01:00
Niko1221 f5b51eb0b2 Merge f-own-3p 865d3ed4d into f-own-int 2026-11-11 16:44:48 +01:00
Niko1221 24e9d3ba82 picture reader: retry a failed GPU context start on a shared-memory GPU (Linux CUDA only)
A new CUDA context on a GPU that shares the system RAM (DGX Spark GB10)
needs physically contiguous memory. When the kernel has almost no free 2 MiB
blocks, cudaSetDevice fails with "out of memory" although 20+ GiB are free,
and the same call 1 to 5 s later succeeds. On the Spark this sent the picture
reader to the CPU (or to llama.cpp's reader, which aborts) at about half of the
starts.

VitGpu::load now tries again, up to 8 times, 1 s apart, only for
cudaErrorMemoryAllocation, only when cudaDevAttrIntegrated is set, and only in
a Linux CUDA build (SPARK-CTX-RETRY guard; HIP, Metal, Windows and gfx906 are
untouched). After the last retry it fails as before and the reader falls back
as before. No new setting and no new log line (STRATA_VIT_PROF=1 shows the
retry count).

Tests: the retry rule (vit_gpu_retry_context) in test_gguf_geometry.cpp;
tools/test_vit_ctx_retry_guard.py checks the guard.
2026-11-11 16:06:06 +01:00
Niko1221 af825339a4 tools/vision/own: the gfx11 fused attention, tuning round 1 (still off by default)
- K and V reach LDS by 128-bit global loads; the WMMA fragments leave LDS by 128-bit loads (rows
  padded by 8 F16 values: 16-byte aligned, banks shifted); 64-key tiles;
- exp2f with log2(e) folded into the scores; the P exchange inside a wave (wave barrier with LDS
  fences) instead of a block barrier;
- the launch cap STRATA_VIT_FA_UNITS now 2^29 query x key x head triples; the head size must be a
  multiple of 8 (Qwen: 72).

780M (p2006, gfx1103, Linux), Qwen3.8, big1024 at 1,024 tokens, stage profile, warm encodes:
attention 604 ms with the fused kernel against 1,512 ms on today's path (the first version: 1,606);
the whole picture 1,202 ms against 2,151 (code4217: 290 against 351). Against our CPU tower:
big1024 0.999971 (today's path 0.999952), code4217 0.999743 (0.998636). Byte-identical over 4 encodes
and across two processes. Longest launch at 1,024 tokens 22.5 ms warm (55.6 ms on the first encode).
Job p2006-20261111-1543-5533. Strix not run yet.
2026-11-11 16:04:24 +01:00
Niko1221 81429a0238 tools/vision/own: a fused attention kernel for gfx11 (WMMA), behind STRATA_VIT_FA (off by default)
k_attn_fa_gfx11 does S = Q K^T, the softmax and O = P V of a chunk of queries for every head in one launch,
flash-attention style, with the gfx11 WMMA instruction (16x16x16, F16 in, float32 accumulate, wave32):
- one block = 4 waves = 64 queries of one head; each wave walks the keys in tiles of 32;
- the scores stay in float32; the softmax is online, in float32 (running row maximum and sum, expf);
- P is rounded to F16 for the second product, as before; O accumulates in float32 and leaves in float32;
- the head size is padded with zeros to a multiple of 16 (72 -> 80); no atomics, a fixed key order.
It replaces the score product, the three-pass softmax, the P*V product and the widen of today's path, and
needs no score buffer. Device code only for gfx11 targets (__GFX11__); other targets get an empty body
and never launch it.

STRATA_VIT_FA=1 turns it on, only on a gfx11 card with 32-wide waves and a head size of at most 96.
A launch takes at most STRATA_VIT_FA_UNITS (default 2^32) query x key x head triples, planned as about
100 ms on a Radeon 8060S, so no launch comes near the Windows GPU timeout of 2 s, also at the
16,384-token limit. With STRATA_VIT_PROF the longest launch of an encode is printed.

Built for gfx1151 (owner PC, owner-20261111-1226-681f): 187 VGPRs, no spills, 14,336 bytes of LDS
for the head-size-80 instance; 84 v_wmma instructions over the six instances. Not run yet.
2026-11-11 12:55:08 +01:00
Niko1221 0991006d2c strata-vision own CPU tower: SSE4.1 and AVX kernel tiers for x86 CPUs without AVX2
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).
2026-11-11 12:29:51 +01:00
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 888ded122f tools/vision/own: on gfx1151, products with F16 results and float32 accumulation by default
The Windows ROCm package's rocBLAS has tuned gfx1151 kernels for 16-bit results only (Tensile
BB_HPA / HH_HPA); BF16 / F16 -> F32, which the tower asked for, has only fallback kernels.
On gfx1151 the tower now takes, by default:
- STRATA_VIT_HPA16: weight products with a 16-bit result, float32 accumulation, widened after;
- STRATA_VIT_HPA16_ATT: the same for the attention's P*V product;
- STRATA_VIT_BF16_AS_F16: BF16 matrices held as F16 (the Pascal path), so every product gives an F16
  result (HH_HPA, 10-bit mantissa) and not a BF16 one.
Each variable set to 0 turns its part off. No other card changes; no user setting.

Strix (Radeon 8060S, Windows), 18 pictures at 1,024 tokens against mtmd-CPU, medians of 5 encodes:
- Qwen3.8 (BF16 file): 0.54-0.83 of mtmd-HIP's time, median 0.66; rule 1 and rule 2 pass on all 18
  (lowest global cosine 0.999285); byte-identical within a process and across two processes.
- Qwen3.6 (F16 file): 0.57-0.91, median 0.67; rule 1 and rule 2 pass on all 18 (lowest 0.999760).
- With BF16 results (no BF16_AS_F16) Qwen3.8 missed rule 1 on 3 pictures and rule 2 on 3.
- Before: 1.72-3.06 of mtmd-HIP's time with float32 results.
Jobs strix-20261111-1135-3669 (R2) and strix-20261111-1147-cbbb (R2b); RESULTS-OWN-3V.md PART F2/F3.
2026-11-11 11:51:05 +01:00
Niko1221 865d3ed4d1 tools/vision: Pascal P100 (compute capability 6.0) takes our picture reader under auto, also with F16 reader files
Until now, under `auto` a cc 6.0 card used llama.cpp's reader for F16 reader files (Qwen3.6, Unsloth's Qwen3.8 F16 file) at 1,024 picture tokens or fewer, because ours is slower there. It now uses our reader, as it already did for BF16 files and above 1,024 tokens. This follows the owner's rule of 11-11: our own code is the default where its accuracy gates pass, even where it is somewhat slower.

P100, Qwen3.6 F16 reader file, 18 pictures, against the x86 llama.cpp CPU references:
- ours: rule 1 0.999865 / 0.999969 (min / mean), smallest single token 0.9962;
- llama.cpp's GPU reader: 0.982913 / 0.994036, single tokens down to 0.19.
- time: 1,064 / 263 / 194 ms against 916 / 224 / 160 ms at 1,024 / 350 / 260 tokens.

llama.cpp's reader stays selectable through the Picture reader setting (STRATA_VISION_TOWER=mtmd) and stays the start fallback.

Pascal 6.1 / 6.2 (GTX 10xx, Jetson TX2) are not measured. They keep llama.cpp's reader up to the default limit, as before.

The unit test lines in test_gguf_geometry.cpp now match the new rule. The reason the reader gives on 6.1 / 6.2 says "not measured".
2026-11-11 11:18:26 +01:00
Niko1221 ba11522ea2 tools/vision/own: on Pascal the larger attention score chunk (32M) for F16 reader files too
On compute capability 6.x the CUDA picture reader already used a 32M-score attention chunk for BF16 files, which it holds as F16. F16 files (Qwen3.6, and Unsloth's Qwen3.8 F16 file) kept the 16 MB chunk. They now take the 32M chunk as well.

P100, Qwen3.6 F16 reader file, median of 5 encodes:
- big1024 (1,024 tokens): 1,243 -> 1,064 ms
- code4217 (350 tokens): 270 -> 263 ms
- shapes (260 tokens): 200 -> 194 ms
- rule 1 against the x86 llama.cpp CPU references: 0.999865 / 0.999969 (min / mean over 18 pictures), unchanged
- 48 MB more GPU memory than the 16 MB chunk

Host code only (load()); no device code changes, and other card classes are unaffected.
2026-11-11 11:17:45 +01:00
Niko1221 8499137ac5 tools/vision/own: HIP products with a 16-bit result and float32 accumulation, behind switches (off by default)
Lane COVER (phaseA-tests\par\RESULTS-COVER.md, 11-11) read the Windows ROCm package: its rocBLAS has tuned
kernels for gfx110x and gfx1151 for BF16 -> BF16 and F16 -> F16 with float32 accumulation (Tensile
BB_HPA, HH_HPA, every transposition), and only the generic fallback kernels for BF16 / F16 -> F32
(BS_HPA, HS_HPA), which our products ask for. mtmd's reader asks for the 16-bit result on RDNA3 and
RDNA3.5 (ggml-cuda.cu, prefer_f32_output).

- STRATA_VIT_HPA16=1: the 16-bit weight products ask rocBLAS for a result in the weight's type (BF16 or
  F16) with HIPBLAS_COMPUTE_32F, into a 16-bit buffer, then a kernel widens it to float32 for the rest of
  the layer. The result is the float32 sum rounded once to 16 bits, as mtmd's GPU reader keeps it.
- STRATA_VIT_HPA16_ATT=1: the same for the attention's P*V product (F16 -> F16). The score product
  S = K Q^T is already F16 -> F16 with float32 accumulation (HH_HPA).
- The 16-bit buffers are taken only when a switch is on. HIP builds only; the CUDA device code is unchanged.
- With no switch set the reader runs exactly as before.
2026-11-11 10:57:14 +01:00
Niko1221 e85fd8795a tools/vision: Strix Halo (gfx1151) takes our picture reader under auto, also on Windows
Owner, 11-11: "For Strix - use our reader, even if its a bit slower. We can always tune it better
afterwards. Our priority is to get off ggml and llama.cpp."

- vit_gpu_slower_amd is gone: gfx1151 no longer keeps llama.cpp's reader. On Strix our reader takes
  1.95 / 2.61 of llama.cpp's time on big1024 / code4217 (hipBLAS products; RESULTS-OWN-3V.md PART F),
  and passes rule 1 and rule 2 on 18 pictures with both models (12.14).
- The Windows HIP hold now leaves out gfx1151, the one card measured with the Windows HIP package:
  vit_gpu_hip_windows_not_measured(windows, gfx). Every other Windows HIP card keeps llama.cpp's reader
  under auto as before; Linux HIP is unchanged.
- llama.cpp's reader stays selectable (the Picture reader setting, --tower mtmd) and still takes over by
  itself when ours does not start.
- Unit test: gfx1151 (with and without a feature suffix) on Windows takes ours; gfx1201, gfx1100 and
  gfx1150 on Windows keep llama.cpp's reader; Linux takes ours.
2026-11-11 10:39:34 +01:00
Niko1221 8b780f5899 Merge commit '6ccf276d2' into f-own-3s 2026-11-11 10:37:03 +01:00
Niko1221 5abd50c1a2 tools/vision/own: hipBLASLt for the HIP tower's products, behind switches (off by default)
On gfx1151 (Strix Halo) the Windows package's rocBLAS has only its generic fallback kernels, and the
tower's hipBLAS products made it 1.7 to 3.0 times mtmd-HIP's time (RESULTS-OWN-3V.md 12.14, section 14).
HIP builds that find hipBLASLt now carry a second path for the products:

- STRATA_VIT_LT=1: the 16-bit weight products (y = x W^T, F32 out, F32 compute)
- STRATA_VIT_LT_ATT=1: the two batched attention products (S = K Q^T, O = V P)
- STRATA_VIT_LT_SOL=<id>: that solution for the weight products instead of hipBLASLt's first heuristic answer
- STRATA_VIT_LT_VERBOSE=1: the solution of every new shape and a summary on stderr

Each call shape gets its solution once per process, by id or as the first heuristic answer that fits a
32 MB workspace, never by timing, so two processes run the same kernels. A shape hipBLASLt cannot run, or
a launch that fails, goes to hipBLAS as before. The float32 patch product stays on hipBLAS. With no
switch set the reader runs exactly as before; the rule that keeps mtmd on gfx1151 is unchanged.
2026-11-11 08:23:20 +01:00
Niko1221 59e0758810 tools/vision: our picture reader is the default (owner 11-11: "Our tower, the other selectable"); llama.cpp's mtmd reader stays selectable and takes over by itself where ours was measured slower or does not start
- the default tower is `auto` (was mtmd); without --tower, STRATA_VISION_TOWER=mtmd|own|auto decides (the run config's env carries it when someone picks llama.cpp's reader; an older strata-vision ignores it); an explicit --tower wins
- `auto` now takes ours on Metal (gate passed on the M5 Max, RESULTS-OWN-3V.md D1/D4-D8) and on MSVC x86 builds (rule cab87a2e8 removed: 0.986 of mtmd-CPU since 54f9cc3c0, D2)
- kept: gfx1151, Pascal with F16 matrices at <= 1,024 tokens, x86 without AVX2; new hold: every card on Windows HIP (not measured with the Windows ROCm package; remove when one RX 9000 / RX 7000 run on Windows is in)
- under `auto`, a failure of ours before READY (no GPU, the load, the warm-up) writes nothing on stdout; strata-vision logs the reason and starts mtmd's reader in the same process; `--tower own` keeps its hard failure
- READY names the reader: "READY <n> own", "READY <n> mtmd", "READY <n> mtmd fallback" (servers read only the start)
- test hook STRATA_VIT_TEST_FAIL=gpu|load|warmup; unit tests for the default, the Windows HIP hold, the soft start and the hook (p2006 job p2006-20261111-0743-7d3b: strata-vision-own-test ok, cpu-test all passed)
2026-11-11 07:44:24 +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 cacaa66437 tools/vision/own: the Qwen vision tower on a Mac's GPU (Metal)
vit_metal.mm implements VitGpu for Metal, the counterpart of vit_gpu.cu (CUDA / HIP) and vit_sycl.cpp (Intel): the same host flow and the same numbers (weights as stored, BF16 or F16; 16-bit product inputs of the weight's type with float32 accumulation; q / k / v and the scores in F16; the same chunk rules), its own small Metal host (one device, one queue, shared buffers, one command buffer per layer), and the kernels in vit_metal.metal / vit_metal_mpp.metal embedded into the program at build time and compiled when the reader starts, so strata-vision stays one file that links only Apple's frameworks.

The weight products, the scores and the P*V product run on the Metal 4 tensor ops (MetalPerformancePrimitives matmul2d) where they compile and a self-test against the exact product passes, decided per product at load and logged once; else on a plain simdgroup kernel (STRATA_VIT_NO_MPP=1 asks for that; STRATA_VIT_NO_MPP_W / _S / _PV per product). The float32 patch product is a one-output-per-thread kernel: the first run of the tiled simdgroup kernel costs the process about 136 MB of GPU-owned memory on an M5 Max, which a Mac with the tensor ops then never pays. Diagnostics: STRATA_VIT_PROF (stage times), STRATA_VIT_MEM (footprint per load step and per first kernel run).

Built with STRATA_VISION_METAL on Apple (the helper) or STRATA_VIT_OWN_METAL (standalone); gate_gpu.py reads the reader's memory on macOS from `footprint`. `--tower auto` still reads with mtmd on a Mac (VitGpu::prefer_mtmd returns true on Metal until the numbers are confirmed); `--tower own --gpu` runs this tower.

Gate on an M5 Max (macOS 27.2), 18 pictures at 1,024 tokens, 5 repeats:
- rule 1 against x86 mtmd-CPU references of the same pictures and reader files: Qwen3.6 min 0.999943 mean 0.999984, Qwen3.8 min 0.999717 mean 0.999902 (mtmd-Metal: 0.999599 / 0.999895 and 0.998006 / 0.999694); rule 2 18/18 on both
- speed 0.47 to 0.79 of mtmd-Metal (big1024 222 against 362 ms, Qwen3.6)
- memory (footprint) 1,235 against 1,313 MiB (Qwen3.6), 1,228 against 1,329 (Qwen3.8)
- byte-identical over 6 encodes and in a second process
- answers (Qwen3.8, replayed through a CUDA engine): 67 of 72 identical to mtmd-Metal's, wrong answers 0 against mtmd-Metal's 1
strata-vision-own-test passes; no warning in the tower's files.
2026-11-11 01:29:05 +01:00
Niko1221 88fc47ccf0 tools/vision: --tower auto uses our GPU tower on every CUDA class when the reader starts with --max-tokens above 1,024 (the default GPU limit), whatever the speed: at 16,384 tokens mtmd-GPU reads 0.81 to 0.83 against mtmd-CPU (A4000 0.813, RTX PRO 5000 0.834, P100 0.834), ours 0.9996 to 0.99998, at a time cost on Pascal (P100, Qwen3.8, 16,384 tokens: 196.6 s against mtmd-GPU 129.0 s); at or below 1,024 the speed rules stay (Pascal with F16 matrices and cc 6.1 / 6.2 keep mtmd); AMD gfx1151 and Metal unchanged; own_reader_supported and prefer_mtmd take max_tokens; unit test 2026-11-10 12:20:55 +01:00
Niko1221 87d9715922 tools/vision/own: the CPU tower's elementwise kernels (GELU, LayerNorm, add, the online-softmax step) run on a raw vector type with free inline functions (VR, vr_*): __m256 / __m512 in the AVX2 and AVX-512 tiers (STRATA_KN_RAW), the old struct V through adapters in the scalar and NEON tiers; the same operations in the same order (MSVC kept the wrapper struct in memory, the rest of its CPU speed miss). GCC: outputs byte-identical old vs new on 6 pictures x 2 models on p2006 AVX-512, AVX2 and scalar and on z440 AVX2 (Qwen3.6); no weak symbols in the tier objects; unit test passes; speed new/old 0.97 to 1.00 (big1024 AVX-512 0.982, AVX2 0.979 / 0.992, scalar 1.002). MSVC not measured 2026-11-10 11:57:13 +01:00
Niko1221 e83138654b tools/vision/own: Pascal (cc 6.x) holds BF16 matrices as F16 (cuBLAS has only a slow BF16 kernel there: 645 against 497 ms of a 1,024-token picture on a P100) and, with them, takes a 32M-score attention chunk; auto now reads with our tower on cc 6.0 when the mmproj's matrices are BF16 (Qwen3.8: P100 gate PASS, rule 1 min 0.999636, 0.32 to 1.00 of mtmd-GPU's time, 1,362 against 1,364 MiB) and keeps mtmd with F16 matrices (Qwen3.6: mtmd's F16-accumulating products stay faster, ours 0.75 to 1.37) and on cc 6.1 / 6.2 (not measured); STRATA_VIT_BF16_AS_F16 diagnostic 2026-11-10 11:17:34 +01:00
Niko1221 df52e70b4d tools/vision/own: above 16,384 patches the GPU attention pads its score rows to 64 elements and takes a multiple of 64 queries per chunk (limit_7000x5000.png, 65,232 patches, on the RTX A4000: 108.1 s -> 80.3 s, 0.79 of mtmd-GPU (was 1.07), rule 1 0.999982, 3,168 MiB against 3,656; limit_4096x4096.png 0.78, unchanged); pictures up to 16,384 patches unchanged; STRATA_VIT_NPAD / STRATA_VIT_QALIGN diagnostics. HIP shares the code, not measured there 2026-11-10 11:13:54 +01:00
Niko1221 fd14cd6858 tools/vision/own: when the large attention chunk above 16,384 patches does not fit, the GPU towers take the default chunk instead (slower, never an error; CUDA and SYCL); STRATA_VIT_SCORES_LARGE (a diagnostic) sets the large size; checked on z440 (falls back to 106.5 s at 2,272 MiB, rule 1 0.999981) and the A750 (147.8 s, rule 1 0.999696) 2026-11-10 05:53:00 +01:00
Niko1221 8c593a000f tools/vision/own: the AVX2 and AVX-512 tiers' product micro-kernels on raw __m256 / __m512 (no wrapper struct in the hot loop, for MSVC); the same operations in the same order: outputs byte-identical to the previous kernels on p2006 (AVX-512 and AVX2) and z440 (AVX2), GCC speed level (p2006 big1024 7,189 against 7,271 ms, 5 pairs) 2026-11-10 04:18:08 +01:00
Niko1221 cab87a2e8f tools/vision/own: --tower auto keeps mtmd on an MSVC-built x86 CPU reader (owner PC, Zen 4: 33.4 s against mtmd-CPU's 18.5 s at 1,024 tokens, while the GCC build is 0.80 to 0.95 of mtmd-CPU); keyed on the compiler, not the OS; unit test; --tower own unchanged 2026-11-10 04:10:04 +01:00
Niko1221 dd04305efd tools/vision/own: --tower auto keeps mtmd on AMD gfx1151 (Strix Halo), where rocBLAS ships only fallback kernels and the own HIP tower takes 1.73 to 3.03 of mtmd-HIP's time (Windows, Strix); the Pascal and gfx1151 rules are pure functions in vit_gpu.h with a unit test; --tower own unchanged 2026-11-10 03:17:43 +01:00
Niko1221 9e5f5a5ed7 tools/vision/own: --tower auto uses our CPU tower on Arm (NEON gate on the DGX Spark: rule 1 PASS on both models, 0.57 to 0.81 of mtmd-CPU's time on F16 and 0.08 to 0.13 on BF16); the scalar-only rule stays for x86 without AVX2 only 2026-11-10 02:24:39 +01:00
Niko1221 5abd6688db tools/vision/own: the NEON tier's own product micro-kernel with lane-indexed FMAs (8 x 8 tile, one vector load per A row for four k steps; the same summation order, outputs byte-identical to the previous NEON tier): DGX Spark Qwen3.6 F16 0.57 to 0.81 of mtmd-CPU's time (was 1.14 to 1.24 on the large pictures) 2026-11-10 02:18:22 +01:00
Niko1221 dcd0ac1605 tools/vision/own: the AVX2 F16 rounding passes _MM_FROUND_TO_NEAREST_INT alone to _mm256_cvtps_ph (the VEX form takes a 3-bit rounding value; MSVC C4556); GCC encoded imm 8, which the hardware reads as round to nearest too: outputs byte-identical with STRATA_VIT_REF_ROUND=1 on F16 weights 2026-11-10 02:12:01 +01:00
Niko1221 92d379070d tools/vision/own: the Arm NEON kernel tier of the CPU tower (cpu_kernels_neon.cpp, baseline AArch64, 12 x 8 tile, on the cpu_tier.h contract; quant::Isa::Neon is the best tier on AArch64, STRATA_FORCE_ISA=scalar still forces the portable one); --tower auto keeps mtmd on Arm until the gate is accepted 2026-11-10 02:05:15 +01:00
Niko1221 d894c31688 tools/vision/own: a larger attention score chunk above 16,384 patches on the GPU towers (CUDA / HIP 512M scores, SYCL 256M): at 16,384 tokens l620 33.4 s -> 24.8 s (0.87 of mtmd-GPU, 3,398 MiB against its 3,858), A750 147.9 s -> 118.3 s; pictures up to 4,096 tokens unchanged; STRATA_VIT_SCORES still sets one size for all 2026-11-10 02:04:21 +01:00
Niko1221 aa2a3f956c tools/vision/own: --tower auto keeps mtmd on a CPU that has only the portable kernel tier (x86 without AVX2, Arm until a NEON tier exists), where the own CPU tower is 2.1 to 3.7 times slower than mtmd-CPU; --tower own unchanged 2026-11-10 00:58:41 +01:00
Niko1221 6311744b37 tools/vision/own: the Qwen vision tower on Intel GPUs (vit_sycl.cpp: SYCL kernels + oneMKL, the VitGpu class of vit_gpu.cu with the attention context written head by head and a 64 MB score chunk; strata-vision-sycl --tower own --gpu); gate_gpu.py reads GPU memory from Linux DRM fdinfo and reports whether our GPU tower is byte-repeatable 2026-11-10 00:42:46 +01:00
Niko1221 b56dc8acf9 tools/vision/own: the AVX2 / AVX-512 kernel files hold no standard-library code (cpu_tier.h, C headers and intrinsics only; min / max / copy / zero as their own internal helpers, expf through an out-of-line baseline function), so no inline library function is compiled with their ISA flags and kept for the whole program; outputs byte-identical on every tier 2026-11-10 00:42:38 +01:00
Niko1221 1f74860fa2 tools/vision/own: --tower auto keeps mtmd on NVIDIA Pascal (compute capability 6.x), where the own GPU tower is slower than mtmd (P100 gate); --tower own unchanged 2026-11-09 23:57:41 +01:00
Niko1221 ebfc6e62f0 tools/vision/own: the reference attention's query block is static constexpr (MSVC rejected acc[QB][128] with QB a const local used inside the lambda, C2131 / C3863) 2026-11-09 23:49:28 +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 423225d879 tools/vision/own: the CPU path of --tower own is the fast tower (VitCpu); STRATA_VIT_CPU=ref selects the float32 reference 2026-11-09 20:02:02 +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 f5db05f106 tools/vision/own: GPU tower speed on small pictures (short-row softmax kernel sized by row length, score rows padded to 8), STRATA_VIT_PROF stage timings, STRATA_VIT_CPU=fast switch in the reader; fork-join team: the task count carries the run tag (one task ran twice in 31 of 60 test runs), team-only test mode 2026-11-09 19:27:35 +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