This document is relevant for: Inf2, Trn1, Trn2
nki.isa.tensor_scalar_reduce#
- nki.isa.tensor_scalar_reduce(*, data, op0, operand0, reduce_op, reduce_res, reverse0=False, dtype=None, mask=None, **kwargs)[source]#
Perform the same computation as
nisa.tensor_scalarwith one math operator and also a reduction along the free dimension of thenisa.tensor_scalarresult using Vector Engine.Refer to nisa.tensor_scalar for semantics of
data/op0/operand0. Unlike regularnisa.tensor_scalarwhere two operators are supported, only one operator is supported in this API. Also,op0can only be arithmetic operation in Supported Math Operators for NKI ISA. Bitvec operators are not supported in this API.In addition to nisa.tensor_scalar computation, this API also performs a reduction along the free dimension(s) of the nisa.tensor_scalar result, at a small additional performance cost. The reduction result is returned in
reduce_resin-place, which must be a SBUF/PSUM tile with the same partition axis size as the input tiledataand one element per partition. Thereduce_opcan be any ofnl.add,nl.subtract,nl.multiply,nl.maxornl.min.Reduction axis is not configurable in this API. If the input tile has multiple free axis, the API will reduce across all of them.
\[\begin{split}result = data <op0> operand0 \\ reduce\_res = reduce\_op(dst, axis=<FreeAxis>)\end{split}\]Estimated instruction cost:
max(MIN_II, N) + MIN_IIVector Engine cycles, whereNis the number of elements per partition indata, andMIN_IIis the minimum instruction initiation interval for small input tiles.MIN_IIis roughly 64 engine cycles.
- Parameters:
data – the input tile
op0 – the math operator used with operand0 (any arithmetic operator in Supported Math Operators for NKI ISA is allowed)
operand0 – a scalar constant or a tile of shape
(data.shape[0], 1), where data.shape[0] is the partition axis size of the inputdatatilereverse0 – (not supported yet) reverse ordering of inputs to
op0; if false,operand0is the rhs ofop0; if true,operand0is the lhs ofop0. <– currently not supported yet.reduce_op – the reduce operation to perform on the free dimension of
data <op0> operand0reduce_res – a tile of shape
(data.shape[0], 1), where data.shape[0] is the partition axis size of the inputdatatile. The result ofreduce_op(data <op0> operand0)is written in-place into the tile.dtype – (optional) data type to cast the output type to (see Supported Data Types for more information); if not specified, it will default to be the same as the data type of the input tile.
mask – (optional) a compile-time constant predicate that controls whether/how this instruction is executed (see NKI API Masking for details)
- Returns:
an output tile of
(data <op0> operand0)computation
This document is relevant for: Inf2, Trn1, Trn2