Add edge mutation and MutableSet interface for graph nodes#1850
Open
Andy-Jost wants to merge 8 commits intoNVIDIA:mainfrom
Open
Add edge mutation and MutableSet interface for graph nodes#1850Andy-Jost wants to merge 8 commits intoNVIDIA:mainfrom
Andy-Jost wants to merge 8 commits intoNVIDIA:mainfrom
Conversation
|
Contributor
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Rename test files to reflect what they actually test: - test_basic -> test_graph_builder (stream capture tests) - test_conditional -> test_graph_builder_conditional - test_advanced -> test_graph_update (moved child_graph and stream_lifetime tests into test_graph_builder) - test_capture_alloc -> test_graph_memory_resource - test_explicit* -> test_graphdef* Made-with: Cursor
- Extend Graph.update() to accept both GraphBuilder and GraphDef sources - Surface CUgraphExecUpdateResultInfo details on update failure instead of a generic CUDA_ERROR_GRAPH_EXEC_UPDATE_FAILURE message - Release the GIL during cuGraphExecUpdate via nogil block - Add parametrized happy-path test covering both GraphBuilder and GraphDef - Add error-case tests: unfinished builder, topology mismatch, wrong type Made-with: Cursor
Replace cached tuple-based pred/succ with mutable AdjacencySet backed by direct CUDA driver calls. Add GraphNode.remove() wrapping cuGraphDestroyNode. Made-with: Cursor
…cencies Enable adding/removing edges between graph nodes via AdjacencySet (a MutableSet proxy on GraphNode.pred/succ), node removal via discard(), and property setters for bulk edge replacement. Includes comprehensive mutation and interface tests. Closes part of NVIDIA#1330 (step 2: edge mutation on GraphDef). Made-with: Cursor
Replace inline skipif version check with requires_module(np, "2.1") from the shared test helpers, consistent with other test files. Made-with: Cursor
4b837a9 to
3aef7e0
Compare
Rename class and file to AdjacencySetProxy to clarify write-through semantics. Add bulk-efficient clear(), __isub__(), __ior__() overrides and remove_edges() on the Cython core. Guard GraphNode.discard() against double-destroy via membership check. Filter duplicates in update(). Add error-path tests for wrong types, cross-graph edges, and self-edges. Made-with: Cursor
3aef7e0 to
8554d30
Compare
Contributor
Author
|
/ok to test |
…INEL Replace discard() with destroy() which calls cuGraphDestroyNode and then zeroes the CUgraphNode resource in the handle box via invalidate_graph_node_handle. This prevents stale memory access on destroyed nodes. Properties (type, pred, succ, handle) degrade gracefully to None/empty for destroyed nodes. Remove the GRAPH_NODE_SENTINEL (0x1) approach in favor of using NULL for both sentinels and destroyed nodes, which is simpler and avoids the risk of passing 0x1 to driver APIs that treat it as a valid pointer. Made-with: Cursor
rparolin
reviewed
Apr 3, 2026
| GraphHandle graph_node_get_graph(const GraphNodeHandle& h) noexcept; | ||
|
|
||
| // Zero the CUgraphNode resource inside the handle, marking it invalid. | ||
| void invalidate_graph_node_handle(const GraphNodeHandle& h) noexcept; |
Collaborator
There was a problem hiding this comment.
Could we make the invalidate_graph_node_handle take a mutable reference? Rather than internally mutating through a const& handle?
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
Implements step 2 of #1330 (graph updates): edge mutation on
GraphDef. Graph node adjacencies (pred/succ) are now exposed asAdjacencySetProxy, acollections.abc.MutableSetproxy backed bycuGraphAddDependencies/cuGraphRemoveDependencies. Nodes can be removed viaGraphNode.destroy()(wrapscuGraphDestroyNode), and property setters onpred/succsupport bulk edge replacement.Examples
Changes
AdjacencySetProxy: fullMutableSetimplementation with bulk-efficientclear(),__isub__(),__ior__(),update(), andremove_edges(). Includes_from_iterableoverride for binary ops and duplicate-add guard to avoidCUDA_ERROR_INVALID_VALUE.GraphNode.destroy(): removes a node and its edges from the graph definition viacuGraphDestroyNode, then zeroes the underlying handle to prevent stale memory access. Safe to call on already-destroyed nodes. Properties (type,pred,succ,handle) degrade gracefully toNoneor empty sets.GraphNode.is_valid: returnsFalseafterdestroy()has been calledGraphNode.pred/succsetters: clear existing edges and add new ones in bulkGraphDef.nodes()/edges(): returnsetinstead oftuplefor consistencycompile_parallel_kernels()ingraph_kernels.py,assert_mutable_set_interface()incollection_interface_testers.pyTest Coverage
TestMutateYRigclass: baseline, node destroy (single/multiple), edge insertion, join-node removal with rewiringtest_destroyed_node: verifies handle invalidation, graceful property degradation, edge-add failure on destroyed nodes, and double-destroy safetytest_adjacency_set_interface: exercises everyMutableSetmethod against a referencesettest_adjacency_set_pred_direction: verifies bidirectional edge visibilitytest_adjacency_set_property_setter: verifies bulk edge replacement via setterstest_add_wrong_type,test_cross_graph_edge,test_self_edge: error-path coveragetest_convert_linear_to_fan_in: rewires a sequential graph into parallel fan-in topologyRelated Work
_graph_def/subpackage refactor fromgraph-updatesbranch