[PR #2672] [Engine] Windows (CUDA): cut engine load time from 15.9 s to 8.7 s #4204

Open
opened 2026-11-07 15:33:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2672
Author: @page1
Created: 10/15/2026
Status: 🔄 Open

Base: main ← Head: feature/arena-touch-before-pin


📝 Commits (4)

  • 7895d14 pinned arena (Windows, CUDA): touch the pages from 16 threads before cudaHostRegister (start 5.1 s sooner)
  • 5de49bb native dense (Windows, CUDA): upload the projection matrices from 8 threads through pinned staging (1.5 s -> 0.3 s)
  • adef281 arena (Windows, CUDA): register the expert arena and read it on its own thread from the start of the load (engine 11.1 -> 9.2 s)
  • aaaefd6 docs: the Windows start changes and their switches (STRATA_ARENA_PREFAULT, STRATA_DENSE_UPLOAD_THREADS, STRATA_EARLY_ARENA)

📊 Changes

6 files changed (+448 additions, -0 deletions)

View changed files

📝 docs/DETAILS.md (+34 -0)
📝 include/strata/core/expert_source.hpp (+19 -0)
📝 src/core/expert_source.cpp (+148 -0)
📝 src/core/native_dense.cpp (+175 -0)
📝 src/core/pinned.cu (+38 -0)
📝 src/program/generate.cpp (+34 -0)

📄 Description

Draft, for agreement on scope and for build checks I can't run. These three changes turn on by default, on
Windows with CUDA only, and CONTRIBUTING.md asks for agreement before a change to a default. Each has a switch to
turn it off. On every other backend the five touched C++ files reduce to 0.2.2's code line for line (checked below),
but I have no Linux, HIP or SYCL environment to build them, so I'd welcome help with that check.

Question: are you happy with all three on by default on Windows with CUDA, or should commits 2 and 3 (the two
that change how the drive is read at start) be opt-in until someone measures them on a slower SSD?

Problem and result

On Windows, the engine spends most of its load time on three waits, one after another:

  1. cudaHostRegister does the first touch (zero-fill) of the 46.8 GiB expert arena on one thread: about 5 s.
  2. native_dense.cpp uploads the 300 projection matrices with one synchronous cudaMemcpy each, straight from the
    memory-mapped file. Windows doesn't read the mapped view ahead, so each copy stalls on its page faults, 4 KiB at
    a time: 1.5 s.
  3. The 46.8 GiB expert arena is read only after the dense weights, MTP and head have finished loading, so for the
    first part of the start the drive reads only the small files.

With all three fixed, engine start to ready (the engine started directly, no server) on an RTX 3090 + Core Ultra 9
285K, IQ3_S at 262K context, 8 starts each, in the order (0.2.2, the build timed first, this branch, this branch,
the build timed first, 0.2.2) four times:

each start median
0.2.2 17.57 / 16.18 / 16.03 / 15.58 / 15.52 / 15.93 / 15.61 / 15.95 s 15.94 s
this branch (1b0f8081) 9.01 / 8.99 / 8.66 / 8.71 / 8.73 / 8.43 / 8.73 / 8.61 s 8.72 s
the build timed first (5468a96d's engine sources) 9.03 / 8.80 / 8.68 / 8.41 / 8.61 / 8.31 / 8.61 / 8.44 s 8.61 s

Every start of this branch was faster than every start of 0.2.2. Against the build timed first, the medians differ by 0.11 s
(8.72 against 8.61 s; this branch was the faster one in 22 of the 64 pairs of starts), within each arm's own spread.
Of the fixes made after review, only one could change the timing: the pinned-memory headroom is now taken before the
expert read starts. An earlier 10 + 10 of that first build against 0.2.2 gave
16.14 against 8.78 s (Validation).

In these runs decode and prompt speed showed no measurable change, and the expert arena and the projection matrices
held the same bytes (Validation).

"Engine alone" above is strata.exe from its start to READY. A full server start, from launching the server to
/health reporting loaded, also includes the server's own startup and the orphan search it runs before launching the
engine (about 6 s on Windows with 0.2.2). With the separate orphan-search fix (#3789) as well, a full server start goes
from 25.38 s to 10.26 s (medians of 3 + 3: 27.68 / 25.31 / 25.38 s against 10.68 / 10.17 / 10.26 s).

This PR was the prefault (now commit 1) before the 0.2.0 tracker reset. It's reopened together with #2673 (the dense
upload, now commit 2) and a new change (commit 3, the early arena load), so that the whole Windows engine-load path,
including how the dense upload and the background arena read share the drive, is measured and reviewed in one place. In #2673 blange48 measured a slower 4-GPU
start on Linux when the upload threads ran on every system, and saw different text between restarts. This version
builds none of it outside Windows, so Linux compiles 0.2.2's native_dense.cpp. The orphan-search fix is a separate
PR (#3789).

Approach

  • 1. Arena prefault (src/core/pinned.cu): for 4 KB pages, min(16, cores) threads touch the pages before
    cudaHostRegister, and the whole arena is still registered. Skipped for large pages, a shared
    arena file, or an unregistered arena (integrated GPU, UMA). STRATA_ARENA_PREFAULT=0 keeps the old order;
    =N sets the threads. With 16 threads the touch took 0.5-0.7 s in 29 of 32 logged starts here (1.1 s in two, 2.5 s in one with other
    programs busy), against about 5 s on one thread inside
    cudaHostRegister; a PC with fewer cores uses fewer threads (min(16, hardware threads)).
  • 2. Dense upload (src/core/native_dense.cpp): the matrices are allocated as before, then copied in 8 MiB pieces
    by 8 threads. Each thread sets the CUDA device of the loading thread, opens its own handle to the file (the same
    ANSI open as the GGUF reader's), reads its
    pieces at explicit offsets (ReadFile with OVERLAPPED) into two pinned staging buffers of its own in turn (8 MiB each, 128 MiB in all, freed after), and sends them
    with cudaMemcpyAsync on its own stream. If the file can't be opened, it says so once and copies from the mapping instead; if a piece can't be read, that
    piece is copied from the mapping. If the threaded upload fails (no pinned memory for the staging buffers, say), it
    says so and the matrices are copied one at a time as before.
    STRATA_DENSE_UPLOAD_THREADS=1 keeps the serial copy; STRATA_DENSE_CHECKSUM=1 hashes the matrices read back from
    the GPU. (On an earlier build, copying straight from the mapped view with 4 / 8 / 16 threads took 2.0 / 1.2 /
    0.8 s. Switching to ReadFile into pinned staging brought 8 threads down to 0.3 s for the 2019 MiB, so more
    threads weren't tried.)
  • 3. Early arena (src/core/expert_source.cpp, generate.cpp):
    • As soon as the expert layout is known, a thread (on the same CUDA device) builds the arena with the normal
      PinnedArena constructor (reserve, touch, register) and then reads the experts into it, while the dense
      weights, MTP and head load. The pinned-memory headroom (pin_reserve_take(), which open() took before) is
      taken first. It isn't started with two GPUs (a layer split, also one that --split-skip-if-fits later drops to one
      GPU, or remote experts), a pin cap, a shared arena file,
      --mmap-experts, STRATA_PIN_BY_NEED=1 or STRATA_DEFERRED_REGISTER=1 (those need another kind of arena).
      open() waits for it and takes the arena; if the read failed, it frees it, logs why, and loads as before.
      close() and the destructor join the thread, so an early return can't leave it running; a load that fails
      before open() therefore exits only once the expert read has finished.
    • If the arena were pinned early when RAM is tight, a later allocation could fail outright instead of open()
      giving its warning. So it starts only when the free RAM covers the arena plus the floor kept free
      (--conversation-cache-min-free-mib, at least 8 GiB). Below that, it's skipped with a log line saying why, and
      the start runs in the old order.
    • Registering before the read matters: an experiment that read first and registered the filled arena afterwards
      cost about 1.5 s at the next large GPU step (the expert cache's cudaMalloc, or its fill) and gained nothing.
    • STRATA_EARLY_ARENA=0 turns it off.
  • Documentation: a section in docs/DETAILS.md, beside the other on-by-default behaviours, says what each change
    does, what was measured, where it applies, and the switch that restores the old way (commit 4).
  • Other builds: not compiled, but the code they see is unchanged. All three commits only add lines. Every added line is inside
    #if defined(_WIN32) && !defined(STRATA_USE_HIP) or inside an #if on a macro that guard defines
    (STRATA_DENSE_THREADED, STRATA_EARLY_ARENA_BUILT); the only other added lines are those #if/#endif lines
    themselves and the guard's #else in native_dense.cpp, which gives the other builds
    #define STRATA_DENSE_THREADED 0 and so switches the new blocks off. With that condition false, pinned.cu, native_dense.cpp, expert_source.hpp,
    expert_source.cpp and generate.cpp are identical to 0.2.2's files, line for line. I checked that with a short script that evaluates only that condition (attached:
    prove_guard.py), not by compiling HIP or SYCL: it's a text comparison, so it shows that no new line reaches
    those builds, not that they compile. The SYCL build compiles its own copies of these files
    (sycl/CMakeLists.txt, strata_resolve), so it doesn't use the changed ones.

Validation

Passed:

  • Build: CUDA 13.4, sm_86, Visual Studio 2026, Windows 11 26300, strata target, Release, at adef281f (docs aaaefd6e):
    cmake -S . -B build -G "Visual Studio 18 2026" -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86 then
    cmake --build build --config Release --target strata. The timing runs used the engine sources of 5468a96d, built on a
    branch that also carried the separate Python orphan-search fix (#3789). Since then, from reviews: a log line when
    the early arena isn't used or the dense file can't be opened, a message when the free RAM can't be read, the early
    read not started for two GPUs, pin by need or deferred registration, the arena freed by its holder on any early
    return, the dense file opened like the GGUF reader opens it, the threaded upload falling back to one-at-a-time copies, and
    the pinned-memory headroom taken before the early read. Only the last of these could change the timing; the
    headline above measures 1b0f8081 and that first build side by side. The submitted head (adef281f) differs from
    1b0f8081 only by a code comment and one cudaGetLastError() clear on the upload's fallback path (not reached in
    these starts). On this head: arena
    8ae1446c68dc969b and projection matrices e2a34e261e2077dd, the same as on the first build, and the log shows the
    headroom taken at 0.43 s and the early read started at 0.44 s. (A first 3 + 3 on this head the same evening, 9.86 /
    9.05 / 9.45 s against 0.2.2's 17.60 / 16.70 / 16.14 s, is superseded by the 8 + 8 + 8.)

  • Other builds see 0.2.2's code. prove_guard.py (attached) takes 0.2.2's copy of a file, this branch's copy, and the
    guard lines to treat as false; all five files report "IDENTICAL":

    W='#if defined(_WIN32) && !defined(STRATA_USE_HIP)'
    python prove_guard.py old/pinned.cu src/core/pinned.cu "$W"
    python prove_guard.py old/native_dense.cpp src/core/native_dense.cpp "#if STRATA_DENSE_THREADED" "$W" --drop-define STRATA_DENSE_THREADED
    for f in include/strata/core/expert_source.hpp src/core/expert_source.cpp src/program/generate.cpp; do
      python prove_guard.py old/$(basename $f) $f "#ifdef STRATA_EARLY_ARENA_BUILT" "$W"; done
    

    (old/ holds the files from 0.2.2, for example git show 011c9e60:src/core/pinned.cu > old/pinned.cu.)

  • Test PC: RTX 3090 24 GB, Core Ultra 9 285K, 95 GB DDR5-6800, WD SN8100 (PCIe 5; 11.2 GiB/s raw unbuffered read,
    measured), IQ3_S, 262,144 context, large pages off.

  • Method: each A/B uses one binary and the change's switch (or 0.2.2 against this branch), with starts alternating
    A B B A A B for the 3 + 3 runs, A B B A five times for the 10 + 10, (A O N N O A) four times for the headline's
    8 + 8 + 8 (A 0.2.2, O the build timed first, N this branch). "Start to loaded": a test server is started on its own port and /health is polled every 0.25 s.
    "Engine alone": the engine is started directly, with CUDA_VISIBLE_DEVICES=0 and STRATA_NO_LARGEPAGES=1, and
    every output line is timestamped as it arrives, up to READY:

    strata.exe --serve --pack <data>/packs/iq3_s
      --native <models>/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf
      --ple-gguf <models>/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf
      --expert-profile <data>/expert-profile.bin --expert-cache auto --prefill auto:32768 --spec 4
      --mtp <data>/mtp/rt --max-context 262144 --kv int8 --kv-resident 65536 --conversation-cache-mib 8192
      --conversation-cache-slots 24 --conversation-cache-min-free-mib 8192 --prompt-cache-every 4096
      --ple-io direct --pcie-frac 1.00 --spec-min-p 0.70 --adapt-every 1 --adapt-swaps 80 --adapt-decay 0.97
      --pool-workers 15 --tail-role-token 8678
    

    The server-level runs use the same arguments through serve/server.py --engine strata --config <config>. Other jobs on the PC were paused, and a background sampler recorded
    every other process's CPU and disk reads.

  • File cache: in every start the expert arena was read unbuffered, straight from the drive (the engine's own probe:
    0-2 of 16 test reads found it cached). Only the smaller files (about 5 GB) go through the Windows file cache, and
    they're warm after the first start of each run, which is why first starts are slower.

Change, measured on Measure Off / old On
all three: 0.2.2 vs this branch (1b0f8081) engine alone, to READY, 8 + 8 17.57 / 16.18 / 16.03 / 15.58 / 15.52 / 15.93 / 15.61 / 15.95 s 9.01 / 8.99 / 8.66 / 8.71 / 8.73 / 8.43 / 8.73 / 8.61 s
all three: 0.2.2 vs the build timed first engine alone, to READY, 10 + 10 18.06 / 17.05 / 16.26 / 16.16 / 16.17 / 16.00 / 16.13 / 16.02 / 16.09 / 15.82 s 9.07 / 9.14 / 8.98 / 8.88 / 8.79 / 8.72 / 8.64 / 8.69 / 8.75 / 8.77 s
1 prefault: 0.2.2 + commit 1 server start to loaded, 3 + 3 24.06 / 24.06 / 24.07 s 18.91 / 18.96 / 18.98 s
2 dense upload: 0.2.2 + commit 2 projection matrices (engine log), 3 + 3 1.5 / 1.5 / 1.5 s 0.3 / 0.3 / 0.3 s
2 dense upload: 0.2.2 + commit 2 server start to loaded, 3 + 3 26.38 (first start) / 23.99 / 24.02 s 22.80 / 22.79 / 22.73 s
3 early arena: this branch, commits 1-2 on, commit 3 off vs on engine alone, to READY, 3 + 3 12.77 / 11.10 / 11.02 s 9.22 / 9.44 / 9.11 s
  • Commit 3, engine alone: the arena is ready at 6.9-7.2 s instead of 8.8-10.2 s. The other loads take longer (done
    at 6.3-6.7 s instead of 2.7-2.8 s) because they share the drive with the expert read; the bytes read are the same.
  • Decode (median of 6 prompts of 400 tokens per start) and a cold 64,629-token prompt: in the 0.2.2-against-branch
    server run, 0.2.2 102.8-108.1 tok/s and 2758-2804 tok/s, the branch 103.3-103.9 tok/s and 2783-2814 tok/s: no
    measurable change. The two arms overlap in every per-change A/B too.
  • Every start of this branch was faster than every start of 0.2.2: 8.43-9.01 s against 15.52-17.57 s in the 8 + 8
    on 1b0f8081, and 8.64-9.14 s against 15.82-18.06 s in the earlier 10 + 10.
  • Generated text across restarts: four prompts at temperature 0 (thinking off, 256 tokens), after six fresh server
    starts: plain 0.2.2 twice, this branch twice at its defaults, and twice with all three changes switched off.
    Plain 0.2.2's own two starts gave different text for two of the four prompts, and every prompt's variants were
    spread across all three arms, not tied to one. One prompt was identical in all six starts. So text that differs
    between restarts is how 0.2.2 already behaves here; these changes didn't introduce it. (docs/DETAILS.md already
    notes that two runs of the same engine aren't identical, because the adaptive tier and the CPU/GPU split depend on
    timing.)
  • Same bytes: the expert arena's checksum is 8ae1446c68dc969b with commit 3 on and off (STRATA_VERIFY_ARENA=1).
    The dense matrices read back from the GPU hash to e2a34e261e2077dd with 1 upload thread and with 8 (4 starts).
  • Commit 3's RAM check: with the floor raised to 60 GiB, the log says "expert read not started: 67.3 GiB of RAM
    available, the arena needs 46.8 GiB plus 60.0 GiB for the rest of the start: loaded as before", and the start runs
    in the old order. With STRATA_EARLY_ARENA=0 the start also runs in the old order, with no early-arena line.

Failed: no correctness failures observed.

Noisy, not used for the claims above: one earlier server-level A/B of commit 3 alone, run while other programs on the PC were busy:
off 11.33 / 11.50 / 11.21 s, on 11.28 / 10.23 / 9.68 s (overlapping). The engine-alone A/B above, on a quiet PC with
the sampler running, had every "on" start faster than every "off" start.

Not run:

  • HIP, SYCL, Linux and macOS builds: not built (no environment here). The guard check above shows they see 0.2.2's
    code; a build or CI run would confirm it.
  • Any other Windows PC: a slower drive, less RAM, a smaller card, or two GPUs. Commit 3 doesn't run for two GPUs
    (a layer split or remote experts), a pin cap, a shared arena file, --mmap-experts, pin by need or deferred
    registration.
  • A Windows PC where registering the whole arena is refused and it pins slice by slice (#243): there the prefault
    and the early arena both run on that path, and it hasn't been measured with them.

Limits

  • Measured on one Windows PC with an NVIDIA card. The gains depend on the arena size, the core count and the drive.
  • Commit 3 overlaps the expert read with the other loads, which then share the drive. The bytes read don't change,
    only their order; on a slower drive the overlap is expected to gain less, and it isn't measured there.

Extending to other hardware

  • AMD on Windows (HIP): the same Windows effects are likely, and every call used exists in the HIP layer. To try:
    drop !defined(STRATA_USE_HIP) from the guards, build a Windows hip or rdna3 engine, check the checksums, then
    run the same A/B with the switches above.
  • Linux, commits 1-2: the mapping is read ahead there, and blange48's 4-GPU run was slower with upload threads, so
    they're left out. An A/B on a Linux CUDA build would show whether the prefault helps.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2672 **Author:** [@page1](https://github.com/page1) **Created:** 10/15/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/arena-touch-before-pin` --- ### 📝 Commits (4) - [`7895d14`](https://github.com/Niko1221/Strata/commit/7895d14fda31a339dfefe5fbd4e71c4b527cfc04) pinned arena (Windows, CUDA): touch the pages from 16 threads before cudaHostRegister (start 5.1 s sooner) - [`5de49bb`](https://github.com/Niko1221/Strata/commit/5de49bbca8451f664ecca3edef41774e4c6514eb) native dense (Windows, CUDA): upload the projection matrices from 8 threads through pinned staging (1.5 s -> 0.3 s) - [`adef281`](https://github.com/Niko1221/Strata/commit/adef281fe72083d2170ab32fc560d35789a85281) arena (Windows, CUDA): register the expert arena and read it on its own thread from the start of the load (engine 11.1 -> 9.2 s) - [`aaaefd6`](https://github.com/Niko1221/Strata/commit/aaaefd6e4c0c834a1d87841e8f053428d771eb95) docs: the Windows start changes and their switches (STRATA_ARENA_PREFAULT, STRATA_DENSE_UPLOAD_THREADS, STRATA_EARLY_ARENA) ### 📊 Changes **6 files changed** (+448 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+34 -0) 📝 `include/strata/core/expert_source.hpp` (+19 -0) 📝 `src/core/expert_source.cpp` (+148 -0) 📝 `src/core/native_dense.cpp` (+175 -0) 📝 `src/core/pinned.cu` (+38 -0) 📝 `src/program/generate.cpp` (+34 -0) </details> ### 📄 Description > **Draft, for agreement on scope and for build checks I can't run.** These three changes turn on by default, on > Windows with CUDA only, and CONTRIBUTING.md asks for agreement before a change to a default. Each has a switch to > turn it off. On every other backend the five touched C++ files reduce to 0.2.2's code line for line (checked below), > but I have no Linux, HIP or SYCL environment to build them, so I'd welcome help with that check. > > **Question:** are you happy with all three on by default on Windows with CUDA, or should commits 2 and 3 (the two > that change how the drive is read at start) be opt-in until someone measures them on a slower SSD? ## Problem and result On Windows, the engine spends most of its load time on three waits, one after another: 1. `cudaHostRegister` does the first touch (zero-fill) of the 46.8 GiB expert arena on one thread: about 5 s. 2. `native_dense.cpp` uploads the 300 projection matrices with one synchronous `cudaMemcpy` each, straight from the memory-mapped file. Windows doesn't read the mapped view ahead, so each copy stalls on its page faults, 4 KiB at a time: 1.5 s. 3. The 46.8 GiB expert arena is read only after the dense weights, MTP and head have finished loading, so for the first part of the start the drive reads only the small files. With all three fixed, engine start to ready (the engine started directly, no server) on an RTX 3090 + Core Ultra 9 285K, IQ3_S at 262K context, 8 starts each, in the order (0.2.2, the build timed first, this branch, this branch, the build timed first, 0.2.2) four times: | | each start | median | |---|---|---| | 0.2.2 | 17.57 / 16.18 / 16.03 / 15.58 / 15.52 / 15.93 / 15.61 / 15.95 s | 15.94 s | | this branch (1b0f8081) | 9.01 / 8.99 / 8.66 / 8.71 / 8.73 / 8.43 / 8.73 / 8.61 s | **8.72 s** | | the build timed first (5468a96d's engine sources) | 9.03 / 8.80 / 8.68 / 8.41 / 8.61 / 8.31 / 8.61 / 8.44 s | 8.61 s | Every start of this branch was faster than every start of 0.2.2. Against the build timed first, the medians differ by 0.11 s (8.72 against 8.61 s; this branch was the faster one in 22 of the 64 pairs of starts), within each arm's own spread. Of the fixes made after review, only one could change the timing: the pinned-memory headroom is now taken before the expert read starts. An earlier 10 + 10 of that first build against 0.2.2 gave 16.14 against 8.78 s (Validation). In these runs decode and prompt speed showed no measurable change, and the expert arena and the projection matrices held the same bytes (Validation). "Engine alone" above is `strata.exe` from its start to `READY`. A full server start, from launching the server to `/health` reporting loaded, also includes the server's own startup and the orphan search it runs before launching the engine (about 6 s on Windows with 0.2.2). With the separate orphan-search fix (#3789) as well, a full server start goes from 25.38 s to 10.26 s (medians of 3 + 3: 27.68 / 25.31 / 25.38 s against 10.68 / 10.17 / 10.26 s). ## Related discussion This PR was the prefault (now commit 1) before the 0.2.0 tracker reset. It's reopened together with #2673 (the dense upload, now commit 2) and a new change (commit 3, the early arena load), so that the whole Windows engine-load path, including how the dense upload and the background arena read share the drive, is measured and reviewed in one place. In #2673 blange48 measured a slower 4-GPU start on Linux when the upload threads ran on every system, and saw different text between restarts. This version builds none of it outside Windows, so Linux compiles 0.2.2's `native_dense.cpp`. The orphan-search fix is a separate PR (#3789). ## Approach - **1. Arena prefault** (`src/core/pinned.cu`): for 4 KB pages, min(16, cores) threads touch the pages before `cudaHostRegister`, and the whole arena is still registered. Skipped for large pages, a shared arena file, or an unregistered arena (integrated GPU, UMA). `STRATA_ARENA_PREFAULT=0` keeps the old order; `=N` sets the threads. With 16 threads the touch took 0.5-0.7 s in 29 of 32 logged starts here (1.1 s in two, 2.5 s in one with other programs busy), against about 5 s on one thread inside `cudaHostRegister`; a PC with fewer cores uses fewer threads (min(16, hardware threads)). - **2. Dense upload** (`src/core/native_dense.cpp`): the matrices are allocated as before, then copied in 8 MiB pieces by 8 threads. Each thread sets the CUDA device of the loading thread, opens its own handle to the file (the same ANSI open as the GGUF reader's), reads its pieces at explicit offsets (`ReadFile` with `OVERLAPPED`) into two pinned staging buffers of its own in turn (8 MiB each, 128 MiB in all, freed after), and sends them with `cudaMemcpyAsync` on its own stream. If the file can't be opened, it says so once and copies from the mapping instead; if a piece can't be read, that piece is copied from the mapping. If the threaded upload fails (no pinned memory for the staging buffers, say), it says so and the matrices are copied one at a time as before. `STRATA_DENSE_UPLOAD_THREADS=1` keeps the serial copy; `STRATA_DENSE_CHECKSUM=1` hashes the matrices read back from the GPU. (On an earlier build, copying straight from the mapped view with 4 / 8 / 16 threads took 2.0 / 1.2 / 0.8 s. Switching to `ReadFile` into pinned staging brought 8 threads down to 0.3 s for the 2019 MiB, so more threads weren't tried.) - **3. Early arena** (`src/core/expert_source.cpp`, `generate.cpp`): - As soon as the expert layout is known, a thread (on the same CUDA device) builds the arena with the normal `PinnedArena` constructor (reserve, touch, register) and then reads the experts into it, while the dense weights, MTP and head load. The pinned-memory headroom (`pin_reserve_take()`, which `open()` took before) is taken first. It isn't started with two GPUs (a layer split, also one that `--split-skip-if-fits` later drops to one GPU, or remote experts), a pin cap, a shared arena file, `--mmap-experts`, `STRATA_PIN_BY_NEED=1` or `STRATA_DEFERRED_REGISTER=1` (those need another kind of arena). `open()` waits for it and takes the arena; if the read failed, it frees it, logs why, and loads as before. `close()` and the destructor join the thread, so an early return can't leave it running; a load that fails before `open()` therefore exits only once the expert read has finished. - If the arena were pinned early when RAM is tight, a later allocation could fail outright instead of `open()` giving its warning. So it starts only when the free RAM covers the arena plus the floor kept free (`--conversation-cache-min-free-mib`, at least 8 GiB). Below that, it's skipped with a log line saying why, and the start runs in the old order. - Registering before the read matters: an experiment that read first and registered the filled arena afterwards cost about 1.5 s at the next large GPU step (the expert cache's `cudaMalloc`, or its fill) and gained nothing. - `STRATA_EARLY_ARENA=0` turns it off. - **Documentation:** a section in `docs/DETAILS.md`, beside the other on-by-default behaviours, says what each change does, what was measured, where it applies, and the switch that restores the old way (commit 4). - **Other builds: not compiled, but the code they see is unchanged.** All three commits only add lines. Every added line is inside `#if defined(_WIN32) && !defined(STRATA_USE_HIP)` or inside an `#if` on a macro that guard defines (`STRATA_DENSE_THREADED`, `STRATA_EARLY_ARENA_BUILT`); the only other added lines are those `#if`/`#endif` lines themselves and the guard's `#else` in `native_dense.cpp`, which gives the other builds `#define STRATA_DENSE_THREADED 0` and so switches the new blocks off. With that condition false, `pinned.cu`, `native_dense.cpp`, `expert_source.hpp`, `expert_source.cpp` and `generate.cpp` are identical to 0.2.2's files, line for line. I checked that with a short script that evaluates only that condition (attached: `prove_guard.py`), not by compiling HIP or SYCL: it's a text comparison, so it shows that no new line reaches those builds, not that they compile. The SYCL build compiles its own copies of these files (`sycl/CMakeLists.txt`, `strata_resolve`), so it doesn't use the changed ones. ## Validation **Passed:** - Build: CUDA 13.4, sm_86, Visual Studio 2026, Windows 11 26300, `strata` target, Release, at adef281f (docs aaaefd6e): `cmake -S . -B build -G "Visual Studio 18 2026" -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86` then `cmake --build build --config Release --target strata`. The timing runs used the engine sources of 5468a96d, built on a branch that also carried the separate Python orphan-search fix (#3789). Since then, from reviews: a log line when the early arena isn't used or the dense file can't be opened, a message when the free RAM can't be read, the early read not started for two GPUs, pin by need or deferred registration, the arena freed by its holder on any early return, the dense file opened like the GGUF reader opens it, the threaded upload falling back to one-at-a-time copies, and the pinned-memory headroom taken before the early read. Only the last of these could change the timing; the headline above measures 1b0f8081 and that first build side by side. The submitted head (adef281f) differs from 1b0f8081 only by a code comment and one `cudaGetLastError()` clear on the upload's fallback path (not reached in these starts). On this head: arena `8ae1446c68dc969b` and projection matrices `e2a34e261e2077dd`, the same as on the first build, and the log shows the headroom taken at 0.43 s and the early read started at 0.44 s. (A first 3 + 3 on this head the same evening, 9.86 / 9.05 / 9.45 s against 0.2.2's 17.60 / 16.70 / 16.14 s, is superseded by the 8 + 8 + 8.) - Other builds see 0.2.2's code. `prove_guard.py` (attached) takes 0.2.2's copy of a file, this branch's copy, and the guard lines to treat as false; all five files report "IDENTICAL": W='#if defined(_WIN32) && !defined(STRATA_USE_HIP)' python prove_guard.py old/pinned.cu src/core/pinned.cu "$W" python prove_guard.py old/native_dense.cpp src/core/native_dense.cpp "#if STRATA_DENSE_THREADED" "$W" --drop-define STRATA_DENSE_THREADED for f in include/strata/core/expert_source.hpp src/core/expert_source.cpp src/program/generate.cpp; do python prove_guard.py old/$(basename $f) $f "#ifdef STRATA_EARLY_ARENA_BUILT" "$W"; done (`old/` holds the files from 0.2.2, for example `git show 011c9e60:src/core/pinned.cu > old/pinned.cu`.) - Test PC: RTX 3090 24 GB, Core Ultra 9 285K, 95 GB DDR5-6800, WD SN8100 (PCIe 5; 11.2 GiB/s raw unbuffered read, measured), IQ3_S, 262,144 context, large pages off. - Method: each A/B uses one binary and the change's switch (or 0.2.2 against this branch), with starts alternating A B B A A B for the 3 + 3 runs, A B B A five times for the 10 + 10, (A O N N O A) four times for the headline's 8 + 8 + 8 (A 0.2.2, O the build timed first, N this branch). "Start to loaded": a test server is started on its own port and `/health` is polled every 0.25 s. "Engine alone": the engine is started directly, with `CUDA_VISIBLE_DEVICES=0` and `STRATA_NO_LARGEPAGES=1`, and every output line is timestamped as it arrives, up to `READY`: strata.exe --serve --pack <data>/packs/iq3_s --native <models>/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf --ple-gguf <models>/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf --expert-profile <data>/expert-profile.bin --expert-cache auto --prefill auto:32768 --spec 4 --mtp <data>/mtp/rt --max-context 262144 --kv int8 --kv-resident 65536 --conversation-cache-mib 8192 --conversation-cache-slots 24 --conversation-cache-min-free-mib 8192 --prompt-cache-every 4096 --ple-io direct --pcie-frac 1.00 --spec-min-p 0.70 --adapt-every 1 --adapt-swaps 80 --adapt-decay 0.97 --pool-workers 15 --tail-role-token 8678 The server-level runs use the same arguments through `serve/server.py --engine strata --config <config>`. Other jobs on the PC were paused, and a background sampler recorded every other process's CPU and disk reads. - File cache: in every start the expert arena was read unbuffered, straight from the drive (the engine's own probe: 0-2 of 16 test reads found it cached). Only the smaller files (about 5 GB) go through the Windows file cache, and they're warm after the first start of each run, which is why first starts are slower. | Change, measured on | Measure | Off / old | On | |---|---|---|---| | all three: 0.2.2 vs this branch (1b0f8081) | engine alone, to READY, 8 + 8 | 17.57 / 16.18 / 16.03 / 15.58 / 15.52 / 15.93 / 15.61 / 15.95 s | 9.01 / 8.99 / 8.66 / 8.71 / 8.73 / 8.43 / 8.73 / 8.61 s | | all three: 0.2.2 vs the build timed first | engine alone, to READY, 10 + 10 | 18.06 / 17.05 / 16.26 / 16.16 / 16.17 / 16.00 / 16.13 / 16.02 / 16.09 / 15.82 s | 9.07 / 9.14 / 8.98 / 8.88 / 8.79 / 8.72 / 8.64 / 8.69 / 8.75 / 8.77 s | | 1 prefault: 0.2.2 + commit 1 | server start to loaded, 3 + 3 | 24.06 / 24.06 / 24.07 s | 18.91 / 18.96 / 18.98 s | | 2 dense upload: 0.2.2 + commit 2 | projection matrices (engine log), 3 + 3 | 1.5 / 1.5 / 1.5 s | 0.3 / 0.3 / 0.3 s | | 2 dense upload: 0.2.2 + commit 2 | server start to loaded, 3 + 3 | 26.38 (first start) / 23.99 / 24.02 s | 22.80 / 22.79 / 22.73 s | | 3 early arena: this branch, commits 1-2 on, commit 3 off vs on | engine alone, to READY, 3 + 3 | 12.77 / 11.10 / 11.02 s | 9.22 / 9.44 / 9.11 s | - Commit 3, engine alone: the arena is ready at 6.9-7.2 s instead of 8.8-10.2 s. The other loads take longer (done at 6.3-6.7 s instead of 2.7-2.8 s) because they share the drive with the expert read; the bytes read are the same. - Decode (median of 6 prompts of 400 tokens per start) and a cold 64,629-token prompt: in the 0.2.2-against-branch server run, 0.2.2 102.8-108.1 tok/s and 2758-2804 tok/s, the branch 103.3-103.9 tok/s and 2783-2814 tok/s: no measurable change. The two arms overlap in every per-change A/B too. - Every start of this branch was faster than every start of 0.2.2: 8.43-9.01 s against 15.52-17.57 s in the 8 + 8 on 1b0f8081, and 8.64-9.14 s against 15.82-18.06 s in the earlier 10 + 10. - Generated text across restarts: four prompts at temperature 0 (thinking off, 256 tokens), after six fresh server starts: plain 0.2.2 twice, this branch twice at its defaults, and twice with all three changes switched off. Plain 0.2.2's own two starts gave different text for two of the four prompts, and every prompt's variants were spread across all three arms, not tied to one. One prompt was identical in all six starts. So text that differs between restarts is how 0.2.2 already behaves here; these changes didn't introduce it. (docs/DETAILS.md already notes that two runs of the same engine aren't identical, because the adaptive tier and the CPU/GPU split depend on timing.) - Same bytes: the expert arena's checksum is `8ae1446c68dc969b` with commit 3 on and off (`STRATA_VERIFY_ARENA=1`). The dense matrices read back from the GPU hash to `e2a34e261e2077dd` with 1 upload thread and with 8 (4 starts). - Commit 3's RAM check: with the floor raised to 60 GiB, the log says "expert read not started: 67.3 GiB of RAM available, the arena needs 46.8 GiB plus 60.0 GiB for the rest of the start: loaded as before", and the start runs in the old order. With `STRATA_EARLY_ARENA=0` the start also runs in the old order, with no early-arena line. **Failed:** no correctness failures observed. **Noisy, not used for the claims above:** one earlier server-level A/B of commit 3 alone, run while other programs on the PC were busy: off 11.33 / 11.50 / 11.21 s, on 11.28 / 10.23 / 9.68 s (overlapping). The engine-alone A/B above, on a quiet PC with the sampler running, had every "on" start faster than every "off" start. **Not run:** - HIP, SYCL, Linux and macOS builds: not built (no environment here). The guard check above shows they see 0.2.2's code; a build or CI run would confirm it. - Any other Windows PC: a slower drive, less RAM, a smaller card, or two GPUs. Commit 3 doesn't run for two GPUs (a layer split or remote experts), a pin cap, a shared arena file, `--mmap-experts`, pin by need or deferred registration. - A Windows PC where registering the whole arena is refused and it pins slice by slice (#243): there the prefault and the early arena both run on that path, and it hasn't been measured with them. ## Limits - Measured on one Windows PC with an NVIDIA card. The gains depend on the arena size, the core count and the drive. - Commit 3 overlaps the expert read with the other loads, which then share the drive. The bytes read don't change, only their order; on a slower drive the overlap is expected to gain less, and it isn't measured there. ## Extending to other hardware - **AMD on Windows (HIP):** the same Windows effects are likely, and every call used exists in the HIP layer. To try: drop `!defined(STRATA_USE_HIP)` from the guards, build a Windows `hip` or `rdna3` engine, check the checksums, then run the same A/B with the switches above. - **Linux, commits 1-2:** the mapping is read ahead there, and blange48's 4-GPU run was slower with upload threads, so they're left out. An A/B on a Linux CUDA build would show whether the prefault helps. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4204
No description provided.