Commit Graph
24 Commits
Author SHA1 Message Date
Niko1221 9e3ad2778f Accelerate Unsloth quants and NVFP4 across Metal, SYCL, and HIP RDNA2-4
Add first-class Unsloth quant (Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, Q8_0, IQ4_XS, IQ3_XXS) and NVFP4 (type 40) support and optimizations across Apple Silicon Metal, Intel Arc SYCL, and AMD RDNA2/3/3.5/4 HIP backends:

- Metal (engine/metal/): Add T_IQ3_XXS, T_Q2_K, T_Q3_K, T_Q8_0, and T_NVFP4 across quant, units (incl. STRATA_METAL_F16), mma, dense_mm, gemv, gemvu, gr (BF16+F32 inject), moe, moeu, and moe_mm (v1/v2/v3/v4/v6 ragged tiles + halved-load W8 for IQ4_XS/IQ4_NL), plus host dispatch (window.cpp, prompt_chain.inc, moe_tiles.h, ref_quant) and parity suites.
- SYCL (engine/sycl/): Add full NVFP4 (40) decode/dequant/combine with exact s_gate/s_up/s_down tail scales in all branches, hoisted Split<TY>/KqSplit<TY> across all Unsloth/NVFP4 types, opt-in SYCL EXP_MODE=8 with had_block==0 guard, SG16 XMX SLM decoders for Q4_K/Q5_K/Q6_K/IQ4_XS/NVFP4, and expanded parity suites.
- HIP (engine/include/strata/kernels/hip_unsloth_*.hpp, engine/src/kernels/hip/): Add clean-room RDNA2/3/3.5/4 Wave32 DP4A + hoisted HipSplit<TY> + fused EXP_MODE=8 (had_block==0 guard, 65535-safe grid striding, exact NVFP4 tail scales) and unified gfx11/gfx12 Wave32 WMMA FP16/BF16/INT8 + fused dequant-to-LDS prefill kernels with standalone 5-arch verification harness.
2026-11-22 19:51:03 +01:00
Niko1221 534802c8dc engine: integrate #6406, #6529, #6550, #6523 and fix #6515, #6431, #6462, #6423, #6417, #6493, #6533, #6470 2026-11-22 13:23:13 +01:00
Niko1221 0f1738e611 engine: integrate #6547, #6548, #6538, #6465 (batched MTP, QSA stream batch, persistent spill, bounded swap) 2026-11-22 13:02:10 +01:00
Niko1221 ad4c565e86 engine: integrate #6549, #6532, #6543, #6545, #6546, #6554 2026-11-22 13:01:28 +01:00
Niko1221 d1f409140c Merge f-0219-sm120: Blackwell sm_120, Ada sm_89, and Ampere sm_86 Flash-Next optimizations 2026-11-22 04:19:02 +01:00
Niko1221 a2ca43e53b cuda: sm_120/121/89/86 Wave-2+3 decode/prefill multipliers, partial-cache fix, and defaults 2026-11-22 02:27:43 +01:00
Niko1221 431a26db11 cuda/cpu: sm_120 & sm_86 prefill, decode, DFlash2 TC, and default stack optimizations
Add clean-room MIT Blackwell (sm_120) and Ampere (sm_86) speedups for Qwen3.8-Flash-Next across IQ3_S, UD-Q4_K_XL, and NVFP4 with zero quality loss (STRATA_ROUTE_TAIL_SKIP=0; force_check.py PASS -0.042 pts, 0 events):

- Prefill pipeline & CPU pool:
  - Warm CUDA GEMM libraries at init to remove cold cuBLAS stall (2.4-3.8x faster TTFT).
  - Pre-pin cpu_x/cpu_rows/cpu_ones + dedicated async cpu_x_stream D2H and ExpertPool::run_range parallel native_quant_act (host grouping 81->7 ms on RTX 5090, 114->16 ms on RTX 3090).
  - Parallelize in-memory PleTable::gather_batch across up to 8 threads and skip per-row madvise syscalls when --ple-io ram already faulted pages (eliminates ~40 ms FP8 PLE stall on NVFP4).
  - Upgrade x86 AVX-512 VNNI dot_nvfp4_q8_0 to mul_sum_i8_pairs_float and register ENTRY(NVFP4, Q8_0, nvfp4_q8_0) (138-147 GB/s CPU pool BW; quant_selftest PASS).
  - Optimize sm_120a/sm_121a mxf4nvf4 MoE prefill v3 (NT=256, single-pass TR=64, coalesced loads, 0 spills, 1.37x at T=8192).
- Decode & DFlash2 verification:
  - Add clean-room sm_80+ BF16 Tensor Core DFlash2 attention (2.1x faster attention, -0.10 to -0.20 ms/round drafting).
  - Fix native_mmvq launch_multi chunking (>8 cols, 0 cuda_spill_guard spills) and keep interleaved native_mmvq_il for ncols 1..8 while routing ncols 9..16 to dense_i8_tc (with WARPS=1 small-N specialization).
  - Hoist Split<TG>::load outside NTC loop in native_gu_fused_kernel and extend to Q4_K, Q5_K, and NVFP4; add opt-in coalesced sm_120a nvfp4_decode_sm120 (STRATA_NVFP4_DEC_SM120=1) and opt-in vhead_bitplane (STRATA_VHEAD_BITPLANE=1) with out_nonfinite support.
  - Default sm_80+ Q8_0 HC to exact-FP32-activation gr_down_q8_fast + gr_up_q8_fast (0 KLD loss; opt-in INT8 TC via STRATA_HC_Q8_TC=1/2).
- Defaults & tests:
  - Enable verified sm_120 and sm_86 defaults in nv_defaults.cpp (with STRATA_VERIFY_DEVICE_HITS=1 + auto pcie_frac=0 on >16 GiB single-GPU cards, preserving ADAPT_FETCH=2 on <=16 GiB cards) and update nv_defaults_test.cpp.
2026-11-21 23:10:29 +01:00
Niko1221 d31256b79d rdna3: Phase 3 CU-safe/WDDM-safe WMMA DFlash2, rdna_gr, rdna_mmvq, and GDN megakernel 2026-11-21 21:31:25 +01:00
Niko1221 34b82b5409 rdna3: Phase 1 WDDM coherent alloc, gfx1100-1151 defaults, and AVX512BW+VNNI ZMM dots 2026-11-21 21:31:24 +01:00
Niko1221 e78cd033ca cuda: add clean-room bit-plane LM head, INT8 TC dense GEMM, and mxf4nvf4 v2 2026-11-21 20:39:07 +01:00
Niko1221 a14c910fe6 Engine: rebase MIT sm_120a/sm_121a mxf4nvf4 prefill and partial-VRAM device hit planning onto 0.2.18 2026-11-21 19:48:39 +01:00
Niko1221 e9c9d504cc CPU rows prefetch: the non-x86 branch passes a constant locality to __builtin_prefetch (clang on arm64 refused the computed one; the Metal engine did not build)
BW-G's row_prefetch.hpp (STRATA_ROW_PF) chose the locality with a conditional; __builtin_prefetch needs a constant integer. One call per case, the same three localities. x86 is unchanged (it takes the _mm_prefetch branch).
2026-11-19 16:39:25 +01:00
Niko1221 902ea23283 CPU pool: STRATA_POOL_DEP is on by default (the per-expert dependency queue of a native layer call); STRATA_POOL_DEP=0 is the way back
BW-G measured it bit-exact (BASE-05 27 of 27, pool_determinism --reps 20, 124,656 checks) with the CPU pool's window -2.9% on an RTX 5090 + EPYC box.
ExpertPool's constructor reads the variable once: unset or anything but "0" is on. Not under the NUMA split and not for Q2_0 down rows, as before.
A second ctest, pool_determinism_dep_off, runs pool_determinism with STRATA_POOL_DEP=0 so the way back stays covered.
2026-11-19 16:23:12 +01:00
Niko1221 abb120c5e7 CPU Q2_0 rows: a CPU with AVX but no AVX2 takes Strata's AVX1 rows, and the AVX1 bit-plane row does its float work on 256 bits (#4854)
From PR #4854 (Keoian; its commits 43e390e0e and 7a68664ac), author kept. On a CPU with AVX and no AVX2 (the older-CPU
source build, STRATA_ISA_FLOOR=avx) q2_native_kernels() admitted AVX2 only, so every native pack's Q2_0 expert ran on
ggml-cpu's own vec_dot and never reached the AVX1 rows of q2_avx1.cpp. It now also admits cpu_avx1_ok(); a CPU
without AVX keeps ggml-cpu. On a CPU with AVX2 nothing changes (the first term is true as before). The AVX1 bit-plane
row (STRATA_Q2_BITPLANE=1) computes a pair's float part in one 256-bit register, block 0 in the low lanes and block 1
in the high ones, each lane with the operations of the 128-bit form, so its bytes do not change; h2f_scale converts a
normal fp16 block scale in four integer operations (h2f's normal branch, bit for bit; zero, subnormals, inf and NaN
still take h2f). Author's numbers (i7-3770): a one-token Q2_0 expert 0.975 ms on ggml-cpu, 0.487 ms on the AVX1 rows,
0.297 ms with the bit-plane form; decode on 2x RX 5700 XT 14.97 to 22.38 tok/s. Not measured by us (no AVX-only CPU);
q2_bitplane_parity (AVX1 form against its 128-bit legacy form) with STRATA_Q2_BITPLANE=1 is in the gate table.
2026-11-19 16:19:22 +01:00
Niko1221 4e94b05592 SYCL start-up line: a CPU with AVX-512 VNNI but no VBMI no longer reads "no AVX-512" (#5481)
From PR #5481 (nekorobi-0; its commit 0946bbd77), author kept. On a CPU with AVX-512 VNNI and
no VBMI (Cascade Lake) the SYCL engine's start-up line said "this CPU has no AVX-512: the expert kernels run on AVX-2",
even with STRATA_VNNI_TIER=1 on. The line now says which case it is: no AVX512-VNNI at all; the VNNI tier off or not
available; or (with the tier on and no VBMI) "AVX-512 VNNI tier enabled (no VBMI)". The cpu_vnni_ok() header comment
names the DQ requirement and the switch, and docs/DETAILS.md gains the STRATA_VNNI_TIER row (off by default: those
rows round differently from the AVX-2 rows). Log text and docs only; no computation changes. The two new lines are in
the results file's text list.
2026-11-19 16:19:21 +01:00
Niko1221 88b8578c3b Merge f-fix-eng (FIX-ENG) into f-eng-0163 2026-11-19 16:18:56 +01:00
Niko1221 29ca1fca37 Merge f-bw-e (BW-E: CPU prompt share, VNNI rows) into f-eng-0163 2026-11-19 16:18:53 +01:00
Niko1221 edef565b90 CPU pool: STRATA_POOL_DEP=1 runs a native layer call as one batch with per-expert dependencies (opt-in, off by default)
The two row phases of run_split_multi_native (gate/up, then down) end in a barrier: every worker waits for the slowest task of the phase, and the host quantizes the intermediate between them. With STRATA_POOL_DEP=1 the layer call is one batch (mode 7): the experts' gate/up row ranges first (expert-major), then the experts' down row ranges. A down task waits only for its own expert's gate/up tasks (a counter), and the first thread that gets there quantizes that expert's intermediate once. Every gate/up task has a lower index than every down task and waits for nothing, so a waiting down task always waits for a running task. The rows are computed by the same kernels from the same bytes: the outputs are the two-phase batch's bits (bwg_pool_bench hashes equal for Q4_K/Q5_1 and Q4_K/Q8_0 experts, 1-3 tokens, tasks 0 / 41 / 132, 1 and 3 workers). Not used under the NUMA split or for Q2_0 down rows.
2026-11-19 12:37:34 +01:00
Niko1221 a9a00cd48e CPU expert rows: STRATA_ROW_PF=<bytes> requests the weights a few rows ahead (opt-in, off by default)
The Q4_K / Q5_1 / Q8_0 row loops of native_gu_rows / native_down_rows can request the next rows of the expert while the current row is computed (row_prefetch.hpp; t0 / t1 / nta hint, a prologue for the first rows). It reads and writes nothing: the results are the same bits. On a 22-worker pool over a cold 6 GB arena it moves the layer call by at most 2.5% (0.389 to 0.379 ms), so it stays off.

Adds bwg_pool_bench: the pool's own run_split_multi_native on UD-shaped synthetic experts (Q4_K gate/up, Q5_1 / Q8_0 down), cold or hot arena, optional MADV_HUGEPAGE, a hash of the outputs.
2026-11-19 12:33:39 +01:00
Niko1221 2720fddb11 Prompt indexer: the batch append's refusal names the failed predicate and its values (#5822)
native_qsa_indexer_append_batch threw one text, "bad geometry, positions, parameters or scaling", for seven different causes (no stream, a wrong
geometry, a negative position, positions past the session's cells, a cell count or base past 2^31, a bad epsilon, a bad RoPE scaling). Three engine
exits on 0.1.58 could not be told apart, and nothing in the log said whether a prefix reuse had handed the append a position past the session.

The check moved into strata/kernels/qsa_batch_check.hpp (pure, no GPU): the text now starts as before and ends with the first failed predicate and
its values (p0, n and the session's cells, the block, the epsilon, the RoPE problem). The conditions are the same as before, so no request that
passed fails and none that failed passes.

Test: qsa_batch_check_test (every predicate, the position case with p0 / n / cells in the text, the old text kept at the start).
2026-11-19 11:36:29 +01:00
Niko1221 461b94b43a CPU experts: AVX-512 VNNI multi-token rows for UD-Q4_K_XL (Q4_K gate/up, Q5_1 and Q8_0 down)
The Q4_K gate/up rows had no 512-bit tier in the default build (the quant layer's Avx2 contract, one token at a time), and the Q5_1 / Q8_0 down rows had a
256-bit VNNI tier per token.  kq_avx512.cpp runs the integer part of every block on vpdpbusd (Q4_K: 64-byte vectors, the 6-bit scales through vpdpwssd) with the
weights decoded once per row for every token of a group, and keeps the AVX2 contract's float chain (the eight-lane accumulator, the mins term, the hsum) so each token's
row is the one-token dot's bit for bit.  Dispatch only on a CPU with AVX-512 F/BW/VL/DQ/VNNI/VBMI (cpu_avx512_ok); the old rows stay the fallback; kq512_ok checks the
rows against the build's own dot on first use and sends a mismatch back to it; STRATA_NO_KQ512=1 never takes them, STRATA_KQ512_MIN=N moves the token floor (gate/up 3, down 2).

kq512_parity (840 cases: 1 to 160 tokens, real and raw-byte activations, row ranges, the SwiGLU of the gate/up rows) is bit-equal on a Xeon 8352V and skips (77) without
AVX-512.  One thread, 256 rows, Xeon 8352V: Q4_K n=2560 8 tokens 113 us against 182 us for the dot per token and 125 us for the AVX2 multi-token rows, 64 tokens 767 / 1474 / 1054;
Q5_1 n=640 8 tokens 44 / 122 / 78; Q8_0 40 / 67 / 48; one token is slower than the dot (Q4_K 68 against 38 us), hence the floors.
2026-11-19 10:26:21 +01:00
Niko1221 20338d1f86 Measuring switch: STRATA_DIAG_POOL=1 times the parts of the CPU pool's native expert rows
Accumulates, per pool, the time of run_split_multi_native split into the wait for the workers to park before each
phase, the phase from publish to the last task done, the wait for the workers to park after it, the host's
activation quantization between the two phases, and per worker the time inside the row tasks and the time from
publish to leaving the park. One line every 2,000 calls and one when the pool ends. Diagnostic only; off without
the variable. Re-applied from 24d6ab38f (f-diag-pool) onto the 0.2.16 layout.
2026-11-19 06:47:44 +01:00
Niko1221 3a0e346db1 Verify window: STRATA_L2_PF=1 prefetches the next layer's dense weights into L2 while the window waits for the CPU experts
A kernel on the shared expert's low-priority side stream issues prefetch hints (cp.async.bulk.prefetch.L2 on
sm_90+, prefetch.global.L2 below) over the next layer's GGUF-form projections, hyper-connection and router
weights and the shared expert's, from the point the wait for the CPU rows starts, and joins through the shared
expert's event. The hints read and write nothing, so the window's values are the same bits. Default off;
STRATA_L2_PF_MIB=n keeps the first n MiB of a layer (in the order the layer reads them), STRATA_L2_PF_BLOCKS
sets the grid. Only the doorbell graph with CPU experts (not all-resident, not a split or batch window,
not the stage profiler). CUDA only (a no-op kernel on HIP is not launched). WeightRef gets native_bytes.
2026-11-19 06:47:38 +01:00
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00