prefill: the MMQ identity row table gets the stream-k fixup's over-read margin (ledger U3, upstream f225844d1); results unchanged

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-09 22:57:41 +01:00
co-authored by Claude Sonnet 5.5
parent 79a7d5ed05
commit 11bdb54666
3 changed files with 39 additions and 2 deletions
@@ -19,7 +19,9 @@ const MMQ_GROUP: usize = 16;
const MMQ_TAIL: usize = 4096;
mod carve_parts;
mod mmq_identity;
use carve_parts::{merge_spans, take_kv_int8, take_kv_q4, take_ple};
use mmq_identity::mmq_identity_words;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PrefillPhase {
@@ -327,7 +329,7 @@ impl PrefillLayoutOptions {
fn take_mmq_groups(&self, a: &mut Alloc, t: usize) -> Result<()> {
if self.mmq_any {
a.rows("ids_identity", t, K, 4)?;
a.take("ids_identity", mmq_identity_words(t)?, 4)?;
let bounds = self.mmq_bounds_words()?;
a.take("bounds_dev", bounds, 4)?;
for (name, max) in [("grp_gu", self.mmq_gu_max), ("grp_d", self.mmq_down_max)] {
@@ -0,0 +1,35 @@
//! Size of the identity row table of the prompt MMQ launches (ledger row U3).
#[allow(unused_imports)]
use super::*;
/// Widest column tile of the grouped MMQ launches (ggml `mul_mat_q_switch_J`: J = 8 .. 128 in steps of 8).
const MMQ_TILE_COLS_MAX: usize = 128;
/// Entries of the identity row table of the prompt MMQ launches: the `t * K` routed rows plus the margin that the
/// stream-k fixup (`mul_mat_q_stream_k_fixup`) reads past them. It loads `ids_dst[col_low + jt * J + j]` for a whole
/// J-column tile before it compares the tile with the expert's rows, and a tile runs to `ceil(max_rows / J) * J` with
/// `max_rows <= t` (an expert takes at most one row per token), so the table needs `roundup(t, J) + J` more entries
/// for the widest J (upstream Strata `f225844d1`). The values past `t * K` are never routed to: results are unchanged.
pub(super) fn mmq_identity_words(t: usize) -> Result<usize> {
let tile_rounded = add(t, MMQ_TILE_COLS_MAX - 1)? / MMQ_TILE_COLS_MAX * MMQ_TILE_COLS_MAX;
add(add(mul(t, K)?, tile_rounded)?, MMQ_TILE_COLS_MAX)
}
#[cfg(test)]
mod mmq_identity_margin_tests {
use super::*;
#[test]
fn the_identity_table_covers_every_index_the_stream_k_fixup_can_read() {
for t in [1usize, 7, 127, 128, 129, 1000, 8192] {
let words = mmq_identity_words(t).unwrap();
// the last column tile of the widest J starts below t and ends at roundup(t, J); the table index adds the
// experts' column offset, which is at most t * K - 1
let last_read = t * K - 1 + t.div_ceil(MMQ_TILE_COLS_MAX) * MMQ_TILE_COLS_MAX;
assert!(last_read < words, "t {t}: reads index {last_read}, table has {words} entries");
assert!(words > t * K, "t {t}: no margin");
}
assert!(mmq_identity_words(usize::MAX / 4).is_err(), "a size that does not fit must fail, not wrap");
}
}
+1 -1
View File
@@ -191,7 +191,7 @@ Owner rule: small upstream wins (+0.3..0.5 %) are taken too. "VANL" here is vani
| --- | --- | --- | --- | --- | --- | --- | --- |
| U1 | prefill: GDN recurrence as a chunked scan on tensor cores (code `STRATA_GDN_TC`, upstream commits `8c2a84694` opt-in 2026-10-26, default `6858c919c` 2026-11-07 with `STRATA_GDN_CONVL2=2`) | not present: our GDN prompt kernels are the sealed Original ones (`gdn_closed_queue*`, `gdn_batch_gemm.rs`); the pinned `engine/strata` (0.1.50) has no `GDN_TC` either | upstream 0.2.9: prompt +4.4 % at 4K, +5.5 % at 16K, +5.7 % at 32K; **lossy**: first-token KL mean 0.0019, max 0.0125; engine gates it at run time (compute capability >= 8, one SM per value head, shared memory) | not a gap against VANL 0.2.6 (it has no `GDN_TC`); a possible win of about 5 % of prefill | upstream commit message | hex-finish | open: port needs a new CUDA kernel and a new sealed PTX (sm_120) plus the lossy quality gate (`docs/quality-gate.md`), marked experimental until it passes; section delta = `prefill.gdn` span at 4K/16K/32K |
| U2 | prefill: batched PLE post-ops (code `STRATA_PLE_BATCH`; upstream `78316c8df` 2026-11-02 turns it off for an engine built with CUDA 12.8 on cc 12.0: illegal memory access in `native_ple_postops_batch_snap`) | we run the PLE of a prompt chunk batched (`OriginalPromptDevice::apply_ple`, `ple_batch_ffi`, `ple_batch_queue`); our sealed PTX is ISA 9.2 = CUDA 13.2 and the deploy refuses a driver older than 595 (`docs/deploy.md`), the production RTX 5090 host runs driver 595.99 / CUDA 13.2 | upstream: with CUDA 13.0 the batch is ~23 % faster prompts, so only the 12.8 toolchain faults | same hazard does not apply (no 12.8 build exists in our chain); the batch is already on | source read | hex-finish | proved-equal (we have the fast path and not the faulting toolchain); no work |
| U3 | prefill: MMQ row table over-read by the stream-k fixup (code `ids_identity`; upstream `f225844d1` 2026-11-05, class E correctness) | same structure: `ids_identity` is `T*K` entries exactly (`original_prefill_layout.rs:330`, `a.rows("ids_identity", t, K, 4)`), read by the same ggml `mul_mat_q_stream_k_fixup` (`mmq_original_formats_fixup.cu`); upstream needs `T*K + roundup(T, J) + J` entries (J = 8..128). It stays inside the arena today because `bounds_dev`, `grp_gu`, `grp_d` follow it in the same allocation, so the over-read lands in a neighbouring span and the skipped writes never use it | upstream faulted (Xid 31) when the exact table ended a 2 MiB page | latent: not a fault with the current layout, would become one if the order of the `Common` spans changes or `mmq_any` spans end the allocation | source read | hex-finish | open: add the margin (about 256 + T/8 words more, bitwise identical results); unit test of the layout, identity = digests of prompt logits equal |
| U3 | prefill: MMQ row table over-read by the stream-k fixup (code `ids_identity`; upstream `f225844d1` 2026-11-05, class E correctness) | same structure: `ids_identity` is `T*K` entries exactly (`original_prefill_layout.rs:330`, `a.rows("ids_identity", t, K, 4)`), read by the same ggml `mul_mat_q_stream_k_fixup` (`mmq_original_formats_fixup.cu`); upstream needs `T*K + roundup(T, J) + J` entries (J = 8..128). It stays inside the arena today because `bounds_dev`, `grp_gu`, `grp_d` follow it in the same allocation, so the over-read lands in a neighbouring span and the skipped writes never use it | upstream faulted (Xid 31) when the exact table ended a 2 MiB page | latent: not a fault with the current layout, would become one if the order of the `Common` spans changes or `mmq_any` spans end the allocation | source read | hex-finish | fixing: margin `roundup(T, 128) + 128` entries added (`original_prefill_layout/mmq_identity.rs`, unit test of every readable index; always on, class E, no switch); identity (prompt logit digests equal) pending in the batched identity job |
| U4 | verify: flag B stays behind queued copies (upstream `40849df0a` 2026-11-05, P1.1, class E) | `OriginalVerifyGpuPlan::raise_after_staging` (`plan_phases.rs`): a plan with a PCIe source queues the flag behind the staging copies on the copy stream even when the plan is empty (`stage_pcie`, then `raise_after_copies`), the copy-kernel mode and the no-source case raise at once. The upstream hazard (an empty plan raising the one counter early while an earlier layer's or the other token group's uploads are still queued) can only occur in the no-source branch if a window mixes groups with and without a source; not shown to happen | upstream: counter jumped past a layer whose bytes had not landed | unknown; needs the check in the file owned by the speed session | source read | device | open: handed to the speed-vs-strata session (`original_verify_gpu_plan*` is theirs): confirm the no-source branch cannot run while copies are queued, add a test |
| U5 | verify: adaptive-copy range covers the whole round (upstream `40849df0a`) | different implementation: adaptive swaps are planned and applied in `original_serve_residency` (`adapt_swaps` cap 96 per round, `swap_tie_order.rs`); no serial/pipelined split with `lo/hi/bi` ranges exists in the Rust port | upstream: a pipelined round that drained early marked only an earlier round's range resident, so other swaps were lost (slot held the new expert, table still named the old one) | analogue not found; the resident marking of a drained round needs a read-through | source read | device | open: review of "slot marked resident exactly when its copy landed" in `original_serve_residency` (hand to the memory/speed session) |