libxe2: decode / verify attention on DPAS, the keys split 32 ways

attn_paged_fast's single-sequence calls under 16 rows took the SIMT kernel (a lane a key, full
256-wide dots: ~137 us a verify call at ~400 tokens). The flash kernel now has a split form: a
work-group a (row block, kv head, partition), partitions past the context exit at once, each
partition's unnormalised (m, l, O) to scratch and a merge pass a sub-group a (row, head).
XE2_ATTN_DEC_SIMT=1 keeps the SIMT kernel. rad-kbench -m mtp4 --op attn_paged: 240/240; greedy
against SIMT 5/8 identical, the others diverge late at near-ties.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-02 01:52:01 +01:00
1 parent 726e532114
commit 2d2356ad4b
2 files changed
+87 -13

No files matched your search

+3 -3
View File
@@ -34,7 +34,7 @@ namespace xe2 {
int attn_flash_esimd(sycl::queue& q, int64_t head_dim, const uint16_t* qb, int64_t q_rs, int64_t q_hs, const uint16_t* cb,
int64_t sb, int64_t sh, int64_t so, const char* btb, uint32_t btdt, int64_t bt_cs, const char* sub,
uint32_t sudt, int64_t rows, int64_t kv_heads, int64_t gqa, float scale, int64_t jcap,
uint16_t* ob, int64_t o_rs, int64_t o_hs);
uint16_t* ob, int64_t o_rs, int64_t o_hs, void* scratch, int64_t scratch_bytes);
namespace {
@@ -113,7 +113,7 @@ int attn_paged_fast(const RadArgs* a, RadStream st) {
/* A single sequence's prefill on DPAS (xe2_attn_flash_esimd.cpp): bf16 throughout, pages of 16,
* causal without a window, every 2D load's base and pitch on its alignment. */
if (n_seq == 1 && rows >= 16 && causal && window == 0 && !KD && !VD && Q->dtype == RAD_BF16 &&
if (n_seq == 1 && (rows >= 16 || !std::getenv("XE2_ATTN_DEC_SIMT")) && causal && window == 0 && !KD && !VD && Q->dtype == RAD_BF16 &&
KV->dtype == RAD_BF16 && O->dtype == RAD_BF16 && q_ds == 1 && o_ds == 1 && sd == 1 && block_size == 16 &&
rad_ptr_aligned(Q->data, 64) && rad_ptr_aligned(KV->data, 64) && rad_ptr_aligned(O->data, 64) &&
(q_rs * 2) % 64 == 0 && (q_hs * 2) % 64 == 0 && (so * 2) % 64 == 0 && (sb * 2) % 64 == 0 &&
@@ -124,7 +124,7 @@ int attn_paged_fast(const RadArgs* a, RadStream st) {
const int rc = attn_flash_esimd(*fq, head_dim, (const uint16_t*)Q->data, q_rs, q_hs, (const uint16_t*)KV->data,
sb, sh, so, (const char*)BT->data, BT->dtype, bt_cs, (const char*)SU->data,
SU->dtype, rows, kv_heads, gqa, fscale, max_blocks * block_size,
(uint16_t*)O->data, o_rs, o_hs);
(uint16_t*)O->data, o_rs, o_hs, a->scratch, a->scratch_bytes);
if (rc != RAD_E_UNSUPPORTED) return rc;
}