sched: size the pinned staging ring for 16 builds instead of 3

A speculative step makes four builds (history pass, draft rounds 2-3, the
next verify). With room for three, the next verify's reserve() waited in
retire_oldest() on one of the current step's draft-pass uploads, so
issue-ahead returned only ~0.1-0.5 ms before the card needed the step and
every host hiccup became card idle.

The ring now holds kRingBuilds = 16 worst-case builds (it must stay below
kFlights). On Qwen3.8-Flash-Next IQR-V4 (MTP chain 3) step_next returns
11-13 ms ahead, and the card's idle time before the verify drops from 317 to
74 us (from 1243 to 470 us mean under host load). The pinned host ring grows
from 753 KiB to 3.9 MiB; the device slab is unchanged. Outputs are identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 authored and StillDeadcode committed 2026-11-17 18:18:02 +01:00
1 parent 8dcd8fdcd7
commit b2228c176b
2 files changed
+9 -3

No files matched your search

+7 -3
View File
@@ -214,13 +214,17 @@ int BatchBuilder::alloc_set(Set& s, const std::vector<KVGroupInfo>& groups) {
}
RAD_TRY(rad_dev_set(ranks_[0].device));
/* The ring holds three worst-case builds before a long-context prefill waits on an upload two
* builds back. A decode build's span is far smaller, so hundreds fit. */
/* The ring holds kRingBuilds worst-case builds. A speculative step takes four or more builds
* (history pass, draft rounds, the next verify), and reserve() must not wait on an upload of
* the step being issued (that would hold step_next back until the card ran this step's draft
* uploads): two steps of builds fit with room over. A decode build's span is far smaller than
* the worst case, so many more fit; this is pinned host memory only, the device slab stays
* one build. */
int64_t worst_pay = 0;
for (const Group& g : s.groups) worst_pay += max_seqs_ * g.max_blocks * (int64_t)sizeof(int32_t);
const int64_t worst_ranges = worst_pay / k_range_max + max_seqs_ * (int64_t)s.groups.size() + 1;
ranges_.reserve((size_t)worst_ranges);
ring_.bytes = 3 * (s.host_bytes + worst_ranges * (int64_t)sizeof(RadCopyRange) + k_carve_align);
ring_.bytes = kRingBuilds * (s.host_bytes + worst_ranges * (int64_t)sizeof(RadCopyRange) + k_carve_align);
ring_.host = static_cast<char*>(rad_dev_alloc(ring_.bytes, RAD_MEM_HOST_PINNED));
if (!ring_.host) {
RAD_ERR("step batch staging: could not reserve %s of pinned host staging",
+2
View File
@@ -259,6 +259,8 @@ private:
int ev = -1; /* row of ev_ holding one event per rank */
};
static constexpr int kFlights = 64;
/* Worst-case builds the staging ring holds (see alloc_set). Must stay below kFlights. */
static constexpr int kRingBuilds = 16;
struct Ring {
char* host = nullptr;
int64_t bytes = 0;