This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/docs/SYCL_PROGRESS.md
T
pascallinxweilerandClaude Opus 5.5 41a3c32a65 libxe2: the Intel kernel library's skeleton, and its first op, add
libxe2 is a kernel plugin like any other, built by rad_add_plugin from the icpx sub-build into the
build tree's $RADIANCE_HOME. It declares no schemas (every op it serves is libref's vocabulary), only
device rows, written with designated initialisers. xe2_common.h holds what every kernel needs: the
launch's queue (rad_sycl.h), row views over padded operands, refusals that name the geometry, and
libref's own dtype conversions so results round where the reference's do.

add passes rad-kbench against libref at tolerance zero, on the recorded fixture (30 cases) and on
MiniCPM5-2B's container (20 cases), inside guarded allocations. In a SYCL build the kbench replays
run libxe2 on the card, so they are labelled sycl there, as they are gpu in a HIP build.

scripts/sycl/notify.sh posts to the Discord webhook when the port needs the user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-23 15:55:39 +02:00

20 KiB

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 written (docs/SYCL_PORTING.md §4); device backend, build integration and core kernels done and passing device_test on the B65; libxe2 skeleton next
3 correctness-first kernels not started
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 (hipcc absent, no /opt/rocm), and sudo needs a password. The user authorized installing what is needed; the HIP compile check runs in docker instead (rocm/dev-ubuntu-24.04:10.1.0-full, the Dockerfile's base, stock clang; see "HIP compile check").

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.

~/tools/betterbench-venv/bin/betterbench run --endpoint http://127.0.0.1:8000/v1 --model <served name> \
    --quick --decode --prefill --no-update-check \
    --name sycl-<model>-<short commit> --out <run dir>/results.json \
    --note backend=sycl --note gpu=arc-pro-b65 --note commit=<short 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.

Runs: none yet. Nothing is benchmarked before Milestone A passes its correctness checks. All runs are --quick (1 warmup, 5 passes): progress tracking, not publishable numbers.

date commit model backend flags prefill tok/s (median / 1% low) decode tok/s (median / 1% low) vs previous report

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.
  • D11: the SYCL engine needs the oneAPI environment at run time: the runtime dlopens 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:

. /opt/intel/oneapi/setvars.sh
RADIANCE_SYCL_TIMING=1 RADIANCE_HOME=$PWD/build-sycl/radiance_home build-sycl/bin/rad-kbench --op <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 <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.

Next steps

  1. Phase 3, Milestone A's 13 + 13 ops in libxe2, each passing rad-kbench (fixture and MiniCPM5), correctness-first kernels. Order: elementwise/norm/rope/cast/embed/gather, sampler, gemm_nt and logits_gemm, kv_store and attn_paged.
  2. Then serve MiniCPM5 on the B65 with --num-speculative-tokens 0 and compare greedy output with the host backend.
  3. 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-side edits awaiting a ROCm compile check

None yet.

Reproduce the current state

. /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