qsa: opt-in STRATA_PA_FAST=1 - the gfx11 prompt attention with single FP16 q and p

prompt_attn_wmma_kernel carries q and p as FP16 hi + lo pairs (two WMMAs each, FP32-level).  SPLIT = false drops
the lo halves: FP16 attention as the usual flash-attention kernels, half the matrix work.

gfx1151, real 64K selections (16383 queries x 2051 cells, one QSA layer): 138.7 -> 117.8 ms; rel RMS vs FP64
4.8e-7 -> 2.7e-4.  Engine 8K "qsa attn" 718 / 712 -> 589 / 590 ms.  Teacher-forced KL on three text offsets 0.153 /
0.087 / 0.027 (the accepted MMQ-vs-fused pair: 0.153 / 0.117 / 0.030).  Off by default.
This commit is contained in:
Niko1221 committed 2026-10-03 07:32:53 +00:00
1 parent 31b2472a3f
commit 7aaf466d18
1 file changed
+15 -5
+15 -5
View File
@@ -754,6 +754,10 @@ __device__ __forceinline__ wh8 i8_to_h(const uint32_t* x) { // PA_KL codes, ex
return h;
}
// SPLIT = true (default): q and p carried as FP16 hi + lo pairs (two WMMAs each: FP32-level). S23 (opt-in
// STRATA_PA_FAST=1): SPLIT = false, one FP16 image each - half the matrix work, rounding-level (FP16 attention as the
// usual flash-attention kernels), quality-gated
template <bool SPLIT>
__global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float* __restrict__ q, QsaAttnPools p,
const int32_t* __restrict__ ids,
const int32_t* __restrict__ steps, int n_kv_heads,
@@ -859,7 +863,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float*
}
const wh8 b = i8_to_h(kx);
s = wmma_f16(qh[kk], b, s);
s = wmma_f16(ql[kk], b, s);
if constexpr (SPLIT) s = wmma_f16(ql[kk], b, s);
}
#pragma unroll
for (int i = 0; i < 8; ++i) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * ksc;
@@ -925,7 +929,7 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float*
#pragma unroll
for (int i = 0; i < PA_KL; ++i) b[i] = (_Float16) (int) (int8_t) S.v[warp][cb + i][d];
tmp[j] = wmma_f16(ah, b, tmp[j]);
tmp[j] = wmma_f16(al, b, tmp[j]);
if constexpr (SPLIT) tmp[j] = wmma_f16(al, b, tmp[j]);
}
}
float a[8];
@@ -988,9 +992,15 @@ bool launch_wmma(const float* q, const QsaAttnPools& pools, const int32_t* ids,
const float scale_log2 = 1.4426950408889634f / sqrtf((float) HD);
for (int64_t q0 = 0; q0 < n_q; q0 += 65535) {
const int64_t nb = n_q - q0 < 65535 ? n_q - q0 : 65535;
prompt_attn_wmma_kernel<<<dim3((unsigned) nb, (unsigned) s.n_head_kv), THREADS, 0, st>>>(
q + q0 * s.n_head * HD, pools, ids + q0 * cap, steps + q0 * kStepCount, (int) s.n_head_kv,
(int) s.page_size, scale_log2, attn + q0 * s.n_head * HD, (int) cap);
static const bool fast = [] { const char* e = std::getenv("STRATA_PA_FAST"); return e != nullptr && e[0] == '1'; }();
if (fast)
prompt_attn_wmma_kernel<false><<<dim3((unsigned) nb, (unsigned) s.n_head_kv), THREADS, 0, st>>>(
q + q0 * s.n_head * HD, pools, ids + q0 * cap, steps + q0 * kStepCount, (int) s.n_head_kv,
(int) s.page_size, scale_log2, attn + q0 * s.n_head * HD, (int) cap);
else
prompt_attn_wmma_kernel<true><<<dim3((unsigned) nb, (unsigned) s.n_head_kv), THREADS, 0, st>>>(
q + q0 * s.n_head * HD, pools, ids + q0 * cap, steps + q0 * kStepCount, (int) s.n_head_kv,
(int) s.page_size, scale_log2, attn + q0 * s.n_head * HD, (int) cap);
}
const cudaError_t e = cudaGetLastError();
if (e != cudaSuccess) {