device: the SYCL backend -- Intel GPUs through oneAPI over Level Zero

A fourth DeviceBackend, in librad_sycl.so: in-order sycl::queues on one context, events as
barriers, copies and fills on the queue, gates as a spin kernel on a pinned flag, and the core's
advance and weight-table kernels as SYCL twins of their .hip files. RadStreams are RadSyclStreams
(abi/rad_sycl.h). Pinned host memory is page-aligned memory registered for device copies, since
O_DIRECT cannot read into SYCL's malloc_host pages; event timing is opt-in (RADIANCE_SYCL_TIMING=1)
because profiling queues cost ~20 us of host time a submission.

The SYCL code is its own CMake project, sycl/, configured with icpx through ExternalProject, so the
engine and every host plugin stay on the main compiler: a SYCL build's host code is the default
build's. RAD_SYCL (default OFF), build.sh --sycl, the sycl presets; HIP and SYCL in one build are
refused at configure.

On the SYCL backend --tp > 1 and ops resolved only to host kernels stop the start, since the Intel
backend runs on one card and never puts an op on the CPU. A SYCL build that sees no GPU warns that
it runs on the CPU and names the missing oneAPI environment.

device_test runs on the Arc Pro B65 as device_test_sycl (label sycl): 36 cases pass, 12 skip
(elastic memory, not provided; host-backend-only cases). Host tests hide Level Zero GPUs with
ONEAPI_DEVICE_SELECTOR. The host tier is the baseline's in both the default and the SYCL build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-23 15:38:42 +02:00
1 parent 17524c95bd
commit 8addda231b
19 files changed
+1302 -39

No files matched your search

+57 -15
View File
@@ -10,7 +10,7 @@ from it alone.
|---|---|
| 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); implementation next |
| 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 |
@@ -136,10 +136,14 @@ present in `betterbench run --help`.
--note backend=sycl --note gpu=arc-pro-b65 --note commit=<short commit>
```
Discord posting: **`~/.config/radiance-bench.env` does not exist, so `DISCORD_WEBHOOK_URL` is unset**
(checked 2026-10-23). Runs are recorded here without posting until the user creates that file.
`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`.
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.
@@ -191,18 +195,53 @@ Planned use: Milestone A = `minicpm5-2b-bf16.rad` (blocked, item 1); Milestone B
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. (§4.7)
- 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 `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.
## Next steps (Phase 2 implementation, in commit order)
## Done in Phase 2 (2026-10-23)
1. CMake: `RAD_SYCL`, the `icpx` check, `-ffp-model=precise`, `build.sh --sycl`, preset, `sycl`
label. Verify: default GCC build unchanged; SYCL build's host tier matches the baseline.
2. `abi/rad_sycl.h`; `__host__ __device__` macros' SYCL case.
3. `core/device/sycl.cpp` backend + selection + `RADIANCE_DEVICE_BACKEND`; a `sycl`-labelled
device test (the contract tests of `tests/device_test.cpp` run against it).
4. `advance` / `wtab` SYCL launchers; `--tp` refusal; fatal host-only placement.
5. `libxe2/` skeleton with one op (`add`) and its libref-checked test; `oot` rebuild.
6. Phase 3: the 13 + 13 ops of `SYCL_PORTING.md` §3.1, each with a libref test, then the tiny
- `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.
## Next steps
1. `libxe2/` skeleton built by the icpx sub-build, installed under `radiance_home/kernels`, with one
op (`add`) and a libref-checked test on the card (`sycl` label); its `oot` rebuild.
2. `code_runs` under SYCL from `build_target` (D4), so a host-only build target never claims the card.
3. Phase 3: the 13 + 13 ops of `SYCL_PORTING.md` §3.1, each with a libref test, then the tiny
llama end to end against the host backend.
## HIP-side edits awaiting a ROCm compile check
@@ -213,6 +252,9 @@ None yet.
```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):