Skip to content

cuda.core: document the canonical resource-lifetime pattern in AGENTS.md#2234

Open
rparolin wants to merge 1 commit into
NVIDIA:mainfrom
rparolin:feature/agents-resource-lifetime
Open

cuda.core: document the canonical resource-lifetime pattern in AGENTS.md#2234
rparolin wants to merge 1 commit into
NVIDIA:mainfrom
rparolin:feature/agents-resource-lifetime

Conversation

@rparolin

Copy link
Copy Markdown
Collaborator

Summary

Documents the canonical CUDA resource-lifetime pattern in cuda_core/AGENTS.md,
so future contributions route resource ownership through the existing C++
std::shared_ptr handle layer instead of re-implementing raw-handle +
__dealloc__ ownership.

This codifies the implementation guidance from the texture/surface review
(#2095, design issue #2188) — @Andy-Jost's note that the new types had diverged
from the handle architecture. The fix landed in #2095; this captures the rule so
it isn't re-learned.

Changes

  • New "Resource lifetime management" section: store a *Handle (not a raw
    handle + _owning flag); close() is self._handle.reset(); no
    __dealloc__/__del__ that calls cu*Destroy; structural dependencies
    embedded in the C++ box (not _parent_ref/_source_ref Python keepalives);
    create_*_handle + get_last_error(); TaggedHandle for identical integer
    handle types (CUdeviceptr/CUtexObject/CUsurfObject). Points at
    _cpp/DESIGN.md, _cpp/REGISTRY_DESIGN.md, and _stream/_event/_buffer
    as reference consumers.
  • Amends the "Semantics" guidance, which previously said "use __dealloc__
    where possible" (the instruction that led to the divergent pattern), to scope
    __dealloc__/__del__ to non-resource finalization and defer resource
    cleanup to the handle deleter.

Docs only; no code or behavior change.

🤖 Generated with Claude Code

Adds a "Resource lifetime management" section codifying that CUDA
resource-owning types must route lifetime through the C++ std::shared_ptr
handle layer (store a *Handle, close() == reset(), no __dealloc__ that calls
cu*Destroy, structural dependencies embedded in the box rather than Python
keepalive refs, create_*_handle + get_last_error, TaggedHandle for identical
integer handle types). Also amends the "Semantics" guidance, which previously
said "use __dealloc__ where possible" — the instruction that led to the
divergent raw-handle pattern flagged in review (PR NVIDIA#2095 / NVIDIA#2188).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rparolin rparolin added this to the cuda.core next milestone Jun 17, 2026
@rparolin rparolin added documentation Improvements or additions to documentation cuda.core Everything related to the cuda.core module labels Jun 17, 2026
@rparolin rparolin self-assigned this Jun 17, 2026
@github-actions

Copy link
Copy Markdown

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 documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant