diff --git a/abi/rad_abi.h b/abi/rad_abi.h index ed4eefa7..37e132bb 100644 --- a/abi/rad_abi.h +++ b/abi/rad_abi.h @@ -16,7 +16,8 @@ extern "C" { * rad_builder.h, rad_runtime.h, rad_device.h, rad_encoding.h, rad_quant.h or rad_sample.h. Every * kind of plugin reports it, and a plugin that does not report exactly this version is refused at * load with both versions printed. A new optional export (e.g. rad_plugin_reference) is not a - * change of shape: a plugin without it gets the default. */ + * change of shape: a plugin without it gets the default. rad_sycl.h is versioned on its own + * (RAD_SYCL_STREAM_VERSION), since only SYCL kernel libraries read it. */ #define RAD_ABI_VERSION 26u /* ================================================================== plugin identity */ diff --git a/abi/rad_sycl.h b/abi/rad_sycl.h new file mode 100644 index 00000000..7ba13761 --- /dev/null +++ b/abi/rad_sycl.h @@ -0,0 +1,56 @@ +#ifndef RAD_SYCL_H +#define RAD_SYCL_H + +/* rad_sycl.h -- what a RadStream is under the SYCL device backend (docs/SYCL_PORTING.md §4.2). + * + * On an AMD card a kernel plugin launches through hipLaunchKernel, which the engine serves on its + * own queues (docs/PLUGIN.md §5). SYCL has no launch entry point the engine could serve, so a SYCL + * kernel library is handed the queue itself: under the SYCL backend a RadStream points to a + * RadSyclStream, whose `queue` is an in-order sycl::queue the engine owns. Under every other + * backend a RadStream is not one, and `magic` says so. + * + * The struct carries its own version instead of moving RAD_ABI_VERSION, because no shape an + * existing plugin compiles against changes; only SYCL plugins read it, and rad_sycl_queue() refuses + * a struct of another version. Bump RAD_SYCL_STREAM_VERSION on any change below. + * + * What a launch may do with the queue mirrors docs/PLUGIN.md §5: submit kernels, copies and fills + * to it. It must not wait on it (a launch never synchronises), allocate (scratch comes from the + * `scratch` hook), submit host tasks, or keep the queue past the launch. */ +#include + +#include "rad_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define RAD_SYCL_STREAM_MAGIC 0x4C435953u /* "SYCL", little-endian */ +#define RAD_SYCL_STREAM_VERSION 1u + +typedef struct RadSyclStream { + uint32_t magic; /* RAD_SYCL_STREAM_MAGIC */ + uint32_t version; /* RAD_SYCL_STREAM_VERSION */ + void* queue; /* sycl::queue*, in order, owned by the engine */ + int32_t device; /* the device index the queue submits to (rad_dev_set's numbering) */ + int32_t reserved; +} RadSyclStream; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#if defined(__cplusplus) && defined(SYCL_LANGUAGE_VERSION) +#include + +/* The queue behind `s`, or null when `s` is not a SYCL stream of this version (another backend's + * stream, or a plugin built against a different rad_sycl.h); the launch then returns + * RAD_E_DEVICE. */ +inline sycl::queue* rad_sycl_queue(RadStream s) { + const RadSyclStream* r = (const RadSyclStream*)s; + if (!r || r->magic != RAD_SYCL_STREAM_MAGIC || r->version != RAD_SYCL_STREAM_VERSION) + return nullptr; + return (sycl::queue*)r->queue; +} +#endif + +#endif /* RAD_SYCL_H */ diff --git a/abi/rad_types.h b/abi/rad_types.h index 45d5bfbd..f4cdd127 100644 --- a/abi/rad_types.h +++ b/abi/rad_types.h @@ -326,8 +326,9 @@ typedef uint32_t rad_kvgroup; /* Opaque: the core never dereferences one. On a card it is the engine's own queue, not a * hipStream_t. A kernel plugin may use it only with hipLaunchKernel (and so <<<>>>), * hipMemcpyAsync, hipMemcpy2DAsync and hipMemsetAsync, which the engine implements itself, and - * must pass it to nothing else in HIP (docs/PLUGIN.md, "What a launch may do"). Under the host - * backend the host kernels ignore it. */ + * must pass it to nothing else in HIP (docs/PLUGIN.md, "What a launch may do"). Under the SYCL + * backend it points to a RadSyclStream holding the engine's sycl::queue (rad_sycl.h). Under the + * host backend the host kernels ignore it. */ typedef void* RadStream; #ifdef __cplusplus diff --git a/docs/SYCL_PROGRESS.md b/docs/SYCL_PROGRESS.md index 7f665538..1c47ea12 100644 --- a/docs/SYCL_PROGRESS.md +++ b/docs/SYCL_PROGRESS.md @@ -180,9 +180,15 @@ Planned use: Milestone A = `minicpm5-2b-bf16.rad` (blocked, item 1); Milestone B 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: `RAD_SYCL=ON` builds everything with `icpx`, host code at `-ffp-model=precise` (icpx's default - is fast math); `-fsycl` only on SYCL sources. Fallback: ExternalProject for the SYCL pieces if - host results differ from GCC's. HIP + SYCL refused together at configure until a ROCm machine can +- 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. (§4.7) diff --git a/tests/abi_c_test.c b/tests/abi_c_test.c index c70569e6..c34faba0 100644 --- a/tests/abi_c_test.c +++ b/tests/abi_c_test.c @@ -15,6 +15,7 @@ #include "rad_quant.h" #include "rad_runtime.h" #include "rad_sample.h" +#include "rad_sycl.h" #include "rad_types.h" #include "rad_yarn.h" diff --git a/tests/abi_layout_rows.h b/tests/abi_layout_rows.h index de2f879e..79a2ba38 100644 --- a/tests/abi_layout_rows.h +++ b/tests/abi_layout_rows.h @@ -642,6 +642,12 @@ ABI_FIELD(RadSampleParams, hist_len) ABI_FIELD(RadSampleParams, mask_row) ABI_FIELD(RadSampleParams, flags) ABI_FIELD(RadSampleParams, dry_rep_limit) +ABI_STRUCT(RadSyclStream) +ABI_FIELD(RadSyclStream, magic) +ABI_FIELD(RadSyclStream, version) +ABI_FIELD(RadSyclStream, queue) +ABI_FIELD(RadSyclStream, device) +ABI_FIELD(RadSyclStream, reserved) ABI_STRUCT(RadTensor) ABI_FIELD(RadTensor, data) ABI_FIELD(RadTensor, dtype) diff --git a/tests/abi_layout_test.cpp b/tests/abi_layout_test.cpp index 611d3c8a..2e79065c 100644 --- a/tests/abi_layout_test.cpp +++ b/tests/abi_layout_test.cpp @@ -26,6 +26,7 @@ #include "rad_quant.h" #include "rad_runtime.h" #include "rad_sample.h" +#include "rad_sycl.h" #include "rad_types.h" #include "rad_yarn.h"