Repository navigation
Bump mlir-air to 17e5730; superkernel lowering by mlir-air's passes - #198
Merged
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
🟢 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 rejectstl.program_idinside 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
enabled auto-merge
November 21, 2026 00:43
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
air-dma-to-channellowers L2-to-L2 copies in a segment and L1-to-L1 copies in a herd. It also addstransform.air.forward_copy_into_destination.air.channel.put/getdeclare their memory effects.air-place-herdsfails when a herd does not fit.convert_size1_vector_to_scalarleaves masked and out-of-bounds transfers alone.What moves out of
superkernel.py(about 300 lines net):air-dma-to-channel._lower_edgeskeeps only whole-buffer reuse and the phase packets._in_placeis 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, throughraise_load_buffer_to_tensor,fold_extract_slice_of_insert_sliceandforward_copy_into_destination. During that transform the kernel's own buffers and the channel placeholders are markedllvm.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'slinalg.copy. The part of_in_placethat remained was also wrong for a neighbour's shared L1 buffer: it pointed one tile's DMA at the neighbour's memory. The newsend_sharedtest covers that case._forward_private_vectorsbecomes upstreamtransform.memref.erase_dead_alloc_and_storeson the herds. Without #2459 that op would erase buffers that a core fills and then sends._place(first fit) becomesair-place-herds, run on the merged module so that_pin_l2and the packet hop still see each herd's column. Herds that giveatkeep their place.One front-end change: inside a herd, a core reads its index with
air.herd_id(axis)rather thantl.program_id.tl.program_idis the Triton grid, which lowers toair.launch; using it inside a herd is now an error. The Gemma4 decode'sproj_coreand the tests are updated.New tests:
test_superkernel.py:two_halves(two phases write the two halves of one on-chip tensor) andsend_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), andplacement.Checked on npu2 (Strix) with the published 17e5730 wheel:
test_superkernel.py,test_superkernel_lowering.pyand the Gemma4-E2B superkernel decode gate pass.bcastandmulticoreget the placer's herd positions, and their NPU results are still correct.decode-vs-prefillreturned zeros once (on main,heterodid the same once); three reruns passed.🤖 Generated with Claude Code