This document is relevant for: Trn2, Trn3
nki.isa.NkiInstruction#
- class nki.isa.NkiInstruction(handle)[source]#
Handle or named reference to a NKI instruction.
Returned by nki.isa operations and
nisa.instruction(). Use.depends_on(*producers, kind=...)to add runtime or scheduling-only dependencies.Methods
Run this instruction after each producer.
Move the
selfinstruction immediately after thetargetinstruction in program order.Move the
selfinstruction immediately before thetargetinstruction in program order.- depends_on(*producers: NkiInstruction, kind: Optional[dependency] = None) NkiInstruction[source]#
Run this instruction after each producer.
depends_on()creates a post-allocation scheduling dependency. Each producer must appear before this instruction in program order. Useschedule_after()orschedule_before()to create a pre-allocation scheduling dependency.kind=dependency.runtimeadds a hardware semaphore wait. The producer must be in the same control-flow block as this instruction, or in an enclosing block.kind=dependency.scheduleadds a compiler scheduling constraint without hardware synchronization.Omitting
kindcurrently adds a hardware semaphore wait. This form is deprecated.Returns this instruction.
- schedule_after(target: NkiInstruction, *, add_dependency: Optional[dependency] = None, carry_cone: bool = False) NkiInstruction[source]#
Move the
selfinstruction immediately after thetargetinstruction in program order.Unlike
depends_on(), which creates a post-allocation scheduling dependency,schedule_after()creates a pre-allocation scheduling dependency. It changes program order before tensor allocation and can affect tensor live ranges and allocation. Thetargetinstruction stays in place.Example:
# Before: op_a, op_b op_a.schedule_after(op_b) # After: op_b, op_a
By default, no additional post-allocation scheduling dependency is added. Set
add_dependencyto also makeselfdepend ontarget. Setcarry_cone=Trueto also move every instruction betweenselfandtargetthatselftransitively depends on (when moving earlier) or that transitively depends onself(when moving later). Carried producers land immediately beforeselfand carried consumers immediately after it, in their current relative order.Both instructions must be in the same block. For example, an instruction inside a compiled loop or branch cannot move outside that loop or branch. An instruction also cannot move across a compiled loop or branch. The compiler checks the final instruction order after applying all pre-allocation scheduling changes. Compilation fails if the final order breaks a data dependency. Add
schedule_before()orschedule_after()calls for any other instructions that must move.Returns this instruction.
- schedule_before(target: NkiInstruction, *, add_dependency: Optional[dependency] = None, carry_cone: bool = False) NkiInstruction[source]#
Move the
selfinstruction immediately before thetargetinstruction in program order.Unlike
depends_on(), which creates a post-allocation scheduling dependency,schedule_before()creates a pre-allocation scheduling dependency. It changes program order before tensor allocation and can affect tensor live ranges and allocation. Thetargetinstruction stays in place.Example:
# Before: op_a, op_b op_b.schedule_before(op_a) # After: op_b, op_a
By default, no additional post-allocation scheduling dependency is added. Set
add_dependencyto also maketargetdepend onself. Setcarry_cone=Trueto also move every instruction betweenselfandtargetthatselftransitively depends on (when moving earlier) or that transitively depends onself(when moving later). Carried producers land immediately beforeselfand carried consumers immediately after it, in their current relative order.Both instructions must be in the same block. For example, an instruction inside a compiled loop or branch cannot move outside that loop or branch. An instruction also cannot move across a compiled loop or branch. The compiler checks the final instruction order after applying all pre-allocation scheduling changes. Compilation fails if the final order breaks a data dependency. Add
schedule_before()orschedule_after()calls for any other instructions that must move.Returns this instruction.
This document is relevant for: Trn2, Trn3