Archived
libxe2: prefill flash attention's two pages' score chains interleaved
S = Q K^T for a step's two pages ran as two chains of 16 DPAS, one after the other, each DPAS waiting on the last's accumulator. With both pages mapped they now advance together a head-dim step at a time, the same sums in the same order; a step with one page keeps the single chain. (Tried before the large-GRF fix it was slower: the extra K operand spilled.) Probe fa.cpp (24/4 heads, head_dim 256): 8192 tokens 15.6 -> 18.9 TFLOPS, 2048 tokens 13.4 -> 13.5; output identical. rad-kbench attn --all-rows 227/227. qwen3.8-27b-w4a16 (mtp4fc), fresh prompts: prefill ~6.9k tokens 1301 -> 1326 tok/s, ~2.1k 1376 -> 1381; greedy 8/8 identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8fced2e79f
commit
c5fe770657
1 file changed
+21
-3
@@ -104,16 +104,34 @@ int launch(sycl::queue& q, const uint16_t* qb, int64_t q_rs, int64_t q_hs, const
|
||||
for (int64_t j0 = jbeg; j0 < jhi; j0 += 32) {
|
||||
simd<float, 128> S[2];
|
||||
int64_t blk[2];
|
||||
/* the two pages' score chains interleaved a head-dim step at a time: each was 16 DPAS
|
||||
* deep on one accumulator, each waiting on the last (the same sums in the same order) */
|
||||
const uint32_t* pgk[2];
|
||||
#pragma unroll
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
const int64_t jp = j0 + 16 * p;
|
||||
blk[p] = jp < jhi ? ld_index(btdt, btb, (jp / 16) * bt_cs) : -1;
|
||||
S[p] = 0.0f;
|
||||
if (blk[p] >= 0) {
|
||||
const uint32_t* pg = (const uint32_t*)(cb + blk[p] * sb + kh * sh);
|
||||
pgk[p] = (const uint32_t*)(cb + (blk[p] >= 0 ? blk[p] : 0) * sb + kh * sh);
|
||||
}
|
||||
if (blk[0] >= 0 && blk[1] >= 0) {
|
||||
#pragma unroll
|
||||
for (int k = 0; k < KS; ++k) {
|
||||
simd<uint32_t, 64> qa = slm_block_load<uint32_t, 64>(qsl + k * 256);
|
||||
simd<uint32_t, 128> k0 = load_2d<uint32_t, 8, 16, 1, true>(pgk[0], pw, ph, pw, k * 8, 0);
|
||||
simd<uint32_t, 128> k1 = load_2d<uint32_t, 8, 16, 1, true>(pgk[1], pw, ph, pw, k * 8, 0);
|
||||
S[0] = xmx::dpas<8, 8, float, float, uint32_t, uint32_t, xmx::dpas_argument_type::bf16,
|
||||
xmx::dpas_argument_type::bf16>(S[0], k0, qa);
|
||||
S[1] = xmx::dpas<8, 8, float, float, uint32_t, uint32_t, xmx::dpas_argument_type::bf16,
|
||||
xmx::dpas_argument_type::bf16>(S[1], k1, qa);
|
||||
}
|
||||
} else {
|
||||
#pragma unroll
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
if (blk[p] < 0) continue;
|
||||
#pragma unroll
|
||||
for (int k = 0; k < KS; ++k) {
|
||||
simd<uint32_t, 128> kt = load_2d<uint32_t, 8, 16, 1, true>(pg, pw, ph, pw, k * 8, 0);
|
||||
simd<uint32_t, 128> kt = load_2d<uint32_t, 8, 16, 1, true>(pgk[p], pw, ph, pw, k * 8, 0);
|
||||
simd<uint32_t, 64> qa = slm_block_load<uint32_t, 64>(qsl + k * 256);
|
||||
S[p] = xmx::dpas<8, 8, float, float, uint32_t, uint32_t, xmx::dpas_argument_type::bf16,
|
||||
xmx::dpas_argument_type::bf16>(S[p], kt, qa);
|
||||
|
||||
Reference in new issue
Block a user