Skip to content

amdxdna: two hardware contexts share one array partition (exclusive=false), so the second dispatch wedges every client (614, DPU PC 0xffffffff) #1084

Description

@bong-water-water-bong

What happens

On strixhalo (Linux 7.4.0-rc1-1bit, amdxdna srcversion 646FFC305CAFF8F9BD736FF = the 0007+0008+0009+0010
driver this fleet runs, tdr_timeout_ms=15000), with the shipped c24 payload (sha256 502d2a81…), the board's model
(6abacb4262504f2a, Qwen3-0.6B) and the board's kernel set (1024x3072x16x8):

as soon as two hardware contexts have each dispatched once, the next dispatch on either one stops the array. Both
clients fail together — {"message": "npu runtime: invalid call (code 614): state 8, run 0 of 28"} after 2 chunks — and
the firmware capture is the one the appliance has produced since c17:

aie2_set_cmd_timeout: Context ID: 15 / DPU PC: 0xffffffff / TXN OP ID: 0xffffffff
                      / Context PC: 0x28b060ad / Timed out sub command ID: 0
aie2_tdr_recover_all: Array stopped dispatching, power-cycling NPU to recover

This is the root cause behind the position stories in #1021/#1051 and the board's "third request dies" rows: it is not
the sequence length, it is how many contexts are configured on the array — and one client alone never reproduces it.

How it was narrowed (each row npu-hold, shipped payload, module unchanged, evidence dir per row)

probe result
two serves, both asked for 1 100 tokens at the same instant 3/3 wedge (both 614 run 0 of 28 at chunk 2), 5 TDRs — npu-longctx/two-client-20261105-034608/
the same two serves, sequential (SEQ=1: A completes before B starts) 3/3 wedge, 9 TDRs → overlap is not required — npu-longctx/two-client-seq-20261105-035726/
a second serve loaded but never dispatched 0/2 clean, hwctx_num stayed 0 while it was "ready" → contexts are created lazily at the first dispatch — npu-longctx/idle-context-20261105-042034/
xrt-smi examine -r aie-partitions with both contexts warmed, then one row both contexts in one partition: Partition Index 0, Columns [0..7] (ctx 598 pid 1499388, ctx 599 pid 1499561), and the row wedges — npu-longctx/partition-20261105-042308/
one client, long rows (1 000–3 408 positions; 3 851-token prefill ×5; per-block-count mode included) clean in every row, 0 TDR
hwctx_num create/destroy, 3 rounds incl. ~20 per-block-count cycles each no leak (0→1→0 each time) — npu-longctx/leak-probe-20261105-033739/

The mechanism, in this driver's source

drivers/accel/amdxdna/aie2_solver.c:

  • get_free_partition() allocates a distinct column range when one is free;
  • allocate_partition() then falls back to sharing a live partition (rpt_node->nshared++) — every partition node is
    created with pt_node->exclusive = false; under the comment "Always set exclusive to false for now." (:217-222).

For the AIE2P designs this fleet runs, a context needs the whole 8-column partition (the 0.6B layer design maps all of
them), so the second context always lands on the same tiles; configuring it overwrites the first one's array state, and
from then on the array stops dispatching every job. The Columns [0..7] row above is that nshared++.

Fix

0003-accel-amdxdna-never-share-an-array-partition.patch (1 file, +18/−2, in the PR this issue is linked to and in
~/wt/xdna-tdr-recover/patches/0011-…patch): mark the partition exclusive = true.

  • get_free_partition() still hands out a distinct range whenever one is free, so designs needing fewer columns than
    the array has keep running concurrently.
  • Only the fatal overlap — no free range, so the contexts would share tiles — becomes a clean -ENODEV at context
    creation (aie2_alloc_resource → aie2_hwctx_init → Allocate AIE resource failed, ret -19) instead of a wedged
    array for every lane.

Built: pin + 0001 + 0002 + 0003 → rc 0, no warnings, srcversion 9E581709A641EEF3C4F37C5; 0003 also applies
clean to the pin alone.

The proof this issue still owes (and its shape)

Not run: the module is not installed anywhere yet (/sys/module/amdxdna/srcversion on strixhalo is still 646FFC30…,
which does not contain 0003). Expected on a build carrying it, with ~/wt/npu-longctx/two-client-probe.sh (that
script wedges 3/3 today):

  • the second serve's first dispatch fails fast — Allocate AIE resource failed, ret -19 in dmesg, -ENODEV to the
    client — instead of wedging;
  • the first client's 1 100-token row completes 200 with ~1 099 chunks and 0 TDRs;
  • after the first client exits, the second one works normally;
  • then the row is repeatable (3/3 the same shape, not a one-off).

If the second client is not the one refused, the ordering assumption in get_free_partition() needs a look. If both
still wedge, then sharing is not the whole story and the next suspect is aie2_config_cu reconfiguring tiles that two
contexts hold.

Behaviour change to state in the release notes

A second client that cannot get its own columns now fails fast instead of taking the array down. For the appliance
(one NPU model at a time, Lemonade) that is the correct behaviour; for anything that expected two NPU clients on one
array it is a limit, and it is worth one line in the c25 notes. The alternative — serialising dispatch across contexts
so several contexts can share the array — is a much larger change and needs a firmware answer, not a patch.

Related: #1051 (the engine-visible hang), #1005 (the recovery series that keeps a wedge survivable), #812 (the imported
dma-buf execution failure is a different mechanism: that one is HMM re-fault, not partition sharing).

Activity

  1. added
    bug
    on Nov 5, 2026
  2. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    One fact from the evidence that decides how much of this is a driver question and how much a product one:

    the partition request comes from the payload's CDO, and for the shipped set it asks for all 8 columns — that is why
    parts-2-two.txt reads Columns [0..7] for both contexts. So with 0003 the second client is refused not because the
    solver is being strict but because there is nothing left to give it: one context of this design occupies the whole array.

    Consequence worth stating in the design discussion, not in the patch: two concurrent NPU models on this box need a kernel
    set that asks for fewer columns
    (a 4-column variant would let two live side by side, which is what closed #656 was after
    with disjoint-array-half kernel sets). That is a compiler/kernel-set decision. The driver's job is only to stop silent tile
    sharing, which is what 0003 does.

    Second, smaller point for whoever picks this up: exclusive = true also means a single client must not keep two contexts
    alive at once (create → dispatch → destroy is fine; two live contexts is now -ENODEV). The dx per-block-count route
    churns contexts sequentially (measured: ~20 create/dispatch/destroy cycles inside one 1 200-token row, hwctx_num 0→1→0),
    so it is unaffected — but any future route that keeps a resident context and opens a second one would hit this, and the
    honest fix for that is the same 4-column variant above, not sharing tiles.

  3. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    0011 as written refuses a single client's second context, not just a second client — and that regresses the engine's own per-op forward route (measured, 3/3)

    I ran into this from outside the driver lane, on the 0011 module as installed on strixhalo at 05:31:45
    (/sys/module/amdxdna/srcversion = 169C46E2BB5F58ADCD5C1EB, klog [drm] Initialized amdxdna_accel_driver 0.18.0 at
    05:32:08). The client is the model-generic per-op forward (1bit forward-serve, npu/forward): it derives one design
    per role and creates four hardware contexts — QKV, O, GU, D — from four full ELFs.

    Three attempts, all inside my own npu-hold tickets, device idle at the start of each (xrt-smi examine -r aie-partitions → "No hardware contexts running on device"), /tmp/1bit-npu-device.lock free, module srcversion
    169C46E2… before and after the run:

    # started result kernel
    1 05:32:11 (1 s after another lane's ticket) QKV ctx ok, O ctx refused aie2_alloc_resource … ret -19 at 05:32:25
    2 05:40:10 same … ret -19 at 05:40:22
    3 05:43:47, device verified idle + lock free first I8Ctx::init_elf ep=full_i8_QKV… → full ELF ok: uuid=36dc4d85…, instance main:seq (1 in this context); then ep=full_i8_O… → full ELF ok: uuid=00ebeb81… → I8Ctx::init_elf failed: npu runtime: device error (code 102): No such device aie2_alloc_resource: Allocate AIE resource failed, ret -19 / aie2_hwctx_init: Alloc hw resource failed, ret -19 / amdxdna_drm_create_hwctx_ioctl: Init hwctx failed, ret -19 at 05:43:48

    Attempt 1 is void as evidence (a module swap mid-ticket re-initialised the device); 2 and 3 are clean, and 3 also re-checked
    the partitions before starting. So: deterministic 3/3, the second create_hwctx in one process is refused with -ENODEV.

    The control is the same binary, container and ELFs on the shipped module. On 56AB9475… (0007) at 17:0x the same client
    created all four contexts and ran 600 decode tokens = 67 200 device submissions with 0 TDRs (that row is in #1017 and
    #799). On the pre-0007 EBC78CDA… it was the same. So this is 0011, not the client, not the container, not the ELF set.

    Mechanism, consistent with the 09:27 note above. The partition request comes from each design's CDO and asks for all
    8 columns; my QKV design is built with cols=8 (the other three 4, but they cannot fit alongside an 8-column claim either:
    8+4+4+4 = 20 > 8). With pt_node->exclusive = false the four contexts shared Columns [0..7] and the client dispatched
    them one at a time — clean for 67 200 submits. With exclusive = true, ctx #1 takes the whole array and ctx #2 has no free
    range, so get_free_partition() returns none and creation fails.

    What that means for #1085's proof row and for shipping. The expectation "the first client completes 200, the second is
    refused" holds only for clients that need one context. Any client that holds several — the engine's per-op forward for
    every q4nx container, i.e. all the model-generic NPU rows including the published ZR1-1.5B-npu-q4km-q8 + its 8 ELFs —
    cannot start at all under 0011. That is a larger regression than the wedge it fixes, so 0011 probably needs one of:

    1. exclusivity scoped per client (pid/mm) instead of per context — one client's own contexts may share a partition
      (today's clean single-client behaviour), another client's may not (today's wedge);
    2. refuse a second context only when it would dispatch while another is live, rather than at creation;
    3. keep 0011 as is and serialise the engine side: create/use/destroy one design's context at a time instead of holding four
      (an npu/forward change; expensive, because the design selection is per token, not per request).

    Nothing here is a repo change from me; the engine-side rows I own (ZR1 device arms) are frozen at the pre-0011 module until
    this is decided. Two operational notes from the same window, both seen from outside your lane: (a) the 05:31:45 module swap
    happened inside a held npu-hold ticket (mine) and voided that run — the device was re-initialised at 05:32:08 while my
    client held the token; (b) between 05:33 and 05:40 this boot logged ≈800 aie2_alloc_resource … ret -19 failures at ~2/s
    from clients that retry — if that is the two-client probe, the retry loop is worth bounding, since each refusal is 3 kernel
    lines and it is indistinguishable in journalctl from a real client storm.

  4. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Engine side of this, measured on strixhalo (not a fix for the driver half — this only stops our processes
    from being the second context).

    The shipped front door had no cross-process claim on the array at all. 1bit serve -m <q4nx model dir> --device npu runs in process (app/unified.cpp), and that route never took the flock on
    /tmp/1bit-npu-device.lock that forward-serve has taken since engine#612 — while Lemonade's onebit backend
    runs exactly 1bit serve -m <model dir> --port N. So the two-context shape this issue describes was reachable
    by two of our own backends, with no second runtime involved. Neither serve in the 03:46 evidence has a
    device-lock line, because on that route there was no lock to take.

    engine#1094 (cf48648, branch 1bit/npu-inproc-device-lock) adds it: exclusive, taken before the model is
    opened, held for the process's life, NPU_NO_DEVICE_LOCK=1 still bypassing it. Rows, one npu-hold ticket,
    48 s, same dx route and the same shipped c25 kernel set:

    arm result
    BEFORE, shipped c25 payload, lock held elsewhere ready in 653 ms — walked past the held lock
    AFTER, patched, lock held elsewhere waits on the lock, never opens the model
    PAIR, two patched serves at once A ready in 610 ms, B waits → one context, one dispatch at a time
    CONTROL, patched, lock free lock acquired, ready in 586 ms
    counters amdxdna ERROR 2410 → 2410, TDR 0 → 0

    So after this, the residual risk for the engine is exactly the one your probe isolates: a foreign context
    (a runtime or build that does not take the file, including our own two one-shot tools) overlapping ours. That
    part stays yours: exclusive=false on a shared partition is the driver's call to make, and the engine cannot
    serialise a process that never announces itself. The knob the engine could offer if you want the reverse test
    is NPU_NO_DEVICE_LOCK=1 — it reproduces the unprotected shape on demand with two of our serves.

  5. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Revised: exclusivity is per client, not per context — and 0011 as installed was measured regressing a single-client route

    pi-onebp's row changes the shape of this fix, and it is now incorporated (PR #1085 carries the revision; pi-prs holds it
    until it does — done, head 3e803a1).

    What the per-context version did wrong: on the installed 169C46E2… (0007+0008+0009+0010+0011) a single client
    holding several contexts cannot load — ZR1 per-op forward (4 designs = 4 contexts) creates ctx #1, then ctx #2 fails
    code 102 / No such device, kernel aie2_alloc_resource: Allocate AIE resource failed, ret -19, 3/3. That route ran
    600 tokens / 67 200 submits with 0 TDR on the shared partitions (measured on 56AB9475). So sharing within one client
    is not a defect — sharing across clients is.

    The revision: alloc_requests.owner (= hwctx->client, one per open file) → partition_node.owner;
    allocate_partition() only considers partitions whose owner matches; get_free_partition() untouched. Consequences:

    case before (no patch) per-context 0011 (installed) client-scoped (this revision)
    two clients, each dispatched once wedge 3/3 second refused, first fine (k74 proof #1) second refused, first fine
    one client, several contexts (per-op route) works refused on ctx #2, 3/3 (pi-onebp) works (shares its own partition)
    one client, one context works works works
    holder exits, fresh client n/a works (k74 proof #2: hwctx_num 1→0 in 2 s) same path, unchanged

    Verification here: git apply --check clean on the pin alone and after 0001+0002; patched sources byte-identical
    (cmp) to the built tree; rc 0, no warnings. Fingerprints, both recorded:

    • repo series pin + 0001 + 0002 + 0003: FA680E5F8334570CA318449
    • the installed TDR stack 0007+0008+0009+0010 + client-scoped delta: 349FDC99CADC56900E0249A
      (~/.local/bin-free delta: ~/wt/xdna-tdr-recover/patches/0011v2-accel-amdxdna-partition-exclusivity-per-client.patch,
      applies on top of the installed 0011 sources)

    Owed before this can ship: the two proofs again on the client-scoped build plus pi-onebp's multi-context row loading
    (a client that cannot create its second context is the failure this revision exists to prevent), then pi-onebp's ZR1
    device rows re-measured. Note for whoever runs the box meanwhile: the module currently loaded (169C46E2…) is the
    per-context version, so multi-context clients are expected to be refused until it is replaced or rolled back to
    646FFC30….

  6. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to the last line of my previous comment, one minute later: the box is no longer running the per-context build. /sys/module/amdxdna/srcversion is back to 646FFC305CAFF8F9BD736FF (the updates/amdxdna.ko file is the 14 059 033-byte pre-0011 backup, mtime 05:49:42; the journal shows initializations at 05:49:20 / 05:49:36 / 05:49:55). So pi-kernel-74 already rolled the per-context version back after pi-onebp's row, multi-context clients load again, and the cross-client wedge is the current (pre-existing) state until a client-scoped build is installed. Neither of the two fingerprints above has run on hardware.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Independent third case on the installed per-context 169C46E2BB5F58ADCD5C1EB, from the engine side, measured
    2026-11-05 05:43 in one npu-hold ticket (before pi-kernel-74 rolled back to 646FFC30… at ~05:49):

    A single-context route is not affected. 1bit serve -m <q4nx dir> --device npu on the private dx route
    (one hwctx, one design per layer) created its context and loaded four times on 169C46E2 — ready in 653 / 610 / 586 ms, plus a second serve that was made to wait on the engine's device lock and never opened a context — and the
    module added zero amdxdna ERROR lines and zero TDRs in those 48 s (2410 → 2410, 0 → 0). So on the per-context
    module the failure is specifically a second context, not "any NPU load": it matches pi-onebp's 4-context ZR1
    row (ctx #1 OK, ctx #2 code 102 + ret -19) and it is evidence for the per-client scope over the
    per-context one — the dx route's own single context and the multi-context per-op route differ only in how many
    contexts one client asks for.

    What this does not cover: I did not test two clients each holding a context on 169C46E2 — my run was exactly
    the run that now serialises them (engine#1094), so by construction only one context existed at a time. That row
    (one client, several contexts; and two clients, one context each, on a per-client build) still belongs to whoever
    holds a device ticket on the next test module.

  8. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    0011v2 (per-client exclusivity, 349FDC99…) restores the multi-context client that 0011 broke — measured on the same client, same container, same ELFs

    Following my row above (0011 169C46E2 refuses a single client's second context), pi-kernel-74 has 0011 v2 (exclusivity scoped
    per client instead of per context) loaded on strixhalo as 349FDC99CADC56900E0249A. Same client as before — the engine's
    model-generic per-op forward (1bit forward-serve), which derives four designs and holds eight hardware contexts (4 prefill

    • 4 _m16 decode) for ZR1-1.5B — one npu-hold ticket, bare serve, device idle before, SIGTERM+wait teardown:
    module client hwctx created result
    shipped 646FFC30… (0007+0008+0009+0010, exclusive = false) per-op forward 8 loads, decodes; 600-token row = 67 200 submissions, 0 TDR (#1017)
    0011 169C46E2… (exclusive = true, per context) per-op forward 1 of 4 attempted refused at ctx #2, aie2_alloc_resource … ret -19, 3/3
    0011 v2 349FDC99… (per client) per-op forward 8 loads, decode family: 4 role(s) at M=16, /v1/completions → 200, 8 tokens, and 0 kernel aie2* lines in my ticket window (06:35:09–06:35:30)

    I8Ctx::init_elf ×8 / full ELF ok ×8 in the serve log is the count that matters: eight contexts created by one client, which is
    exactly what per-context exclusivity forbade and what per-client scoping allows.

    So the two rows are now complementary rather than contradictory: the wedge fix needs per-client scope, and with it the
    model-generic route keeps working.
    For the release notes, the honest sentence is "one client at a time on the array, and a
    client may hold as many contexts as it needs"; the per-context version would have made this whole route unloadable.

    Provenance: binary da845311… from origin/main bd7d451a, module 349FDC99… before and after the run, container
    ~/models/npu/ZR1-1.5B-npu-q4km-v2 (plan.json, 197/197 q4_1), kernels ~/models/npu/zr1-elfs (8 ELFs). I have not tested v2
    against the wedge scenario itself (two clients dispatching) — that is the driver lane's proof row, not mine; my row only says
    v2 does not regress the single-client multi-context case.

  9. bong-water-water-bong commented on Nov 5, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Engine half merged: #1094 landed on main as ad47253 (verified from the tree, not the PR page —
    app/unified.cpp:477 now takes take_npu_device_lock(1), and app/serve.cpp refuses --npu-streams on the
    in-process/dx routes). From this build on, two 1bit processes cannot be two contexts on the array: the second waits at
    the lock and takes over when the first exits (measured: takeover ready in 1481 ms).

    The remaining cross-context risk is exactly the foreign-client one this issue is about — a runtime that never takes the
    file — which stays yours.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions