Archived
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:
1 parent
17524c95bd
commit
8addda231b
19 files changed
+1302
-39
No files matched your search
+16
-14
@@ -194,16 +194,17 @@ implementations are already behind it. So no wrapper is introduced and the HIP p
|
||||
| vtable entry | SYCL / Level Zero |
|
||||
|---|---|
|
||||
| `count`, `set`, `props` | GPU devices of the Level Zero platform; `props.arch` from `ext::oneapi::experimental::info::device::architecture` (`"intel_gpu_bmg_g31"`); `n_cu` = `max_compute_units` (160), `warp_size` = 16 (the sub-group the kernels use), `lds_bytes` = `local_mem_size`, `vram_free` from `ext::intel::info::device::free_memory` |
|
||||
| `alloc` | `RAD_MEM_DEVICE` -> `malloc_device`; `HOST_PINNED` and `HOST_MAPPED` -> `malloc_host` (device-reachable, same address both sides, so `host_ptr`/`device_ptr` are identity); `HOST` -> plain `malloc` |
|
||||
| streams | one in-order `sycl::queue` per stream on one shared `sycl::context`; `high_priority` -> `ext::oneapi::property::queue::priority_high` |
|
||||
| events | `queue::ext_oneapi_submit_barrier()` returns the record; `event_wait` = `ext_oneapi_submit_barrier({e})` on the waiting queue (no host sync); `query` / `sync` on the event; `elapsed_ms` from profiling info (queues created with `enable_profiling`; its cost to be measured, and dropped if it shows) |
|
||||
| `alloc` | `RAD_MEM_DEVICE` -> `malloc_device` behind a room check; `HOST_PINNED` and `HOST_MAPPED` -> page-aligned memory registered with `prepare_for_device_copy` (not `malloc_host`, which O_DIRECT cannot target; D10), same address both sides; `HOST` -> plain `malloc` |
|
||||
| streams | one in-order `sycl::queue` per stream on one shared `sycl::context`; `high_priority` -> `ext::oneapi::property::queue::priority_high`; no `enable_profiling` unless `RADIANCE_SYCL_TIMING=1` (it costs ~20 us of host time a submission, D9) |
|
||||
| events | `queue::ext_oneapi_submit_barrier()` returns the record; `event_wait` = `ext_oneapi_submit_barrier({e})` on the waiting queue (no host sync); `query` / `sync` on the event; `elapsed_ms` from profiling info, under `RADIANCE_SYCL_TIMING=1` only |
|
||||
| copies, fills | `queue::memcpy`, `memset`; 2-D copy as `ext_oneapi_copy2d` or a row loop; ranges and lists as one small kernel / a loop of copies |
|
||||
| `host_wrote` | nothing: USM host allocations are coherent for the device at submission |
|
||||
| `vram_used` | `ext::intel::info::device::free_memory` |
|
||||
| `pci_address` | `ext::intel::info::device::pci_address` |
|
||||
| `runtime_version` | the SYCL platform version string |
|
||||
| tapes | null at first; later `sycl_ext_oneapi_graph` (Phase 4, if submission overhead dominates decode) |
|
||||
| vmem, DMA lane, link holds, rides, prefetch, gates | null (each a supported configuration) |
|
||||
| gates | a one-work-item kernel spinning on a flag in pinned host memory |
|
||||
| vmem, DMA lane, link holds, rides, prefetch | null (each a supported configuration) |
|
||||
|
||||
`select_backend()` tries, in order: AQL (if built with HIP and an AMD card is visible), SYCL (if built
|
||||
with SYCL and a Level Zero GPU is visible), host. `RADIANCE_DEVICE_BACKEND=sycl|aql|host` (new)
|
||||
@@ -261,16 +262,17 @@ without weights already fail as holes. `--debug-graph` shows the resolution eith
|
||||
|
||||
- `RAD_SYCL` (`OFF | ON | AUTO`, default **OFF**), `build.sh --sycl`, a `sycl` preset, a `sycl` ctest
|
||||
label (card tests, `SKIP_RETURN_CODE 77` without a Level Zero GPU, like `gpu`).
|
||||
- **Compiler.** CMake has no SYCL language, and `-fsycl` sources need `icpx`. With `RAD_SYCL=ON` the
|
||||
whole build uses `icpx` as `CMAKE_CXX_COMPILER` and only SYCL sources get `-fsycl` (with
|
||||
`-fsycl` on the link of targets holding them). Configure refuses `RAD_SYCL=ON` with another C++
|
||||
compiler, naming the fix (`-DCMAKE_CXX_COMPILER=icpx`, which `build.sh --sycl` passes).
|
||||
**`icpx` defaults to `-fp-model=fast`**; the SYCL build passes `-ffp-model=precise` to host code so
|
||||
libref and libavx compute what they compute under GCC, and the host tier is run in the SYCL build
|
||||
too to show it. The default build (GCC, `RAD_SYCL=OFF`) is unchanged.
|
||||
*Fallback* if host code under `icpx` does not reproduce the GCC results: build the SYCL pieces
|
||||
(`core/device/sycl.cpp` as a small C-ABI shared library, `libxe2`) as a separate CMake project
|
||||
with `icpx` through `ExternalProject`, leaving the main build on GCC.
|
||||
- **Compiler.** CMake has no SYCL language, and `-fsycl` sources need `icpx`. The first plan, the
|
||||
whole build on `icpx`, failed: libavx calls `_pdep_u64` without `-mbmi2`, which GCC accepts and
|
||||
clang refuses (`SYCL_PROGRESS.md` D6). So **the main build stays on its own compiler in every
|
||||
configuration**, and the SYCL code is a separate CMake project, `sycl/`, configured with `icpx`
|
||||
through `ExternalProject`: `librad_sycl.so` (the device backend with the core's SYCL kernels;
|
||||
one C entry point, `rad_sycl_backend`, and a callback table for the engine's logger and error
|
||||
slot, `core/device/sycl_host.h`) and later `libxe2.so`. Host code in a SYCL build is therefore the
|
||||
default build's. `icpx` defaults to `-fp-model=fast`; the sub-build passes `-ffp-model=precise`.
|
||||
- **Run time.** The SYCL runtime `dlopen`s its Level Zero adapter, which needs oneAPI's `umf/`
|
||||
libraries, so the engine runs under the oneAPI environment (`. /opt/intel/oneapi/setvars.sh`).
|
||||
Without it no GPU is visible and the engine warns that it is running on the CPU.
|
||||
- **HIP and SYCL in one build**: allowed in principle (HIP is its own CMake language), but untestable
|
||||
here (no ROCm). The first version refuses `RAD_SYCL=ON` together with a found HIP at configure
|
||||
time with a clear message; lifting that is a later change made on a machine with both.
|
||||
|
||||
+57
-15
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user