Archived
libxe2: sliding-window attention on the DPAS kernels
attn_paged_fast sent any window > 0 to the SIMT split-KV kernel, so every sliding-window layer (Gemma 2/3/4, Mistral-style and gpt-oss models) missed the DPAS decode and prefill kernels. They now take the window: each 8-row block starts at its first row's bound (pos - window + 1, on a whole 32-key step; the split decode form partitions from there) and the mask hides keys below each row's own bound, as libref's attn_paged. The window form is its own instantiation (WIN), so the window-0 kernels are unchanged: the Qwen3.5-9B's attention times match a rebuild of the old code to 0.5%. The quad prefill form keeps window 0; a windowed prefill takes the esimd prefill form. rad-kbench, Gemma 4 E2B (head_dim 256, window 512): decode 101 -> 23.5 us and 23 -> 18 us; q_len 128 757 -> 92 us; q_len 512 2833 -> 98 us; 320/320 within tolerance. Qwen3.5-9B 160/160, default fixture 2144/2144. Gemma 4 E2B end to end: decode 63.0 -> 74.4 tok/s, 2.4k-token prefill 1537 -> 1886 tok/s; a story, a 120-paragraph count and a password at paragraph 77 of 120 answered correctly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d35027aaf7
commit
dd20835f18
2 files changed
+44
-28
No files matched your search
@@ -34,7 +34,8 @@ 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, void* scratch, int64_t scratch_bytes);
|
||||
uint16_t* ob, int64_t o_rs, int64_t o_hs, void* scratch, int64_t scratch_bytes,
|
||||
int64_t window);
|
||||
/* xe2_attn_flash_quad.cpp: the prefill form at the default register file, four threads a (16 rows,
|
||||
* query head); RAD_E_UNSUPPORTED where it does not serve, and attn_flash_esimd then runs */
|
||||
int attn_flash_quad(sycl::queue& q, int64_t head_dim, const uint16_t* qb, int64_t q_rs, int64_t q_hs, const uint16_t* cb,
|
||||
@@ -118,9 +119,9 @@ int attn_paged_fast(const RadArgs* a, RadStream st) {
|
||||
const bool vec_kv = KV->dtype == RAD_BF16 && sd == 1 && head_dim % 8 == 0 && sb % 8 == 0 &&
|
||||
sh % 8 == 0 && so % 8 == 0 && rad_ptr_aligned(KV->data, 16);
|
||||
|
||||
/* 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 || !std::getenv("XE2_ATTN_DEC_SIMT")) && causal && window == 0 && !KD && !VD && Q->dtype == RAD_BF16 &&
|
||||
/* A single sequence on DPAS (xe2_attn_flash_esimd.cpp): bf16 throughout, pages of 16, causal, any
|
||||
* sliding window (the quad prefill form without one), every 2D load's base and pitch on its alignment. */
|
||||
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 &&
|
||||
@@ -128,7 +129,7 @@ int attn_paged_fast(const RadArgs* a, RadStream st) {
|
||||
sycl::queue* fq = queue_of(st);
|
||||
if (!fq) return RAD_E_DEVICE;
|
||||
const float fscale = (float)rad_args_getf_or(a, "scale", (double)(1.0f / std::sqrt((float)head_dim)));
|
||||
if (rows >= 16 && !std::getenv("XE2_ATTN_NO_QUAD")) {
|
||||
if (rows >= 16 && window == 0 && !std::getenv("XE2_ATTN_NO_QUAD")) {
|
||||
const int rq = attn_flash_quad(*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,
|
||||
@@ -138,7 +139,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, a->scratch, a->scratch_bytes);
|
||||
(uint16_t*)O->data, o_rs, o_hs, a->scratch, a->scratch_bytes, window);
|
||||
if (rc != RAD_E_UNSUPPORTED) return rc;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user