Skip to content

IRON operators

IRON is the operator and graph library on top of MLIR-AIE's aie.iron, and fastflow-sdk installs it with the compiler and the HRX runtime. An operator, such as GEMM, RMSNorm or MHA, is a class you construct by keyword. Called on device tensors, it compiles once and runs on the NPU; compiled images are cached by content under NPU_CACHE_HOME (default ~/.npu/cache). A graph, a subclass of iron.Graph, records the steps of several operators and compiles them into one image, which is how iron.lm runs language models.

Run an operator

This is the first example of IRON's programming guide, section 1:

# SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Section-1 example: one operator, called on its own, no graph.

``AXPY`` computes ``scalar_factor * a + b``. Construction is keyword-only and
declares the shape; the first call compiles for the device, later calls with
the same shape reuse that compile. Outside a graph, a call takes one device
tensor per declared buffer, in order (every input, then every output).
"""

import argparse

import aie.utils as aie_utils
import numpy as np
from aie.utils.verify import compare
from ml_dtypes import bfloat16

from iron.operators import AXPY


def main(argv=None):
    parser = argparse.ArgumentParser(description="Section 1: AXPY standalone")
    parser.add_argument("--size", type=int, default=2048)
    parser.add_argument("--scalar", type=float, default=1.5)
    args = parser.parse_args(argv)

    op = AXPY(
        size=args.size,
        num_aie_columns=1,
        tile_size=args.size,
        scalar_factor=args.scalar,
    )

    rng = np.random.default_rng(0)
    a_np = rng.standard_normal(args.size).astype(bfloat16)
    b_np = rng.standard_normal(args.size).astype(bfloat16)
    reference = op.reference(a_np, b_np)

    Tensor = aie_utils.DEFAULT_TENSOR_CLASS
    a, b = Tensor(a_np), Tensor(b_np)
    y = Tensor(a_np.shape, dtype=a_np.dtype)
    op(a, b, y)
    result = y.numpy()

    verdict = compare(result, reference, op.resolved().tolerance())
    print(f"AXPY vs. its own reference: {verdict.detail}")
    assert verdict, verdict.detail
    print("PASS!")


if __name__ == "__main__":
    main()
  • Construction declares the problem and touches no device. Parameters such as size fix the shape. Tunables such as num_aie_columns and tile_size choose how the work spreads over the array; leave them out and op.resolved() shows what the operator picks for your device.
  • A call takes one device tensor per declared buffer, in the order op.buffers lists them. aie.utils.DEFAULT_TENSOR_CLASS is the device tensor type of the host runtime: importing aie with fastflow-sdk installed selects HRX unless NPU_RUNTIME says otherwise. Wrap a NumPy array to upload it, or give a shape and dtype for a buffer the NPU writes.
  • op.reference() computes the expected result with NumPy, and op.resolved().tolerance() says how close the NPU must come.

Compile without an NPU

Bind the device before building anything, then compile. Only calling an operator needs an NPU:

import aie.utils as aie_utils
from aie.iron.device import from_name
from iron.operators import AXPY

aie_utils.set_current_device(from_name("npu2", n_cols=8))
artifacts = AXPY(size=2048, scalar_factor=1.5).compile()

Go further

IRON's programming guide, at the revision this SDK ships, continues from one operator to graphs and models:

The IRON API reference documents every field of every operator, including the tunables. Agents writing or changing operators should follow IRON's AGENTS.md.

The tables are generated from iron/operators at IRON b7e8ea91eaad, the revision this SDK ships.

Operators

Operator Description Required parameters Inputs Outputs Source
AXPY AIE-accelerated aX + Y operator. size a, b y source
Clamp x clamped to [low, high], elementwise, the bounds rounded to bf16. size, low, high x y source
Copy A copy between two views, gathered by src and scattered by dst. input_buffer_size x y source
DepthwiseConv1d A causal depthwise convolution over time, five taps, channels last. rows, channels x, weight y source
ElementwiseAdd AIE-accelerated element-wise addition. size a, b y source
ElementwiseMul AIE-accelerated element-wise multiplication. size a, b y source
Emit Evaluate an emit program: the next call's scratchpad image and state. slots, carried, rows program, planes image, state source
GELU AIE-accelerated GELU. size x y source
GEMM C = A @ B, tiled m x k x n. M, K, N, precision A, B C source
GEMV C = A @ B as row-blocks of A per lane, tile_size_input rows per mv.cc call. M, K, num_matrices A, B C source
Gather Copy(table[ids]) with ids per call: the rows a call names. rows, table_rows, row, words table, control y source
GatherWords A Gather's control words for ids the device made, in a graph. rows, table_rows, row_bytes, words, pairs, record ids control source
LayerNorm AIE-accelerated Layer Normalization of each row (beta 0), optionally times a learned weight row (gamma). rows, tile_size x, weight y source
Limbs Each row of float32 as six planes of its bf16 limbs, for a float32 product by GEMM. rows, tile_size, line x y source
Log log(x + offset) of float32, rounded once to bf16. size x y source
MHA Fused attention over (B_q, d) Q, (d, B_kv) K and (B_kv, d) V blocks. num_heads, seq_pad, packed Q, K, V O source
Magnitude The magnitude of each row of complex float32 held as [re \| im]. rows, tile_size, width x y source
Merge The row each position of ids takes from the text's embeddings and the towers' soft tokens. rows, placeholders, kinds ids, before merge source
PatchPositions Where each of rows patch rows of the vision tower comes from. rows, out_height, out_width xy, position_ids, order source
RMSNorm AIE-accelerated RMS Normalization of each row, optionally times a learned weight row. rows, tile_size x, weight y source
ReLU AIE-accelerated ReLU activation function. size x y source
Resample An image resized as torchvision's antialiased bicubic resize does it on the CPU. height, width, out_height, out_width image, taps_w, taps_h patches source
ResampleTaps The int16 filter table and precision torch resamples one axis with. in_size, out_size table source
RoPE AIE-accelerated RoPE: one core per column, each rotating rows of cols. rows, cols x, angles y source
RowwiseAdd Each row plus one row, x + row: a projection's bias. rows, tile_size x, row y source
RowwiseMul Each row times one row, x * row. rows, tile_size x, row y source
Sample Draw the next token from a row of logits (exact temperature/top-k). vocab logits, draws, tokens tokens, token source
SelectiveScan Each row t of xbc updates each head's state (head_dim, state_size) and reads it out. rows, heads, head_dim, state_size, inner, width, slice_state xbc, dt, head, state y, final source
SiLU AIE-accelerated SiLU activation function. size x y source
Sigmoid AIE-accelerated Sigmoid activation function. size x y source
Softmax Softmax over each row, one core per (column, channel), each taking a contiguous run of rows. rows, cols x, addend y source
Tanh AIE-accelerated Tanh activation function. size x y source

FastFlowLM ports (iron.operators.flm)

Operator Description Required parameters Inputs Outputs Source
DecodeLayer One Gemma 4 decode layer for one token, as FastFlowLM's engine drives it. geometry, layer_type, x_len, proj_len, rms_len, rope_rms_len, kv_len x, proj, rms, rope_rms, kv x, kv source
DequantBFP q4nx weights to bfp16, packed the way flm.ProjectionGEMM reads B. K, N, quantized_bytes, packed_blocks qw out source
LMHead Softcapped logits from a q4nx vocabulary, with the RMS norm folded in. dim, vocab, softcap, w_words, x_len w, x y source
PrefillAttention Causal prefill attention with a head dim of 512, from a KV cache. max_context, num_heads, num_kv_heads, head_dim, qo_len, kv_len q, kv o source
PrefillSlidingAttention Sliding-window causal prefill attention with a head dim of 256, from a KV cache. max_context, num_heads, num_kv_heads, head_dim, qo_len, kv_len q, kv o source
ProjectionGEMM AIE-accelerated bf16 GEMM on a 4-row grid, as wide as the device. M, K, N, packed_blocks, precision, b_dtype A, B C source