warp.capture_if#

warp.capture_if(
condition,
on_true=None,
on_false=None,
stream=None,
**kwargs,
)[source]#

Create a dynamic branch based on a condition.

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

This function is particularly useful with CUDA graphs, but can be used without graph capture as well. CUDA 12.4+ is required for CUDA graph conditional nodes. CPU APIC capture records this operation directly, but branch bodies must be callbacks; passing Graph objects under CPU APIC capture is not yet supported.

Parameters:
  • condition (warp.array(dtype=wp.int32, ndim=1)) – Warp array holding the condition value.

  • on_true (Callable | Graph | None) – A callback function or Graph to execute if the condition is True.

  • on_false (Callable | Graph | None) – A callback function or Graph to execute if the condition is False.

  • stream (Stream) – 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 functions.