Skip to content

npu: two resident engines need disjoint-array-half kernel sets (per-engine column partition) #656

Closed

Description

@bong-water-water-bong

Split out of #612 (item 1, PR #640). That PR makes two NPU engines possible through a supported opt-in
lock (--npu-streams N); it says nothing good about their throughput, and now it has been measured.

The problem, measured

Two resident engines on whole-array kernel sets lose throughput. strixhalo 2026-10-30, binary
b78868c (-DONEBIT_NPU=ON), both serves on the shared lock (no NPU_NO_DEVICE_LOCK), 8 greedy
tokens, temperature 0, 3 reps per arm, rep 1 dropped, each model measured alone with the other not
loaded, kernels ~/lb/lfm2-npu/kernels_m16:

arm wall (s), mean of 2 measured reps decode (tok/s)
Qwen3-0.6B alone 5.79 1.38
Qwen3-4B alone 25.08 0.32
both at once: Qwen3-0.6B 16.99 0.47 (34.1 % of solo)
both at once: Qwen3-4B 35.61 0.22 (70.4 % of solo)
aggregate 0.41x

Running the two models back to back is 2.4x faster than running them together. The per-token times add
up (0.72 + 3.13 s solo per token = 3.85 s against 4.45 s concurrent, plus ~16 % handoff), which is what
"two whole-array streams share one DMA engine" looks like. The 0.6B pays most (34 % of solo) because it
is latency-bound; the 4B keeps 70 % because its token cost is its own 3.3 GB weight stream anyway.

The same protocol on one model twice, lock bypassed, measured 65.7 % of solo per stream, 1.31x
aggregate
(a88ef00, 2026-10-29) — better aggregate only because both streams stream the same weights.

The arrangement that scaled, and why it is not here

#612's own table has the row: "Two concurrent NPU streams, disjoint array halves — ~100 % of
single-stream speed each, the arrangement that scales"
. The September prototype got there by giving each
stream a disjoint half of the array columns, which also halves per-stream weight reuse; four
full-array streams measured ~24 % each with no aggregate gain, i.e. full-array execution is mutually
exclusive but column-disjoint execution is not.

It cannot be re-run to confirm: the prototype's model is gone and its halved xclbin pair is ABI-stale by
its own header (2026-10-29 pass, #612). So "~100 % each" is a September claim, unverified at any current
pin
— this issue exists to settle it, not to repeat it.

What it would take (smallest build plan)

  1. Kernel side — a half-array ELF family. Rebuild the full_i8_* design family from
    npu/dx/kernels for a 4-column (half) array: same geometry, half the AIE columns per program, so two
    engines' programs occupy disjoint column sets. Nothing else about the model changes: the weights
    (model.q4nx) stay whole, each engine loads its own copy as it does today.
  2. Verify before any model run (lane rule): host-side bounds proof for the rebuilt programs, then the
    existing small-shape CPU-vs-NPU checks (ctest -R npu_q4nx, npu_forward_loader, golden tensors), and
    only then a model.
  3. Lock carries the partition id. --npu-partition {0,1}: take LOCK_EX on
    /tmp/1bit-npu-device.part{N} and LOCK_SH on the whole-device file. That gives exactly the
    semantics wanted: two partitioned engines on different partitions co-exist; two on the same partition
    exclude each other; a full-device (LOCK_EX) run excludes both and waits for them; a partitioned run
    waits for a full-device holder. --npu-streams stays for the no-partition case.
  4. Measure with the same protocol as showcase: one measured heterogeneous demo (2-stream NPU, batched HRX, hybrid) at the current pin #612 (8 greedy tokens, 3 reps, rep 1 dropped, solo then
    concurrent, per-stream and aggregate, pin stamped), on the same pair Qwen3-0.6B + Qwen3-4B so the
    numbers are directly comparable with the 0.41x above. Acceptance: aggregate > 1.0x, and both streams'
    greedy outputs identical to a whole-array run of the same prompt (a partition that changes the answer
    is a bug, not a speedup).
  5. Say what it costs: half-array programs have half the tiles, so a single stream on a partition is
    expected to be slower than solo on the whole array; the win, if any, is aggregate. If step 4 shows
    aggregate <= 1.0x, close this issue with that number and stop claiming the arrangement scales.

Out of scope

Refs #612, PR #640, RFC #639.

Activity

  1. bong-water-water-bong commented on Oct 31, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Triage: enhancement. Split correctly from #612, and the comparison it sets up is sound: the mechanism it has
    to beat is merged (#640 3c2521222, --npu-streams N), the 0.41x aggregate in the body was measured with
    #612's protocol (8 greedy tokens, 3 reps, rep 1 dropped, each model alone first), so a half-array run measured
    the same way will be directly comparable.

    Order of work, and which part does not need the device:

    1. Host-side bounds proof for the half-array programs — no device, no window, and it must come before any
      model run (lane rule), since a 4-column program that reads outside its partition is a wrong answer, not a
      crash.
    2. --npu-partition {0,1} lock semantics (item 3) — plain file locking (LOCK_EX on
      /tmp/1bit-npu-device.part{N} + LOCK_SH on the whole-device file next to the existing
      app/npu_device_lock.h), fully testable on this box with a two-process test that asserts the four
      combinations the issue names: partition/partition co-exist, same partition excludes, full-device excludes
      both, partitioned run waits for a full-device holder.
    3. Item 1's ELF family and item 4's measurement need the NPU — and it queues behind npu: readback can observe stale data after the ERT completion signal; needs a fence or verify-and-reissue #666, because a
      throughput table measured through a readback that can return a short tile is not a throughput table.

    If item 4 lands ≤ 1.0x aggregate, this issue closes with that number and #612's September "~100 % each" row
    stops being repeated anywhere. I would rather see that outcome recorded than the arrangement stay folklore.

    Board row: ~/briefs/TISSUES-BOARD.md (window order: ORCHESTRATOR item 4).

  2. bong-water-water-bong commented on Oct 31, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Status after today's merges (#692 state, 4a58da9b0 pin): not closed — no part of this issue is in the tree.

    Checked rather than assumed, at origin/main 3cddcd6:

    $ git grep -c "npu-partition\|npu_partition\|half-array\|column partition" origin/main -- app/ npu/ docs/ tools/
       (no hits)
    $ git grep -ln "npu-streams" origin/main -- app/ docs/
       app/forward_serve.cpp  app/npu_device_lock.h  app/serve.cpp      <- #640's mechanism, as before
    

    What today's work did not change: #692 is the pb16i weight layout and the sealed multi-instance ELF (context
    switches 386/token → 3, per-launch arithmetic byte-exact). It shortens one engine's token, which lowers the cost
    side of running two engines but does nothing about the mechanism this issue asks for: a half-array (4-column) ELF
    family plus --npu-partition {0,1} so two engines occupy disjoint columns instead of sharing one whole array.
    #672 was a pin bump.

    So the build plan in the body stands unchanged, and so does the acceptance: aggregate > 1.0x for the
    Qwen3-0.6B + Qwen3-4B pair with both streams' greedy output identical to a whole-array run. If item 4 shows ≤ 1.0x,
    this issue closes with that number and the September "~100 % each" claim stops being repeated.

    Ordering note for whoever picks it up: item 2 (the lock semantics) is the only part that needs no device and it is
    still the right first step — LOCK_EX on /tmp/1bit-npu-device.part{N} plus LOCK_SH on the whole-device lock.
    Item 1's ELF family and item 4's measurement need a window, behind #666.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Measured on strixhalo 2026-10-31 23:01-23:03 (Ross kernel lane, record in TROSS-GU-STATE.md 23:10 entry), half-array kernel sets built for Qwen3-0.6B on npu2_4col (4 columns) next to the whole-array set (8 columns), all 16 ELFs x 3 seeds byte-exact against the frozen int8 harnesses (48/48):

    • single launches on a half set cost 1.4-2.0x the whole-array time (QKV_m16 1.682 -> 3.144 ms, GU_m16 2.396 -> 4.751 ms);
    • two half-array contexts never run side by side on this driver/firmware: each takes twice its solo time when the other runs (GU_m16 4.597 -> 9.60 ms, QKV_m16 2.784 -> 5.79 ms), aggregate 0.96x;
    • two Qwen3-0.6B engines at once (--npu-streams 2, greedy text identical in every arm): whole-array sets 1.15x aggregate vs one engine, half-array sets 0.88x of one whole-array engine.

    By this issue's own acceptance rule the half-array arrangement does not pay on the current amdxdna/firmware (no spatial partitioning); closing with that number. Re-open if a firmware with spatial partitioning appears. The generator with --device npu2|npu2_4col and build_family.sh are in npu-kernels npu/arena/HALF/.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions