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
This commit is contained in:
pascallinxweilerandClaude Opus 5.5 committed 2026-10-23 16:05:59 +02:00
1 parent b2cdcb4420
commit fca4cbe3b5
5 files changed
+297

No files matched your search

+25
View File
@@ -11,6 +11,8 @@
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[] = {
@@ -43,6 +45,29 @@ const RadKernelInfo kKernels[] = {
.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 = {