This document is relevant for: Trn2, Trn3

nki.language.empty_like#

nki.language.empty_like(x: nki.language.NkiTensor | nki.language.NkiTileGrid | nki.language.NkiBlockGrid, dtype: Optional[str] = None, buffer: Optional[MemoryRegion] = None, name: str = '', *, transpose_axes: Optional[tuple[int, ...]] = None, address: Optional[tuple] = None) → nki.language.NkiTensor | nki.language.NkiTileGrid | nki.language.NkiBlockGrid[source]#

Allocate independent, uninitialized storage with matching geometry.

The destination uses the source dtype and buffer unless either is specified explicitly. Tensor inputs preserve the source shape. Grid inputs preserve the concrete grid type, navigation shape, tile shape, block grouping, and exact remainder extents.

A positive-step grid slice can select cells separated by physical gaps. The destination packs those cells densely while preserving their logical hierarchy and boundary extents.

transpose_axes prepares an SBUF destination for a later nki.isa.dma_transpose(); allocation does not issue the instruction. Supported tiled-dimension orders are (1, 0), (2, 1, 0), and (3, 1, 2, 0) for ranks two through four. The source free extent that becomes the destination partition extent must not exceed 128.

Parameters:
  • x – The NkiTensor, NkiTileGrid, or NkiBlockGrid whose geometry defines the allocation.

  • dtype – Destination element dtype. Defaults to x.dtype.

  • buffer – Destination MemoryRegion. Defaults to x.buffer.

  • name – the name of the tensor, used in scheduling.

  • transpose_axes – Optional tiled-dimension order for a native nki.isa.dma_transpose() destination.

  • address – Optional manual address (partition_offset, free_offset) with the same contract as nki.language.ndarray().

Returns:

New uninitialized storage with the matching tensor or grid abstraction. Transpose allocation permutes the tiled dimensions.

Raises:
  • TypeError – if x is unsupported, buffer is not an NKI MemoryRegion, or transpose_axes is not a tuple.

  • ValueError – if transpose rank, order, destination buffer, or partition extent is unsupported.

  • AssertionError – if manual address validation in nki.language.ndarray() fails.

See also

nki.language.alloc_tiles(): Allocate from explicit tile geometry. nki.language.alloc_blocks(): Allocate from explicit block geometry.

This document is relevant for: Trn2, Trn3