Mixed-HIP pipelined prompt read: stage 0 is served to its end before the drafter's blocking prefill on its card (P1.9, part 2)

Correctness (class E): the same windows are served in the same order, only a little earlier; the tokens do not change.

With --pipeline-windows 2 on a two-stage layer split the drafter sits on the first stage's card (mtp_first).
read_windows_pl called mtp.prefill(...) right after a stage-1 window finished, while stage 0 still had a window in
flight on that same card. MtpDrafter::prefill blocks the host until its stream is idle (on HIP it synchronizes once
per group whatever its `sync` argument says: prefill_per_group_sync), a stage-0 window only advances when this same
thread serves its doorbells, so the host sat in hipStreamSynchronize and the window it waited for could never
finish: the first request of a fresh engine read its prompt, produced 0 tokens, and the watchdog ended the engine
60 s later (gfx1201 + gfx1030, issue #5147). Neither 20 s guard in Verifier::service / done can fire, because the
loop never runs again.

serve_stage0_to_end() serves stage 0's windows to their end before that prefill, when the drafter shares stage 0's
card. The HIP per-group synchronization (which exists because the unsynchronized E-4 queue hangs on gfx1201 /
ROCm 7.2.4) is left as it is: the caller is fixed, not the mitigation. Pipeline windows 0 and 1 take no new path
(mtp_first is false there). The overlap lost around each drafter prefill has not been measured.

Not testable on the boxes of this round: it needs a mixed pair of HIP cards (gfx1201 + gfx1030) and a two-stage split;
p620 has one R9700. Compiles on CUDA (z440, sm_86).

Co-authored-by: cloud4t0r <16303982+cloud4t0r@users.noreply.github.com>
This commit is contained in:
Niko1221andcloud4t0r committed 2026-11-05 23:57:51 +01:00
1 parent f225844d19
commit aeaca205eb
1 file changed
+21
+21
View File
@@ -16551,6 +16551,24 @@ int main(int argc, char** argv) {
e = why.empty() ? std::string("a pipelined prompt window failed") : why;
return false;
};
// The drafter's prefill blocks this thread until its stream is idle (on HIP, MtpDrafter::prefill syncs
// once per group whatever its `sync` says: prefill_per_group_sync, src/core/mtp.cpp). With the drafter
// on the first card (mtp_first) a stage-0 window still in flight spins on that GPU for doorbells only
// this thread serves, so a prefill called beside it never returns: the prompt read stopped for good at
// its first window (0.1.56, gfx1201 + gfx1030, --pipeline-windows 2, issue #5147). Serve stage 0 to its
// end first; the rest of the read keeps both stages overlapped. The tokens are unchanged: the same
// windows, in the same order, only served a little earlier.
auto serve_stage0_to_end = [&]() -> bool {
while (f0 < l0) {
strata::core::Verifier& v0 = *PV[0][f0 & 1];
if (v0.service(win_pool_fn, PSD[f0 & 1], e) < 0) return false;
if (v0.done(e)) {
if (!v0.pl_finish(nullptr, e)) return false;
++f0;
} else if (!e.empty()) return false;
}
return true;
};
while (f1 < N) {
if (stop_req.load()) return fail("cancelled");
// stage 0: up to two windows queued; window K+2 (K's parity) only once stage 1 has finished window
@@ -16589,6 +16607,9 @@ int main(int argc, char** argv) {
if (nonfinite_hit(v, "prompt")) return fail("non-finite logits (#879)");
const Win& w = wins[f1];
for (int t = 0; t < w.T; ++t) nx[(size_t) t] = (int32_t) cur[(size_t) (w.q + t + 1)];
// the drafter shares stage 0's card: no stage-0 window may still be in flight when its
// prefill waits on the host (see serve_stage0_to_end)
if (mtp_first && !serve_stage0_to_end()) return fail(e);
if (!mtp.prefill(v.final_R(0), nx.data(), w.T, w.q, e, false)) return fail(e);
{
const strata::core::OnDevice on(mtp.device());