Repository navigation
Description
Summary
scripts/hw-gate.sh takes flock ~/npu.lock before every GPU step, and that lock is the one an NPU
serve holds for its entire lifetime. So while any NPU model is up, the hardware gate cannot run: it sits in
flock at 0 % CPU until the caller's own hold expires, is killed, re-queues, and sits again. Tonight that
cost c16's gate three consecutive attempts without a single step executing.
Now that GPU and NPU concurrency has been measured safe (#673), the gate should take the NPU lock only for
its npu phase, which is the only phase that touches the device and already does exactly that.
The code, at origin/main
| line | what it does |
|---|---|
scripts/hw-gate.sh:94 |
LOCK=${HW_GATE_LOCK:-$HOME/npu.lock} — the lock is the NPU device lock |
scripts/hw-gate.sh:95 |
LOCK_WAIT=${HW_GATE_LOCK_WAIT:-5400} — a step will wait 90 minutes for it |
scripts/hw-gate.sh:303 |
gpu() — "hold the GPU token, wait for coder-llm, hold the lock, mem-guard + thermal-run" |
scripts/hw-gate.sh:316 |
flock -w "$LOCK_WAIT" -E 75 "$LOCK" "$0" --cool --mem "${GPU_MODEL:--}" … mem-guard.sh "$MEM_FLOOR" "$THERMAL" "$@" |
scripts/hw-gate.sh:580 |
flock -w "$LOCK_WAIT" -E 75 "$LOCK" sh -c "$HW_GATE_NPU_CHECK" — the npu phase, correct today |
scripts/hw-gate.sh:569-570 |
its own comment: the npu phase "runs inside the gate's GPU claim and holds ~/npu.lock, and is NOT wrapped in thermal-run" |
So every GPU step — build, ops, kat, kld, needle, placement — serialises against the NPU device lock, and
gpu() treats a lock timeout as infra=1 (:335), i.e. "the box could not run the gate", after up to
LOCK_WAIT.
The behaviour is not unknown to the docs; it is written down as a cost: docs/hw-gate.md:199-201 —
"Waiting for ~/npu.lock costs more than the gate itself: flock is not first-come-first-served, and with
about ten jobs queueing, each acquisition waited 10 to 60 minutes. The summary reports both numbers (waiting,
holding)." That was tolerable when the queue was GPU jobs. It is not tolerable when the holder is an NPU
serve that holds the lock for hours by design.
Evidence: three cuts, no steps run
From ~/briefs/TRELEASE-3-STATE.md, entry 31 Oct 00:18 (line 1849 of that file):
- the
opsunit was cut by its own 20-minutegpu-holdtwice — attempt 2 token 23:44:42 → cut 00:04:42,
attempt 3 token 00:07:43 — and a third attempt followed the same way; the unit failed with 92; - the holder was the owner's Bonsai serve
(/home/bcloud/wt/w-587-build/1bit forward-serve -m …/bonsai2-27b-NPU/model.q4nx, pid 3272533),
fuser -v ~/npu.lockshowing itF....through six samples over a minute; - the gate sat in
flockat 0 % CPU for the whole window, so the 20-minute hold was spent waiting, not
measuring — and the same attempt re-queued into the same wait.
The lane's own reading of the options (same entry) concluded that pointing HW_GATE_LOCK at a private file
was not acceptable, because "the lock is what keeps GPU and NPU work from colliding on heat and memory".
That premise is what #673 changed.
Why the lock is no longer needed on the GPU steps
- docs(hybrid): NPU and GPU run at the same time, measured — no hazard, ~13 % stream cost (engine#612 item 5) #673 (docs, open PR) measures the NPU and the GPU running at the same time on this box: no hazard,
~13 % stream cost. That retires the collision argument for correctness. - The GPU steps keep every guard they need without
npu.lock:~/GPU-TOKENfair queue, taken per step (:304,take_token), still serialises GPU work against other
GPU jobs and against Hyperloom;scripts/mem-guard.sh(MEM_FLOOR12 GiB) and thetools/mem_budget.pypre-check that refuses a step
which would take GTT to 95 GiB or past MemAvailable (:318-322,rc=76);thermal-run.shcooling and thecool()gate (:578for the npu phase, per step for GPU);- the post-step amdgpu ring-timeout check (
:331-334).
- The
npuphase keeps the lock at:580, unchanged — that is the phase whose device the lock protects.
Smallest fix
In gpu() (:316), stop wrapping the step in flock; keep the self re-exec that does the memory pre-check
and the cooling, and leave LOCK/LOCK_WAIT in place for the npu phase:
- flock -w "$LOCK_WAIT" -E 75 "$LOCK" "$0" --cool --mem "${GPU_MODEL:--}" "$ROOT/scripts/mem-guard.sh" "$MEM_FLOOR" "$THERMAL" "$@"
+ "$0" --cool --mem "${GPU_MODEL:--}" "$ROOT/scripts/mem-guard.sh" "$MEM_FLOOR" "$THERMAL" "$@"plus the doc lines that describe the old behaviour (docs/hw-gate.md:129 "It holds ~/npu.lock (flock) only
while it runs…", and :199-201), and the header comment at scripts/hw-gate.sh:63-64. rc=75
(:335, lock timeout) then applies to the npu phase only, where it is meaningful.
Acceptance
- With an NPU serve running and holding
~/npu.lock,hw-gate.shcompletes its GPU phases (build, ops,
kat, kld, needle, placement) and reports itstiming.tsv"waiting" split as GPU-TOKEN + heat + memory
only — no lock wait. - Two concurrent gate runs still serialise on
~/GPU-TOKEN(no overlap in their GPU steps). mem-guard.shstill refuses a step that would cross the 12 GiB MemAvailable floor / 95 GiB GTT.- The
npuphase still waits for~/npu.lockand still returnsinfra=1onrc=75. - A run with the NPU serve up shows no new
amdgpu ring timeout(the existing post-step check).
New exposure, stated plainly
GPU steps and the NPU serve will now share the box's memory and heat without the lock as an interlock. The
GPU side is still budgeted (mem_budget.py, mem-guard.sh); the NPU side is not — nothing in that path
consults MemAvailable before it grows. If a fix here is followed by a combined-memory incident, the next step
is to have the NPU serve publish its footprint in a file the gate's pre-check can read, not to re-introduce a
global lock. #680 (page faults at GTT 106.5 of 120 GiB) is the shape of what that interlock would have to
prevent.
Scope
Small-fix candidate, deliberately after the release: one script file plus two doc paragraphs, no
behaviour change when no NPU serve is running, and it can be tested on this box without a window once #673
has landed.
Related
- docs(hybrid): NPU and GPU run at the same time, measured — no hazard, ~13 % stream cost (engine#612 item 5) #673 — the measurement that makes this possible (NPU + GPU concurrent: no hazard, ~13 % stream cost).
- HRX: GLM-4.7-Flash intermittent HSA memory fault / NaN logits under varied-length requests (base fork tip too) #315 (closed) — the GTT fault zone the mem pre-check guards.
- hrx: gfxhub page fault + MODE2 GPU reset when GTT nears the 120 GiB ceiling (Flash-Next UD-IQ3_XXS, 18.8k ctx, 106.5 GiB GTT) #680 — page faults + MODE2 resets at GTT 106.5 of 120 GiB: the failure mode a memory interlock exists
to avoid. - Source:
~/briefs/TRELEASE-3-STATE.mdentry 31 Oct 00:18 (line 1849).
Activity
bong-water-water-bong commentedon Nov 1, 2026
Merged — closing. PR #716 → merge commit
cd83e1202(main, 2026-11-01 02:29:55Z).What is verified, and what is not:
hw_gateskipped (nohw-gatelabel)gpu()no longer wraps the step inflock ~/npu.lock; the NPU phase still takes it (an NPU dispatch must not overlap another). GPU token,coder-llmidling, cool-down,mem-guardand the 76-retry untouched; rc 75 is no longer produced by a GPU step, so the three callers now treat 76 onlytests/hw_gate_test.py(ctesthw_gate_judges):gpu()must contain noflock, the NPU phase must — verified both ways, PASS as merged and FAIL with the old line put backRun that gate capped and alone (
systemd-run --user -p MemoryMax=<cap>,free -gfirst, nothing else loading):it loads the 27B row, and the 23:38 OOM is what an uncapped gate plus a neighbour looks like. If a new amdgpu ring
timeout appears in it, this diff is the first suspect and the comment goes here.