Script.scan

Contents

Script.scan

Script.scan(x, *, dim, op, exclusive=False, out=None)

Prefix scan along dim.

For each non-dim coordinate independently, the output at position i along dim is the ⊕-combination of the input values at positions [0, i] (inclusive mode, default) or [0, i) with the identity at position 0 (exclusive mode).

Parameters:
  • x (RegisterTensor) – Input tile.

  • dim (int) – Compile-time scan axis.

  • op (str) – One of 'add', 'mul', 'max', 'min', 'and', 'or', 'xor'. Bitwise ops ('and' / 'or' / 'xor') require an integer dtype.

  • exclusive (bool) – If True, return the exclusive prefix (identity at the boundary); otherwise the inclusive prefix.

  • out (RegisterTensor, optional) – Output tile. Must match x in shape and dtype. If not provided, a new tile is allocated with the same layout as x. Passing out=x performs the scan in-place (the emitter saves the original values when needed).

Returns:

ret – The scanned tile, same shape and dtype as x.

Return type:

RegisterTensor

Notes

  • Thread group: Can be executed by any sized thread group whose size matches the input layout’s spatial_size.