Skip to content

cuda.core: retain graph attachments with per-node user objects#2357

Draft
Andy-Jost wants to merge 14 commits into
NVIDIA:mainfrom
Andy-Jost:graph-node-attachment-user-objects
Draft

cuda.core: retain graph attachments with per-node user objects#2357
Andy-Jost wants to merge 14 commits into
NVIDIA:mainfrom
Andy-Jost:graph-node-attachment-user-objects

Conversation

@Andy-Jost

@Andy-Jost Andy-Jost commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the graph attachment lifetime problem described in #2350. Replace the mutable graph-wide attachment table with one immutable CUDA user object per resource-bearing node. This lets CUDA propagate each node's owners independently to graph clones and executable graphs, preventing source-graph mutation or node-handle reuse from invalidating existing executions.

Changes

  • Add transactional per-node attachment preparation and commit in the resource-handle layer, with metadata shared across root, child, and conditional graph views.
  • Prepare owners before explicit or captured node creation, eliminating unsafe best-effort rollback after CUDA has committed a node.
  • Make node deletion failure-atomic and release only the source graph's attachment reference after successful deletion.
  • Add regressions for clone, exec, child-view, whole-update, failed-delete, and multi-owner lifetime behavior.

Review guide

Suggested review order:

  1. Ownership model: Start with GRAPH_ATTACHMENTS.md, then review resource_handles.cpp/.hpp. Focus on transactional prepare/commit/abandon, non-owning metadata, node deletion, updates, and graph hierarchy ownership.
  2. Cython integration: Review _resource_handles.* and graph/*.pyx. Each resource-bearing operation should prepare ownership before the driver call, commit only after success, and preserve prior ownership on failure.
  3. Correctness evidence: Review the graph lifetime, mutation, and update tests. They cover cloning/instantiation, source-node deletion, failed mutations, captured and child graphs, and independent executable lifetimes.

Most remaining changes are mechanical wiring, tests, or documentation around that ownership state machine.

Related Work

@Andy-Jost Andy-Jost added this to the cuda.core next milestone Jul 14, 2026
@Andy-Jost Andy-Jost added P0 High priority - Must do! feature New feature or request cuda.core Everything related to the cuda.core module labels Jul 14, 2026
@Andy-Jost Andy-Jost self-assigned this Jul 14, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
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.

@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test

@Andy-Jost Andy-Jost force-pushed the graph-node-attachment-user-objects branch from d7e8d3e to 945672d Compare July 15, 2026 00:42
@github-actions

Copy link
Copy Markdown

@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test

@Andy-Jost Andy-Jost force-pushed the graph-node-attachment-user-objects branch 2 times, most recently from 1d399c7 to a8a5879 Compare July 15, 2026 18:49
Andy-Jost added 10 commits July 15, 2026 12:40
Give each resource-bearing graph node an immutable CUDA user object so clones and executable graphs no longer share mutable attachment ownership. Prepare bundles before node creation and share non-owning metadata across child and conditional graph views.
Destroy the CUDA node before invalidating Python/C++ handles, then release only the source graph's attachment reference. Existing execs retain deleted-node owners while failed graph-memory deletions preserve the node and its metadata.
Store the non-standard-layout transaction box behind an opaque shared value instead of recovering it with offsetof. This removes the compiler warning while preserving rollback ownership.
Exercise clone, child-view, whole-update, and two-owner bundle behavior under per-node user objects. Also clean up raw graph handles in existing lifetime tests and update slot-table terminology.
Document the per-node CUDA user-object model, hierarchy-wide metadata, transaction lifecycle, struct responsibilities, and correctness invariants alongside the implementation.
Keep rollback ownership single-valued across allocation failures, make post-destroy metadata purging allocation-free, and clarify graph hierarchy synchronization.
Represent empty ownership as a tombstone transaction so successful node updates can release obsolete graph references without installing a replacement user object.
Remap managed attachment records into internal child-graph clones so deleting cloned nodes releases their graph-owned references without waiting for the entire parent graph to die.
Document why queue initialization is serialized and why pending-call scheduling may need a later retry.
Exercise subgraph deletion, in-flight launches, failed transactions, and independent executable references so attachment lifetime guarantees remain regression-tested.
@Andy-Jost Andy-Jost force-pushed the graph-node-attachment-user-objects branch from a8a5879 to c3fce2c Compare July 15, 2026 19:41
Keep each CUDA user object and its owners in one payload, and make prepared attachment handles own their transaction state directly.
Set a current device explicitly so the isolated probe remains valid on drivers that require a context for graph creation.
Keep the resource-handle guide focused on the general handle pattern and document deferred user-object cleanup with the graph attachment lifecycle.
Make graph attachments intrusive cleanup items so CUDA callbacks can queue each payload directly without a separate envelope allocation.
@Andy-Jost Andy-Jost force-pushed the graph-node-attachment-user-objects branch from 807cac8 to 6d7ae74 Compare July 15, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module feature New feature or request P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.core: retain graph node attachments as per-node CUDA user objects

1 participant