warp.Graph#

class warp.Graph(device, capture_id=0)[source]#

A handle to a captured graph of Warp operations.

Instances are returned by warp.capture_end() (after recording with warp.capture_begin() or via warp.ScopedCapture) or by warp.capture_load() (after deserializing a .wrp file written by warp.capture_save()). Use warp.capture_launch() to replay either kind.

Graphs returned by warp.capture_load() additionally expose parameter binding through set_param(), get_param(), and get_param_ptr(). These methods raise RuntimeError on graphs obtained from warp.capture_end(). Use is_loaded to distinguish the two cases at runtime.

Parameters:
__init__(device, capture_id=0)[source]#
Parameters:

Methods

__init__(device[, capture_id])

get_param(name, arr)

Copy data from a named parameter region of a loaded APIC graph into an array.

get_param_ptr(name)

Return the device pointer of a named parameter region in a loaded APIC graph.

set_param(name, arr)

Copy array data into a named parameter region of a loaded APIC graph.

Attributes

is_loaded

True if this graph was loaded from a .wrp file.

params

Mapping of parameter name to binding metadata for a loaded APIC graph.

set_param(name, arr)[source]#

Copy array data into a named parameter region of a loaded APIC graph.

Parameters:
  • name (str) – The parameter name as registered in warp.capture_save() (via its inputs or outputs argument).

  • arr – A Warp array on the same device as the graph. The array’s underlying memory is copied into the parameter region.

Raises:
  • RuntimeError – If this graph was not loaded from a .wrp file (use is_loaded to check), or if the runtime fails to copy the data (including when arr’s capacity does not match the registered parameter size).

  • TypeError – If arr is not a Warp array.

  • ValueError – If arr is on a different device than the graph.

Return type:

None

Example

Load a graph and update an input parameter before each replay:

graph = wp.capture_load("simulation", device="cuda")
new_positions = wp.array(data, dtype=wp.vec3, device="cuda")

graph.set_param("positions", new_positions)
wp.capture_launch(graph)
get_param(name, arr)[source]#

Copy data from a named parameter region of a loaded APIC graph into an array.

Parameters:
  • name (str) – The parameter name as registered in warp.capture_save() (via its inputs or outputs argument).

  • arr – A Warp array on the same device as the graph. The parameter region is copied into the array’s underlying memory.

Raises:
  • RuntimeError – If this graph was not loaded from a .wrp file (use is_loaded to check), or if the runtime fails to copy the data (including when arr’s capacity does not match the registered parameter size).

  • TypeError – If arr is not a Warp array.

  • ValueError – If arr is on a different device than the graph.

Return type:

None

Example

Read an output parameter back after a replay:

output = wp.empty(N, dtype=wp.vec3, device="cuda")
wp.capture_launch(graph)
graph.get_param("results", output)
get_param_ptr(name)[source]#

Return the device pointer of a named parameter region in a loaded APIC graph.

The returned pointer is owned by the graph and remains valid until the graph is destroyed. Useful for zero-copy interop with other libraries or for implementing custom replay loops in C++ via the wp_apic_* C API.

Parameters:

name (str) – The parameter name registered when the graph was saved.

Returns:

The device pointer (as an integer) for the parameter region, or None if name is not a registered parameter.

Raises:

RuntimeError – If this graph was not loaded from a .wrp file (use is_loaded to check).

property params: dict[source]#

Mapping of parameter name to binding metadata for a loaded APIC graph.

Each value is a dict with a single "size" key giving the parameter region’s size in bytes. Empty for graphs that were not loaded from a .wrp file.

Returns:

A dict of the form {"param_name": {"size": int}, ...}.

property is_loaded: bool[source]#

True if this graph was loaded from a .wrp file.

Use this to distinguish graphs returned by warp.capture_load() (which support set_param(), get_param(), and get_param_ptr()) from graphs returned by warp.capture_end() (which do not).