[HIP] DSpark brick 5b-1: per-prefix ShortConv history snapshots kernel

k_shortconv4_hist_snaps: snaps[t] (t=0..B) = [3,C] history after t tokens of
in_x from hist0, same bf16-round/shift semantics as update_hist. Enables exact
DSpark partial-accept rollback (hist <- snaps[accepted]); the KV ring truncates
with no data restore (proofs/speculative_draft.lean kept_rejected_disjoint).
Parity: snaps[t] == verified update_hist on prefix t, all 9 prefixes EXACT.
This commit is contained in:
adm committed 2026-12-02 20:56:49 +01:00
1 parent 3812845f1a
commit ca12801b40
2 files changed
+80

No files matched your search

+44
View File
@@ -1980,6 +1980,50 @@ extern "C" int vetta_shortconv4_update_hist(const float* in_x, float* hist, int
return 0;
}
// ---- k_shortconv4_hist_snaps: per-prefix ShortConv history snapshots --------
// snaps[t] (t=0..B) = the [3,C] history after processing t tokens of in_x from
// hist0, with the SAME bf16-round + shift semantics as update_hist. Used for
// DSpark partial-accept rollback: hist <- snaps[accepted] (KV ring truncates).
__global__ void k_shortconv4_hist_snaps(const float* __restrict__ in_x,
const float* __restrict__ hist0,
float* __restrict__ snaps, int B,
int C) {
const int c = blockIdx.x * blockDim.x + threadIdx.x;
if (c >= C) return;
snaps[(size_t)0 * 3 * C + 0 * C + c] = hist0[0 * C + c];
snaps[(size_t)0 * 3 * C + 1 * C + c] = hist0[1 * C + c];
snaps[(size_t)0 * 3 * C + 2 * C + c] = hist0[2 * C + c];
for (int t = 1; t <= B; ++t) {
float h0, h1, h2;
if (t >= 3) {
h0 = bf16_round(in_x[(size_t)(t - 3) * C + c]);
h1 = bf16_round(in_x[(size_t)(t - 2) * C + c]);
h2 = bf16_round(in_x[(size_t)(t - 1) * C + c]);
} else if (t == 2) {
h0 = hist0[2 * C + c];
h1 = bf16_round(in_x[0 * C + c]);
h2 = bf16_round(in_x[1 * C + c]);
} else {
h0 = hist0[1 * C + c];
h1 = hist0[2 * C + c];
h2 = bf16_round(in_x[0 * C + c]);
}
snaps[(size_t)t * 3 * C + 0 * C + c] = h0;
snaps[(size_t)t * 3 * C + 1 * C + c] = h1;
snaps[(size_t)t * 3 * C + 2 * C + c] = h2;
}
}
extern "C" int vetta_shortconv4_hist_snaps(const float* in_x, const float* hist0,
float* snaps, int B, int C,
vetta_stream_t stream) {
if (B <= 0 || C <= 0) return 1;
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
k_shortconv4_hist_snaps<<<(C + 255) / 256, 256, 0, s>>>(in_x, hist0, snaps, B, C);
HIP_CHECK(hipGetLastError());
return 0;
}
// ---- k_attn_res_mix: Inkling AttnRes deep-residual block-mix (parity) ------
// Exact strata k1_attn_res_mix: for each query q and token m, mix n_states =
// n_blocks+1 depth states (block snapshots + current). Per state s: