This document is relevant for: Trn2, Trn3

nki.isa.instruction#

nki.isa.instruction(name=None, *, input_name=None, output_name=None, iterations=None)[source]#

Reference an instruction by its name or tensor debug names.

Each supplied name is matched exactly. input_name selects readers and output_name selects writers. All supplied selectors must match one instruction; missing and ambiguous references fail compilation.

References are resolved after loop unrolling, so instruction("load_3") can select an instruction named "load" in iteration 3. Fixed names gain loop index suffixes automatically; explicit formatted names such as f"load_{i}" retain their format. Use the returned handle with depends_on, schedule_after, schedule_before, or nki.Kernel.with_schedule. For example, after a loop with unroll=True:

nisa.instruction("load", iterations=[3]).schedule_before(
    nisa.instruction("load", iterations=[0])
)

iterations accepts a list or tuple of integer loop index values, ordered outermost to innermost. It appends decimal suffixes to name: instruction("load", iterations=[i, j]) is equivalent to instruction(f"load_{i}_{j}"). Indices may be compiled loop variables that become constant after unrolling. An empty sequence leaves name unchanged. Tensor selectors are matched as supplied, without suffixes.

This document is relevant for: Trn2, Trn3