mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2672] [Engine] Windows (CUDA): cut engine load time from 15.9 s to 8.7 s #4204
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4204
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
7895d14pinned arena (Windows, CUDA): touch the pages from 16 threads before cudaHostRegister (start 5.1 s sooner)5de49bbnative dense (Windows, CUDA): upload the projection matrices from 8 threads through pinned staging (1.5 s -> 0.3 s)adef281arena (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)aaaefd6docs: 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
Problem and result
On Windows, the engine spends most of its load time on three waits, one after another:
cudaHostRegisterdoes the first touch (zero-fill) of the 46.8 GiB expert arena on one thread: about 5 s.native_dense.cppuploads the 300 projection matrices with one synchronouscudaMemcpyeach, straight from thememory-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.
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:
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.exefrom its start toREADY. A full server start, from launching the server to/healthreporting loaded, also includes the server's own startup and the orphan search it runs before launching theengine (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 separatePR (#3789).
Approach
src/core/pinned.cu): for 4 KB pages, min(16, cores) threads touch the pages beforecudaHostRegister, and the whole arena is still registered. Skipped for large pages, a sharedarena file, or an unregistered arena (integrated GPU, UMA).
STRATA_ARENA_PREFAULT=0keeps the old order;=Nsets 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 otherprograms busy), against about 5 s on one thread inside
cudaHostRegister; a PC with fewer cores uses fewer threads (min(16, hardware threads)).src/core/native_dense.cpp): the matrices are allocated as before, then copied in 8 MiB piecesby 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 (
ReadFilewithOVERLAPPED) into two pinned staging buffers of its own in turn (8 MiB each, 128 MiB in all, freed after), and sends themwith
cudaMemcpyAsyncon 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, thatpiece 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=1keeps the serial copy;STRATA_DENSE_CHECKSUM=1hashes the matrices read back fromthe 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
ReadFileinto pinned staging brought 8 threads down to 0.3 s for the 2019 MiB, so morethreads weren't tried.)
src/core/expert_source.cpp,generate.cpp):PinnedArenaconstructor (reserve, touch, register) and then reads the experts into it, while the denseweights, MTP and head load. The pinned-memory headroom (
pin_reserve_take(), whichopen()took before) istaken first. It isn't started with two GPUs (a layer split, also one that
--split-skip-if-fitslater drops to oneGPU, or remote experts), a pin cap, a shared arena file,
--mmap-experts,STRATA_PIN_BY_NEED=1orSTRATA_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 failsbefore
open()therefore exits only once the expert read has finished.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, andthe start runs in the old order.
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=0turns it off.docs/DETAILS.md, beside the other on-by-default behaviours, says what each changedoes, what was measured, where it applies, and the switch that restores the old way (commit 4).
#if defined(_WIN32) && !defined(STRATA_USE_HIP)or inside an#ifon a macro that guard defines(
STRATA_DENSE_THREADED,STRATA_EARLY_ARENA_BUILT); the only other added lines are those#if/#endiflinesthemselves and the guard's
#elseinnative_dense.cpp, which gives the other builds#define STRATA_DENSE_THREADED 0and so switches the new blocks off. With that condition false,pinned.cu,native_dense.cpp,expert_source.hpp,expert_source.cppandgenerate.cppare 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 reachesthose 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,
stratatarget, Release, atadef281f(docsaaaefd6e):cmake -S . -B build -G "Visual Studio 18 2026" -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86thencmake --build build --config Release --target strata. The timing runs used the engine sources of 5468a96d, built on abranch 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 from1b0f8081 only by a code comment and one
cudaGetLastError()clear on the upload's fallback path (not reached inthese starts). On this head: arena
8ae1446c68dc969band projection matricese2a34e261e2077dd, the same as on the first build, and the log shows theheadroom 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 theguard lines to treat as false; all five files report "IDENTICAL":
(
old/holds the files from 0.2.2, for examplegit 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
/healthis polled every 0.25 s."Engine alone": the engine is started directly, with
CUDA_VISIBLE_DEVICES=0andSTRATA_NO_LARGEPAGES=1, andevery output line is timestamped as it arrives, up to
READY: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 recordedevery 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.
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.
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.
on 1b0f8081, and 8.64-9.14 s against 15.82-18.06 s in the earlier 10 + 10.
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.)
8ae1446c68dc969bwith commit 3 on and off (STRATA_VERIFY_ARENA=1).The dense matrices read back from the GPU hash to
e2a34e261e2077ddwith 1 upload thread and with 8 (4 starts).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=0the 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:
code; a build or CI run would confirm it.
(a layer split or remote experts), a pin cap, a shared arena file,
--mmap-experts, pin by need or deferredregistration.
and the early arena both run on that path, and it hasn't been measured with them.
Limits
only their order; on a slower drive the overlap is expected to gain less, and it isn't measured there.
Extending to other hardware
drop
!defined(STRATA_USE_HIP)from the guards, build a Windowshiporrdna3engine, check the checksums, thenrun the same A/B with the switches above.
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.