Archived
Compare commits
4
Commits
main
...
370a906c70
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
370a906c70 | ||
|
|
a3dc47b79a | ||
|
|
ec4dbb6464 | ||
|
|
c25f610fda |
No files matched your search
@@ -84,6 +84,38 @@ elseif(NOT RAD_HIPCC)
|
|||||||
"/opt/rocm/llvm/bin and $ROCM_PATH.")
|
"/opt/rocm/llvm/bin and $ROCM_PATH.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- SYCL detection
|
||||||
|
# The Intel GPU backend (docs/SYCL_PORTING.md). Off by default. SYCL code is compiled and linked by
|
||||||
|
# icpx in a sub-build of its own (sycl/CMakeLists.txt, added below), so everything else stays on
|
||||||
|
# this project's compiler: a SYCL build's host code is the default build's.
|
||||||
|
#
|
||||||
|
# RAD_SYCL_TARGETS names the AOT targets (icpx -fsycl-targets spelling); the default is the Arc Pro
|
||||||
|
# B65's Battlemage G31.
|
||||||
|
set(RAD_SYCL "OFF" CACHE STRING "ON | OFF | AUTO -- build the SYCL (Intel GPU) backend with icpx")
|
||||||
|
set_property(CACHE RAD_SYCL PROPERTY STRINGS ON OFF AUTO)
|
||||||
|
set(RAD_SYCL_TARGETS "intel_gpu_bmg_g31" CACHE STRING "AOT targets for SYCL device code")
|
||||||
|
set(RAD_SYCL_FOUND OFF)
|
||||||
|
if(NOT RAD_SYCL STREQUAL "OFF")
|
||||||
|
find_program(RAD_ICPX icpx HINTS ENV CMPLR_ROOT PATH_SUFFIXES bin
|
||||||
|
PATHS /opt/intel/oneapi/compiler/latest/bin)
|
||||||
|
if(RAD_ICPX)
|
||||||
|
set(RAD_SYCL_FOUND ON)
|
||||||
|
elseif(RAD_SYCL STREQUAL "ON")
|
||||||
|
message(FATAL_ERROR "RAD_SYCL=ON but icpx was not found. Install the oneAPI DPC++ compiler, or "
|
||||||
|
"source /opt/intel/oneapi/setvars.sh first.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(RAD_SYCL_FOUND AND RAD_HIP_FOUND)
|
||||||
|
# Both could be compiled side by side in principle; nothing has tested one engine holding both,
|
||||||
|
# so a build picks one (docs/SYCL_PORTING.md §4.5).
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"radiance: RAD_SYCL and the HIP backend are both on. One build holds one device backend: "
|
||||||
|
"configure the SYCL build with -DRAD_WITH_HIP=OFF (build.sh --sycl does).")
|
||||||
|
endif()
|
||||||
|
if(RAD_SYCL_FOUND)
|
||||||
|
message(STATUS "radiance: SYCL backend ON, ${RAD_ICPX}, targets ${RAD_SYCL_TARGETS}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# ASan + UBSan for host code only. AMD's amdgcn ASan needs xnack+ for its page-fault-based shadow,
|
# ASan + UBSan for host code only. AMD's amdgcn ASan needs xnack+ for its page-fault-based shadow,
|
||||||
# and RDNA has no xnack, so the generator expressions keep the flags off HIP. Device kernels rely on
|
# and RDNA has no xnack, so the generator expressions keep the flags off HIP. Device kernels rely on
|
||||||
# rad-kbench's red zones instead: a poisoned margin around every operand and scratch allocation,
|
# rad-kbench's red zones instead: a poisoned margin around every operand and scratch allocation,
|
||||||
@@ -286,6 +318,31 @@ if(NOT RAD_WITH_FFMPEG STREQUAL "OFF")
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- the icpx sub-build
|
||||||
|
# sycl/ is its own CMake project, configured with icpx, so -fsycl code never meets this project's
|
||||||
|
# compiler. rad_core links librad_sycl.so (the device backend) as an imported library.
|
||||||
|
if(RAD_SYCL_FOUND)
|
||||||
|
include(ExternalProject)
|
||||||
|
set(RAD_SYCL_BINARY_DIR ${CMAKE_BINARY_DIR}/sycl)
|
||||||
|
ExternalProject_Add(rad_sycl_build
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sycl
|
||||||
|
BINARY_DIR ${RAD_SYCL_BINARY_DIR}
|
||||||
|
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${RAD_ICPX}
|
||||||
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||||
|
-DRAD_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
-DRAD_SYCL_TARGETS=${RAD_SYCL_TARGETS}
|
||||||
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
BUILD_ALWAYS ON
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
BUILD_BYPRODUCTS ${RAD_SYCL_BINARY_DIR}/librad_sycl.so
|
||||||
|
USES_TERMINAL_BUILD ON)
|
||||||
|
add_library(rad_sycl_rt SHARED IMPORTED GLOBAL)
|
||||||
|
set_target_properties(rad_sycl_rt PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${RAD_SYCL_BINARY_DIR}/librad_sycl.so
|
||||||
|
IMPORTED_NO_SONAME ON)
|
||||||
|
add_dependencies(rad_sycl_rt rad_sycl_build)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(vendor)
|
add_subdirectory(vendor)
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
# Kernel plugins, one root directory each. Each holds its kernels, row table and layouts and links
|
# Kernel plugins, one root directory each. Each holds its kernels, row table and layouts and links
|
||||||
|
|||||||
+17
-1
@@ -21,12 +21,20 @@
|
|||||||
"inherits": "default",
|
"inherits": "default",
|
||||||
"binaryDir": "${sourceDir}/build-tsan",
|
"binaryDir": "${sourceDir}/build-tsan",
|
||||||
"cacheVariables": { "RAD_TSAN": "ON", "RAD_ASAN": "OFF", "RAD_WITH_HIP": "OFF" }
|
"cacheVariables": { "RAD_TSAN": "ON", "RAD_ASAN": "OFF", "RAD_WITH_HIP": "OFF" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sycl",
|
||||||
|
"displayName": "The Intel GPU (SYCL) backend, its code built by icpx, in build-sycl/",
|
||||||
|
"inherits": "default",
|
||||||
|
"binaryDir": "${sourceDir}/build-sycl",
|
||||||
|
"cacheVariables": { "RAD_SYCL": "ON", "RAD_WITH_HIP": "OFF" }
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"buildPresets": [
|
"buildPresets": [
|
||||||
{ "name": "default", "configurePreset": "default" },
|
{ "name": "default", "configurePreset": "default" },
|
||||||
{ "name": "asan", "configurePreset": "asan" },
|
{ "name": "asan", "configurePreset": "asan" },
|
||||||
{ "name": "tsan", "configurePreset": "tsan" }
|
{ "name": "tsan", "configurePreset": "tsan" },
|
||||||
|
{ "name": "sycl", "configurePreset": "sycl" }
|
||||||
],
|
],
|
||||||
"testPresets": [
|
"testPresets": [
|
||||||
{
|
{
|
||||||
@@ -59,6 +67,14 @@
|
|||||||
"inherits": "base",
|
"inherits": "base",
|
||||||
"filter": { "include": { "label": "^gpu$" } }
|
"filter": { "include": { "label": "^gpu$" } }
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "sycl",
|
||||||
|
"displayName": "The tests that need an Intel GPU, one at a time (load the oneAPI environment first)",
|
||||||
|
"inherits": "base",
|
||||||
|
"configurePreset": "sycl",
|
||||||
|
"filter": { "include": { "label": "^sycl$" } },
|
||||||
|
"execution": { "jobs": 1, "noTestsAction": "error" }
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "perf",
|
"name": "perf",
|
||||||
"displayName": "The wall-clock checks, one at a time",
|
"displayName": "The wall-clock checks, one at a time",
|
||||||
|
|||||||
+2
-1
@@ -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
|
* 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
|
* 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
|
* 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
|
#define RAD_ABI_VERSION 26u
|
||||||
|
|
||||||
/* ================================================================== plugin identity */
|
/* ================================================================== plugin identity */
|
||||||
|
|||||||
@@ -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 <stdint.h>
|
||||||
|
|
||||||
|
#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 <sycl/sycl.hpp>
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
+3
-2
@@ -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
|
/* 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 <<<>>>),
|
* hipStream_t. A kernel plugin may use it only with hipLaunchKernel (and so <<<>>>),
|
||||||
* hipMemcpyAsync, hipMemcpy2DAsync and hipMemsetAsync, which the engine implements itself, and
|
* 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
|
* must pass it to nothing else in HIP (docs/PLUGIN.md, "What a launch may do"). Under the SYCL
|
||||||
* backend the host kernels ignore it. */
|
* 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;
|
typedef void* RadStream;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
# ./build.sh --no-hip force the host backend even where hipcc exists
|
# ./build.sh --no-hip force the host backend even where hipcc exists
|
||||||
# ./build.sh --asan AddressSanitizer + UBSan, host backend, in build-asan/
|
# ./build.sh --asan AddressSanitizer + UBSan, host backend, in build-asan/
|
||||||
# ./build.sh --tsan ThreadSanitizer, host backend, in build-tsan/
|
# ./build.sh --tsan ThreadSanitizer, host backend, in build-tsan/
|
||||||
|
# ./build.sh --sycl the Intel GPU (SYCL) backend, in build-sycl/: the engine as usual, its
|
||||||
|
# SYCL code built by icpx (oneAPI); docs/SYCL_PORTING.md
|
||||||
# ./build.sh --debug CMAKE_BUILD_TYPE=Debug
|
# ./build.sh --debug CMAKE_BUILD_TYPE=Debug
|
||||||
# ./build.sh -b DIR build in DIR instead of build/ (or build-asan/, build-tsan/)
|
# ./build.sh -b DIR build in DIR instead of build/ (or build-asan/, build-tsan/)
|
||||||
#
|
#
|
||||||
@@ -33,6 +35,7 @@ while [ $# -gt 0 ]; do
|
|||||||
--no-hip) CMAKE_ARGS="$CMAKE_ARGS -DRAD_WITH_HIP=OFF" ;;
|
--no-hip) CMAKE_ARGS="$CMAKE_ARGS -DRAD_WITH_HIP=OFF" ;;
|
||||||
--asan) SAN=asan ;;
|
--asan) SAN=asan ;;
|
||||||
--tsan) SAN=tsan ;;
|
--tsan) SAN=tsan ;;
|
||||||
|
--sycl) SAN=sycl ;;
|
||||||
--debug) CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug" ;;
|
--debug) CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug" ;;
|
||||||
-b) shift; BUILD="$1" ;;
|
-b) shift; BUILD="$1" ;;
|
||||||
*) echo "build.sh: unknown option $1" >&2; exit 2 ;;
|
*) echo "build.sh: unknown option $1" >&2; exit 2 ;;
|
||||||
@@ -47,6 +50,9 @@ case "$SAN" in
|
|||||||
BUILD=${BUILD:-build-asan} ;;
|
BUILD=${BUILD:-build-asan} ;;
|
||||||
tsan) CMAKE_ARGS="$CMAKE_ARGS -DRAD_TSAN=ON -DRAD_ASAN=OFF -DRAD_WITH_HIP=OFF"
|
tsan) CMAKE_ARGS="$CMAKE_ARGS -DRAD_TSAN=ON -DRAD_ASAN=OFF -DRAD_WITH_HIP=OFF"
|
||||||
BUILD=${BUILD:-build-tsan} ;;
|
BUILD=${BUILD:-build-tsan} ;;
|
||||||
|
# Not a sanitiser, but likewise a configuration with a directory of its own.
|
||||||
|
sycl) CMAKE_ARGS="$CMAKE_ARGS -DRAD_SYCL=ON -DRAD_WITH_HIP=OFF"
|
||||||
|
BUILD=${BUILD:-build-sycl} ;;
|
||||||
*) BUILD=${BUILD:-build} ;;
|
*) BUILD=${BUILD:-build} ;;
|
||||||
esac
|
esac
|
||||||
[ "$CLEAN" = 1 ] && rm -rf "$BUILD"
|
[ "$CLEAN" = 1 ] && rm -rf "$BUILD"
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ if(RAD_FFMPEG_FOUND)
|
|||||||
target_link_libraries(rad_core PUBLIC PkgConfig::RAD_FFMPEG)
|
target_link_libraries(rad_core PUBLIC PkgConfig::RAD_FFMPEG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(RAD_SYCL_FOUND)
|
||||||
|
# The SYCL device backend lives in librad_sycl.so, built by icpx (sycl/CMakeLists.txt);
|
||||||
|
# device/sycl.cpp compiles to nothing here. The rpath finds it in the build tree.
|
||||||
|
target_compile_definitions(rad_core PUBLIC RAD_HAVE_SYCL=1)
|
||||||
|
target_link_libraries(rad_core PUBLIC rad_sycl_rt)
|
||||||
|
target_link_options(rad_core INTERFACE "LINKER:-rpath,${RAD_SYCL_BINARY_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(RAD_HIP_FOUND)
|
if(RAD_HIP_FOUND)
|
||||||
target_compile_definitions(rad_core PUBLIC RAD_HAVE_HIP=1)
|
target_compile_definitions(rad_core PUBLIC RAD_HAVE_HIP=1)
|
||||||
target_link_libraries(rad_core PUBLIC ${RAD_HIP_RUNTIME} ${RAD_HSA_RUNTIME})
|
target_link_libraries(rad_core PUBLIC ${RAD_HIP_RUNTIME} ${RAD_HSA_RUNTIME})
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ typedef void* RadTape;
|
|||||||
* no VRAM tier), the selector (only RAD_DOMAIN_HOST can run) and tests that skip device-only
|
* no VRAM tier), the selector (only RAD_DOMAIN_HOST can run) and tests that skip device-only
|
||||||
* assertions. */
|
* assertions. */
|
||||||
bool device_is_host();
|
bool device_is_host();
|
||||||
const char* device_backend_name(); /* "host" or "aql" */
|
const char* device_backend_name(); /* "host", "aql" or "sycl" */
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ two contract notes
|
/* ------------------------------------------------------------------ two contract notes
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "../rad_internal.h"
|
#include "../rad_internal.h"
|
||||||
|
#if defined(RAD_HAVE_SYCL) && RAD_HAVE_SYCL
|
||||||
|
#include "sycl_host.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
@@ -84,7 +87,33 @@ static void warn_cwsr_off() {
|
|||||||
static DeviceBackend g_host_beside_hip;
|
static DeviceBackend g_host_beside_hip;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(RAD_HAVE_SYCL) && RAD_HAVE_SYCL
|
||||||
|
/* What librad_sycl.so reaches of the engine (sycl_host.h). */
|
||||||
|
static const SyclHost g_sycl_host = {
|
||||||
|
kSyclHostVersion,
|
||||||
|
[] { return (int)log_level(); },
|
||||||
|
[](int level, const char* file, int line, const char* msg) {
|
||||||
|
log_emit((Log)level, file, line, "%s", msg);
|
||||||
|
},
|
||||||
|
[](const char* msg) { device_set_error("%s", msg); },
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static const DeviceBackend* select_backend() {
|
static const DeviceBackend* select_backend() {
|
||||||
|
#if defined(RAD_HAVE_SYCL) && RAD_HAVE_SYCL
|
||||||
|
/* A SYCL build has no HIP (configure refuses both, docs/SYCL_PORTING.md §4.5). */
|
||||||
|
if (const DeviceBackend* b = rad_sycl_backend(&g_sycl_host)) {
|
||||||
|
RAD_INFO("device: SYCL backend, %d device(s) [%s]", b->count(),
|
||||||
|
device_inventory(b).c_str());
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
/* A warning, not Info: on a machine whose card is there, this is the GPU being skipped. The
|
||||||
|
* usual cause is a missing oneAPI environment, since the runtime loads its Level Zero adapter
|
||||||
|
* and that adapter's libraries (libumf) from the oneAPI tree at run time. */
|
||||||
|
RAD_WARN("device: built with SYCL but no Level Zero GPU is visible -- using the host backend "
|
||||||
|
"(CPU). If this machine has an Intel GPU, load the oneAPI environment first "
|
||||||
|
"(. /opt/intel/oneapi/setvars.sh); ONEAPI_DEVICE_SELECTOR may also be hiding it");
|
||||||
|
#endif
|
||||||
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
|
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
|
||||||
if (const DeviceBackend* b = aql_backend_if_present()) {
|
if (const DeviceBackend* b = aql_backend_if_present()) {
|
||||||
RAD_INFO("device: AQL backend, %d device(s) [%s]", b->count(),
|
RAD_INFO("device: AQL backend, %d device(s) [%s]", b->count(),
|
||||||
|
|||||||
@@ -0,0 +1,851 @@
|
|||||||
|
/* sycl.cpp -- the SYCL device backend: Intel GPUs through oneAPI's SYCL runtime over Level Zero.
|
||||||
|
*
|
||||||
|
* Every stream is an in-order sycl::queue on one context holding every device, and a RadStream is
|
||||||
|
* a RadSyclStream (abi/rad_sycl.h), so a SYCL kernel library submits to the engine's queue itself.
|
||||||
|
* Events are barriers on those queues: a record is a barrier whose event completes once everything
|
||||||
|
* before it has, and a wait is a barrier on the waiting queue that depends on that event, so no
|
||||||
|
* host thread blocks for either.
|
||||||
|
*
|
||||||
|
* Thin by design, like hip.cpp: each entry point is one runtime call plus error capture, and the
|
||||||
|
* contract is the host backend's (docs/IMPLEMENTATION.md). Where the runtime is more permissive
|
||||||
|
* than a card's contract (rad_memset_async on pageable memory, device.h note 1) the refusal is
|
||||||
|
* made here, so code developed on the host backend sees the same answer on this one.
|
||||||
|
*
|
||||||
|
* What this backend leaves out, each a supported configuration (device.h): recorded passes, elastic
|
||||||
|
* memory, the DMA lane and link holds, the expert prefetch, gates, chained launches. Peer access is
|
||||||
|
* refused, since the Intel backend serves one card (docs/SYCL_PORTING.md §4.7).
|
||||||
|
*
|
||||||
|
* Timing is opt-in. A queue made with enable_profiling costs ~20 us of host time per submission
|
||||||
|
* against ~4.5 us without (measured on the Arc Pro B65, docs/SYCL_PROGRESS.md D9), which at ~550
|
||||||
|
* launches a decode step is most of a step. So queues carry it only under RADIANCE_SYCL_TIMING=1,
|
||||||
|
* and otherwise rad_event_elapsed_ms refuses, naming the variable (--profile-ops, rad-kbench).
|
||||||
|
*
|
||||||
|
* Built by icpx into librad_sycl.so (sycl/CMakeLists.txt); the engine reaches it through
|
||||||
|
* rad_sycl_backend() and hands it its logger (sycl_host.h). core/CMakeLists.txt globs this
|
||||||
|
* directory into the engine, built without SYCL, where the file compiles to nothing.
|
||||||
|
*/
|
||||||
|
#if defined(SYCL_LANGUAGE_VERSION)
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
#include "sycl_host.h"
|
||||||
|
|
||||||
|
#include "../rad_internal.h"
|
||||||
|
#include "rad_sycl.h"
|
||||||
|
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <atomic>
|
||||||
|
#include <cstring>
|
||||||
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <new>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace rad {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
namespace syclex = sycl::ext::oneapi::experimental;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ the runtime's state
|
||||||
|
*
|
||||||
|
* Built once, on first use: the Level Zero GPUs in the platform's order and one context over all
|
||||||
|
* of them (USM pointers are valid only within their context). */
|
||||||
|
struct Runtime {
|
||||||
|
std::vector<sycl::device> devs;
|
||||||
|
sycl::context* ctx = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
Runtime& rt() {
|
||||||
|
static Runtime* r = [] {
|
||||||
|
auto* x = new Runtime();
|
||||||
|
try {
|
||||||
|
for (const sycl::device& d : sycl::device::get_devices(sycl::info::device_type::gpu))
|
||||||
|
if (d.get_backend() == sycl::backend::ext_oneapi_level_zero) x->devs.push_back(d);
|
||||||
|
if (!x->devs.empty()) x->ctx = new sycl::context(x->devs);
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
RAD_DEBUG("device: SYCL device enumeration failed: %s", e.what());
|
||||||
|
x->devs.clear();
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}();
|
||||||
|
return *r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RADIANCE_SYCL_TIMING=1: queues are made with enable_profiling (see the file header). */
|
||||||
|
bool timing_on() {
|
||||||
|
static const bool on = [] {
|
||||||
|
const char* e = std::getenv("RADIANCE_SYCL_TIMING");
|
||||||
|
return e && e[0] == '1';
|
||||||
|
}();
|
||||||
|
return on;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Per thread, matching hipSetDevice: one thread per rank, one device per rank (spec §1). */
|
||||||
|
thread_local int t_device = 0;
|
||||||
|
|
||||||
|
int sycl_fail(const sycl::exception& e, const char* who) {
|
||||||
|
device_set_error("%s: %s", who, e.what());
|
||||||
|
const std::error_code c = e.code();
|
||||||
|
if (c == sycl::errc::memory_allocation) return RAD_E_NOMEM;
|
||||||
|
if (c == sycl::errc::invalid || c == sycl::errc::nd_range) return RAD_E_INVAL;
|
||||||
|
if (c == sycl::errc::feature_not_supported) return RAD_E_UNSUPPORTED;
|
||||||
|
return RAD_E_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SYCL_TRY(who, ...) \
|
||||||
|
do { try { __VA_ARGS__; } \
|
||||||
|
catch (const sycl::exception& _e) { return sycl_fail(_e, who); } } while (0)
|
||||||
|
|
||||||
|
bool valid_device(int device) { return device >= 0 && device < (int)rt().devs.size(); }
|
||||||
|
|
||||||
|
/* Asynchronous errors (a kernel fault) arrive here from wait_and_throw. A device fault is not
|
||||||
|
* recoverable in-process (rad_device.h), so the error is recorded for the thread that waited and
|
||||||
|
* every later wait reports it too. */
|
||||||
|
std::mutex g_async_m;
|
||||||
|
std::string g_async_error;
|
||||||
|
|
||||||
|
void async_handler(sycl::exception_list errs) {
|
||||||
|
for (const std::exception_ptr& p : errs) {
|
||||||
|
try {
|
||||||
|
std::rethrow_exception(p);
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
std::lock_guard<std::mutex> lk(g_async_m);
|
||||||
|
if (g_async_error.empty()) g_async_error = e.what();
|
||||||
|
RAD_WARN("device: asynchronous SYCL error: %s", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int async_status(const char* who) {
|
||||||
|
std::lock_guard<std::mutex> lk(g_async_m);
|
||||||
|
if (g_async_error.empty()) return RAD_OK;
|
||||||
|
device_set_error("%s: the device reported an error earlier: %s", who, g_async_error.c_str());
|
||||||
|
return RAD_E_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ devices */
|
||||||
|
|
||||||
|
int d_count(void) { return (int)rt().devs.size(); }
|
||||||
|
|
||||||
|
int d_set(int device) {
|
||||||
|
if (!valid_device(device)) {
|
||||||
|
device_set_error("rad_dev_set(%d): %d SYCL device(s)", device, d_count());
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
t_device = device;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RadDeviceProps::arch, the name a kernel library's build_target names: the oneAPI architecture
|
||||||
|
* enum's own spelling. A device this table does not know is "intel_gpu" plus its IP version, so
|
||||||
|
* a library built for a named architecture never claims it. */
|
||||||
|
std::string arch_name(const sycl::device& d) {
|
||||||
|
try {
|
||||||
|
switch (d.get_info<syclex::info::device::architecture>()) {
|
||||||
|
case syclex::architecture::intel_gpu_bmg_g21: return "intel_gpu_bmg_g21";
|
||||||
|
case syclex::architecture::intel_gpu_bmg_g31: return "intel_gpu_bmg_g31";
|
||||||
|
case syclex::architecture::intel_gpu_lnl_m: return "intel_gpu_lnl_m";
|
||||||
|
case syclex::architecture::intel_gpu_ptl_h: return "intel_gpu_ptl_h";
|
||||||
|
case syclex::architecture::intel_gpu_ptl_u: return "intel_gpu_ptl_u";
|
||||||
|
case syclex::architecture::intel_gpu_acm_g10: return "intel_gpu_acm_g10";
|
||||||
|
case syclex::architecture::intel_gpu_acm_g11: return "intel_gpu_acm_g11";
|
||||||
|
case syclex::architecture::intel_gpu_acm_g12: return "intel_gpu_acm_g12";
|
||||||
|
case syclex::architecture::intel_gpu_pvc: return "intel_gpu_pvc";
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
char b[32];
|
||||||
|
std::snprintf(b, sizeof b, "intel_gpu_%llx",
|
||||||
|
(unsigned long long)d.get_info<syclex::info::device::architecture>());
|
||||||
|
return b;
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return "intel_gpu";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t free_bytes(const sycl::device& d) {
|
||||||
|
if (!d.has(sycl::aspect::ext_intel_free_memory)) return -1;
|
||||||
|
try {
|
||||||
|
return (int64_t)d.get_info<sycl::ext::intel::info::device::free_memory>();
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_integrated(int device) {
|
||||||
|
if (!valid_device(device)) return 0;
|
||||||
|
/* Unified host memory is how SYCL tells an integrated GPU, whose "device memory" is host
|
||||||
|
* memory shared with every process. */
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
try {
|
||||||
|
return rt().devs[device].get_info<sycl::info::device::host_unified_memory>() ? 1 : 0;
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_props(int device, RadDeviceProps* out) {
|
||||||
|
if (!out) return RAD_E_INVAL;
|
||||||
|
if (!valid_device(device)) {
|
||||||
|
device_set_error("rad_dev_props(%d): %d SYCL device(s)", device, d_count());
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
const sycl::device& d = rt().devs[device];
|
||||||
|
std::memset(out, 0, sizeof *out);
|
||||||
|
SYCL_TRY("rad_dev_props", {
|
||||||
|
const std::string name = d.get_info<sycl::info::device::name>();
|
||||||
|
std::snprintf(out->name, sizeof out->name, "%.*s", (int)(sizeof out->name) - 1, name.c_str());
|
||||||
|
const std::string arch = arch_name(d);
|
||||||
|
std::snprintf(out->arch, sizeof out->arch, "%.*s", (int)(sizeof out->arch) - 1, arch.c_str());
|
||||||
|
out->device_id = device;
|
||||||
|
out->n_cu = (int)d.get_info<sycl::info::device::max_compute_units>();
|
||||||
|
/* The sub-group the kernel libraries use: 16 where offered (Xe2's native width). */
|
||||||
|
const std::vector<size_t> sg = d.get_info<sycl::info::device::sub_group_sizes>();
|
||||||
|
out->warp_size = sg.empty() ? 1 : (int)sg.front();
|
||||||
|
for (size_t s : sg)
|
||||||
|
if (s == 16) out->warp_size = 16;
|
||||||
|
out->vram_bytes = (int64_t)d.get_info<sycl::info::device::global_mem_size>();
|
||||||
|
const int64_t fr = free_bytes(d);
|
||||||
|
out->vram_free = fr >= 0 ? fr : out->vram_bytes;
|
||||||
|
out->lds_bytes = (int64_t)d.get_info<sycl::info::device::local_mem_size>();
|
||||||
|
});
|
||||||
|
out->supports_p2p = 0;
|
||||||
|
out->is_host_backend = 0;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* One card only (docs/SYCL_PORTING.md §4.7): no peer is reachable. */
|
||||||
|
int d_peer_access(int self, int peer) { return self == peer ? 1 : 0; }
|
||||||
|
|
||||||
|
int d_enable_peer(int self, int peer) {
|
||||||
|
if (self == peer) return RAD_OK;
|
||||||
|
device_set_error("rad_dev_enable_peer(%d, %d): the SYCL backend serves one card; tensor "
|
||||||
|
"parallelism is not supported on it", self, peer);
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_pci_address(int device, char* out, int cap) {
|
||||||
|
if (!out || cap <= 0) return RAD_E_INVAL;
|
||||||
|
if (!valid_device(device)) return RAD_E_INVAL;
|
||||||
|
const sycl::device& d = rt().devs[device];
|
||||||
|
if (!d.has(sycl::aspect::ext_intel_pci_address)) return RAD_E_UNSUPPORTED;
|
||||||
|
std::string a;
|
||||||
|
SYCL_TRY("rad_dev_pci_address", a = d.get_info<sycl::ext::intel::info::device::pci_address>());
|
||||||
|
unsigned dom = 0, b = 0, dv = 0, f = 0;
|
||||||
|
if (std::sscanf(a.c_str(), "%x:%x:%x.%x", &dom, &b, &dv, &f) != 4) {
|
||||||
|
device_set_error("ext_intel_pci_address(%d): '%s' is not a PCI address", device, a.c_str());
|
||||||
|
return RAD_E_IO;
|
||||||
|
}
|
||||||
|
std::snprintf(out, (size_t)cap, "%04x:%02x:%02x.%x", dom, b, dv, f);
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_runtime_version(char* out, int cap) {
|
||||||
|
if (!out || cap <= 0) return RAD_E_INVAL;
|
||||||
|
if (rt().devs.empty()) return RAD_E_UNSUPPORTED;
|
||||||
|
SYCL_TRY("rad_dev_runtime_version", {
|
||||||
|
const sycl::device& d = rt().devs[0];
|
||||||
|
std::snprintf(out, (size_t)cap, "SYCL %s, Level Zero driver %s",
|
||||||
|
d.get_platform().get_info<sycl::info::platform::version>().c_str(),
|
||||||
|
d.get_info<sycl::info::device::driver_version>().c_str());
|
||||||
|
});
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VRAM in use by all processes, from the driver's free count. Answered once props() has read the
|
||||||
|
* device, as the contract asks; the query does not enter a queue. */
|
||||||
|
int d_vram_used(int device, int64_t* out) {
|
||||||
|
if (!out || !valid_device(device)) return RAD_E_INVAL;
|
||||||
|
const sycl::device& d = rt().devs[device];
|
||||||
|
const int64_t fr = free_bytes(d);
|
||||||
|
if (fr < 0) return RAD_E_UNSUPPORTED;
|
||||||
|
int64_t total = 0;
|
||||||
|
SYCL_TRY("rad_dev_vram_used", total = (int64_t)d.get_info<sycl::info::device::global_mem_size>());
|
||||||
|
*out = total - fr;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ memory
|
||||||
|
*
|
||||||
|
* Pinned host memory (RAD_MEM_HOST_PINNED and _MAPPED) is ordinary page-aligned memory registered
|
||||||
|
* with the driver (prepare_for_device_copy), not SYCL's malloc_host. The driver maps malloc_host
|
||||||
|
* pages itself, and O_DIRECT cannot read into them (EFAULT), while the mover reads the file tier
|
||||||
|
* straight into pinned buffers (directio.h). Registered memory copies at the same rate (28.4 GB/s
|
||||||
|
* either way on the Arc Pro B65) and kernels reach it through system USM, which the Intel driver
|
||||||
|
* provides (aspect usm_system_allocations). The runtime does not know such a pointer, so the
|
||||||
|
* ranges are kept here for host_ptr, device_ptr and the memset check. */
|
||||||
|
std::mutex g_pinned_m;
|
||||||
|
std::map<uintptr_t, size_t> g_pinned; /* base -> bytes */
|
||||||
|
|
||||||
|
bool in_pinned(const void* p) {
|
||||||
|
const uintptr_t a = (uintptr_t)p;
|
||||||
|
std::lock_guard<std::mutex> lk(g_pinned_m);
|
||||||
|
auto it = g_pinned.upper_bound(a);
|
||||||
|
if (it == g_pinned.begin()) return false;
|
||||||
|
--it;
|
||||||
|
return a < it->first + it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Device bytes this process holds through rad_dev_alloc, for the room check's message. */
|
||||||
|
std::atomic<int64_t> g_device_bytes{0};
|
||||||
|
std::mutex g_dev_sizes_m;
|
||||||
|
std::map<uintptr_t, int64_t> g_dev_sizes;
|
||||||
|
|
||||||
|
std::string human(int64_t b) {
|
||||||
|
char buf[32];
|
||||||
|
if (b >= ((int64_t)1 << 30)) std::snprintf(buf, sizeof buf, "%.2f GiB", (double)b / (1 << 30));
|
||||||
|
else if (b >= ((int64_t)1 << 20)) std::snprintf(buf, sizeof buf, "%.1f MiB", (double)b / (1 << 20));
|
||||||
|
else std::snprintf(buf, sizeof buf, "%lld B", (long long)b);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* True when the card can take `bytes` more. Level Zero may accept an allocation past the free
|
||||||
|
* figure and fault later, so the backend refuses it itself, as the AQL backend does. If the driver
|
||||||
|
* gives no figure the allocation is allowed. */
|
||||||
|
bool card_has_room(int device, int64_t bytes, const char* what) {
|
||||||
|
const int64_t avail = free_bytes(rt().devs[device]);
|
||||||
|
if (avail < 0 || bytes <= avail) return true;
|
||||||
|
device_set_error("%s(%s) on card %d: the driver has %s left to give on it. Of the memory in "
|
||||||
|
"use on it, this process holds %s through rad_dev_alloc. Memory another "
|
||||||
|
"process took after the VRAM budget was measured is the usual cause",
|
||||||
|
what, human(bytes).c_str(), device, human(avail).c_str(),
|
||||||
|
human(g_device_bytes.load()).c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* d_alloc(int64_t bytes, int kind) {
|
||||||
|
if (bytes <= 0) {
|
||||||
|
device_set_error("rad_dev_alloc(%lld): size must be positive", (long long)bytes);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (!valid_device(t_device)) {
|
||||||
|
device_set_error("rad_dev_alloc: no SYCL device %d", t_device);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
void* p = nullptr;
|
||||||
|
try {
|
||||||
|
switch (kind) {
|
||||||
|
case RAD_MEM_DEVICE:
|
||||||
|
if (!card_has_room(t_device, bytes, "rad_dev_alloc")) return nullptr;
|
||||||
|
p = sycl::malloc_device((size_t)bytes, rt().devs[t_device], *rt().ctx);
|
||||||
|
if (p) {
|
||||||
|
g_device_bytes += bytes;
|
||||||
|
std::lock_guard<std::mutex> lk(g_dev_sizes_m);
|
||||||
|
g_dev_sizes[(uintptr_t)p] = bytes;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RAD_MEM_HOST_PINNED:
|
||||||
|
case RAD_MEM_HOST_MAPPED: {
|
||||||
|
/* Registered page-aligned memory (see above): one address on both sides, so
|
||||||
|
* host_ptr and device_ptr are the pointer itself. */
|
||||||
|
const size_t n = (size_t)((bytes + 4095) / 4096 * 4096);
|
||||||
|
if (posix_memalign(&p, 4096, n) != 0) p = nullptr;
|
||||||
|
if (!p) break;
|
||||||
|
try {
|
||||||
|
syclex::prepare_for_device_copy(p, n, *rt().ctx);
|
||||||
|
} catch (...) {
|
||||||
|
std::free(p);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
std::lock_guard<std::mutex> lk(g_pinned_m);
|
||||||
|
g_pinned[(uintptr_t)p] = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case RAD_MEM_HOST:
|
||||||
|
/* Pageable, page-aligned so it can be an O_DIRECT target. */
|
||||||
|
if (posix_memalign(&p, 4096, (size_t)((bytes + 4095) / 4096 * 4096)) != 0) p = nullptr;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
device_set_error("rad_dev_alloc: unknown memory kind %d", kind);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
sycl_fail(e, "rad_dev_alloc");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (!p) device_set_error("rad_dev_alloc(%lld, kind %d): out of memory", (long long)bytes, kind);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void d_free(void* p, int kind) {
|
||||||
|
if (!p) return;
|
||||||
|
switch (kind) {
|
||||||
|
case RAD_MEM_DEVICE:
|
||||||
|
try {
|
||||||
|
sycl::free(p, *rt().ctx);
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
RAD_WARN("device: rad_dev_free(%p): %s", p, e.what());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(g_dev_sizes_m);
|
||||||
|
auto it = g_dev_sizes.find((uintptr_t)p);
|
||||||
|
if (it != g_dev_sizes.end()) {
|
||||||
|
g_device_bytes -= it->second;
|
||||||
|
g_dev_sizes.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RAD_MEM_HOST_PINNED:
|
||||||
|
case RAD_MEM_HOST_MAPPED: {
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(g_pinned_m);
|
||||||
|
if (!g_pinned.erase((uintptr_t)p)) {
|
||||||
|
RAD_WARN("rad_dev_free(%p): not pinned memory this backend gave out; leaked "
|
||||||
|
"rather than freed with the wrong allocator", p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
syclex::release_from_device_copy(p, *rt().ctx);
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
RAD_WARN("device: rad_dev_free(%p): %s", p, e.what());
|
||||||
|
}
|
||||||
|
std::free(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case RAD_MEM_HOST:
|
||||||
|
std::free(p);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
RAD_WARN("rad_dev_free(%p): unknown memory kind %d; leaked rather than freed with the "
|
||||||
|
"wrong allocator", p, kind);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* What `p` is to the device: USM device memory, host memory it reaches (SYCL's or this backend's
|
||||||
|
* registered pinned ranges), or unknown (pageable). */
|
||||||
|
sycl::usm::alloc ptr_kind(const void* p) {
|
||||||
|
if (in_pinned(p)) return sycl::usm::alloc::host;
|
||||||
|
try {
|
||||||
|
return sycl::get_pointer_type(p, *rt().ctx);
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return sycl::usm::alloc::unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* d_host_ptr(void* p) {
|
||||||
|
if (!p) return nullptr;
|
||||||
|
const sycl::usm::alloc k = ptr_kind(p);
|
||||||
|
return k == sycl::usm::alloc::host || k == sycl::usm::alloc::shared ? p : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* d_device_ptr(void* p) {
|
||||||
|
if (!p) return nullptr;
|
||||||
|
return ptr_kind(p) != sycl::usm::alloc::unknown ? p : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ streams */
|
||||||
|
|
||||||
|
/* `pub` first, so the RadStream handed out is the RadSyclStream a plugin reads. */
|
||||||
|
struct SyclStream {
|
||||||
|
RadSyclStream pub;
|
||||||
|
sycl::queue q;
|
||||||
|
std::atomic<int> gates{0}; /* closed gates on this stream (rad_stream_gate) */
|
||||||
|
SyclStream(const sycl::context& c, const sycl::device& d, const sycl::property_list& pl)
|
||||||
|
: pub{}, q(c, d, async_handler, pl) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
SyclStream* as_stream(RadStream s) { return (SyclStream*)s; }
|
||||||
|
|
||||||
|
/* A null stream is refused, as on every backend (device.h note 2). */
|
||||||
|
int check_stream(RadStream s, const char* who) {
|
||||||
|
if (s) return RAD_OK;
|
||||||
|
device_set_error("%s: null stream -- radiance does not use the default stream, "
|
||||||
|
"create one with rad_stream_create", who);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_stream_create(RadStream* out, int high_priority) {
|
||||||
|
if (!out) return RAD_E_INVAL;
|
||||||
|
if (!valid_device(t_device)) {
|
||||||
|
device_set_error("rad_stream_create: no SYCL device %d", t_device);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
SyclStream* s = nullptr;
|
||||||
|
SYCL_TRY("rad_stream_create", {
|
||||||
|
using sycl::property::queue::enable_profiling;
|
||||||
|
using sycl::property::queue::in_order;
|
||||||
|
using sycl::ext::oneapi::property::queue::priority_high;
|
||||||
|
sycl::property_list pl;
|
||||||
|
if (high_priority && timing_on())
|
||||||
|
pl = sycl::property_list{in_order{}, enable_profiling{}, priority_high{}};
|
||||||
|
else if (high_priority)
|
||||||
|
pl = sycl::property_list{in_order{}, priority_high{}};
|
||||||
|
else if (timing_on())
|
||||||
|
pl = sycl::property_list{in_order{}, enable_profiling{}};
|
||||||
|
else
|
||||||
|
pl = sycl::property_list{in_order{}};
|
||||||
|
s = new (std::nothrow) SyclStream(*rt().ctx, rt().devs[t_device], pl);
|
||||||
|
});
|
||||||
|
if (!s) {
|
||||||
|
device_set_error("rad_stream_create: out of memory");
|
||||||
|
return RAD_E_NOMEM;
|
||||||
|
}
|
||||||
|
s->pub.magic = RAD_SYCL_STREAM_MAGIC;
|
||||||
|
s->pub.version = RAD_SYCL_STREAM_VERSION;
|
||||||
|
s->pub.queue = &s->q;
|
||||||
|
s->pub.device = t_device;
|
||||||
|
*out = (RadStream)s;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Drains rather than discards, as the host backend's destroy does. */
|
||||||
|
void d_stream_destroy(RadStream st) {
|
||||||
|
if (!st) return;
|
||||||
|
SyclStream* s = as_stream(st);
|
||||||
|
try {
|
||||||
|
s->q.wait_and_throw();
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
RAD_WARN("device: rad_stream_destroy: %s", e.what());
|
||||||
|
}
|
||||||
|
s->pub.magic = 0;
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_stream_sync(RadStream st) {
|
||||||
|
if (!st) {
|
||||||
|
device_set_error("rad_stream_sync: null stream");
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
if (as_stream(st)->gates.load() > 0) {
|
||||||
|
device_set_error("rad_stream_sync: the stream waits at a closed gate, which only "
|
||||||
|
"rad_gate_open releases");
|
||||||
|
return RAD_E_STATE;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_stream_sync", as_stream(st)->q.wait_and_throw());
|
||||||
|
return async_status("rad_stream_sync");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ events
|
||||||
|
*
|
||||||
|
* An event holds its latest record. `recorded` counts records, so a never-recorded event is
|
||||||
|
* complete and waiting on it is a no-op (the mover relies on that, host.cpp). */
|
||||||
|
struct SyclEvent {
|
||||||
|
std::mutex m;
|
||||||
|
sycl::event ev;
|
||||||
|
uint64_t recorded = 0;
|
||||||
|
bool host = false; /* RAD_EVENT_HOST_WAIT: rad_event_sync may block on it */
|
||||||
|
};
|
||||||
|
|
||||||
|
int d_event_create(RadEvent* out, unsigned flags) {
|
||||||
|
if (!out) return RAD_E_INVAL;
|
||||||
|
auto* e = new (std::nothrow) SyclEvent();
|
||||||
|
if (!e) {
|
||||||
|
device_set_error("rad_event_create: out of memory");
|
||||||
|
return RAD_E_NOMEM;
|
||||||
|
}
|
||||||
|
/* RAD_EVENT_LOCAL has no scope to choose here: a barrier's completion is visible to the host
|
||||||
|
* and to every queue of the context alike. */
|
||||||
|
e->host = (flags & RAD_EVENT_HOST_WAIT) != 0;
|
||||||
|
*out = (RadEvent)e;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A queued barrier that waits on the event holds its own reference, so dropping ours is safe. */
|
||||||
|
void d_event_destroy(RadEvent ev) { delete (SyclEvent*)ev; }
|
||||||
|
|
||||||
|
int d_event_record(RadEvent ev, RadStream st) {
|
||||||
|
if (!ev || !st) {
|
||||||
|
device_set_error("rad_event_record: null %s", ev ? "stream" : "event");
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
auto* e = (SyclEvent*)ev;
|
||||||
|
sycl::event b;
|
||||||
|
SYCL_TRY("rad_event_record", b = as_stream(st)->q.ext_oneapi_submit_barrier());
|
||||||
|
std::lock_guard<std::mutex> lk(e->m);
|
||||||
|
e->ev = b;
|
||||||
|
++e->recorded;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_event_wait(RadStream st, RadEvent ev) {
|
||||||
|
if (!ev || !st) {
|
||||||
|
device_set_error("rad_event_wait: null %s", ev ? "stream" : "event");
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
auto* e = (SyclEvent*)ev;
|
||||||
|
sycl::event dep;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(e->m);
|
||||||
|
if (e->recorded == 0) return RAD_OK;
|
||||||
|
dep = e->ev;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_event_wait", as_stream(st)->q.ext_oneapi_submit_barrier({dep}));
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool event_done(const sycl::event& ev) {
|
||||||
|
return ev.get_info<sycl::info::event::command_execution_status>() ==
|
||||||
|
sycl::info::event_command_status::complete;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_event_query(RadEvent ev) {
|
||||||
|
if (!ev) return RAD_E_INVAL;
|
||||||
|
auto* e = (SyclEvent*)ev;
|
||||||
|
std::lock_guard<std::mutex> lk(e->m);
|
||||||
|
if (e->recorded == 0) return 1;
|
||||||
|
try {
|
||||||
|
return event_done(e->ev) ? 1 : 0;
|
||||||
|
} catch (const sycl::exception& x) {
|
||||||
|
return sycl_fail(x, "rad_event_query");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_event_sync(RadEvent ev) {
|
||||||
|
if (!ev) return RAD_E_INVAL;
|
||||||
|
auto* e = (SyclEvent*)ev;
|
||||||
|
if (!e->host) {
|
||||||
|
device_set_error("rad_event_sync: the event was made without RAD_EVENT_HOST_WAIT");
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
sycl::event w;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(e->m);
|
||||||
|
if (e->recorded == 0) return RAD_OK;
|
||||||
|
w = e->ev;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_event_sync", w.wait_and_throw());
|
||||||
|
return async_status("rad_event_sync");
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_event_elapsed_ms(RadEvent a, RadEvent b, float* out) {
|
||||||
|
if (!a || !b || !out) return RAD_E_INVAL;
|
||||||
|
if (!timing_on()) {
|
||||||
|
device_set_error("rad_event_elapsed_ms: the SYCL backend times events only under "
|
||||||
|
"RADIANCE_SYCL_TIMING=1 (profiling queues cost ~20 us a submission)");
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
auto stamp = [](RadEvent ev, uint64_t* t) -> int {
|
||||||
|
auto* e = (SyclEvent*)ev;
|
||||||
|
std::lock_guard<std::mutex> lk(e->m);
|
||||||
|
if (e->recorded == 0) return RAD_E_STATE;
|
||||||
|
SYCL_TRY("rad_event_elapsed_ms", {
|
||||||
|
if (!event_done(e->ev)) return RAD_E_STATE;
|
||||||
|
*t = e->ev.get_profiling_info<sycl::info::event_profiling::command_end>();
|
||||||
|
});
|
||||||
|
return RAD_OK;
|
||||||
|
};
|
||||||
|
uint64_t ta = 0, tb = 0;
|
||||||
|
RAD_TRY(stamp(a, &ta));
|
||||||
|
RAD_TRY(stamp(b, &tb));
|
||||||
|
*out = (float)(((double)tb - (double)ta) / 1e6);
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USM host memory is coherent for the device at submission: nothing to make visible. */
|
||||||
|
void d_host_wrote(void) {}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ copies and fills */
|
||||||
|
|
||||||
|
int d_memcpy_async(void* dst, const void* src, int64_t bytes, RadStream st) {
|
||||||
|
RAD_TRY(check_stream(st, "rad_memcpy_async"));
|
||||||
|
if (bytes == 0) return RAD_OK;
|
||||||
|
if (!dst || !src || bytes < 0) {
|
||||||
|
device_set_error("rad_memcpy_async(%p <- %p, %lld): invalid argument", dst, src,
|
||||||
|
(long long)bytes);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_memcpy_async", as_stream(st)->q.memcpy(dst, src, (size_t)bytes));
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_memcpy_2d_async(void* dst, int64_t dpitch, const void* src, int64_t spitch, int64_t width,
|
||||||
|
int64_t height, RadStream st) {
|
||||||
|
RAD_TRY(check_stream(st, "rad_memcpy_2d_async"));
|
||||||
|
if (width == 0 || height == 0) return RAD_OK;
|
||||||
|
if (!dst || !src || width < 0 || height < 0 || dpitch < width || spitch < width) {
|
||||||
|
device_set_error("rad_memcpy_2d_async(%p/%lld <- %p/%lld, %lld x %lld): invalid argument",
|
||||||
|
dst, (long long)dpitch, src, (long long)spitch, (long long)width,
|
||||||
|
(long long)height);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_memcpy_2d_async",
|
||||||
|
as_stream(st)->q.ext_oneapi_memcpy2d(dst, (size_t)dpitch, src, (size_t)spitch,
|
||||||
|
(size_t)width, (size_t)height));
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_memset_async(void* dst, int value, int64_t bytes, RadStream st) {
|
||||||
|
RAD_TRY(check_stream(st, "rad_memset_async"));
|
||||||
|
if (bytes == 0) return RAD_OK;
|
||||||
|
if (!dst || bytes < 0) {
|
||||||
|
device_set_error("rad_memset_async(%p, %lld): invalid argument", dst, (long long)bytes);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
/* The runtime fills pageable memory too; a card's contract does not (device.h note 1). */
|
||||||
|
if (ptr_kind(dst) == sycl::usm::alloc::unknown) {
|
||||||
|
device_set_error("rad_memset_async(%p): the destination is not device-accessible "
|
||||||
|
"(pageable host memory)", dst);
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
SYCL_TRY("rad_memset_async", as_stream(st)->q.memset(dst, value & 0xff, (size_t)bytes));
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The list is read here, at the call. The contract (device.h) requires it unchanged until the
|
||||||
|
* stream passes the copy, so reading it early copies the same bytes. */
|
||||||
|
int d_memcpy_ranges_async(void* dst, const void* src, int64_t prefix, const RadCopyRange* ranges,
|
||||||
|
int n, RadStream st) {
|
||||||
|
RAD_TRY(check_stream(st, "rad_memcpy_ranges_async"));
|
||||||
|
/* The card's copy kernel moves 16-byte pieces (aql.cpp), and the host backend refuses what it
|
||||||
|
* cannot copy; the same calls are refused here, so the three backends agree. */
|
||||||
|
if (!dst || !src || prefix < 0 || (prefix & 15) || n < 0 || (n > 0 && !ranges)) {
|
||||||
|
device_set_error("rad_memcpy_ranges_async(%p <- %p, prefix %lld (a multiple of 16), %d "
|
||||||
|
"ranges): invalid argument", dst, src, (long long)prefix, n);
|
||||||
|
return RAD_E_INVAL;
|
||||||
|
}
|
||||||
|
if (prefix == 0 && n == 0) return RAD_OK;
|
||||||
|
if (((uintptr_t)dst | (uintptr_t)src) & 15) {
|
||||||
|
device_set_error("rad_memcpy_ranges_async(%p <- %p): both bases must be 16-byte aligned",
|
||||||
|
dst, src);
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
sycl::queue& q = as_stream(st)->q;
|
||||||
|
char* d = (char*)dst;
|
||||||
|
const char* s = (const char*)src;
|
||||||
|
SYCL_TRY("rad_memcpy_ranges_async", {
|
||||||
|
if (prefix > 0) q.memcpy(d, s, (size_t)prefix);
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
if (ranges[i].bytes > 0)
|
||||||
|
q.memcpy(d + ranges[i].dst, s + ranges[i].src, (size_t)ranges[i].bytes);
|
||||||
|
});
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ gates
|
||||||
|
*
|
||||||
|
* A gate is a one-work-item kernel that spins until a flag in pinned host memory turns 1; the
|
||||||
|
* in-order queue holds everything behind it. rad_gate_open sets the flag. The flag's memory is
|
||||||
|
* freed only once the kernel has finished (reaped on later gate calls), since the kernel may still
|
||||||
|
* be reading it when the host opens. A gate held for seconds can trip the driver's job timeout;
|
||||||
|
* rad-kbench holds one for a batch. */
|
||||||
|
struct SyclGate {
|
||||||
|
uint32_t* flag = nullptr;
|
||||||
|
SyclStream* s = nullptr;
|
||||||
|
sycl::event spin;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::mutex g_gate_m;
|
||||||
|
std::vector<std::pair<sycl::event, uint32_t*>> g_gate_graveyard;
|
||||||
|
|
||||||
|
void gate_reap() {
|
||||||
|
std::lock_guard<std::mutex> lk(g_gate_m);
|
||||||
|
for (size_t i = 0; i < g_gate_graveyard.size();) {
|
||||||
|
bool done = true;
|
||||||
|
try {
|
||||||
|
done = event_done(g_gate_graveyard[i].first);
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
}
|
||||||
|
if (!done) { ++i; continue; }
|
||||||
|
d_free(g_gate_graveyard[i].second, RAD_MEM_HOST_PINNED);
|
||||||
|
g_gate_graveyard[i] = g_gate_graveyard.back();
|
||||||
|
g_gate_graveyard.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_stream_gate(RadStream st, void** out) {
|
||||||
|
RAD_TRY(check_stream(st, "rad_stream_gate"));
|
||||||
|
if (!out) return RAD_E_INVAL;
|
||||||
|
gate_reap();
|
||||||
|
SyclStream* s = as_stream(st);
|
||||||
|
auto* g = new (std::nothrow) SyclGate();
|
||||||
|
uint32_t* flag = (uint32_t*)d_alloc(64, RAD_MEM_HOST_PINNED);
|
||||||
|
if (!g || !flag) {
|
||||||
|
delete g;
|
||||||
|
if (flag) d_free(flag, RAD_MEM_HOST_PINNED);
|
||||||
|
device_set_error("rad_stream_gate: out of memory");
|
||||||
|
return RAD_E_NOMEM;
|
||||||
|
}
|
||||||
|
*flag = 0;
|
||||||
|
try {
|
||||||
|
g->spin = s->q.single_task([=] {
|
||||||
|
sycl::atomic_ref<uint32_t, sycl::memory_order::relaxed, sycl::memory_scope::system,
|
||||||
|
sycl::access::address_space::global_space> f(*flag);
|
||||||
|
while (f.load() == 0) {
|
||||||
|
}
|
||||||
|
sycl::atomic_fence(sycl::memory_order::acquire, sycl::memory_scope::system);
|
||||||
|
});
|
||||||
|
} catch (const sycl::exception& e) {
|
||||||
|
delete g;
|
||||||
|
d_free(flag, RAD_MEM_HOST_PINNED);
|
||||||
|
return sycl_fail(e, "rad_stream_gate");
|
||||||
|
}
|
||||||
|
g->flag = flag;
|
||||||
|
g->s = s;
|
||||||
|
++s->gates;
|
||||||
|
*out = g;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int d_gate_open(void* p) {
|
||||||
|
auto* g = (SyclGate*)p;
|
||||||
|
if (!g || !g->flag) return RAD_E_INVAL;
|
||||||
|
std::atomic_ref<uint32_t>(*g->flag).store(1, std::memory_order_release);
|
||||||
|
--g->s->gates;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(g_gate_m);
|
||||||
|
g_gate_graveyard.emplace_back(g->spin, g->flag);
|
||||||
|
}
|
||||||
|
delete g;
|
||||||
|
return RAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A Level Zero queue has no fixed depth, so nothing behind a gate waits for room; the figure only
|
||||||
|
* bounds how far a caller runs ahead. */
|
||||||
|
int64_t d_gate_room(RadStream st) { return st ? 4096 : 0; }
|
||||||
|
|
||||||
|
const DeviceBackend g_sycl = {
|
||||||
|
.name = "sycl",
|
||||||
|
.count = d_count, .set = d_set, .props = d_props, .enable_peer = d_enable_peer,
|
||||||
|
.alloc = d_alloc, .free = d_free, .host_ptr = d_host_ptr, .device_ptr = d_device_ptr,
|
||||||
|
.stream_create = d_stream_create, .stream_destroy = d_stream_destroy,
|
||||||
|
.stream_sync = d_stream_sync,
|
||||||
|
.event_create = d_event_create, .event_destroy = d_event_destroy,
|
||||||
|
.event_record = d_event_record, .event_wait = d_event_wait, .event_query = d_event_query,
|
||||||
|
.event_sync = d_event_sync, .event_elapsed_ms = d_event_elapsed_ms,
|
||||||
|
.host_wrote = d_host_wrote,
|
||||||
|
.memcpy_async = d_memcpy_async, .memcpy_2d_async = d_memcpy_2d_async,
|
||||||
|
.memset_async = d_memset_async, .memcpy_ranges_async = d_memcpy_ranges_async,
|
||||||
|
/* memcpy_list_async, link_hold, link_gate: null (dispatch.cpp copies segment by segment and
|
||||||
|
* holds nothing). Recorded passes, elastic memory: null. */
|
||||||
|
.vram_used = d_vram_used,
|
||||||
|
/* code_mark / code_runs: null for now, so every plugin runs; a build with libr4d beside the
|
||||||
|
* SYCL backend is refused at configure (docs/SYCL_PORTING.md §4.5). */
|
||||||
|
.integrated = d_integrated,
|
||||||
|
.peer_access = d_peer_access,
|
||||||
|
.pci_address = d_pci_address,
|
||||||
|
.runtime_version = d_runtime_version,
|
||||||
|
/* Expert prefetch: null. */
|
||||||
|
.stream_gate = d_stream_gate, .gate_open = d_gate_open, .gate_room = d_gate_room,
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace */
|
||||||
|
|
||||||
|
extern const SyclHost* g_sycl_host; /* sycl_host.cpp */
|
||||||
|
|
||||||
|
} /* namespace rad */
|
||||||
|
|
||||||
|
extern "C" __attribute__((visibility("default")))
|
||||||
|
const rad::DeviceBackend* rad_sycl_backend(const rad::SyclHost* host) {
|
||||||
|
if (!host || host->version != rad::kSyclHostVersion) {
|
||||||
|
std::fprintf(stderr, "librad_sycl: the engine's host table is version %u, this library "
|
||||||
|
"reads %u; rebuild them together\n",
|
||||||
|
host ? host->version : 0u, rad::kSyclHostVersion);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
rad::g_sycl_host = host;
|
||||||
|
if (rad::rt().devs.empty()) {
|
||||||
|
/* Supported configuration (host backend); dispatch.cpp logs it at Info. */
|
||||||
|
RAD_DEBUG("device: no Level Zero GPU visible to SYCL");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return &rad::g_sycl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* SYCL_LANGUAGE_VERSION */
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* sycl_host.cpp -- inside librad_sycl.so: the engine's logger and error slot, over the table the
|
||||||
|
* engine hands rad_sycl_backend() (sycl_host.h). Built by the icpx sub-build; in the engine's own
|
||||||
|
* build (core/CMakeLists.txt globs this directory) it compiles to nothing. */
|
||||||
|
#if defined(SYCL_LANGUAGE_VERSION)
|
||||||
|
|
||||||
|
#include "sycl_host.h"
|
||||||
|
#include "../rad_internal.h"
|
||||||
|
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
namespace rad {
|
||||||
|
|
||||||
|
const SyclHost* g_sycl_host = nullptr;
|
||||||
|
|
||||||
|
Log log_level() {
|
||||||
|
return g_sycl_host ? (Log)g_sycl_host->log_level() : Log::Warn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_emit(Log l, const char* file, int line, const char* fmt, ...) {
|
||||||
|
char buf[2048];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (g_sycl_host) g_sycl_host->log((int)l, file, line, buf);
|
||||||
|
else std::fprintf(stderr, "%s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void device_set_error(const char* fmt, ...) {
|
||||||
|
char buf[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (g_sycl_host) g_sycl_host->set_error(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace rad */
|
||||||
|
|
||||||
|
#endif /* SYCL_LANGUAGE_VERSION */
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* sycl_host.h -- the seam between the engine and librad_sycl.so, the SYCL device backend.
|
||||||
|
*
|
||||||
|
* The SYCL backend is compiled and linked by icpx into a shared library of its own, while the
|
||||||
|
* engine stays a GCC build (docs/SYCL_PORTING.md §4.5, docs/SYCL_PROGRESS.md D6). The library
|
||||||
|
* reaches the engine's logger and error slot through this table, so it links nothing of the
|
||||||
|
* engine's, and the engine reaches the library through one C entry point.
|
||||||
|
*
|
||||||
|
* Inside the library, sycl_host.cpp defines rad::log_level, rad::log_emit and
|
||||||
|
* rad::device_set_error over the table, so the backend's source uses rad_internal.h's macros as
|
||||||
|
* hip.cpp does. Bump kSyclHostVersion on any change to the table.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace rad {
|
||||||
|
|
||||||
|
struct DeviceBackend;
|
||||||
|
|
||||||
|
constexpr uint32_t kSyclHostVersion = 1;
|
||||||
|
|
||||||
|
struct SyclHost {
|
||||||
|
uint32_t version; /* kSyclHostVersion */
|
||||||
|
int (*log_level)(void); /* rad::log_level() as an int */
|
||||||
|
void (*log)(int level, const char* file, int line, const char* msg);
|
||||||
|
void (*set_error)(const char* msg); /* rad::device_set_error("%s", msg) */
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace rad */
|
||||||
|
|
||||||
|
/* The backend, or null when no Level Zero GPU is visible or `host` is of another version. The
|
||||||
|
* table must outlive the backend. */
|
||||||
|
extern "C" const rad::DeviceBackend* rad_sycl_backend(const rad::SyclHost* host);
|
||||||
+24
-1
@@ -1225,6 +1225,7 @@ int Engine::declare() {
|
|||||||
{
|
{
|
||||||
std::vector<MissReport> rep;
|
std::vector<MissReport> rep;
|
||||||
for (auto& r : ranks_) rep.push_back(miss_report(r->program, device_is_host()));
|
for (auto& r : ranks_) rep.push_back(miss_report(r->program, device_is_host()));
|
||||||
|
const bool sycl = std::strcmp(device_backend_name(), "sycl") == 0;
|
||||||
bool same = true;
|
bool same = true;
|
||||||
for (size_t i = 1; i < rep.size(); ++i) if (!(rep[i] == rep[0])) same = false;
|
for (size_t i = 1; i < rep.size(); ++i) if (!(rep[i] == rep[0])) same = false;
|
||||||
|
|
||||||
@@ -1237,9 +1238,23 @@ int Engine::declare() {
|
|||||||
"one of them cannot run:", who.c_str(), rep[i].device.size());
|
"one of them cannot run:", who.c_str(), rep[i].device.size());
|
||||||
for (const std::string& l : rep[i].device) RAD_ERR(" %s", l.c_str());
|
for (const std::string& l : rep[i].device) RAD_ERR(" %s", l.c_str());
|
||||||
}
|
}
|
||||||
if (!rep[i].host_only.empty()) RAD_INFO("%s", rep[i].host_only.c_str());
|
if (!rep[i].host_only.empty()) {
|
||||||
|
if (sycl) RAD_ERR("%s", rep[i].host_only.c_str());
|
||||||
|
else RAD_INFO("%s", rep[i].host_only.c_str());
|
||||||
|
}
|
||||||
if (!rep[i].host.empty()) RAD_INFO("%s", rep[i].host.c_str());
|
if (!rep[i].host.empty()) RAD_INFO("%s", rep[i].host.c_str());
|
||||||
}
|
}
|
||||||
|
/* On the SYCL backend a host-only op is a hole, not a placement: the Intel backend runs
|
||||||
|
* its ops on the card or not at all, so a kernel it lacks stops the start by name rather
|
||||||
|
* than running that op on the CPU (docs/SYCL_PORTING.md §4.4). --debug-graph serves
|
||||||
|
* nothing and prints the graph regardless. */
|
||||||
|
if (sycl && !cfg_.debug_graph)
|
||||||
|
for (const MissReport& m : rep)
|
||||||
|
if (!m.host_only.empty()) {
|
||||||
|
RAD_ERR("not starting: on the SYCL backend every op runs on the card, and the "
|
||||||
|
"op(s) above have no device kernel in the loaded libraries");
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
/* A hole refuses startup: the bands come from this run's limits, so a request can land in
|
/* A hole refuses startup: the bands come from this run's limits, so a request can land in
|
||||||
* one, and that step would fail at issue and stop the engine. --debug-graph serves nothing,
|
* one, and that step would fail at issue and stop the engine. --debug-graph serves nothing,
|
||||||
* so it continues to print the graph and reports the holes in its exit status
|
* so it continues to print the graph and reports the holes in its exit status
|
||||||
@@ -3306,6 +3321,14 @@ int Engine::start() {
|
|||||||
devnote_ = devnote;
|
devnote_ = devnote;
|
||||||
if (s < 0) { RAD_ERR("no usable device"); return s; }
|
if (s < 0) { RAD_ERR("no usable device"); return s; }
|
||||||
|
|
||||||
|
/* One card on the SYCL backend (docs/SYCL_PORTING.md §4.7): it has no all-reduce kernels, and a
|
||||||
|
* second rank would wait on one. */
|
||||||
|
if (cfg_.tp > 1 && std::strcmp(device_backend_name(), "sycl") == 0) {
|
||||||
|
RAD_ERR("--tp %d: the SYCL (Intel GPU) backend serves one card; tensor parallelism needs "
|
||||||
|
"all-reduce kernels it does not have. Use --tp 1", cfg_.tp);
|
||||||
|
return RAD_E_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
if ((int)devs.size() < cfg_.tp) {
|
if ((int)devs.size() < cfg_.tp) {
|
||||||
RAD_ERR("--tp %d needs %d devices of one architecture; %zu are usable [%s]",
|
RAD_ERR("--tp %d needs %d devices of one architecture; %zu are usable [%s]",
|
||||||
cfg_.tp, cfg_.tp, devs.size(), inventory.c_str());
|
cfg_.tp, cfg_.tp, devs.size(), inventory.c_str());
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ int wtab_patch(const WtabPatch& p, RadStream s) {
|
|||||||
for (uint32_t i = 0; i < p.n; ++i) *p.dst[i] = p.val[i];
|
for (uint32_t i = 0; i < p.n; ++i) *p.dst[i] = p.val[i];
|
||||||
return RAD_OK;
|
return RAD_OK;
|
||||||
}
|
}
|
||||||
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
|
#if (defined(RAD_HAVE_HIP) && RAD_HAVE_HIP) || (defined(RAD_HAVE_SYCL) && RAD_HAVE_SYCL)
|
||||||
|
/* The launcher: wtab.hip on the AQL backend, wtab_sycl.cpp (in librad_sycl.so) on the SYCL
|
||||||
|
* one. A build holds one of the two. */
|
||||||
return rad_wtab_patch_launch(&p, (void*)s) == 0 ? RAD_OK : RAD_E_DEVICE;
|
return rad_wtab_patch_launch(&p, (void*)s) == 0 ? RAD_OK : RAD_E_DEVICE;
|
||||||
#else
|
#else
|
||||||
(void)s;
|
(void)s;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* wtab_sycl.cpp -- the weight-table patch kernel under the SYCL backend: one work-item a write. See
|
||||||
|
* wtab.h; wtab.hip is the AMD twin. Built by icpx into librad_sycl.so; in the engine's own build
|
||||||
|
* (core/CMakeLists.txt globs this directory) it compiles to nothing. */
|
||||||
|
#if defined(SYCL_LANGUAGE_VERSION)
|
||||||
|
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
|
||||||
|
#include "rad_sycl.h"
|
||||||
|
#include "wtab.h"
|
||||||
|
|
||||||
|
extern "C" __attribute__((visibility("default")))
|
||||||
|
int rad_wtab_patch_launch(const rad::WtabPatch* p, void* stream) {
|
||||||
|
if (!p || p->n == 0) return 0;
|
||||||
|
sycl::queue* q = rad_sycl_queue((RadStream)stream);
|
||||||
|
if (!q) return -1;
|
||||||
|
const rad::WtabPatch w = *p;
|
||||||
|
try {
|
||||||
|
q->parallel_for(sycl::nd_range<1>{64, 64}, [=](sycl::nd_item<1> it) {
|
||||||
|
const uint32_t i = (uint32_t)it.get_local_id(0);
|
||||||
|
if (i < w.n) *w.dst[i] = w.val[i];
|
||||||
|
});
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* SYCL_LANGUAGE_VERSION */
|
||||||
@@ -15,7 +15,9 @@ int step_advance(const AdvanceArgs& a, RadStream s) {
|
|||||||
for (int i = 0; i < a.n_seq; ++i) adv_row(a, i);
|
for (int i = 0; i < a.n_seq; ++i) adv_row(a, i);
|
||||||
return RAD_OK;
|
return RAD_OK;
|
||||||
}
|
}
|
||||||
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
|
#if (defined(RAD_HAVE_HIP) && RAD_HAVE_HIP) || (defined(RAD_HAVE_SYCL) && RAD_HAVE_SYCL)
|
||||||
|
/* The launcher: advance.hip on the AQL backend, advance_sycl.cpp (in librad_sycl.so) on the
|
||||||
|
* SYCL one. A build holds one of the two. */
|
||||||
return rad_step_advance_launch(&a, (void*)s) == 0 ? RAD_OK : RAD_E_DEVICE;
|
return rad_step_advance_launch(&a, (void*)s) == 0 ? RAD_OK : RAD_E_DEVICE;
|
||||||
#else
|
#else
|
||||||
(void)s;
|
(void)s;
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* advance_sycl.cpp -- the advance kernel under the SYCL backend: one work-item per row of the batch
|
||||||
|
* it patches, in stream order on the rank's queue. See advance.h; advance.hip is the AMD twin.
|
||||||
|
*
|
||||||
|
* Built by icpx into librad_sycl.so (sycl/CMakeLists.txt); core/CMakeLists.txt globs this directory
|
||||||
|
* into the engine, built without SYCL, where the file compiles to nothing. There is no chained form:
|
||||||
|
* chained launches are the AQL backend's (rad_dev_chain_enabled is 0 here).
|
||||||
|
*/
|
||||||
|
#if defined(SYCL_LANGUAGE_VERSION)
|
||||||
|
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
|
||||||
|
#include "advance_impl.h"
|
||||||
|
#include "rad_sycl.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr int kThreads = 64;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
extern "C" __attribute__((visibility("default")))
|
||||||
|
int rad_step_advance_launch(const rad::AdvanceArgs* args, void* stream) {
|
||||||
|
if (!args || args->n_seq <= 0) return 0;
|
||||||
|
sycl::queue* q = rad_sycl_queue((RadStream)stream);
|
||||||
|
if (!q) return -1;
|
||||||
|
const rad::AdvanceArgs a = *args;
|
||||||
|
const size_t blocks = (size_t)((a.n_seq + kThreads - 1) / kThreads);
|
||||||
|
try {
|
||||||
|
q->parallel_for(sycl::nd_range<1>{blocks * kThreads, kThreads}, [=](sycl::nd_item<1> it) {
|
||||||
|
const int i = (int)it.get_global_id(0);
|
||||||
|
if (i < a.n_seq) rad::adv_row(a, i);
|
||||||
|
});
|
||||||
|
} catch (const sycl::exception&) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* SYCL_LANGUAGE_VERSION */
|
||||||
@@ -0,0 +1,551 @@
|
|||||||
|
# Porting radiance to Intel GPUs (SYCL / Level Zero)
|
||||||
|
|
||||||
|
What the core depends on, what the Intel backend has to provide, and the design. The running log
|
||||||
|
(status, blockers, commands, benchmark runs) is `docs/SYCL_PROGRESS.md`. Written against the tree at
|
||||||
|
`87ec3c1` (radiance 1.11.0, `RAD_ABI_VERSION` 26).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Where the core depends on HIP
|
||||||
|
|
||||||
|
Reproduce the raw list with:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
grep -rn -E '\bhip[A-Z][A-Za-z]*\b|hip/hip_|__HIP|RAD_HAVE_HIP|RAD_HIP_FOUND|__global__|__device__|<<<' \
|
||||||
|
--include=*.cpp --include=*.h --include=*.hip --include=*.cc --include=*.c \
|
||||||
|
--include=CMakeLists.txt --include=*.cmake . | grep -v -E '^\./(vendor|libr4d|build|tests/r4d_emu)/'
|
||||||
|
```
|
||||||
|
|
||||||
|
288 lines outside `libr4d/` and `vendor/`; 47 of them are comments that only name a HIP call. The
|
||||||
|
substance, classified:
|
||||||
|
|
||||||
|
### 1.1 Already behind the device ABI (`abi/rad_device.h` + the `DeviceBackend` vtable)
|
||||||
|
|
||||||
|
The device layer is a vtable (`core/device/device.h:178`, `struct DeviceBackend`), chosen once in
|
||||||
|
`select_backend()` (`core/device/dispatch.cpp:87`). Every `rad_dev_*` / `rad_stream_*` /
|
||||||
|
`rad_event_*` / `rad_memcpy*` call above the device layer goes through it. Today it has three
|
||||||
|
implementations:
|
||||||
|
|
||||||
|
| backend | file | runtime calls |
|
||||||
|
|---|---|---|
|
||||||
|
| host | `core/device/host.cpp` | none (worker threads, `malloc`) |
|
||||||
|
| HIP | `core/device/hip.cpp` | `hipMalloc`, `hipFree`, `hipSetDevice`, `hipGetDevice(Count)`, `hipGetDeviceProperties`, `hipDeviceGetAttribute`, `hipMemGetInfo`, `hipDeviceGetPCIBusId`, `hipDeviceCanAccessPeer`, `hipDeviceEnablePeerAccess`, `hipPointerGetAttributes`, `hipHostGetDevicePointer`, `hipRuntimeGetVersion` |
|
||||||
|
| AQL (the one a card actually runs) | `core/device/aql.cpp`, `aql_code.cpp`, `aql_blit.hip` | HIP for allocation, properties, peer access, IPC, code registration; HSA for everything on the queues: `hsa_queue_*`, `hsa_signal_*`, `hsa_amd_memory_pool_*`, `hsa_amd_vmem_*` (elastic memory), `hsa_executable_*` / `hsa_code_object_reader_*` (it loads plugins' code objects itself), `hsa_amd_profiling_*`, `hsa_amd_memory_lock_to_pool` (pinning) |
|
||||||
|
|
||||||
|
What the AQL backend implements that matters for a port (from `aql.cpp`'s header and
|
||||||
|
`device.h`):
|
||||||
|
|
||||||
|
- **Streams** are HSA queues the engine owns; every kernel, copy, fill and fence is an AQL packet it
|
||||||
|
writes (6 ns per dispatch versus 0.5-1.3 us through `hipLaunchKernel`, ~1600 dispatches per rank
|
||||||
|
per decode step).
|
||||||
|
- **Kernel-argument staging**: a ring of 1 KiB slots written by the host, in VRAM through the BAR
|
||||||
|
when the BAR spans VRAM, in pinned host memory otherwise (`aql_force_host_kargs`, `device.h:476`),
|
||||||
|
with a system-scope acquire at least once per half lap.
|
||||||
|
- **Resizable BAR handling** is exactly that placement choice. Nothing else in the core reads the
|
||||||
|
BAR size.
|
||||||
|
- **Events**: barrier packets with agent-scope (`RAD_EVENT_LOCAL`) or system-scope release;
|
||||||
|
`RAD_EVENT_HOST_WAIT` adds an interrupt signal.
|
||||||
|
- **Graphs**: "tapes" (`DeviceBackend::tape_*`, `device.h:227`) record a pass's packets and replay
|
||||||
|
them. They are optional; null means every pass is issued.
|
||||||
|
- **Elastic memory** (`vmem_*`, `device.h:271`) shares VRAM between KV and experts. Optional; null
|
||||||
|
sizes pools once at startup.
|
||||||
|
- **Pinned memory**: `RAD_MEM_HOST_PINNED` / `RAD_MEM_HOST_MAPPED`; the host arena locks file
|
||||||
|
mappings to the pool (`hsa_amd_memory_lock_to_pool`).
|
||||||
|
- **P2P / IPC**: `enable_peer`, `peer_access`; IPC lives in libr4d's collectives, not the core.
|
||||||
|
- **DMA lane, link holds, rides, gates, expert prefetch** (`memcpy_list_async`, `link_hold`,
|
||||||
|
`xp_*`, `stream_gate`): all optional, null on a backend without them.
|
||||||
|
|
||||||
|
### 1.2 The core calls HIP directly
|
||||||
|
|
||||||
|
These are the places a second device backend has to touch. None is a HIP call from generic engine
|
||||||
|
code: each is a device-code launcher or a build switch.
|
||||||
|
|
||||||
|
| site | what | classification / what the Intel backend needs |
|
||||||
|
|---|---|---|
|
||||||
|
| `core/sched/advance.cpp:18` + `core/sched/advance.hip` | the per-step advance kernel (one thread per batch row), launched through `hipLaunchKernel` | **core device kernel**, every decode step. The row logic is shared host/device code in `core/sched/advance_impl.h` (`RAD_ADV_FN`, `:10`, is `__host__ __device__` under `__HIPCC__`). Needs a SYCL launcher calling the same `adv_row` |
|
||||||
|
| `core/runtime/wtab.cpp:18` + `core/runtime/wtab.hip` | the weight-table patch kernel (one thread per pointer write) | **core device kernel**; needs a SYCL launcher (19 lines of HIP) |
|
||||||
|
| `core/runtime/xprefetch.cpp:11` + `core/runtime/xprefetch.hip` | MoE expert prefetch (router logits, plan) | **core device kernel**, MoE only. Gated by `rad_xp_supported`; the Intel backend reports 0 and the prefetch is off (supported configuration) |
|
||||||
|
| `core/device/aql_blit.hip` | copy / fill kernels behind the AQL backend's memcpy / memset | AQL-only; SYCL has `queue::memcpy` / `memset` / `fill` |
|
||||||
|
| `core/CMakeLists.txt:73` | the engine exports `hipLaunchKernel`, `hipMemcpyAsync`, ..., `__hipRegisterFatBinary` so plugins' HIP launches bind to the AQL backend | **the plugin launch contract**: a plugin launches device work with HIP calls the engine serves (`abi/rad_types.h:325`, `docs/PLUGIN.md` §5). A SYCL plugin needs its own hand-off (§4.2 below) |
|
||||||
|
| `core/device/dispatch.cpp:60, 88`; `core/device/device.h:465` | backend selection and AQL-only hooks under `RAD_HAVE_HIP` | selection gains a SYCL branch |
|
||||||
|
| `core/engine_diag.cpp:60` | `device_build` fact for the startup report | becomes "HIP or SYCL" |
|
||||||
|
| `abi/rad_philox.h:16`, `abi/rad_yarn.h:16`, `core/sched/advance_impl.h:10` | `__host__ __device__` qualifiers under `__HIPCC__` | header-only device code; under SYCL device compilation the qualifier is empty (SYCL device code is plain C++), so these need an `#elif defined(SYCL_LANGUAGE_VERSION)` that defines the macro to `inline` |
|
||||||
|
| `CMakeLists.txt:17-77, 132-156, 229-236, 297` | `RAD_WITH_HIP`, `RAD_HIP_FOUND`, `RAD_GPU_TARGETS`, `enable_language(HIP)`, `RAD_HAVE_HIP` on `rad_abi`, `add_subdirectory(libr4d)` | build integration; `RAD_SYCL` mirrors it |
|
||||||
|
| `cmake/RadAddPlugin.cmake:68-121` | `HIP_SOURCES`, `rad_hipify`, per-source `-cuid` | gains `SYCL_SOURCES` |
|
||||||
|
| `tests/CMakeLists.txt:236, 313, 328, 342, 523, 551, 579`; `tests/plugin_test.cpp:93`; `tests/host_kargs_main.h:21` | card tests (`device_test`, `mem_test`, `place_test`, `runtime_test` on a card, `r4d_selftest`, `kbench` gpu label, ops_doc and oot over libr4d) | the `sycl` label and its tests |
|
||||||
|
| `tools/vmemprobe.cpp` | a HIP diagnostic tool | AMD-only; not ported |
|
||||||
|
|
||||||
|
Comments only (no code dependency): `core/engine_bringup.cpp:3656`, `core/mem/pools.cpp:221`,
|
||||||
|
`core/format/radfile.h:82`, `core/runtime/ctx.h:12`, `core/device/host.cpp:267, 445, 496`,
|
||||||
|
`libavx/avx_ngram.cpp:8`, `abi/rad_types.h:327`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. How the host backend avoids HIP (the template)
|
||||||
|
|
||||||
|
- `select_backend()` returns `host_backend()` when the build has no HIP
|
||||||
|
(`core/device/dispatch.cpp:100`). `RadDeviceProps::is_host_backend = 1`, arch `"host"`.
|
||||||
|
- **Streams** are queues run by worker threads; **device memory** is host memory; events are
|
||||||
|
counters (`core/device/host.cpp`).
|
||||||
|
- **Kernels**: libref and libavx declare `RAD_DOMAIN_HOST` rows and are plain shared objects built by
|
||||||
|
`rad_add_plugin` with `SOURCES` only. They ignore the `RadStream` they are handed
|
||||||
|
(`abi/rad_types.h:330`).
|
||||||
|
- **Core device kernels** branch on `device_is_host()` *before* the `RAD_HAVE_HIP` branch: drain the
|
||||||
|
stream, then run the shared row function on the host (`core/sched/advance.cpp:13`,
|
||||||
|
`core/runtime/wtab.cpp`). Without HIP the device branch returns `RAD_E_UNSUPPORTED`.
|
||||||
|
- **Optional features** (tapes, vmem, DMA lane, prefetch, gates) are null, which the engine treats as
|
||||||
|
a supported configuration.
|
||||||
|
- **Build**: `RAD_WITH_HIP=OFF` (or AUTO without `hipcc`) leaves `RAD_HIP_FOUND` off; libr4d is not
|
||||||
|
added, `RAD_HAVE_HIP` is not defined, the HIP-only tests are not registered.
|
||||||
|
|
||||||
|
A SYCL backend follows the same shape: a fourth `DeviceBackend`, a third branch in the core
|
||||||
|
kernels' launchers, its own kernel library, its optional features null until measured worth it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. The op vocabulary
|
||||||
|
|
||||||
|
`docs/OPS.md` documents 238 ops: **205 that libref implements** (the oracle for `rad-kbench` and for
|
||||||
|
the Intel kernels' tests) and **33 device-only** ops that only libr4d declares (no host fallback and
|
||||||
|
no oracle; libr4d's own `r4d_selftest` patterns are their checks). Appendix A is the full table,
|
||||||
|
generated by `scripts/sycl/op_inventory.sh` (libref's schemas through `rad-schemas`; libr4d's 407
|
||||||
|
`kKernels` rows parsed from `libr4d/r4d_rows.cpp` by `scripts/sycl/r4d_rows.py`, since a build
|
||||||
|
without HIP has no `libr4d.so`; the architectures column is a grep of `arch/` and over-counts).
|
||||||
|
|
||||||
|
How libr4d implements the ops a dense LLM needs (from the rows' prose and `libr4d/README.md`):
|
||||||
|
|
||||||
|
- **GEMM**: one geometry per entry point. bf16 (`gemm_bf16_nt_m16`/`m64` skinny with split-K and
|
||||||
|
16x16x16 WMMA, `gemm_bf16_nt_tiled` for M > 64), each quantised format its own family
|
||||||
|
(`gemm_fp8a8_*`, `gemm_w4a8_*`, `gemm_mxfp4a8_*`, `gemm_i8a8_*`, ...), a skinny decode kernel
|
||||||
|
(M <= 16..128) and a tiled prefill kernel per format; weights pre-permuted into WMMA fragment
|
||||||
|
order by a `relayout` hook at load. Deterministic reductions: the split-K slices are summed in a
|
||||||
|
fixed order, and "BYTE-IDENTICAL" siblings are stated in the rows.
|
||||||
|
- **Attention**: paged (block 16) prefill and split-KV decode, one instantiation per
|
||||||
|
(head_dim, gqa, kv dtype): `attn_decode_h128_gqa{1,2,4,8}_{bf16,fp8}kv`,
|
||||||
|
`attn_window_h<HD>_gqa<G>_<kv>` templates, fp8 KV with per-(seq, head) descales.
|
||||||
|
- **Norms and elementwise**: one workgroup a row (`rmsnorm_quant_fp8` "two passes, the second L1-hot"),
|
||||||
|
fused quantisers (`gated_quant_fp8`, `quant_act_fp8`) writing E4M3 with an f32 scale per
|
||||||
|
(row, 128 columns).
|
||||||
|
- **Vocabulary edge**: `logits_gemm_{bf16,fp8,i8}` writing f32 logits, `embed_lookup_bf16`.
|
||||||
|
- **Sampling**: f32 stages (`r4d_sample_stages_f32.hip`), `sample_argmax_f32`.
|
||||||
|
|
||||||
|
### 3.1 The minimal set: MiniCPM5-2B
|
||||||
|
|
||||||
|
No MiniCPM5 container is in the model library (`SYCL_PROGRESS.md`, blocker 1), so the set below was
|
||||||
|
measured on the test suite's synthetic llama (`tests/tiny_model.h`, the same `llama_dense_fp8`
|
||||||
|
graph: `rad-convert` with no recipe for bf16, the e2e test's `llama.recipe` for the block-fp8 trunk)
|
||||||
|
with `radiance --model <tiny>.rad --debug-graph` on the host backend. The geometry differs (the tiny
|
||||||
|
model is head_dim 64, gqa 2, n_embd 128; MiniCPM5 is head_dim 128, 16 q over 2 kv heads = gqa 8,
|
||||||
|
n_embd 2048, ffn 6144, vocab 130560), the op list does not.
|
||||||
|
|
||||||
|
**MiniCPM5-2B bf16: 13 model ops.** (`docs/PLUGIN.md` §10 also says 13.)
|
||||||
|
|
||||||
|
| op | params as declared | count per layer / model | dtype |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `embed_lookup` | n_embd, n_vocab | 1 / model | bf16 table |
|
||||||
|
| `rmsnorm_quant_fp8` | n, eps, group=128 | 2 / layer | bf16 in; writes bf16 `h` plus E4M3 `h.q` and f32 scale `h.s` |
|
||||||
|
| `gemm_nt` | N, K | 4 / layer (qkv, o, gate_up, down) | bf16 |
|
||||||
|
| `rope` | head_dim, n_head, n_head_kv, theta, mode=neox, rotary_dim | 1 / layer | bf16 |
|
||||||
|
| `cast` | n, from=bf16, to=bf16 | 1 / layer | copy-out of q |
|
||||||
|
| `kv_store` | head_dim, n_head_kv, block_size=16 | 1 / layer | bf16 KV, or `fp8_e4m3` at `--kv-cache-dtype fp8` |
|
||||||
|
| `attn_paged` | head_dim, gqa, causal=1, window=0, block_size=16 | 1 / layer | q bf16; kv bf16 or `fp8_e4m3` |
|
||||||
|
| `quant_act_fp8` | n, group=128 | 1 / layer | bf16 -> E4M3 + f32 scale |
|
||||||
|
| `gated_quant_fp8` | n, group=128, act=silu | 1 / layer | SwiGLU, bf16 out plus E4M3 |
|
||||||
|
| `add` | n | residual | bf16 |
|
||||||
|
| `rmsnorm` | n, eps | final norm | bf16 |
|
||||||
|
| `gather_rows` | | last-token rows for the head | |
|
||||||
|
| `logits_gemm` | n_vocab, n_embd | 1 / model | bf16 head, **f32 logits** |
|
||||||
|
|
||||||
|
**Sampler: 13 ops** (`docs/PLUGIN.md` says 11; the measured list is): `sample_penalties`,
|
||||||
|
`sample_dry`, `sample_ngram_ban`, `sample_temp`, `sample_mask`, `sample_topk`, `sample_argmax`,
|
||||||
|
`sample_topp`, `sample_minp`, `sample_typical`, `sample_xtc`, `sample_pick`, `sample_logprobs`.
|
||||||
|
Greedy decoding uses `sample_argmax`; the token-for-token comparison in Milestone A runs greedy.
|
||||||
|
|
||||||
|
**MiniCPM5-2B fp8** (block-fp8 trunk, 128x128 scales): `gemm_nt` becomes `gemm_nt_q` at
|
||||||
|
`dtype=fp8a8 group=128`, plus **`gemm_nt_q_gated`** (gate_up GEMM with the SiLU-gate fused,
|
||||||
|
`act=silu`) as the alternative the fp8 path declares. Everything else is the same list. With an fp8
|
||||||
|
or int8 lm_head (`llama_fp8head`, `llama_i8head`), `logits_gemm` stays one op and selects the kernel
|
||||||
|
by the head's encoding.
|
||||||
|
|
||||||
|
**The 4-bit paths**, measured the same way on the tiny llama: int4 (compressed-tensors, asymmetric)
|
||||||
|
issues `gemm_nt_q` at `w4a16_asym` and `w4a8i8_asym` plus `quant_act_i8g`; MXFP4 issues `gemm_nt_q`
|
||||||
|
at `mxfp4a8 group=32`. The real 27B / 31B containers add their architectures' own ops (gated delta
|
||||||
|
net for qwen35, Gemma's norms and soft-caps); those are listed when a container is available.
|
||||||
|
|
||||||
|
**Speculative decoding** (DSpark, 5 layers, block 7) adds the draft block's ops: fp8a8 GEMMs at
|
||||||
|
128x128 blocks and the `u2` 2-bit draft head; to be measured on a container that carries a drafter.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Design
|
||||||
|
|
||||||
|
The brief's default design, with what the code showed. Each decision is also in
|
||||||
|
`SYCL_PROGRESS.md` under Decisions.
|
||||||
|
|
||||||
|
### 4.1 Device runtime: a fourth `DeviceBackend`, not a new abstraction
|
||||||
|
|
||||||
|
The brief proposes a device-runtime interface if the core calls HIP directly. It does not: the
|
||||||
|
`DeviceBackend` vtable already *is* that interface (§1.1), with every call the brief lists
|
||||||
|
(allocate/free device and pinned memory, copies, streams, events, device info), and the HIP/AQL
|
||||||
|
implementations are already behind it. So no wrapper is introduced and the HIP path is not touched.
|
||||||
|
|
||||||
|
`core/device/sycl.cpp`, compiled only when `RAD_SYCL=ON`, defines `sycl_backend_if_present()`:
|
||||||
|
|
||||||
|
| 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` 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) |
|
||||||
|
| 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)
|
||||||
|
chooses explicitly in a build with both.
|
||||||
|
|
||||||
|
### 4.2 Plugin launches: a SYCL stream contract
|
||||||
|
|
||||||
|
On a card the engine serves plugins' `hipLaunchKernel`. SYCL has no launch symbol to interpose, so
|
||||||
|
a SYCL kernel library needs the queue itself. Under the SYCL backend a `RadStream` points to
|
||||||
|
|
||||||
|
```c
|
||||||
|
/* abi/rad_sycl.h (new, C-compatible) */
|
||||||
|
#define RAD_SYCL_STREAM_MAGIC 0x4C435953u /* "SYCL" */
|
||||||
|
typedef struct RadSyclStream {
|
||||||
|
uint32_t magic; /* RAD_SYCL_STREAM_MAGIC */
|
||||||
|
uint32_t version; /* RAD_SYCL_STREAM_VERSION, bumped on any change of this struct */
|
||||||
|
void* queue; /* sycl::queue*, in-order, owned by the engine */
|
||||||
|
} RadSyclStream;
|
||||||
|
```
|
||||||
|
|
||||||
|
with an inline C++ helper `rad_sycl_queue(RadStream)` that checks the magic and version and returns
|
||||||
|
the `sycl::queue&` (or null, which the launch turns into `RAD_E_DEVICE`). The engine and every SYCL
|
||||||
|
plugin load the same `libsycl.so`, so the object is valid across the boundary.
|
||||||
|
|
||||||
|
Why a new header with its own version rather than a bump of `RAD_ABI_VERSION`: nothing an existing
|
||||||
|
plugin compiles against changes shape (`rad_types.h` keeps `typedef void* RadStream`; only its
|
||||||
|
comment gains the SYCL case), so a bump would force every out-of-tree plugin to rebuild for no
|
||||||
|
reason. A SYCL plugin checks `version` at each launch's first call and refuses by name on a
|
||||||
|
mismatch, which is the same guarantee for the only plugins that read the struct.
|
||||||
|
|
||||||
|
What a SYCL launch may do mirrors `docs/PLUGIN.md` §5: submit to that queue only; no `wait`, no
|
||||||
|
allocation (scratch from the `scratch` hook), no host tasks.
|
||||||
|
|
||||||
|
### 4.3 The kernel library: `libxe2/`
|
||||||
|
|
||||||
|
Built by `rad_add_plugin(libxe2 kernels SYCL_SOURCES ...)`, AOT for `bmg-g31` (`-fsycl-targets=
|
||||||
|
intel_gpu_bmg_g31`), `build_target "intel_gpu_bmg_g31"`. Device rows only; kernels launch on the
|
||||||
|
stream's queue with sub-group 16. A library with no code for the card is left out of selection, as
|
||||||
|
for AMD (`docs/PLUGIN.md` §10): the SYCL backend's `code_runs` answers from the plugin's
|
||||||
|
`build_target` against `props.arch`, so libr4d's rows can never be selected on the B65 in a build
|
||||||
|
with both (and libxe2's never on an AMD card).
|
||||||
|
|
||||||
|
Built and loaded like every bundled plugin, so `tests/oot_plugins.sh` rebuilds it out of tree when
|
||||||
|
`icpx` is available.
|
||||||
|
|
||||||
|
### 4.4 No silent CPU fallback
|
||||||
|
|
||||||
|
On a device backend the engine places an op that has weights and no device kernel on the host and
|
||||||
|
logs it once at INFO ("host-only ops: ... Not a hole", `core/engine_bringup.cpp:146`). That is a
|
||||||
|
CPU route for a GPU op, which the brief forbids. **On the SYCL backend that message becomes a fatal
|
||||||
|
startup error naming the ops**, unless `--debug-accept-host-ops` (new, debug-only) is given; ops
|
||||||
|
without weights already fail as holes. `--debug-graph` shows the resolution either way.
|
||||||
|
|
||||||
|
### 4.5 Build integration
|
||||||
|
|
||||||
|
- `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`. 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.
|
||||||
|
|
||||||
|
### 4.6 Core device kernels under SYCL
|
||||||
|
|
||||||
|
`advance` and `wtab` get SYCL launchers (`core/sched/advance_sycl.cpp`, `core/runtime/wtab_sycl.cpp`,
|
||||||
|
`-fsycl`) as a third branch after `device_is_host()`. `RAD_ADV_FN`, `RAD_PHILOX_HD`, `RAD_YARN_HD`
|
||||||
|
gain a SYCL case so the shared row code compiles for the device. `xprefetch` stays off
|
||||||
|
(`rad_xp_supported` = 0).
|
||||||
|
|
||||||
|
### 4.7 Single card
|
||||||
|
|
||||||
|
`--tp > 1` on the SYCL backend stops at startup: "the Intel backend serves one card (--tp 1); tensor
|
||||||
|
parallelism needs the all-reduce kernels it does not have". No collective rows are declared.
|
||||||
|
|
||||||
|
### 4.8 Numerics
|
||||||
|
|
||||||
|
- fp8 is OCP E4M3 everywhere the engine reads it (`docs/PLUGIN.md` §10). XMX has no fp8 input on this
|
||||||
|
part (`SYCL_PROGRESS.md`, Phase 0), so fp8 and MXFP4 weights are widened to bf16 in registers;
|
||||||
|
int8 uses s8 DPAS.
|
||||||
|
- Tolerances come from the matching libr4d rows and `rad-kbench`'s checks for that op and dtype,
|
||||||
|
never looser.
|
||||||
|
- Reductions: the first kernels use a fixed reduction order per output so results do not depend on
|
||||||
|
work-group scheduling. Where that differs from libref's order, greedy outputs may diverge after a
|
||||||
|
near-tie, and Milestone A then states a measured KL bound (the engine has a KL tool: `core/kld.cpp`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Appendix A. Every op
|
||||||
|
|
||||||
|
Generated by `scripts/sycl/op_inventory.sh`; regenerate after a vocabulary change. Columns: whether
|
||||||
|
libref implements the op (the oracle), libr4d's kernels for it, the dtype prose of up to three of
|
||||||
|
those rows, and the architecture plugins whose source names it (a grep: `common` is
|
||||||
|
`arch/common`, the shared blocks every LLM uses).
|
||||||
|
|
||||||
|
| op | libref | libr4d kernels | libr4d dtypes (first three rows' prose) | architectures naming it |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| `act_mul` | yes | act_mul_bf16 | bf16 in and out, f32 arithmetic, libm silu / erf / tanh | common, embgemma2, gemma4, minimaxmusic3, sdxl |
|
||||||
|
| `add` | yes | add_bf16, add_f32 | bf16 in and out, fp32 arithmetic; f32 in and out | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl, unlimitedocr_bf16 |
|
||||||
|
| `add_rmsnorm` | no | add_rmsnorm_bf16 | bf16 x / a / y, f32 or bf16 gain, fp32 reduction; byte-identical to add_bf16 + rmsnorm_bf16 | common |
|
||||||
|
| `all_gather` | yes | ar_gather_2rank, ar_gather_3rank, ar_gather_4rank, ar_gather_8rank | any payload -- the bytes are moved, never summed, so the (u32 id, f32 logit) pairs the vocab-parallel sampler gathers survive intact | common, krea2, minimaxh3, qwenimage21 |
|
||||||
|
| `all_reduce` | yes | ar_oneshot_2rank_exact, ar_oneshot_2rank_exact_lane, ar_oneshot_2rank_wht6, ar_oneshot_2rank_wht6_lane, ar_oneshot_3rank_exact, ar_oneshot_4rank_exact, ar_oneshot_8rank_exact, ar_twoshot_3rank_exact, ar_twoshot_3rank_ti8, ar_twoshot_4rank_exact, ar_twoshot_4rank_exact_lane, ar_twoshot_4rank_ti8, ar_twoshot_4rank_ti8_lane, ar_twoshot_8rank_exact | bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks; bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks and to ar_oneshot_3rank_exact; bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks and to the wide row | common, flux3, gemma3, gemma4, gemma4_bf16, krea2, llama_fp8, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, unlimitedocr_bf16 |
|
||||||
|
| `ar_gather_hc_write` | no | ar_gather_hc_write, ar_gather_hc_write_4rank | bf16 throughout; the gather's sums and narrows are moe_gather's (round-to-nearest-even, the shared arm's product rounded before the add), the reduction and the write ar_hc_write's on the same wire -- byte-identical to the three kernels it replaces; bf16 throughout; the gather's sums and narrows are moe_gather's (round-to-nearest-even, the shared arm's product rounded before the add), the sum in fp32 in ascending rank order and rounded to bf16 exactly as the four-rank exact all-reduce stores it, and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the three kernels it replaces | common |
|
||||||
|
| `ar_hc_write` | no | ar_hc_write, ar_hc_write_4rank | bf16 throughout; the sum in fp32 in ascending rank order and rounded to bf16 exactly as the four-rank exact all-reduce stores it, and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the pair it replaces; bf16 throughout; the sum rounded to bf16 exactly as the standalone all-reduce of the SAME wire stores it and the write in hc_write's arithmetic over that bf16 value -- byte-identical to the pair it replaces | common |
|
||||||
|
| `ar_ln_had_quant_i8` | no | ar_ln_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had), optional bf16 out | -- |
|
||||||
|
| `ar_rmsnorm_had_quant_i8g` | no | ar_rmsnorm_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out of the UNROTATED norm output; x and the residual are ar_rmsnorm_quant_fp8's bytes, and the codes rmsnorm_had_quant_i8g's over the same norm output | common, qwen35_fp8 |
|
||||||
|
| `ar_rmsnorm_post_quant_fp8` | no | ar_rmsnorm_post_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns); x receives the reduced sum | gemma3 |
|
||||||
|
| `ar_rmsnorm_quant_fp8` | no | ar_rmsnorm_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; codes taken over the BF16-ROUNDED norm output, and the reduced sum rounded to bf16 exactly as the standalone all-reduce of the SAME wire stores it -- byte-identical to the pair it replaces | common |
|
||||||
|
| `ar_rmsnorm_quant_i8` | no | ar_rmsnorm_quant_i8, ar_rmsnorm_quant_i8_4rank | bf16 in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale; the reduced sum rounded to bf16 as the standalone exact all-reduce stores it | gemma3, gemma4_bf16 |
|
||||||
|
| `attn_cross` | yes | attn_cross_h128_bf16, attn_cross_h64_bf16 | bf16 query / key / value / out, bf16 operands, fp32 accumulate | anima, flux3, ltx2, sdxl |
|
||||||
|
| `attn_dense` | yes | attn_dense_h1152_bf16, attn_dense_h128_bf16, attn_dense_h256_gqa2_bf16, attn_dense_h256_gqa4_bf16, attn_dense_h256_gqa8_bf16, attn_dense_h384_bf16, attn_dense_h512_bf16, attn_dense_h512_gqa2_bf16, attn_dense_h512_gqa4_bf16, attn_dense_h512_gqa8_bf16, attn_dense_h64_bf16, attn_dense_h768_bf16, attn_dense_small_h256_bf16, attn_vit_h72_bf16 | bf16 query / key / value / out, bf16 operands, fp32 accumulate; bf16 query / key / value / out, f16 operands, fp32 accumulate; bf16 query / key / value / out, fp32 scores and accumulate | anima, breeze, common, embgemma2, flux3, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl |
|
||||||
|
| `attn_local_rel` | yes | attn_local_rel_bf16 | bf16 q / k / v / relk / out, bf16 or f32 per-dim scale, f32 softmax | embgemma2 |
|
||||||
|
| `attn_na3d` | yes | attn_na3d_h64 | bf16 or f32 q / k / v / out, fp32 accumulate | ltx2 |
|
||||||
|
| `attn_paged` | yes | attn_decode_h128_gqa1_bf16kv, attn_decode_h128_gqa1_fp8kv, attn_decode_h128_gqa2_bf16kv, attn_decode_h128_gqa2_fp8kv, attn_decode_h128_gqa2w_bf16kv, attn_decode_h128_gqa2w_fp8kv, attn_decode_h128_gqa4_bf16kv, attn_decode_h128_gqa4_fp8kv, attn_decode_h128_gqa8_bf16kv, attn_decode_h128_gqa8_fp8kv, attn_decode_h256_gqa12_bf16kv, attn_decode_h256_gqa12_fp8kv, attn_decode_h256_gqa12_fp8v4, attn_decode_h256_gqa12_k6v4, attn_decode_h256_gqa2_bf16kv, attn_decode_h256_gqa2_fp8kv, attn_decode_h256_gqa4_bf16kv, attn_decode_h256_gqa4_fp8kv, attn_decode_h256_gqa6_bf16kv, attn_decode_h256_gqa6_bs4_bf16kv, attn_decode_h256_gqa6_bs4_fp8kv, attn_decode_h256_gqa6_bs4_fp8v4, attn_decode_h256_gqa6_bs4_k6v4, attn_decode_h256_gqa6_fp8kv, attn_decode_h256_gqa6_fp8v4, attn_decode_h256_gqa6_k6v4, attn_decode_h256_gqa8_bf16kv, attn_decode_h256_gqa8_fp8kv, attn_prefill_h128_gqa1_bf16kv, attn_prefill_h128_gqa1_fp8kv, attn_prefill_h128_gqa2_bf16kv, attn_prefill_h128_gqa2_fp8kv, attn_prefill_h128_gqa2w_bf16kv, attn_prefill_h128_gqa2w_fp8kv, attn_prefill_h128_gqa8_bf16kv, attn_prefill_h128_gqa8_fp8kv, attn_prefill_h256_gqa12_bf16kv, attn_prefill_h256_gqa12_fp8kv, attn_prefill_h256_gqa12_fp8v4, attn_prefill_h256_gqa12_k6v4, attn_prefill_h256_gqa2_bf16kv, attn_prefill_h256_gqa2_fp8kv, attn_prefill_h256_gqa4_bf16kv, attn_prefill_h256_gqa4_fp8kv, attn_prefill_h256_gqa6_bf16kv, attn_prefill_h256_gqa6_bs4_bf16kv, attn_prefill_h256_gqa6_bs4_fp8kv, attn_prefill_h256_gqa6_bs4_fp8v4, attn_prefill_h256_gqa6_bs4_k6v4, attn_prefill_h256_gqa6_fp8kv, attn_prefill_h256_gqa6_fp8kv_pv8, attn_prefill_h256_gqa6_fp8kv_qk8, attn_prefill_h256_gqa6_fp8kv_qk8pv8, attn_prefill_h256_gqa6_fp8v4, attn_prefill_h256_gqa6_fp8v4_pv8, attn_prefill_h256_gqa6_fp8v4_qk8, attn_prefill_h256_gqa6_fp8v4_qk8pv8, attn_prefill_h256_gqa6_k6v4, attn_prefill_h256_gqa6_k6v4_pv8, attn_prefill_h256_gqa6_k6v4_qk8, attn_prefill_h256_gqa6_k6v4_qk8pv8, attn_prefill_h256_gqa8_bf16kv, attn_prefill_h256_gqa8_fp8kv, attn_prefill_h64_gqa4_bf16kv, attn_prefill_h64_gqa4_fp8kv, attn_window_h<HD>_gqa<G>_<KVN> | bf16 query and probabilities rounded to e4m3, fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out; bf16 query and probabilities rounded to e4m3, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), K and V as e4m3 in LDS, bf16 out; bf16 query and probabilities rounded to e4m3, k6_v4 kv cache (int6 K, int4 V, each in groups of 32 with f16 scales), K and V as e4m3 in LDS, bf16 out | breeze, common, gemma3, gemma4, gemma4_bf16, lfm2_bf16, minimaxmusic3, unlimitedocr_bf16 |
|
||||||
|
| `attn_paged_gate_quant` | no | attn_decode_gq_h256_gqa12_bf16kv, attn_decode_gq_h256_gqa12_fp8kv, attn_decode_gq_h256_gqa12_fp8v4, attn_decode_gq_h256_gqa12_k6v4, attn_decode_gq_h256_gqa6_bs4_bf16kv, attn_decode_gq_h256_gqa6_bs4_fp8kv, attn_decode_gq_h256_gqa6_bs4_fp8v4, attn_decode_gq_h256_gqa6_bs4_k6v4 | bf16 query, bf16 kv cache, bf16 gated out, E4M3 codes with an f32 scale per 128 columns; bf16 query, fp8-e4m3 kv cache, bf16 gated out, E4M3 codes with an f32 scale per 128 columns; bf16 query, fp8_v4 kv cache (E4M3 K, int4 V in groups of 32 with f16 scales), bf16 gated out, E4M3 codes with an f32 scale per 128 columns | common |
|
||||||
|
| `attn_paged_qrow` | no | attn_qrow_decode_h256_gqa2_bf16kv, attn_qrow_decode_h256_gqa2_fp8kv, attn_qrow_h128_gqa8_bf16kv, attn_qrow_h128_gqa8_fp8kv, attn_qrow_h<HD>_gqa<G>_<KVN> | bf16 query (any row pitch), <KVDOC> kv cache, bf16 out, f32 partials; bf16 query (any row pitch, a multiple of 4), bf16 kv cache, bf16 out, f16 partials; bf16 query (any row pitch, a multiple of 4), fp8-e4m3 kv cache with per-(seq,head) descales, bf16 out, f16 partials | common, gemma4, gemma4_bf16, unlimitedocr_bf16 |
|
||||||
|
| `attn_prefix_self` | yes | attn_prefix_self_h128_bf16 | bf16 q/k/v/out and cache, bf16 operands, fp32 accumulate; or i8 Q.K codes, i32 accumulate; or E4M3 V codes and P, fp32 accumulate | breeze, minimaxh3, minimaxmusic3, qwenimage21 |
|
||||||
|
| `attn_vsa` | yes | attn_vsa_h128_bf16 | bf16 q / k / v / coarse / gate / out, i32 segs / geom / sel; bf16 operands, fp32 accumulate; or i8 Q.K codes, i32 accumulate; or E4M3 V codes and P, fp32 accumulate | minimaxh3 |
|
||||||
|
| `bwe_up` | yes | bwe_up | bf16 or f32 operands | ltx2 |
|
||||||
|
| `cast` | yes | cast_bf16_bf16, cast_bf16_f16, cast_bf16_f32, cast_f32_bf16, cast_f32_f32 | bf16 in, bf16 out, byte-for-byte; bf16 in, f16 out, rounded to nearest even (a value past f16's range becomes an infinity); bf16 in, f32 out, exact | breeze, common, embgemma2, gemma3, gemma4, gemma4_bf16, glm5next, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_fp8, sdxl, unlimitedocr_bf16 |
|
||||||
|
| `causal_conv1d` | yes | causal_conv1d_bf16 | bf16 activations, weights and conv state; i32 cu, slots, has_init and num_accepted | lfm2_bf16 |
|
||||||
|
| `cfg_topk_sample` | yes | cfg_topk_sample | f32 or bf16 logits, i32 picks | breeze, minimaxmusic3 |
|
||||||
|
| `chan_affine` | yes | chan_affine_bf16, chan_affine_f32 | bf16; f32 | anima, flux3, krea2, minimaxh3, qwenimage21, sdxl |
|
||||||
|
| `chan_split` | yes | chan_split_bf16 | bf16 | minimaxmusic3 |
|
||||||
|
| `chan_stats` | yes | chan_stats_bf16, chan_stats_f32 | bf16; f32 x and y, bf16 or f32 statistics, every step rounded to f32 | flux3, ltx2 |
|
||||||
|
| `clamp` | yes | clamp_bf16 | bf16 in and out | embgemma2, minimaxh3 |
|
||||||
|
| `conv1d` | yes | conv1d_bf16, conv1d_f32 | bf16 rows, weight, bias and residual, fp32 accumulate, one rounding; act none, tanh or clamp; f32 rows, weight, bias and residual, f32 accumulate; act none, tanh or clamp | breeze, ltx2, minimaxh3, minimaxmusic3 |
|
||||||
|
| `conv1d_dw` | yes | conv1d_dw_bf16 | bf16 x / w / y, i32 cu_seqlens, f32 accumulate | breeze, embgemma2 |
|
||||||
|
| `conv2d` | yes | conv2d_bf16 | bf16 x / w / y, i32 cu_seqlens and mask, f32 accumulate | embgemma2, qwen3asr_bf16 |
|
||||||
|
| `conv2d_nhwc` | yes | conv2d_nhwc_bf16 | bf16 image, weight and bias, fp32 accumulate, one rounding | common, ltx2, sdxl |
|
||||||
|
| `conv2d_unfold` | yes | conv2d_unfold_bf16 | bf16 x / y, i32 cu_seqlens and mask | common, qwen3asr_bf16 |
|
||||||
|
| `conv3d_ndhwc` | yes | conv3d_ndhwc_bf16 | bf16 voxels, weight and residual, bf16 or f32 bias, fp32 accumulate | ltx2, minimaxh3 |
|
||||||
|
| `conv_t1d` | yes | conv_t1d_bf16, conv_t1d_f32 | bf16 rows, weight and bias, fp32 accumulate, one rounding; f32 rows, weight and bias, f32 accumulate | breeze, ltx2, minimaxh3, minimaxmusic3 |
|
||||||
|
| `cu_repeat` | yes | cu_repeat | i32 | anima, breeze, flux3, krea2, minimaxh3, minimaxmusic3, sdxl |
|
||||||
|
| `d2s3d` | yes | d2s3d | bf16 or f32 x and y, i32 geom | ltx2 |
|
||||||
|
| `d2s_add` | yes | d2s_add_bf16 | bf16 | anima, common, flux3, krea2 |
|
||||||
|
| `dequant` | yes | -- | | -- |
|
||||||
|
| `dequant_w4` | no | dequant_w4_bf16 | 4-bit in with an f16 scale and a zero in the dword's high half, bf16 out | -- |
|
||||||
|
| `dflash_conv` | yes | dflash_conv_t2_g16_bf16 | bf16 x / delta / base / out, fp32 accumulate | common |
|
||||||
|
| `dflash_select` | yes | dflash_select_bf16 | i32 candidate ids, f32 unary logits, bf16 hp and both codebooks, i32 tokens out | common |
|
||||||
|
| `dsa_pool` | yes | dsa_pool_fp8 | bf16 keys/gates, f32 position bias; FP8 codes and f32 scale | common |
|
||||||
|
| `dsa_query` | yes | dsa_query_fp8 | bf16 input, E4M3 codes and power-of-two f32 scale | common |
|
||||||
|
| `dsa_score` | yes | dsa_score_fp8 | E4M3 codes, f32 scales and gates | common |
|
||||||
|
| `embed_lookup` | yes | embed_lookup_bf16 | i32 tokens, bf16 table and output | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl, unlimitedocr_bf16 |
|
||||||
|
| `embed_lookup_q` | yes | embed_lookup_q_bf16 | i32 tokens, an E4M3 table with a bf16 or f32 scale or a plain bf16 one, bf16 output | common |
|
||||||
|
| `end_status` | yes | end_status | i32 | breeze, minimaxmusic3 |
|
||||||
|
| `expert_scale` | no | expert_scale_bf16 | i32 ids, bf16 table and weights | gemma4 |
|
||||||
|
| `fill` | yes | fill_bf16, fill_f32 | bf16 out; the value rounds to nearest even once; f32 out, the value exactly | anima, breeze, common, flux3, krea2, ltx2, sdxl |
|
||||||
|
| `flow_euler` | yes | flow_euler_bf16 | bf16 | anima, flux3, krea2, minimaxmusic3, qwenimage21 |
|
||||||
|
| `flow_renoise` | yes | flow_renoise_f32 | f32 latent and sigma, u32 seed words | ltx2, minimaxh3 |
|
||||||
|
| `flow_x0_step` | yes | flow_x0_step_f32 | f32 state, f32 or bf16 velocity | minimaxh3 |
|
||||||
|
| `fourier_embed` | yes | fourier_embed_bf16 | f32 time and w, bf16 out | minimaxmusic3 |
|
||||||
|
| `frame_mix_store` | yes | frame_mix_store_bf16 | bf16 planes and rows, f32 logits and scale | minimaxmusic3 |
|
||||||
|
| `frame_store` | yes | frame_store | i32 | breeze |
|
||||||
|
| `gate_add` | yes | gate_add_bf16 | bf16 | anima, flux3, krea2, ltx2, qwenimage21 |
|
||||||
|
| `gate_quant_fp8` | no | gate_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common, krea2 |
|
||||||
|
| `gated_had_quant_fp8` | no | gated_had_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED product; the codes are taken over the rotated BF16-ROUNDED product, and the residual factor of 128 is folded into the stored weight scale at convert, not here | common |
|
||||||
|
| `gated_had_quant_i8` | yes | gated_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had) | -- |
|
||||||
|
| `gated_had_quant_i8g` | no | gated_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED product; the codes are taken over the rotated BF16-ROUNDED product, byte-identical to the product + had_quant_act_i8g | common, qwen35_fp8 |
|
||||||
|
| `gated_quant_fp8` | yes | gated_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common |
|
||||||
|
| `gather_rows` | yes | gather_rows_bf16, gather_rows_u8 | i32 indices, bf16 rows; i32 indices, u8 rows | breeze, common, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl, unlimitedocr_bf16 |
|
||||||
|
| `gather_rows2` | yes | gather_rows2_bf16 | bf16 | anima, krea2 |
|
||||||
|
| `gdn_chunk_scan` | yes | gdn_chunk_scan_k128_v128_c64_bf16 | bf16 q/k/v/A, fp32 gate/beta, bf16 out; the state cache is f32 or f16 | common |
|
||||||
|
| `gdn_conv_prep` | yes | gdn_conv_prep_w4_h128_bf16 | bf16 x / weights / conv state / q,k,v out, fp32 a,b and gate/beta out | common |
|
||||||
|
| `gdn_conv_recurrent_update` | yes | gdn_conv_recurrent_update_k128_v128_bf16 | bf16 x / conv weights / conv state / a,b / out; the state cache is f32 or f16. Byte-identical to gdn_conv_update followed by gdn_recurrent_update | common |
|
||||||
|
| `gdn_conv_update` | yes | gdn_conv_update_w4_h128_bf16 | bf16 x / weights / conv state / q,k,v out | common |
|
||||||
|
| `gdn_gated_norm_had_quant_i8` | no | gdn_gated_norm_had_quant_i8 | bf16 x and z, f32 norm weight, int8 out with an f32 per-row scale carrying 1/sqrt(had) | -- |
|
||||||
|
| `gdn_gated_rmsnorm` | yes | gdn_gated_rmsnorm_h128_bf16 | bf16 x / z / out, fp32 weight | common |
|
||||||
|
| `gdn_kkt_solve` | yes | gdn_kkt_solve_k128_c64_bf16 | bf16 k and A out, fp32 beta / gate / gram / inverse | common |
|
||||||
|
| `gdn_recurrent_update` | yes | gdn_recurrent_update_k128_v128_bf16_fp32state | bf16 q/k/v and out, fp32 a,b; the state cache is f32 or f16 and the operand says which | common |
|
||||||
|
| `gelu` | yes | gelu_bf16 | bf16 in and out, fp32 arithmetic | anima, breeze, common, lfm2_bf16, qwen3asr_bf16, sdxl |
|
||||||
|
| `gelu_mul` | yes | gelu_mul_bf16 | bf16 in and out, fp32 arithmetic | breeze, gemma3, gemma4_bf16, ltx2 |
|
||||||
|
| `gelu_mul_quant_i8` | no | gelu_mul_quant_i8 | bf16 gate_up in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale, optional bf16 out; the codes taken over the bf16-rounded product | gemma3, gemma4_bf16 |
|
||||||
|
| `gelu_quick` | yes | gelu_quick_bf16 | bf16 or f32 in and out (one dtype), f32 arithmetic | sdxl |
|
||||||
|
| `gelu_tanh` | yes | gelu_tanh_bf16 | bf16 | common, embgemma2, gemma4, krea2, lfm2_bf16, ltx2, qwenimage21 |
|
||||||
|
| `gemm_nt` | yes | gemm_bf16_nt_m16, gemm_bf16_nt_m64, gemm_bf16_nt_tiled | bf16 A / W / C, fp32 accumulate, deterministic reduction; bf16 A / W / C, fp32 accumulate. BYTE-IDENTICAL to gemm_bf16_nt_m64: the same WMMA sequence a tile and the same split count, the slices summed in the same order from 0.f | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, lfm2_bf16, ltx2, minimaxmusic3, qwen3asr_bf16, qwenimage21, sdxl, unlimitedocr_bf16 |
|
||||||
|
| `gemm_nt_bias` | yes | gemm_bf16_nt_bias_tiled, gemm_f32_nt_bias | bf16 A / W / C / res, bf16 or f32 bias, fp32 accumulate, three RNE roundings in the store; f32 A / W, f32 or bf16 bias, f32 accumulate, C f32 or bf16 with res in C's dtype (each epilogue step rounded to C's dtype) | anima, breeze, common, embgemma2, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen3asr_bf16, sdxl |
|
||||||
|
| `gemm_nt_f32` | yes | gemm_nt_f32_bf16 | bf16 input, f32 weights and output | common |
|
||||||
|
| `gemm_nt_q` | yes | gemm_fp8a16_nt_m1, gemm_fp8a8_f32scale, gemm_fp8a8_nt_m16, gemm_fp8a8_tiled, gemm_i8a8_nt_m16, gemm_i8a8_tiled, gemm_mxfp4a8_decode, gemm_mxfp4a8_nt_m64, gemm_mxfp4a8_tiled, gemm_w2a8_nt, gemm_w4a16_asym_nt_m64, gemm_w4a16_nt_m64, gemm_w4a8_nt_m64, gemm_w4a8_prefill, gemm_w4a8_tiled, gemm_w4a8i8_tiled, gemm_w5a16_nt_m64, gemm_w5a8i8_tiled, gemm_w8a16_nt_m64, gemm_w8a8_nt_m64, gemm_w8a8_tiled | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, bf16 C. The split-K finisher sums its planes in INDEX order, so a run repeats exactly; but the split COUNT is chosen from M, so the same row computed at M=1 and at M=8 is not bit-identical. That is why a speculative decode diverges from a non-speculative one on a near-tie. NOTHING PINS IT TODAY: --deterministic reaches placement and the sampler, not this kernel; E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, bf16 C; each 128-K block's product folded into the f32 accumulator with one fma; E4M3 codes, F32 scales, BF16 output | common, gemma3, gemma4_bf16 |
|
||||||
|
| `gemm_nt_q_bias` | yes | gemm_fp8a8_bias_nt_m16 | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, a bf16 bias added to the f32 accumulator before its one rounding, bf16 C | minimaxh3 |
|
||||||
|
| `gemm_nt_q_gated` | yes | gemm_fp8a8_gated_nt_m16 | E4M3 A with an f32 scale per (row, 128 K), E4M3 W with a bf16 scale per 128x128 tile, and the QUANTISER's outputs: E4M3 codes, an f32 scale per (row, 128 columns) and an optional bf16 product. Byte-identical to gemm_nt_q followed by gated_quant_fp8 -- the accumulator is rounded to bf16 before the gate and the multiply, and the amax is an fmaxf reduction, which is exact and order-free however it is regrouped across the waves | common |
|
||||||
|
| `givens_dense_quant` | yes | givens_dense_quant | bf16 in, int8 or E4M3 out in PLAIN ROW-MAJOR order, parts side by side, with an f32 scale (amax/127 or amax/448) per (row, part, 128 columns); f16 matrices and f32 channel scales | common |
|
||||||
|
| `givens_rotate` | yes | givens_rotate | bf16 in, f16 out, parts side by side; the tables are the weight's int32 pairs, f32 angles and f32 channel scales | common |
|
||||||
|
| `gram_accum` | yes | gram_accum, gram_accum_bf16 | E4M3 plus an f32 scale per (row, 128 columns) in; an f32 [n][n] accumulator in and out; bf16 in, no scale operand; an f32 [n][n] accumulator in and out | common, gemma3 |
|
||||||
|
| `grid_embed` | yes | grid_embed_bf16 | bf16 x, bf16 or f32 table, i32 coord, f32 taps | common |
|
||||||
|
| `grid_embed_aa` | yes | grid_embed_aa_bf16 | bf16 x, bf16 or f32 table, i32 coord, f32 taps | lfm2_bf16 |
|
||||||
|
| `grid_pos3` | yes | grid_pos3 | f32 | minimaxh3 |
|
||||||
|
| `group_norm` | yes | group_norm | bf16 or f32 rows, bf16 or f32 gain, bias and modulation, f32 statistics | common, ltx2, minimaxh3, sdxl |
|
||||||
|
| `had_quant_act_fp8` | yes | had_quant_act_fp8 | bf16 in, E4M3 out in PLAIN ROW-MAJOR order with an f32 scale per (row, 128 columns); the sqrt(128) the unnormalised transform leaves behind is NOT undone here, because <Hw,Ha> = 128<w,a> and the whole factor is folded into the stored weight scale at convert | common |
|
||||||
|
| `had_quant_act_i8` | yes | had_quant_act_i8 | bf16 in, int8 out with an f32 per-row scale that also carries the 1/sqrt(had) normalisation | -- |
|
||||||
|
| `had_quant_act_i8g` | yes | had_quant_act_i8g | bf16 in, int8 out in PLAIN ROW-MAJOR order with an f32 scale of amax/127 per (row, 128 columns); the factor of 128 of the unnormalised transform is left to the weight's stored scale (dtype i8a8h) | common |
|
||||||
|
| `hc_enter` | yes | hc_enter_bf16 | bf16 in and out | common |
|
||||||
|
| `hc_project` | yes | hc_project_bf16 | bf16 stream, f32 direction, i32 switch | common |
|
||||||
|
| `hc_read` | yes | hc_read_bf16, hc_read_e4m3 | bf16 stream and mixing matrices, f32 gain, bf16 out, E4M3 + f32 scale for the optional twin; bf16 stream, E4M3 mixing matrices with f32 scales in each row (128-column groups for mix_down, a quarter row for mix_up), f32 gain, bf16 out, E4M3 + f32 scale for the twin | common |
|
||||||
|
| `hc_write` | yes | hc_write_bf16 | bf16 throughout | common |
|
||||||
|
| `head_gate` | yes | head_gate | bf16 logits, bf16 or f32 x | ltx2 |
|
||||||
|
| `im2col_nhwc` | yes | im2col_nhwc_bf16 | bf16 in and out, copied bit for bit | sdxl |
|
||||||
|
| `int_affine` | yes | int_affine | i32 | ltx2 |
|
||||||
|
| `interleave2` | yes | interleave2_bf16 | bf16 or f32 in, f32 out | minimaxh3, minimaxmusic3 |
|
||||||
|
| `iota` | yes | iota | i32 | anima, breeze, common, flux3, krea2, ltx2, minimaxh3, minimaxmusic3, sdxl |
|
||||||
|
| `join_add_scale` | no | join_add_scale_bf16 | bf16 activations, f32 gains, bf16 scalar | gemma4 |
|
||||||
|
| `kd_input` | yes | kd_input_bf16 | f32 lanes, bf16 y | sdxl |
|
||||||
|
| `kd_step` | yes | kd_step_bf16 | bf16 model output, f32 lanes, history and preview, f32 arithmetic | sdxl |
|
||||||
|
| `kda_update` | yes | kda_update_k128_v128_bf16 | bf16 activations, f32 gates and state | common |
|
||||||
|
| `kv_len_trim` | no | kv_len_trim | int32 in, int32 out, clamped at zero | gemma4_bf16 |
|
||||||
|
| `kv_store` | yes | kv_store_bf16, kv_store_fp8, kv_store_fp8v4, kv_store_k6v4 | bf16 k / v / cache, i32 slot mapping; bf16 k / v, E4M3 K and int4 V in groups of 32 with f16 scales, i32 slot mapping; bf16 k / v, fp8-e4m3 cache, i32 slot mapping, scalar k_scale / v_scale descales | breeze, common, gemma3, gemma4, gemma4_bf16, lfm2_bf16, minimaxmusic3, qwenimage21, unlimitedocr_bf16 |
|
||||||
|
| `l2norm_chan` | yes | l2norm_chan_bf16 | bf16 | common |
|
||||||
|
| `lane_gather` | yes | lane_gather_w32 | bf16 | anima, flux3, krea2, minimaxh3, qwenimage21 |
|
||||||
|
| `lane_store` | yes | lane_store_w32 | bf16 | anima, flux3, krea2, qwenimage21, sdxl |
|
||||||
|
| `layernorm` | yes | layernorm_bf16 | bf16 or f32 x, bf16 y, f32 or bf16 gain and bias | breeze, common, embgemma2, lfm2_bf16, minimaxh3, minimaxmusic3, qwen3asr_bf16, sdxl |
|
||||||
|
| `ln_mod` | yes | ln_mod_bf16 | bf16 | qwenimage21 |
|
||||||
|
| `ln_mod_quant_fp8` | yes | ln_mod_quant_fp8_bf16 | bf16 in, E4M3 codes with f32 scales out | qwenimage21 |
|
||||||
|
| `logit_rerank` | yes | logit_rerank, logit_rerank_i8 | bf16 in, f32 values + i32 ids out, ties to the lower id | common |
|
||||||
|
| `logit_softcap` | yes | logit_softcap_bf16, logit_softcap_f32 | bf16 in and out, fp32 arithmetic; f32 in and out — the 1.3.0 sampling chain carries the logits as f32 from the gemm | gemma4, gemma4_bf16 |
|
||||||
|
| `logits_gemm` | yes | logits_gemm_bf16, logits_gemm_bf16_cols, logits_gemm_fp8, logits_gemm_i8 | bf16 x and lm_head, F32 LOGITS OUT, fp32 accumulate; bf16 x and lm_head, F32 LOGITS OUT, fp32 accumulate. BYTE-IDENTICAL to logits_gemm_bf16; bf16 x, E4M3 head with a bf16 scale per 128x128 tile stored PER ROW, F32 LOGITS OUT, fp32 accumulate | breeze, common, gemma3, gemma4, gemma4_bf16, glm5next, lfm2_bf16, llama_fp8, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, unlimitedocr_bf16 |
|
||||||
|
| `lora_expand` | yes | lora_expand_scalar, lora_expand_tiled | f32 t and scale; bf16 lora_b; i32 slot; bf16 / f16 / f32 y | -- |
|
||||||
|
| `lora_expand_mm` | yes | lora_expand_mm_wmma | f32 t and scale; bf16 lora_b; i32 slot; bf16 / f16 / f32 y | -- |
|
||||||
|
| `lora_shrink` | yes | lora_shrink_scalar, lora_shrink_wmma, lora_shrink_wmma_q | bf16 / f16 / f32 a, or fp8_e4m3 / fp8_e5m2 / i8 a with its f32 scale stream; bf16 lora_a; i32 slot; f32 t; bf16 a; bf16 lora_a; i32 slot; f32 t; fp8_e4m3 / fp8_e5m2 / i8 a with its f32 scale stream; bf16 lora_a; i32 slot; f32 t | -- |
|
||||||
|
| `ltx_guide` | yes | ltx_guide | f32 latent, bf16 or f32 velocities | ltx2 |
|
||||||
|
| `mhc_contract` | yes | mhc_contract_bf16 | bf16 | glm5next |
|
||||||
|
| `mhc_post` | yes | mhc_post_bf16 | bf16 activation, f32 coefficients | common |
|
||||||
|
| `mhc_pre` | yes | mhc_pre_bf16 | bf16 activation, f32 weights and coefficients | common |
|
||||||
|
| `mhc_pre_finish` | yes | mhc_pre_finish_bf16 | bf16 activation, f32 partials and coefficients | common |
|
||||||
|
| `mhc_pre_partial` | yes | mhc_pre_partial_bf16 | bf16 activation, f32 weights and partials | common |
|
||||||
|
| `mix_rows` | yes | mix_rows_bf16 | bf16 | krea2 |
|
||||||
|
| `mla_attn` | yes | mla_attn_bf16, mla_attn_matrix_bf16 | bf16 Q/cache/output, f32 softmax and partials; bf16 operands; FP32 probabilities via high/low BF16 | common |
|
||||||
|
| `mla_project` | yes | mla_project_bf16 | bf16 input, weights and output; fp32 arithmetic | common |
|
||||||
|
| `moe_gather` | yes | moe_gather_bf16 | bf16 in and out | common, gemma4 |
|
||||||
|
| `moe_gather_inv` | no | moe_gather_inv_bf16 | bf16 in and out, f32 or bf16 routing weights | common |
|
||||||
|
| `moe_gemm` | yes | moe_gemm_bf16 | bf16 activation, bf16 weight as the checkpoint stores it ([N, K] row-major, no layout hook), f32 accumulate over the whole of K, bf16 out rounded to nearest-even | common, gemma4 |
|
||||||
|
| `moe_gemm_q` | yes | moe_gemm_fp8a8, moe_gemm_fp8a8_f32scale, moe_gemm_mxfp4a8, moe_gemm_w4a8 | E2M1 and E8M0 weights, E4M3 activations and f32 scales, bf16 output; E4M3 activation with an f32 scale per 128 of K, E4M3 weight with a bf16 scale per 128x128 tile, bf16 out; E4M3 activation with an f32 scale per 128 of K, symmetric int4 weight (codes -8..7) with a bf16 scale per row per 128 of K, bf16 out; dtype w4a8h is the same plane with a 128-wide Hadamard rotation along K baked into both, and pairs with had_quant_act_fp8; dtype w4nla8h is w4a8h with the codes indexing libquant's w4nl levels, and w4nl64a8h / w4nl32a8h are w4nla8h with an E4M3 scale per row per 64 / 32 of K under a fixed 2^-13; w5nl64a8h is w4nl64a8h with five-bit codes into libquant's w5nl levels, a sign bit plane after each row's nibbles | common, gemma4 |
|
||||||
|
| `moe_gemm_q_mod4` | yes | moe_gemm_fp8a8_mod4, moe_gemm_w4a8_mod4 | as moe_gemm_fp8a8; as moe_gemm_w4a8 | common |
|
||||||
|
| `moe_scatter` | yes | moe_scatter_i32 | i32 throughout | common, gemma4 |
|
||||||
|
| `moe_scatter_inv` | no | moe_scatter_inv_i32 | i32 throughout | common |
|
||||||
|
| `mtp_enter` | yes | mtp_enter_bf16, mtp_enter_e4m3 | bf16 activations and fc, f32 gains; bf16 activations, E4M3 fc rows with f32 128-column group scales in each row's tail, f32 gains | common |
|
||||||
|
| `mul` | yes | mul_bf16 | bf16 in and out, fp32 arithmetic | anima, common, flux3, gemma4, krea2, lfm2_bf16, ltx2, minimaxh3, qwenimage21, sdxl |
|
||||||
|
| `mul_weight` | yes | mul_weight_bf16, mul_weight_f32 | bf16 in and out, a bf16 or f32 weight, fp32 arithmetic; bf16 or f32 in, a bf16 or f32 weight, f32 out, the product rounded once | breeze, common, embgemma2, gemma4, minimaxh3 |
|
||||||
|
| `ngram_ids` | yes | ngram_ids_i32 | i32 tokens and state, i64 multipliers and per-head vocab sizes and offsets | common |
|
||||||
|
| `norm_add_norm` | no | norm_add_norm_bf16 | bf16 activations, f32 gains | gemma4 |
|
||||||
|
| `norm_add_norm_route` | no | norm_add_norm_route_bf16 | bf16 activations, f32 gains; E4M3 codes with an f32 scale a 128 columns | gemma4 |
|
||||||
|
| `pair_argmax` | yes | pair_argmax_f32 | f32 pairs (int32 id bits, f32 value), i32 idx, f32 val | common |
|
||||||
|
| `patch_fold` | yes | patch_fold_f32 | bf16 or f32 voxels, f32 patch rows | minimaxh3 |
|
||||||
|
| `patch_unfold` | yes | patch_unfold_f32 | f32 | minimaxh3 |
|
||||||
|
| `pix_patch` | yes | pix_patch | bf16 or f32 x and y | ltx2 |
|
||||||
|
| `pixel_norm` | yes | pixel_norm | bf16 or f32 x and y | ltx2 |
|
||||||
|
| `ple_conv` | yes | ple_conv_bf16 | bf16 activations, weights and conv state; i32 cu, slots, has_init and num_accepted | common |
|
||||||
|
| `ple_gate` | yes | ple_gate_bf16 | bf16 activations, F32 norm gains | common |
|
||||||
|
| `pool_rows` | yes | pool_rows_bf16 | bf16 in and out, f32 sum, two roundings | common |
|
||||||
|
| `prefetch` | no | prefetch | any | common, gemma4_bf16 |
|
||||||
|
| `qk_norm_rope` | yes | qk_norm_rope_bf16 | bf16 qkv, bf16 or f32 gains, i32 positions, f32 arithmetic, the norm rounded before the rotation | anima, breeze, common, embgemma2, flux3, gemma4, krea2, ltx2, minimaxh3, qwenimage21 |
|
||||||
|
| `qk_norm_rope_gate` | no | qk_norm_rope_gate | bf16 in and out; the norm output is rounded to bf16 before the rotation, as the unfused reference does by storing it | common |
|
||||||
|
| `qk_norm_rope_gate_kv_store` | no | qk_norm_rope_gate_kv_store_bf16, qk_norm_rope_gate_kv_store_fp8, qk_norm_rope_gate_kv_store_fp8v4, qk_norm_rope_gate_kv_store_k6v4 | bf16 in and out, E4M3 K and int4 V with f16 scales, i32 slot mapping; bf16 in and out, bf16 cache, i32 slot mapping; bf16 in and out, fp8-e4m3 cache, i32 slot mapping, scalar k_scale / v_scale descales | common |
|
||||||
|
| `qkv_norm_rope` | no | qkv_norm_rope_bf16, qkv_norm_rope_h128_bf16 | bf16 q/k/v and gains (or f32 gains), i32 positions; byte-identical to [rmsnorm_p +] rmsnorm x2 + rope x2, each norm taken by its standalone kernel's partition; bf16 q/k/v and gains (or f32 gains), i32 positions; byte-identical to rmsnorm_p + rmsnorm x2 + rope x2, each norm taken by its standalone kernel's partition | gemma3, gemma4_bf16 |
|
||||||
|
| `qkv_norm_rope_kv_store` | no | qkv_norm_rope_kv_store_bf16, qkv_norm_rope_kv_store_fp8 | bf16 q/k/v and gains (or f32 gains), i32 positions and slots, fp8-e4m3 cache, scalar k_scale / v_scale descales; byte-identical to qkv_norm_rope + kv_store_fp8; bf16 q/k/v, gains, cache; i32 positions and slots; byte-identical to qkv_norm_rope + kv_store_bf16 | common, gemma4_bf16 |
|
||||||
|
| `qsa_block_key` | yes | qsa_block_key_bf16 | bf16 keys in with an f32 gain; bf16 out, one row a BLOCK. The mean is rounded to bf16 before the norm, which is the reference's order and not the convenient one | common |
|
||||||
|
| `qsa_score` | yes | qsa_score_bf16 | bf16 queries and block keys, an i32 page-id table, f32 scores; a negative table entry scores -inf and not zero | common, qwen4exp_fp8 |
|
||||||
|
| `qsa_select` | yes | qsa_select_i32 | f32 scores and an i32 page table in; an i32 [M, topk+1] table and a live count out | common |
|
||||||
|
| `qsa_tail_store` | yes | qsa_tail_store_bf16 | bf16 keys in, an i32 position and an i32 cu_seqlens; the bf16 tail written in place | common |
|
||||||
|
| `qsa_work` | yes | qsa_work_bf16 | bf16 keys and a bf16 tail in, an i32 position, cu_seqlens and the block-key table; a bf16 staging plane out with an i32 page and first-token position a block | common |
|
||||||
|
| `quant_act_fp8` | yes | quant_act_fp8 | bf16 in, E4M3 out in PLAIN ROW-MAJOR order with an f32 scale per (row, 128 columns) | common, gemma3, gemma4 |
|
||||||
|
| `quant_act_i8` | yes | quant_act_i8 | bf16 in, int8 out with an f32 per-row scale | common, gemma3, gemma4_bf16 |
|
||||||
|
| `quant_act_i8g` | yes | quant_act_i8g | bf16 in, int8 out in PLAIN ROW-MAJOR order with an f32 scale of amax/127 per (row, 128 columns) | common, gemma3, minimaxh3, qwenimage21 |
|
||||||
|
| `quant_cols_fp8` | yes | quant_cols_fp8_bf16 | bf16 in, E4M3 out at its own pitch, f32 scale per column | minimaxh3 |
|
||||||
|
| `randn_lanes` | yes | randn_lanes_bf16, randn_lanes_f32 | bf16; f32 | anima, flux3, krea2, ltx2, minimaxh3, qwenimage21 |
|
||||||
|
| `rel_sinusoid` | yes | rel_sinusoid_bf16 | bf16 out, f32 libm sin / cos / exp | embgemma2 |
|
||||||
|
| `relu` | yes | relu_bf16 | bf16 in and out | embgemma2 |
|
||||||
|
| `resample_nearest` | yes | resample_nearest_bf16 | bf16 | minimaxmusic3 |
|
||||||
|
| `resize_bilinear` | yes | resize_bilinear | bf16 or f32 voxels, f32 arithmetic | minimaxh3 |
|
||||||
|
| `rms_mod` | yes | rms_mod_bf16 | bf16 rows, gain and table, fp32 sum of squares | anima, flux3, krea2, ltx2, minimaxh3 |
|
||||||
|
| `rms_mod_quant_fp8` | yes | rms_mod_quant_fp8_bf16 | bf16 rows, gain and table, E4M3 codes and f32 scales | anima, flux3, krea2, minimaxh3 |
|
||||||
|
| `rmsnorm` | yes | rmsnorm_bf16 | bf16 y, x bf16 or (with a gain) f32, bf16 or f32 gain, fp32 reduction | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, glm5next, krea2, lfm2_bf16, llama_fp8, ltx2, minimaxh3, minimaxmusic3, qwen35_bf16, qwen35_fp8, qwen3asr_bf16, qwenimage21, unlimitedocr_bf16 |
|
||||||
|
| `rmsnorm_add` | yes | -- | | -- |
|
||||||
|
| `rmsnorm_had_quant_i8` | yes | rmsnorm_had_quant_i8 | bf16 in, int8 out with an f32 per-row scale carrying 1/sqrt(had), optional bf16 out | -- |
|
||||||
|
| `rmsnorm_had_quant_i8g` | no | rmsnorm_had_quant_i8g | bf16 in, int8 out with an f32 scale per (row, 128 columns) and an optional bf16 out that receives the UNROTATED norm output; the codes are taken over the rotated BF16-ROUNDED norm output, byte-identical to rmsnorm + had_quant_act_i8g | common, qwen35_fp8 |
|
||||||
|
| `rmsnorm_p` | yes | rmsnorm_p_bf16 | bf16 x / y, fp32 reduction | gemma4_bf16, ltx2 |
|
||||||
|
| `rmsnorm_quant_fp8` | yes | rmsnorm_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED norm output | common, gemma3, gemma4 |
|
||||||
|
| `rmsnorm_quant_i8` | no | rmsnorm_quant_i8 | bf16 in, int8 out in the w4a8 GEMM's fragment order with an f32 per-row scale, optional bf16 out; every stored intermediate rounded to bf16 as the unfused chain stores it | common, gemma3, gemma4_bf16 |
|
||||||
|
| `rope` | yes | rope_bf16 | bf16 qkv, i32 positions, fp32 angles through the accurate sincosf | breeze, common, gemma3, gemma4, gemma4_bf16, ltx2 |
|
||||||
|
| `rope_split` | yes | rope_split | bf16 or f32 x, f32 or i32 positions | ltx2 |
|
||||||
|
| `rope_table` | yes | rope_table_f32 | f32 or bf16 table, i32 or i64 positions; the angles are rope_bf16's exactly | qwen35_fp8, qwen4exp_fp8 |
|
||||||
|
| `router_gemm_topk_scatter` | yes | router_gemm_topk_scatter_bf16 | bf16 activation and weights, fp32 accumulate; bf16 logits, gate and weights, i32 ids, sorted slots, offsets and counts out | common, gemma4 |
|
||||||
|
| `router_sigmoid_topk` | yes | router_sigmoid_topk_f32 | f32 logits, bias and weights; i32 ids | common |
|
||||||
|
| `router_sigmoid_topk_scatter` | no | router_sigmoid_topk_scatter_f32 | f32 logits, bias and weights; i32 ids, sorted slots, offsets and counts; bf16 gate | common |
|
||||||
|
| `router_topk` | yes | router_topk_bf16 | bf16 in, bf16 weights + i32 expert ids out | common, gemma4 |
|
||||||
|
| `router_topk_scatter` | yes | router_topk_scatter_bf16 | bf16 in, bf16 weights + i32 ids, sorted slots, offsets and counts out | common, gemma4 |
|
||||||
|
| `row_topk` | yes | rowtopk_bf16 | bf16 in, f32 values + i32 columns out | common |
|
||||||
|
| `row_topk_merge` | yes | rowtopk_merge | f32 pairs in, f32 values + i32 ids out, ties to the lower id | common |
|
||||||
|
| `rvq_embed` | yes | rvq_embed_bf16 | bf16 tables and rows | breeze, minimaxmusic3 |
|
||||||
|
| `s2d3d` | yes | s2d3d | bf16 or f32 x and y, i32 geom | ltx2 |
|
||||||
|
| `s2d_avg_add` | yes | s2d_avg_add_bf16 | bf16 | common, flux3 |
|
||||||
|
| `sam_attn` | yes | sam_attn_bf16 | bf16 query / key / value / out and rel_pos tables, i32 cu_seqlens, fp32 accumulate | common |
|
||||||
|
| `sample_argmax` | yes | sample_argmax_f32 | f32 logits, i32 token | -- |
|
||||||
|
| `sample_chain` | no | sample_chain_f32 | f32 logits, f32 uniforms (two a position), u32 query tokens or absent, {u32 tok, u32 tok_excl, f32 p_query} out | -- |
|
||||||
|
| `sample_dry` | yes | sample_dry_f32 | f32 logits in place, i32 history, optional u8 breaker plane, per-row params | -- |
|
||||||
|
| `sample_logprobs` | yes | sample_logprobs_f32 | f32 logits, f32 stats [M, 2 + 2k] with the ids as floats | -- |
|
||||||
|
| `sample_mask` | yes | sample_mask_f32 | f32 logits in place, u32 bitmask, per-row params | -- |
|
||||||
|
| `sample_merge_topk` | yes | sample_merge_topk_f32 | u32 (id, logit-bits) pairs in, i32 candidate ids and f32 candidate logits out | -- |
|
||||||
|
| `sample_minp` | yes | sample_minp_f32 | i32 candidate ids and f32 candidate logits, both in place | -- |
|
||||||
|
| `sample_ngram_ban` | yes | sample_ngram_ban_f32 | f32 logits in place, i32 history, i32 {n, window} per-row pair | -- |
|
||||||
|
| `sample_penalties` | yes | sample_penalties_f32 | f32 logits in place, i32 history, per-row params | -- |
|
||||||
|
| `sample_pick` | yes | sample_pick_f32 | i32 candidate ids, f32 candidate logits, i32 token | -- |
|
||||||
|
| `sample_temp` | yes | sample_temp_f32 | f32 logits in place, per-row params | -- |
|
||||||
|
| `sample_topk` | yes | sample_topk_f32 | f32 logits, i32 candidate ids, f32 candidate LOGITS (not probabilities) | -- |
|
||||||
|
| `sample_topp` | yes | sample_topp_f32 | i32 candidate ids and f32 candidate logits, both in place | -- |
|
||||||
|
| `sample_typical` | yes | sample_typical_f32 | i32 candidate ids and f32 candidate logits, both in place | -- |
|
||||||
|
| `sample_xtc` | yes | sample_xtc_f32 | i32 candidate ids and f32 candidate logits, both in place | -- |
|
||||||
|
| `scale` | yes | scale_bf16 | bf16 in and out, fp32 arithmetic, s f32 or bf16 | anima, breeze, common, embgemma2, flux3, gemma3, gemma4, gemma4_bf16, krea2, lfm2_bf16, ltx2, minimaxh3, minimaxmusic3, qwen35_fp8, qwen3asr_bf16, qwen4exp_fp8, qwenimage21, sdxl |
|
||||||
|
| `scale_rows` | yes | scale_rows_bf16 | bf16 in and out, fp32 arithmetic | -- |
|
||||||
|
| `scatter_add_rows` | yes | scatter_add_rows_bf16 | bf16 | qwenimage21 |
|
||||||
|
| `scatter_rows` | yes | scatter_rows_bf16, scatter_rows_u8 | i32 indices, bf16 rows; i32 indices, u8 rows | breeze, common, embgemma2, flux3, gemma4_bf16, krea2, minimaxmusic3, qwenimage21, unlimitedocr_bf16 |
|
||||||
|
| `seg_mean` | yes | seg_mean_bf16 | bf16 in and out, f64 sum, one rounding | embgemma2 |
|
||||||
|
| `seg_sinusoid` | yes | seg_sinusoid_bf16 | bf16 out, i32 cu_seqlens, f32 libm sin / cos / exp | qwen3asr_bf16 |
|
||||||
|
| `sigmoid` | yes | sigmoid_bf16 | bf16 in and out, fp32 arithmetic | common, embgemma2, krea2, qwen4exp_fp8 |
|
||||||
|
| `silu` | yes | silu_bf16, silu_f32 | bf16 in and out, fp32 arithmetic; f32 in, f32 out or bf16 rounded once | anima, common, embgemma2, flux3, gemma4_bf16, krea2, ltx2, minimaxh3, minimaxmusic3, qwen4exp_fp8, qwenimage21, sdxl |
|
||||||
|
| `silu_mul` | yes | silu_mul_bf16 | bf16 in and out, fp32 arithmetic | breeze, common, ltx2, minimaxh3, unlimitedocr_bf16 |
|
||||||
|
| `snake` | yes | snake_bf16 | bf16 rows, f32 alpha | breeze, minimaxmusic3 |
|
||||||
|
| `snake_aa` | yes | snake_aa_f32 | f32 rows, filters, alpha and beta | ltx2, minimaxh3 |
|
||||||
|
| `softmax` | yes | -- | | unlimitedocr_bf16 |
|
||||||
|
| `stft_logmel` | yes | stft_logmel | bf16 or f32 operands | ltx2 |
|
||||||
|
| `swiglu_clamped` | yes | swiglu_clamped_bf16 | bf16 in and out, fp32 arithmetic | common |
|
||||||
|
| `swiglu_clamped_quant_fp8` | no | swiglu_clamped_quant_fp8 | bf16 in, E4M3 out with an f32 scale per (row, 128 columns) and an optional bf16 out; the codes are taken over the BF16-ROUNDED product | common |
|
||||||
|
| `table_add` | yes | table_add_bf16 | bf16 | krea2, ltx2 |
|
||||||
|
| `tconv_dw` | yes | tconv_dw_bf16 | bf16 voxels, weight and bias, fp32 accumulate | minimaxh3 |
|
||||||
|
| `tile_crop` | yes | tile_crop | bf16 or f32 x and y, i32 geom and box | ltx2 |
|
||||||
|
| `tile_grid` | yes | tile_grid | i32 | ltx2 |
|
||||||
|
| `tile_stitch` | yes | tile_stitch | bf16 or f32 x, u8 y, i32 geom and first | ltx2 |
|
||||||
|
| `timestep_embed` | yes | timestep_embed_bf16, timestep_embed_f32 | bf16; f32 t and out, f32 angles | anima, flux3, krea2, ltx2, minimaxh3, qwenimage21, sdxl |
|
||||||
|
| `to_rgba8` | yes | to_rgba8_bf16 | bf16 | anima, flux3, krea2, qwenimage21, sdxl |
|
||||||
|
| `vol_index` | yes | vol_index | i32 | ltx2 |
|
||||||
|
| `vsa_select` | yes | vsa_select_h128_bf16 | bf16 q / k / v / coarse, i32 segs / geom / sel; f32 means, scores and softmax | minimaxh3 |
|
||||||
|
| `vtile_gather` | yes | vtile_gather | bf16 or f32 rows and registers | minimaxh3 |
|
||||||
|
| `vtile_stitch` | yes | vtile_stitch | bf16 or f32 tiles and overlap, u8 out | minimaxh3 |
|
||||||
|
| `win_finish` | yes | win_finish_bf16 | bf16 states | minimaxmusic3 |
|
||||||
|
| `win_input` | yes | win_input_bf16 | bf16 | minimaxmusic3 |
|
||||||
|
| `win_prep` | yes | win_prep_bf16 | bf16 states, f32 t | minimaxmusic3 |
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
# 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`.**
|
||||||
|
`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`). "The HIP build must still compile"
|
||||||
|
cannot be checked here; it needs a ROCm host or a ROCm container (the repo's `Dockerfile` may
|
||||||
|
serve). Until then, HIP-side edits are kept to a minimum and listed below for review.
|
||||||
|
|
||||||
|
## 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`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
~/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 `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.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
None yet.
|
||||||
|
|
||||||
|
## Reproduce the current state
|
||||||
|
|
||||||
|
```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):
|
||||||
|
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
|
||||||
|
```
|
||||||
@@ -55,3 +55,13 @@ output. `mcagent.sh` and `mcdecl.sh` start their own MiniCPM5-2B server through
|
|||||||
| `mcstream.sh` | Tool-call replies streamed, asserting on raw SSE fragments rather than the assembled message. Streamed content cannot be retracted, so a repair applied at the end is not a fix. |
|
| `mcstream.sh` | Tool-call replies streamed, asserting on raw SSE fragments rather than the assembled message. Streamed content cannot be retracted, so a repair applied at the end is not a fix. |
|
||||||
| `mcagent.sh` | What speculation is worth on an agentic workload: `/v1/chat/completions` with tools, a constrained decode. Speculation on and off alternate across restarts because the speculation depth is a server-level setting. |
|
| `mcagent.sh` | What speculation is worth on an agentic workload: `/v1/chat/completions` with tools, a constrained decode. Speculation on and off alternate across restarts because the speculation depth is a server-level setting. |
|
||||||
| `mcdecl.sh` | How often the drafter proposes, by context length. `draft_acceptance_ratio` is conditional on having drafted, so it can look healthy while tokens per step collapse; blocks per step separates the two. |
|
| `mcdecl.sh` | How often the drafter proposes, by context length. `draft_acceptance_ratio` is conditional on having drafted, so it can look healthy while tokens per step collapse; blocks per step separates the two. |
|
||||||
|
|
||||||
|
## The Intel (SYCL) backend
|
||||||
|
|
||||||
|
Tools for the port in `docs/SYCL_PORTING.md`; its log is `docs/SYCL_PROGRESS.md`. They need oneAPI
|
||||||
|
(`. /opt/intel/oneapi/setvars.sh`) only where they compile device code.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| `sycl/probe.sh` | The card's limits, sub-group sizes and `joint_matrix` combinations, and whether XMX executes E4M3 / E5M2 DPAS, each checked against a host loop with bf16 and s8 DPAS as controls in the same harness (on the Arc Pro B65 fp8 DPAS compiles and returns garbage). |
|
||||||
|
| `sycl/op_inventory.sh` | The op vocabulary as a markdown table: libref's schemas, libr4d's kernels and dtypes per op (its rows read from source by `sycl/r4d_rows.py`, since a build without HIP has no `libr4d.so`), and which architectures name each op. |
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
// Phase 0 device probe: limits, aspects, sub-groups, joint_matrix combinations, and a
|
||||||
|
// numerical check of which XMX element types actually execute on the device.
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace syclex = sycl::ext::oneapi::experimental;
|
||||||
|
namespace jm = sycl::ext::oneapi::experimental::matrix;
|
||||||
|
|
||||||
|
static const char *mt(jm::matrix_type t) {
|
||||||
|
switch (t) {
|
||||||
|
case jm::matrix_type::bf16: return "bf16";
|
||||||
|
case jm::matrix_type::fp16: return "fp16";
|
||||||
|
case jm::matrix_type::tf32: return "tf32";
|
||||||
|
case jm::matrix_type::fp32: return "fp32";
|
||||||
|
case jm::matrix_type::fp64: return "fp64";
|
||||||
|
case jm::matrix_type::sint8: return "s8";
|
||||||
|
case jm::matrix_type::uint8: return "u8";
|
||||||
|
case jm::matrix_type::sint32: return "s32";
|
||||||
|
case jm::matrix_type::uint32: return "u32";
|
||||||
|
default: return "other";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// One sub-group computes C[M x N] = A[M x K] * B[K x N] with joint_matrix, compared with a host loop.
|
||||||
|
template <typename Ta, typename Tc, size_t M, size_t N, size_t K>
|
||||||
|
static double jm_test(sycl::queue &q, const char *name) {
|
||||||
|
std::vector<Ta> a(M * K), b(K * N);
|
||||||
|
std::vector<Tc> c(M * N, 0);
|
||||||
|
std::vector<double> ref(M * N, 0);
|
||||||
|
for (size_t i = 0; i < M * K; i++) a[i] = Ta(float(int(i * 7 % 11) - 5) * 0.25f);
|
||||||
|
for (size_t i = 0; i < K * N; i++) b[i] = Ta(float(int(i * 5 % 13) - 6) * 0.5f);
|
||||||
|
for (size_t m = 0; m < M; m++)
|
||||||
|
for (size_t n = 0; n < N; n++)
|
||||||
|
for (size_t k = 0; k < K; k++) ref[m * N + n] += double(float(a[m * K + k])) * double(float(b[k * N + n]));
|
||||||
|
Ta *da = sycl::malloc_device<Ta>(M * K, q), *db = sycl::malloc_device<Ta>(K * N, q);
|
||||||
|
Tc *dc = sycl::malloc_device<Tc>(M * N, q);
|
||||||
|
q.memcpy(da, a.data(), sizeof(Ta) * M * K);
|
||||||
|
q.memcpy(db, b.data(), sizeof(Ta) * K * N);
|
||||||
|
q.memset(dc, 0, sizeof(Tc) * M * N).wait();
|
||||||
|
try {
|
||||||
|
q.parallel_for(sycl::nd_range<1>{16, 16}, [=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(16)]] {
|
||||||
|
auto sg = it.get_sub_group();
|
||||||
|
jm::joint_matrix<sycl::sub_group, Ta, jm::use::a, M, K, jm::layout::row_major> ma;
|
||||||
|
jm::joint_matrix<sycl::sub_group, Ta, jm::use::b, K, N, jm::layout::row_major> mb;
|
||||||
|
jm::joint_matrix<sycl::sub_group, Tc, jm::use::accumulator, M, N> mc;
|
||||||
|
jm::joint_matrix_fill(sg, mc, Tc(0));
|
||||||
|
auto pa = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(da);
|
||||||
|
auto pb = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(db);
|
||||||
|
auto pc = sycl::address_space_cast<sycl::access::address_space::global_space, sycl::access::decorated::no>(dc);
|
||||||
|
jm::joint_matrix_load(sg, ma, pa, K);
|
||||||
|
jm::joint_matrix_load(sg, mb, pb, N);
|
||||||
|
jm::joint_matrix_mad(sg, mc, ma, mb, mc);
|
||||||
|
jm::joint_matrix_store(sg, mc, pc, N, jm::layout::row_major);
|
||||||
|
}).wait_and_throw();
|
||||||
|
} catch (sycl::exception &e) {
|
||||||
|
printf(" jm %-28s FAILED: %s\n", name, e.what());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
q.memcpy(c.data(), dc, sizeof(Tc) * M * N).wait();
|
||||||
|
double maxerr = 0;
|
||||||
|
for (size_t i = 0; i < M * N; i++) maxerr = std::fmax(maxerr, std::fabs(double(c[i]) - ref[i]));
|
||||||
|
printf(" jm %-28s M%zu N%zu K%zu max|err|=%g\n", name, M, N, K, maxerr);
|
||||||
|
sycl::free(da, q); sycl::free(db, q); sycl::free(dc, q);
|
||||||
|
return maxerr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
|
||||||
|
auto d = q.get_device();
|
||||||
|
printf("device: %s\n", d.get_info<sycl::info::device::name>().c_str());
|
||||||
|
printf("backend: %s driver: %s\n",
|
||||||
|
d.get_backend() == sycl::backend::ext_oneapi_level_zero ? "level_zero" : "other",
|
||||||
|
d.get_info<sycl::info::device::driver_version>().c_str());
|
||||||
|
printf("max_compute_units: %u\n", d.get_info<sycl::info::device::max_compute_units>());
|
||||||
|
printf("max_work_group_size: %zu\n", d.get_info<sycl::info::device::max_work_group_size>());
|
||||||
|
printf("sub_group_sizes:");
|
||||||
|
for (auto s : d.get_info<sycl::info::device::sub_group_sizes>()) printf(" %zu", s);
|
||||||
|
printf("\nlocal_mem_size: %llu\n", (unsigned long long)d.get_info<sycl::info::device::local_mem_size>());
|
||||||
|
printf("global_mem_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info<sycl::info::device::global_mem_size>(),
|
||||||
|
d.get_info<sycl::info::device::global_mem_size>() / 1073741824.0);
|
||||||
|
printf("max_mem_alloc_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info<sycl::info::device::max_mem_alloc_size>(),
|
||||||
|
d.get_info<sycl::info::device::max_mem_alloc_size>() / 1073741824.0);
|
||||||
|
printf("max_clock_frequency: %u MHz\n", d.get_info<sycl::info::device::max_clock_frequency>());
|
||||||
|
printf("global_mem_cache_size: %llu\n", (unsigned long long)d.get_info<sycl::info::device::global_mem_cache_size>());
|
||||||
|
printf("aspects: fp16=%d fp64=%d usm_device=%d usm_host=%d usm_shared=%d usm_system=%d atomic64=%d intel_matrix=%d\n",
|
||||||
|
d.has(sycl::aspect::fp16), d.has(sycl::aspect::fp64), d.has(sycl::aspect::usm_device_allocations),
|
||||||
|
d.has(sycl::aspect::usm_host_allocations), d.has(sycl::aspect::usm_shared_allocations),
|
||||||
|
d.has(sycl::aspect::usm_system_allocations), d.has(sycl::aspect::atomic64),
|
||||||
|
d.has(sycl::aspect::ext_intel_matrix));
|
||||||
|
try {
|
||||||
|
auto arch = d.get_info<syclex::info::device::architecture>();
|
||||||
|
printf("architecture enum: %d (bmg_g31=%d)\n", int(arch), int(syclex::architecture::intel_gpu_bmg_g31));
|
||||||
|
} catch (...) { printf("architecture: query failed\n"); }
|
||||||
|
|
||||||
|
printf("matrix_combinations:\n");
|
||||||
|
try {
|
||||||
|
auto combos = d.get_info<syclex::info::device::matrix_combinations>();
|
||||||
|
for (auto &c : combos)
|
||||||
|
printf(" A=%s B=%s C=%s D=%s M=%zu N=%zu K=%zu (max M %zu N %zu K %zu)\n", mt(c.atype), mt(c.btype),
|
||||||
|
mt(c.ctype), mt(c.dtype), c.msize, c.nsize, c.ksize, c.max_msize, c.max_nsize, c.max_ksize);
|
||||||
|
if (combos.empty()) printf(" (none)\n");
|
||||||
|
} catch (sycl::exception &e) { printf(" query failed: %s\n", e.what()); }
|
||||||
|
|
||||||
|
printf("joint_matrix execution checks:\n");
|
||||||
|
jm_test<sycl::ext::oneapi::bfloat16, float, 8, 16, 16>(q, "bf16 x bf16 -> f32");
|
||||||
|
jm_test<sycl::half, float, 8, 16, 16>(q, "fp16 x fp16 -> f32");
|
||||||
|
jm_test<int8_t, int32_t, 8, 16, 32>(q, "s8 x s8 -> s32");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// Does Xe2 (BMG) XMX execute FP8 DPAS? One ESIMD work-item does C[8x16] = A[8x32] * B[32x16]
|
||||||
|
// with A and B as E4M3 (hf8) or E5M2 (bf8) bytes, checked against a host reference. A bf16
|
||||||
|
// DPAS of the same values (K=16, two halves) runs first as a control.
|
||||||
|
#include <sycl/sycl.hpp>
|
||||||
|
#include <sycl/ext/intel/esimd.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace sycl::ext::intel::esimd;
|
||||||
|
namespace xmx = sycl::ext::intel::esimd::xmx;
|
||||||
|
|
||||||
|
constexpr int M = 8, N = 16, K = 32;
|
||||||
|
|
||||||
|
static uint8_t enc(float v, int ebits) { // exact values only
|
||||||
|
int mbits = 7 - ebits, bias = (1 << (ebits - 1)) - 1;
|
||||||
|
if (v == 0) return 0;
|
||||||
|
uint8_t s = v < 0 ? 0x80 : 0;
|
||||||
|
float a = std::fabs(v);
|
||||||
|
int e = int(std::floor(std::log2(a)));
|
||||||
|
int m = int(std::lround((a / std::ldexp(1.f, e) - 1.f) * (1 << mbits)));
|
||||||
|
return s | uint8_t((e + bias) << mbits) | uint8_t(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <xmx::dpas_argument_type P>
|
||||||
|
static void run(sycl::queue &q, const char *name, int ebits) {
|
||||||
|
std::vector<float> af(M * K), bf(K * N);
|
||||||
|
const float vals[] = {-2, -1.5f, -1, -0.5f, 0, 0.5f, 1, 1.5f, 2};
|
||||||
|
for (int i = 0; i < M * K; i++) af[i] = vals[(i * 7 + 3) % 9];
|
||||||
|
for (int i = 0; i < K * N; i++) bf[i] = vals[(i * 5 + 1) % 9];
|
||||||
|
std::vector<uint8_t> a8(M * K), b8(K * N);
|
||||||
|
for (int i = 0; i < M * K; i++) a8[i] = enc(af[i], ebits);
|
||||||
|
for (int k = 0; k < K; k++) // VNNI: [K/4][N][4]
|
||||||
|
for (int n = 0; n < N; n++) b8[(k / 4) * N * 4 + n * 4 + (k % 4)] = enc(bf[k * N + n], ebits);
|
||||||
|
std::vector<double> ref(M * N, 0);
|
||||||
|
for (int m = 0; m < M; m++)
|
||||||
|
for (int n = 0; n < N; n++)
|
||||||
|
for (int k = 0; k < K; k++) ref[m * N + n] += af[m * K + k] * bf[k * N + n];
|
||||||
|
|
||||||
|
uint8_t *da = sycl::malloc_device<uint8_t>(M * K, q), *db = sycl::malloc_device<uint8_t>(K * N, q);
|
||||||
|
float *dc = sycl::malloc_device<float>(M * N, q);
|
||||||
|
q.memcpy(da, a8.data(), M * K).wait();
|
||||||
|
q.memcpy(db, b8.data(), K * N).wait();
|
||||||
|
try {
|
||||||
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
||||||
|
simd<uint8_t, M * K> A = block_load<uint8_t, M * K>(da);
|
||||||
|
simd<uint8_t, K * N> B = block_load<uint8_t, K * N>(db);
|
||||||
|
simd<float, M * N> C = 0;
|
||||||
|
C = xmx::dpas<8, M, float, float, uint8_t, uint8_t, P, P>(C, B, A);
|
||||||
|
block_store<float, M * N>(dc, C);
|
||||||
|
}).wait_and_throw();
|
||||||
|
} catch (sycl::exception &e) {
|
||||||
|
printf("%-6s DPAS FAILED: %s\n", name, e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<float> c(M * N);
|
||||||
|
q.memcpy(c.data(), dc, sizeof(float) * M * N).wait();
|
||||||
|
double err = 0;
|
||||||
|
for (int i = 0; i < M * N; i++) err = std::fmax(err, std::fabs(c[i] - ref[i]));
|
||||||
|
printf("%-6s DPAS M8 N16 K32 -> f32: max|err| = %g (c[0]=%g ref=%g)\n", name, err, c[0], ref[0]);
|
||||||
|
sycl::free(da, q); sycl::free(db, q); sycl::free(dc, q);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controls with the same harness: bf16 (K=16, VNNI pairs) -> f32 and s8 (K=32) -> s32.
|
||||||
|
static void ctl_bf16(sycl::queue &q) {
|
||||||
|
using bf = sycl::ext::oneapi::bfloat16;
|
||||||
|
constexpr int KB = 16;
|
||||||
|
const float vals[] = {-2, -1.5f, -1, -0.5f, 0, 0.5f, 1, 1.5f, 2};
|
||||||
|
std::vector<bf> a(M * KB), b(KB * N);
|
||||||
|
std::vector<double> ref(M * N, 0);
|
||||||
|
for (int i = 0; i < M * KB; i++) a[i] = vals[(i * 7 + 3) % 9];
|
||||||
|
std::vector<float> bfv(KB * N);
|
||||||
|
for (int i = 0; i < KB * N; i++) bfv[i] = vals[(i * 5 + 1) % 9];
|
||||||
|
for (int k = 0; k < KB; k++)
|
||||||
|
for (int n = 0; n < N; n++) b[(k / 2) * N * 2 + n * 2 + (k % 2)] = bfv[k * N + n];
|
||||||
|
for (int m = 0; m < M; m++) for (int n = 0; n < N; n++) for (int k = 0; k < KB; k++)
|
||||||
|
ref[m * N + n] += float(a[m * KB + k]) * bfv[k * N + n];
|
||||||
|
bf *da = sycl::malloc_device<bf>(M * KB, q), *db = sycl::malloc_device<bf>(KB * N, q);
|
||||||
|
float *dc = sycl::malloc_device<float>(M * N, q);
|
||||||
|
q.memcpy(da, a.data(), sizeof(bf) * M * KB).wait();
|
||||||
|
q.memcpy(db, b.data(), sizeof(bf) * KB * N).wait();
|
||||||
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
||||||
|
simd<bf, M * KB> A = block_load<bf, M * KB>(da);
|
||||||
|
simd<bf, KB * N> B = block_load<bf, KB * N>(db);
|
||||||
|
simd<float, M * N> C = 0;
|
||||||
|
C = xmx::dpas<8, M, float, float, bf, bf>(C, B, A);
|
||||||
|
block_store<float, M * N>(dc, C);
|
||||||
|
}).wait();
|
||||||
|
std::vector<float> c(M * N);
|
||||||
|
q.memcpy(c.data(), dc, sizeof(float) * M * N).wait();
|
||||||
|
double err = 0;
|
||||||
|
for (int i = 0; i < M * N; i++) err = std::fmax(err, std::fabs(c[i] - ref[i]));
|
||||||
|
printf("bf16 DPAS M8 N16 K16 -> f32: max|err| = %g (c[0]=%g ref=%g)\n", err, c[0], ref[0]);
|
||||||
|
}
|
||||||
|
static void ctl_s8(sycl::queue &q) {
|
||||||
|
std::vector<int8_t> a(M * K), b(K * N);
|
||||||
|
std::vector<int> bv(K * N); std::vector<long> ref(M * N, 0);
|
||||||
|
for (int i = 0; i < M * K; i++) a[i] = int8_t((i * 7 + 3) % 9 - 4);
|
||||||
|
for (int i = 0; i < K * N; i++) bv[i] = (i * 5 + 1) % 9 - 4;
|
||||||
|
for (int k = 0; k < K; k++) for (int n = 0; n < N; n++) b[(k / 4) * N * 4 + n * 4 + (k % 4)] = int8_t(bv[k * N + n]);
|
||||||
|
for (int m = 0; m < M; m++) for (int n = 0; n < N; n++) for (int k = 0; k < K; k++) ref[m * N + n] += a[m * K + k] * bv[k * N + n];
|
||||||
|
int8_t *da = sycl::malloc_device<int8_t>(M * K, q), *db = sycl::malloc_device<int8_t>(K * N, q);
|
||||||
|
int *dc = sycl::malloc_device<int>(M * N, q);
|
||||||
|
q.memcpy(da, a.data(), M * K).wait();
|
||||||
|
q.memcpy(db, b.data(), K * N).wait();
|
||||||
|
q.parallel_for(sycl::range<1>{1}, [=](sycl::id<1>) SYCL_ESIMD_KERNEL {
|
||||||
|
simd<int8_t, M * K> A = block_load<int8_t, M * K>(da);
|
||||||
|
simd<int8_t, K * N> B = block_load<int8_t, K * N>(db);
|
||||||
|
simd<int, M * N> C = 0;
|
||||||
|
C = xmx::dpas<8, M, int, int, int8_t, int8_t>(C, B, A);
|
||||||
|
block_store<int, M * N>(dc, C);
|
||||||
|
}).wait();
|
||||||
|
std::vector<int> c(M * N);
|
||||||
|
q.memcpy(c.data(), dc, sizeof(int) * M * N).wait();
|
||||||
|
long err = 0;
|
||||||
|
for (int i = 0; i < M * N; i++) err = std::max(err, std::labs(c[i] - ref[i]));
|
||||||
|
printf("s8 DPAS M8 N16 K32 -> s32: max|err| = %ld (c[0]=%d ref=%ld)\n", err, c[0], ref[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
sycl::queue q{sycl::gpu_selector_v};
|
||||||
|
printf("device: %s\n", q.get_device().get_info<sycl::info::device::name>().c_str());
|
||||||
|
run<xmx::dpas_argument_type::hf8>(q, "e4m3", 4);
|
||||||
|
run<xmx::dpas_argument_type::bf8>(q, "e5m2", 5);
|
||||||
|
ctl_bf16(q);
|
||||||
|
ctl_s8(q);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# op_inventory.sh -- the op vocabulary as a markdown table, for docs/SYCL_PORTING.md.
|
||||||
|
#
|
||||||
|
# One row per op that libref or libr4d declares: whether libref has it (the oracle), the libr4d
|
||||||
|
# kernels that implement it (from the kKernels rows in libr4d/r4d_rows.cpp, read as source because a
|
||||||
|
# build without HIP has no libr4d.so), the dtypes those rows state, and the architecture plugins
|
||||||
|
# whose source names the op. "Architectures naming it" is a grep, so it over-counts an op a plugin
|
||||||
|
# names only conditionally; --debug-graph on a real container is the exact answer for one model.
|
||||||
|
#
|
||||||
|
# Usage: scripts/sycl/op_inventory.sh [BUILD_DIR] (default build/)
|
||||||
|
set -e
|
||||||
|
root=$(cd "$(dirname "$0")/../.." && pwd)
|
||||||
|
build=${1:-$root/build}
|
||||||
|
tmp=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
|
||||||
|
RADIANCE_HOME=$build/radiance_home "$build/bin/rad-schemas" "$build/radiance_home/kernels/libref.so" |
|
||||||
|
awk '/^ [a-z0-9_]+$/ {print $1}' | sort -u > "$tmp/libref"
|
||||||
|
|
||||||
|
python3 -I "$root/scripts/sycl/r4d_rows.py" "$root/libr4d/r4d_rows.cpp" | sort > "$tmp/r4d"
|
||||||
|
|
||||||
|
cut -f1 "$tmp/r4d" | sort -u > "$tmp/r4d_ops"
|
||||||
|
sort -u "$tmp/libref" "$tmp/r4d_ops" > "$tmp/all"
|
||||||
|
|
||||||
|
echo "| op | libref | libr4d kernels | libr4d dtypes (first three rows' prose) | architectures naming it |"
|
||||||
|
echo "|---|---|---|---|---|"
|
||||||
|
while read -r op; do
|
||||||
|
ref=no; grep -qx "$op" "$tmp/libref" && ref=yes
|
||||||
|
kern=$(awk -F'\t' -v o="$op" '$1 == o {print $2}' "$tmp/r4d" | tr '\n' ' ' | sed 's/ $//; s/ /, /g')
|
||||||
|
dts=$(awk -F'\t' -v o="$op" '$1 == o && $3 != "" {print $3}' "$tmp/r4d" | sort -u | head -3 |
|
||||||
|
tr '\n' ';' | sed 's/;$//; s/;/; /g; s/|/\\|/g')
|
||||||
|
archs=$(grep -rlw --include=*.cpp --include=*.h -e "\"$op\"" "$root/arch" 2>/dev/null |
|
||||||
|
sed "s#$root/arch/##; s#/.*##" | sort -u | tr '\n' ' ' | sed 's/ $//; s/ /, /g')
|
||||||
|
[ -z "$kern" ] && kern="--"
|
||||||
|
[ -z "$archs" ] && archs="--"
|
||||||
|
echo "| \`$op\` | $ref | $kern | $dts | $archs |"
|
||||||
|
done < "$tmp/all"
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# probe.sh -- Phase 0 device checks for the Intel (SYCL / Level Zero) backend; see docs/SYCL_PROGRESS.md.
|
||||||
|
# devprobe: limits, aspects, sub-group sizes, joint_matrix combinations and three joint_matrix runs
|
||||||
|
# dpas_fp8: whether XMX executes E4M3 / E5M2 DPAS, against bf16 and s8 DPAS controls in the same harness
|
||||||
|
# Usage: scripts/sycl/probe.sh [OUTDIR] (needs oneAPI; sources setvars.sh if icpx is not on PATH)
|
||||||
|
set -e
|
||||||
|
here=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
out=${1:-${TMPDIR:-/tmp}/rad-sycl-probe}
|
||||||
|
mkdir -p "$out"
|
||||||
|
command -v icpx >/dev/null || . /opt/intel/oneapi/setvars.sh >/dev/null
|
||||||
|
icpx -fsycl -O2 "$here/devprobe.cpp" -o "$out/devprobe"
|
||||||
|
icpx -fsycl -O2 -fsycl-targets=spir64_gen -Xs "-device bmg-g31" "$here/dpas_fp8.cpp" -o "$out/dpas_fp8"
|
||||||
|
"$out/devprobe"
|
||||||
|
"$out/dpas_fp8"
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
"""r4d_rows.py ROWS_CPP -- the kKernels rows of libr4d/r4d_rows.cpp as TSV: op, kernel, dtypes, domain.
|
||||||
|
|
||||||
|
Read as source because a build without HIP has no libr4d.so to ask. A row is
|
||||||
|
{ "kernel", "op", "family", "computes", "shape", "dtypes", RAD_DOMAIN_..., ... }; adjacent string
|
||||||
|
literals are joined as the C compiler joins them, so a dtypes string split over lines stays whole.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
src = open(sys.argv[1], encoding="utf-8").read()
|
||||||
|
start = src.index("static const RadKernelInfo kKernels[] = {")
|
||||||
|
body = src[start:]
|
||||||
|
# Comments out, so prose in them cannot look like a row.
|
||||||
|
body = re.sub(r"/\*.*?\*/", " ", body, flags=re.S)
|
||||||
|
body = re.sub(r"//[^\n]*", " ", body)
|
||||||
|
|
||||||
|
body = body.replace("\\\n", "\n") # macro line continuations
|
||||||
|
|
||||||
|
lit = r'"(?:[^"\\]|\\.)*"'
|
||||||
|
# Between literals a row may splice in a macro: R4D_XSTR(X), a stringised #PARAM, or a name such as
|
||||||
|
# KVDOC. Each is kept as <NAME>, so a template row's kernel reads attn_window_h<HD>_gqa<G>_<KVN>.
|
||||||
|
mac = r"R4D_XSTR\(\s*\w+\s*\)|#\w+|\b(?!RAD_DOMAIN_)[A-Z][A-Z0-9_]*\b"
|
||||||
|
row_re = re.compile(r"\{\s*((?:(?:" + lit + "|" + mac + r")\s*,?\s*)+?)(RAD_DOMAIN_[A-Z]+)")
|
||||||
|
for m in row_re.finditer(body):
|
||||||
|
if not m.group(1).lstrip().startswith('"'):
|
||||||
|
continue
|
||||||
|
# Split the run into arguments at commas; join adjacent literals and macros within one.
|
||||||
|
args, cur = [], []
|
||||||
|
for tok in re.finditer(lit + "|" + mac + r"|,", m.group(1)):
|
||||||
|
t = tok.group(0)
|
||||||
|
if t == ",":
|
||||||
|
args.append("".join(cur))
|
||||||
|
cur = []
|
||||||
|
elif t.startswith('"'):
|
||||||
|
cur.append(re.sub(r"\\(.)", r"\1", t[1:-1]))
|
||||||
|
else:
|
||||||
|
name = re.sub(r"^R4D_XSTR\(\s*|\s*\)$|^#", "", t)
|
||||||
|
cur.append(f"<{name}>")
|
||||||
|
if cur:
|
||||||
|
args.append("".join(cur))
|
||||||
|
if len(args) < 6:
|
||||||
|
continue
|
||||||
|
kern, op, dtypes = args[0], args[1], " ".join(args[5].split())
|
||||||
|
print(f"{op}\t{kern}\t{dtypes}\t{m.group(2)[len('RAD_DOMAIN_'):].lower()}")
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# The parts of radiance compiled by icpx: the SYCL device backend (librad_sycl.so) and, later, the
|
||||||
|
# Intel kernel library. The main project builds this directory through ExternalProject with icpx
|
||||||
|
# as the C++ compiler (top-level CMakeLists.txt, RAD_SYCL), so the engine and every host plugin
|
||||||
|
# stay on the main project's compiler (docs/SYCL_PORTING.md §4.5, docs/SYCL_PROGRESS.md D6).
|
||||||
|
cmake_minimum_required(VERSION 3.21)
|
||||||
|
project(radiance_sycl LANGUAGES CXX)
|
||||||
|
|
||||||
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
||||||
|
message(FATAL_ERROR "sycl/ is built by icpx (IntelLLVM); this configure has "
|
||||||
|
"${CMAKE_CXX_COMPILER_ID} at ${CMAKE_CXX_COMPILER}.")
|
||||||
|
endif()
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(RAD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." CACHE PATH "the radiance checkout")
|
||||||
|
set(RAD_SYCL_TARGETS "intel_gpu_bmg_g31" CACHE STRING "AOT targets for SYCL device code")
|
||||||
|
|
||||||
|
# The same warnings as the main build. icpx defaults to -fp-model=fast; host code here is precise
|
||||||
|
# as the main build's is, and device code keeps the main build's -ffp-contract=off discipline in
|
||||||
|
# the kernels themselves.
|
||||||
|
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
|
||||||
|
-ffp-model=precise)
|
||||||
|
set(RAD_SYCL_FLAGS -fsycl "-fsycl-targets=${RAD_SYCL_TARGETS}")
|
||||||
|
|
||||||
|
# The oneAPI runtime libraries sit beside the compiler; record their directory so the engine runs
|
||||||
|
# without setvars.sh in its environment.
|
||||||
|
get_filename_component(_icpx_bin "${CMAKE_CXX_COMPILER}" DIRECTORY)
|
||||||
|
get_filename_component(RAD_ONEAPI_LIBDIR "${_icpx_bin}/../lib" ABSOLUTE)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- the device backend
|
||||||
|
# The backend, and the core's own kernels under it (the step's advance, the weight-table patches),
|
||||||
|
# each the SYCL twin of a .hip the AMD build compiles. The engine calls the kernels' launchers by
|
||||||
|
# the same names on either backend.
|
||||||
|
add_library(rad_sycl SHARED
|
||||||
|
${RAD_SOURCE_DIR}/core/device/sycl.cpp
|
||||||
|
${RAD_SOURCE_DIR}/core/device/sycl_host.cpp
|
||||||
|
${RAD_SOURCE_DIR}/core/sched/advance_sycl.cpp
|
||||||
|
${RAD_SOURCE_DIR}/core/runtime/wtab_sycl.cpp)
|
||||||
|
target_include_directories(rad_sycl PRIVATE
|
||||||
|
${RAD_SOURCE_DIR}/core/device ${RAD_SOURCE_DIR}/core ${RAD_SOURCE_DIR}/abi
|
||||||
|
${RAD_SOURCE_DIR}/vendor)
|
||||||
|
target_compile_definitions(rad_sycl PRIVATE RAD_HAVE_SYCL=1)
|
||||||
|
target_compile_options(rad_sycl PRIVATE ${RAD_SYCL_FLAGS} -fvisibility=hidden)
|
||||||
|
target_link_options(rad_sycl PRIVATE ${RAD_SYCL_FLAGS} "LINKER:-rpath,${RAD_ONEAPI_LIBDIR}"
|
||||||
|
"LINKER:--no-undefined")
|
||||||
|
set_target_properties(rad_sycl PROPERTIES OUTPUT_NAME rad_sycl)
|
||||||
+25
-5
@@ -80,7 +80,8 @@ set(RAD_TEST_SHARDS_gbnf_test 4)
|
|||||||
#
|
#
|
||||||
# ROCR_VISIBLE_DEVICES=99 hides every card, so a unit test runs on the host backend on every
|
# ROCR_VISIBLE_DEVICES=99 hides every card, so a unit test runs on the host backend on every
|
||||||
# machine: the same code everywhere, and nothing touches a card a server is using. The _card
|
# machine: the same code everywhere, and nothing touches a card a server is using. The _card
|
||||||
# entries below run the device tests on a card.
|
# entries below run the device tests on a card. A SYCL build hides its cards the same way with
|
||||||
|
# ONEAPI_DEVICE_SELECTOR (the backend uses Level Zero devices only).
|
||||||
#
|
#
|
||||||
# RAD_TEST_STRICT=1: a plugin or fixture this build makes is never legitimately absent, so a test
|
# RAD_TEST_STRICT=1: a plugin or fixture this build makes is never legitimately absent, so a test
|
||||||
# that cannot find one fails rather than skips. RAD_TEST_TMPDIR puts radtest::tmpdir() in the build
|
# that cannot find one fails rather than skips. RAD_TEST_TMPDIR puts radtest::tmpdir() in the build
|
||||||
@@ -109,7 +110,11 @@ set(RAD_TEST_OMP_ENV "OMP_WAIT_POLICY=passive" "OMP_NUM_THREADS=${RAD_TEST_OMP_T
|
|||||||
set(RAD_TEST_CARD_ENV "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home" ${RAD_TEST_OMP_ENV}
|
set(RAD_TEST_CARD_ENV "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home" ${RAD_TEST_OMP_ENV}
|
||||||
"RAD_TEST_STRICT=1" "RAD_TEST_TMPDIR=${CMAKE_BINARY_DIR}/tmp"
|
"RAD_TEST_STRICT=1" "RAD_TEST_TMPDIR=${CMAKE_BINARY_DIR}/tmp"
|
||||||
${RAD_TEST_SAN_ENV})
|
${RAD_TEST_SAN_ENV})
|
||||||
set(RAD_TEST_ENV ${RAD_TEST_CARD_ENV} "ROCR_VISIBLE_DEVICES=99")
|
set(RAD_TEST_HIDE_ENV "ROCR_VISIBLE_DEVICES=99")
|
||||||
|
if(RAD_SYCL_FOUND)
|
||||||
|
list(APPEND RAD_TEST_HIDE_ENV "ONEAPI_DEVICE_SELECTOR=!level_zero:*")
|
||||||
|
endif()
|
||||||
|
set(RAD_TEST_ENV ${RAD_TEST_CARD_ENV} ${RAD_TEST_HIDE_ENV})
|
||||||
|
|
||||||
# Binaries that need more CPU than the default budget, and what costs it. Lower an entry when its
|
# Binaries that need more CPU than the default budget, and what costs it. Lower an entry when its
|
||||||
# cost comes down, so the tripwire stays tight.
|
# cost comes down, so the tripwire stays tight.
|
||||||
@@ -244,6 +249,21 @@ if(RAD_HIP_FOUND)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# The same on an Intel GPU through the SYCL backend, labelled sycl. The oneAPI environment must be
|
||||||
|
# loaded (the runtime finds its Level Zero adapter through it), and RAD_TEST_BACKEND=sycl makes a
|
||||||
|
# run that fell back to the host backend fail instead of passing on the CPU. RADIANCE_SYCL_TIMING=1
|
||||||
|
# turns event timing on, which the backend leaves off by default (core/device/sycl.cpp), so the
|
||||||
|
# whole device contract is under test.
|
||||||
|
if(RAD_SYCL_FOUND)
|
||||||
|
foreach(n device_test)
|
||||||
|
add_test(NAME ${n}_sycl COMMAND ${n} -perf_)
|
||||||
|
set_tests_properties(${n}_sycl PROPERTIES
|
||||||
|
LABELS sycl
|
||||||
|
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||||
|
ENVIRONMENT "${RAD_TEST_CARD_ENV};RAD_TEST_BACKEND=sycl;RADIANCE_SYCL_TIMING=1")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
# ================================================================== whole models on the CPU
|
# ================================================================== whole models on the CPU
|
||||||
#
|
#
|
||||||
# engine_e2e_test runs the radiance binary on tiny synthetic checkpoints (tests/tiny_model.h) on
|
# engine_e2e_test runs the radiance binary on tiny synthetic checkpoints (tests/tiny_model.h) on
|
||||||
@@ -362,7 +382,7 @@ if(TARGET libavx AND TARGET rad-avx-check)
|
|||||||
add_test(NAME avx_check
|
add_test(NAME avx_check
|
||||||
COMMAND rad-avx-check --ref ${RAD_PLUGIN_OUT}/kernels/libref.so
|
COMMAND rad-avx-check --ref ${RAD_PLUGIN_OUT}/kernels/libref.so
|
||||||
--avx ${RAD_PLUGIN_OUT}/kernels/libavx.so)
|
--avx ${RAD_PLUGIN_OUT}/kernels/libavx.so)
|
||||||
set(env ${RAD_TEST_OMP_ENV} "ROCR_VISIBLE_DEVICES=99" ${RAD_TEST_SAN_ENV})
|
set(env ${RAD_TEST_OMP_ENV} ${RAD_TEST_HIDE_ENV} ${RAD_TEST_SAN_ENV})
|
||||||
set_tests_properties(avx_check PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
set_tests_properties(avx_check PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -376,7 +396,7 @@ if(TARGET rad-avx-check AND TARGET libref)
|
|||||||
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/avx_check_general.sh
|
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/avx_check_general.sh
|
||||||
$<TARGET_FILE:rad-avx-check> ${RAD_PLUGIN_OUT}/kernels/libref.so
|
$<TARGET_FILE:rad-avx-check> ${RAD_PLUGIN_OUT}/kernels/libref.so
|
||||||
$<TARGET_FILE:avx_subset_plugin>)
|
$<TARGET_FILE:avx_subset_plugin>)
|
||||||
set(env ${RAD_TEST_OMP_ENV} "ROCR_VISIBLE_DEVICES=99" ${RAD_TEST_SAN_ENV})
|
set(env ${RAD_TEST_OMP_ENV} ${RAD_TEST_HIDE_ENV} ${RAD_TEST_SAN_ENV})
|
||||||
set_tests_properties(avx_check_general PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
set_tests_properties(avx_check_general PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -530,7 +550,7 @@ add_test(NAME ops_doc
|
|||||||
set_tests_properties(ops_doc PROPERTIES
|
set_tests_properties(ops_doc PROPERTIES
|
||||||
SKIP_RETURN_CODE 77
|
SKIP_RETURN_CODE 77
|
||||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||||
ENVIRONMENT "ROCR_VISIBLE_DEVICES=99")
|
ENVIRONMENT "${RAD_TEST_HIDE_ENV}")
|
||||||
|
|
||||||
# tools/rad-export. Its standard-library checks always run; the merge arithmetic runs where torch
|
# tools/rad-export. Its standard-library checks always run; the merge arithmetic runs where torch
|
||||||
# and safetensors import, and the PEFT comparison where peft and transformers do too.
|
# and safetensors import, and the PEFT comparison where peft and transformers do too.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "rad_quant.h"
|
#include "rad_quant.h"
|
||||||
#include "rad_runtime.h"
|
#include "rad_runtime.h"
|
||||||
#include "rad_sample.h"
|
#include "rad_sample.h"
|
||||||
|
#include "rad_sycl.h"
|
||||||
#include "rad_types.h"
|
#include "rad_types.h"
|
||||||
#include "rad_yarn.h"
|
#include "rad_yarn.h"
|
||||||
|
|
||||||
|
|||||||
@@ -642,6 +642,12 @@ ABI_FIELD(RadSampleParams, hist_len)
|
|||||||
ABI_FIELD(RadSampleParams, mask_row)
|
ABI_FIELD(RadSampleParams, mask_row)
|
||||||
ABI_FIELD(RadSampleParams, flags)
|
ABI_FIELD(RadSampleParams, flags)
|
||||||
ABI_FIELD(RadSampleParams, dry_rep_limit)
|
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_STRUCT(RadTensor)
|
||||||
ABI_FIELD(RadTensor, data)
|
ABI_FIELD(RadTensor, data)
|
||||||
ABI_FIELD(RadTensor, dtype)
|
ABI_FIELD(RadTensor, dtype)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "rad_quant.h"
|
#include "rad_quant.h"
|
||||||
#include "rad_runtime.h"
|
#include "rad_runtime.h"
|
||||||
#include "rad_sample.h"
|
#include "rad_sample.h"
|
||||||
|
#include "rad_sycl.h"
|
||||||
#include "rad_types.h"
|
#include "rad_types.h"
|
||||||
#include "rad_yarn.h"
|
#include "rad_yarn.h"
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,21 @@ std::string temp_path(const char* tag) {
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------ identity */
|
/* ------------------------------------------------------------------ identity */
|
||||||
|
|
||||||
|
/* RAD_TEST_BACKEND names the backend a run is registered for (the sycl-labelled entries set it).
|
||||||
|
* A run that fell back to another backend, typically the host one for want of a driver
|
||||||
|
* environment, fails here instead of passing every case on the CPU. */
|
||||||
|
TEST(the_backend_is_the_one_the_run_names) {
|
||||||
|
const char* want = std::getenv("RAD_TEST_BACKEND");
|
||||||
|
if (!want || !*want) return;
|
||||||
|
if (std::strcmp(rad::device_backend_name(), want) != 0)
|
||||||
|
fprintf(stderr, " RAD_TEST_BACKEND=%s but the %s backend is running: %s\n", want,
|
||||||
|
rad::device_backend_name(),
|
||||||
|
std::strcmp(want, "sycl") == 0
|
||||||
|
? "load the oneAPI environment (. /opt/intel/oneapi/setvars.sh)"
|
||||||
|
: "is the device visible?");
|
||||||
|
CHECK_EQ(std::string(rad::device_backend_name()), std::string(want));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(backend_reports_itself) {
|
TEST(backend_reports_itself) {
|
||||||
const char* name = rad::device_backend_name();
|
const char* name = rad::device_backend_name();
|
||||||
CHECK(name && *name);
|
CHECK(name && *name);
|
||||||
|
|||||||
Reference in new issue
Block a user