Repository navigation
Description
A launch whose buffer is narrower than the ELF's declared argument does not fail — it faults the IOMMU and returns garbage. Measured 2026-11-02 on the strixhalo NPU with an OGA-pack container; one npu-hold ticket pair, 11 s of device time, three IO_PAGE_FAULT bursts, no amdxdna ERROR, no TDR.
What happened
Our own runtime (npu_rt, direct /dev/accel/accel0, no XRT, no AMD library loaded) served a 291-tensor container with a five-ELF kernel set. The forward derived the right kernel names, all five designs plus their _m16 twins initialised, and generation completed — returning garbage. In the same seconds the kernel logged:
amdxdna 0000:c6:00.1: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0001 address=0x7f111f15f000 flags=0x0007]
... 10 entries, one per 4 KB page, then "AMD-Vi: IOMMU Event log restarting"
Both buffers involved are ordinary driver GEM BOs (DRM_IOCTL_AMDXDNA_CREATE_BO, type=shmem, mmap(MAP_SHARED|MAP_LOCKED)) — no imported dma-buf, no userptr, no host pointer handed to the device.
Why
A full ELF declares each argument's width in .dynsym, and the driver patches those symbols, so the declared widths are the contract. For this ELF family:
| argument | declared | meaning |
|---|---|---|
arg0 |
163,840 B (.dynsym), 655,360 B (whole stream) |
weights |
arg1 |
2,048 B (= 2 × K) | activations, bf16 |
arg2 |
1,024 (= N) | output, f32 |
The int8 launcher assumes (activations, weights, output) with M-scaled widths — at M=16 it passes 16,384 / 1,048,576 / 65,536 B. So the kernel's shim DMA read 639 KB of weight stream starting inside a 16 KB BO: consecutive pages, no mapping, one IO_PAGE_FAULT per page. forge_bench (which passes (w, x, y) in exactly the declared sizes) is bit-exact on the same files, which is what made the discrepancy visible.
Three independent confirmations of the contract, all device-free: the MLIR aie.runtime_sequence signature (memref<655360xui8>, memref<1024xbf16>, memref<1024xf32>), the .dynsym widths, and forge_bench.cpp:241-242.
What this PR does
Refuses the launch instead of faulting: q4nx_elf_arg_sizes() reads the three widths out of the artifact, and I8Ctx::init_elf() fails with both numbers when a declared width exceeds the buffer it would pass. One-directional: a declared width may be smaller than the buffer (the tile-family ELFs address a tile of a larger BO through the control text), never larger — so every geometry validated so far is unaffected and the check cannot fire on a working model.
tests/npu_elf_args_test.c pins the reader with hand-built ELF32 fixtures (no aiecc, no model, no device), including three refusals.
Not in this PR, and the actual fix for the family
Driving this family needs the launch in its own contract — (weights, activations, output) with the per-core weight-stream layout forge_bench builds — plus a decision on whether these kernels stay a family at all, given that their "M=16" and "M=128" files are byte-identical one-row GEMV designs (so the engine's M dimension has no meaning for them). Filed separately rather than smuggled into a safety gate.
Activity
bong-water-water-bong commentedon Nov 3, 2026
Triaged at
origin/main692cfa25c; labelsbug+npuadded (it had none). PR #869 is already up for it (npu/elf-arg-contract, basemain, 6 files+241/−1:q4nx_elf_arg_sizes()innpu/forward/src/q4nx_pack.c+q4nx_pack.h, the refusal innpu_forward/engine-src/npu_engine_i8ctx_inc.h::init_elf(),tests/npu_elf_args_test.cwith ELF32 fixtures,CMakeLists.txt, CI), so this row's remaining work is a review and a merge, not a diagnosis.The part that matters most: this is very likely the cause of #855, and it is the same container
#855 ("the OGA 0.5B pack loads and answers, but the first greedy token is wrong") has the same subject as the run in this report — 291 tensors, five ELFs, generation completing and returning garbage. The
IO_PAGE_FAULTburst described here is that run's own evidence from the kernel side, and it explains the shape #855 measured: a stream read from 639 KB inside a 16 KB BO is not "a wrong scale", it is addresses that are not the weights, which is exactly a flat head over a large-magnitude residual.So the ordering for #855 changes: re-test on top of #869 before spending another ticket on the oracle re-capture. Two lines in #855's own step list (item 2, the device-free numpy layer-0) are still the right first move, but the device half should be re-run after this refusal is in, because a run that faults the IOMMU cannot distinguish "the container is wrong" from "the launch was wrong", and #845's 00:09Z array-leg comment (the container loading and answering at 1.44 tok/s) was measured in the same window as these bursts.
Two facts the report states that I would write differently
main:seqvsmain:sequence(the ELF's COMDAT instance symbol,npu_rt.cpp:449-453,362). So this family now has three implicit contracts read out of the artifact: kernel instance name, argument order, and argument width. The refusal in npu forward: refuse a launch whose buffer is narrower than the ELF's declared argument (closes #868) #869 pins the third; the other two are still conventions that a new ELF family can violate silently, and the next one will. Worth onereadelf-based check in the same reader while it is being written — it already walks.dynsym, and the instance symbol is in the same table.What would close it
Not the merge alone: the row's own subject is "the IOMMU faults instead of failing", so the acceptance worth writing on it is the negative test on the array — the same container and the same narrower launch, once, under one
npu-holdticket, expectinginit_elf failed: … declares 655360 B, buffer is 16384 Band 0 newIO_PAGE_FAULTindmesg(the current count is 3 bursts × 10 entries in that run's window; capturedmesg | grep -c IO_PAGE_FAULTbefore and after, which is the instrument this report lacked). The unit test in the PR covers the reader, not the fault, and the fault is the issue.Owner pi-ogaload (the OGA container lane, same as #845/#855;
npu_rtitself is shared with pi-zerocopy's #753, so if the launch layer is where the fix belongs long-term, that lane inherits it). Bucket A — one merge plus one ticket.