diff --git a/docs/SYCL_PROGRESS.md b/docs/SYCL_PROGRESS.md index 9f7f1bb2..0734c442 100644 --- a/docs/SYCL_PROGRESS.md +++ b/docs/SYCL_PROGRESS.md @@ -12,7 +12,7 @@ from it alone. | 1 codebase study, `SYCL_PORTING.md` | done (`docs/SYCL_PORTING.md` §1-§3, Appendix A) | | 2 design | done: device backend, build integration, core kernels (`device_test_sycl` on the B65) | | 3 correctness-first kernels | **Milestone A reached 2026-10-23** (`874f8d2`): MiniCPM5-2B bf16 serves on the B65, greedy-identical to the libref host backend; Milestone B next | -| 4 performance | MiniCPM5-2B bf16: decode 4.2 -> 51.8 tok/s, prefill 17 -> 1576 tok/s (`b07da2a`); Qwen3.8-27B-PARO-M2XFP4 (the model from 2026-10-23): 0.1 -> 13.2 tok/s decode, in progress | +| 4 performance | MiniCPM5-2B bf16: decode 4.2 -> 51.8 tok/s, prefill 17 -> 1576 tok/s (`b07da2a`); Qwen3.8-27B-PARO-M2XFP4 (the model from 2026-10-23): 0.1 -> 30.6 tok/s decode with the DFlash2 drafter, prefill 124 tok/s (`b0e34c6`), in progress | | 5 broaden and finish | not started | ## Open blockers / questions for the user @@ -160,6 +160,7 @@ fonts (this host has none; the first post had no text) -- all unpacked without r | 2026-10-23 | `874f8d2` | minicpm5-2b-bf16 | sycl, correctness-first kernels | `--num-speculative-tokens 0 --max-model-len 8192 --max-num-seqs 4` | 17.3 / 17.3 @2000 (8000+ skipped: over the 8192 context) | 4.2 / 3.5 | first run | `~/radiance-bench/runs/20261023-165102-minicpm5-2b-bf16-874f8d2/results.html`, posted with `report.jpg` | | 2026-10-23 | `a869226` | minicpm5-2b-bf16 | sycl, Phase 4 step 1 (GEMV) | same | 17.5 / 17.4 @2000 | 25.3 / 16.2 | decode +504.5% | `~/radiance-bench/runs/20261023-194856-minicpm5-2b-bf16-a869226/results.html`, posted with `report.jpg` | | 2026-10-24 | `5720a95` | qwen38-27b-m2xfp4 (Qwen3.8-27B-DFLASH2-PARO-M2XFP4) | sycl, fast m2xfp4 GEMV / DPAS verify / tiled XMX prefill, DFlash2 drafter on | `--max-model-len 8192 --max-num-seqs 4` | 113.4 / 113.3 @2000 | 19.1 / - | first run | `~/radiance-bench/runs/20261024-060226-qwen38-27b-m2xfp4-5720a95/results.html`, posted with `report.jpg` | +| 2026-10-24 | `b0e34c6` | qwen38-27b-m2xfp4 | sycl, the speculative round's kernels (draft head and logits on DPAS, exact selection ops, typed gdn, vector norm, register-DPAS verify GEMM) | `--max-model-len 8192 --max-num-seqs 1` | 131.3 / 130.6 @2000 | 28.9 / - | decode +51.5%, prefill +15.8% | `~/radiance-bench/runs/20261024-135808-qwen38-27b-m2xfp4-b0e34c6/results.html`, posted with `report.jpg` | | 2026-10-23 | `b07da2a` | minicpm5-2b-bf16 | sycl, Phase 4 steps 2-6 (XMX prefill, split-KV attention, norms, GEMV split) | same | 1575.6 / 1547.1 @2000 | 51.8 / 41.4 | decode +104.7%, prefill 90x | `~/radiance-bench/runs/20261023-221354-minicpm5-2b-bf16-b07da2a/results.html`, posted with `report.jpg` | ## Models @@ -572,8 +573,53 @@ Probes in the scratch directory, not in the tree: `gemm.cpp` (XMX GEMM tilings), m2xfp4 data), `chain.cpp` (the ordered-sum floor), `jmap.cpp` (joint_matrix_apply coordinates on a packed B -- lost the device; not used). +## Qwen3.8-27B: the speculative round (2026-10-24) + +**What the target means.** The user's vLLM numbers (~90 tok/s decode, ~1200 tok/s prefill) are for +`Swift-1.5-Qwen3.8-27b-GPTQ-Int4-baked-v1-embed-int8` with MTP6 speculation: its model card's own +records (`benchmarks/swift-baked-coding-c1.jsonl`) show ~5.3 tokens a round at ~68 ms a round. One +token at a time is bandwidth-bound near 40 tok/s on this card, so the lever is the cost of a round, +not acceptance: radiance's DFlash2 drafter already lands 4.2-4.3 tokens a round (45-47% of drafts +accepted, `/metrics` `radiance:draft_*`), but a round cost ~235 ms. + +**Per round, device time** (`scripts/sycl/profile_decode.sh`, 256 tokens, grouped by geometry): + +| op | before | after | how | +|---|---|---|---| +| w2a8 draft head (N=248320) | 24.0 ms | 4.2 | int8 DPAS on the group sums, u2 codes unpacked into the packed B tile; lane-per-column group terms in order: bit-identical (63/63 live calls against the libref-checked form) | +| dflash_select | 11.4 | 0.5 | a sub-group a sequence, a lane a candidate in libref's order: exact | +| row_topk (R=32 of 248320) | 3.2 | 0.95 | 128 chunks' top R, then the top R of the winners: exact | +| logits head, M = 8 | 9.5 | 3.5 | E4M3 by bits into a packed fp16 tile, fp16 DPAS, a scale block's sum scaled in f32 (also M = 1: 3.9 -> 3.4) | +| gemm_nt bf16, N=96 x 48 | 7.7 | 1.4 | M <= 8 on bf16 DPAS, 8 activation rows in local memory, K split | +| rmsnorm_quant_fp8 x 128 | 17.2 | 6.5 | 16-byte loads and stores for bf16 rows (gain bf16 or f32): 112 -> 44 us a call, bit-identical (408/408 live) | +| gdn_conv_recurrent_update x 48 | 32.7 | ~13 | typed q/k/v and an f32 state moved 16 rows at a time through local memory: the 8-token pass 408 -> 101 us, the replay 222 -> 110 us; bit-identical (400/400 live) | +| m2xfp4 verify GEMMs | ~86 | ~75 | DPAS on registers (`dpas_f16`, SPV_INTEL_subgroup_matrix_multiply_accumulate): a lane decodes its column straight into B, no local memory; 15-20% a call | + +**End to end** (greedy, 512-token answers, drafter on): **30.4-30.9 tok/s** (was 14.0); prefill 124 +tok/s at 2584 tokens (unchanged). + +**Learned on the way.** +- libxe2's generic element accessors (`rad_load_f32` / `DT::ld`, a dtype switch an element) inside + a kernel's hot loop cost far more than their instruction count: the gdn register kernel ran 8x a + probe of the same loop until its accessors were typed. Kernels that stream with them are suspects. +- The m2 verify GEMM's weight stream is not the limit by layout: the lane-a-row 64-byte pattern + reads 89 MB of codes at 526 GB/s alone (a contiguous 1 KiB-a-sub-group layout: 281 GB/s, probe + `pat.cpp`); the kernel loses its time on the activation loads and the decode not overlapping it. + Tried and slower: two column tiles a lane (463 -> 639 us), the step's activation loads batched + ahead (-> 586 us), longer per-lane runs (KS 8/16), more K splits, a software-pipelined line load. +- VTune's GPU analyses do not run here (it does not recognise the host CPU); the per-kernel split + above came from temporary waits around each sub-kernel. + ## Next steps +1. The verify round, ~137 ms now against vLLM's ~68: the m2xfp4 verify GEMMs (~75 ms, ~2.5x their + bandwidth floor), givens_dense_quant at M = 8 (~19 ms), the DeltaNet conv (~70 us x 48) and its + norm kernel, embed_lookup over the x1 link (4 ms: the table is host-pinned), attention. +2. Prefill (124 tok/s): the chunk scan (4.6 s of 1792 tokens; its probe runs 3x faster than the + engine's kernel), the prefill GEMM (~30% of the DPAS peak), kkt. + +## Next steps (Milestone era) + 1. ~~Milestone B, part 2: `minicpm5-2b-fp8.rad`~~ **Dropped by the user (2026-10-23): "instead of the fp8 use the one you are already using so the bf16".** Milestone B's MiniCPM5 half is the bf16 container with its DSpark drafter, done above. diff --git a/libxe2/xe2_givens.cpp b/libxe2/xe2_givens.cpp index 8376a788..2e241f20 100644 --- a/libxe2/xe2_givens.cpp +++ b/libxe2/xe2_givens.cpp @@ -14,6 +14,7 @@ #include "xe2_common.h" #include "xe2_ops.h" +#include #include namespace xe2 { @@ -104,6 +105,79 @@ int givens_dense_quant(const RadArgs* a, RadStream st) { }); }); } + if (tdt == RAD_F16 && rad_ptr_aligned(T->data, 16) && rows <= 16 && !exact_only() && + !std::getenv("XE2_GIVENS_PAIR")) { + /* Decode and the verify (rows <= 16): a (part, group)'s rotation as one small GEMM on + * register DPAS (dpas_f16), y[r][j] = sum_i T[j][i] fp16(x[r][i] / D[i]) -- the prefill + * form's arithmetic (activation rounded once to fp16, f32 sums), held to the same + * tolerance and the KL bound. A work-group a (part, group): the rows' inputs in local + * memory as A columns, sub-group s the outputs 16 s .. 16 s + 15, a lane's B column its + * output's row of T (32 contiguous bytes a K16 step), so T is read once for all rows; then + * libref's quantiser a (row, part, group). The float-pair form (XE2_GIVENS_PAIR=1) walked + * the rows in turn on 80 work-groups at n = 5120. */ + const int mt = rows <= 8 ? 1 : 2; + const int64_t mp = mt * 8; + return submit([&] { + q->submit([&](sycl::handler& h) { + sycl::local_accessor at(sycl::range<1>((size_t)(kG * 16)), h); + sycl::local_accessor red(sycl::range<1>((size_t)(8 * 16)), h); + h.parallel_for(sycl::nd_range<1>{(size_t)(P * ngrp) * kG, kG}, + [=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] { + const int64_t gid = (int64_t)it.get_group(0); + const int64_t gi = gid % ngrp, p = gid / ngrp; + const int t = (int)it.get_local_id(0); + const sycl::sub_group sg = it.get_sub_group(); + const int sgi = (int)sg.get_group_linear_id(), lane = (int)sg.get_local_linear_id(); + const int64_t c = gi * kG + t; + const float dsc = rad_load_f32(db, ddt, p * n + c); + for (int r = 0; r < mp; ++r) { /* at[i][r]: lane k's A column is 16 bytes */ + const float v = r < rows ? rad_load_f32(xb, xdt, r * xrs + c * xcs) / dsc : 0.0f; + at[t * mp + r] = sycl::bit_cast((sycl::half)v); + } + sycl::group_barrier(it.get_group()); + const int j = sgi * 16 + lane; + const uint16_t* trow = (const uint16_t*)tb + ((p * ngrp + gi) * kG + j) * kG; + xe2_float8 acc[2] = { xe2_float8(0.0f), xe2_float8(0.0f) }; + for (int k0 = 0; k0 < kG; k0 += 16) { + const sycl::vec b0 = *(const sycl::vec*)(trow + k0); + const sycl::vec b1 = *(const sycl::vec*)(trow + k0 + 8); + xe2_int8 b; + for (int u = 0; u < 4; ++u) { b[u] = b0[u]; b[u + 4] = b1[u]; } + for (int i = 0; i < mt; ++i) { + const sycl::vec av = *(const sycl::vec*)&at[(k0 + lane) * mp + i * 8]; + xe2_short8 a; + for (int m = 0; m < 8; ++m) a[m] = (short)av[m]; + acc[i] = dpas_f16(a, b, acc[i]); + } + } + /* each row's amax over the group's 128 outputs: the sub-groups' maxima in + * local memory, read by all */ + for (int i = 0; i < mt; ++i) { + for (int m = 0; m < 8; ++m) { + const float am = sycl::reduce_over_group(sg, sycl::fabs(acc[i][m]), sycl::maximum()); + if (lane == 0) red[sgi * 16 + i * 8 + m] = am; + } + } + sycl::group_barrier(it.get_group()); + for (int i = 0; i < mt; ++i) + for (int m = 0; m < 8; ++m) { + const int64_t r = i * 8 + m; + if (r >= rows) break; + float amax = 0.0f; + for (int u = 0; u < 8; ++u) amax = sycl::fmax(amax, red[u * 16 + i * 8 + m]); + const float scl = amax > 0.0f ? amax * (1.0f / qmax) : 1.0f; + const float inv = 1.0f / scl; + float v = acc[i][m] * inv; + if (v > qmax) v = qmax; + if (v < -qmax) v = -qmax; + if (i8) v = sycl::rint(v); + rad_store_f32(qb, qdt, r * qrs + (p * n + gi * kG + j) * qcs, v); + if (t == 0) rad_store_f32(sb, sdt, r * srs + (p * ngrp + gi) * scs, scl); + } + }); + }); + }); + } if (tdt == RAD_F16 && rad_ptr_aligned(T->data, 16)) { /* The fast form. A work-group a (part, group) and up to kRows rows; sub-group s takes the * outputs j = 16 s .. 16 s + 15, and for each its lanes read row j of T in one coalesced