warp.tile_store_indexed#
- warp.tile_store_indexed(
- a: Array[Any],
- indices: Tile[int32, tuple[int]],
- t: Tile[Any, tuple[int, ...]],
- offset: tuple[int, ...] = ...,
- axis: int32 = 0,
Store a tile to a global memory array, scattering along one axis through a 1D tile of indices.
Cooperative operation: every thread of the block must reach the call. Element
coftis written toaatoffset[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 destination index is negative or past the end ofais skipped, so-1can be used to discard a slice.The selected elements of
aare overwritten. Each destination must be selected by at most one element — duplicate indices race.axismust be a compile-time constant. The backward pass accumulates gradients at the written destinations into the adjoint oft, then clears those entries froma.grad.- Parameters:
a – The destination array in global memory
indices – A 1D tile of
int32indices intoaalongaxis. It must hold exactlyt.shape[axis]values and is always placed in shared memory (a register tile passed here is promoted).t – The source tile to store data from, must have the same data type and number of dimensions as the destination array, and along
axisthe same number of elements as theindicestileoffset – Offset in the destination array, 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 to
Example
This example writes the rows of a tile to the even-numbered rows of a 2D array.
TILE_M, TILE_N = 2, 4 TILE_THREADS = 4 @wp.kernel def scatter_even_rows(x: wp.array2d[float], y: wp.array2d[float]): t = wp.tile_load(x, shape=(TILE_M, TILE_N)) # tile row k is written to row 2*k of `y` rows = wp.tile_arange(TILE_M, dtype=int) * 2 wp.tile_store_indexed(y, indices=rows, t=t, axis=0) x = wp.array(np.arange(1, 9, dtype=np.float32).reshape(2, 4), dtype=float) y = wp.zeros((4, 4), dtype=float) wp.launch_tiled(scatter_even_rows, dim=1, inputs=[x], outputs=[y], block_dim=TILE_THREADS) print(y.numpy())
[[1. 2. 3. 4.] [0. 0. 0. 0.] [5. 6. 7. 8.] [0. 0. 0. 0.]]