This document is relevant for: Trn2, Trn3
nki.language.NkiTileGrid#
- class nki.language.NkiTileGrid(**kwargs: Any)[source]#
A tensor view navigated in tile coordinates.
Each tiled entry in
NkiGrid.shapecounts tiles, whileNkiGrid.tile_shapegives the nominal source-element shape of one tile. Untiled HBM dimensions form a leading prefix and are indexed one slab at a time.Integer indexing consumes coordinates but retains
NkiTileGrid.NkiGrid.dataexposes the exactNkiTensoroperand for the selected view.Instances come from
nki.language.tiles()or a block-to-tile transition. Creating and indexing the view allocates no storage and moves no data.Examples:
import nki import nki.isa as nisa import nki.language as nl @nki.jit def copy_tile_grid(src): tile_shape = (128, 256) src_tiles = nl.tiles(src, tile_shape=tile_shape) dst = nl.ndarray( src.shape, dtype=src.dtype, buffer=nl.shared_hbm ) dst_tiles = nl.tiles(dst, tile_shape=tile_shape) for i in range(src_tiles.shape[0]): for j in range(src_tiles.shape[1]): src_tile = src_tiles[i, j] tile = nl.ndarray( src_tile.element_shape, dtype=src.dtype, buffer=nl.sbuf, ) nisa.dma_copy(dst=tile.data, src=src_tile.data) nisa.dma_copy( dst=dst_tiles[i, j].data, src=tile.data, ) return dst
See also
NkiBlockGrid: A grid whose cells group multiple tiles.nki.language.tiles(): Create or retile a tile grid.Methods
Attributes
bufferReturn the memory region containing the backing tensor.
dataExpose the complete grid selection as one native tensor operand.
dtypeReturn the element dtype of the backing tensor.
element_shapeReturn the number of selected elements along each source dimension.
index_step_elementsReturn each grid-coordinate step in source-element units.
is_data_representableReturn whether
datacan represent this selection exactly.is_remainderReturn whether this selection contains a partial boundary tile.
shapeReturn the extents of the grid coordinates available for indexing.
tile_shapeReturn the nominal source-element shape of one tile.
This document is relevant for: Trn2, Trn3