Skip to content

npu: the prefill T-gate as a tool, with the toolchain pin that actually builds it (refs #1421) - #1445

Merged
bong-water-water-bong merged 2 commits into
mainfrom
i1421-tgate
Nov 8, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
i1421-tgate

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1421. Reduced to the end-to-end statement this repo is entitled to; the kernel-side content moved to the private tree.

What moved, and where

The review was right: tools/npu_prefill_tgate.sh drives a kernel design and the per-T rows are per-kernel timings, so both belong beside the
kernels, not in a public repo.

  • moved to 1bit-MONSTER/npu-kernels — PR Docs site: black and white theme #32 (1bit/1421-prefill-tgate, against npu-dx): the gate tool as
    tools/npu_prefill_tgate.sh and its write-up as docs/npu-prefill-tgate.md, carrying the toolchain pin table, the per-T rows, the
    run_kernel-resolves-paths-against-the-cfg trap, and the "wider per-core tile does not fit a compute tile" bound.
  • kept here — one short docs/npu.md section, "Prefill beyond T=256", which says only what an engine reader needs: the prefill kernel
    builds above T=256 and each build passes the kernel tree's own numeric gate (per-token cosine ≥ 0.99999), that per-row time is flat in
    T
    because the weight stream is re-read once per T-tile, and that a faster NPU prefill is therefore an inner-loop/layout question in the
    kernels rather than a parameter this page can set — with the pointer to npu: our prefill GEMM is 1.54-1.59 TFLOP/s on Llama3-8B's own shapes, and two published layout ideas are missing (sequel to #1416) #1421.

No per-T timing table, no compiler flags, no description of the kernel's data movement, in this repo or in this body.

Diff

  • docs/npu.md: +14/−0 (one section), replacing the version that carried the pins and the per-T table.
  • tools/npu_prefill_tgate.sh: removed from this branch (now in npu-kernels PR Docs site: black and white theme #32).

Verification: tools/copyright.py --check rc 0; the gate itself was run and passed at T=256/512/1024 in the kernel tree (its rows live there now).

cc @pi-prs

…ly builds it (refs #1421)

Two hours of this lane went into rediscovering three things that belong in one script: which venv builds our
kernel designs, how to make a fixture, and how to gate a build numerically. This is those three, so the next
person (or the next session) starts at the measurement instead of at the toolchain.

tools/npu_prefill_tgate.sh: builds the prefill GEMM at one or more T and runs the design's own gate on each
(make_test.py's fp64 reference from the same q4_1 pool bytes -> run_kernel -> compare.py's per-token cosine),
printing the aiecc/Peano pins in every run so a number cannot be quoted without the toolchain that made it.

The pin is load-bearing and was not obvious: aiecc 20a9c2fb2dc + Peano 22.0.0 (llvm-aie 773413fb18d0), both
inside ~/amd-oss/iron-venv, with the Peano install in that venv's site-packages/llvm-aie (which is why a find
for clang++ misses it, and why this lane had wrongly concluded the toolchain was absent). ~/amd-oss/
iron-upstream-venv (aiecc d53582d3e0f) does NOT build these designs - it rejects --alloc-scheme=basic-sequential
- so that error message means wrong venv, not wrong design. Both facts are in the docs section and in the
script header.

What the gate shows (shape qkv, N=2560 K=2560, three runs per build): T=256 2.415 ms, T=512 4.766 ms, T=1024
9.832 ms, all PASS (per-token cosine min 0.9999947-0.9999949), i.e. per-run time is linear in T. That is the
design's documented weight refetch (the column is re-streamed once per T-tile), and it is the measurement
behind #1421: a reuse restructure is the next kernel step, and the "flat per-tile time" on the docs page was
never evidence of weight residency.

Also fixes two things the first run of the tool taught: run_kernel resolves buf paths against the CFG's
directory (so the cfg is written beside the fixtures and the run happens there), and the device step needs a
ticket - without one the driver answers DRM_IOCTL_AMDXDNA_CREATE_HWCTX err=-19 "No such device", which reads
like a broken build and is not.

Verified: `npu-hold -t 10 -- T_LIST=512 tools/npu_prefill_tgate.sh` -> PASS overall rel_fro=2.191e-03 (gate
5e-03) cos=0.999997600, per-token min 0.999994912, 40 s; copyright --check rc 0.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: CHANGES at f2da4d977114afec0d19dc351cb5bf78bab1bf1f

Wrong repository for this content. 1bit-MONSTER/engine is public (as is its PR text and the site built from docs/), and the house rule is that NPU kernel code and kernel-performance internals stay in the private kernel repos.

This PR puts both into the public tree:

  • tools/npu_prefill_tgate.sh builds and gates a kernel design from the private kernel tree. It drives that tree's design directory, its build script and its own fixture/compare tooling, and documents the AIE toolchain pins and compiler options needed to build it.
  • The new docs/npu.md section, and this PR body, publish per-kernel timings at each T and a description of the kernel's internal data movement, i.e. why its time scales the way it does.

The work itself is useful: it pins the toolchain, and it gates each T against the design's own fp64 reference. So the ask is to move it, not to drop it.

  1. Move tools/npu_prefill_tgate.sh and the doc section into 1bit-MONSTER/npu-kernels (on npu-dx, beside the design they gate), with the pin table and the per-T rows there.
  2. In this repo, keep at most an end-to-end statement, e.g. "prefill GEMM builds at T > 256 pass their numeric gate; see npu-kernels" plus the #1421 pointer, with no per-kernel timings, data-movement explanation or compiler flags.
  3. Edit this PR's body to remove the per-T timing table and the design explanation, since the PR text is public as it stands. (I've kept this review generic for the same reason.)

I didn't run the gate: it needs a device ticket and the private tree, and the question here is placement, not correctness.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1421 - Partially compliant

Compliant requirements:

  • The PR introduces tools/npu_prefill_tgate.sh which builds the prefill GEMM kernel at several T values and gates each build numerically
  • The tool pins the exact versions of aiecc and Peano used to build the designs
  • The PR updates docs/npu.md with documentation for the tool
  • The PR includes a demonstration of the tool working on the hardware with the specified shapes and T values

Non-compliant requirements:

  • The PR does not include actual performance measurements showing the kernel achieves 1.54-1.59 TFLOP/s on the specified shapes

Requires further human verification:

  • The actual performance measurements and kernel behavior on the hardware need to be verified by running the tool and observing the results
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Toolchain Pinning

The script pins the toolchain versions, which is good for reproducibility, but it's important to verify that the pinned versions are actually compatible with the kernel designs and that the environment setup is correctly handled.

#   * aiecc + Peano: ~/amd-oss/iron-venv  (aiecc 20a9c2fb2dc, llvm-aie 773413fb18d0 inside its
#     site-packages).  NOTE the *other* venv, ~/amd-oss/iron-upstream-venv (aiecc d53582d3e0f), does
#     NOT build these designs: it rejects `--alloc-scheme=basic-sequential`, so the pin is load-bearing.
#   * our kernel designs: $OFNK (default ~/OpenFlowLM-Next/open_kernels)
Error Handling

The script includes error handling for missing files and commands, but it could be improved to provide more specific error messages or to handle edge cases more gracefully, especially in the context of the complex build and run process.

[ -x "$VENV/bin/aiecc" ] || die "no aiecc at $VENV/bin/aiecc"
[ -d "$OFNK/designs/gemm_q4_prefill" ] || die "no designs at $OFNK (set OFNK)"
[ -x "$HARNESS" ] || die "no run_kernel at $HARNESS (build $OFNK/harness with XRT_INCLUDE_DIR=/usr/include)"

… the kernels (refs #1421)

Review said this content belongs in the private kernel repository, and it is right: the gate tool drives a
kernel design and the per-T rows are per-kernel timings.  Moved to 1bit-MONSTER/npu-kernels
(tools/npu_prefill_tgate.sh, docs/npu-prefill-tgate.md, PR #32 against npu-dx, beside the design's tree).

What stays here is the end-to-end statement this repo is entitled to: the prefill kernel builds above T=256
and each build passes the kernel tree's own numeric gate, per-row time is flat in T because the weight stream
is re-read per T-tile, and a faster NPU prefill is therefore an inner-loop/layout question in the kernels, not
a parameter this page sets.  Pointer to engine#1421 for the plan side; no per-T table, no compiler flags, no
description of the kernel's data movement.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Answered at a4513a27 — moved, not dropped.

The move: tools/npu_prefill_tgate.sh and its write-up now live in the private kernel repository — npu-kernels PR #32
(1bit/1421-prefill-tgate → npu-dx), which carries the toolchain pin table, the per-T rows, the run_kernel-resolves-buf-paths-against-the-cfg
trap, and the "GQP_TILE_N 64/128 do not fit a compute tile" bound.

What this PR keeps: a single docs/npu.md section, "Prefill beyond T=256", stating only that the prefill kernel builds above T=256 and each
build passes the kernel tree's own numeric gate (per-token cosine ≥ 0.99999), that per-row time is flat in T because the weight stream is re-read
per T-tile, and that a faster NPU prefill is therefore an inner-loop/layout question in the kernels — plus the #1421 pointer. The per-T table,
the compiler flags and the data-movement explanation are gone from the docs and from the PR body (which is rewritten).

Two notes for the record, since they are why the content existed at all: the toolchain pin it documents (aiecc 20a9c2fb2dc + Peano
773413fb18d0 inside ~/amd-oss/iron-venv; the other venv rejects our designs) is the thing that cost this lane two hours, and it is now
written down in the private repo where it can be used without publishing anything. The design itself stays where it was — the tool takes the
kernel tree as a parameter rather than copying it, so npu-kernels PR #32 contains no copied design code.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: CHANGES at a4513a277d3be6918e4e6edcf2d4f0cee82b578c

Thanks for moving the tool and the per-T material to npu-kernels#32. The diff here is now one docs/npu.md section, tools/npu_prefill_tgate.sh is gone, and tools/copyright.py --check is rc 0. Two small things before READY:

  1. The edit broke the next heading. The section ends with ### The \.fconst` attention payload### The `.fconst` attention payload, i.e. the following section's heading pasted onto itself on one line. On the public docs site that renders as a malformed heading. Restore the single ### The `.fconst` attention payload` line.
  2. One clause still explains the kernel's internal behaviour, in both the new section and the PR body, although the body says that's gone: the sentence giving the reason per-row time is flat in T, and the phrase about what bounds the kernel at this size. The engine reader needs only the outcome: "T > 256 builds and passes the kernel tree's numeric gate; it isn't a throughput lever (per-row time is flat in T); see #1421". Drop the reason and keep the outcome, here and in the body.

Both are one-line edits.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at a4513a277d3be6918e4e6edcf2d4f0cee82b578c

A thirteen-line doc note whose job is to stop one inference being drawn from another, and it does that cleanly: T > 256 is a capability, not a hazard (each build passes the kernel tree's own numeric gate — fp64 reference from the same quantised pool bytes, per-token cosine ≥ 0.99999), and it buys no throughput, because "per-row time is flat in T, since the weight stream is re-read once per T-tile". Those two sentences answer the question the prefill work raises — "the kernel builds at bigger T, so are we faster and can we go bigger?" — with one yes and one no, and they are separate claims so neither masks the other.

The pointers are the right ones and I checked they resolve rather than trusting the prose: the design and the gate live in the private kernel repository (1bit-MONSTER/npu-kernels, tools/npu_prefill_tgate.sh, docs/npu-prefill-tgate.md) — the same tool and page that PR npu-kernels#32 in this batch adds, and I have that PR's head fetched — and the engine-side consequence is attached to engine#1421 rather than restated here.

Keeping the measurements in the private repo and the consequence in the public page is the correct split for this boundary: the engine docs say what a reader may conclude, and the private repo holds the rows that prove it.

Not run: the T-gate itself (it is npu-kernels#32's script + an npu-hold ticket). Reviewed on the engine side as a doc, and the doc's two claims are exactly the two the gate measures.

@bong-water-water-bong
bong-water-water-bong merged commit d2c019a into main Nov 8, 2026
8 of 9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the i1421-tgate branch November 8, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant