Archived
libxe2: prefill flash attention four threads a (16 rows, query head), at the default register file
The 8-row form holds a thread's 8 x 256 f32 accumulator, which keeps it on the large register file
at 4 threads an EU; its stall samples were scoreboard waits, too few threads to cover the latency
of each step's loads and DPAS chains (paired threads sharing 16 rows showed it: 15 TFLOPS at one
work-group a core, 23.6 at two).
xe2_attn_flash_quad.cpp: a quad of threads takes 16 query rows of one head and 64 keys a step,
thread qd scoring page qd for all 16 rows (two DPAS chains on each key tile), the quad swapping row
maxima, then P and row sums, through local memory, and each thread running P V for its quarter of
the head dims. A 16 x 64 f32 accumulator: 128 registers with no spill, two work-groups (48
threads) a core. The softmax runs in the step's two 32-key halves in turn, so every value is the
8-row form's: probe output bit-identical at 2k..64k. It lives in libxe2 proper (the large-register
library would force it to 256); attn_paged_fast tries it first for rows >= 16, XE2_ATTN_NO_QUAD
skips it. (The query staging split four ways, by head-dim steps too, gave wrong output; two
threads stage a half each, not understood yet.)
Probe, 2048 rows over 2k / 8k / 16k / 32k / 64k of context: 16.7 / 25.0 / 24.0 / 23.4 / 22.3 ->
18.8 / 28.0 / 28.2 / 28.5 / 28.1 TFLOPS. Fresh prompts (mtp4fc, MTP 6), against 2da2eb0: ~2.1k
1419 -> 1426 tok/s, ~6.9k 1382 -> 1400, ~24k 1177 -> 1221, ~47k 952 -> 1025.
rad-kbench attn --all-rows 227/227, full replay 1410/1410, greedy 8/8.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2da2eb0b6c
commit
86955a62c5
2 files changed
+268
No files matched your search
@@ -35,6 +35,12 @@ int attn_flash_esimd(sycl::queue& q, int64_t head_dim, const uint16_t* qb, int64
|
||||
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);
|
||||
/* 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,
|
||||
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);
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -121,6 +127,13 @@ 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")) {
|
||||
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,
|
||||
(uint16_t*)O->data, o_rs, o_hs);
|
||||
if (rq != RAD_E_UNSUPPORTED) return rq;
|
||||
}
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user