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 withwarp.capture_begin()or viawarp.ScopedCapture) or bywarp.capture_load()(after deserializing a.wrpfile written bywarp.capture_save()). Usewarp.capture_launch()to replay either kind.Graphs returned by
warp.capture_load()additionally expose parameter binding throughset_param(),get_param(), andget_param_ptr(). These methods raiseRuntimeErroron graphs obtained fromwarp.capture_end(). Useis_loadedto distinguish the two cases at runtime.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
Trueif this graph was loaded from a.wrpfile.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 itsinputsoroutputsargument).arr – A Warp
arrayon 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
.wrpfile (useis_loadedto check), or if the runtime fails to copy the data (including whenarr’s capacity does not match the registered parameter size).TypeError – If
arris not a Warp array.ValueError – If
arris 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 itsinputsoroutputsargument).arr – A Warp
arrayon 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
.wrpfile (useis_loadedto check), or if the runtime fails to copy the data (including whenarr’s capacity does not match the registered parameter size).TypeError – If
arris not a Warp array.ValueError – If
arris 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
Noneifnameis not a registered parameter.- Raises:
RuntimeError – If this graph was not loaded from a
.wrpfile (useis_loadedto 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.wrpfile.- Returns:
A dict of the form
{"param_name": {"size": int}, ...}.
- property is_loaded: bool[source]#
Trueif this graph was loaded from a.wrpfile.Use this to distinguish graphs returned by
warp.capture_load()(which supportset_param(),get_param(), andget_param_ptr()) from graphs returned bywarp.capture_end()(which do not).