Skip to content

npu: a host-GEMM forward-serve takes the exclusive device lock, so a no-device probe blocks every device lane (4 h 52 m measured) #1353

Closed

Description

@bong-water-water-bong

1bit forward-serve with NPU_INFER_HOST_GEMM=1 — the offline mode whose whole point is that the forward "runs the model with host GEMMs and never opens the device" (app/forward_serve.cpp:842-845) — still takes /tmp/1bit-npu-device.lock LOCK_EX at startup, because the lock is taken a few lines above the host_gemm flag that would have said not to.

The lock is held for the process's life, so an idle host-GEMM serve blocks every lane that does use the array. Measured on this box:

  • 2026-11-06 11:28 → 16:5x, pid 2231177 (~/lb/1035-row's probe, NPU_INFER_HOST_GEMM=1, :18095): 4 h 52 m holding LOCK_EX with 0 /dev/accel* handles and no CPU (state=S, wchan=hrtimer_nanosleep, utime flat). During that window two npu-hold tickets of mine died on [npu] waiting for the exclusive device lock (186 s each, one full ticket), and pi-moe-npu's 1bit-t2s2-20261102 serve sat blocked on the same flock while holding ~/NPU-TOKEN — so it burned a third lane's ticket time. pi-prs confirmed the same from its side.
  • 2026-11-07 ~05:40, another lane's report (T1BP-ZYPHRA-STATE.md:1415): an unticketed host-GEMM forward-serve on :18099 held the lock through their whole 8 s device window; they concluded "host-GEMM still needs the lock, or should not take it".

NPU_NO_DEVICE_LOCK=1 is the existing workaround, but it is documented as an unsupported escape hatch and is opt-in: every host-GEMM run (probe, row, repro) has to remember it, and one that forgets takes the array out of the fleet for hours. The mode already tells the engine it will not open the device, so the lock should follow that fact rather than a second environment variable.

Fix: take no lock when the run does not open the device. app/npu_device_lock.h gains the policy beside npu_lock_mode_for() (npu_lock_taken(opens_device, escape_hatch)), app/forward_serve.cpp computes host_gemm before the lock and asks it, and the existing device-free npu_device_lock_test gets the truth table. NPU_NO_DEVICE_LOCK=1 still works for the operator. unified.cpp is untouched: that route has no host-GEMM mode, it always opens the device, so its unconditional lock is correct.

Activity

  1. bong-water-water-bong commented on Nov 7, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Fix up as #1363 (bc6cbc8e): npu_lock_taken(opens_device, escape_hatch) beside npu_lock_mode_for(), and host_gemm computed before the lock in app/forward_serve.cpp instead of four lines after it. Every route that opens the device is unchanged, including #1241's holder-naming diagnostics; app/unified.cpp keeps its unconditional lock (that route has no host-GEMM mode) and the ONNX EP is untouched (LOCK_NB + CPU fallback, so it never blocks anyone).

    Same reproducer (tools/repro-hostgemm-lock.sh, in the PR), same 0.6B container, same prompt:

    binary serve holds the lock fd flock from outside answers verdict
    before — deployed ~/wt/serve-bin/t2s2-20261104/1bit YES blocked (Resource temporarily unavailable) ' Paris. The capital', 4 tokens takes the lock
    after — branch build no succeeds ' Paris. The capital', 4 tokens takes none

    Both arms passed the "it is a working serve, not a corpse" check, which is the part that matters: a serve that had died would release the lock and look fixed. npu_device_lock_test gains the truth table and is green (npu_device_lock: ok), device-free.

    One thing worth keeping in the thread: this defect is invisible from the outside — pid 2231177 had zero /dev/accel* handles and a flat utime while it blocked the fleet for 4 h 52 m, so the only reliable tell is the lock fd itself. That is why the reproducer checks the serve's own /proc/<pid>/fd rather than only probing the lock from outside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions