attn prefill: a windowed CTA starts its KV walk at its own first row's window

The windowed prefill took the walk's first tile from the chunk's row 0, so every CTA of a long
chunk walked from the chunk's window start to its own causal limit. Tiles below the window of a
CTA's first row are masked for every row it holds, so starting there changes no value.
This commit is contained in:
keptn42 authored and sfjes committed 2026-10-10 08:08:43 -07:00
1 parent c045ff85e9
commit cb5e812ccc
1 file changed
+6 -3
+6 -3
View File
@@ -180,9 +180,12 @@ void r4d_attn_prefill_kernel(const R4DArgs a)
const int qmax_cta = min(qb * BLOCK_Q + BLOCK_Q - 1, qlen - 1);
const int klimit_cta = ctx - qlen + qmax_cta;
const int ntiles = (min(klimit_cta + 1, ctx) + TILE - 1) / TILE;
// The window's first tile, taken at query row 0 (whose window reaches furthest back); the walk
// starts there so no row's below-window tiles are fetched. WIN off (or window <= 0) starts at 0.
const int wlo0 = (WIN && a.window > 0) ? (ctx - qlen - a.window + 1) : 0;
// The window's first tile, taken at THIS CTA's first query row (whose window reaches furthest
// back among the rows it holds); the walk starts there, so no tile below every row's window is
// fetched. Taken at the CHUNK's row 0 instead, the last CTA of an 8192-token chunk walked eight
// thousand keys none of its rows can see -- fully masked tiles, so skipping them changes no
// value. WIN off (or window <= 0) starts at 0.
const int wlo0 = (WIN && a.window > 0) ? (ctx - qlen + qb * BLOCK_Q - a.window + 1) : 0;
const int tstart = (WIN && a.window > 0 && wlo0 > 0) ? (wlo0 / TILE) : 0;
// ---- staging, split into a global FETCH (registers) and an LDS STORE ------------------------