warp
warp copied to clipboard
[REQ] Improve ScopedCapture to simplify writing code with and without graphs
Description
Running with and without graph capture requires some clunky if-else statements, e.g.:
if use_graph:
if graph is None:
with wp.ScopedCapture() as capture:
# call the function that encapsulates the kernel launch to do not repeat it
graph = capture.graph
else:
wp.capture_launch(graph)
else:
# call the function that encapsulates the kernel launch to do not repeat it
One suggestion is to add an active flag like so:
if graph is None:
with wp.ScopedCapture(active=use_graph) as capture:
# just call the kernel launch here... defined once... no function is needed to encapsulate the kernel launch
graph = capture.graph
else:
wp.capture_launch(graph)
Another idea would be neat to be able to capture the code inside ScopedCapture as a lambda.
Yet another idea is to have a wp.graphable() function decorator that returns a graph or the function itself depending on settings.