warp.tile_load_indexed#
- warp.tile_load_indexed(
- a: Array[Any],
- indices: Tile[int32, tuple[int]],
- shape: tuple[int, ...],
- offset: tuple[int, ...] = ...,
- axis: int32 = 0,
- storage: str = 'register',
Load a tile from a global memory array, gathering along one axis through a 1D tile of indices.
Cooperative operation: every thread of the block must reach the call. Tile element
cis read fromaatoffset[d] + c[d]along every dimensiondother thanaxis, and atoffset[axis] + indices[c[axis]]alongaxis. Every coordinate is checked against both the lower and upper array bounds: an element whose source index is negative or past the end ofareads as zero, so-1can be used as a padding sentinel without a physical zero row.shape,axis, andstoragemust be compile-time constants. In a backward pass the adjoint of the returned tile is atomically accumulated intoa.gradat the same gathered locations.- Parameters:
a – The source array in global memory
indices – A 1D tile of
int32indices intoaalongaxis. It must hold exactlyshape[axis]values and is always placed in shared memory (a register tile passed here is promoted).shape – Shape of the tile to load, must have the same number of dimensions as
a, and alongaxisthe same number of elements as theindicestileoffset – Offset in the source array to begin reading from, one value per dimension of
a; the entry foraxisis added to each index; may be a runtime value.axis – Axis of
athat the indices refer tostorage – The storage location for the tile:
"register"for registers or"shared"for shared memory.
- Returns:
A tile with shape as specified and data type the same as the source array.
Example
This example gathers the even-numbered rows of a 2D array.
TILE_M, TILE_N = 2, 4 TILE_THREADS = 4 @wp.kernel def gather_even_rows(x: wp.array2d[float], y: wp.array2d[float]): # gather rows 0, 2, 4, ... of `x` rows = wp.tile_arange(TILE_M, dtype=int) * 2 t = wp.tile_load_indexed(x, indices=rows, shape=(TILE_M, TILE_N), axis=0) wp.tile_store(y, t) x = wp.array(np.arange(1, 17, dtype=np.float32).reshape(4, 4), dtype=float) y = wp.zeros((2, 4), dtype=float) wp.launch_tiled(gather_even_rows, dim=1, inputs=[x], outputs=[y], block_dim=TILE_THREADS) print(y.numpy())
[[ 1. 2. 3. 4.] [ 9. 10. 11. 12.]]