This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/libxe2/xe2_rows.cpp
T
claudeandClaude Opus 5.5 dc89eb45fb libxe2: rope, embed_lookup, gather_rows, cast
rope builds its frequency ladder on the host per launch exactly as libref's rope_freqs does (a
double pow, then YaRN or llama3 from rad_yarn.h) and takes cos and sin of the f32 angle in double on
the card, as libref does; positions reach 131072 at MiniCPM5's context. neox and gptj with one
position component; the row says so with a mode constraint and the launch refuses anything else by
name.

The gathers write a zero row for an index outside the table, libr4d's rule: libref instead checks
every index on the host before running, which a launch cannot do without waiting on its stream.

rad-kbench against libref: fixture 127/127 and MiniCPM5-2B 94/94, rel_l2 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-23 16:05:59 +02:00

97 lines
5.0 KiB
C++

/* xe2_rows.cpp -- libxe2's plugin exports: identity and the kernel rows the engine selects from.
*
* libxe2 is radiance's kernel library for Intel Xe2 GPUs (the Arc Pro B65, Battlemage G31) through
* SYCL. It defines no op schemas of its own: every op it serves is in the conventional vocabulary,
* whose schemas libref fixes (docs/OPS.md). All rows are device-domain; an op libxe2 lacks has no
* row here, and on the SYCL backend the engine stops at startup naming it (docs/SYCL_PORTING.md
* §4.4).
*/
#include "rad_abi.h"
#include "xe2_ops.h"
namespace {
const RadConstraint cRopeModes[] = { RAD_CIN("mode", "neox gptj") };
/* Rows by field name (C++20 designated initialisers must follow declaration order, so the compiler
* checks it), unlike a positional table where a shifted field can still compile. */
const RadKernelInfo kKernels[] = {
{ .name = "xe2_add", .op = "add", .family = "elem",
.computes = "elementwise sum, b broadcast along rows when it is one row; optional div",
.shape = "any n and row count; rows may be padded, the last axis dense",
.dtypes = "any float dtype in and out (bf16, f16, f32, fp8), f32 arithmetic, rounded as libref",
.domain = RAD_DOMAIN_DEVICE, .priority = 0,
.launch = xe2::add },
{ .name = "xe2_rmsnorm", .op = "rmsnorm", .family = "norm",
.computes = "RMS norm, one work-group a row, f32 work-group reduction",
.shape = "any n; rows may be padded",
.dtypes = "float x, gain and y (bf16 in the recipes), f32 arithmetic",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::rmsnorm },
{ .name = "xe2_rmsnorm_quant_fp8", .op = "rmsnorm_quant_fp8", .family = "norm",
.computes = "residual add (optional), RMS norm, bf16 narrowing, E4M3 codes and an f32 scale "
"per group; int8 codes at amax/127 for an int8 q",
.shape = "any n and group; one sub-group a quantisation group",
.dtypes = "bf16 in, E4M3 (or i8) codes, f32 scales, optional bf16 out",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::rmsnorm_quant_fp8 },
{ .name = "xe2_quant_act_fp8", .op = "quant_act_fp8", .family = "quant",
.computes = "E4M3 codes and an f32 scale amax/448 per group",
.shape = "any n and group",
.dtypes = "float in, E4M3 codes, f32 scales",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::quant_act_fp8 },
{ .name = "xe2_gated_quant_fp8", .op = "gated_quant_fp8", .family = "quant",
.computes = "silu(gate)*up or sigmoid(gate)*up over packed gate_up, bf16 narrowing, E4M3 "
"codes and an f32 scale per group",
.shape = "any n and group",
.dtypes = "bf16 gate_up, E4M3 (or i8) codes, f32 scales, optional bf16 out",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gated_quant_fp8 },
{ .name = "xe2_rope", .op = "rope", .family = "rope",
.computes = "rotary embedding in place over q and k heads; frequency ladder (YaRN, llama3) "
"on the host as libref builds it, cos/sin in double",
.shape = "neox or gptj, one position component a token, rotary_dim <= 256",
.dtypes = "bf16 qkv (any float), integer or float positions",
.domain = RAD_DOMAIN_DEVICE, .constraints = cRopeModes, .n_constraints = 1,
.launch = xe2::rope },
{ .name = "xe2_embed_lookup", .op = "embed_lookup", .family = "vocab",
.computes = "embedding gather times mult; an id outside the table writes a zero row",
.shape = "any n_embd and n_vocab, vocab_offset",
.dtypes = "integer ids, float table and output",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::embed_lookup },
{ .name = "xe2_gather_rows", .op = "gather_rows", .family = "elem",
.computes = "row gather; a negative or out-of-range index writes a zero row",
.shape = "any n",
.dtypes = "integer indices, float rows",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gather_rows },
{ .name = "xe2_cast", .op = "cast", .family = "elem",
.computes = "dtype conversion; integer to integer exact",
.shape = "contiguous operands",
.dtypes = "any float or integer pair",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::cast },
};
const RadPluginInfo kInfo = {
RAD_PLUGIN_KERNEL, "libxe2", "0.1",
"Intel Xe2 (Battlemage) kernels in SYCL, checked against libref",
"intel_gpu_bmg_g31",
};
} // namespace
extern "C" {
__attribute__((visibility("default"))) uint32_t rad_plugin_abi_version(void) {
return RAD_ABI_VERSION;
}
__attribute__((visibility("default"))) const RadPluginInfo* rad_plugin_info(void) { return &kInfo; }
__attribute__((visibility("default"))) int rad_kernel_schema_count(void) { return 0; }
__attribute__((visibility("default"))) const RadOpSchema* rad_kernel_schema_at(int) { return nullptr; }
__attribute__((visibility("default"))) int rad_kernel_count(void) {
return (int)(sizeof kKernels / sizeof kKernels[0]);
}
__attribute__((visibility("default"))) const RadKernelInfo* rad_kernel_at(int i) {
return i >= 0 && i < rad_kernel_count() ? &kKernels[i] : nullptr;
}
} // extern "C"