warp.experimental.cutile.array_pointer_args#
- warp.experimental.cutile.array_pointer_args(arr)[source]#
Return the
(address, size, ...)values that pass awarp.arrayto a foreign function.Experimental
The cuTile interop API is experimental and subject to change without a formal deprecation cycle. See
export_func()for details.A
warp.arrayparameter ofexport_func()takes a tuple of plain values at the call site: the array’s data address followed by one extent per dimension. Pass the address into the cuTile kernel as act.Constant[int]parameter (runtime scalar parameters are 32-bit and cannot carry it); the extents may be constants or runtime parameters. Hand the tuple to the call.- Parameters:
arr (array) – A contiguous, non-empty CUDA
warp.array.- Returns:
A tuple
(address, *shape)of Python integers.- Raises:
TypeError – If
arris not awarp.array.ValueError – If the array is not contiguous, not on a CUDA device, or empty.
- Return type:
Example
Unpack the tuple into the kernel’s arguments and pass the address and size on to the exported function as one tuple:
import cuda.tile as ct import numpy as np import warp as wp import warp.experimental.cutile as wpct TILE_SIZE = 128 @warp.func def gather_scale(data: warp.array[float], i: int, scale: float) -> float: return data[i] * scale wp_gather_scale = wpct.export_func(gather_scale) @ct.kernel def gather_scale_cutile_kernel(data_ptr: ct.Constant[int], data_len: ct.Constant[int], indices, gathered): index_tile = ct.load(indices, (0,), shape=(TILE_SIZE,)) ct.store(gathered, (0,), wp_gather_scale((data_ptr, data_len), index_tile, 2.5)) data = warp.array(np.arange(100), dtype=warp.float32) indices = warp.array(np.arange(TILE_SIZE) % 100, dtype=warp.int32) gathered = warp.empty(TILE_SIZE, dtype=warp.float32) ct.launch( warp.get_stream().cuda_stream, (1, 1, 1), gather_scale_cutile_kernel, (*wpct.array_pointer_args(data), indices, gathered), )