warp.capture_while#

warp.capture_while(condition, while_body, stream=None, **kwargs)[source]#

Create a dynamic loop based on a condition.

The condition value is retrieved from the first element of the condition array.

The while_body callback is responsible for updating the condition value so the loop can terminate.

This function is particularly useful during graph capture, but can be used without graph capture as well. CUDA 12.4+ is required for CUDA graph conditional nodes. A Graph loop body must be a finished capture on the same device as condition and must not itself contain capture_if() or capture_while(). CUDA captures with apic=True do not yet support a Graph loop body, and CPU captures do not yet support a Graph from capture_load(). capture_save() rejects a CPU graph that records a Graph loop body.

Parameters:
  • condition (warp.array[warp.int32]) – Warp array holding the condition value.

  • while_body (Callable | Graph) – A callback function or Graph to execute while the loop condition is True.

  • stream (Stream | None) – The CUDA stream where the condition was written. If None, use the current stream on the device where condition resides.

Any additional keyword arguments are forwarded to the callback function.