# 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](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/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:

- [Section 0 — Getting started](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-0>)
- [Section 1 — An operator on its own](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-1>)
- [Section 2 — Your first graph](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-2>)
- [Section 3 — Per-call values and bounds](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-3>)
- [Section 4 — Weights and state](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-4>)
- [Section 5 — Carried values and device loops](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-5>)
- [Section 6 — The host reference and check mode](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-6>)
- [Section 7 — Profiles and tunables](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-7>)
- [Section 8 — From graphs to a language model](<https://github.com/amd/IRON/tree/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/programming_guide/section-8>)

The [IRON API reference](<https://amd.github.io/IRON/api/operators/>) documents every field of every operator, including the tunables. Agents writing or changing operators should follow IRON's [AGENTS.md](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/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`](<https://amd.github.io/IRON/api/operators/#iron.operators.AXPY>) | AIE-accelerated aX + Y operator. | `size` | `a`, `b` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/axpy.py#L12>) |
| [`Clamp`](<https://amd.github.io/IRON/api/operators/#iron.operators.Clamp>) | `x` clamped to `[low, high]`, elementwise, the bounds rounded to bf16. | `size`, `low`, `high` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/clamp.py#L16>) |
| [`Copy`](<https://amd.github.io/IRON/api/operators/#iron.operators.Copy>) | A copy between two views, gathered by `src` and scattered by `dst`. | `input_buffer_size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/copy.py#L546>) |
| [`DepthwiseConv1d`](<https://amd.github.io/IRON/api/operators/#iron.operators.DepthwiseConv1d>) | A causal depthwise convolution over time, five taps, channels last. | `rows`, `channels` | `x`, `weight` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/depthwise_conv1d.py#L19>) |
| [`ElementwiseAdd`](<https://amd.github.io/IRON/api/operators/#iron.operators.ElementwiseAdd>) | AIE-accelerated element-wise addition. | `size` | `a`, `b` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/elementwise_add.py#L11>) |
| [`ElementwiseMul`](<https://amd.github.io/IRON/api/operators/#iron.operators.ElementwiseMul>) | AIE-accelerated element-wise multiplication. | `size` | `a`, `b` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/elementwise_mul.py#L11>) |
| [`Emit`](<https://amd.github.io/IRON/api/operators/#iron.operators.Emit>) | Evaluate an emit program: the next call's scratchpad image and state. | `slots`, `carried`, `rows` | `program`, `planes` | `image`, `state` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/emit.py#L70>) |
| [`GELU`](<https://amd.github.io/IRON/api/operators/#iron.operators.GELU>) | AIE-accelerated GELU. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/gelu.py#L14>) |
| [`GEMM`](<https://amd.github.io/IRON/api/operators/#iron.operators.GEMM>) | `C = A @ B`, tiled m x k x n. | `M`, `K`, `N`, `precision` | `A`, `B` | `C` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/gemm.py#L143>) |
| [`GEMV`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/gemv.py#L79>) |
| [`Gather`](<https://amd.github.io/IRON/api/operators/#iron.operators.Gather>) | `Copy(table[ids])` with `ids` per call: the rows a call names. | `rows`, `table_rows`, `row`, `words` | `table`, `control` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/copy.py#L72>) |
| [`GatherWords`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/copy.py#L380>) |
| [`LayerNorm`](<https://amd.github.io/IRON/api/operators/#iron.operators.LayerNorm>) | AIE-accelerated Layer Normalization of each row (beta 0), optionally times a learned weight row (gamma). | `rows`, `tile_size` | `x`, `weight` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/layer_norm.py#L10>) |
| [`Limbs`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/limbs.py#L24>) |
| [`Log`](<https://amd.github.io/IRON/api/operators/#iron.operators.Log>) | `log(x + offset)` of float32, rounded once to bf16. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/log.py#L14>) |
| [`MHA`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/mha.py#L191>) |
| [`Magnitude`](<https://amd.github.io/IRON/api/operators/#iron.operators.Magnitude>) | The magnitude of each row of complex float32 held as `[re \\| im]`. | `rows`, `tile_size`, `width` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/magnitude.py#L14>) |
| [`Merge`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/merge.py#L50>) |
| [`PatchPositions`](<https://amd.github.io/IRON/api/operators/#iron.operators.PatchPositions>) | Where each of `rows` patch rows of the vision tower comes from. | `rows`, `out_height`, `out_width` |  | `xy`, `position_ids`, `order` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/resample/op.py#L838>) |
| [`RMSNorm`](<https://amd.github.io/IRON/api/operators/#iron.operators.RMSNorm>) | AIE-accelerated RMS Normalization of each row, optionally times a learned weight row. | `rows`, `tile_size` | `x`, `weight` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/rms_norm.py#L10>) |
| [`ReLU`](<https://amd.github.io/IRON/api/operators/#iron.operators.ReLU>) | AIE-accelerated ReLU activation function. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/relu.py#L11>) |
| [`Resample`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/resample/op.py#L463>) |
| [`ResampleTaps`](<https://amd.github.io/IRON/api/operators/#iron.operators.ResampleTaps>) | The int16 filter table and precision torch resamples one axis with. | `in_size`, `out_size` |  | `table` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/resample/op.py#L214>) |
| [`RoPE`](<https://amd.github.io/IRON/api/operators/#iron.operators.RoPE>) | AIE-accelerated RoPE: one core per column, each rotating rows of `cols`. | `rows`, `cols` | `x`, `angles` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/rope.py#L58>) |
| [`RowwiseAdd`](<https://amd.github.io/IRON/api/operators/#iron.operators.RowwiseAdd>) | Each row plus one row, `x + row`: a projection's bias. | `rows`, `tile_size` | `x`, `row` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/elementwise_add.py#L18>) |
| [`RowwiseMul`](<https://amd.github.io/IRON/api/operators/#iron.operators.RowwiseMul>) | Each row times one row, `x * row`. | `rows`, `tile_size` | `x`, `row` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/elementwise_mul.py#L18>) |
| [`Sample`](<https://amd.github.io/IRON/api/operators/#iron.operators.Sample>) | Draw the next token from a row of logits (exact temperature/top-k). | `vocab` | `logits`, `draws`, `tokens` | `tokens`, `token` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/sample.py#L106>) |
| [`SelectiveScan`](<https://amd.github.io/IRON/api/operators/#iron.operators.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/selective_scan.py#L46>) |
| [`SiLU`](<https://amd.github.io/IRON/api/operators/#iron.operators.SiLU>) | AIE-accelerated SiLU activation function. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/silu.py#L12>) |
| [`Sigmoid`](<https://amd.github.io/IRON/api/operators/#iron.operators.Sigmoid>) | AIE-accelerated Sigmoid activation function. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/sigmoid.py#L9>) |
| [`Softmax`](<https://amd.github.io/IRON/api/operators/#iron.operators.Softmax>) | Softmax over each row, one core per (column, channel), each taking a contiguous run of rows. | `rows`, `cols` | `x`, `addend` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/softmax.py#L77>) |
| [`Tanh`](<https://amd.github.io/IRON/api/operators/#iron.operators.Tanh>) | AIE-accelerated Tanh activation function. | `size` | `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/tanh.py#L9>) |

## FastFlowLM ports (`iron.operators.flm`)

| Operator | Description | Required parameters | Inputs | Outputs | Source |
| --- | --- | --- | --- | --- | --- |
| [`DecodeLayer`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/layer/op.py#L24>) |
| [`DequantBFP`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.DequantBFP>) | q4nx weights to bfp16, packed the way `flm.ProjectionGEMM` reads B. | `K`, `N`, `quantized_bytes`, `packed_blocks` | `qw` | `out` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/dequant/op.py#L109>) |
| [`LMHead`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.LMHead>) | Softcapped logits from a q4nx vocabulary, with the RMS norm folded in. | `dim`, `vocab`, `softcap`, `w_words`, `x_len` | `w`, `x` | `y` | [source](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/lm_head/op.py#L64>) |
| [`PrefillAttention`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/prefill_attn/op.py#L118>) |
| [`PrefillSlidingAttention`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/prefill_attn/op.py#L124>) |
| [`ProjectionGEMM`](<https://amd.github.io/IRON/api/operators/#iron.operators.flm.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](<https://github.com/amd/IRON/blob/b7e8ea91eaad163c01fbc93e9253eb66163d4fce/iron/operators/flm/gemm/op.py#L128>) |
