[HIP] SiTU activation + MoE reduce kernels — full MoE primitive set verified
- k_situ: SiTU double-softcapped MoE activation, exact strata situ_f32 — g_act = beta*tanh(g/beta)*sigmoid(g), u_act = lb*tanh(u/lb), act = g_act*u_act (beta=4, lb=25). gu=[gate;up] from w13 -> act[inter]. - k_moe_reduce: out[d] = sum_e tk_w[e]*y_part[e,d] (weighted expert sum). - C ABI + safe wrappers (situ, moe_reduce) + CPU-oracle parity tests. With nvfp4_gemv (w13/w2) + moe_router_topk, the full MoE compute primitive set is now verified on gfx1150: router -> per-expert nvfp4 GEMV -> SiTU -> nvfp4 GEMV -> weighted reduce. Parity: SiTU ~4e-7 (inter 1152/64/256), moe_reduce ~3e-6 (top-8, hidden 2304). Ten GPU kernels verified. Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS; lean proofs (4 files, 42 theorems) green; GPU parity 10/10 (--features hip).
This commit is contained in:
1 parent
bd49da5636
commit
529709cc64
3 files changed
+123
No files matched your search
@@ -70,6 +70,14 @@ int vetta_nvfp4_gemv(const uint8_t* packed, const uint8_t* scales,
|
||||
float outer_scale, const float* x, float* y,
|
||||
int N, int K, vetta_stream_t stream);
|
||||
|
||||
// k_situ: SiTU double-softcapped MoE activation. gu=[gate;up] (2*inter) -> act.
|
||||
int vetta_situ(const float* gu, float* act, int inter, float beta, float lb,
|
||||
vetta_stream_t stream);
|
||||
|
||||
// k_moe_reduce: out[d] = sum_e tk_w[e]*y_part[e,d] (weighted expert sum).
|
||||
int vetta_moe_reduce(const float* y_part, const float* tk_w, float* out,
|
||||
int top_k, int hidden, vetta_stream_t stream);
|
||||
|
||||
// Core <15 microkernel entry points (implemented progressively in M1 & M2):
|
||||
// 1. k_embed_bf16
|
||||
// 2. k_rms_norm
|
||||
|
||||
@@ -418,4 +418,54 @@ extern "C" int vetta_nvfp4_gemv(const uint8_t* packed, const uint8_t* scales,
|
||||
k_nvfp4_gemv<<<N, 256, 0, s>>>(packed, scales, outer_scale, x, y, N, K);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- SiTU activation (exact strata situ_f32, double-softcapped) ------------
|
||||
// gu = [gate(inter); up(inter)] from w13. act[j] = g_act * u_act where
|
||||
// g_act = beta*tanh(g/beta)*sigmoid(g), u_act = lb*tanh(u/lb).
|
||||
|
||||
__device__ __forceinline__ float situ_f32(float g, float u, float beta, float lb) {
|
||||
const float sig = 1.f / (1.f + __expf(-g));
|
||||
const float g_act = beta * tanhf(g / beta) * sig;
|
||||
const float u_act = lb * tanhf(u / lb);
|
||||
return g_act * u_act;
|
||||
}
|
||||
|
||||
__global__ void k_situ(const float* __restrict__ gu, float* __restrict__ act,
|
||||
int inter, float beta, float lb) {
|
||||
int j = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (j < inter) act[j] = situ_f32(gu[j], gu[inter + j], beta, lb);
|
||||
}
|
||||
|
||||
extern "C" int vetta_situ(const float* gu, float* act, int inter, float beta,
|
||||
float lb, vetta_stream_t stream) {
|
||||
if (inter <= 0) return 1;
|
||||
const int nt = 256;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_situ<<<(inter + nt - 1) / nt, nt, 0, s>>>(gu, act, inter, beta, lb);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- k_moe_reduce: out[d] = sum_e tk_w[e] * y_part[e, d] -------------------
|
||||
|
||||
__global__ void k_moe_reduce(const float* __restrict__ y_part,
|
||||
const float* __restrict__ tk_w, float* __restrict__ out,
|
||||
int top_k, int hidden) {
|
||||
int d = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (d < hidden) {
|
||||
float acc = 0.f;
|
||||
for (int e = 0; e < top_k; ++e) acc += tk_w[e] * y_part[(size_t)e * hidden + d];
|
||||
out[d] = acc;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int vetta_moe_reduce(const float* y_part, const float* tk_w, float* out,
|
||||
int top_k, int hidden, vetta_stream_t stream) {
|
||||
if (top_k <= 0 || hidden <= 0) return 1;
|
||||
const int nt = 256;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_moe_reduce<<<(hidden + nt - 1) / nt, nt, 0, s>>>(y_part, tk_w, out, top_k, hidden);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user