Archived
libr4d: mla_attn_rows_bf16 -- one key load for all 64 heads of a query row
A third mla_attn row, at 64 heads. A workgroup takes one query row and all its heads, four waves to each group of sixteen, and loads each 16-token key chunk once for all of them, where the matrix row loads it once a tile of sixteen. The scores are K Q^T, tokens as the tile's rows and heads as its columns, so a head's running maximum and denominator stay in its lane; the waves of a group each take a quarter of the latent's dot products and add the four partials in one order, and the probabilities reach the value product through a permlanex16 swap instead of LDS. The next chunk's keys are fetched into registers while the current one is multiplied, two barriers a chunk. A row's bytes do not depend on the other rows of the batch. Under 32 rows the launcher runs the matrix row's kernel; r4d_mla_rows_pin_form, a test hook, pins the element-wise key load, 32 heads a workgroup, the rows kernel at any row count, or the matrix row's kernel at every row count (the form a KL measurement needs to tell this kernel's share of a row split's difference). Measured on gfx1201 (r4d_selftest --perfmla, one sequence past the DSA budget at 16k of context, 513 blocks): 512 rows x 64 heads take 3.9 ms, 35 TFLOP/s, against 12.3 ms on the matrix row, and the 4096 rows x 8 heads they stand for in a TP8 prefill chunk 14.0 ms on the paired union tile. Against the wave row the output stays within the matrix row's tolerance (max abs 2.4e-4 at 513 blocks). r4d_selftest checks it against libref at 1 to 33 rows, 32 and 64 heads, every fill and both key loads, and times it against the matrix row (--case mla_attn_rows_bf16, --perfmla at 64 heads). r4d_emu_mla runs it on the host against an f64 softmax, its forms bit for bit against each other, a run of rows against the same rows of the whole batch, and a mixed TP step (decodes, a verify window, a prefill past the budget, a fresh chunk) split by heads over the matrix row and by rows over this one, at runs that do and do not divide the step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
123c439684
commit
87701cb6b8
8 files changed
+645
-66
No files matched your search
@@ -698,6 +698,7 @@ int r4d_rad_mla_attn(const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_mla_attn_scratch(const RadArgs*);
|
||||
int r4d_rad_mla_attn_matrix(const RadArgs*, RadStream);
|
||||
int64_t r4d_rad_mla_attn_matrix_scratch(const RadArgs*);
|
||||
int r4d_rad_mla_attn_rows(const RadArgs*, RadStream);
|
||||
int r4d_shape_mla_attn(const RadParam*, int, int, RadOpdDesc*);
|
||||
int r4d_rad_router_sigmoid_topk(const RadArgs*, RadStream);
|
||||
int r4d_shape_router_sigmoid_topk(const RadParam*, int, int, RadOpdDesc*);
|
||||
|
||||
Reference in new issue
Block a user