warp.tile_transpose#

warp.tile_transpose(
a: Tile[Any, tuple[int, int]],
) Tile[Any, tuple[int, int]]#
  • Kernel: true
  • Python: false
  • Differentiable: true

Transpose a 2D tile.

The result aliases a with reversed shape, so writing through it modifies a. The current implementation places a in shared memory before transposing. The result is non-owning and allocates no additional storage.

Parameters:

a – 2D tile to transpose with shape=(M,N)

Returns:

A non-owning tile with shape=(N,M) that aliases a.

Example

@wp.kernel
def transpose_matrix(a: wp.array2d[float], out: wp.array2d[float]):
    t = wp.tile_load(a, shape=(2, 3))

    wp.tile_store(out, wp.tile_transpose(t))

a = wp.array(np.arange(1, 7, dtype=np.float32).reshape(2, 3), dtype=float)
out = wp.zeros((3, 2), dtype=float)

wp.launch_tiled(transpose_matrix, dim=1, inputs=[a], outputs=[out], block_dim=4)

print(out.numpy())
[[1. 4.]
 [2. 5.]
 [3. 6.]]