This document is relevant for: Trn2, Trn3

nki.isa.nc_match_replace8#

nki.isa.nc_match_replace8(dst: NkiTensor, data: NkiTensor, vals: NkiTensor, imm: float, dst_idx: Optional[NkiTensor] = None, name=None)[source]#

Replace first occurrence of each value in vals with imm in data using the Vector engine and return the replaced tensor. If dst_idx tile is provided, the indices of the matched values are written to dst_idx.

Behavior with duplicate vals: when vals contains the same value multiple times within a partition, the instruction processes vals in reverse order (i = 7, 6, ..., 0), so each occurrence of a duplicate in data is paired with a distinct column of dst_idx. The first matched data position (smallest input-position index) is written to the highest dst_idx slot among the duplicates, and subsequent occurrences fill lower slots in descending order. For example, with data = [1, 2, 3, 4, 8, 8, 8, 8, 8, 8, 8] and vals = [3, 8, 8, 8, 8, 8, 8, 8], dst_idx is [2, 10, 9, 8, 7, 6, 5, 4]: column 0 holds the unique match for vals[0] = 3 at position 2, and the seven duplicate 8 values are paired with their seven matching positions [4, 5, 6, 7, 8, 9, 10] in descending order across columns 1-7. This duplicate-vals tie-break is the opposite of nc_find_index8(), which pairs duplicate vals with their matching positions in ascending order across dst_idx columns.

Parameters:
  • dst – output tile with replaced values

  • data – the data tensor to search and replace in

  • vals – tensor containing the 8 values per partition to match

  • imm – the immediate float value to replace matched values with

  • dst_idx – optional tile to store indices of matched values

This document is relevant for: Trn2, Trn3