This document is relevant for: Trn2, Trn3

nki.isa.nc_find_index8#

nki.isa.nc_find_index8(dst: NkiTensor, data: NkiTensor, vals: NkiTensor, name=None)[source]#

Find indices of the 8 given vals in each partition of the data tensor.

This instruction first loads the 8 values, then loads the data tensor and outputs the indices (starting at 0) of the first occurrence of each value in the data tensor, for each partition. Each index is a position in the iteration order of the access pattern: 0 is the first element that the pattern visits, not column 0 of the tile.

The data tensor can have at most four free dimensions (maximum rank 5), while dst and vals can have at most two free dimensions (maximum rank 3). These ranks include the partition dimension. The data tensor must have between 8 and 16,384 elements per partition. The vals tensor must have exactly 8 elements per partition. The output will contain exactly 8 elements per partition and will be uint16 or uint32 type. Default output type is uint32.

If a value in the vals tensor is not present in the data tensor, its output slot is set to an all-ones sentinel (0xFFFFFFFF for uint32, 0xFFFF for uint16).

If provided, a mask is applied only to the data tensor.

Dynamic access patterns.

data may carry a dynamic access pattern built with nki.language.NkiTensor.ap(), whose stride and count slots hold a nki.isa.NkiScalar read at runtime. dst and vals must be static, with no register-bound stride or count. The partition dimension (dim 0) of data is also an exception: both its stride and its count must be Python int values, so put the dynamic slots on a free dimension.

Parameters:
  • dst – a 2D tile containing indices (uint16 or uint32) of the 8 values in each partition with shape [par_dim, 8]

  • data – the data tensor to find indices from

  • vals – tensor containing the 8 values per partition whose indices will be found

This document is relevant for: Trn2, Trn3