Skip to content

[Frontend] A prefill's block is bounded by one query block's scratch, not S / BQ of them - #402

Merged
YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
attn-block-one-set
Oct 21, 2026
Merged

YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
attn-block-one-set

Conversation

@student-Jungmin

Copy link
Copy Markdown
Collaborator

What

attention.fused_plan bounds a prefill's block by one query block's scratch, not by S / BQ blocks of it.

The prefill kernel's static query loop makes a new set of q, K^T, V, score and accumulator buffers per query block, each dead once its block has stored. _fits took copies=S // block sets of them, so the bound grew with S and the block was halved to fit: S 4096 ran at 512 and S 8192 at 128, against splash's 1024 on v6e. A smaller block runs the same rows as more, shorter steps, each paying the matrix unit's fill and drain again.

Depends on

PyTorchSim-Triton-Backend #227, torchsim-share-spad-buffers, which gives the query blocks one set of scratchpad buffers. On a compiler without it, a 1024 block at S >= 4096 overruns the scratchpad. Draft until #227 is on PTB main and this repository's compiler pin carries it. The pin bump goes in with this PR.

Test

tests/ops/attention/test_fused_sdpa.py spad:

  • doubling S keeps min(S, SPLASH_BLOCK);
  • doubling D halves the block until one row per lane overruns the bound and the plan declines.

The S case fails on the tree before this change.

Numbers (local, labelled)

These were measured with PTB's validation harness: validation/attention/simulate_shapes.py --bundle. The bundle's prefill specs carry the blocks this change gives (1024 at S >= 4096). The compiler is PTB main with its open PRs #222, #223, #227 and #228 stacked, at TOGSim e2d7a49. The ratio is TOGSim time ÷ v6e latency_ns.

prefill block main CI stacked
16x8 S 4096 512 → 1024 2.212 1.118
24x8 S 4096 512 → 1024 1.129
32x8 S 4096 512 → 1024 1.134
64x8 S 4096 512 → 1024 1.143
32x8 S 8192 128 → 1024 timed out 1.198

CI numbers follow once the pin carries #227.

🤖 Generated with Claude Code

… not S / BQ of them

The static query loop's blocks each die once their block has stored, and the
compiler (PyTorchSim-Triton-Backend's torchsim-share-spad-buffers) gives them
one set of scratchpad buffers. The bound therefore no longer grows with S:
S 4096 keeps splash's 1024 block instead of 512, and S 8192 keeps 1024
instead of 128.

This needs the compiler pin to carry that pass: on a compiler without it, a
1024 block at S >= 4096 overruns the scratchpad.

test_fused_sdpa spad: doubling S keeps min(S, SPLASH_BLOCK); doubling D halves
the block until one row per lane overruns the bound and the plan declines.
@YWHyuk
YWHyuk marked this pull request as ready for review October 21, 2026 04:14
@YWHyuk
YWHyuk merged commit 8b2c0d1 into pytorchsim-triton-backend Oct 21, 2026
@student-Jungmin
student-Jungmin deleted the attn-block-one-set branch October 21, 2026 12:30
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