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
@@ -43,4 +43,19 @@ void qsa_decode_attn_step(const float* q, const QsaAttnPools& pools, const int32
|
||||
void qsa_decode_attn_batch(const float* q, const QsaAttnPools& pools, const int32_t* ids, const int32_t* steps,
|
||||
int64_t cap, const QsaShapes& s, float* scratch, float* attn, int64_t n_q, void* stream);
|
||||
|
||||
/// Up to this many queries of different slots in one qsa_decode_attn_slots call.
|
||||
constexpr int kQsaAttnMaxSlots = 8;
|
||||
|
||||
/// One KV pool set per query of a qsa_decode_attn_slots call (passed by value as a kernel argument).
|
||||
struct QsaAttnSlotPools {
|
||||
QsaAttnPools p[kQsaAttnMaxSlots];
|
||||
};
|
||||
|
||||
/// qsa_decode_attn_batch for `n_q` queries that each attend over their OWN pools (`pools.p[i]`, one KV cache per batch
|
||||
/// slot): one launch instead of one call per query, every block computing exactly what the per-query call computes.
|
||||
/// The pools must all have one KV format. False (nothing launched) where the per-query call would run another kernel
|
||||
/// (n_q > kQsaAttnMaxSlots, mixed formats, the pre-sm_75 / gfx103x or gfx906 variants): the caller loops instead.
|
||||
bool qsa_decode_attn_slots(const float* q, const QsaAttnSlotPools& pools, const int32_t* ids, const int32_t* steps,
|
||||
int64_t cap, const QsaShapes& s, float* scratch, float* attn, int64_t n_q, void* stream);
|
||||
|
||||
} // namespace strata::kernels
|
||||
@@ -29,6 +29,13 @@ void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx
|
||||
int64_t active_blocks = -1); ///< perf-review C-1: > 0 launches only this many blocks (the
|
||||
///< batch's largest n_bid + 1; not for a captured graph)
|
||||
|
||||
/// qsa_block_scores for `nq` queries of different slots, query i scoring its own slot's keys (pooled[i], dead[i]; host
|
||||
/// arrays of device pointers): one launch whose blocks each compute exactly what the single-query call computes.
|
||||
/// False (nothing launched) where that call would run another kernel (nq > 8, STRATA_SCORES_MULTI=0): loop instead.
|
||||
bool qsa_block_scores_slots(const float* const* pooled, const float* const* dead, const float* q_idx,
|
||||
const int32_t* steps, int64_t nq, int64_t max_blocks, const QsaShapes& s, float* scores,
|
||||
void* stream);
|
||||
|
||||
/// The same scores on tensor cores (3xTF32, FP32-level accuracy but another summation order: not bitwise; the tail
|
||||
/// block n_bid is the warp kernel's arithmetic). For the prompt path; false (nothing launched) on another geometry.
|
||||
/// On AMD it is the gfx12 (RDNA4) WMMA kernel (a three-way bf16 split, six products); false on any other AMD target.
|
||||
|
||||
Reference in new issue
Block a user