Skip to content

kv pool: a window's pages go back once their readers are done, and sliding attention reads through page tables (#2444 P4, step 1) - #3353

Merged
ashhart merged 6 commits into
ashhart:mainfrom
laudney:kv-windows-p41
Nov 16, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
laudney:kv-windows-p41

Conversation

@laudney

@laudney laudney commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

P4 of #2444 (sliding windows on pool pages, D4 and C5), its first step: the pool calls, a window helper and the kernel admission a sliding layer needs to keep its rows in pool pages. No family calls them yet, so every path today runs as before.

Before After
A lease's page mid-stream stays until the stream ends (or trim from the end) kv.retirement.retire(pool, lease, i, token) gives entry i back now; the page is reused only after settle(token), once the last forward that may read it is done
A retired page the store also holds n/a keeps its token until its last holder lets it go, so an eviction never frees it early
The lease's promise for a retired page n/a comes back at settle, so no count ever names a page that is not free; a page is reused only after the caller settles, once the forward's work is done
Free for take, runs, available(), reclaimable() nobody holds it nobody holds it and no reader of it is pending
A stream's sliding rows a ring outside the pool kv_window.zig, not used yet: bands of sliding layers in pages of the full group's rows (one logical page index for both groups); before each forward it retires the pages no kernel can load under that forward's token, which its caller settles once the forward's work is done, and covers the rows ahead, all or nothing; its promise covers one step's retired pages until that settle; a keep gets each band's pages, a resume places copies at their index
Head dim 256 paged attention with a window refused by the host admitted: the kernels already start at the window's first key and find each key's page by its position; head dim 512 and 128 keep their refusals

kv_pool.zig keeps its length (564 lines): the new state lives in kv_pool_retire.zig behind one field, allocated at a pool's first retire. Before any retire, every freed page goes to the free stack as today. reclaimable() scans only the pages that carry a token, not the whole pool.

Checks on this head

  • Head commit: e0ea94b, on main d6c4cce; it merges clean into today's main 41a72fd.
  • Lean checker on main 41a72fd and on this head merged into it: 341 and 341, 0 new.
  • Tests run on this head: zig build test: passed (712 of 712 steps; 3067 tests, 3026 passed, 41 skipped); zig build test-cuda-host: 6711 passed, 31 skipped; zig build test-kv-pool: 93 passed; zig build test-window-rows-host: 9 passed; zig build compile-cuda-tests: builds; zig fmt --check build.zig zig and git diff --check: clean. zig build test-golden passed on 91edde8; the two new commits touch only the pool's retire state and the window helper, which no golden reaches.
  • CI: pending.
  • Not run, and why: HIP and Metal (no change there); CUDA chips other than sm_121 (the kernels are unchanged, only their host admission).

Receipt

  • Main against branch: n/a. No family calls retire, settle, skip or the window helper, and none passes a window with pages, so no served path changes. The pool's shared paths are covered by the host suites above: before any retire, freeOrPend frees exactly as before and nothing is held.
  • Boxes it reaches: the core page pool (every paged family's leases, unchanged without a retire), kv_window.zig (no caller yet), the CUDA window attention host checks.
  • New switch? None.
  • Environment: Zig 0.17.0; GB10 (sm_121), CUDA 13.4 nvcc, for the kernel cells and the device test.
  • Paths and platforms: CUDA sm_121 run; other CUDA chips, HIP and Metal not run (no code there changes).
  • Exactness: the device test below, bit for bit against the ring kernel.
  • Decode and prompt speed: n/a (no served path changes).
  • Licence of any new weights or drafter: n/a.
Kernel contract
  • Kernels: no new kernel. The head dim 256 paged decode (tf_wrows_part_256_pg + tf_wrows_merge_256_pg) and paged prompt rows (tf_wrows_prompt_256_pg, tf_wrows_prompt_256_p32_pg) are now admitted with a window. Cells: decode at 32/16 heads, window 1024, and 16/8 heads, window 512; prompt rows (bf16 P, and P32 with image rows) at 32/16, window 1024; all with pages of 256.
  • Controls: windowed paged decode with two streams' tables swapped, windowed paged prompt rows with a stale first page: both red as planted.
  • SUMMARY (sm_121, filtered to window_pages and windowed paged): 16 kernels: 16 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 6 limit problems, exit 1 from the limit problems alone. They are register counts off the records (for example 108 against 110, 62 against 48 for tf_wrows_merge_256_pg) with threads and shared bytes equal: the images were built by nvcc 13.5 and checked against nvcc 13.3's records, and no kernel source changes here. The full output is in the comment below.
  • Device test (tf-cuda-test window-pages-512, which now also runs window_pages_slide_tests.zig): head dim 256 windowed decode over shuffled pages of 256 and 512 (31B's 32/16 at window 1024 with 2 streams, E4B's 8/2 at 512 with 3; rows at the first key, inside the first window, on page and window edges, scattered, the end) and prompt rows, bf16 P and P32 (at 0, across the window, far past it), with NaN in every unused slot and every page wholly below each stream's window: PASS, bit-equal to the ring kernel, so no kernel reads a page a stream has retired.
  • Chips not run: every CUDA chip but sm_121.

Host: the pool's retire, settle and skip (83 then 93 kv-pool cases): a page waits for its readers with every count and notice exact (checked against a scan of the pages); a page the store keeps is pending when evicted before settle, free when evicted after it, and backed through the reclaim chain when a credit needs it; no take or run gets a pending page; a failed settle grants its credit later and once; each allocation of a retire fails without a change; a share into an empty entry; the window helper's geometry for Gemma 4 31B (5 layers a band, 10 bands, no padding), Kolibri-1 (10, 4, none) and Gemma 4 26B-A4B (2, 13, 20 %), its live bound over a prefill and a decode with the caller settling after each forward, its band tables, keeps, resumes, and failed takes and table writes with exact retries; two leases on one pool, where another lease's page retired for forward t stays out of take, runs and available() while the window steps for forward t, until settle(t); and a full pool whose credit at settle reclaims a kept window page from the store. Planting immediate reuse fails four cases; planting a settle inside the window's step fails the two-lease case; planting the old promise fails the prefill case.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, this is a careful first step for P4. Keeping the retire state in its own file behind one field keeps kv_pool.zig at 564 lines, and with no retire every freed page goes to the free stack in the same order as on main. We traced every path that returns a lease's pages (unlease, drop, release of runs, shrink/trim, share, finish) and found nothing that changes for today's families. Nothing calls retire, settle, skip or kv_window.zig yet. No family builds a window with both win != 0 and pages, so the wider pageShape admission can't be reached on any served path. The series applies cleanly, and test-kv-pool (91 cases), test-lane-strand-host, test-lane-halt-host, test-lane-interrupted-host, test-lane-lone-host, test-window-rows-host and test-window-fallback-host pass. We also planted immediate reuse in freeOrPend, and the same four cases fail as you describe. Lean is 341 against 341 with nothing new, fmt is clean, and every file is under 600 lines.

One thing needs a change before this lands:

  1. zig/src/core/kv_window.zig:72 (and the errdefer at :63) settles the step's own token before the forward that token names has run. settle is pool-wide: zig/src/core/kv_pool_retire.zig:83 sets settled = @max(settled, token). So a window's step also frees every page that any other lease retired with a token no higher than its own, whether or not those readers are done. We checked this with a host test on this head:

    • lease A takes page 0 and calls retire(&pool, &a, 0, 5), so forward 5 may still read page 0;
    • a window on the same pool then calls step(&pool, 0, 256, 5, ...) before forward 5 is enqueued;
    • afterwards page 0 is no longer held and nothing is pending, and the window's own take got page 0 as its entry 0. Forward 5's put would write that page while A's reader in the same forward reads it.

    Inside one window, the same immediate settle frees the page the previous forward read (step(255, 256) after step(0, 255) frees page 0) without that forward being known done. That is only safe if every reader and every later writer of the page sit on one queue in order. The comment at :63 relies on that, but retire's doc promises something else ("the page is reused only after settle(token), once the last forward that may read it is done").

    Please have step retire with the token and leave settle to the caller once the forward's work is done. If stream order is the contract you want for window pages, keep them off the token path so the pool's settled can't move past another lease's reader. Either way, please add a host test with two leases on one pool showing that a page retired for forward t stays out of take, runs and available() until settle(t) runs after forward t.

A question for the next step rather than an ask here: settle grants each credit through promise, which can return LaneMemory. For example, a retired page the store also keeps may not be reclaimable when the credit falls due. When that happens, the stream's next take in step fails with PastReservation. How will the Gemma 4 wiring keep an admitted request finishing in that case?

Optional suggestions:

  • reclaimable() now scans every page (waiting, zig/src/core/kv_pool_retire.zig:110) once a pool has retired anything, and the ledger reads it on each admission check and change notice. A running count kept where ownership and retire change the counts would make it O(1).
  • Credit keeps a *Lease, and Window holds its lease by value. A window that moves while it owes a credit (a failed settle) would leave a dangling pointer, and forget would miss it. Please say in Window's doc that it must not move, or key credits by something that stays put.
  • The trailing comments at zig/src/core/kv_window.zig:63 and :112 run to 134 and 137 columns. Shortening them would keep them within 120.

On the receipt: since no served path changes, this step doesn't need main-against-branch numbers. Could you attach the device run's output (the full SUMMARY and the window-pages-512 pass lines from sm_121) so the kernel cells have a log behind them, not just the quoted line?

  • Synthena (Ash's Agent)

@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart thanks for the careful read. Two new commits answer it; the head is now e0ea94b6b (pushed on top, no force-push; still on main d6c4cce60, and it merges clean into today's 41a72fd25).

Point Change Check
Required: step settled its own token ff9a4f77b: Window.step only retires, under the forward's token; there is no settle in step or on its error path. The caller settles that token once the forward's work is done (a later token if the forward never runs), before the window's next step. promise() now adds, per band, (chunk + drafts + a - 1) / rows + 1: the pages one step can retire (first() moves by at most a forward's rows plus a tile), which owe their credit until that settle. New host test "a step settles nothing": a page of another lease retired for forward 5 stays held while the window steps for forward 5; the step takes two pages and neither is that page, no findRun covers it and available() does not change; after settle(5) it is free and available() is one higher. A settle planted back into step fails this test. The prefill-and-decode test now settles after each forward and checks that held plus pending pages stay within the promise; the old promise fails it.
Question: LaneMemory at settle No code change; see below. New host test "a full pool: a kept page the window retires…".
Optional: reclaimable() scanned every page e0ea94b6b: the retire state keeps a list of the pages that carry a token (each with its place in it, removed in constant time when its token clears), and waiting() scans that list only. It is not O(1): an exact count would need hooks in retain and release. The list holds only retired pages whose token has not cleared: those waiting for their settle (about one step's pages a window stream) and retired pages the store still keeps. The scan oracle checks the list and waiting() against a full scan; the first retire's allocation failures are covered at all five allocations.
Optional: Window must not move Its doc now says so: a credit points at its lease. n/a
Optional: long comments The comment at :63 went with the settle; the one at :112 is on its own line. Every new comment is one line of at most 120 columns. Lean on this head merged into main: 341 and 341, 0 new.
Receipt: device output The full output is below. One correction to the description: the images were built by nvcc 13.5 and checked against nvcc 13.3's records (the description said 13.4 and 13.0). The run exits 1 only because of the six register-count limit lines. Below.

On LaneMemory at settle. A credit is backed by the page it was given for. At settle that page is either free (it was pending) or held by the store alone, because window pages are never shared between leases (a resume copies). Once its token is settled, waiting() no longer counts it, so it is reclaimable, and the credit's promise reclaims it through the chain. The promise fails only if the store pins that page at that moment. The store pins pages only inside a keep or a restore. In the Gemma 4 wiring (P4.2), the lane settles at the round's end, after the round's forward and outside keep and restore. The new test pins this case: a pool with room for one window only, the store keeps window page 0, each step retires a page, and every settle grants its credit, the first by reclaiming the kept page. If a settle still fails, the credit stays owed and a later settle grants it once (the existing "a settle that cannot grant a credit" test). The next step's take then fails with PastReservation before its forward runs, and the lane ends that request with its memory refusal, as it does for any failed take today. P4.2 will include a lane test for that path.

Checks on e0ea94b6b: zig build test 3026 passed and 41 skipped (712 of 712 steps), test-cuda-host 6711 passed and 31 skipped, test-kv-pool 93 passed, test-window-rows-host 9 passed, compile-cuda-tests builds, and zig fmt --check and git diff --check are clean. I updated the description to match.

Device test: tf-cuda-test window-pages-512 on sm_121
PASS window pages 256: windowed decode over shuffled pages of 256 and 512 and prompt rows (P as bf16 and P32), NaN in every unused slot and every page below each window, bit-equal to the ring kernel
rc=0
Kernel contract on sm_121, filtered to window_pages and windowed paged (full output)
N/A  cuda affine4 MLP128 replacement bits: cluster path needs sm_90 or newer, this GPU is sm_121
N/A  cuda affine4 MLP128 FP64: cluster path needs sm_90 or newer, this GPU is sm_121
PASS nonfinite cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 256: five runs byte-identical (32768 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 256: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 256: within its bound at k 32768; fp16 sums would miss infx, bf16 0.1x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 1024: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 1024: five runs byte-identical (32768 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 1024: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/4 heads, no window, pages of 1024: within its bound at k 32768; fp16 sums would miss infx, bf16 0.1x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 256: five runs byte-identical (524288 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 256: 11 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 256: within its bound at k 4096; fp16 sums would miss infx, bf16 0.5x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 1024: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 1024: five runs byte-identical (524288 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 1024: 11 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 16/4 heads, no window, pages of 1024: within its bound at k 4096; fp16 sums would miss infx, bf16 0.5x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 256: five runs byte-identical (524288 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 256: 11 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 256: within its bound at k 4096; fp16 sums would miss infx, bf16 7.7x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 32: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 32: five runs byte-identical (524288 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 32: 11 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 16/4 heads, no window, pages of 32: within its bound at k 4096; fp16 sums would miss infx, bf16 12.9x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 256: five runs byte-identical (65536 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 256: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 256: within its bound at k 32768; fp16 sums would miss infx, bf16 0.0x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 37: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 37: five runs byte-identical (65536 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 37: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 16/1 heads of 512, pages of 37: within its bound at k 32768; fp16 sums would miss infx, bf16 0.0x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 10/2 heads of 512 (GQA 5), pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 10/2 heads of 512 (GQA 5), pages of 256: five runs byte-identical (40960 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 10/2 heads of 512 (GQA 5), pages of 256: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_512_pg + tf_wrows_merge_512_pg, 10/2 heads of 512 (GQA 5), pages of 256: within its bound at k 32768; fp16 sums would miss infx, bf16 0.0x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 16/1 heads of 512, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 16/1 heads of 512, pages of 256: five runs byte-identical (1048576 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 16/1 heads of 512, pages of 256: 11 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 16/1 heads of 512, pages of 256: within its bound at k 4096; fp16 sums would miss infx, bf16 4.0x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_512_pg (P as bf16), 32/4 heads of 512, pages of 64: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_512_pg (P as bf16), 32/4 heads of 512, pages of 64: five runs byte-identical (2097152 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_512_pg (P as bf16), 32/4 heads of 512, pages of 64: 10 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_512_pg (P as bf16), 32/4 heads of 512, pages of 64: within its bound at k 3000; fp16 sums would miss infx, bf16 0.5x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 10/2 heads of 512 (GQA 5), pages of 32: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 10/2 heads of 512 (GQA 5), pages of 32: five runs byte-identical (655360 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 10/2 heads of 512 (GQA 5), pages of 32: 10 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_512_p32_pg, 10/2 heads of 512 (GQA 5), pages of 32: within its bound at k 3000; fp16 sums would miss infx, bf16 4.8x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 32/16 heads, window 1024, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 32/16 heads, window 1024, pages of 256: five runs byte-identical (262144 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 32/16 heads, window 1024, pages of 256: 8 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 32/16 heads, window 1024, pages of 256: within its bound at k 32000; fp16 sums would miss infx, bf16 73.1x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/8 heads, window 512, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/8 heads, window 512, pages of 256: five runs byte-identical (131072 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/8 heads, window 512, pages of 256: 7 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages decode tf_wrows_part_256_pg + tf_wrows_merge_256_pg, 16/8 heads, window 512, pages of 256: within its bound at k 32000; fp16 sums would miss infx, bf16 49.4x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 32/16 heads, window 1024, pages of 256, image rows: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 32/16 heads, window 1024, pages of 256, image rows: five runs byte-identical (1048576 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 32/16 heads, window 1024, pages of 256, image rows: 10 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_p32_pg, 32/16 heads, window 1024, pages of 256, image rows: within its bound at k 5000; fp16 sums would miss infx, bf16 7.9x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
PASS nonfinite cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 32/16 heads, window 1024, pages of 256: the stated rule holds: outputs equal the float64 reference's bytes
PASS repeat cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 32/16 heads, window 1024, pages of 256: five runs byte-identical (1048576 bytes), inputs and guards untouched, no overlap
PASS shapes cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 32/16 heads, window 1024, pages of 256: 10 shapes exact by its own check (worst 0.000 of the bound), 0 edges refused by the kernel
PASS sums cuda window_pages prompt tf_wrows_prompt_256_pg (P as bf16), 32/16 heads, window 1024, pages of 256: within its bound at k 5000; fp16 sums would miss infx, bf16 0.6x (all keys alike make every weight exactly 1: o is a plain sum of V's integers, exact in fp32 (any order); fp16 sums overflow, bf16 ones lose its low bits)
FAIL shapes control: windowed paged decode whose first two streams' tables are swapped: at 16x32x32000: row 0 head 0 out[0] = -1.9335938e-1 (0xbe46) outside float64's -9.921875e-1 +- 1.67964553909227e-5
CONTROL control: windowed paged decode whose first two streams' tables are swapped: red at shapes, as planted
FAIL shapes control: windowed paged prompt rows whose first page id is a later page's: at 512x32x0: row 0 head 0 out[0] = -1.2734375e0 (0xbfa3) outside float64's 1.2578125e0 +- 3.0979616774871244e-5
CONTROL control: windowed paged prompt rows whose first page id is a later page's: red at shapes, as planted
PASS limits live sm_121 most shared bytes a block (opt-in): the driver says 101376, the table 101376
PASS limits live sm_121 threads a block: the driver says 1024, the table 1024
INFO limits live: images built by nvcc 13.5, checked against nvcc 13.3's records (the newest set at or below it)
FAIL limits live window_pages tf_wrows_part_256_pg: 256 threads launched, the driver allows 256; 108 registers, 46208 + 0 shared bytes (recorded 110, 46208)
FAIL limits live window_pages tf_wrows_merge_256_pg: 256 threads launched, the driver allows 256; 62 registers, 128 + 0 shared bytes (recorded 48, 128)
FAIL limits live window_pages tf_wrows_prompt_256_pg: 256 threads launched, the driver allows 256; 254 registers, 144 + 81920 shared bytes (recorded 255, 144)
PASS limits live window_pages tf_wrows_prompt_256_p32_pg: 256 threads launched, the driver allows 256; 255 registers, 144 + 81920 shared bytes (recorded 255, 144)
FAIL limits live window_pages tf_wrows_part_512_pg: 256 threads launched, the driver allows 256; 120 registers, 17536 + 65536 shared bytes (recorded 122, 17536)
PASS limits live window_pages tf_wrows_merge_512_pg: 256 threads launched, the driver allows 256; 60 registers, 128 + 0 shared bytes (recorded 60, 128)
FAIL limits live window_pages tf_wrows_prompt_512_pg: 256 threads launched, the driver allows 256; 255 registers, 144 + 81920 shared bytes (recorded 253, 144)
FAIL limits live window_pages tf_wrows_prompt_512_p32_pg: 256 threads launched, the driver allows 256; 254 registers, 144 + 81920 shared bytes (recorded 255, 144)
PASS limits live window_pages tf_wrows_put: 128 threads launched, the driver allows 128; 38 registers, 0 + 0 shared bytes (recorded 38, 0)
(filtered) SUMMARY 16 kernels: 16 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 6 limit problems; gates 469394 ms, limits 0 ms
FAIL kernel-contract: 0 gate failures, 0 controls missed, 6 limit problems
FAIL kernel-contract: TestFailed
rc=1

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jschmied, the required change is in and the host tests pin it: a step retires under the forward's token and
leaves the settle to the caller, so a window's step can no longer free another lease's reader. The pool's
shared paths are exercised by the suites, the waiting count scans only the pages that carry a token, and no
family calls any of the new calls yet - so no served path moves.

Your answer on the LaneMemory question reads right for the wiring you describe: a credit's page is either
free or held by the store alone at settle, the store pins pages only inside a keep or a restore, and the Gemma
4 lane settles at the round's end - outside keep and restore. The new test that pins the full-pool case is the
right guard for it.

Nothing to change from us. The next step of #2444 - the Gemma 4 sliding layers on these pages behind the
window flag - is where the round-end settle gets its first real caller, and the device run your description
carries already shows the windowed paged kernels bit-equal to the ring kernel on sm_121.

  • Synthena (Ash's Agent)

laudney and others added 6 commits November 16, 2026 14:01
C5 of ashhart#2444: a sliding window gives back the pages behind it while
its stream runs. A retired page carries the token of the last
forward that may read it until its last holder lets it go, waits
pending until settle passes that token, and only then is free; the
lease's promise for it comes back at settle, so no count names a
page that is not free and no run takes a pending page. The state
lives in one field, allocated at a pool's first retire.
P4 of ashhart#2444: a window helper lays a family's sliding layers out as
bands in pool pages of its full pages' rows, each band its own table
on one page-major lease. Before each forward it retires the pages no
kernel can load again and covers the rows ahead, all or nothing, and
it hands a keep each band's pages from the window's first loaded row.
P4 of ashhart#2444: the head dim 256 paged attention kernels already start
at a window's first key and find each key's page by its absolute
position, so the host now admits a window with pages there. Contract
cells and a device test show the paged path gives the ring kernel's
bits, with NaN in every page below each window, so no kernel reads a
page a stream has retired.
Window.step settled its own forward's token before that forward ran,
and settle is pool-wide, so it could free another lease's page
retired under the same token while that forward might still read
it. A step now only retires under its token; the caller settles the
token once the forward's work is done, before the window's next
step, and the window's promise covers one step's retired pages until
then. Tests settle after each forward, show a page retired for
forward t staying out of take, runs and available() until settle(t),
and show a full pool's credit backed by reclaiming a kept page.
reclaimable() subtracted waiting(), which scanned every page of the
pool once any page had been retired. The retire state now keeps a
list of the pages that carry a token, each with its place in the
list, so waiting() scans only those and a page leaves the list in
constant time when its token clears. The scan oracle checks the list
and waiting() against a full scan, and the first retire's allocation
failures are covered at all five allocations.
@ashhart
ashhart merged commit 116b811 into ashhart:main Nov 16, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants