AIEX Passes
-aie-assign-runtime-sequence-bd-ids¶
Assign IDs to Buffer Descriptors Configured in the Runtime Sequence
Gives each aie.dma_bd of an aiex.dma_configure_task in a runtime
sequence a buffer descriptor id on its tile, in program order, and takes
a task's ids back once it is known to have finished, for later tasks to
reuse. The sequence must have one block with straight-line execution.
The pipeline unrolls constant loops and folds constant branches before
this pass. The allocator rejects runtime-valued scf ops.
An await (aiex.dma_await_task, aiex.npu.sync, aiex.npu.dma_wait)
takes the oldest completion token on its channel, which proves that push
and every push queued ahead of it finished. aiex.dma_free_task releases
a task's ids without waiting; reusing ids a free released with nothing
proving the task finished is a warning (warn-unsafe-bd-reuse), as is an
aiex.npu.dma_memcpy_nd that reprograms an id an earlier copy on the tile
may still have in flight.
An await on an output also finishes the input pushes its
#aie.consumed_by proofs cover; a task carries its allocation's proofs
through alloc.
A sequence that ends with another device's PDI loaded leaves that array to
the next dispatch, whose proofs count on a clean start, so the stretch
since the latest load must balance under that device's proofs: no more
through an input than its output proves taken, the output not partway
through a granule, no other traffic on their channels, and transfer sizes
the pass can count. Otherwise the aiex.npu.load_pdi is an error.
Before allocating, the pass checks each channel's completion tokens (an
await with no token to take would deadlock the host) and task queue
(enforce-queue-depth).
defer_completion on an await permits independent task triples to share
a completion boundary. The allocator schedules compatible single-BD,
single-start tasks within its current descriptor and queue limits. With
chain-tasks, it links tasks on the same channel into chains that fit.
It may reorder starts across channels and delay marked waits. The first
unmarked await closes the group, including its task. Another operation or
an ineligible triple ends the group before that operation. Every group
transfer completes before the next operation outside the group.
aiex.dma_await_task defines the producer's whole-group independence and
progress contract. Tasks with explicit IDs, repeats, locks, or additional
handle uses remain unchanged.
Options¶
-chain-tasks : Combine compatible tasks across deferrable awaits into chains that fit the available descriptor IDs.
-enforce-queue-depth : Insert an aiex.npu.maskpoll before any dma_start_task that could push onto a full DMA task queue, so the sequence waits for a free slot instead of racing on drain timing. On by default: the stall only happens where the DMA cannot drain ahead of the pushes, which is exactly where the alternative is a dropped transfer. Targets that report no pollable occupancy register fall back to warning.
-warn-unsafe-bd-reuse : Warn when a BD id released by aiex.dma_free_task without any completion guarantee is later reused on the same tile, or an aiex.npu.dma_memcpy_nd reprograms an id an earlier copy may still have in flight. On by default; disable when completion is guaranteed through the compute core or another tile, which the runtime sequence cannot see.
-warn-unreleased-transfers : Warn when a straight-line runtime sequence leaves DMA transfers neither awaited nor freed. Completion established indirectly through computation or other channels may not be visible.
-reclaim-bds : When a tile runs out of BD ids, take them back from a started task that was never released and is not started again, instead of failing: one already proven finished (by an await, a poll or a consumed_by proof), or else, inserting an aiex.npu.maskpoll that proves it finished, one on a channel whose status can be polled that waits on no lock a later task releases. Emits a remark for each inserted poll. Off by default: the poll hangs if the task's completion depends, through a core or another tile, on a push issued after it.
-aie-cert-verify¶
Verify CERT ordering/placement legality invariants
This pass checks the firmware-imposed legality invariants on cert operations. It performs no IR mutation; it only emits diagnostics for illegal cert programs.
The uC (microcontroller / CERT group) of a cert op is the group_id of
its nearest enclosing cert.attach_to_group, or 0 if the op is at device
level (not inside any cert.attach_to_group).
-aie-coalesce-control-packets¶
Merge adjacent control-packet writes
Combines adjacent writes with consecutive addresses and matching destinations and header settings inside ordinary-write intervals. The merged payload stays within one aligned four-word line.
-aie-create-cores¶
Create CoreOp, MemOp, and FlowOp of AIE dialect
Lower toplevel 'call' operations with implicit data movement into aie.core, aie.mem, and aie.flow operations with explicit data movement. The tile tile associated with the operations is inferred based on the aie.x and aie.y attributes of the call operation. e.g.:
func.func @aie_task(%arg0: memref<256xi32>, %arg1: i32) -> () {
...
return
}
%a = constant 0 : i32
func.call @aie_task(%buf, %a) { aie.x = 1, aie.y = 1 } : (memref<256xi32>, i32) -> ()
%0 = AIE.tile(1, 1)
%1 = AIE.buffer(%0) : memref<256xi32>
%2 = AIE.buffer(%0) : memref<1xi32>
%c0_i32 = constant 0 : i32
%5 = AIE.core(%0) {
...
}
-aie-create-locks¶
Generate physical lock ops from logical lock (token) ops
Tokens represent high-level buffer synchronization through a sequence of pipeline stages. This pass lowers token operations into physical aie.lock operations.
-aie-ctrl-packet-infer-tiles¶
Infer aie.tile ops from aiex.control_packet addresses
-aie-ctrl-packet-to-dma¶
Deliver control packets with DMA tasks
Streams unicast control packets through their column's control channel. A multicast uses the allocation symbol in its overlay declaration. Consecutive packets to one destination go in one transfer where the target supports it. Each transfer has one buffer descriptor. The descriptor ends its stream packet; the switches route each stream packet by its first header.
Each batch uses one configure/start/await triple. chain-bds permits
chains on one channel for the same destination or independent writes.
parallel-shims permits independent
destinations to share completion. The descriptor allocator owns queue
capacity, descriptor IDs, scheduling, and chain formation.
The shared packet interval contract supplies independence and delivery boundaries. Hardware barriers and other runtime operations complete every preceding transfer. Compiler-only barriers retain packet order but permit consecutive packets with the same destination to share a transfer. The pass closes a preceding deferred DMA group before replacing a packet or erasing a packet barrier.
Distinct multicast routes may share completion when their destination lists are disjoint across the entire interval. Overlapping multicast routes require separate completion, including nonadjacent routes. A multicast and unicast require separate completion unless their destination words are disjoint within an ordinary-write interval. These permissions end at an interval boundary when the interval contains multicast packets. The control overlay must deliver these transfers without application interference. This pass does not analyze application execution or routes.
Options¶
-chain-bds : Permit allocation to chain consecutive transfers on one shim channel
-parallel-shims : Permit independent shim channels to share a completion boundary
-aie-decompose-large-dma-bd¶
Decompose oversized non-contiguous ND DMA transfers
Splits aiex.npu.dma_memcpy_nd ops and task-path aie.dma_bd ops (inside
aiex.dma_configure_task / aiex.dma_configure_task_for) whose constant
ND wrap/stride encoding exceeds the hardware buffer-descriptor field limits
(and that cannot be linearized because the access is non-contiguous) into
one or more hardware-legal ND transfers that move exactly the same data.
On the task path, sub-patterns are linked with aie.next_bd blocks inside
the configure region; bd_id / next_bd_id are left for later passes to
assign. Past the channel's task-queue depth, or when they need repeat
counts of their own, each becomes a single-BD task instead; only the last
issues the token, and their starts are interleaved with the starts issued
alongside them. A task-path descriptor may give more than 4 dimensions if
all are constant; ones that do not fold are split into a task per index.
See "Running Out of Buffer Descriptors" in
programming_guide/section-2/section-2d/DMATasks.md.
Two techniques are used: dimension factoring (split an oversized dimension of size N=a*b across a free dimension slot) is preferred, falling back to slicing an oversized dimension into ceil(N/limit) sub-transfers with adjusted offsets. Contiguous oversized patterns are left untouched; they are handled by canonicalization to linear mode.
-aie-dedup-ctrl-packet-multicast¶
Send the control packets a multicast's tiles share once
Replaces equal per-destination prefixes inside ordinary-write or independent
action intervals. Each destination retains its action order and multiplicity.
The overlay declares destination groups in aie.ctrl_pkt_multicast.
DMA lowering owns delivery ordering and completion.
-aie-dma-tasks-to-npu¶
Lower configured DMA tasks to NPU instructions
-aie-dma-to-npu¶
Lower runtime-sequence DMA operations to NPU register writes
Lowers aiex.npu.dma_memcpy_nd, aiex.npu.dma_wait, RTP and buffer
descriptor writes, and aiex.npu.push_queue to register writes and syncs.
Every path's pushes and syncs meet here, so the pass checks two things
on all of them: it guards task-queue depth (enforce-queue-depth), and
it rejects a runtime sequence that ends with a task-completion token
outstanding on a channel some sequence of the device awaits. Such a token
outlives the command, and the next command's await on that channel takes
it and returns before its own transfer has finished.
Options¶
-enforce-queue-depth : Insert an aiex.npu.maskpoll before any npu.dma_memcpy_nd that could push onto a full DMA task queue. Mirrors the option of the same name on aie-assign-runtime-sequence-bd-ids, which covers the dma_start_task path.
-aie-expand-load-pdi¶
Expand load_pdi operations to explicit configuration sequences
This pass transforms load_pdi { device_ref = @device } operations.
By default (ctrl-pkt = false), each op is replaced with:
1. A load_pdi { device_ref = @empty_N } op (loading an empty device,
which causes a device reset).
2. An aiex.npu.write_config @device op, whose register writes the NPU
translation emits from the device, generating them once however many
times the device is reloaded. With inline-config = true, the
aiex.npu.write32/aiex.npu.blockwrite ops of those writes instead.
With ctrl-pkt = true, each op is replaced with:
1. A load_pdi { device_ref = @ctrl_pkt_overlay } op, which loads the
column control packet overlay needed to stream further configuration
as control packets.
2. A sequence of aiex.npu.control_packet ops that configure the device.
The configuration operations are generated by converting the referenced device's configuration to a transaction binary and then disassembling it into MLIR operations.
This pass is intended to run after runtime sequence materialization
(i.e., after aiex.configure ops have been turned into
aiex.npu.load_pdi).
With teardown = true, each configuration undoes what it enabled before
the next load_pdi, or at the sequence's end: with an
aiex.npu.write_teardown @device, or with control packets for a control
packet configuration. Only a sequence's first configuration, or one after a
configuration of the other kind, keeps its reset or overlay load. With
init-entry = true as well, a device whose sequences all end on
configurations of one kind gets an argument-free reconfig_init runtime
sequence holding that kind's preload, which the host runs before the
others.
The pass completes supported in-flight core lock acquires before reconfiguration. It warns and omits lock draining for unknown acquires, incompatible values, or multiple possible core waiters on one lock. These cases require explicit PDI resets.
A sequence whose first and last reset (or overlay load) name the same PDI gets one more of the other, so the next dispatch's first load is not skipped as cached. Under teardown no sequence needs this.
A reset between two configurations that each hold a buffer resident on
the same memref.global is an error, as it clears the array underneath
that buffer. That includes the reset between a sequence's last
configuration and its first when the host runs it again. Every load_pdi
resets the array unless the firmware skips it as the PDI it loaded last;
under teardown, an expanded load resets it only through its preload.
Options¶
-ctrl-pkt : If true, lower each load_pdi to an @ctrl_pkt_overlay load_pdi followed by aiex.npu.control_packet ops instead of write32/blockwrite ops with an empty-device reset.
-inline-config : If true, write each reloaded device's configuration and teardown as write32/blockwrite ops rather than an aiex.npu.write_config and aiex.npu.write_teardown.
-teardown : If true, each configuration undoes what it enabled once it is done, and only the first configuration of a runtime sequence keeps its reset.
-init-entry : If true (requires teardown), the one reset moves to an argument-free `reconfig_init` runtime sequence per device.
-aie-fuse-trace-buffers¶
Give every traced sequence a slice of one fused trace buffer
Trace lowering appends a trace buffer to each traced aie.runtime_sequence.
It does not update the aiex.run call sites. These call sites are therefore
one argument short.
This pass gives each aie.runtime_sequence one trace buffer covering its
own traces and those of every sequence it runs. It passes each aiex.run a
memref.subview of that buffer, sized to the callee's claim. Every call
site gets its own region, so a sequence that runs one design twice keeps the
two traces apart. aiex.configure plays no part in the split: the buffer
follows the aiex.run call graph, whether the calls reconfigure the array
between them or repeat one design.
A sequence's own traces take the front of its buffer, then each call site in
turn. The pass records the layout as an aie.trace_slices array of
#aie.trace_slice, and the buffer itself as #aie.trace_buffer. A host
reads the slices to attribute each region to the design that wrote it.
Run after the trace pipeline and before -aie-materialize-runtime-sequences.
-aie-inline-trace-config¶
Inline trace configuration and generate NPU writes
Replaces aie.trace.start_config operations by: 1. Looking up the referenced trace.config symbol 2. Resolving register/field names using RegisterDatabase 3. Encoding bitfield values 4. Merging multiple field writes to same register 5. Generating aiex.npu.write32 operations with col/row preserved
-aie-legalize-ctrl-packet¶
Legalize control packet operations for target
-aie-lower-broadcast-packet¶
Replace combination of broadcast and packet-switch by packet-flow
Replace combination of broadcast and packet-switch by packet-flow
-aie-lower-core-reset¶
Lowers all aiex.core_reset operations to npu.maskwrite32
-aie-lower-dma-channel-reset¶
_Lowers aiex.dma_channel_reset(for) to npu.maskwrite32 + re-arm
Two concerns, one pass (kept together like the other reset lowerings):
- Each
aiex.dma_channel_reset_for @fifois first expanded, via the fifo'saie.objectfifo_rearm_binding, into the resident re-arm of its non-shim channels: anaiex.dma_channel_resetper channel, anaiex.set_lockper producer/consumer lock, and anaiex.npu.push_queueSTART_QUEUE re-push per channel (head BD id + repeat read straight off the binding, populated by--aie-assign-bd-ids). - Every
aiex.dma_channel_reset-- standalone or just emitted above -- is then lowered to theaiex.npu.maskwrite32reset pulse.
The emitted set_lock / push_queue are lowered later by
--aie-lower-set-lock / --aie-dma-to-npu, so run this before them.
-aie-lower-dynamic-bd-pool¶
Lower runtime-bound DMA task allocation to a runtime BD free-list pool
The dynamic counterpart to aie-assign-runtime-sequence-bd-ids. That pass
requires straight-line IR and rejects runtime-bound scf.for; this pass
handles the runtime-bound case by keeping the loop rolled and drawing buffer
descriptor IDs from a per-tile runtime free-list pool.
For each dma_configure_task it inserts an aiex.dma_bd_pool_pop and routes
the popped SSA bd_id into the BD's lowering; each dma_free_task and the
recycling half of a dma_await_task becomes an aiex.dma_bd_pool_push of
the matching ID (matched through the def-use / scf.for iter_args chain).
Runs only on the dynamic EmitC path, after aie-unroll-runtime-sequence-
loops has removed every constant-trip loop, so any surviving scf.for is
genuinely runtime-bound. v1 supports single-BD tasks; multi-BD chains under a
runtime loop are diagnosed.
Options¶
-enforce-queue-depth : Insert an aiex.npu.maskpoll before any dma_start_task in a runtime-bound loop that could push onto a full DMA task queue. The same option as on aie-dma-to-npu and aie-assign-runtime-sequence-bd-ids, covering the one path neither of those reaches: a loop this pass deliberately keeps rolled.
-warn-unsafe-bd-reuse : Warn when a dma_free_task releases a buffer descriptor id with no completion guarantee, so the runtime pool could hand it straight back out before hardware has finished the freed transfer. The same default-on option as on aie-assign-runtime-sequence-bd-ids: the pass can only reason within the runtime sequence, so a design that proves completion through the compute core or another tile looks unsafe without being so.
-aie-lower-memcpy¶
Lower aie.memcpy operations to Flows and DMA programs
aie.memcpy operations are an experimental high-level abstraction which move data from one buffer to another. This pass lowers them into appropriate aie.flow and aie.mem operations.
-aie-lower-multicast¶
Lower AIE.multicast operation to AIE.flow operations
This pass replaces AIE.multicast operation with the equivalent number of AIE.flow operations. The lowered AIE.flow operations have the same source port but different destinations.
-aie-lower-scratchpad-parameters¶
Lower scratchpad parameter ops and emit parameter-sync preambles
Lowers aiex.scratchpad_parameter and aiex.read_scratchpad_parameter
ops into concrete scratchpad-based communication between host and AIE
cores.
Assigns globally-unique state table indices to every
aiex.scratchpad_parameter in the module (indices in [0, 32), since the
scratchpad is a single hardware resource shared by all PDIs loaded by a
runtime sequence). Creates per-core buffers for each
aiex.read_scratchpad_parameter usage. Automatically emits a
parameter-sync preamble driven by the emit_parameter_sync_preamble
attribute on aie.core and aie.runtime_sequence:
- In each qualifying core: inserts aie.lock + aie.use_lock(Acquire, 1).
- In each qualifying runtime sequence: inserts aiex.npu.create_scratchpad,
per-parameter aiex.npu.write32 + aiex.npu.update_from_scratchpad,
and aiex.set_lock for each core lock, after the last top-level
aiex.npu.load_pdi (or first, if the sequence loads no PDI).
Sets a kind attribute on each aiex.scratchpad_parameter based on how
it is used: core if read by aiex.read_scratchpad_parameter, addr if
used as a DMA offset_parameter. A parameter may not be used as both. A
DMA length_parameter works with either kind and makes an otherwise
unused parameter addr; a core-kind length gets length_core_encoded.
Optionally emits a params.txt file describing every parameter in the
module (name, global state_table_idx, type, and kind).
Options¶
-aie-lower-set-lock¶
Lowers all aiex.set_lock operations to npu.write32Op
-aie-materialize-bd-chains¶
Concretize aie.bd_chain ops at aiex.start_task use sites
Inlines pre-defined aie.bd_chains at aiex.start_task use sites to become aiex.dma_configure_task and aiex.dma_start_task ops.
-aie-materialize-runtime-sequences¶
Turn aiex.configure into configuration primitives and inline aiex.run calls
Turns top-level aiex.configure into load PDI firmware instructions that set up the requested configuration.
Inlines calls to other runtime sequences using aiex.run into the calling runtime sequence, resolving references within them to the device containing the definition.
This pass requires ObjectFIFOs to be lowered first; apply the ObjectFIFO stateful transform before applying this pass.
-aie-normalize-dma-task-groups¶
Make deferred DMA group endings explicit
Removes defer_completion from awaits that end a group at another
operation, an ineligible triple, or the block end. Each group then ends
with an unmarked await. Concrete and symbolic configure tasks use the
static allocator's eligibility checks.
Run before canonicalization, inlining, or other rewrites can remove implicit group boundaries.
-aie-npu-to-cert¶
Transform aiex.npu operations to aiex.cert operations
This pass transforms low level aiex.npu operations contained in aie.runtime_sequence operations into aiex.cert operations enclosed in aiex.cert.job operations. The write32, maskwrite32, blockwrite and sync operations are supported.
Referenced devices are absorbed into cert.section operations and removed from the output, keeping only the main device.
Options¶
-aie-reorder-ctrl-packets-by-tile¶
Order ordinary control writes and remove overwritten words
Groups independent packets by destination while retaining each destination's action order and multiplicity. Retains the last value for each ordinary unicast word and orders surviving packets by address inside ordinary-write intervals. Barriers, ordered actions, header changes, and other operations end each interval. Run before multicast selection and adjacent-write coalescing.
address-order and eliminate-dead-writes select each transformation
independently. Address ordering without elimination partitions each
sequence at overlapping writes to retain their order.
Options¶
-aie-reserve-runtime-bd-ids¶
Reserve runtime-sequence pinned BD ids for the static allocator
Records the compile-time BD ids the runtime sequence pins, per tile, on
each aie.tile: the bd_ids of aiex.dma_configure_task and
aiex.dma_configure_task_for BDs, and the id of each
aiex.npu.dma_memcpy_nd. An id goes in aiex.reserved_bd_ids when it is
reserved in every BD pool of the tile that holds it, which is the case on
tiles with a single pool, for ids only one pool holds (an AIE4 shim bank),
and for ids whose channel is unknown. An id only
the pinning channel's private pool should give up goes in
aiex.reserved_channel_bd_ids, a dictionary from <direction>_<channel>
(e.g. MM2S_0) to ids. The static allocator (aie-assign-bd-ids) runs in
the AIE dialect and cannot walk AIEX ops, so it reads these attributes to
keep its auto-assignment off ids the runtime sequence already claimed.
-aie-resolve-address-patch-buffers¶
Resolve an address patch's buffer operand to a buffer index
Rewrites each aiex.npu.address_patch that names its host buffer by SSA
value into the arg_idx form the targets emit. Adds the buffer's byte
offset to arg_plus.
Run after -aie-materialize-runtime-sequences. An index exists only in the
sequence that holds the op. Inlining moves the op into that sequence.
-aie-scf-to-control-flow¶
Lower scf to cf everywhere except inside runtime sequences
Converts structured control flow (scf) to unstructured control flow
(cf) throughout the module, with one exception: scf operations nested
inside an aie.runtime_sequence are left untouched.
A runtime sequence is NoTerminator and is lowered to a flat NPU
instruction stream that has no notion of branches; its loops are instead
resolved by the dedicated runtime-sequence lowering path (loop unrolling
for compile-time-constant trip counts, or the dynamic EmitC path
otherwise). Running the generic convert-scf-to-cf over a runtime
sequence would both violate its NoTerminator block invariant (the ops
following a lowered loop end up in a terminator-less block) and feed the
flat NPU emitter control-flow ops it silently drops -- a miscompile.
This pass is therefore a drop-in replacement for convert-scf-to-cf in
pipelines that contain runtime sequences: core/host scf is lowered to
cf as usual (e.g. before aie-standard-lowering), while runtime-sequence
control flow is preserved for its own lowering.
-aie-split-long-repeats¶
Split a task start whose repeat count overflows a queue push
Issues each aiex.dma_start_task whose constant repeat count is past the
target's queue-push field as several starts of the same task: full-size
ones first, then the remainder. Only the last keeps the task's token, so
an await still completes after every pass. A runtime repeat count is left
for aie-dma-to-npu to guard. A start on a task carried through scf
control flow uses its own count, or else the count of the one configure
the task can come from.
Runs before aie-assign-runtime-sequence-bd-ids, which then counts one
queue slot per start. A start that needs more pushes than the queue holds
is a warning, since the sequence then waits for the channel to drain. One
that needs more than max-pushes is an error.
Options¶
-aie-substitute-shim-dma-allocations¶
Replace symbolic references to aie.shim_dma_allocation ops with their (tile, direction, channel) triple
-aie-transform-bfp-types¶
Transform bfp types to standard builtin types
Lowers bfp types to standard builtin types. Adapts operations as necessary to accomodate for bfp data movement.
-aie-txn-to-ctrl-packet¶
Convert transaction operations to control packet operations
-aie-unroll-runtime-sequence-loops¶
Unroll constant-bound loops in runtime sequences
Fully unrolls scf.for loops with compile-time-constant trip counts that
appear inside aie.runtime_sequence bodies.
Runs before aie-assign-runtime-sequence-bd-ids so BD-ID allocation sees
straight-line IR: configure operations in each loop iteration can receive
individual BD IDs after unrolling.
Runtime-bound loops (non-constant trip count) are left in place for the dynamic EmitC lowering path.
-aie-verify-runtime-rearm¶
Experimental, opt-in: reject an aiex.dma_channel_reset whose objectFIFO lock is never re-armed (a necessary, not sufficient, condition for a safe reset)
-aiex-standard-lowering¶
Lower AIEX operations
AIEX Npu Ops are removed.
-cert-legalize-pages¶
Split cert jobs to fit into 8k pages
This pass splits cert jobs into smaller jobs that fit into 8k pages. It is used to ensure that the generated code does not exceed the page size limit of the aiebu tools and cert firmware. After splitting, it moves job IDs that collide modulo 64 on a page to unused slots. A page with more than 64 jobs is an error.