diff --git a/engine/src/ling32/ling32_engine.cu b/engine/src/ling32/ling32_engine.cu index b846ed1add..b7c694d9f1 100644 --- a/engine/src/ling32/ling32_engine.cu +++ b/engine/src/ling32/ling32_engine.cu @@ -489,11 +489,15 @@ struct Ling32Engine::StageCtx { void make_room(size_t bytes) { if (!E.provider_ || E.opt.kv_init_ctx <= 0) return; static const size_t margin = [] { const char* e = std::getenv("STRATA_L32_ALLOC_MARGIN_MB"); return static_cast(e && e[0] ? std::max(0, std::atoi(e)) : 256) * 1048576ull; }(); + static const bool trace = [] { const char* f = std::getenv("STRATA_L32_REGROW_TRACE"); return f && f[0] == '1'; }(); + static int n_print = 0; // the first checks of a process are always printed (one short line each, at most 4): the numbers cudaMemGetInfo gives are what decides whether the pool makes room for (int t = 0; t < 64; ++t) { size_t fr = 0, tot = 0; if (cudaMemGetInfo(&fr, &tot) != cudaSuccess) { (void)cudaGetLastError(); return; } - if (fr >= bytes + margin) return; - if (E.provider_->release_bytes(bytes + margin - fr) == 0) return; + const bool low = fr < bytes + margin; + if ((trace && bytes >= (8u << 20)) || (n_print < 4 && bytes >= (8u << 20))) { ++n_print; std::printf("[make_room] alloc %.1f MiB, card free %.0f of %.0f MiB, margin %.0f MiB: %s\n", bytes / 1048576.0, fr / 1048576.0, tot / 1048576.0, margin / 1048576.0, low ? "releasing pool chunks" : "room"); } + if (!low) return; + if (E.provider_->release_bytes(bytes + margin - fr) == 0) { if (trace) std::printf("[make_room] the pool has nothing more to give\n"); return; } } } diff --git a/engine/src/ling32/ling32_main.cpp b/engine/src/ling32/ling32_main.cpp index 642dd9b18e..534eb4847b 100644 --- a/engine/src/ling32/ling32_main.cpp +++ b/engine/src/ling32/ling32_main.cpp @@ -753,6 +753,18 @@ int cmd_run(const RunOpts& o_in) { #endif igpu_zero_copy = win_igpu && o.tier != "vram"; uint64_t plan_vram = fr, plan_ram = host_ram_available(), win_ram_budget = 0; +#if defined(_WIN32) && !defined(STRATA_USE_HIP) + if (!integrated && o.tier != "vram") { + // Windows (WDDM) with a discrete card: the planner filled the card to the last 0.4 GiB (a 12 GB RTX 5070: "GPU memory 11.54 / 11.91 GiB used" at ready), and WDDM does not fail an allocation + // beyond the dedicated memory, it pages it into shared system memory: the prefill scratch, the graphs and the desktop's own use ended up there and a 33,784-token prompt took 620 s instead of 100 s. + // Plan against the free memory minus a headroom (STRATA_L32_WDDM_HEADROOM_MB, default 1536; 0 switches it off). + static const uint64_t headroom = [] { const char* e = std::getenv("STRATA_L32_WDDM_HEADROOM_MB"); return static_cast(e && e[0] ? std::max(0, std::atoi(e)) : 1536) << 20; }(); + if (headroom > 0) { + plan_vram = fr > headroom ? fr - headroom : 0; + std::printf("Windows: the card is planned within %.2f of its %.2f GiB free (%.2f GiB headroom against WDDM paging)\n", plan_vram / 1073741824.0, fr / 1073741824.0, headroom / 1073741824.0); + } + } +#endif if (win_igpu && o.tier != "vram") { constexpr uint64_t kGiBu = 1ull << 30; l32::trace("main: probing the GPU allocation cap");