#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 */