This document is relevant for: Trn2, Trn3
nki.isa.tensor_copy_predicated#
- nki.isa.tensor_copy_predicated(dst: NkiTensor, src: float | NkiTensor, predicate: NkiTensor, reverse_pred=False, name=None)[source]#
Conditionally copy elements from the
srctile to thedsttile on SBUF / PSUM based on apredicateusing Vector Engine.This instruction provides low-level control over conditional data movement on NeuronCores, optimized for scenarios where only selective copying of elements is needed. Either
srcorpredicatemay be in PSUM, but not both simultaneously. Bothsrcandpredicateare permitted to be in SBUF.reverse_predcan only be set to true ifsrcis a scalar.Shape and data type constraints:
src(if it is a tensor),dst, andpredicatemust occupy the same number of partitions and same number of elements per partition.predicatemust be of typeuint8,uint16, oruint32.srcanddstmust share the same data type.dst,predicate, and a tensorsrccan have at most three free dimensions (maximum rank 4, including the partition dimension).if
srcis a scalar, i.e. a Pythonintorfloat, only the kind must matchdst: a Pythonfloatrequires a floatdstdtype and a Pythonintrequires an integerdstdtype. The bit widths need not match – the scalar is materialized indst’s dtype, so e.g. a Pythonintmay be copied into anint8.
Behavior:
Where predicate is True: The corresponding elements from src are copied to dst tile. If src is a scalar, the scalar is copied to the dst tile.
Where predicate is False: The corresponding values in dst tile are unmodified
Tensor indirection.
On NeuronCore-v4 and later,
dstandpredicatesupport tensor indirection (gather/scatter) by passing a view created with.indirect(index).srcdoes not support tensor indirection. Runs on the Vector engine.When operands are manually allocated, their base partitions must satisfy:
the
indexof every.indirect()view starts on a quadrant boundary (a multiple of 32);if
predicateuses.indirect(),predicatestarts on the same partition as itsindex;if
dstuses.indirect()andpredicateis in SBUF,dst’sindexstarts on the same partition aspredicate;if
dstuses.indirect()andpredicateis in PSUM and uses.indirect(),dst’sindexstarts on the same partition aspredicate’sindex.
- Parameters:
src – The source tile or number to copy elements from when
predicateis Truedst – The destination tile to copy elements to
predicate – A tile that determines which elements to copy
reverse_pred – A boolean that reverses the effect of
predicate. Only available whensrcis a scalar.
This document is relevant for: Trn2, Trn3