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
@@ -688,6 +688,10 @@ void r4d_hc_read_pin_prefill(int form);
|
||||
// wherever the cache rows are aligned to them), 1 the element-wise load the rule falls back to.
|
||||
// Bit-identical; r4d_selftest compares them and --perfmla times both.
|
||||
void r4d_mla_matrix_pin_form(int form);
|
||||
// Test hook: pins the MLA rows row's form. 0 is the launcher's rule (64 heads a workgroup, vector
|
||||
// key loads where aligned; the matrix row's kernel under 32 rows), 1 the element-wise key load
|
||||
// (bit-identical to 3), 2 32 heads a workgroup, 3 the rows kernel of the rule at any row count.
|
||||
void r4d_mla_rows_pin_form(int form);
|
||||
// Test hook: records the function each launch dispatches into `fns[0..cap)`, in order, until the
|
||||
// next call, and returns how many launches the previous recording saw (which may exceed its cap).
|
||||
// Null `fns` stops recording. r4d_selftest uses it to show that a pinned form dispatches a kernel
|
||||
|
||||
Reference in new issue
Block a user