Skip to content

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

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

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. Each resource-bearing node version now has an immutable attachment owned through its own CUDA user object, so source-graph mutation cannot release resources still used by clones, executable graphs, or in-flight launches.

Implementing that ownership change also required cuda-core's metadata to follow CUDA's graph topology and mutation boundaries. Each graph hierarchy keeps root, child, and conditional graph state coherent; clone and embed paths copy and rekey that metadata, and prepare/commit operations publish it only after the corresponding CUDA mutation succeeds. Together, these pieces make cuda-core's bookkeeping match the lifetimes CUDA actually enforces.

Changes

  • Replace the mutable graph-wide slot table with complete per-node attachment bundles and user objects.
  • Track canonical root, child, and conditional graphs in a shared hierarchy while keeping attachment and node-handle metadata scoped to each graph.
  • Copy and rekey attachment metadata when CUDA embeds cloned child graphs, and invalidate borrowed graph/node handles when CUDA destroys their backing objects.
  • Preserve captured host callback owners when CUDA commits a callback but its node cannot be recovered.
  • Keep graph mutation and metadata updates failure-aware via prepare/commit attachment transactions and failure-atomic deletion.
  • Add contributor design documentation, release notes, and regressions across graph definitions, clones, executable updates, and launches.

Review guide

  1. Start with cuda_core/cuda/core/_cpp/GRAPH_ATTACHMENTS.md for the ownership model, graph hierarchy, common operations, and invariants.
  2. Review resource_handles.cpp/.hpp for per-node user objects, canonical graph boxes, clone metadata import, handle invalidation, and deferred cleanup.
  3. Review _resource_handles.* and graph/*.pyx for the Cython integration and CUDA-operation ordering.
  4. Review the graph lifetime, mutation, builder, and update tests for correctness evidence and failure coverage.

Test coverage

  • pre-commit run --all-files
  • Full local cuda-core test suite on GPU

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 4 times, most recently from 807cac8 to 6d7ae74 Compare July 15, 2026 23:10
@Andy-Jost
Andy-Jost force-pushed the graph-node-attachment-user-objects branch from 6d7ae74 to e7391d3 Compare July 17, 2026 23:38
@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 e7391d3 to 8babae5 Compare July 18, 2026 00:10
Andy-Jost added 10 commits July 20, 2026 08:06
Preserve the validated lifetime and failure scenarios as executable specifications for the metadata redesign, alongside independent cleanup clarifications.
Establish canonical per-graph boxes, stable hierarchy ownership, and Level 1 graph identity before rebuilding attachment operations.
Give root and child graph handles stable per-graph boxes while sharing one hierarchy control block and registry identity.
Replace the mutable graph-wide slot table with complete per-node user objects and intrusive deferred cleanup.
Copy and rekey source attachment metadata into embedded graph hierarchies before publishing their canonical boxes.
Unregister and tombstone child graph boxes after CUDA destroys their owner while preserving stable storage for existing handles.
Allow graph-level anonymous attachments so a captured host callback stays safe when CUDA commits it but its node cannot be recovered.
Verify anonymous capture retention and proactive invalidation of child and conditional graph views.
Orient contributors to versioned node ownership, graph hierarchy metadata, clone propagation, invalidation, and deferred cleanup.
Make node identity atomic, preserve tombstoned graph identity, retry deferred cleanup safely, and cover final-reference launch ownership.
Document corrected graph attachment lifetime and callback-safe resource release.
Retain attachment owners and preallocate metadata before CUDA graph mutations so failures cannot leave nodes with unretained resources.
Carry rollback through the prepared attachment deleter so consumer extension modules do not depend on an out-of-line C++ symbol.
@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test

Preserve the general no-invalidation guarantee while documenting borrowed child graphs as a narrow driver-owned exception, and tighten implementation comments for reviewers.
@Andy-Jost
Andy-Jost marked this pull request as ready for review July 20, 2026 19:20
@Andy-Jost
Andy-Jost requested review from leofang and mdboom and removed request for leofang July 20, 2026 19:22
@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test

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