Skip to content

Bump mlir-air to 17e5730; superkernel lowering by mlir-air's passes - #198

Merged
erwei-xilinx merged 16 commits into
mainfrom
superkernel-air-lowering
Nov 21, 2026
Merged

erwei-xilinx merged 16 commits into
mainfrom
superkernel-air-lowering

Conversation

@erwei-xilinx

Copy link
Copy Markdown
Collaborator

Bumps mlir-air from 74ec2b7 to 17e5730. The superkernel lowering then hands most of its own rewrites to mlir-air. Builds on #197, whose three commits are the first three here.

mlir-air changes this relies on:

What moves out of superkernel.py (about 300 lines net):

  • Copies between two L2 buffers in the segment, including ones whose destination moves with a phase loop, are left to aircc's air-dma-to-channel. _lower_edges keeps only whole-buffer reuse and the phase packets.
  • _in_place is gone. A block a kernel loads from a channel and stores unchanged into its own L1 buffer becomes a single copy before the schedule runs, through raise_load_buffer_to_tensor, fold_extract_slice_of_insert_slice and forward_copy_into_destination. During that transform the kernel's own buffers and the channel placeholders are marked llvm.noalias, because forwarding needs to know that they do not overlap. A copy between two L1 buffers is left to aircc, which lowers it to the core's linalg.copy. The part of _in_place that remained was also wrong for a neighbour's shared L1 buffer: it pointed one tile's DMA at the neighbour's memory. The new send_shared test covers that case.
  • _forward_private_vectors becomes upstream transform.memref.erase_dead_alloc_and_stores on the herds. Without #2459 that op would erase buffers that a core fills and then sends.
  • _place (first fit) becomes air-place-herds, run on the merged module so that _pin_l2 and the packet hop still see each herd's column. Herds that give at keep their place.

One front-end change: inside a herd, a core reads its index with air.herd_id(axis) rather than tl.program_id. tl.program_id is the Triton grid, which lowers to air.launch; using it inside a herd is now an error. The Gemma4 decode's proj_core and the tests are updated.

New tests:

  • test_superkernel.py: two_halves (two phases write the two halves of one on-chip tensor) and send_shared (a herd sends a neighbour's shared L1 buffer). The program-id and herd-id error cases are covered too.
  • test_superkernel_lowering.py: forward_copies, forwarding (through the herd transform script, including a buffer that is sent), and placement.

Checked on npu2 (Strix) with the published 17e5730 wheel:

  • test_superkernel.py, test_superkernel_lowering.py and the Gemma4-E2B superkernel decode gate pass.
  • aircc's output for every superkernel test and for the decode matches what a local build of the same mlir-air changes produced. Against main, the outputs change only where the lowering does: bcast and multicore get the placer's herd positions, and their NPU results are still correct.
  • The full CI steps, including the pr-scope LLM gates, pass. The iGPU oracle of decode-vs-prefill returned zeros once (on main, hetero did the same once); three reruns passed.
  • Decode steady-state dispatch, alternating runs: position 0 is 33.43–33.46 ms against 33.55–33.68 ms on main, and position 2047 is 34.88–34.91 ms against 34.97–34.99 ms.

🤖 Generated with Claude Code

erwei-xilinx and others added 15 commits November 19, 2026 11:04
The merged segment's copies were numbered by hand. mlir-air's
air-renumber-dma does it, and numbers the channel ops too, as aircc does
again at its end; aircc's output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r_to_scalar

_scalar_transfers turned a herd's vector reads and writes of a 0-d
buffer into a scalar load and store. mlir-air's
transform.air.convert_size1_vector_to_scalar does that for every size-1
vector and folds the broadcasts and extracts it leaves; its pattern
driver also folds the herds' constants. aircc's output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emref_memory_space

_retype_herd_args gave herd block arguments their operands' types, and
_respace_views gave the views of a core's own L1 buffer its memory
space. mlir-air's transform.air.override_memref_memory_space, targeted
at the herds, does both; it runs in the same transform script as the
size-1 vector rewrite. The merged AIR is unchanged.

The air-override-memref-memory-space pass would do the same, but its
pattern driver runs over the whole module and folds the segment's
constants out of its loops, which changes what aircc makes of them (the
proj16 test hung).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up Xilinx/mlir-air#2458, #2459, #2460 and #2461, which the
superkernel lowering now relies on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…annel

_lower_edges turned each L2-to-L2 copy into a channel of its own. With
mlir-air's air-dma-to-channel lowering such copies, the plain ones stay
as copies; _lower_edges keeps the whole-buffer reads it forwards, the
phases' packet outputs and the copies whose destination moves with a
loop around cores. The test's IR check accepts either form. Needs an
mlir-air with that lowering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nsor

Where the phases' output lands in the tensor moves with the phase loop,
which no case covered: _lower_edges takes that copy's get out of the
loop into one of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…c too

_lower_edges took the get of a copy into an on-chip tensor whose place
moves with a loop around cores out into a loop of its own. aircc does
the same with the copy left in the loop: for two_halves the runtime
sequence and the device are the same once names are set aside. The
loop's helpers (_get_loop, _trips, _static) go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A block a kernel takes from a channel into its own L1 buffer lowered to a
copy into a buffer of the load's and a copy, by the core, into the L1
buffer, which _in_place merged after the fact. Before the schedule, the
kernel's loads are now raised as AIR's schedules raise them and the
pair is forwarded into one copy (mlir-air's
air.forward_copy_into_destination), so the channel's DMA writes the L1
buffer from the start. _in_place has nothing left to do there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…buffer

With a kernel's channel loads forwarded before its schedule, no copy
between a channel's buffer and an L1 buffer is left for _in_place to
merge: the code that did (_l1_copies and its helpers) goes, and its unit
test is replaced by one of _forward_copies. _in_place keeps turning DMAs
between two L1 buffers into a channel on the L1 buffer or a core's copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_in_place turned a herd's DMA between an L1 buffer and a buffer of the
kernel's own into a copy by the core when a channel could not take its
place. mlir-air's air-dma-to-channel now lowers such a DMA to the core's
copy itself, so the DMA stays; the device differs only in where a view
is computed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What was left of _in_place moved a channel's put or get from a buffer of
a herd's kernel to the L1 buffer it copied that buffer from or into. For
a neighbour's L1 buffer that is a DMA of one tile on another's memory,
which aircc rejects ("'aie.use_lock' op can only access a lock in the
same tile"); left alone, the copy is the core's (aircc's
air-dma-to-channel) and the channel stays on the herd's own buffer. A
kernel's own L1 buffers no longer get such copies (_forward_copies).

The new send_shared case sends a neighbour's L1 buffer through a
channel; it fails with _in_place and passes without it. _in_place's
helpers (_view, _within, _contiguous, _move_before) go too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A herd's kernel read its core's index in the herd as tl.program_id. That
is the superkernel's launch grid, the same as in any Triton kernel; a
core's place in a herd is AIR's (air.herd tile (%x, %y)), so it gets an
op of its own, air.herd_id(axis), 0 the column and 1 the row, only in a
herd's kernel. A herd's kernel that reads tl.program_id is rejected.

The lowering is the same: the merged AIR and aircc's output do not
change. The decode's projection cores and the tests use air.herd_id;
two cases check the errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_and_stores

The herds get memref's transform.memref.erase_dead_alloc_and_stores in
place of _forward_private_vectors. It needs AIR's channel ops to declare
their memory effects, or it erases buffers that cores send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_place's first fit gives way to AIR's placer, run on the merged module
before the passes that read a herd's column. Pinned herds keep their
corners and are still checked for overlap; the placer only runs when a
herd has no `at`, so a design that pins every herd does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lias while forwarding copies

air.forward_copy_into_destination now forwards a copy only when its
source and destination provably do not overlap. A core's own L1 buffer
and the placeholder standing for a channel overlap no other argument;
_forward_copies says so with llvm.noalias for the duration of the
transform. The merged AIR and aircc's outputs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 00:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the migration of superkernel lowering to upstream AIR passes.

No open issues 🎉

What changed in this PR

Updates mlir-air to 17e5730 and builds on #197 by moving more superkernel lowering from custom Python rewrites to upstream AIR passes.

Changes:

  • Delegates copy lowering, buffer cleanup, and automatic herd placement to AIR.
  • Introduces air.herd_id(axis) for core coordinates and rejects tl.program_id inside herd kernels.
  • Adds regression coverage for phased writes, shared L1 transfers, forwarding, placement, and ID validation.
File Description
utils/​mlir-air-hash.txt Updates the AIR commit and wheel timestamp.
scripts/​test_superkernel.py Migrates core IDs and adds transfer and validation cases.
scripts/​test_superkernel_lowering.py Tests upstream forwarding and placement behavior.
examples/​gemma4_e2b_q4nx/​superkernel_decode/​wave.py Uses herd coordinates in the projection kernel.
amd_triton_npu/​language/​air/​superkernel.py Defines herd_id and documents ID and placement semantics.
amd_triton_npu/​language/​air/​__init__.py Exports herd_id.
amd_triton_npu/​backend/​superkernel.py Replaces custom lowering and placement with AIR passes.
amd_triton_npu/​backend/​superkernel_jit.py Extracts herd IDs, rejects program IDs, and retains explicit-pin validation.

Review effort: Balanced

@erwei-xilinx
erwei-xilinx added this pull request to the merge queue Nov 21, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 21, 2026
# Conflicts:
#	amd_triton_npu/backend/superkernel.py
@erwei-xilinx
erwei-xilinx added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 1cf96d0 Nov 21, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants