gemma4k, arch/gemma4: norm_add_norm_route -- the attention join writes the routed arm's inputs

The 26B-A4B's router reads rmsnorm(x) * w_r * hidden^-0.5 and its experts rmsnorm(x) * w_e,
quantised to E4M3 for the fp8 gate_up: an `rmsnorm` and an `rmsnorm_quant_fp8` a layer, each
reading back the x norm_add_norm has just written and taking the sum of squares it has just taken.
At decode that is 60 launches a step (8.3 and 7.8 us under --profile-ops on 4x R9700); at a
prefill, eleven passes of each a layer per 20K-token request.

norm_add_norm_route is norm_add_norm, then from the norm factor it already holds the router's row
by rmsnorm's expression, ((x * s) * w_r) * mult, and the experts' codes as rmsnorm_quant_fp8 writes
them: the bf16-rounded norm, a scale of amax * (1 / 448) a 128 columns (1 for an all-zero group),
the value times its reciprocal clamped to +-448, one v_cvt_pk_fp8_f32. Element i is thread i % 256
at slot i / 256, so a group is four waves at one slot -- a wave's max, then the four through LDS.
Its own name rather than optional operands on norm_add_norm: the codes need whole 128-column
groups, which the plain join does not, and the arch falls back cleanly where it does not resolve.
A device row and a host arm (one helper with norm_add_norm's), the schema, OPS.md.

arch/gemma4 asks for it on every layer whose gate_up is block fp8 -- the user's fp8gu container,
every layer -- and then issues neither op_rnorm nor op_enorm; it declares both still, and
norm_add_norm and the chain behind it, for where it does not resolve. The routed arm's two norm
gains are declared ahead of the attention join now, which names them. The overlap takes either
join. A startup note counts the layers that take it.

The same rounding as the chain, but for the order a sum of squares is added in, as every join here:
g4k_emu holds the kernel to a chain summed in its block order bit for bit -- x, y, the router's
row, every code and scale -- at the 26B-A4B's 2816 at four heights, at 128, 3072, 3200 and 6144,
and with an all-zero group; against the host arm, no code more than a step off. The emulator gains
v_cvt_pk_fp8_f32, through the project's saturating encoder. arch_test: with fp8 gate_up experts the
route op resolves on all six layers, a decode step issues it and no rmsnorm_quant_fp8 and one
rmsnorm fewer a layer; refused, norm_add_norm and both launches; a tp-4 prefill through the
overlap issues it a slice and keeps every reduction ordered.

Not yet run on the cards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 committed 2026-10-12 14:40:04 -05:00
1 parent efff69be1d
commit 7a1ae22690
11 files changed
+449 -43

No files matched your search

+4 -2
View File
@@ -27,9 +27,11 @@ int64_t g4k_attn_h512_scratch(const RadArgs* a);
int g4k_pair_argmax_f32(const RadArgs* a, RadStream s);
/* Gemma 4's sandwich-norm joins, one kernel each (g4k_norm.hip):
* norm_add_norm operands a, w_a, x (inout), w_y, y
* join_add_scale operands d, w_d, r, w_r, w_j, x (inout), s */
* norm_add_norm operands a, w_a, x (inout), w_y, y
* norm_add_norm_route the same, then w_r, r, w_e, q, qs: the routed arm's two inputs
* join_add_scale operands d, w_d, r, w_r, w_j, x (inout), s */
int g4k_norm_add_norm_bf16(const RadArgs* a, RadStream s);
int g4k_norm_add_norm_route_bf16(const RadArgs* a, RadStream s);
/* expert_scale: each routing weight times its expert's scale, in place (g4k_escale.hip):
* operands ids, w_e, ew (inout) */
+113 -10
View File
@@ -20,6 +20,16 @@
* and, rarely, a bf16 output by one ulp. The arch plugin asks for these first and falls back to
* the chain where nothing serves them (gemma4.cpp).
*
* AND THE ROUTED ARM'S TWO INPUTS (norm_add_norm_route). The 26B-A4B's router reads norm(x) * w_r *
* hidden^-0.5 and its experts norm(x) * w_e, quantised to E4M3 -- two more launches a layer
* (`rmsnorm`, `rmsnorm_quant_fp8`), each reading back the x norm_add_norm has just written and
* taking the sum of squares norm_add_norm has just taken. The route form writes both from the norm
* factor it holds: the router's row by libr4d's rmsnorm expression, ((x * s) * w) * mult, and the
* experts' codes as libr4d's rmsnorm_quant_fp8 writes them -- the bf16-rounded norm, a scale of
* amax * (1 / 448) a 128 columns (1 where the group is all zero), the value times its reciprocal
* clamped to +-448, one v_cvt_pk_fp8_f32. Element i is thread i % 256 at slot i / 256, so a group
* is four waves at one slot: a wave's max, then the four.
*
* One 256-thread block a row: a decode step is a handful of rows, so the row is latency-bound and
* a block's three reductions beat seven launches. Values a later stage reuses stay in registers
* (PER a thread, 12 to n = 3072 and kMaxPer = 24 to 6144; the row table says so).
@@ -99,22 +109,30 @@ struct NormArgs {
const float* w2; /* w_j */
const float* w3; /* w_n, the next norm's gain (or null) */
const uint16_t* s; /* the layer scalar, bf16, one element */
/* norm_add_norm_route: the router's input, the experts' codes and their scales; the router's
* gain is w2 and the experts' w3 */
uint16_t* rt; long long rt_ld;
uint8_t* q; long long q_ld;
float* qs; long long qs_ld;
float mult;
int n;
float eps;
};
/* t = norm(a) * w_a; x += t; y = norm(x) * w_y */
template <int PER>
/* t = norm(a) * w_a; x += t; y = norm(x) * w_y -- and with ROUTE, from the same norm of x, the
* router's input norm(x) * w_r * mult and the experts' norm(x) * w_e as E4M3 codes and scales */
template <int PER, bool ROUTE>
__global__ __launch_bounds__(kThreads) void norm_add_norm_kernel(NormArgs A) {
__shared__ float lds[kWaves];
__shared__ float gmax[ROUTE ? PER * kWaves : 1];
const int tid = (int)threadIdx.x, n = A.n;
const long long m = (long long)blockIdx.x;
const uint16_t* ar = A.a + m * A.a_ld;
uint16_t* xr = A.x + m * A.x_ld;
uint16_t* yr = A.y + m * A.y_ld;
/* every operand of the row in flight at once: the block output, the residual, both gains */
float av[PER], xv[PER], wa[PER], wy[PER];
/* every operand of the row in flight at once: the block output, the residual, the gains */
float av[PER], xv[PER], wa[PER], wy[PER], wr[ROUTE ? PER : 1], we[ROUTE ? PER : 1];
#pragma unroll
for (int k = 0; k < PER; ++k) {
const int i = tid + k * kThreads;
@@ -123,6 +141,10 @@ __global__ __launch_bounds__(kThreads) void norm_add_norm_kernel(NormArgs A) {
xv[k] = in ? bf2f(xr[i]) : 0.0f;
wa[k] = in ? A.w0[i] : 0.0f;
wy[k] = in ? A.w1[i] : 0.0f;
if constexpr (ROUTE) {
wr[k] = in ? A.w2[i] : 0.0f;
we[k] = in ? A.w3[i] : 0.0f;
}
}
float ss = 0.0f;
#pragma unroll
@@ -140,10 +162,45 @@ __global__ __launch_bounds__(kThreads) void norm_add_norm_kernel(NormArgs A) {
ss += xv[k] * xv[k];
}
const float sx = norm_factor(block_sum(ss, lds), n, A.eps);
uint16_t* rr = ROUTE ? A.rt + m * A.rt_ld : nullptr;
#pragma unroll
for (int k = 0; k < PER; ++k) {
const int i = tid + k * kThreads;
if (i < n) yr[i] = f2bf((xv[k] * sx) * wy[k]);
if (i < n) {
yr[i] = f2bf((xv[k] * sx) * wy[k]);
if constexpr (ROUTE) {
rr[i] = f2bf(((xv[k] * sx) * wr[k]) * A.mult);
av[k] = rbf((xv[k] * sx) * we[k]); /* the experts' row, as quantised */
}
} else if constexpr (ROUTE) {
av[k] = 0.0f;
}
}
if constexpr (ROUTE) {
/* group 2k + tid / 128 at slot k is waves 0..3 or 4..7: each wave's max, then its four */
const int wave = tid >> 5, half = tid >> 7;
#pragma unroll
for (int k = 0; k < PER; ++k) {
float mx = fabsf(av[k]);
#pragma unroll
for (int d = 16; d >= 1; d >>= 1) mx = fmaxf(mx, shfl_xor(mx, d));
if (lane_id() == 0) gmax[k * kWaves + wave] = mx;
}
__syncthreads();
uint8_t* qr = A.q + m * A.q_ld;
float* sr = A.qs + m * A.qs_ld;
#pragma unroll
for (int k = 0; k < PER; ++k) {
const int i = tid + k * kThreads;
if (i >= n) continue; /* n is whole groups: a group is in or out */
const float* g = gmax + k * kWaves + 4 * half;
const float am = fmaxf(fmaxf(g[0], g[1]), fmaxf(g[2], g[3]));
const float sc = am > 0.0f ? am * (1.0f / 448.0f) : 1.0f;
const float inv = 1.0f / sc;
const float v = fminf(fmaxf(av[k] * inv, -448.0f), 448.0f);
qr[i] = (uint8_t)(__builtin_amdgcn_cvt_pk_fp8_f32(v, v, 0, false) & 0xff);
if ((tid & 127) == 0) sr[i >> 7] = sc;
}
}
}
@@ -224,14 +281,17 @@ __global__ __launch_bounds__(kThreads) void join_add_scale_kernel(NormArgs A) {
/* ------------------------------------------------------------------ host: the launch adapters */
/* [rows..., n] with a dense last axis: its row count and pitch, or false */
static bool rows_of(const RadTensor* t, int64_t n, int64_t* rows, int64_t* ld) {
if (!t || t->dtype != RAD_BF16 || t->rank < 1) return false;
/* [rows..., n] of `dt` with a dense last axis: its row count and pitch, or false */
static bool rows_as(const RadTensor* t, uint32_t dt, int64_t n, int64_t* rows, int64_t* ld) {
if (!t || t->dtype != dt || t->rank < 1) return false;
if (rad_tensor_lastdim(t) != n || (t->stride[t->rank - 1] != 1)) return false;
*rows = rad_tensor_rows(t);
*ld = rad_tensor_row_pitch(t);
return *ld >= n || *rows <= 1;
}
static bool rows_of(const RadTensor* t, int64_t n, int64_t* rows, int64_t* ld) {
return rows_as(t, RAD_BF16, n, rows, ld);
}
static bool gain(const RadTensor* w, int64_t n) {
return w && w->dtype == RAD_F32 && rad_tensor_numel(w) == n &&
(w->rank == 0 || w->stride[w->rank - 1] == 1);
@@ -272,11 +332,54 @@ int g4k_norm_add_norm_bf16(const RadArgs* a, RadStream stream) {
P.w0 = (const float*)Wa->data; P.w1 = (const float*)Wy->data;
P.n = (int)n; P.eps = eps;
if (n <= (int64_t)kThreads * 12)
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<12>), dim3((unsigned)M), dim3(kThreads),
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<12, false>), dim3((unsigned)M), dim3(kThreads),
(hipStream_t)stream, P);
else
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<kMaxPer>), dim3((unsigned)M), dim3(kThreads),
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<kMaxPer, false>), dim3((unsigned)M),
dim3(kThreads), (hipStream_t)stream, P);
return hipGetLastError() == hipSuccess ? RAD_OK : RAD_E_DEVICE;
}
/* operands: a, w_a, x (inout), w_y, y, w_r, r, w_e, q, qs */
int g4k_norm_add_norm_route_bf16(const RadArgs* a, RadStream stream) {
using namespace g4kn;
if (!a || a->n_t < 10) return RAD_E_INVAL;
int64_t n = 0;
float eps = 0.0f;
if (int rc = params(a, &n, &eps)) return rc;
if (n % 128 || rad_args_geti_or(a, "group", 0) != 128) return RAD_E_SHAPE;
const RadTensor *A_ = rad_arg_in(a, 0), *Wa = rad_arg_in(a, 1), *X = rad_arg_in(a, 2),
*Wy = rad_arg_in(a, 3), *Y = rad_arg_in(a, 4), *Wr = rad_arg_in(a, 5),
*R = rad_arg_in(a, 6), *We = rad_arg_in(a, 7), *Q = rad_arg_in(a, 8),
*S = rad_arg_in(a, 9);
if (!A_ || !X || !Y || !R || !Q || !S) return RAD_E_INVAL;
if (!gain(Wa, n) || !gain(Wy, n) || !gain(Wr, n) || !gain(We, n)) return RAD_E_DTYPE;
int64_t ra = 0, la = 0, rx = 0, lx = 0, ry = 0, ly = 0, rr = 0, lr = 0, rq = 0, lq = 0,
rs = 0, ls = 0;
if (!rows_of(A_, n, &ra, &la) || !rows_of(X, n, &rx, &lx) || !rows_of(Y, n, &ry, &ly) ||
!rows_of(R, n, &rr, &lr) || !rows_as(Q, RAD_F8E4M3, n, &rq, &lq) ||
!rows_as(S, RAD_F32, n / 128, &rs, &ls))
return RAD_E_SHAPE;
const int64_t M = rx; /* the step's rows: the stream's view */
if (M <= 0) return RAD_OK;
if (ra < M || ry < M || rr < M || rq < M || rs < M || M > 0x7fffffff) return RAD_E_SHAPE;
NormArgs P{};
P.a = (const uint16_t*)A_->data; P.a_ld = la;
P.x = (uint16_t*)X->data; P.x_ld = lx;
P.y = (uint16_t*)Y->data; P.y_ld = ly;
P.rt = (uint16_t*)R->data; P.rt_ld = lr;
P.q = (uint8_t*)Q->data; P.q_ld = lq;
P.qs = (float*)S->data; P.qs_ld = ls;
P.w0 = (const float*)Wa->data; P.w1 = (const float*)Wy->data;
P.w2 = (const float*)Wr->data; P.w3 = (const float*)We->data;
P.mult = (float)rad_args_getf_or(a, "mult", 1.0);
P.n = (int)n; P.eps = eps;
if (n <= (int64_t)kThreads * 12)
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<12, true>), dim3((unsigned)M), dim3(kThreads),
(hipStream_t)stream, P);
else
G4K_LAUNCH(G4K_KNAME(norm_add_norm_kernel<kMaxPer, true>), dim3((unsigned)M),
dim3(kThreads), (hipStream_t)stream, P);
return hipGetLastError() == hipSuccess ? RAD_OK : RAD_E_DEVICE;
}
+95 -6
View File
@@ -11,6 +11,8 @@
* norm_add_norm and join_add_scale, ops this library DEFINES: Gemma 4's two sandwich-norm joins,
* each one kernel in place of a chain of rmsnorm / add / mul_weight launches, rounding where the
* chain rounds (g4k_norm.hip). The arch plugin asks for them and falls back to the chain.
* norm_add_norm_route is the attention join writing the routed arm's two inputs as well -- the
* router's norm and the experts' fp8 codes -- in place of an rmsnorm and an rmsnorm_quant_fp8.
*
* Put it AHEAD of libr4d for Gemma 4 (`--kernels gemma4k,libr4d,...`). The hierarchy is absolute,
* and libr4d has rows at h256/gqa2 and h512/gqa8 too -- written for the dense 31B, which has no
@@ -40,6 +42,7 @@
#define C_GE(k, v) { (k), RAD_C_GE, (long long)(v), nullptr }
#define C_LE(k, v) { (k), RAD_C_LE, (long long)(v), nullptr }
#define C_IN(k, s) { (k), RAD_C_IN, 0, (s) }
#define C_DIV(k, v) { (k), RAD_C_DIV, (long long)(v), nullptr }
namespace {
@@ -74,6 +77,26 @@ static const RadOperandSpec oNan[] = {
{ "w_y", RAD_OPD_WEIGHT, 0 },
{ "y", RAD_OPD_OUT, 0 },
};
static const RadParamSpec pRoute[] = {
{ "M", RAD_P_INT, RAD_REQUIRED, 0 },
{ "n", RAD_P_INT, RAD_REQUIRED, 0 },
{ "eps", RAD_P_F64, RAD_REQUIRED, 0 },
{ "dtype", RAD_P_STR, RAD_REQUIRED, 0 },
{ "mult", RAD_P_F64, RAD_REQUIRED, 0 },
{ "group", RAD_P_INT, RAD_REQUIRED, 0 },
};
static const RadOperandSpec oRoute[] = {
{ "a", RAD_OPD_IN, 0 },
{ "w_a", RAD_OPD_WEIGHT, 0 },
{ "x", RAD_OPD_INOUT, 0 },
{ "w_y", RAD_OPD_WEIGHT, 0 },
{ "y", RAD_OPD_OUT, 0 },
{ "w_r", RAD_OPD_WEIGHT, 0 },
{ "r", RAD_OPD_OUT, 0 },
{ "w_e", RAD_OPD_WEIGHT, 0 },
{ "q", RAD_OPD_OUT, 0 },
{ "qs", RAD_OPD_OUT, 0 },
};
static const RadOperandSpec oJas[] = {
{ "d", RAD_OPD_IN, 0 },
{ "w_d", RAD_OPD_WEIGHT, 0 },
@@ -138,6 +161,11 @@ static const RadOpSchema kSchemas[] = {
"t = rmsnorm(a) * w_a; x = x + t; y = rmsnorm(x) * w_y, over [M, n] rows; every value the "
"unfused rmsnorm, add, rmsnorm chain stores is rounded to the activation dtype at the same "
"point. A post-norm, the residual add and the next pre-norm (Gemma's sandwich)." },
{ "norm_add_norm_route", ROW(pRoute), ROW(oRoute),
"norm_add_norm, then from the same rmsnorm of the x it writes r = rmsnorm(x) * w_r * mult "
"and the E4M3 codes q of rmsnorm(x) * w_e with an f32 scale qs per (row, `group` columns): "
"rmsnorm_quant_fp8's codes, taken over the bf16-rounded norm. A MoE layer's router input and "
"its experts' fp8 input, written by the attention join that already holds the norm." },
{ "join_add_scale", ROW(pJoin), ROW(oJas),
"x = (x + rmsnorm(rmsnorm(d) * w_d + rmsnorm(r) * w_r) * w_j) * s, over [M, n] rows, s one "
"element; and with w_n and y, y = rmsnorm(x) * w_n over the x written. Rounding where the "
@@ -301,17 +329,36 @@ static bool hgain(const RadTensor* w, int64_t n) {
return w && w->dtype == RAD_F32 && rad_tensor_numel(w) == n;
}
int norm_add_norm_host(const RadArgs* a, RadStream) {
if (!a || a->n_t < 5) return RAD_E_INVAL;
/* [rows..., n] of `dt`, dense last axis, for the route form's fp8 codes and f32 scales */
static bool hrows_as(const RadTensor* t, uint32_t dt, int64_t n, int64_t* rows, int64_t* ld) {
if (!t || t->dtype != dt || t->rank < 1 || rad_tensor_lastdim(t) != n) return false;
if (t->stride[t->rank - 1] != 1) return false;
*rows = rad_tensor_rows(t);
*ld = rad_tensor_row_pitch(t);
return true;
}
/* norm_add_norm, and with `route` norm_add_norm_route's three more outputs */
static int nan_host(const RadArgs* a, bool route) {
if (!a || a->n_t < (route ? 10 : 5)) return RAD_E_INVAL;
const int64_t n = rad_args_geti_or(a, "n", 0);
const double eps = rad_args_getf_or(a, "eps", 1e-6);
const float mult = (float)rad_args_getf_or(a, "mult", 1.0);
const RadTensor *A_ = rad_arg_in(a, 0), *Wa = rad_arg_in(a, 1), *X = rad_arg_in(a, 2),
*Wy = rad_arg_in(a, 3), *Y = rad_arg_in(a, 4);
if (n <= 0 || !A_ || !X || !Y) return RAD_E_INVAL;
if (!hgain(Wa, n) || !hgain(Wy, n)) return RAD_E_DTYPE;
int64_t ra, la, rx, lx, ry, ly;
const RadTensor *Wr = route ? rad_arg_in(a, 5) : nullptr, *R = route ? rad_arg_in(a, 6) : nullptr;
const RadTensor *We = route ? rad_arg_in(a, 7) : nullptr, *Q = route ? rad_arg_in(a, 8) : nullptr;
const RadTensor *S = route ? rad_arg_in(a, 9) : nullptr;
if (n <= 0 || !A_ || !X || !Y || (route && (!R || !Q || !S))) return RAD_E_INVAL;
if (route && (n % 128 || rad_args_geti_or(a, "group", 0) != 128)) return RAD_E_SHAPE;
if (!hgain(Wa, n) || !hgain(Wy, n) || (route && (!hgain(Wr, n) || !hgain(We, n))))
return RAD_E_DTYPE;
int64_t ra, la, rx, lx, ry, ly, rr = 0, lr = 0, rq = 0, lq = 0, rs = 0, ls = 0;
if (!hrows(A_, n, &ra, &la) || !hrows(X, n, &rx, &lx) || !hrows(Y, n, &ry, &ly)) return RAD_E_SHAPE;
if (ra < rx || ry < rx) return RAD_E_SHAPE;
if (route && (!hrows(R, n, &rr, &lr) || !hrows_as(Q, RAD_F8E4M3, n, &rq, &lq) ||
!hrows_as(S, RAD_F32, n / 128, &rs, &ls)))
return RAD_E_SHAPE;
if (ra < rx || ry < rx || (route && (rr < rx || rq < rx || rs < rx))) return RAD_E_SHAPE;
const float *wa = (const float*)Wa->data, *wy = (const float*)Wy->data;
std::vector<float> v((size_t)n), xv((size_t)n);
for (int64_t m = 0; m < rx; ++m) {
@@ -327,9 +374,33 @@ int norm_add_norm_host(const RadArgs* a, RadStream) {
}
const float sx = hnorm(xv.data(), n, eps);
for (int64_t i = 0; i < n; ++i) yr[i] = hf2b((xv[(size_t)i] * sx) * wy[i]);
if (!route) continue;
/* the router's row, and the experts' as rmsnorm_quant_fp8 writes it (v holds it) */
const float *wr = (const float*)Wr->data, *we = (const float*)We->data;
uint16_t* rrow = (uint16_t*)R->data + m * lr;
uint8_t* qrow = (uint8_t*)Q->data + m * lq;
float* srow = (float*)S->data + m * ls;
for (int64_t i = 0; i < n; ++i) {
rrow[i] = hf2b(((xv[(size_t)i] * sx) * wr[i]) * mult);
v[(size_t)i] = hrbf((xv[(size_t)i] * sx) * we[i]);
}
for (int64_t g = 0; g < n / 128; ++g) {
float am = 0.0f;
for (int64_t i = g * 128; i < g * 128 + 128; ++i)
am = std::fmax(am, std::fabs(v[(size_t)i]));
const float sc = am > 0.0f ? am * (1.0f / 448.0f) : 1.0f;
const float inv = 1.0f / sc;
srow[g] = sc;
for (int64_t i = g * 128; i < g * 128 + 128; ++i) {
const float c = std::fmin(std::fmax(v[(size_t)i] * inv, -448.0f), 448.0f);
qrow[i] = rad_f32_to_fp8e4m3(c);
}
}
}
return RAD_OK;
}
int norm_add_norm_host(const RadArgs* a, RadStream) { return nan_host(a, false); }
int norm_add_norm_route_host(const RadArgs* a, RadStream) { return nan_host(a, true); }
int join_add_scale_host(const RadArgs* a, RadStream) {
if (!a || a->n_t < 7) return RAD_E_INVAL;
@@ -431,6 +502,10 @@ G4K_ATTN_C(cH512x8B, 512, 8, "bf16", 0) G4K_ATTN_C(cH512x8F, 512, 8, "fp8_e4m3",
/* the device kernels hold 24 elements a thread over a 256-thread block */
static const RadConstraint cJoin[] = { C_GE("n", 1), C_LE("n", 6144), C_IN("dtype", "bf16") };
static const RadConstraint cJoinHost[] = { C_GE("n", 1), C_IN("dtype", "bf16") };
static const RadConstraint cRoute[] = { C_GE("n", 128), C_LE("n", 6144), C_DIV("n", 128),
C_EQ("group", 128), C_IN("dtype", "bf16") };
static const RadConstraint cRouteHost[] = { C_GE("n", 128), C_DIV("n", 128), C_EQ("group", 128),
C_IN("dtype", "bf16") };
static const RadConstraint cPick[] = { C_GE("n", 1), C_IN("dtype", "f32 fp32") };
static const RadConstraint cEscale[] = { C_GE("top_k", 1), C_LE("top_k", 64), C_GE("n_expert", 1),
C_IN("dtype", "bf16") };
@@ -490,6 +565,20 @@ static const RadKernelInfo kKernels[] = {
RAD_DOMAIN_HOST, 10, ROW(cJoinHost), NOTUNE,
nullptr, nullptr, norm_add_norm_host, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr },
{ "norm_add_norm_route_bf16", "norm_add_norm_route", "norm",
"norm_add_norm, and the routed arm's router input and fp8 expert input from the same norm",
"n <= 6144 in whole 128-column groups, any M, row pitches honoured",
"bf16 activations, f32 gains; E4M3 codes with an f32 scale a 128 columns",
RAD_DOMAIN_DEVICE, 10, ROW(cRoute), NOTUNE,
nullptr, nullptr, g4k_norm_add_norm_route_bf16, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr },
{ "norm_add_norm_route_bf16_host", "norm_add_norm_route", "norm",
"norm_add_norm, and the routed arm's router input and fp8 expert input from the same norm",
"any [M, n] in whole 128-column groups",
"bf16 activations, f32 gains; E4M3 codes with an f32 scale a 128 columns",
RAD_DOMAIN_HOST, 10, ROW(cRouteHost), NOTUNE,
nullptr, nullptr, norm_add_norm_route_host, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr },
{ "join_add_scale_bf16", "join_add_scale", "norm",
"two arms' post-norms, sum, norm, residual add, layer scalar: one block a row",
"n <= 6144, any M, row pitches honoured", "bf16 activations, f32 gains, bf16 scalar",