# Intel GPU (SYCL / Level Zero) backend: progress log Task brief: `radiance-sycl.md` (repo root, not committed). Porting analysis: `docs/SYCL_PORTING.md` (Phase 1, not written yet). This file is the resume point: a fresh session should be able to continue from it alone. ## Status | phase | state | |---|---| | 0 environment check | done | | 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 | not started | | 5 broaden and finish | not started | ## Open blockers / questions for the user 1. ~~**No `.rad` container for any milestone model is in `/mnt/model-library`.**~~ Resolved for bf16 (2026-10-23): `StillDeadcode/minicpm5-2b-bf16/minicpm5-2b-bf16.rad` (5,501,632,512 bytes) appeared; copied to `/models/minicpm5-2b-bf16/` and verified with `cmp`. **Still missing: `minicpm5-2b-fp8.rad`** (Milestone B). Original note: `StillDeadcode/minicpm5-2b-bf16/` holds only `README.md` and `minicpm5-2b-bf16-dspark.recipe`; there is no `minicpm5-2b-bf16.rad`, no `minicpm5-2b-fp8.rad`, and no raw `openbmb/MiniCPM5-2B` / `MiniCPM5-2B-DSpark` checkpoint to convert from. A `find -iname '*.rad'` over the library and `/models` returns nothing. Milestones A and B cannot be run until the user provides the containers (or the checkpoints plus permission to run `rad-convert`). Per the brief, nothing is downloaded or converted without asking. 2. **Bring-up without a real model.** The test suite writes synthetic llama checkpoints and converts them to `.rad` itself (`tests/tiny_model.h`, `tests/engine_e2e_test.cpp`; `RAD_E2E_KEEP=1` keeps them): bf16, block-fp8 trunk, fp8 / int8 heads, int4, MXFP4, all on the `llama_dense_fp8` graph MiniCPM5 uses. Those are test fixtures, not library models, and are what the Intel backend is brought up and compared against the host backend on until the real containers exist. Optionally, `HuggingFaceTB/SmolLM2-135M` (real bf16 llama weights, head_dim 64, tied embeddings) could be converted as a real-weights check; that needs the user's OK, since it is a conversion. 3. ~~**No ROCm on this machine**~~ Resolved: `sudo` needs a password, so the HIP compile check runs in docker (see "HIP compile check"); it passes. ## Phase 0 results (2026-10-23) ### Toolchain and device - Compiler: `Intel(R) oneAPI DPC++/C++ Compiler 2026.2.0 (2026.2.0.20261001)`, at `/opt/intel/oneapi` (not on PATH by default: `. /opt/intel/oneapi/setvars.sh`). - `sycl-ls`: `[level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero V2, Intel(R) Arc(TM) Pro B65 Graphics 20.2.0 [1.17.39395+16]` (also an OpenCL GPU entry for the same card, NEO 26.31.39395.16, and the OpenCL CPU device). - `clinfo -l`: Intel OpenCL (EPYC 7282 CPU), Intel OpenCL Graphics (Arc Pro B65). - `lspci -k`: `01:00.0 Intel Corporation Battlemage G31`, kernel driver `xe`. Linux 7.0.0-38-generic. - User is in `render` and `video`; `/dev/dri/renderD128` is `root:render 0660`. - Host: AMD EPYC 7282, 8 visible cores, 30 GiB RAM (a VM; the bochs VGA is the emulated console). ### Device limits (`scripts/sycl/devprobe.cpp`) | query | value | |---|---| | architecture | `intel_gpu_bmg_g31` (alias `intel_gpu_20_2_0`); AOT target `-device bmg-g31` | | compute units | 160 (20 Xe cores x 8 vector engines) | | max work-group size | 1024 | | sub-group sizes | 16, 32 | | local memory (SLM) per work-group | 131072 B (128 KiB) | | global memory | 34242297856 B (31.89 GiB) | | max single allocation | 32530182144 B (30.30 GiB) | | L2 (global_mem_cache_size) | 18 MiB | | max clock | 2400 MHz | | fp16 / fp64 / atomic64 | yes / yes / yes | | USM device / host / shared / system | yes / yes / yes / yes | | `ext_intel_matrix` aspect | yes | ### XMX (joint_matrix and ESIMD DPAS) `matrix_combinations` reports, for sub-group 16: A/B in {u8,s8} -> s32 at M<=8 N16 K32; fp16 and bf16 -> fp32 or 16-bit at M<=8 N16 K16, plus the larger fixed shapes M16N16K16, M1/M32 x N64 x K16/K32; tf32 -> fp32 at M<=8 N16 K8. No FP8 combination is listed (the query enum has no fp8 member). Executed on the device, each checked exactly against a host loop: | op | result | |---|---| | joint_matrix bf16 x bf16 -> f32, M8 N16 K16 | exact | | joint_matrix fp16 x fp16 -> f32, M8 N16 K16 | exact | | joint_matrix s8 x s8 -> s32, M8 N16 K32 | exact | | ESIMD `xmx::dpas` bf16 -> f32, M8 N16 K16 (control) | exact | | ESIMD `xmx::dpas` s8 -> s32, M8 N16 K32 (control) | exact | | ESIMD `xmx::dpas` **hf8 (E4M3)** -> f32, M8 N16 K32 | **wrong** (values ~1e15..1e24 and inf; expected 31.75) | | ESIMD `xmx::dpas` **bf8 (E5M2)** -> f32, M8 N16 K32 | **wrong** | The ESIMD headers declare `hf8`/`bf8`/`e2m1` DPAS argument types, and IGC compiles them for `bmg-g31` (AOT and JIT) without a diagnostic, but the results are garbage while the bf16 and s8 controls through the identical harness and VNNI packing are exact. **Conclusion: FP8 is not a native XMX input on this Battlemage part** (the brief's belief holds). The 8-bit float DPAS precisions are for a later generation; the compiler does not reject them for BMG. Consequence for the design: fp8 (E4M3) weights are widened in-register before DPAS. E4M3 -> bf16 is exact for every finite E4M3 value (3 mantissa bits fit in bf16's 7; max 448 and the smallest subnormal 2^-9 are inside bf16's range), and it keeps the activations bf16, so **bf16 XMX is the default path for fp8 weights**. (E4M3 -> fp16 is also exact, but the bf16 activations would then have to be narrowed to fp16, which can overflow.) MXFP4 (e2m1) is the same: widen to bf16 in-register. int8 (w4a8, int8 trunks) has native s8 DPAS. Reproduce: `scripts/sycl/probe.sh` (prints both tables' raw output). ### Host baseline (tree at `9eaf10d`, before any change) `./build.sh --no-hip` builds cleanly (625 targets, GCC, Ninja). Then: - `ctest -L '^fast$' -j8`: 75/80 pass. - `ctest --test-dir build -LE 'gpu|oot' -j8`: **82/88 pass, 540 s**. `engine_e2e_test` (33 s) and `convert_test` pass. The six failures are pre-existing and environmental; none touches code this task changes. **This set is the baseline that "passes exactly as before" is measured against:** | test | cause | evidence | |---|---|---| | `images_test` | no FFmpeg dev libraries, so `RAD_WITH_FFMPEG` resolves off and pictures cannot be encoded | `500 ... this build has no media decoder: it was configured without libavformat / libavcodec / libswscale`; `pkg-config libavcodec` fails | | `videos_test` | same | `400 ... input_reference: the picture could not be read: this build has no media decoder` | | `glm5next_test` | over its CPU-time budget on this slow VM host | `the binary spent 11.17 s of CPU, over its budget of 10 s (RAD_TEST_CPU_BUDGET)` | | `gbnf_test_shard2` | same | `10.52 s of CPU, over its budget of 10 s` | | `quant_ggml_test` | same | `25.38 s of CPU, over its budget of 25 s` | | `trigger_test` | timing ratio under `-j8` load; passes 3/3 run alone | `trigger_test.cpp:429: CHECK((double)last < (double)first * 1.25)` in `lazy_grammar_waiting_work_does_not_grow_with_the_reply` | Installing `libavformat-dev libavcodec-dev libswscale-dev` would clear the first two (the user's call; not needed for this task). After each phase, the same command must show these six and no others; the CPU-budget and timing tests are compared by cause (re-run alone if they flip). ## Benchmarks Tool: BetterBench 0.6.1 (`GGZ14/BetterBench` at `f72bb90`), cloned to `~/tools/BetterBench` and installed editable into its own venv `~/tools/betterbench-venv` (Python 3.14.4). Every flag of the brief's command (`--quick --decode --prefill --no-update-check --name --out --note --api-key`) is present in `betterbench run --help`. ```sh ~/tools/betterbench-venv/bin/betterbench run --endpoint http://127.0.0.1:8000/v1 --model \ --quick --decode --prefill --no-update-check \ --name sycl-- --out /results.json \ --note backend=sycl --note gpu=arc-pro-b65 --note commit= ``` Discord posting: the user added `~/.config/radiance-bench.env` (mode 0600) on 2026-10-23; `DISCORD_WEBHOOK_URL` loads from it (never printed or logged). The user also asked for **screenshots of BetterBench's HTML report** to be sent to the webhook with each result. No headless browser is installed (no chromium/firefox/wkhtmltoimage, no playwright); at the first benchmark, install one outside the repo (e.g. playwright + chromium in `~/tools/betterbench-venv`) and have `scripts/bench_report.sh` render the report to PNG and post it as a multipart attachment beside the summary. `scripts/bench_report.sh` (quick run, parse `results.json` with `jq`, post, check the HTTP status) is to be written at the first benchmarkable milestone, against a real `results.json`. All runs are `--quick` (1 warmup, 5 passes): progress tracking, not publishable numbers. `scripts/sycl/bench_report.sh TAG` runs the brief's command against a live server, summarises with BetterBench's own report functions, screenshots the HTML report (JPEG, at the user's request) and posts both to the webhook; `--report RUN_DIR TAG` reports an existing run. The screenshot needs headless Chromium (Playwright in the BetterBench venv), nine system libraries it lacks here and fonts (this host has none; the first post had no text) -- all unpacked without root under `~/tools/chromium-libs` (`apt-get download` + `dpkg -x`, a private `fonts.conf`). | date | commit | model | backend | flags | prefill tok/s (median / 1% low) | decode tok/s (median / 1% low) | vs previous | report | |---|---|---|---|---|---|---|---|---| | 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` | ## Models Library (`/mnt/model-library`, read-only), as of 2026-10-23: | path | what | useful for | |---|---|---| | `StillDeadcode/minicpm5-2b-bf16/` | README + recipe only, **no weights** | nothing until the `.rad` is supplied | | `HuggingFaceTB/SmolLM2-135M/` | bf16 safetensors, llama | possible bring-up stand-in (blocker 2) | | `Launch80/Swift-1.5-Qwen3.8-27B-Uncensored-Int4-baked/` | 16 GiB int4 safetensors (qwen35, "baked") | possibly a 19-22 GiB-class Milestone B model, if `rad-convert` reads it; unverified | | `Wrapzii/Swift-1.5-Qwen3.8-27b-GPTQ-Int4-baked-v1-embed-int8/` | 17 GiB GPTQ int4 + int8 embed | same | | `unsloth/Qwen3.8-27B-GGUF`, other `*-GGUF` dirs | GGUF quantisations | the engine converts some GGUF (`libquant/lq_ggml.cpp`); unverified for these | | `Qwen/Qwen3-0.6B-GGUF`, `unsloth/Qwen3-8B-GGUF`, `SmolLM3-3B-GGUF`, ... | GGUF | not on the README's model table | `/models` (196 GiB, 137 GiB free) already holds copies made before this task: `Qwen3.8-27B-Q4_0.gguf`, `mtp-Qwen3.8-27B-Q4_0.gguf`, and the two Swift 27B directories. They are left as found. Planned use: Milestone A = `minicpm5-2b-bf16.rad` (blocked, item 1); Milestone B = `minicpm5-2b-fp8.rad` (blocked) and one of the 27B int4 / MXFP4 containers (to be decided once Phase 1 shows what `rad-convert` accepts, and with the user's OK for any conversion). ## Decisions - D1 (Phase 0): FP8 and FP4 weights are widened to bf16 in-register for XMX; int8 uses native s8 DPAS. Evidence above. - D2 (Phase 1): no new device-runtime abstraction. `DeviceBackend` (`core/device/device.h:178`) already is one and HIP/AQL sit behind it; the Intel backend is a fourth vtable, `core/device/sycl.cpp`. The HIP path is not touched. (`SYCL_PORTING.md` §4.1) - D3: plugins get the queue through `abi/rad_sycl.h`'s `RadSyclStream` (magic + own version + `sycl::queue*`), not a `RAD_ABI_VERSION` bump: no existing shape changes. (§4.2) - D4: kernel library `libxe2/`, AOT for `intel_gpu_bmg_g31`; `code_runs` under SYCL compares a plugin's `build_target` with the device arch so libr4d rows are never selected on the B65. (§4.3) - D5: on the SYCL backend the "host-only ops ... Not a hole" placement is fatal unless `--debug-accept-host-ops`. (§4.4) - D6 (revised 2026-10-23): ~~`RAD_SYCL=ON` builds everything with `icpx`~~. Tried: `cmake -B build-icpx -DCMAKE_CXX_COMPILER=icpx -DCMAKE_CXX_FLAGS=-ffp-model=precise -DRAD_WITH_HIP=OFF` fails in libavx: `avx_gemm_tile.cpp:289: always_inline function '_pdep_u64' requires target feature 'bmi2', but would be inlined into function 'qb_codes_zp' that is compiled without support` (GCC accepts it, clang does not), and fixing that means changing libavx. So the **main build stays GCC in every configuration** and only the SYCL code is built and linked by `icpx`, as shared libraries in a sub-build (`librad_sycl.so`: the device backend and the core's SYCL kernels, a C entry point and a callback table for logging and errors; `libxe2.so`: the kernel plugin). Host code in a SYCL build is then the default build's, byte for byte. HIP + SYCL refused together at configure until a ROCm machine can test it. (§4.5) - D7: `advance` and `wtab` get SYCL launchers; `xprefetch` stays off. (§4.6) - D8: `--tp > 1` refused at startup on the SYCL backend, before the device-count check. (§4.7) - D9 (2026-10-23): queues are made **without** `enable_profiling` unless `RADIANCE_SYCL_TIMING=1`. Measured on the idle B65 (`scratchpad` probe `subcost.cpp`, 4000 trivial kernels): in-order + profiling 24.4 us host time per `single_task`, 22.8 us per `parallel_for`; in-order without profiling 4.5 / 4.4 us; `ext::oneapi::experimental::nd_launch` 4.0 us either way. At ~550 launches per MiniCPM5 decode step that is 13 ms vs 2.5 ms. Without timing, `rad_event_elapsed_ms` refuses and names the variable (`--profile-ops` and `rad-kbench` need it set). libxe2 launches with `nd_launch`. (An earlier 50 us figure was measured while a -j8 build loaded the host.) - D10 (2026-10-23): `RAD_MEM_HOST_PINNED` / `_MAPPED` are `posix_memalign` + `prepare_for_device_copy`, not SYCL `malloc_host`: O_DIRECT into `malloc_host` fails with EFAULT (driver-mapped pages), and the mover reads the file tier straight into pinned buffers. Measured, 256 MiB: `malloc_host` 28.4 / 28.5 GB/s H2D / D2H, O_DIRECT fails; registered `posix_memalign` 28.4 / 28.4 GB/s, O_DIRECT ok, kernel read/write ok (system USM); unregistered 21.0 / 18.2 GB/s. The backend keeps a registry of those ranges, since the runtime does not know them. - D13 (2026-10-23): fast kernels may change libref's reduction order. They are held to rad-kbench's per-op tolerances (libr4d's standard) and, end to end, to the KL bound measured above against the libref host build -- no worse than libavx's distance from libref. Every fast row keeps its exact twin, selectable with `XE2_EXACT=1`. - D12 (2026-10-23): every libxe2 op is checked twice: rad-kbench (dense operands, fixture and the real container) and the engine's op oracle on the operands the engine hands it (`RADIANCE_OP_ORACLE`), at tolerance ~0 where the kernel reproduces libref's order. Transcendentals are libref's: double `exp`/`log`/`cos`/`sin` on the device, rounded once to f32 (verified bit-identical to glibc over MiniCPM5's rope angles and exp's [-104, -20] range). - D11: the SYCL engine needs the oneAPI environment at run time: the runtime `dlopen`s its Level Zero adapter, which needs `libumf.so.1` from oneAPI's `umf/` tree (no RUNPATH can reach it). A SYCL build that sees no GPU now warns (not Info) that it is running on the CPU and names the fix. ## Done in Phase 2 (2026-10-23) - `abi/rad_sycl.h` (commit `f00e9b7`). The `__host__ __device__` macros needed no SYCL case: their `#else` (empty) is what SYCL device code wants. - Build: `RAD_SYCL=OFF|ON|AUTO` (default OFF), `RAD_SYCL_TARGETS` (default `intel_gpu_bmg_g31`), `build.sh --sycl` (in `build-sycl/`), presets `sycl` (configure, build, test). The icpx sub-build is `sycl/CMakeLists.txt`, run through ExternalProject; `rad_core` links `librad_sycl.so` with `RAD_HAVE_SYCL=1`. HIP + SYCL refused at configure. The default build's generated test definitions are byte-identical apart from CMake's backtrace line numbers. - `core/device/sycl.cpp` (+ `sycl_host.h/.cpp`: the logger/error-slot callback table), selection in `dispatch.cpp` ahead of the host fallback; `core/sched/advance_sycl.cpp`, `core/runtime/wtab_sycl.cpp`; startup refusals for `--tp > 1` and host-only ops on SYCL. - Tests: host-tier tests hide Level Zero GPUs with `ONEAPI_DEVICE_SELECTOR=!level_zero:*` (`RAD_TEST_HIDE_ENV`). `device_test_sycl` (label `sycl`, `RAD_TEST_BACKEND=sycl` so a fallback to the host backend fails, `RADIANCE_SYCL_TIMING=1`): **36 cases pass on the B65, 16579 checks**, 12 skipped (8 elastic memory, not provided; 4 host-backend-only, skipped on AMD cards too). It runs the SYCL `advance` kernel (`an_advance_reads_the_token_a_copy_issued_before_it_delivers`). Fixed on the way: memset of pageable memory returns `RAD_E_UNSUPPORTED`; ranged copies refuse what the other backends refuse; a room check refuses an allocation past the driver's free count; gates (a spin kernel on a pinned flag). - SYCL build, `ctest -LE 'gpu|oot'` with the oneAPI environment loaded (card present, hidden): 83/88, the baseline's failures (FFmpeg, CPU budgets); `trigger_test`'s load flake did not occur. ## libxe2 (started 2026-10-23) `libxe2/` is built by the sycl sub-build with `rad_add_plugin` into `radiance_home/kernels` (`xe2_common.h`: queue, row views, refusals; `xe2_rows.cpp`: rows with designated initialisers). Ops so far: `add`. **The correctness check for every op is `rad-kbench`**: it replays each kernel against libref's recorded answers on seeded inputs inside guarded allocations (`data/kernels.rkb`, recorded from qwen3.8-27b; `kernels_moe.rkb`), at the project's per-op tolerances, and with `-m` against a real container at its geometry. In a SYCL build the `kbench` and `kbench_moe` tests are labelled `kbench;sycl` (card tier), as they are `kbench;gpu` in a HIP build. Per op: ```sh . /opt/intel/oneapi/setvars.sh RADIANCE_SYCL_TIMING=1 RADIANCE_HOME=$PWD/build-sycl/radiance_home build-sycl/bin/rad-kbench --op RADIANCE_SYCL_TIMING=1 RADIANCE_HOME=$PWD/build-sycl/radiance_home build-sycl/bin/rad-kbench \ -m /models/minicpm5-2b-bf16/minicpm5-2b-bf16.rad --num-speculative-tokens 0 --op ``` `add`: fixture 30/30 and MiniCPM5 20/20, worst rel_l2 0, no writes outside guarded allocations. `ctest -L '^sycl$'` (device_test_sycl, kbench, kbench_moe): 3/3 on the B65. In a SYCL build the host tier is `ctest -LE 'gpu|oot|sycl'` (kbench moved to the card tier). ### MiniCPM5-2B bf16, the real container (`--debug-graph`, host backend) 42 layers, n_embd 2048, 16 q / 2 kv heads, head_dim 128 (gqa 8), ffn 6144, vocab 130560, rope theta 5e6 neox, eps 1e-6. With `--num-speculative-tokens 0`: 523 ops, exactly the 13 + 13 of `SYCL_PORTING.md` §3.1 (gemm_nt at N,K = 2560x2048 qkv, 2048x2048 o, 12288x2048 gate_up, 2048x6144 down; logits 130560x2048). With its DSpark drafter (default, depth 7): 619 ops, adding `gemm_nt_q` fp8a8 (128x128 blocks) and `w2a8` (the 2-bit head), `gemm_nt_q_gated`, `silu_mul`, `quant_act_i8`, `row_topk` (N 130560, R 16), `dflash_select`, a non-causal `attn_paged`, and `rmsnorm` n=128. Milestone A runs with speculation off first; the drafter's ops are Milestone B. ## Milestone A (2026-10-23, commit `874f8d2`) `minicpm5-2b-bf16.rad` with `--num-speculative-tokens 0` serves on the Arc Pro B65: 26 libxe2 ops (13 model, 13 sampler), every one resolved to a device row, none placed on the host. - **Greedy, token for token, against the host backend restricted to libref** (`--kernels libref --debug-accept-reference-kernels`): `scripts/sycl/greedy_compare.py`, 8 prompts x 64 tokens, **8/8 identical**; top-5 logprobs over 96 decode steps differ by **exactly 0**. - Against the default host backend (libavx): 5/8 identical; the three others diverge late (tokens 27, 55, 61) at near-ties (top-2 gaps 0.01-0.07 nats). libavx's reductions are not libref's, and libxe2 reproduces libref, so this is libavx vs libref, not the card. Measured, not bounded further. - `/v1/chat/completions` answers coherently, the reasoning split out ("In one sentence, why is the sky blue?" -> "The sky appears blue because shorter blue wavelengths of sunlight are scattered more by the atmosphere's molecules than longer red wavelengths."). - Reproduce: ```sh . /opt/intel/oneapi/setvars.sh RADIANCE_HOME=$PWD/build-sycl/radiance_home build-sycl/bin/radiance \ --model /models/minicpm5-2b-bf16/minicpm5-2b-bf16.rad --num-speculative-tokens 0 \ --max-model-len 8192 --max-num-seqs 4 --port 8100 & RADIANCE_HOME=$PWD/build/radiance_home ROCR_VISIBLE_DEVICES=99 build/bin/radiance \ --model /models/minicpm5-2b-bf16/minicpm5-2b-bf16.rad --kernels libref \ --debug-accept-reference-kernels --num-speculative-tokens 0 --max-model-len 8192 --port 8102 & python3 -I scripts/sycl/greedy_compare.py http://127.0.0.1:8100 http://127.0.0.1:8102 ``` **Two checks, not one.** rad-kbench passed every op, and the engine still found two bugs, because its operands are not kbench's: `cast` was handed a strided slice of the fused qkv row (refused, loudly), and `gated_quant_fp8`'s f32 `exp` was inside kbench's tolerance but not libref's double `exp`, which moved one E4M3 code in some layers and flipped a greedy near-tie later. The engine's op oracle finds the second kind: it runs libref on the very operands each device kernel was handed. **Every new op gets both checks** (D12): ```sh RADIANCE_OP_ORACLE='*' RADIANCE_OP_ORACLE_MAX=600 RADIANCE_OP_ORACLE_TOL=1e-9 \ RADIANCE_HOME=$PWD/build-sycl/radiance_home build-sycl/bin/radiance --model ... --port 8120 # one short request, then: grep -c 'oracle #.* agrees' / grep 'MISMATCH' in the log ``` After the fix: 600/600 issues of a 26-token prefill bit-identical. Speed (correctness-first kernels: serial-dot GEMM, one work-group a (row, head) attention): 24 tokens in 5.6 s including prefill; BetterBench quick numbers in "Benchmarks". ## Milestone B, part 1: the DSpark drafter (2026-10-23) libxe2 now serves every op of `minicpm5-2b-bf16.rad` with its drafter: `gemm_nt_q` over fp8a8 (128x128 blocks; libref's `quant_dot` per output), `gemm_nt_q_gated` (fp8a8, gated epilogue; n <= 28672 in local memory, declared as N <= 57344), the `w2a8` vocabulary head (libref's `gemm_zp`; `b_scale` in libref's joined planes form through the same layout hook, the planes found on the device), `quant_act_i8`, `silu_mul`, `row_topk`, `dflash_select`. Non-causal attention and head-only rope were already served. - rad-kbench: MiniCPM5-2B 191/191 at rel_l2 0 (the head's row is not reached by kbench's cases); fixture: the gated GEMM at a 27B geometry (N 34816) was refused at first -- its first version held the whole N-wide row in local memory -- and passes since. - Engine oracle with speculation on: **1500/1500 issues bit-identical**, the w2a8 head included. - Greedy, speculation on (DSpark, depth 7) against libref's greedy with it off: **8/8 prompts identical** (`greedy_compare.py`, 64 tokens each). - Speed: 2.5-5.4 tok/s with speculation against 4.2 without: verifying 7 drafts costs about as much as 7 tokens in a serial-dot GEMM. Speculation pays once the GEMMs are bandwidth-bound (Phase 4). ## Install and the out-of-tree rebuild (2026-10-23) A SYCL build installs `librad_sycl.so` to `lib/` and `libxe2.so` to `share/radiance/kernels`, and its executables carry `INSTALL_RPATH $ORIGIN/../lib` (checked: an installed `radiance` resolves the backend from the prefix with no environment). `tests/oot_plugins.sh` rebuilds libxe2 out of tree with icpx when `RAD_OOT_ICPX` is set (the SYCL build's registration sets it) and hides Level Zero GPUs from its listing and replay. `ctest -R oot_plugins` in build-sycl: **passed** (370 s). ## Phase 4, step 1 (2026-10-23) Profile (`RADIANCE_SYCL_TIMING=1 --profile-ops`, MiniCPM5 bf16 decode, correctness-first kernels): 232.8 ms/step; `gemm_nt` 79.2% (gate_up, 50 MB of bf16, 810 us a call = 62 GB/s on a ~600 GB/s card), `rmsnorm_quant_fp8` 13.0% (the serial sum of squares, 360 us a call), `logits_gemm` 3.4%, the rest under 1.5% each. - `rmsnorm*`: the squares are formed in parallel into local memory, work-item 0 adds them in index order -- the same additions, still bit-identical to libref (kbench rel_l2 0). - `xe2_gemm_nt_gemv`, `xe2_logits_gemm_gemv` (priority 10, `M <= 16`, bf16): a sub-group an output column, 16-byte coalesced weight loads, a tree reduction. Not libref's order. kbench: fixture 361/361, MiniCPM5 180/180 (worst rel_l2 1.6e-4, tol 8e-3). `XE2_EXACT=1` sends them to the exact kernels. - **Decode: 4.2 -> 35.5 tok/s** (128-token greedy completions, speculation off). - **KL bound (D13)**, `--kld-record` with the libref host build over 12 passages of the repo's docs (1914 positions), scored with `--max-num-batched-tokens 16` so the GEMV computes every position: | path | KL mean | median | p99 | p99.9 | max | top-1 | PPL ratio | |---|---|---|---|---|---|---|---| | B65, `XE2_EXACT=1` | 0 | 0 | 0 | 0 | 0 | 100% | 1.0000 | | B65, fast GEMV | 5.9e-4 | 4.1e-4 | 3.5e-3 | 9.4e-3 | 0.045 | 98.54% | 0.9989 | | host, libavx (reference point) | 5.7e-4 | 4.2e-4 | 3.0e-3 | 6.4e-3 | 0.016 | 98.59% | 1.0004 | The B65's fast path is as far from libref as the production CPU library is. Greedy against libref: 7/8 prompts identical, the eighth diverging at token 18 on a 0.008-nat near-tie. ## Phase 4, step 2 (2026-10-23): XMX GEMM and one-pass attention - `xe2_gemm_nt_xmx` / `xe2_logits_gemm_xmx` (priority 5, `M >= 17`, bf16): joint_matrix M8 N16 K16, use::b loaded column-major straight from the [N, K] weight (probed exact on the card), eight sub-groups a work-group sharing one 64-column slice; tail rows by the GEMV, odd shapes to the exact kernel. - `xe2_attn_paged` (priority 10): one pass, online softmax, keys over eight sub-groups, head_dim over lanes; the exact kernel underneath. - rad-kbench: fixture 499/499, MiniCPM5 482/482 (worst rel_l2 1.7e-4); every new row reached. - KL against the libref reference (same corpus as D13): normal batching (XMX + fast attention) mean 5.8e-4, p99 3.2e-3, top-1 98.69%, PPL x1.0001; 16-token chunks (GEMV + fast attention) 5.8e-4 / 2.9e-3 / 98.59%. Inside the bound. - **Prefill 1795 tokens: TTFT 4.57 s = 393 tok/s (was ~17).** Decode 33.2 tok/s over 512 tokens, but 16.2 tok/s right after a 1.8k-token prompt: single-row decode attention runs 16 work-groups (one a head) on a 160-engine card, and each kv head is read by 8 query heads. Next: split the keys across work-groups and share a kv head's reads across its query heads. ## Phase 4, step 3 (2026-10-23): split-KV attention Long-context decode profile (1.8k-token prompt, 64 steps): attn_paged 69.9%, gemm_nt 11.1%, rmsnorm_quant_fp8 9.3%, gated_quant_fp8 4.1%. `xe2_attn_paged` is now flash-decoding: a work-group a (row, kv head, key partition) whose sub-groups are the kv head's query heads (each key read once for all 8), partitions of 32+ keys merged from 64 MiB of scratch; P = 1 for prefill-sized row counts. A first try at 256-key partitions halved short-context decode (all keys in one partition, each sub-group walking every key for its head): 32 keys fixed it. - rad-kbench 138/138 and 132/132 (worst rel_l2 2.9e-4); KL mean 5.8e-4, p99 3.2e-3, top-1 98.5%. - **Decode after a 1797-token prompt: 16.2 -> 29.8 tok/s**; short-context decode 32.0 tok/s; 1797-token prefill 4.61 s. ## Phase 4, step 4 (2026-10-23): the norm and the quantisers, still exact `scripts/sycl/profile_decode.sh MODEL PROMPT [STEPS] [flags]` isolates decode: the same request at 1 and 1 + STEPS tokens in two profiled servers, the difference per op divided by STEPS. At a 1.8k-token context, before: 34.8 ms/step of device time -- gemm_nt 9.65, attn_paged 9.51, rmsnorm_quant_fp8 9.12 (108 us a call for one row), gated_quant_fp8 3.52 (84 us, one work-group a row and every value computed twice, a double exp each). - The ordered sum reads its squares eight at a time, adding them in the same order. - `quant_group` computes a group's values once into registers (up to 128 a group) and writes out_bf16 itself; `gated_quant_fp8` spreads a row's groups over ceil(groups/16) work-groups. - Still bit-identical: rad-kbench 208/208 and 206/206 at rel_l2 0. - After: **26.6 ms/step** -- gemm_nt 9.62, attn_paged 9.50, rmsnorm_quant_fp8 3.75, logits_gemm 1.02, gated_quant_fp8 0.87. ## Next steps 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. 2. A 19-22 GiB container: none is in the library as `.rad` (the two Swift-1.5 Qwen3.8-27B int4 checkpoints there are safetensors, not containers). Asking the user which to use / for a container. 3. Phase 4 can start now that Milestone A is correct: XMX GEMMs and a split-KV attention, each checked against the correctness-first kernels and libref with both checks (D12). ## Next steps (previous list, kept for reference) 1. Milestone B: `minicpm5-2b-fp8.rad` (**not in the library; asked**), the DSpark drafter's ops (fp8a8 GEMMs, `gemm_nt_q_gated`, `w2a8` head, `quant_act_i8`, `row_topk`, `dflash_select`, `silu_mul`, non-causal attention), then a 19-22 GiB container. The 27B models at correctness- first speed will be very slow (a serial-dot GEMM over 27B weights), so their end-to-end check may come after the first XMX GEMM (Phase 4 order adjusted only for the big model, not for correctness: the fast GEMM is checked against the slow one and libref first). 2. `code_runs` under SYCL from `build_target` (D4); install rules and the `oot` rebuild for `librad_sycl.so` and libxe2. ## Notifications `scripts/sycl/notify.sh "msg"` posts to the Discord webhook (user's request, 2026-10-23): used for blockers, questions and milestones. Tested: posted. ## HIP compile check 2026-10-23, commit `370a906` (the SYCL backend, every core-side change): built in docker, `rocm/dev-ubuntu-24.04:10.1.0-full` (HIP 7.16, AMD clang 24.0.0git, the Dockerfile's base with its stock compiler rather than the Dockerfile's patched LLVM), `cmake -DRAD_WITH_HIP=ON -DRAD_GPU_TARGETS=gfx1201`, g++-14: **785/785 targets, 0 errors**, libr4d included. Later commits add only libxe2 and sycl/, which a HIP build does not compile. Re-run after any core change: ```sh git worktree add --detach /tmp/hipsrc HEAD docker run --rm -v /tmp/hipsrc:/src:ro rocm/dev-ubuntu-24.04:10.1.0-full bash -c ' apt-get update -qq && apt-get install -y -qq --no-install-recommends cmake ninja-build pkg-config g++-14 gawk export CC=gcc-14 CXX=g++-14 ROCM_PATH=/opt/rocm HIP_PATH=/opt/rocm cmake -S /src -B /build -G Ninja -DRAD_WITH_HIP=ON -DRAD_GPU_TARGETS=gfx1201 && cmake --build /build -j6' git worktree remove --force /tmp/hipsrc ``` ## Reproduce the current state ```sh . /opt/intel/oneapi/setvars.sh ./build.sh --sycl # build-sycl/: configure, build, fast tests ctest --test-dir build-sycl -L '^sycl$' --output-on-failure # the card tests (B65) ctest --test-dir build-sycl -LE 'gpu|oot' -j8 # host tier in the SYCL build scripts/sycl/probe.sh # Phase 0 device tables scripts/sycl/op_inventory.sh # SYCL_PORTING.md Appendix A # the tiny llama containers and their graphs (Phase 1, SYCL_PORTING.md §3.1): mkdir -p "$T/tmp" && env RADIANCE_HOME=$PWD/build/radiance_home RAD_TEST_TMPDIR=$T/tmp \ ROCR_VISIBLE_DEVICES=99 RAD_E2E_KEEP=1 build/tests/engine_e2e_test -perf_ # -> $T/tmp/radiance_e2e.*/{llama,llama_int4}/ checkpoints and llama*.rad containers build/bin/rad-convert $D/llama -o $D/llama_bf16.rad # the bf16 analogue (no recipe) build/bin/radiance --model $D/llama_bf16.rad --debug-graph build/bin/radiance --model $D/llama.rad --kv-cache-dtype fp8 --debug-graph ./build.sh --no-hip # host backend + fast tests ctest --test-dir build -LE 'gpu|oot' # host baseline ```