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
@@ -996,7 +996,8 @@ TEST(libr4d_resolves_the_vision_attention_without_a_window) {
|
||||
}
|
||||
|
||||
/* GLM-5.3-Flash's MLA at eight heads a rank: the matrix row ranks above the wave row and serves
|
||||
* every M up to its bound, a decode step's rows and a prefill chunk alike. */
|
||||
* every M up to its bound, a decode step's rows and a prefill chunk alike. At 64 heads the rows
|
||||
* row ranks above both. */
|
||||
TEST(libr4d_resolves_the_mla_attention_by_rows) {
|
||||
const std::string so = libr4d();
|
||||
if (so.empty()) return;
|
||||
@@ -1010,6 +1011,11 @@ TEST(libr4d_resolves_the_mla_attention_by_rows) {
|
||||
g.set_s("dtype", "bf16");
|
||||
CHECK_EQ(band_names(r.build_bands("mla_attn", "M", 1, 2048, g)), "2048:mla_attn_matrix_bf16 ");
|
||||
CHECK_EQ(band_names(r.build_bands("mla_attn", "M", 1, 48, g)), "48:mla_attn_matrix_bf16 ");
|
||||
// All 64 heads of a row, as GLM's prefill split by rows runs it: the rows row.
|
||||
g.set_i("heads", 64);
|
||||
CHECK_EQ(band_names(r.build_bands("mla_attn", "M", 1, 512, g)), "512:mla_attn_rows_bf16 ");
|
||||
g.set_i("heads", 16);
|
||||
CHECK_EQ(band_names(r.build_bands("mla_attn", "M", 1, 512, g)), "512:mla_attn_matrix_bf16 ");
|
||||
}
|
||||
|
||||
/* ================================================================== constraints that are not intervals */
|
||||
|
||||
Reference in new issue
Block a user