cuda.core: add GraphBuilder.graph_definition property#2026
Open
Andy-Jost wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Completes step 3 of NVIDIA#1330 by exposing the captured graph as an explicit `GraphDefinition` view that shares ownership of the underlying `CUgraph`. The handle-layer plumbing landed in PR NVIDIA#2008; this commit wires up the user-facing surface and locks in the state-guard rules. State semantics: - PRIMARY builder: only valid after `end_building()`. Before `begin_building()` no graph exists; during capture the driver is the sole writer, so explicit access is unsafe. - CONDITIONAL_BODY builder: valid both before `begin_building()` (the body graph is allocated at conditional-node creation time) and after `end_building()`. This enables a hybrid flow where a conditional body is populated entirely via the explicit API, with no capture at all. - FORKED builder: never valid. Forked builders share the primary's graph; access through the primary instead. Tests cover the happy path, both hybrid flows on conditional bodies (populate-via-explicit-API and capture-then-augment), the three error states (forked, capturing, primary pre-capture), and the shared-ownership guarantee (the `GraphDefinition` survives the builder's `close()`). Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes step 3 of #1330 by exposing the captured graph as an explicit
GraphDefinitionview that shares ownership of the same graph the builder is producing. The handle-layer plumbing landed in #2008; this PR wires up the user-facing surface and the state-guard rules.The new property unlocks two hybrid flows:
end_building(), then re-complete()to pick up the changes.if_then/if_else/while_loop/switch) entirely through the explicit API without ever callingbegin_building()on it.API addition
GraphBuilder.graph_definition: GraphDefinition(read-only property)Availability rules:
begin_buildingend_buildingThe returned
GraphDefinitionis a view, not an owning wrapper: nodes added through it appear in subsequentcomplete()anddebug_dot_print()calls on the builder.Test plan
Nine new tests in
test_graph_builder.py:graph_definitionreturns aGraphDefinitionafterend_building()and reflects the captured nodes.begin_building, any builder mid-capture.GraphDefinitionkeeps working after the builder is closed.complete(), and run end-to-end on a stream.Local pre-commit clean. Local test run on a 2-GPU machine: all
cuda_core/tests/graphpass.Related
graph-builder-refactor); branched off that PR's head, plusorigin/main(so reviewers see only this commit).Made with Cursor