Prompt path: a stager buffer's first job of a generation waits for the previous DMA from it

Stager::work waited for a buffer's DMA only from the generation's kRing-th job on (j >= kRing); a generation's first
kRing jobs wrote their buffers straight away. The previous generation's last DMAs from those buffers are only
known to be done where something else waits for them: the routing sync before a staged layer's start(), or the
sync at the end of a chunk with an MTP drafter or stages. A stream_all chunk that ends without one (no --mtp), or a
ring entry the routing skipped (its copy is never waited for), leaves a window where the next chunk's first jobs
overwrite a pinned buffer a DMA may still read. The event is now waited for on every job; an event never recorded,
or already complete, returns at once.

IQ2_XS with --mmap-experts --resident-budget-gib 16 (12,144 of 48,668 streamed experts through the stager): the
same tokens on a 32K prompt, prefill 6,491 vs 6,546 ms.
This commit is contained in:
sergiywith authored and Niko1221 committed 2026-10-02 21:57:12 +02:00
1 parent 067c9362c8
commit 6a5902832c
1 file changed
+5 -3
+5 -3
View File
@@ -272,10 +272,12 @@ struct Stager {
const int j = claim(seen);
if (j < 0) { active.fetch_sub(1, std::memory_order_acq_rel); break; }
const int b = j % kRing;
if (j >= kRing) {
if (j >= kRing) // job j - kRing's DMA from this buffer is queued
while (issued.load(std::memory_order_acquire) <= j - kRing) std::this_thread::yield();
cudaEventSynchronize(dma_done[b]);
}
// and done - for a generation's first kRing jobs that is the previous generation's last DMA from
// the buffer, which nothing else waits for when a chunk ends without a sync (no MTP) or the DMA
// was a ring entry the routing skipped (an event never recorded returns at once)
cudaEventSynchronize(dma_done[b]);
const Job& jb = jobs[(size_t) j];
if (jb.from == nullptr) std::memcpy(buf[b], jb.src, jb.bytes);
else if (!jb.from->copy_blob(jb.l, jb.e, buf[b])) {