[HIP] ShortConv4 decode kernel (Inkling causal depthwise conv + history ring) verified

- k_shortconv4_decode / vetta_shortconv4_decode: exact strata
  k2_shortconv4_batched static (no-dyn) semantics — per channel
  y = x0 + sw0*h0 + sw1*h1 + sw2*h2 + sw3*x0, scaled by 1/sqrt(5); the 3-tap
  history ring (t-3,t-2,t-1) shifts h0<-h1<-h2<-x0 in place. This is a defining
  Inkling mechanism (applied to k/v/attn/mlp). f32 history here; the BF16 ring
  for bit-exact CPU match is a later parity refinement.
- Multi-step parity test: 6-token recurrence vs a CPU oracle, per-step output
  match (<1e-5) AND device history ring == host history ring after all steps
  (exact). The stateful short-conv evolves correctly across tokens.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU 11/11 (--features hip).
This commit is contained in:
adm committed 2026-12-01 14:26:14 +01:00
1 parent 00a6993c50
commit e060862660
3 files changed
+96

No files matched your search

+41
View File
@@ -468,4 +468,45 @@ extern "C" int vetta_moe_reduce(const float* y_part, const float* tk_w, float* o
k_moe_reduce<<<(hidden + nt - 1) / nt, nt, 0, s>>>(y_part, tk_w, out, top_k, hidden);
HIP_CHECK(hipGetLastError());
return 0;
}
// ---- k_shortconv4_decode: Inkling causal depthwise ShortConv (kernel 4) ----
// Exact strata k2_shortconv4_batched (static, no dyn): per channel c, token t,
// y = x0 + sw0*h0 + sw1*h1 + sw2*h2 + sw3*x0; y *= 1/sqrt(5)
// history ring (t-3,t-2,t-1) shifts h0<-h1<-h2<-x0. f32 history here; the
// reference uses a BF16 ring for bit-exact CPU match (a parity refinement).
__global__ void k_shortconv4_decode(const float* __restrict__ cur,
const float* __restrict__ static_w,
float* __restrict__ hist,
float* __restrict__ out,
const int32_t* __restrict__ slot_ids,
int M, int C) {
const int c = blockIdx.x * blockDim.x + threadIdx.x;
const int m = blockIdx.y;
if (c >= C || m >= M) return;
const int slot = slot_ids[m];
float* h = hist + (size_t)slot * 3 * C;
const float h0 = h[0 * C + c];
const float h1 = h[1 * C + c];
const float h2 = h[2 * C + c];
const float x0 = cur[(size_t)m * C + c];
const float* sw = static_w + (size_t)c * 4;
float y = x0 + sw[0] * h0 + sw[1] * h1 + sw[2] * h2 + sw[3] * x0;
y *= 0.44721359549995793f; // 1/sqrt(5)
h[0 * C + c] = h1;
h[1 * C + c] = h2;
h[2 * C + c] = x0;
out[(size_t)m * C + c] = y;
}
extern "C" int vetta_shortconv4_decode(const float* cur, const float* static_w,
float* hist, float* out, const int32_t* slot_ids,
int M, int C, vetta_stream_t stream) {
if (M <= 0 || C <= 0) return 1;
dim3 grid((C + 255) / 256, M);
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
k_shortconv4_decode<<<grid, 256, 0, s>>>(cur, static_w, hist, out, slot_ids, M, C);
HIP_CHECK(hipGetLastError());
return 0;
}