From cb5e812ccc6222bc109093964238e142208ca560 Mon Sep 17 00:00:00 2001 From: keptn42 Date: Sat, 10 Oct 2026 13:11:03 +0000 Subject: [PATCH] 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. --- libr4d/r4d_attn_prefill_h256_gqa6.hip | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libr4d/r4d_attn_prefill_h256_gqa6.hip b/libr4d/r4d_attn_prefill_h256_gqa6.hip index 20746451..6e124859 100644 --- a/libr4d/r4d_attn_prefill_h256_gqa6.hip +++ b/libr4d/r4d_attn_prefill_h256_gqa6.hip @@ -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 ------------------------