Repository navigation
Description
What happens
Reading a kernel's result BO after the ERT completion signal sometimes returns a short tile: a
few percent of the C elements are zeros (never written) although the launch reported completed and
the same program, ELF, inputs and weight BO produce an exact result on the next run. Measured on
strixhalo with the shipping M=16 decode twin of the 27B container (ELF md5 b662765e…, i.e. the
artifact the engine ships and that NPU_M16_CHECK passes 7,295 launches against).
This is the same phenomenon already recorded in-tree, without a fix, in
npu/forward/engine-src/npu_engine_i8ctx_inc.h (RESULTS-coverage-multifamily sections 68/82:
"bC is identical immediately before each launch, and yet the dequantized bA -- the host's reading of
that same bC -- differs … So the kernel's output buffer is the same and what the host gets back from
it is not."). This issue is that finding with a reproducible harness and a scope: production
decode reads C the same way (wait_kernel() then readback()), one launch per GEMM, so a dropped
write inside a layer is a silent wrong activation that can flip a token.
Evidence (key RESULT lines; identical harness bytes, verified by SHA256SUMS)
RESULT task=GU seed=2 K=5120 N=17408 M=16 verdict=FAIL mismatches=17488 ...
first_idx=832 got=0 want=15154 worst_absdiff=826718 reads=7 clean_reads=0
RESULT task=GU seed=3 K=5120 N=17408 M=16 verdict=FAIL mismatches=608 ...
first_idx=9344 got=0 want=-222094 worst_absdiff=628392 reads=7 clean_reads=0
Earlier in the same session: 24,782 / 23,229 / 25,901 / 216,399 / 1,519 mismatching elements, all
got=0, all with the same ELF and inputs.
Timeline on one box, no code change between the runs:
| window | runs | failed |
|---|---|---|
| 11:40–12:15 | 15 | ~7 |
| 12:19–12:20 | 12 | 0 |
| 12:50 | 7 | 2 |
| 12:56 | 4 | 0 |
| 13:01 (new blocked-B kernel) | 3 | 3 — every run needed exactly one relaunch |
What it is not
- Not the harness or the inputs: the frozen harness is checked with
sha256sum -cbefore every
run, and three consecutive runs on the same seed alternate pass/fail. - Not a host-side transfer race: re-reading after 2 ms, 7 times over 12 ms, still short
(reads=7 clean_reads=0); syncing the activation BO before and after each launch, and sleeping
10 ms afterwait(), changes nothing. - Not the kernel's maths: the same ELF is byte-exact in the engine's own gate on 7,295 launches,
and the failures are always missing writes (got=0), never wrong values. - Not load/contention: it happened on an exclusive device (
fuser /dev/accel/accel0empty, no
other serve) and was absent for hours on the same box.
Workaround currently in use (arena only, not in the engine)
~/wt/npu-arena/runner/runner.cpp: after the launches, read C; PASS requires two consecutive
clean reads; if the first read is short, the whole launch group is re-issued (up to 3 attempts)
and the timing of a non-clean attempt is discarded, so a score can never come from a bad read.
~/wt/npu-arena/oracle.sh additionally requires every seed run and the timed run to be
byte-exact. This makes the benchmark trustworthy; it does nothing for the engine.
Two candidate fixes
- A real fence after the completion signal. The ERT
COMPLETEDstate appears to be signalled
when the core/control sequence retires, not when the last S2MM of the output buffer has landed in
DDR. Options: an explicit end-of-sequence barrier (a tiny ERT task that touches the output
buffer / a dedicated "flush" BD on the C channel) beforereadback()trusts the data, or a
driver-level fence (DMA-buf fence /amdxdnasyncobj) sowait_kernel()implies the writes are
visible. Preferred if it can be done without a per-launch cost: this is the only fix that helps
production, which cannot afford a re-read of the tile. - Verify-and-reissue in
readback()(cheap, no runtime change): poison a canary in the result
BO before each launch (e.g. the last row, or oneint32per C tile) and after the sync check the
canary changed; if it did not, re-issue the launch once. Costs one sentinel store + one load per
tile and only pays when the race fires. Second choice because it doubles the launch rate in the
bad windows and hides a runtime defect behind a retry.
How to reproduce
~/wt/npu-arena/oracle.sh GU tasks/GU/kernel --no-leader # freezes harness, rebuilds the ELF
# or directly:
~/wt/npu-arena/runner/runner --elf <full_i8_G_K5120_N17408_m16.elf> \
--task ~/wt/npu-arena/tasks/GU --seed 2 --iters 2
Repeat until it fails (it did within 4 runs in three separate windows today); a failure prints
reads=… clean_reads=… and the first mismatching index with got=0.
Blast radius
Every npu_gemm()/npu_gemm_rows() call in npu/forward/src/q4nx_forward.cpp — i.e. all decode and
prefill GEMMs, plus run_lm_head. A dropped write is not detected anywhere: the host dequantises
whatever is in Cm and continues. Proposed owner decision: fix (1) in the engine before the
release candidate is declared final, or (2) as the minimum.
Activity
tools/npu-arena: the kernel arena, its DMA-ceiling probe, and a test …
bong-water-water-bong commentedon Oct 31, 2026
Triage:
bug, and it is the most load-bearing open bug on the NPU side because production reads exactly theway the harness does. At
origin/main31d52e1:So nothing in the engine can currently distinguish "launch retired" from "last S2MM landed". #668 (
2b33b75c0)landed the arena's verify-and-reissue, but as a benchmark discipline — it does not touch
readback(), so theengine still trusts the first read.
The issue is filed with the right two candidate fixes and the right cost structure. What it needs is a decision,
not more measurement:
that helps production without a retry, but it prices every launch, and the 1.037 ms GU kernel is the wrong
place to add 5 %.
readback(): one sentinel store per launch + one load per tile,pays only when the race fires; the cost is a doubled launch rate inside the bad windows, which is exactly
what
NPU_M16_CHECK's 7,295-launch gate would then also be exercising.My recommendation to the owner, in this order: option 2 now as the safety net (it is small, it is testable
on the arena harness already in the tree, and it converts a silent wrong activation into a retry), and
option 1 investigated for the next kernel-format bump, where a per-launch cost can be amortised into the
chunk. Shipping a release candidate whose
wait_kernel()means "probably" is the one outcome I would notaccept, because every decode GEMM is on that line.
Board row and the decision request:
~/briefs/TISSUES-BOARD.md, ORCHESTRATOR item 3 / OWNER item 3.bong-water-water-bong commentedon Oct 31, 2026
Decision (orchestrator, 2026-10-31 12:30 ADT), recorded here so the next reader does not re-litigate it:
Owner lane:
pi-zerocopy. It already owns the copy path on this box (#698 target 2), and a stale-read onreadback is the same question asked from the other end — what the host may assume about bytes the device wrote.
Fence first, canary as fallback. The fence is a
FROM_DEVICEinvalidate on readback: invalidate the hostcache range covering the result BO before the host reads it, so
wait_kernel(); readback();becomes"the device's writes are visible" rather than "the launch retired". That is a coherency operation on a cacheable
host mapping, not a copy — it is the cheap form, and it is the one that can stay in the production path. The
canary (poison a sentinel per tile before the launch, verify it changed after the sync, re-issue once if not)
stays as the fallback only if a short tile survives a correct invalidate; it doubles the launch rate in the bad
windows, which is why it is second.
Gate:
NPU_M16_CHECK, 7,295 launches. That is the artifact the engine ships (the M=16 decode twin of the 27Bcontainer, ELF md5
b662765e…) and the launch count at which it currently comes back byte-exact. Acceptance isthat gate clean with the invalidate in place, no per-launch cost that shows up in
NPU_PHASE_PROF/[prof]readback(today ~0.1 ms), and the 1.037 ms GU kernel unchanged on the arena harness.The two candidate fixes in the body are unchanged; this only fixes the order and the owner. If the invalidate alone
does not close it, the fallback is the canary and the issue stays open until
NPU_M16_CHECKis clean on both.bong-water-water-bong commentedon Oct 31, 2026
Measured on this box (strixhalo, shipping int8 M=16 path, engine build from
zerocopy/main+ the shippingruntime
~/wt/bonsai-speed-build/libonebit_npu_rt.a), following the orchestrator's "fence first" decision. Twofindings, one of which changes the plan.
1. The FROM_DEVICE invalidate the fence would add is already in the shipping path, on every readback.
wait_kernel(r); readback();beforeCmis touched:npu_gemm(npu/forward/src/q4nx_forward.cpp:1937),npu_gemm_rows(:2021),run_lm_head(:3508).I8Ctx::readback()(npu/forward/engine-src/npu_engine_i8ctx_inc.h:405) isbC->sync(XCL_BO_SYNC_BO_FROM_DEVICE).npu_rt::bo::sync(dir,size,off)->flush_range()=_mm_mfence(); clflushon every 64 B of the range; _mm_mfence();— disassembled from the exact library thearena runner links (
TOOLCHAIN.lock->NPU_RT_LIB=~/wt/bonsai-speed-build/libonebit_npu_rt.a):4d92 mfence / 4db4 clflush (%rcx) / 4de0 clflush 0x0(%rax) + 0x40(%rax) / 4df0 mfence.runner.cpp:180,:211) and still reportsreads=7 clean_reads=0, with the pre-launch zeros at the short indices.So a stale host line cannot be what those runs read: after a
clflushsweep the line is gone. A short row meansthe writes are not in memory when the host looks (or never landed at all), which no amount of
re-invalidation can fix. This is evidence for your option 1's second half — "ERT COMPLETED is signalled when the
control sequence retires, not when the last S2MM has landed" — and against a cache-fix reading of the symptom.
2. What that invalidate already costs (the 2 % question). Measured on the shipping decode path with
NPU_PHASE_PROF=1([ph]on a 1.33 s/token pb16i decode): "C readback" 9 ms/token of 1,330 ms = 0.68 %,i.e. ~24 µs per launch over 368 launches. Nothing to win there, and nothing to add: it is already paid.
What I landed instead (your option 2, the fallback), on branch
zerocopy/main:I8Ctx::poison_canary()writesINT32_MINinto every 16th int32 of C row 0 (and of the last row for a batchedlaunch) immediately before the kernel is submitted;
verify_canary()runs right after the invalidate insidereadback(). More than 8 survivors = the row is not there.issue()lambda re-poison -> re-quantise -> relaunch) inall three shipping sites, counted in
canary_retries_; a second short read is printed loudly rather thandequantised into the layer. The M=128 reference side of
NPU_M16_CHECKgets the same treatment, so a shortreference read cannot be blamed on the M=16 twin and pollute the gate.
ONEBIT_NPU_CANARY=0disables it,NPU_CANARY_STATS=1reports the counters.608-216,399 zeroed elements), so every 16th element catches it at 1/16 the traffic; the threshold of 8 keeps an
accumulator that happens to equal the sentinel (1 in 2^32 per element) from ever looking like a short tile.
Pending, needs the device window (requested in
~/NPU-WINDOW-OK; pi-release's c17 gate has the box): thecanary's measured cost (
[ph] h_rbwith it on vs off) and the acceptance run the orchestrator asked for —NPU_M16_CHECK=1, ~8,800 launches (past the 7,295 this issue quotes), requiringMISMATCH: 0and reporting howmany
[canary] SHORTretries fired. I will post those numbers here and in TZEROCOPY-STATE.md.bong-water-water-bong commentedon Oct 31, 2026
Second window (
bonsai2-27b-NPU-m16, canary now flushing its poison before the submit), gate passed, and thenumbers the fix was waiting on. PR: #701.
[canary] SHORTSampling output byte-identical across the arms (
argmax=40554 top=23.238878 margin=5.498953), so the canary doesnot perturb the arithmetic. Cost: readback
rb = 5.4 ms/tokenwith it,4.1-5.1 ms/tokenwithout — +0.36 ms pertoken, mean over 38 tokens ≈ 0.03 % of a token, far inside the 2 % budget. Request wall 472 s (on) / 479 s (off),
i.e. inside run-to-run noise.
Reset of the earlier evidence, for the record: at 6,915 checks in each arm the engine path produced zero
short rows — this issue's phenomenon still reproduces in the arena runner and not through the engine's launch path,
which is exactly why the fix here is detect-and-retry rather than a claim to have removed the dropped write.
Two things this window taught, both of which were my bugs and are fixed in the PR:
they are evicted after the kernel wrote the same lines and clobber the result with the sentinel — 1,416 false
short reads on the shipping M=128 path, one per launch group. Anything that leaves a dirty host line over the
result BO can produce this issue's exact symptom; worth keeping in mind for the runtime side.
NPU_M16_CHECKchecks nothing on the shipping container~/models/npu/bonsai2-27b-NPU: it registersdecode family: 0 role(s) at M=16, so the run reportschecks=0. The 7,295-launch gate in this issue lives on~/models/npu/bonsai2-27b-NPU-m16(withkernels-m16/), which is what the run above used.Limits, stated plainly: row 0 only (a batched launch is not canaried beyond row 0 — poisoning row
am-1fires onevery prefill launch because the kernel does not write the padded last row of the activation BO); the underlying
completion-signal/fence question is still open, and this makes it a detected retry instead of a silent wrong
activation.
npu: canary + one retry in readback(), so a short result row is never…
bong-water-water-bong commentedon Nov 1, 2026
Closing — fix merged and in the v2026.44 draft. Orchestrator 02:05: close it, the fix merged in #701 and shipped
in v2026.44.
What this issue is closed on, all measured:
#701→e7446eef3(2026-10-31 16:51Z)v2026.44resolves toe7446ee, i.e. exactly the #701 mergepoison_canary()before submit (flushed to memory) +verify_canary()insidereadback(); a short row re-issues the whole launch once and is never dequantised. Default on (ONEBIT_NPU_CANARY=0disables,NPU_CANARY_STATS=1reports)NPU_M16_CHECK=1onbonsai2-27b-NPU-m16: 6,915 checks per arm, 0 mismatched, worst int32 = 0; canary ON and OFF arms produce byte-identical sampling (argmax=40554 top=23.238878 margin=5.498953)rb5.4 ms/token with it vs 4.1–5.1 without → +0.36 ms/token ≈ 0.03 % of a 1.33 s/token decode, inside the 2 % budget; request wall 472 s vs 479 s (noise)Two limits the fix states itself, recorded here so the close is honest rather than generous:
NPU_M16_CHECKonly checks anything on~/models/npu/bonsai2-27b-NPU-m16(the shipping container registers no M=16roles, so it reports
checks=0), and the canary covers row 0 (plus the last row for a batched launch) at every16th int32 — a dropped tile is hundreds of elements, so that sampling catches it, but it is detection and re-issue,
not a proven removal of the dropped write.
The underlying completion-signal question stays open in the runtime, not here: at 6,915 checks per arm the
engine's launch path produced zero short rows in both arms, while the arena runner still reproduces them
(
clean_reads=0with theFROM_DEVICEinvalidate already in place). If you want that tracked, it wants its ownissue against the runtime — a fence cannot fix writes that are not in memory when the host looks, which is what the
window measured. Not reopening this one for it.