#253: the 8 GiB arena pin cap only under WDDM; STRATA_ARENA_PIN_GIB; the split's prompt chunk steps down

- The expert arena was pinned at most 8 GiB whenever a layer split (or remote experts) ran, on every OS - a
  Windows/WDDM workaround that cost a Linux 4090 + 3060 split two thirds of its prompt speed (#253,
  bettercallcaleb). The cap now applies only under WDDM (_WIN32, or WSL2 detected by /dev/dxg), for multi_gpu and
  expert_cache_remote alike. STRATA_ARENA_PIN_GIB overrides it on any OS: "0" pins the whole arena, N > 0 at most
  N GiB (arena_pin_cap_gib(), -1 when unset: the same name and meaning as the S2 branch's helper, file-local here).
- The split's prompt chunk no longer stops the start when its buffers do not fit: a prompt path without a loan
  first gets the largest chunk whose buffers (Prefill::bytes_needed) leave 512 MiB free on its device, and an init
  that still fails steps down one size (8192 -> 6144 -> ... -> 2048 -> 1536 -> 1024 -> 512): Prefill::reset() frees
  what the failed init made, the loans are re-priced, and the failed allocation's sticky error is consumed (else the
  next launch check reported "out of memory").
- pinned.cu: the capped note no longer says "for CUDA1".
- docs: MULTI_GPU.md, SECOND_GPU.md.

Measured on amdbox (Linux, R9700 + RX 9070 XT, gpu [1, 0], Coder IQ1_M, 128 greedy tokens; tok/s):
  | cache                  | arm          | 4K cold | 4K warm | 16K cold | 16K warm | decode    |
  | auto (holds ~all)      | 8 GiB cap    | 678     | 1,355   | 1,709    | 1,880    | 44.5-51.5 |
  |                        | whole arena  | 703     | 1,234   | 1,729    | 1,864    | 44.6-51.4 |
  | fixed 1500 on CUDA0    | 8 GiB cap    | 608     | 1,101   | 1,287    |          | 34.5-36.1 |
  |                        | whole arena  | 716     | 1,160   | 1,803    |          | 34.8-36.0 |
(2 starts per arm for auto, 5 for fixed.)  With most experts streamed the whole arena reads a 16K prompt 40%
faster; with every expert already on the cards the two are within noise except 4K warm (-9%: the pinned share
raises the auto lend to 90% and the streamed ring to 384 slots).  Identity: the fixed-cache arms gave the same
tokens in all 5 + 5 starts (4K, 16K, 4K again), and the auto arms 2 + 2.  The step-down was exercised on the
9070 XT with --expert-cache 3000 --no-prefill-borrow --prefill 8192 ("need 4528 MiB, 2910 MiB free: 2048-token
chunks"; with the init retry alone it went 8192 -> ... -> 2048, and 1536 ran all four requests).  Known, also on
main: that own-buffer configuration at 2048 makes hipBLAS pick hipBLASLt kernels whose code objects this ROCm 7.14
lacks (TensileLibrary_..._gfx1201-xnack+.co not found, "launchKernel failed") and the prompt hangs.  The WDDM side (Windows, WSL2) is unchanged and not re-measured here.
This commit is contained in:
Niko1221 committed 2026-10-01 01:31:22 +02:00
1 parent ebe52edd8b
commit 9f8fa9088e
7 files changed
+159 -30

No files matched your search

+132 -22
View File
@@ -94,6 +94,29 @@
#include <vector>
namespace {
// STRATA_ARENA_PIN_GIB: how much of the expert arena is registered (pinned) for the GPUs. Unset: -1 (the default
// rule below); "0": the whole arena; N > 0: at most N GiB. (The same helper as src/core/pinned.cu's on the S2
// branch: identical name and meaning, file-local here.)
static int arena_pin_cap_gib() {
const char* v = std::getenv("STRATA_ARENA_PIN_GIB");
if (v == nullptr || *v == '\0') return -1;
char* end = nullptr;
const long n = std::strtol(v, &end, 10);
return (end == v || n < 0) ? -1 : (int) std::min<long>(n, 1 << 20);
}
// Windows' WDDM driver model: native Windows, or WSL2 (its GPU goes through /dev/dxg to the Windows driver). There,
// pinning a large arena into two CUDA contexts leaves WDDM refusing every later allocation (the 5080 + 3090 rig);
// a Linux driver has no such limit (#253: the 8 GiB cap cost a 4090 + 3060 split 3x of its prompt speed).
bool under_wddm() {
#ifdef _WIN32
return true;
#else
static const bool dxg = std::filesystem::exists("/dev/dxg");
return dxg;
#endif
}
// perf-review D-4: the lent slots are refilled with queued copies and one wait; STRATA_REFILL_BLOCKING=1 waits on each
bool refill_blocking() {
static const bool v = std::getenv("STRATA_REFILL_BLOCKING") != nullptr;
@@ -2274,11 +2297,20 @@ int main(int argc, char** argv) {
srcp = &src;
} else {
arena_src.set_gguf(o.native_preset); // plan v0.3 P6: a native pack may take its experts from shard 1
// On the multi-GPU Windows experiment, start with at most 8 GiB of mapped host pages.
// Unregistered layers remain in the resident arena and use the CPU expert path.
// (a layer split across GPUs too: pinning all of it into two contexts leaves WDDM refusing every later
// allocation - measured on the 5080 + 3090 rig: cudaMemGetInfo and the next cudaMalloc fail)
const uint64_t pin_limit = (o.expert_cache_remote[0] > 0 || multi_gpu) ? (8ull << 30) : 0;
// Under WDDM (Windows, WSL2), a multi-GPU run (a layer split, or remote experts) starts with at most 8 GiB of
// mapped host pages: pinning all of it into two contexts leaves WDDM refusing every later allocation -
// measured on the 5080 + 3090 rig: cudaMemGetInfo and the next cudaMalloc fail. Unregistered layers remain
// in the resident arena; their streamed experts go through the pinned staging ring. A Linux driver has no
// such limit, so there the whole arena is pinned (#253). STRATA_ARENA_PIN_GIB overrides both ways.
const int pin_env = arena_pin_cap_gib();
const bool pin_wddm_cap = pin_env < 0 && (o.expert_cache_remote[0] > 0 || multi_gpu) && under_wddm();
const uint64_t pin_limit = pin_env >= 0 ? (uint64_t) pin_env << 30 : pin_wddm_cap ? (8ull << 30) : 0;
if (pin_env >= 0)
std::fprintf(stderr, "strata generate: STRATA_ARENA_PIN_GIB=%d: %s\n", pin_env,
pin_env == 0 ? "the whole expert arena is pinned" : "the expert arena's pinning is capped");
else if (pin_wddm_cap)
std::fprintf(stderr, "strata generate: multi-GPU under WDDM: at most 8 GiB of the expert arena is pinned "
"(STRATA_ARENA_PIN_GIB changes it)\n");
if (!arena_src.open(o.pack, g.n_layers, g.n_expert, /*threads=*/6, err, pin_limit,
o.shared_expert_arena)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
@@ -3555,26 +3587,104 @@ int main(int argc, char** argv) {
} else {
std::fprintf(stderr, "strata serve: the prompt path allocates its own buffers (too few cache slots to borrow)\n");
}
// layer split across GPUs: a prompt path per stage, each handing its chunk's rows to the next
for (size_t i = 0; i < stages.size(); ++i) {
GpuStage& st = *stages[i];
st.sp.set_stage(st.lb, i + 1 < stages.size() ? st.le : -1, i + 1 < stages.size() ? &stages[i + 1]->sp : nullptr);
const strata::core::OnDevice on(st.dev);
void* sb = nullptr; // this stage's own loan, out of its own cache
uint64_t sbb = 0;
// `first < 0`: no loan was taken (nothing was lendable), so this stage allocates its own buffers
if (i + 1 < pf_parts.size() && pf_parts[i + 1].first >= 0) {
sb = st.cache.device_slot(pf_parts[i + 1].first);
sbb = part_bytes(pf_parts[i + 1], pf_parts[i + 1].first);
// layer split across GPUs: a prompt path per stage, each handing its chunk's rows to the next.
// THE CHUNK STEPS DOWN INSTEAD OF EXITING. A split's stage caches are sized after the arena is registered, and
// the prompt path's own buffers (no loan) are not priced into them: with the whole arena pinned (#253) a
// `--prefill auto` split could stop at start with "device buffers for a chunk of 2048 tokens do not fit". A
// chunk that does not fit is tried again one size smaller, down to 512 tokens (a smaller chunk only reads slower).
auto init_prompt_paths = [&]() -> int { // 0: ready; 1: failed (err set); 2: failed with "do not fit"
for (size_t i = 0; i < stages.size(); ++i) {
GpuStage& st = *stages[i];
st.sp.set_stage(st.lb, i + 1 < stages.size() ? st.le : -1, i + 1 < stages.size() ? &stages[i + 1]->sp : nullptr);
const strata::core::OnDevice on(st.dev);
void* sb = nullptr; // this stage's own loan, out of its own cache
uint64_t sbb = 0;
// `first < 0`: no loan was taken (nothing was lendable), so this stage allocates its own buffers
if (i + 1 < pf_parts.size() && pf_parts[i + 1].first >= 0) {
sb = st.cache.device_slot(pf_parts[i + 1].first);
sbb = part_bytes(pf_parts[i + 1], pf_parts[i + 1].first);
}
if (!st.sp.init(st.wt, g, st.ss, srcp, &st.cache, host_res.data(), o.prefill_chunk, (void*) st.stream,
err, sb, sbb)) {
err = "layer split, CUDA" + std::to_string(st.dev) + " prompt path: " + err;
return err.find("do not fit") != std::string::npos ? 2 : 1;
}
}
if (!st.sp.init(st.wt, g, st.ss, srcp, &st.cache, host_res.data(), o.prefill_chunk, (void*) st.stream, err,
sb, sbb)) {
std::fprintf(stderr, "strata serve: layer split, CUDA%d prompt path: %s\n", st.dev, err.c_str());
return 1;
if (multi_gpu) sp.set_stage(0, split_at[0], &stages[0]->sp);
if (!sp.init(wt, g, ss, srcp, &xcache, host_res.data(), o.prefill_chunk, main_cs, err, borrow, borrow_bytes))
return err.find("do not fit") != std::string::npos ? 2 : 1;
return 0;
};
static constexpr int64_t kStepChunks[] = {6144, 4096, 3072, 2048, 1536, 1024, 512};
{
// First by arithmetic: a prompt path without a loan allocates its buffers, so the chunk must leave
// headroom on that device (a chunk that fits to the last MiB left hipBLAS nothing: its GEMMs then
// failed to launch on gfx1201 and the prompt hung). `bytes_needed` is the same count `init` makes.
const int64_t kHeadroom = 512ll << 20;
auto own_fits = [&](int64_t c, int& dev_out, int64_t& need_out, int64_t& free_out) -> bool {
for (size_t i = 0; i <= stages.size(); ++i) {
const bool loan = i == 0 ? borrow != nullptr : (i < pf_parts.size() && pf_parts[i].first >= 0);
if (loan) continue;
const int dev = i == 0 ? -1 : stages[i - 1]->dev;
const strata::core::OnDevice on(dev);
size_t fb = 0, tb = 0;
cudaMemGetInfo(&fb, &tb);
const int64_t need = (int64_t) strata::prefill::Prefill::bytes_needed(g, i == 0 ? ss : stages[i - 1]->ss, c);
if (need + kHeadroom > (int64_t) fb) {
dev_out = dev < 0 ? 0 : dev; need_out = need; free_out = (int64_t) fb;
return false;
}
}
return true;
};
int dev = 0;
int64_t need = 0, fb = 0;
if (!own_fits(o.prefill_chunk, dev, need, fb)) {
int64_t c = 0;
for (const int64_t s : kStepChunks) {
int d2 = 0;
int64_t n2 = 0, f2 = 0;
if (s < o.prefill_chunk && own_fits(s, d2, n2, f2)) { c = s; break; }
}
if (c > 0) {
std::fprintf(stderr, "strata serve: a %lld-token chunk's prompt buffers need %lld MiB on CUDA%d, "
"%lld MiB free: %lld-token chunks\n", (long long) o.prefill_chunk,
(long long) (need >> 20), dev, (long long) (fb >> 20), (long long) c);
o.prefill_chunk = c;
}
}
}
if (multi_gpu) sp.set_stage(0, split_at[0], &stages[0]->sp);
if (!sp.init(wt, g, ss, srcp, &xcache, host_res.data(), o.prefill_chunk, main_cs, err, borrow, borrow_bytes)) {
for (;;) {
const int r = init_prompt_paths();
if (r == 0) break;
int64_t next = 0;
for (const int64_t c : kStepChunks)
if (c < o.prefill_chunk) { next = c; break; }
if (r == 2 && next > 0) {
std::fprintf(stderr, "strata serve: %s: trying a %lld-token chunk\n", err.c_str(), (long long) next);
// start the prompt paths over (a failed init may hold buffers), and consume the failed allocation's
// error: it is sticky, and the next launch check would report "out of memory" for a kernel
for (auto& stp : stages) {
const strata::core::OnDevice on(stp->dev);
stp->sp.reset();
(void) cudaGetLastError();
}
sp.reset();
(void) cudaGetLastError();
o.prefill_chunk = next;
if (borrow != nullptr) { // smaller loans for the smaller chunk
for (PfPart& p : pf_parts)
if (p.first >= 0) {
p.first = (int32_t) (p.cache->slots() - part_slots(p, next));
p.first_now = p.first;
}
lend_first = pf_parts[0].first;
borrow = xcache.device_slot(lend_first);
borrow_bytes = part_bytes(pf_parts[0], lend_first);
}
err.clear();
continue;
}
std::fprintf(stderr, "strata serve: %s\n", err.c_str());
if (err.find("fit") != std::string::npos) // #85: say what frees VRAM
std::fprintf(stderr, "strata serve: the GPU has too little free VRAM for the prompt path: turn images "