Implement the forward pass of the selection attention branch — the core sparse attention kernel in NSA. Given top-k block indices, this kernel gathers the selected KV blocks and computes attention only over those blocks.
Input: Q [B, M, H, D], K [B, N, G, D], V [B, N, G, D], block_indices [B, M, G, T]
Output: O_slc [B, M, H, D], LSE_slc [B, H, M]
Where T = block_count (number of selected blocks per query).
Parent
Part of #1243 — DeepSeek NSA kernels for MI350
Description
Implement the forward pass of the selection attention branch — the core sparse attention kernel in NSA. Given top-k block indices, this kernel gathers the selected KV blocks and computes attention only over those blocks.
Operation
Where T = block_count (number of selected blocks per query).
Algorithm
For each query position m:
Requirements
block_size=64andblock_size=32MI350 considerations
tl.multiple_of(col, SELECTION_BLOCK_SIZE)hint in the reference is critical for coalesced loads on MI350Performance target
Depends on
References
_sel_attn_fwd_kernelin tilde-research/nsa-impl/nsa/selection.py