libr4d: swiglu_step, router_sigmoid_group_topk, mla_attn_paged, and mla_project at head_dim 128

mla_attn_paged is the wave-per-(row, head) latent attention of mla_attn with the rotary part in
the score, one page table a sequence, the causal bound from cu_seqlens and seqused, and the head
gate in its store; a short batch splits the history and merges f32 partials as mla_attn does.
router_sigmoid_group_topk is router_sigmoid_topk's wave with the groups ranked first, a lane a
group. mla_project takes the head width as a template parameter; at 256 it is the kernel it was.
r4d_selftest holds each new row and the 128-wide mla_project to libref.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-11-03 19:07:34 +01:00
1 parent e4ca20ddf8
commit 523349dd8f
7 files changed
+619 -29

No files matched your search

+30
View File
@@ -617,6 +617,18 @@ extern "C" int r4d_shape_router_sigmoid_topk(const RadParam* p, int n_p, int ope
opd(D, M, k) };
R4D_PICK(l);
}
extern "C" int r4d_shape_router_sigmoid_group_topk(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M"), ne = pi(p, n_p, "n_expert"), k = pi(p, n_p, "top_k");
const int64_t ng = pi(p, n_p, "n_group"), kg = pi(p, n_p, "topk_group");
if (ne <= 0 || ne > 512 || k <= 0 || ng <= 0 || ng > 32 || ne % ng || ne / ng < 2 || kg <= 0 ||
kg > ng || k > kg * (ne / ng))
return RAD_E_UNSUPPORTED;
const uint32_t D = dt_act(p, n_p, "dtype");
const RadOpdDesc l[] = { opd(D, M, ne), opd((uint32_t)RAD_F32, ne), opd_idx(M, k, ne),
opd(D, M, k) };
R4D_PICK(l);
}
extern "C" int r4d_shape_router_sigmoid_topk_scatter(const RadParam* p, int n_p, int operand,
RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M"), ne = pi(p, n_p, "n_expert"), k = pi(p, n_p, "top_k");
@@ -663,6 +675,24 @@ extern "C" int r4d_shape_mla_project(const RadParam* p, int n_p, int operand, Ra
opd((uint32_t)RAD_BF16, M, h, absorb ? l : d) };
R4D_PICK(list);
}
/* One sequence whose context is its query, as libref describes the op; a harness passes `ctx`. */
extern "C" int r4d_shape_mla_attn_paged(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M"), h = pi(p, n_p, "heads"), L = pi(p, n_p, "latent_dim"),
R = pi(p, n_p, "rope_dim"), bs = pi(p, n_p, "block_size");
if (M <= 0 || h <= 0 || L <= 0 || R <= 0 || bs <= 0) return RAD_E_UNSUPPORTED;
int64_t ctx = pi(p, n_p, "ctx", 0);
if (ctx < M) ctx = M;
const int64_t blocks = (ctx + bs - 1) / bs;
const RadOpdDesc list[] = { opd((uint32_t)RAD_BF16, M, h, L),
opd((uint32_t)RAD_BF16, M, h, R),
opd((uint32_t)RAD_BF16, blocks, 1, bs, L + R),
opd_idx(1, blocks, blocks),
opd_idx(1, 0, 0, ctx),
opd_idx(2, 0, M + 1, -1, (uint32_t)RAD_OPD_F_IDX_CU),
opd_none(),
opd((uint32_t)RAD_BF16, M, h, L) };
R4D_PICK(list);
}
extern "C" int r4d_shape_dsa_score(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
const int64_t M = pi(p, n_p, "M"), n = pi(p, n_p, "n"), H = pi(p, n_p, "heads");
const int64_t B = pi(p, n_p, "blocks"), S = pi(p, n_p, "seqs"), pages = S * B;