verify: STRATA_QSA_SLOTS=1 runs a batch window's QSA block scores, top-k and attention as one launch over its rows
In a batch window every row reads its own slot's indexer keys and K/V, so each QSA layer ran the selection and attention once per row: four rows (16 slots) or eight (32 slots) times qsa_block_scores, qsa_block_topk and qsa_decode_attn_batch, each launch small (the top-k on one CTA, the attention on cap/64 x 2 blocks). With the switch, per window (up to 8 rows per launch): - block_scores_slots_kernel: grid (256, rows), blockIdx.y runs the single-query block_scores_multi_kernel body with that row's slot keys (block_scores_multi_kernel is now a wrapper around the same body) - qsa_block_topk over the rows in one call (it only reads the rows' scores and steps) - attn_chunk_slots_kernel: attn_chunk_kernel's body with the row's own QsaAttnPools (an 8-entry table passed by value, blockIdx.z picks), then the existing batched merge Each row is computed by the same kernel body with the same reduction order as its own call. The launchers decline (the per-row calls run) where that call would pick another kernel: STRATA_SCORES_MULTI=0, the pre-sm_75 / gfx103x attention, the gfx906 query swizzle. A streamed KV cache keeps the per-row resolve-then-attend loop. Default (switch off): unchanged. Checked on 4x RTX 3090, T16-143gsc setup (layer split 12,24,37, int8 KV): - SASS (sm_86) of every existing kernel in qsa_select.cu and of the default attn_chunk_kernel<M> and the merge is identical before/after; the opt-in lane-cell instantiations differ only in register allocation - new qsa_slots_parity (ctest, also with STRATA_ATTN_LANECELL=1): fp16, int8, q4_0 and int8-K/q4_0-V pools, 1/2/4/8 rows of different slots with their own page tables and contexts 37..32768: scores, ids and attention bitwise identical to one call per row - batch_test16/32 (greedy and t=0.7), batch_interleave_test and batch_overlap_test (STRATA_PIPE_OVERLAP=1) token-identical to the build without the change; with the switch off batch_test16 is byte-identical too - batch decode rows/s (engine level, 30 s, back to back with the reference): 16 slots 683 -> 726 (+6.3 %), 32 slots 750 -> 802 (+6.9 %); STRATA_VERIFY_PROFILE "QSA projections + attention" per stage-window 0.89 -> 0.52 ms (16) and 1.52 -> 0.79 ms (32) HIP: the new code uses only what the existing kernels use; SYCL has its own sources and only sees the new declarations. Neither was built here.
This commit is contained in:
1 parent
2f4fe20a9a
commit
a71ee46cd2
7 files changed
+455
-21
No files matched your search
+42
-1
@@ -206,6 +206,11 @@ const bool g_no_batch_kv = env_on("STRATA_NO_BATCH_KV_STEP"); // #783 PR-d: pe
|
||||
// of the commit graph only repeats what the window wrote: the indexer tails are put back and appended again from the
|
||||
// same rows, the PLE histories are put back to the window's own snapshot.
|
||||
const bool g_batch_self_commit = env_on("STRATA_BATCH_SELF_COMMIT");
|
||||
// STRATA_QSA_SLOTS=1 (opt-in): in a batch window, a QSA layer's block scores, top-k and attention run as one launch
|
||||
// each over the window's rows (up to 8 per launch, each row reading its own slot's indexer keys and K/V) instead of
|
||||
// one call per row; every row is computed by the same kernel with the same arithmetic as its own call. Not with a
|
||||
// streamed KV cache (a row's block resolve could evict the blocks an earlier row of the same slot selected).
|
||||
const bool g_qsa_slots = env_on("STRATA_QSA_SLOTS");
|
||||
|
||||
// every row of a batch window is another slot's (no slot has proposal rows)
|
||||
bool one_row_per_slot(const int* rows, int S) {
|
||||
@@ -1417,7 +1422,43 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
|
||||
}
|
||||
}
|
||||
stamp(l, 10, grp);
|
||||
if (batch_rec_) { // each row selects and attends over its own slot's K/V
|
||||
bool streamed = false; // a streamed KV cache keeps the per-row resolve-then-attend order
|
||||
if (batch_rec_ && g_qsa_slots)
|
||||
for (int t = tb; t < te; ++t) streamed = streamed || slot_ss(t).qsa_states[qi].kv_mode == 1;
|
||||
if (batch_rec_ && g_qsa_slots && !streamed) {
|
||||
// the rows' block scores, top-k and attention, up to 8 rows per launch. The rows only read
|
||||
// their slots' keys and K/V here and write their own scores/sel/scratch/attn rows, so running
|
||||
// each step for all rows before the next is the per-row loop's result
|
||||
for (int t0 = tb; t0 < te; t0 += kQsaAttnMaxSlots) {
|
||||
const int m = std::min(te - t0, kQsaAttnMaxSlots);
|
||||
const float* pooled[kQsaAttnMaxSlots];
|
||||
const float* dead[kQsaAttnMaxSlots];
|
||||
QsaAttnSlotPools px;
|
||||
for (int i = 0; i < m; ++i) {
|
||||
const QsaState& sx = slot_ss(t0 + i).qsa_states[qi];
|
||||
pooled[i] = sx.idx_pooled;
|
||||
dead[i] = sx.idx_dead;
|
||||
px.p[i] = qsa_attn_pools(sx);
|
||||
}
|
||||
// a launcher that would not run the per-row call's kernel launches nothing: per-row calls
|
||||
if (!qsa_block_scores_slots(pooled, dead, qidx_ + t0 * IQ * ID, step_ + t0 * kStepCount, m,
|
||||
max_blocks_, s, scores_ + (size_t) t0 * max_blocks_, cs))
|
||||
for (int t = t0; t < t0 + m; ++t)
|
||||
qsa_block_scores(pooled[t - t0], dead[t - t0], qidx_ + t * IQ * ID, step_ + t * kStepCount,
|
||||
1, max_blocks_, s, scores_ + (size_t) t * max_blocks_, cs);
|
||||
qsa_block_topk(scores_ + (size_t) t0 * max_blocks_, step_ + t0 * kStepCount, m, max_blocks_,
|
||||
cap_, s, sel_ + (size_t) t0 * cap_, cs);
|
||||
if (!qsa_decode_attn_slots(qcur_ + t0 * NH * HD, px, sel_ + (size_t) t0 * cap_,
|
||||
step_ + t0 * kStepCount, cap_, s,
|
||||
attn_scratch_ + (size_t) t0 * attn_scratch_floats_,
|
||||
attn_ + t0 * NH * HD, m, cs))
|
||||
for (int t = t0; t < t0 + m; ++t)
|
||||
qsa_decode_attn_batch(qcur_ + t * NH * HD, px.p[t - t0], sel_ + (size_t) t * cap_,
|
||||
step_ + t * kStepCount, cap_, s,
|
||||
attn_scratch_ + (size_t) t * attn_scratch_floats_,
|
||||
attn_ + t * NH * HD, 1, cs);
|
||||
}
|
||||
} else if (batch_rec_) { // each row selects and attends over its own slot's K/V
|
||||
for (int t = tb; t < te; ++t) {
|
||||
const QsaState& sx = slot_ss(t).qsa_states[qi];
|
||||
qsa_block_scores(sx.idx_pooled, sx.idx_dead, qidx_ + t * IQ * ID, step_ + t * kStepCount, 1,
|
||||
|
||||
Reference in new issue
Block a user