Commit Graph
1156 Commits
Author SHA1 Message Date
Niko1221 e1a17f116b Merge f-gfx11-reset 5450e4344: the unregistered expert arena only on the Radeon 780M class
The owner's decision (by 11:05 on 11-15): NOREG's default applies to gfx1103 only (the 780M, 760M and 740M). gfx1150 and
gfx1151 keep the registered arena. LOAD, EXIT and XFER stay on for the whole integrated gfx11 class.
2026-11-15 11:10:03 +01:00
Niko1221 5450e4344d Integrated gfx11 under Linux: the unregistered expert arena only on the Radeon 780M class
The owner decided (by 11:05 on 11-15) that the default "arena not registered with the GPU driver" (NOREG, 8d1fadf92 and the
pinned.cu guard 05718a08f) applies to the Radeon 780M class only: gfx1103, which includes the 760M / 740M of the same chip
family. Strix Halo (gfx1151) keeps its registered arena. Strix Point (gfx1150, an experimental opt-in like gfx1103) also
keeps registration, as before NOREG.

Scope: only NOREG's class changes. LOAD (load order and settle), EXIT (the drain on a stop by signal) and XFER
(GPU_PINNED_MIN_XFER_SIZE) stay as they are for the whole integrated gfx11 class (gfx1103 / gfx1150 / gfx1151). Tokens are
the same in both modes.

How it is enforced: kfd_quiet.hpp gets NOREG's own rule, nodes_in_noreg_class: at least one GPU node in the KFD topology and
every GPU node gfx_target_version 110003. generate.cpp passes that rule to noreg_default instead of `true`, inside the
existing STRATA_USE_HIP && __linux__ block and still under the class check. Any other value (110500, 110501, a discrete
card, a 780M beside another card, no topology) keeps the registered arena. A user's STRATA_ARENA_PIN_GIB or
STRATA_UMA_REGISTER=1 still wins, and STRATA_KFD_QUIET_NOREG=0 (or STRATA_KFD_QUIET=0) still registers. pinned.cu changes
only two comments inside its Linux HIP guards.

Test: tests/core/kfd_quiet_test.cpp checks 110003 (unregistered), 110500 and 110501 (registered), discrete cards and
mixed machines (registered), the switches and STRATA_ARENA_PIN_GIB on top of the new rule, and that LOAD / EXIT / XFER keep
the whole class. g++ -std=c++20 -O1 -Wall -Wextra -Werror on p1004: ok.
2026-11-15 11:09:51 +01:00
Niko1221 cbb0a62d68 Merge f-gfx11-reset (6069c9d0c): the Radeon 780M fixes for integrated gfx11 under Linux
- f9932c6ae no GPU work right after the big load allocations
- 59375eb06 a stop by signal drains the GPU before the process ends
- f73fa7410 pageable copies staged by the HIP runtime
- f5f28ae74 kfd_quiet_test: build under -Wall -Wextra -Werror
- 8d1fadf92 the expert arena is not registered with the driver by default
- c3f6978b1 the prompt path can keep its own buffers instead of lending cache slots (off by default)
- 6069c9d0c two more first-request allocations made during the load
2026-11-15 04:14:40 +01:00
Niko1221 6069c9d0c4 Integrated gfx11 under Linux: two more first-request allocations made during the load
What the box showed (p2006, Radeon 780M gfx1103, 11-15): in every mode, registered or not, the first request still grew the GPU's
GTT by 10-15 MiB in 3-5 steps (for example +3 MiB at 87 ms and +10 MiB at 487 ms into the first 512-token request), while its
kernels ran.

Two of the candidates are now made before READY, inside the existing LOAD move (fix 1):
- one staged copy each way (2 MiB, pageable host memory, the null stream: the stream of the lent refill and the blocking cache
  fills) just before the last KFD settle, so the HIP runtime makes its staging buffer and copy path during the load and the settle
  waits for what that provokes. The 2 MiB device buffer is kept for the run;
- the CPU prompt share's pinned buffers (activations, rows, row scales) in Prefill::init at the sizes the first sharing layer asks
  for, for the largest chunk that shares. Only where the share is armed: it is off by default on this class (HIP keeps it off
  except on a single gfx12 card), so the default path allocates nothing here.
The DFlash2 tap staging needs no change: the serve path reserves it at load (sp.reserve_taps) before the settle.

Scope: HIP builds under Linux, the kfd_quiet class (every visible card an integrated gfx1103 / gfx1150 / gfx1151), through
kfd_quiet::load_moves() like the other load moves; nothing changes elsewhere. Token-neutral: no kernel and no computed value
changes; the copy writes only its own buffer.

Switch: STRATA_KFD_QUIET_LOAD=0 (or STRATA_KFD_QUIET=0) turns these off with the rest of the load moves. No new user setting and no
new user-visible line (one STRATA_TRACE line).
2026-11-15 03:14:32 +01:00
Niko1221 c3f6978b10 Integrated gfx11 under Linux: the prompt path can keep its own buffers instead of lending cache slots (off by default)
What the box showed (p2006, Radeon 780M gfx1103, 11-15): with the arena unregistered, every short prompt took 1.1-1.4 s more
(512 tokens 3,517 against 2,620 ms; 84-256 tokens about 2,850-3,050 against 1,500-1,920 ms). That time is the copy-back of the
1,967 cache slots (2.53 GiB) the prompt path borrows, from pageable memory, after every prompt. Without a loan there is no copy-back.

This extends the Strix Halo rule of 0.2.8 (Windows gfx1151: no loan) to this class, with two differences. The decision is made after
the expert cache is sized as with a loan, so the cache gets the same slots it gets today (--expert-cache N, or the auto size). And
the chunk stays the one the loan would have used: no drop to the 2,048 that --no-prefill-borrow alone gives an auto chunk. The
prompt path's own buffers must fit in what the driver reports free beside the cache and the reserve, with 3 GiB to spare (the
arithmetic of AUTO NO-BORROW); otherwise the loan stays. The chunk check at the prompt path's start then runs as for any path with
its own buffers. One GPU only, chunks up to 16,384.

Scope: HIP builds under Linux, the kfd_quiet class (every visible card an integrated gfx1103 / gfx1150 / gfx1151), one block after
the cache sizing in generate.cpp under STRATA_USE_HIP && __linux__; it reads class_flag(), so nothing changes elsewhere.

Default OFF: kNoLendDefaultOn in kfd_quiet.hpp is the one constant to flip once the box test decides. STRATA_KFD_QUIET_LEND=1 turns
it on for a test on the same binary; STRATA_KFD_QUIET_LEND=0, STRATA_KFD_QUIET=0 or STRATA_PREFILL_BORROW=1 keep the loan. No new
user setting and no new user-visible line (one STRATA_TRACE line). Unit tests: the switch rule and the pick, with the chunk kept.
2026-11-15 03:12:43 +01:00
Niko1221 8d1fadf925 Integrated gfx11 under Linux: the expert arena is not registered with the driver by default
What the box showed (p2006, Radeon 780M gfx1103, 11-15): with the load, exit and transfer fixes in, the registered arena still reset
the GPU on its first start (first 512-token request, queue 1, "Failed to quiesce KFD"). The same binary with the arena unregistered
(STRATA_ARENA_PIN_GIB=none) ran 12 of 12 starts and 144 of 144 requests clean, with no eviction and no page move after READY, and
gave the same tokens as the registered build on every request.

So on this class the arena takes the existing unregistered path (UMA mode) by default. In that default no mlock is tried: it cannot
succeed under the default memlock limit and only printed "mlock failed (raise ulimit -l)". The start-up line keeps today's text
without that part.

Scope: HIP builds under Linux, every visible card an integrated gfx1103 / gfx1150 / gfx1151 (the class rule of
igpu_kfd_settle_default, the same as the other kfd_quiet fixes). Enforced at the class site in generate.cpp, inside the existing
STRATA_USE_HIP && __linux__ block. Other cards and builds: arena_no_register() and the lock rule compute the same as before (the
rules moved to kfd_quiet.hpp as pure functions, with unit tests).

A value the user set for STRATA_ARENA_PIN_GIB wins (none / 0 / N / auto), STRATA_UMA_REGISTER=1 still registers, a
STRATA_ARENA_LOCK the user set still decides the lock. Switch: STRATA_KFD_QUIET_NOREG=0 (or STRATA_KFD_QUIET=0) registers the arena
as before. No new user setting; STRATA_TRACE prints one trace line.
2026-11-15 03:11:03 +01:00
Niko1221 64e95049ab prefill: the fused trellis prompt kernels are the default on Windows gfx1151
kG1151DefaultOn = true in include/strata/prefill/fused_tq_hip.hpp: with STRATA_PF_TQ_G1151 unset,
Windows gfx1151 takes Gyro-S's trellis pair on the fused prompt kernels in the build without MMQ
(STRATA_PF_FUSED_TQ=1 is set only there, own_only_switches.hpp). STRATA_PF_TQ_G1151=0 or
STRATA_GFX1151_DEFAULTS=0 is the way back. Linux gfx1151, gfx12, the other HIP devices, CUDA and
the build with MMQ are unchanged (device_on).

Strix Halo, Gyro-S at setup's low-RAM line, against 0.2.13 (same job, prompt ms):
128 / 256 / 512 / 1,000 tokens 348 / 485 / 680 / 1,098 against 476 / 736 / 1,136 / 1,676;
4,096 / 8,192 / 32,000 tokens 3,233 / 6,598 / 24,247 against 4,323 / 7,404 / 28,027.
Prompts of 26-64 tokens read through the verify windows, as with the switch off.

tests/prefill/fused_tq_hip_test.cpp: the shipped default is true, and device_on with it is on for
Windows gfx1151 and off on Linux, with STRATA_GFX1151_DEFAULTS=0, with the switch at 0 and
without STRATA_PF_FUSED_TQ.
2026-11-15 02:16:33 +01:00
Niko1221 f73fa74107 Integrated gfx11 under Linux: pageable copies staged by the HIP runtime
The HIP runtime copies a pageable source of 1 MiB or more by pinning its pages in place
(a GPU userptr) and keeps them (generate.cpp, the STRATA_ARENA_MMAP note). On a Radeon
780M such a userptr is memory the kernel can move under a running dispatch: the hc
check's two 6.5 MB vectors at load, and without a registered arena the lent refill's
1.3 MiB blobs (expert_cache.cpp fill_slot_queued); uma-r13 reset in the load with a
"Failed to quiesce KFD" line although nothing of ours was registered.

The engine now sets GPU_PINNED_MIN_XFER_SIZE=1000000 before HIP starts on this class,
the value STRATA_ARENA_MMAP=1 already sets (measured then: decode 49.06 vs 49.16 ms a
window). The class is read from the KFD topology files, since the device properties need
HIP up: every GPU node (simd_count > 0) of /sys/class/kfd/kfd/topology/nodes/*/properties
has gfx_target_version 110003, 110500 or 110501 (gfx1103 / gfx1150 / gfx1151, integrated
only); a machine with another GPU beside them, or no KFD topology, is not the class.

What the runtime does with the variable was not checked against its source: C:\TheRock
on the owner PC is the Windows binary SDK of TheRock 10.0.0 (bin, include, lib, share;
therock-10.0.0.tar.gz holds the same files), not the ROCclr / ROCr sources. Its
bin\amdhip64_7.dll carries the names GPU_PINNED_MIN_XFER_SIZE and GPU_PINNED_XFER_SIZE and
the line "HSA Copy Using Pinned resource size %d", without the flags' descriptions; it is
the Windows (PAL) runtime. The behaviour relied on is the one measured on Linux for
STRATA_ARENA_MMAP.

Cost by reading: one CPU copy into the runtime's staging buffer per pageable copy of
1 MiB or more (milliseconds at load); none in the default mode's requests, whose copies
come from registered or cudaHostAlloc memory.

Scope: compiled only with STRATA_USE_HIP on __linux__; set only in the class above, and
never over a value the caller set (setenv without overwrite, and not at all when the
variable exists). STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_XFER=0 sets nothing; STRATA_TRACE
prints one line when it is set. Test: the topology rule and the value rule in
tests/core/kfd_quiet_test.cpp (text cases and a temporary folder tree).
2026-11-15 01:57:16 +01:00
Niko1221 59375eb069 Integrated gfx11 under Linux: a stop by signal drains the GPU before the process ends
Reset 45 on p2006: SIGTERM 1 s into the first request ended the engine with kernels in
flight and the expert arena still registered; the kernel's exit then evicted the busy
queues ("Failed to evict queue 1", "Failed to quiesce KFD") and MES reset the GPU.

Now SIGTERM, SIGINT and SIGHUP take this order: the handler only writes the signal's
number into a pipe; a thread of its own (strata-stop) sets the serve loop's STOP flag,
releases the verify windows' GPU waits (the #267 release, silent, through a new bounded
hook release_gpu_waits_within), waits for the whole device for what is left of 3 s
(cudaDeviceSynchronize on a helper thread, the wait bounded), drops the arena's
registration only when the device finished (unregister_arena_ranges, pinned.cu, which
unregisters the ranges register_range recorded), and ends the process by the same
signal, so the wait status the caller sees is unchanged. A second signal during the
stop ends the process at once.

The bound: the server stops its engine with STOP + QUIT and waits 20 s, then SIGTERM and
5 s, then SIGKILL (serve/server.py:114, :3011-3034); Control sends SIGTERM to the server
and kills its process group after shutdown_timeout + 8 s (strata_control/runtime.py:
1113-1134); the macOS lifeline waits 10 s after its SIGTERM (serve/lifeline.py:132-145);
Linux children get SIGKILL by PDEATHSIG when the server dies. 3 s stays inside the 5 s.
QUIT was left as it is: it already leaves the serve scope through the destructors (the
verifier syncs its streams, the prefill frees) and ~ArenaExpertSource (the local at
generate.cpp:7898) unregisters the arena before main returns.

Cost by reading: a stop by signal during a request takes up to 3 s longer; nothing while
the engine runs.

Scope: compiled only with STRATA_USE_HIP on __linux__; installed at run time only when
kfd_quiet::class_flag() is set (integrated gfx1103 / gfx1150 / gfx1151, every visible
card), and only for a signal whose action is still the default (nohup's ignored SIGHUP
stays ignored). No signal mask is changed anywhere. Elsewhere the new code is a pointer
stored in Verifier::init and a list of registered range starts kept on Linux; neither is
read without the handler. STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_EXIT=0 keeps the old
death by signal; STRATA_TRACE prints one line when the handler is in and one at the stop.
Test: the stop's order with a fake GPU layer in tests/core/kfd_quiet_test.cpp.
2026-11-15 01:56:18 +01:00
Niko1221 f9932c6aee Integrated gfx11 under Linux: no GPU work right after the big load allocations
On a Radeon 780M (p2006) both load resets fell in the hyper-connection check, which ran
right after the 7.7 GiB expert cache was allocated, while the kernel was still moving
pages (KFD queue eviction, MES gave no answer, MODE2 reset). Three moves, token-neutral:

- the check (fused_gr_check) runs right after the card is named and before the warm
  thread and the expert arena; Verifier::init then finds it done. Its result depends on
  the card and STRATA_HC_SPLIT only (random weights compared bit for bit; nothing it
  reads is set between the two places), so it chooses the same variant as before;
- one more KFD settle (kfd_settle.hpp: eviction counter quiet for 2 s, at most 10 s)
  between the expert cache allocation and the profile fill;
- the first prompt's lazy device buffers are made in Prefill::init: the int8 experts'
  q8_1 activations for a whole chunk (chunk x 80 x 36 B, 24 MB at 8192), the group
  record, and the K/V copy stream when STRATA_KV_PREFETCH=1. Same buffers and sizes the
  prompt path makes; a failure there is ignored and the prompt path tries as before.

Cost by reading: one settle per start (at least 2 s, at most 10 s), about 24 MB of GPU
memory at an 8192 chunk; nothing per request.

Scope: compiled only with STRATA_USE_HIP on __linux__ (CUDA, Metal, SYCL and Windows HIP
builds have no new code), and at run time only when kfd_quiet::class_flag() is set, from
the same rule as the existing settle (igpu_kfd_settle_default: every visible card an
integrated gfx1103 / gfx1150 / gfx1151). Every other card runs the old order.
STRATA_KFD_QUIET=0 or STRATA_KFD_QUIET_LOAD=0 is the old order on the same binary;
STRATA_TRACE prints one line when it is active. Test: tests/core/kfd_quiet_test.cpp.
2026-11-15 01:53:45 +01:00
Niko1221 477831fb6f prefill: Windows gfx1151 with the fused trellis set: floor 64, --short-read keeps 64
With STRATA_PF_TQ_G1151=1 every Gyro-S layer is fused-only on Windows gfx1151, and two class
rules made for UD-Q4_K_XL took over: --short-read went to 24 (pieces of 25-63 tokens left the
verify windows for a batched read) and the long-prompt floor stayed 1,024 (the staged fused
entry is on). The staged entry does not take Hadamard-folded layers, so both sent those prompts
to the FP16 path: 26-49 tokens 705-993 ms against 293-486 ms with the switch off, 256 tokens
1,914 ms against 726 ms in 0.2.13.

- prefill.cpp trellis_g1151_all_fused(): a native pack whose every gate/up is a trellis type
  (TQ2_T..TQP7), stream_floor_class_measured() (one card, gfx1151) and layers_all_fused_only().
- stream_floor_rule.hpp: new argument trellis_g1151_fused -> kFusedOnlyFloor (64), as gfx12.
- staged_fo_rule.hpp short_read_default: new argument folded_trellis (that set with a
  Hadamard-folded layer, layers_any_folded()) -> keeps the base 64.
- Tests: stream_floor_rule_test and staged_fo_rule_test cover the new rows and the old ones
  with the new argument false.

How each scope is kept out:
- The switch: on gfx1151 layers_all_fused_only() is true for a trellis set only when
  fused_tq_hip.hpp device_on lets the fused kernels take the pair (STRATA_PF_TQ_G1151=1 while
  the default is off), so with the switch off both new flags are false.
- Linux gfx1151: trellis_g1151_all_fused() is compiled only under _WIN32 (and
  stream_floor_class_measured() is _WIN32 only); elsewhere it returns false.
- gfx12: trellis_gfx12_all_fused() and its argument are unchanged; the new function needs
  gfx_arch_is_gfx1151.
- gfx1100-1103, gfx1150: gfx_arch_is_gfx1151 is false, and device_on is off for them.
- CUDA: the function is compiled only under STRATA_USE_HIP; trellis_cuda_all_fused() and
  kTrellisCudaFloor are unchanged.
- The build with MMQ: the function is compiled only under STRATA_PF_OWN_ONLY; elsewhere false.
- Both new arguments default to false, so every other call keeps its old answer.
2026-11-15 01:36:42 +01:00
Niko1221 6bb186c278 prefill: gfx1151 can take the fused trellis prompt kernels (STRATA_PF_TQ_G1151=1, off by default)
The trellis pairs (Gyro-S TQK6 / TQK7, Gyro-M TQ2_T / TQ2_T) ran on native_w11_kernel only
behind a gfx12 device check. The kernel's gfx11 code is the one the other formats already run
on gfx1151, and the trellis decode, the FP32-H epilogue of a Hadamard-folded down and
rot_quant_h_kernel have no per-architecture code.

The three device checks (gu_covered, d_covered_on, native_supported) now go through one rule,
include/strata/prefill/fused_tq_hip.hpp: gfx12 as before (STRATA_PF_FUSED_TQ=1); gfx1151 only
with STRATA_PF_FUSED_TQ=1 and STRATA_PF_TQ_G1151=1 (Gyro-M only with the switch at 1); every
other HIP device off. The Windows gfx1151 default is off in this commit. CUDA and the build
with MMQ are unchanged. tests/prefill/fused_tq_hip_test.cpp checks every input.
2026-11-15 00:35:50 +01:00
Niko1221 49b61d0d44 prefill: the two-chunk equal minimum is 5,400 tokens (a prompt of 10,800 tokens or more takes the equal cut)
kEqualMinChunk2 5,500 -> 5,400. The engine cuts the prompt length minus 1, so a 10,800-token prompt is a segment of
10,799 and reads as 2 x 5,400. Measured at 10,800: RTX 4090 24 GB, IQ3_S, chunk 8,192: equal cut / today's cut 0.985
(5,500: 1.007, 5,600: 1.021); RTX 5070 12 GB, Q2_0 plain pack, chunk 10,496: today's 10,496 + 303 took 1.150 of the
equal cut's time. The test's limit cases move: 10,798 keeps today's cut, 10,799 and 10,800 take 2 x 5,400 at chunk 8,192
and at chunk 10,496; 10,500 keeps today's cut.
2026-11-14 23:57:19 +01:00
Niko1221 bc4026239d prefill: the two-chunk equal minimum is 5,500 tokens (segments of 11,000 tokens or more take the equal cut)
With two chunks the segment is twice the equal chunk, so the minimum is a prompt length.
RTX 5070 Q2_0 chunk 10,496, equal cut against today's cut, prompt ms (BLOCK C6):
5,250: 1.043 (a 10,496 + 3 cut), 5,500: 0.862, 5,650: 0.856. RTX 4090 IQ3_S chunk 8,192:
5,596: 1.011, 5,725: 0.938.

kEqualMinChunk2 5,700 -> 5,500; three or more chunks keep 6,144. Tests: the limit at chunk
8,192 (10,998 today's cut, 10,999 / 11,000 2 x 5,500), 11,192 now equal, 10,800 / 11,000 /
11,300 at chunk 10,496.
2026-11-14 23:08:37 +01:00
Niko1221 3cf99f840a prefill: two equal chunks take the equal cut from 5,700 tokens each (three or more stay at 6,144)
With a configured chunk of 8,192 or more the equal cut was taken only when its equal chunk
was at least 6,144 tokens. Measured since, equal cut against today's cut, prompt ms:
RTX 4090 IQ3_S chunk 8,192, two chunks: 5,596: 1.01, 5,725: 0.938, 5,950: 0.938, 6,125: 0.977;
three chunks: 5,628: 1.13, 5,717: 1.111, 5,933: 1.084, 6,133: 1.058, 6,667: 0.98.
RTX 5070 Q2_0 chunk 10,496, two chunks: 5,250: 1.04, 5,750: 0.83, 6,100: 0.86.

kEqualMinChunk2 = 5,700 applies when the equal cut has exactly two chunks; kEqualMinChunk
(6,144) stays for three or more. A configured chunk under 8,192 and the keep-equal fallback
are unchanged. Tests: the cases above at chunk 8,192 and 10,496 and the limits on both sides.
2026-11-14 22:40:42 +01:00
Niko1221 26c03ce743 Merge f-equal-min: keep today's prompt cut when the equal chunk would be short (under 6,144 tokens at a chunk of 8,192 or more) 2026-11-14 20:49:31 +01:00
Niko1221 74e0ad55ba prefill: keep today's cut when the equal chunk would be short (under 6,144 tokens at a chunk of 8,192 or more)
In a build without MMQ on one GPU, a segment longer than its chunk is read in
equal chunks. On an RTX 4090 24 GB with IQ3_S at a chunk of 8,192, equal
chunks of 4,140 to 5,628 tokens made a prompt just above one chunk slower:
8,279 tokens as 2 x 4,140 took 3,517 ms against 2,579-2,686 ms for
8,192 + 87 (wait copy 1,178 against 470-480 ms, K/V stage 450 against 4 ms,
34,852 experts streamed against 20,963). Against today's cut the equal cut
measured 1.34 / 1.25 / 1.14 at 8,279 / 8,448 / 9,192 tokens, 1.01-1.03 at
11,192, 1.13 at 16,884, 0.98 at 20,000 and 0.99 at 32,000. Every gain
measured on the RTX 5070 12 GB has equal chunks of 6,978 tokens or more.

With a configured chunk of 8,192 or more, an equal chunk under 6,144 tokens
now keeps today's cut (full chunks and a remainder). A smaller configured
chunk keeps the rule unchanged. If today's cut, handed back this way, cannot
be lent while the equal cut can, the equal cut is kept and one line says so
("prompt chunk X -> Y tokens for this request: the old cut's buffers do not
fit ..."), instead of halving the chunk.

equal_cut_rule.hpp holds both decisions (short_equal, declined_equal,
keep_equal); the serve lend and generate's prompt in generate.cpp call them.
A build with MMQ is unchanged: it never takes the equal cut.

Tests: equal_cut_rule_test (two cases at a 10,240 chunk flip, new cases at
8,192 and 4,096 and for keep_equal), fit_out_rule_test unchanged.
2026-11-14 19:31:02 +01:00
Niko1221 4786a2e7d8 Merge f-strix-p1a: P1A prompt experts for Windows gfx1151, on by default there 2026-11-14 16:58:36 +01:00
Niko1221 727890fde6 Merge f-q36-fit: strata-q36 context fit check counts the staging pair in a build without MMQ 2026-11-14 16:58:36 +01:00
Niko1221 1ed9c5c382 strata-q36: context fit check counts the staging pair in the build without MMQ
The one-session fit check (#5715) counted the hybrid mode's staging pair
only when a layer took MMQ or our int8 kernels. In the build without MMQ
the fused kernels take the layers, so use_mmq was false, n_i8 was 0 and
the floor was 0, while place_experts still allocates the pair on the
streamed prompt path. On an RTX 3060 Ti 8 GB at 32K that build went on
and ended with the hybrid buffers' line (1159 MiB needed, 114 MiB free)
instead of the line with a context size that fits.

one_session_staging_counted: the build with MMQ keeps its rule; the build
without MMQ also counts the pair when use_pf is on. The unit test gains
the rule's cases and the 3060 Ti 32K case.
2026-11-14 15:00:04 +01:00
Niko1221 3d302a600d prefill: P1A prompt experts on by default on Windows gfx1151
src/core/arch_defaults.cpp: STRATA_PF_P1A=1 joins the Windows gfx1151 table.
Measured on that chip with UD-Q4_K_XL, 5 interleaved pairs: prompt x1.046
(4K), x1.043 (8K), x1.043 (32K), decode unchanged. KL to the FP16 truth,
24 prompts a size: on 0.0112 / 0.0116 against off 0.0179 / 0.0118 at
4K / 8K. A value the user sets wins, so STRATA_PF_P1A=0 turns it off.
Every other card and system keeps its table.

H grows to FP16 rows only when a layer of the loaded pack takes the P1A
kernels (p1a_takes_pair), so a pack with none allocates what it did before.
The start-up line keeps its wording and is not printed when no layer takes
the P1A kernels.

The settings register lists STRATA_PF_P1A and STRATA_PF_P1A_L2; the
settings page is regenerated.
2026-11-14 14:56:44 +01:00
Niko1221 7aa7c8238f prefill: gfx1151 prompt experts with F16 activations and F16 H behind STRATA_PF_P1A=1
src/prefill/moe_p1a.cu: gufo's RoutedPairF16Kernel / RoutedDownF16Kernel
(07e1191f, MIT) on fused::group's tables and the native blobs: gate/up
(Q4_K, Q5_K) + SwiGLU from the layer input's FP16 rows into FP16 H, down
(Q5_1, Q8_0) of that H into FP16 down rows for moe_combine16. Work items
are 128 rows of one expert (two 64-row tiles). The kernels are the one-layer
harness's line for line except the work-item decode and the arguments.

experts_native takes them only on gfx1151 with STRATA_PF_P1A=1, when the
prompt path handed over the FP16 input (p1a_input), the down rows go out as
FP16 and H has room for FP16 rows (moe_bufs grows H only with the switch on).
Q4_K gate/up + Q5_1 down by default under the switch; STRATA_PF_P1A_L2=1 adds
the Q5_K gate/up and Q8_0 down layers. A layer whose pair is not taken keeps
today's kernels for both projections (the int8 H of today's downs does not
take FP16 H). One start-up line says which layers took which kernels.

With the switch off (the default) nothing changes on any card: p1a_input
keeps a null input, so experts_native never reaches the new branch, and
moe_bufs adds nothing to H.
2026-11-14 13:22:03 +01:00
Niko1221 13363bdb74 prefill: --peer-device keeps the fused prompt kernels in a build without MMQ
With --peer-device the prompt walk ran every layer off the fused kernels (no_peer from
core::peer_portable), so that a peer prompt share, which runs on MMQ only, found the MMQ
ring and buffers fused_ring() sized for it. A build without MMQ declines that share every
time (Prefill::set_peer), so the flag only cost prompt speed there: on z440 (2x RTX A4000,
Q2_0) prompt ms with the flag were 1.33x / 1.37x the build with MMQ at 8,192 / 20,000
tokens.

own_only_line.hpp peer_keeps_mmq(flag, own_only) is now the one rule: true only with the
flag in a build with MMQ. The walk's no_peer and the start-up line's peer_off use it, so a
build without MMQ keeps the kernels it picks without the flag, in MMQ's buffer layout
(fused_ring() still answers false for a peer session: the ring, the buffers, the Portable
host buffers and the peer's expert placement are unchanged). The fused kernels in that
layout are the small-card path's kPfFusedKernelsOnly combination; they read experts from
the ring and the primary's cache only. The start-up line of such a build no longer carries
"(--peer-device: the fused kernels are off)".

Without --peer-device nothing changes (peer_portable() is false, set only from the flag in
generate.cpp); a build with MMQ is unchanged (own_only false).

Edge: STRATA_PF_GROUP_SCRATCH together with --peer-device in a build without MMQ now
reaches the existing "needs MMQ on every layer" error in the walk, as that variable
already does there without the flag.

Tests: own_only_line_test checks the four cases of the rule and the start-up line of a
build without MMQ with the flag on (no clause).
2026-11-14 13:14:49 +01:00
Niko1221 3b0ca805f8 Merge f-sm75-iq-b19: in a build without MMQ, Turing cards (RTX 20 series) read i-quant prompts on Strata's fused expert kernels
On sm_75 the fused expert kernels already compiled for every format, but only
the Q2_0 pair was set up there. In a build without MMQ, where the Turing set
(STRATA_PF_FUSED_SM75) is on by default, they now also take the IQ3_S gate/up
with an IQ4_NL or Q2_0 down, and the other i-quant gate/up formats (IQ2_S,
IQ3_XXS, IQ4_XS, IQ2_XXS, IQ2_XS). A tile rule picks the 128-row instance
above 56 rows an expert for the i-quant gate/up, and an instance whose shared
memory does not fit the card's 64 KB is not set up.

pf_wmma_parity skips, with its reason, the formats whose tile needs more shared
memory than the card allows. The spill baseline lists the known sm_75
instances.

Cards other than Turing and a build with MMQ are unchanged.

No user text changes.
2026-11-14 12:38:54 +01:00
Niko1221 5a952d4d5b Merge f-numa-card2's comment fix: the home CPU set comment in home_cpus.hpp says what the code does
Comment only. No code change.
2026-11-14 12:01:15 +01:00
Niko1221 7a9f8d2ad0 platform: correct the home CPU set comment
The header comment said the home CPU set is not set on one-node hosts or
when the card-node rule declines. generate.cpp sets it in every Linux
start except STRATA_NUMA_CARD=0, so background threads keep the CPU set
the engine was started with. The comment now says that. Comment only; no
behaviour change.
2026-11-14 12:00:41 +01:00
Niko1221 a6859aa7db Merge f-texts-b20: start-up lines of a build without MMQ no longer name MMQ kernels
A build without llama.cpp's MMQ kernels said at start that a model with
K-quant experts reads its prompt "on llama.cpp's MMQ kernels". It now says it
reads it on Strata's own kernels, on NVIDIA cards and on gfx12 (RDNA4) cards.
The "prompt pieces" line of such a build named STRATA_PREFILL_STREAM_MIN=1024
as the way back to the old rule, which was not true; it now names
STRATA_PF_PLAIN_FLOOR=0 for the plain pack, the only pack that switch changes,
and says that STRATA_PREFILL_STREAM_MIN=N sets the number by hand.

A build with MMQ prints the same lines as before.
2026-11-14 11:51:00 +01:00
Niko1221 f02b8a9e02 Merge f-chunk-fit-out: with the equal cut, the automatic prompt chunk is sized for layouts without a short tail
In a build without MMQ, the serve scan for the automatic prompt chunk counted
every layout with the rows of a short last chunk under the stream floor. With
the equal cut on one GPU no layout above the old chunk has such a tail any
more, so the scan now counts what those layouts actually carve. On an RTX 5070
12 GB with the Q2_0 plain pack the automatic chunk goes from 9,216 to 10,240
tokens; with the equal cut that build reads 0.986 to 0.996 of the time of the
build with MMQ at 18,932 to 28,000 tokens.

The RAM copy's lend region (with --resident-experts, --resident-budget-gib or
the automatic RAM fallback) is now sized for that larger chunk too, so the
borrowed cache slots are not read from the model file on every chunk.

A build with MMQ is unchanged.

No user text changes.
2026-11-14 11:46:16 +01:00
Niko1221 c0c2d72c8d Merge f-chunk-equal: in a build without MMQ, long prompts on one GPU are read in chunks of equal size
A prompt segment longer than its chunk was read in full chunks and a short
remainder. In a build without MMQ on one GPU it is now read in
ceil(tokens / chunk) chunks of equal size: 20,932 tokens at a 10,240-token
chunk become 3 x 6,978 instead of 10,240 + 10,240 + 452. The number of chunks
stays the same, no chunk is larger than the configured one, and the short last
chunk under the stream floor goes away. On an RTX 5070 12 GB with the Q2_0
plain pack, 14,000 to 32,000 tokens read in 0.923 to 1.001 of the time of the
old cut; first-token KL at 10,500 tokens no worse.

A segment that fits one chunk keeps its chunk, and a guard keeps the old cut
when the equal chunk would lend more cache slots. The opt-in rule for other
builds (STRATA_PREFILL_EQUAL=1) is kept value for value. A build with MMQ is
unchanged.

No user text changes.
2026-11-14 11:46:04 +01:00
Niko1221 2e279f7583 Merge f-numa-card2: on two-socket Linux machines the engine runs on the graphics card's NUMA node
On a Linux machine with two or more memory nodes, the engine now restricts
itself at start-up to the CPUs of the node the graphics card is attached to,
before the CPU pool and the helper threads start. Decode with CPU experts on
a two-socket RTX 5090 host: a 32-worker pool on one node read 1.11-1.18 of the
two-node default over three rounds (UD 4-bit set).

The process is left as it is when any of these is not met: Linux, the
process's CPUs span more than one node, every card used reports the same known
node, that node can hold the pinned K/V copy and staging buffers, the threads
were not placed by hand (--pool-cores, STRATA_NUMA_SPLIT, --aux-cpus), the CPU
is not hybrid, and the pool keeps its worker count on that node alone. A
taskset, numactl or cpuset restriction is kept. The background copy threads
(checkpoints and parking) now also stay inside the process's CPU set.

STRATA_NUMA_CARD=0 turns it off. On one-node machines the output is identical
to STRATA_NUMA_CARD=0. With STRATA_TRACE the engine prints one
"strata trace: card node: ..." line with the inputs and the decision.

No user text changes outside STRATA_TRACE.
2026-11-14 11:44:58 +01:00
Niko1221 29173b3dba engine: start-up lines of a build without MMQ no longer name MMQ kernels
A build without llama.cpp's MMQ kernels said at start that a model with
K-quant experts reads its prompt "on llama.cpp's MMQ kernels". It now says
it reads it on Strata's own kernels, on NVIDIA cards and on gfx12 (RDNA4)
cards. A build with MMQ prints the same lines as before.

The "prompt pieces" line of a build without MMQ said that
STRATA_PREFILL_STREAM_MIN=1024 keeps the old rule, which is not true. It now
names STRATA_PF_PLAIN_FLOOR=0 for the plain pack, the only pack that switch
changes, and for every pack says that STRATA_PREFILL_STREAM_MIN=N sets the
number by hand.
2026-11-14 10:18:54 +01:00
Niko1221 6aae30348e Merge f-kv-default: with KV streaming on NVIDIA cards, the prompt's new K/V cells reach the host copy by one DMA copy per array
With KV streaming (--kv-resident, which setup writes from 64K context) the
prompt path's append kernel stored every new K/V cell into the host copy
itself, one small store per value over the link: on an RTX 5090 about
17-59 us per prompt token, a fifth to a third of the prompt time at 8K-128K.
CUDA builds now write the cells into the staging pool in VRAM, as before, and
copy the chunk's blocks to the host copy with one cudaMemcpyAsync per array on
the same stream. STRATA_KV_HOST_DMA=0 gives the kernel's own stores back.
HIP keeps its opt-in (STRATA_KV_HOST_DMA=1) as before, and a layer without a
staging pool keeps the kernel's stores. No new buffer.

Nothing changes without KV streaming.

No user text changes.
2026-11-14 10:10:23 +01:00
Niko1221 28e8d0e05c Merge the expert cache fix for a part-way shrink: with --vram-elastic, a refused shrink no longer leaves experts listed in unmapped slots
When the driver refused a segment part way through a VRAM shrink, the segments
given back before the refusal were gone but the residency table still listed
experts in them. After every shrink, refused or not, the entries past what
stays mapped are now evicted, the table is uploaded again and the prompt
path's loan moves down to the end of the live slots; then the error goes out
as before. A segment whose unmap succeeded but whose handle release failed now
counts as unmapped at once.

Nothing changes without --vram-elastic, or when every shrink succeeds.

No user text changes.
2026-11-14 10:09:27 +01:00
Niko1221 420e03b12a Merge f-small-walk: in a build without MMQ, long prompts on 8 GB cards use the layer-major walk with the fused kernels
A build without MMQ set STRATA_PF_FUSED itself before main, and the small-card
prompt rule took that as the user's choice and stood aside, so on an 8 GB card
long prompts were read chunk by chunk. The build now records which switches it
set and the rule only stands aside for a value the user named. The layer-major
walk also takes the fused kernels for the layers they cover in such a build,
instead of falling back to the dequantize and FP16 path.

A build with MMQ is unchanged. STRATA_PF_FUSED set by hand and
STRATA_PF_SMALL=0 keep working as before.

No user text changes.
2026-11-14 10:08:37 +01:00
Niko1221 b9c9484dda prefill: size the RAM copy's lend region for the tail-0 auto chunk
With --resident-experts, --resident-budget-gib or the automatic RAM
fallback (the arena does not fit the RAM, generate.cpp:8064-8091), the
RAM copy keeps the experts of the cache slots the prompt path borrows,
so a prompt does not read them from the model file on every chunk
(#669). The copy's lend region is sized before the serve scan runs
(generate.cpp, the resident block), by plan_lend, which counted today's
tail. After the tail-0 scan of the previous commit, the serve scan could
take a larger chunk (12 GB: 10,240 against 9,216) whose loan is larger
than the region. The slots past the region would then come from the
model file on every chunk, and the low-RAM warning did not report them.

Now, in a build without MMQ:
- One lambda (fit_case, generate.cpp:10810) fills fit_out::ScanCase
  for both the serve scan (generate.cpp:11510) and the region sizing.
- plan_lend takes a tail (generate.cpp:10311; default -1, so every
  other caller, the CLI path included, counts as before). It prices
  the tail the way the serve scan's ring_room and part_slots do.
- Under --serve, when scan_tail() is 0, the region holds the start-up
  loan (today's tail, the largest loan any request takes at that chunk)
  of the tail-0 chunk, when that loan keeps the 128-slot floor
  (fit_out::region_slots, generate.cpp:10836). Otherwise today's region
  is kept. plan_lend then runs once more at today's tail, which leaves
  the ring state as before.
- Hard guard (generate.cpp:11520): the serve scan takes the tail-0
  chunk only when the RAM copy KEPT every slot of its start-up loan
  (src.resident_lent_slots(); fit_out::region_holds). Otherwise it
  keeps today's chunk. The arena holds every expert in RAM and has no
  region, so nothing is checked there.
- The low-RAM warning (generate.cpp:11005) has the same text and the
  same condition. It now names the chunk and slot count of the loan
  that will be taken: the region's chunk, or today's when the RAM kept
  less than the larger region. Before, it named o.prefill_chunk, which
  under auto is the ceiling and not the chunk taken.

RAM: the larger region holds 207 more slots on an RTX 5070 12 GB (3,624
against 3,417 at 1.3175 MiB a slot, about 273 MiB) and about 155 more
on a 16 GB card (6,414 against 6,259, about 204 MiB; from the slope
measured on the 5070). The RAM decision counts these slots inside the
same budget and never refuses a start for them.
src/core/expert_source.cpp:3713-3731 checks only the complement (the
experts no slot holds) against the available RAM less the headroom.
3736-3739 with choose_resident_keep_from (293-303) keep the region's
slots from the last slot down while they fit what is left, and the
budget mode does the same (3675-3691). A start that fitted before
therefore still fits. A copy short of RAM keeps fewer region slots, and
the guard then keeps today's chunk. Today's loan is the region's last
slots, kept first, so it is held at least as far as before.

A build with MMQ compiles the same behaviour (the warning's numbers
are unchanged there). tests/prefill/fit_out_rule_test.cpp checks 12 GB
and 16 GB with the equal cut on and off: the region's extra slots, the
serve start-up loan never above the region, every lent slot kept
wherever today's were, a request's loan at most the start-up loan, and
today's chunk when the copy keeps less than the larger region.
2026-11-14 08:36:08 +01:00
Niko1221 a17d2f9100 prefill: size the auto prompt chunk for tail-free layouts when the equal cut is on
In a build without MMQ, the serve auto chunk scan counted every layout
with the rows of a short last chunk under the stream floor (3,071
tokens: GU, H, Hq and the FP16 Xs / Hh). With the equal cut on one GPU
no layout above 0.1.39's chunk has such a tail any more, so the scan
now counts what those layouts carve: tail 0. On an RTX 5070 12 GB with
the Q2_0 plain pack the auto chunk goes from 9,216 to an expected
10,240 tokens (the build with MMQ takes 9,984 there; at equal chunks
the two builds read level, 1.001-1.002 of the time). Measured with a
9,984 chunk and the equal cut: 0.996 / 0.986 / 0.991 of the build with
MMQ at 18,932 / 20,000 / 28,000 tokens, where the 9,216 chunk read
1.020 / 0.986 / 1.039.

When the scan counts tail 0 (include/strata/prefill/fit_out_rule.hpp,
scan_tail): --prefill auto, one GPU (no layer split, no peer card, one
slot, no head alias), the request-sized tail loan on, the equal cut on
(STRATA_PREFILL_EQUAL not 0), the small-card prompt path not taken, and
today's chunk a fused layout. Everywhere else, STRATA_PREFILL_EQUAL=0
included, the scan counts the 3,071-token tail as before.

Why no layout at run time holds a short tail next to the full ring
while the scan counted tail 0:
- equal chunks: equal_cut_rule.hpp:70-76 returns the equal chunk only
  when its last chunk is at or above the floor; every chunk of the cut
  is at least half the scan's chunk, so the request's tail is 0
  (loan_rules.hpp segment_tail).
- a one-chunk prompt above 0.1.39's chunk is above the floor: tail 0.
  A one-chunk prompt under the floor is not a fused layout and has its
  own small layout; one of 2,817-3,071 tokens is laid out at 3,072 with
  its tail, at or below 0.1.39's chunk.
- every layout at or below 0.1.39's chunk is bounded by old_pick, which
  is always priced with today's tail (generate.cpp:11303).
- today's cut as the loan guard's fallback (equal_cut::loan_ok) would
  carve chunk + tail at the scan's chunk: after a tail-0 scan it is
  taken only at or below 0.1.39's chunk (generate.cpp:18019,
  fit_out_rule.hpp today_cut_ok).
- the grow-only tail (loan_rules.hpp:64, used at generate.cpp:18071)
  grows to the floor's tail only for a request at the layout's own
  chunk that needs a tail, which the cases above exclude.
- a prompt cache hit, a follow-up turn and picture tokens all lend
  through the same lend() per segment (generate.cpp:18972); on one GPU
  the exact-chunk resume is 0 (Prefill::plan_chunk returns 0 under two
  stages, prefill.cpp:3300-3303), so each segment is cut as above.
- the start-up layout (the chunk with today's tail) is checked against
  the 128-slot floor before the larger chunk is taken, and is laid out
  again at the first request.
Today's chunk also stays when the host-aware plan (#2824) planned a
smaller chunk, or plans one for the larger chunk. The VRAM command's
relend (--vram-elastic) prices the cap with the same tail and the
128-slot floor with today's (generate.cpp:14984).

A build with MMQ compiles the previous code unchanged (every change is
under STRATA_PREFILL_FUSED && !STRATA_PREFILL_MMQ). No new setting and
no new log line. tests/prefill/fit_out_rule_test.cpp checks which tail
is counted in each case, the 12 GB and 16 GB chunks from the loans
measured on the RTX 5070, and that a card in the 3,409-3,566-slot band
keeps the small-card path it takes today.
2026-11-14 08:20:02 +01:00
Niko1221 6b63729a97 Merge f-container-mem-core: memory checks that read a container's limit correctly
Inside a container with a memory limit below the machine's RAM:
- the memory guard counts reclaimable file cache (active and inactive, less
  dirty pages and the engine's own mapped file pages) as available, so it no
  longer stops or shrinks a run that fits;
- the expert arena's RAM check no longer counts shared memory as free;
- setup reads the container's memory limit and compares RAM and the expert
  arena in one unit when it picks the low-RAM line; the Terminal tools read
  the same limit as the RAM size.

Outside a container, with a limit at or above the machine's RAM, or with
--memory-limit-mib, nothing changes. STRATA_MEM_CREDIT_INACTIVE=1 brings back
the old inactive-only credit.

The settings register was merged by hand (the new switch added, every other
entry as on this branch) and is regenerated in the next commit.
2026-11-14 06:50:29 +01:00
Niko1221 513fd0cff5 Merge f-kvgrow-guard: --kv-grow no longer faults on a long prompt when the expert cache is at its floor
With --kv-grow and an expert cache that cannot give slots (for example
--expert-cache 100), the K/V pools stayed at their first 16,384 cells and a
longer prompt wrote past them. The K/V now grows from free VRAM in that case,
or the run ends with the existing "no VRAM is left" exit. Nothing changes when
the cache can give slots, and nothing changes without --kv-grow.

Side effect: in the state where the cache cannot give slots, the elastic K/V
now counts as on, so the paths that check it behave as for an accepted
--kv-grow: the concurrent batch run and merge_from are off, and the
end-of-run elastic K/V stats line prints.

No user text changes.
2026-11-14 06:48:40 +01:00
Niko1221 4ebfcda436 Merge the Turing fused i-quant experts onto the NVFP4 base
Brings the sm_75 fused prompt kernels for the i-quant gate/up pairs
(IQ3_S, IQ2_S, IQ3_XXS, IQ4_XS, IQ2_XXS, IQ2_XS gate/up with IQ4_NL or
Q2_0 down; STRATA_PF_FUSED_SM75_IQ=0 turns them off) onto the base that
added the NVFP4 fused kernels.

Two conflicts:

- src/prefill/moe_fused_iq.cu: both sides ended the same list of type
  constants. Kept the base's list, which now ends with T_NVFP4, and put
  the Turing block (t75_slot, t75_bit, kT75Formats) after it. The lines
  the merge adds to this file against the base are exactly the lines the
  Turing commits added against their own base.
- data/settings-register.json: every conflict was a generated "line"
  field. Took one side, then regenerated the register; --check passes
  and the register test passes.

What an NVFP4 expert does on a Turing card, before and after the merge
(line numbers are the merged file's):

- dev_info() (2426-2443): on sm_75 it returns from the Turing block
  before the NVFP4 kernels are set up (2502-2508), so d.nvfp4 stays
  false there. This was already the case in the base; the merge only
  adds the i-quant set-up calls inside that block, and NVFP4 has no
  Turing slot (t75_slot gives -1, so t75_bit is 0).
- native_supported() (2918-2921): the NVFP4 clause returns before the
  new Turing pair check (3009) is reached, and it asks for d.nvfp4 and
  !d.t75, so it answers false on Turing, as in the base.
- gu_covered() (2570) answers false for NVFP4 on Turing, as in the base,
  so experts_native() would refuse the pair at its first check (3049)
  in either tree; the added t75_missing term does not change that.

So on sm_75 an NVFP4 layer never takes the fused kernels, before or
after the merge, and it goes down the same prompt path as in the base:
prefill.cpp, which picks that path, is the base's file unchanged. No
Turing-only branch sits in front of the NVFP4 path.
2026-11-14 06:24:20 +01:00
Niko1221 29147556b9 engine: background copies honour the process's CPU set
The background copy threads (checkpoints and parking) and the checkpoint
helpers start on the host's one CPU and widen their CPU mask before they
work. They widened to every CPU number, so the kernel gave them every
CPU of the cgroup: they left a CPU set the process was started with
(taskset, numactl) and the card's NUMA node the engine now places itself
on. They now widen to the process's CPU set as it is at start-up, after
the card-node placement. With STRATA_NUMA_CARD=0 they widen to every CPU
as before. These threads exist only with the conversation cache or
STRATA_CKPT_THREADS=1. Output does not depend on where they run;
home_cpus_test checks the widening.
2026-11-14 05:51:17 +01:00
Niko1221 716ebae14e engine: run on the graphics card's NUMA node on two-node machines
On a machine with two or more memory nodes the engine now restricts
itself, at start-up and before the CPU pool, the host thread and the
helper threads exist, to the CPUs of the node the graphics card is
attached to. A start with nothing pinned then ends with the same thread
masks, pool start-up line and worker count as the same engine started
under taskset on that node (checked on a rented two-socket host with an
RTX 4090; card_node_test checks the decision on made-up machines and the
restriction of a live process).

Measured value: decode with CPU experts on a two-socket host: a
32-worker pool on one node read 1.11-1.18 of the two-node default over
three rounds (UD 4-bit set, RTX 5090 host).

The process is left as it is unless all of these hold: Linux, two or
more nodes with CPUs, the process's CPUs span more than one node (a
taskset, numactl or cpuset restriction is kept), every card the run uses
reports the same known node (sysfs numa_node), the process may allocate
on that node and the node has free memory for the pinned K/V copy and
staging buffers, the threads were not placed by hand (--pool-cores,
STRATA_NUMA_SPLIT, an --aux-cpus list), the CPU is not hybrid, and the
pool keeps its worker count on that node alone (with --pool-workers N:
the node has N + 1 physical cores). A container CPU quota bounds both
counts alike, so the quota's worker count is kept.

STRATA_NUMA_CARD=0 turns it off. One-node machines read the sysfs node
folder and nothing else; there the output is identical to
STRATA_NUMA_CARD=0 (first-token logits, expert-stream counts and
tokens). With STRATA_TRACE set the engine prints one line,
"strata trace: card node: ...", with the inputs and the decision. The
expert arena itself is not placed by this change.
2026-11-14 05:51:17 +01:00
Niko1221 bde58068a0 Revert "expert arena RAM check: optionally leave the engine's own mappings out"
This reverts commit 667533760d.

Measured in a 57.7 GiB container (RTX 4090, IQ3_S, two starts each way):
with STRATA_ARENA_OWN_MAPPED=1 the arena check read about 27 GiB where
the memory guard read 56.8, waited 80 s, warned of a shortfall, and then
loaded the same arena as without it. Refaults and the PLE table's
resident pages were in the same range both ways and prompt time was
level. The switch was off by default, so the default path is unchanged;
the settings register is regenerated without it.
2026-11-14 05:05:02 +01:00
Niko1221 388a1554f0 expert cache: evict the slots a part-way shrink lost
With --vram-elastic, a VRAM command shrinks the expert cache by giving its
last segments back to the driver. When the driver refused a segment part way,
the segments released before the refusal were already gone, but the command
returned its error before the residency table was updated. The engine kept
serving with experts still listed in slots that were no longer mapped, and the
prompt path's loan could still sit past the end of the live slots.

Now the residency entries past what stays mapped are evicted after every
shrink, refused or not, the table is uploaded again and the loan moves down
to the end of the slots left; then the error goes out as before.

Also: when the unmap of a segment succeeded and only the release of its
handle failed, the segment was still counted as mapped. It now counts as
unmapped at once; the handle stays and is released again by the next grow
or at close.

The eviction is a pure function (strata/core/residency_trim.hpp) with its own
CPU test. expert_cache_segmented_test refuses an unmap and a release part way
through a shrink, through a test-only hook that the engine never sets
(strata/core/expert_cache_refuse.hpp), and checks the slots kept, the entries
evicted and a full grow afterwards. A shrink the driver accepts behaves as
before.
2026-11-14 04:49:38 +01:00
Niko1221 7104c8b8ef prefill: equal-chunk cut rule for long prompt segments, with its unit test
A prompt segment longer than its chunk is read in full chunks and a
remainder (20,931 tokens at 10,240: 10,240 + 10,240 + 451). The new
header equal_cut_rule.hpp holds the rule for reading it in
n = ceil(tokens / chunk) chunks of equal size instead: the first n - 1
chunks take ceil(tokens / n) tokens and the last one at most n - 1 fewer,
never more chunks than today's cut and never a chunk larger than the
configured one. A segment that fits one chunk, or a cut whose last chunk
would fall under the stream floor, keeps today's chunk. The older opt-in
rule (STRATA_PREFILL_EQUAL=1, #693) is kept value for value, and a loan
guard keeps today's cut when the equal chunk would lend more cache slots.

Header only; nothing calls it yet. tests/prefill/equal_cut_rule_test.cpp
checks the switch, the examples measured on an RTX 5070, a sweep of
segment lengths and chunks, and the old opt-in rule against its current
code.
2026-11-14 04:16:24 +01:00
Niko1221 652f5fbd35 generate: the elastic K/V grows from new VRAM when the expert cache cannot give it slots
With --kv-grow accepted at session init, the K/V pools hold physical memory only
for their first 16,384 cells. The start of the elastic K/V then switched growth
off completely when the expert cache could not give slots (no VMM range, no
residency table or expert source, or a cache top at or under its floor of 128
slots, as with --expert-cache 100). The pools stayed at their first cells, and a
longer prompt wrote past them: an illegal memory access.

Now the K/V grows whenever its pools are elastic. The cache gives it slots only
when it can; otherwise every grow takes new VRAM, as it already does when the
cache is at its floor, and the K/V is not trimmed back (there is no cache slot
to return). Nothing changes when the cache can give slots.

kv_grow_rules.hpp holds the decision and the grow target. Tests:
kv_grow_rules_test (CPU) and kv_grow_refused_test (GPU: elastic pools grown from
new VRAM to a 20,000-token prompt's cells and to the whole context, every mapped
cell writable).
2026-11-14 03:38:17 +01:00
Niko1221 f0356cb25f prefill: copy the prompt's new K/V cells to the host copy by DMA on CUDA
With KV streaming (--kv-resident, which setup writes from 64K context) the
prompt path's append kernel stored every new K/V cell into the pinned,
device-mapped host copy itself, one small store per value over the link.
On an RTX 5090 those stores ran at about 0.24 GB/s: 50-59 us per prompt
token when the host copy sat on the other socket's memory, about 17 us on
the GPU's own node, against about 0.5 us for the append into VRAM. That was
a fifth to a third of the prompt time at 8K-128K.

The append already writes the same cells into the one-layer staging pool in
VRAM. The HIP-only switch STRATA_KV_HOST_DMA=1 used that: the append writes
the staging pool and the resident slots only, and one cudaMemcpyAsync per
array copies the chunk's blocks to the host copy on the same stream, so
every later reader is ordered after it as it was after the kernel.

CUDA now takes that path by default; STRATA_KV_HOST_DMA=0 gives the
kernel's own stores back. HIP keeps its opt-in as before. A layer without a
staging pool keeps the kernel's stores. No new buffer: the staging pool is
allocated for every streamed session before any prompt is read.

Tests: kv_host_dma_test (the switch both ways, the backend defaults, no
pool) and kv_host_dma_parity (GPU: fp16, int8 and q4_0, four chunks with
unaligned starts, a reader on another stream behind an event; host copies,
read-backs and VRAM slots byte-equal both ways).
2026-11-14 03:21:21 +01:00
Niko1221 667533760d expert arena RAM check: optionally leave the engine's own mappings out
STRATA_ARENA_OWN_MAPPED=1 makes the expert arena's RAM figure leave out
this process's own resident file mappings, as the memory guard does: in
a container the PLE table the engine mapped before the arena is then no
longer counted as room for the arena. Without it (the default for now)
the table and the arena can together hold more than the container's
limit, and the table's pages are read again from the drive while the
engine answers. With it the arena verdict can switch to the RAM copy of
the hottest experts; which one is faster has not been measured yet, so
the default stays as it was.
2026-11-14 02:21:17 +01:00
Niko1221 434663b1ba expert arena RAM check: do not credit shmem or locked pages in a container
The RAM figure behind the expert arena's verdict, the file tier and the
CPU share credits a cgroup's whole memory.stat "file" counter as
reclaimable. That counter includes shmem (memfd, tmpfs, the shared K/V
pool) and mlocked file pages, neither of which the kernel can give back
in a container without swap. In a 24 GiB scope with a 3 GiB memfd held
the figure said 23.61 GiB where 20.98 GiB was true, and an allocation up
to it was OOM-killed; up to the corrected figure it ran without a kill.

Under a cgroup limit below MemTotal the credit now comes from the same
memory.stat arithmetic as the memory guard (active_file + inactive_file
less dirty and writeback: shmem sits on the anon lists and locked pages
on the unevictable list), keeping this figure's own margin of
min(half the credit, limit / 64). With no limit, a limit at or above
MemTotal, or STRATA_MEM_CREDIT_INACTIVE=1, the figure is the earlier one.
2026-11-14 02:18:05 +01:00
Niko1221 f36f8168f9 memory guard: do not credit the engine's own mapped file pages
Under a container's limit the guard now credits every clean page on the
file lists, which includes the pages the engine itself maps and reads:
the PLE table in ram or mmap mode (when the lock is refused, as in most
containers), mapped model files and the libraries. Planning that RAM for
something else pushes those pages out: in a 24 GiB scope an allocation up
to the lists figure left 22% of a mapped 11 GiB table resident; up to the
figure without the process's own mappings it stayed fully resident.

The credit under a container's limit is now the file lists less this
process's RssFile (/proc/self/status), with the file bytes the engine has
locked added back (a locked PLE table is in RssFile but on the
unevictable list, not on the file lists; generate registers it after the
table is opened and clears it when the lock is given back). When RssFile
cannot be read the inactive-only credit is used. Cold and warm starts of
the same configuration get the same figure: before the table is mapped
its cached pages are credited, after it is mapped its resident pages are
left out in both.

Limit: the Intel engine's generate does not register a locked table, so
there a container with a locked table gets a lower figure than the true
one (on the safe side). Outside a container nothing changes.
2026-11-14 02:14:47 +01:00
Niko1221 e02647b741 memory guard: credit active file cache under a container's limit
The guard credited only inactive_file as reclaimable. On a kernel with
the multi-generational LRU a page faulted in through a mapping lands on
the active list at once, so the same engine in the same container saw
26.7 GiB available after a restart with its n-gram table still cached and
57.1 GiB after a cold start. The kernel reclaims clean active file pages
at the limit as it does inactive ones (checked in a 24 GiB scope without
swap: 21.45 GiB of anonymous memory allocated over 11 GiB of active cache,
no OOM kill). The old comment said active_file holds mlocked pages; the
kernel puts mlocked pages on the unevictable list and shmem on the anon
lists, so neither is on the file lists.

Under a cgroup limit below MemTotal (a container: /proc/meminfo is the
host's) the credit is now active_file + inactive_file less dirty and
writeback. With no limit, a limit at or above MemTotal, or the operator's
--memory-limit-mib cap, the credit stays inactive_file only, unchanged.
STRATA_MEM_CREDIT_INACTIVE=1 keeps the inactive-only credit everywhere.
The memory.stat parsing is a pure function now, with unit tests.
2026-11-14 02:10:12 +01:00