[HIP] attention + MoE router + vec_add kernels (GPU-verified, parity vs reference semantics)

- k_flash_gqa_decode: single-token GQA attention over a f32 KV cache,
  two-pass softmax, correctness-first base. Parity vs CPU oracle ~3e-6 on the
  real Inkling shape (24 heads / 8 KV, hd 128). SWA window / relpos bias /
  sinks / split-KV / WMMA are the later parity+performance refinements.
- k_moe_router_topk: Inkling EXACT sigmoid router, semantics verified against
  strata k4_moe_router_topk — p=sigmoid(logit), score=p+bias, top-K by score
  (smallest eid wins ties), weight=p[chosen], renormalized to route_scale.
  Parity: top-k ids exact, weights ~1e-5 (128 experts, top-8, route_scale 8).
- k_vec_add: y=a+b elementwise (residual stream), exact.
- C ABI + safe Rust wrappers + DeviceBuf byte/i32 transfers + CPU-oracle tests.

Six compute kernels now verified on gfx1150 (embed, rms_norm, gemm_bf16,
flash_gqa, moe_router, vec_add); the base decode graph is covered except the
NVFP4 expert GEMMs (w13/w2) + reduce. Approach: standard correctness-first
math, Inkling-specific features ported from the measured reference (no
invented attention variants); performance pass (WMMA/split-KV) comes after.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU parity 7/7 (--features hip).
This commit is contained in:
adm committed 2026-12-01 13:53:56 +01:00
1 parent 356f9c458e
commit b99d3a7a6a
3 files changed
+327

No files matched your search

+15
View File
@@ -45,6 +45,21 @@ int vetta_embed_bf16_gather(const uint16_t* table, const int32_t* tokens,
int vetta_gemm_bf16(const uint16_t* x, const uint16_t* w, float* y,
int M, int N, int K, vetta_stream_t stream);
// k_flash_gqa_decode (base): single-token GQA attention over a f32 KV cache.
int vetta_flash_gqa_decode(const float* q, const float* k, const float* v,
float* out, int n_head, int n_kv, int seq,
int hd, float scale, vetta_stream_t stream);
// k_moe_router_topk: Inkling exact sigmoid router (top-K, route_scale norm).
int vetta_moe_router_topk(const float* logits, const float* bias,
int32_t* topk_ids, float* topk_weights,
int M, int n_experts, int K_top,
float route_scale, vetta_stream_t stream);
// k_vec_add: y = a + b elementwise (residual stream).
int vetta_vec_add(const float* a, const float* b, float* y, size_t n,
vetta_stream_t stream);
// Core <15 microkernel entry points (implemented progressively in M1 & M2):
// 1. k_embed_bf16
// 2. k_rms_norm