From cb22a53e0e7bec08c74a0a04025be293149ae143 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 13 Oct 2026 01:18:33 +0200 Subject: [PATCH] Adaptive overlap: the host-function signal is the Windows default, and the copy stream is flushed after the swaps are queued (#2188) Under WDDM a stream's work sits in the driver's command buffer until a driver call flushes it. With the stream-ordered signal the verify window only spins on a pinned int, so the last layers' copies and their 4-byte signal copies were never submitted: the first request stopped with "the adaptive tier's copies for layer 45 never landed" (RTX 4070 SUPER, 0.1.43.1, opt-in STRATA_ADAPT_OVERLAP=1). STRATA_ADAPT_SIGNAL=host worked. - Windows: the host function is the default signal; STRATA_ADAPT_SIGNAL=copy asks for the copy. - Every platform: one cudaStreamQuery on the copy stream after the swaps and their signals are queued (a no-op for the results; it submits the batch under WDDM). Linux keeps the copy signal as before. Needs a Windows run with STRATA_ADAPT_OVERLAP=1 STRATA_ADAPT_SIGNAL=copy to confirm the flush. --- docs/DETAILS.md | 5 +++++ src/program/generate.cpp | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 998d661e..1c570419 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1748,6 +1748,11 @@ the pairs in which the switched arm won). They are here so you can try them on y - **`STRATA_ADAPT_SIGNAL=host`: the overlap's per-layer "landed" signal as a host function** (the 0.1.43 way). From 0.1.43.1 the default is a 4-byte stream-ordered copy into pinned memory, which needs no driver callback thread: on a 20-core desktop (RTX 3060) the host functions still cost ~7 ms per window with the thread started early, because the pool's workers occupy every other CPU. + **On Windows the host function stays the default** (0.1.44, #2188): under WDDM the copy and its signal waited in the + driver's command buffer while the window spun on the pinned int, and the first request stopped with "the adaptive + tier's copies for layer 45 never landed" (RTX 4070 SUPER, driver 617.42). `STRATA_ADAPT_SIGNAL=copy` asks for the copy + there; the engine now flushes the copy stream after queueing the swaps, which is meant to fix it but has not been run + on Windows yet. ## Thread placement: `--aux-cpus` (Linux, off by default) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 0328b387..adf97122 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -8471,7 +8471,20 @@ int main(int argc, char** argv) { for (int64_t l = 0; l <= g.n_layers; ++l) agate.ticks[(size_t) l] = {&agate, (int32_t) l}; agate.has.assign((size_t) g.n_layers, 0); if (!ver.set_adapt_gate(&agate)) aov_why = "the device-planned layers (STRATA_VERIFY_DEVICE_PLAN) are on"; - if (aov_why == nullptr && !(std::getenv("STRATA_ADAPT_SIGNAL") && std::getenv("STRATA_ADAPT_SIGNAL")[0] == 'h')) { + // #2188: on Windows the default is the host function. Under WDDM a stream's work sits in the driver's + // command buffer until something flushes it, and nothing does while the host only spins on the pinned + // int: the first request stopped with "copies for layer 45 never landed". STRATA_ADAPT_SIGNAL=copy asks + // for the stream-ordered copy there too (the enqueue then flushes the stream), =host everywhere. + const char* asig = std::getenv("STRATA_ADAPT_SIGNAL"); +#if defined(_WIN32) + const bool sig_copy = asig != nullptr && asig[0] == 'c'; +#else + const bool sig_copy = !(asig != nullptr && asig[0] == 'h'); +#endif + if (aov_why == nullptr && !sig_copy) + std::fprintf(stderr, "strata serve: adaptive overlap signal: host functions%s\n", + asig == nullptr ? " (the Windows default, #2188; STRATA_ADAPT_SIGNAL=copy: a stream-ordered copy)" : ""); + if (aov_why == nullptr && sig_copy) { // the landing of each layer's copies is told by a stream-ordered D2H copy of the layer number into pinned memory // (STRATA_ADAPT_SIGNAL=host: a host function instead). No callback thread has to be scheduled while the pool's workers spin on every other CPU int32_t* vals = nullptr; void* hp = nullptr; @@ -8661,6 +8674,9 @@ int main(int argc, char** argv) { return false; } if (!swaps.empty()) cudaEventRecord(adapt_ev, adapt_stream); + // #2188: hand the copies and their landing signals to the GPU now. WDDM batches a stream's work until a + // driver call flushes it, and the verify window only spins on the pinned int (Linux submits at once: no-op) + if (aov && agate.hland != nullptr && !swaps.empty()) (void) cudaStreamQuery(adapt_stream); (void) main_live; for (auto& st : stages) if (st->adapt_live) {