warp.utils.array_scan_temp_storage_size#

warp.utils.array_scan_temp_storage_size(count, dtype, device=None)[source]#

Return the temporary storage size in bytes that array_scan() needs.

Use this to allocate a buffer for the temp_storage argument of array_scan() ahead of time, for example before a graph capture.

The size depends on count, the scalar type of dtype, and the device. It does not depend on the vector length of dtype, on whether the scan is inclusive or exclusive, or on the array strides, so one buffer can serve all of these. A buffer sized for count elements is also large enough for any scan of at most count elements with the same scalar type on the same device. CPU scans need no temporary storage, so the size is 0 on CPU devices.

Parameters:
  • count (int) – Number of array elements to scan.

  • dtype (type) – Data type of the arrays to scan. Must be a scalar or vector type with scalar type int32, int64, float32, or float64.

  • device (Device | str | None) – The device the scan runs on. If None, the default device is used.

Returns:

The number of bytes of temporary storage required.

Raises:
  • RuntimeError – If dtype is unsupported or if the size query fails.

  • ValueError – If count is negative or exceeds the 32-bit element limit.

Return type:

int

Example

n = 4096
temp = warp.empty(
    warp.utils.array_scan_temp_storage_size(n, warp.int32, device="cuda:0"),
    dtype=warp.uint8,
    device="cuda:0",
)
src = warp.ones(n, dtype=warp.int32, device="cuda:0")
dst = warp.empty_like(src)

with warp.ScopedCapture(device="cuda:0") as capture:
    warp.utils.array_scan(src, dst, inclusive=False, temp_storage=temp)