warp icon indicating copy to clipboard operation
warp copied to clipboard

[REQ] Improve ScopedCapture to simplify writing code with and without graphs

Open nvlukasz opened this issue 2 months ago • 0 comments

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.

Context

nvlukasz avatar Oct 06 '25 18:10 nvlukasz