cuda.core: document the canonical resource-lifetime pattern in AGENTS.md#2234
Open
rparolin wants to merge 1 commit into
Open
cuda.core: document the canonical resource-lifetime pattern in AGENTS.md#2234rparolin wants to merge 1 commit into
rparolin wants to merge 1 commit into
Conversation
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>
|
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
Documents the canonical CUDA resource-lifetime pattern in
cuda_core/AGENTS.md,so future contributions route resource ownership through the existing C++
std::shared_ptrhandle 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
*Handle(not a rawhandle +
_owningflag);close()isself._handle.reset(); no__dealloc__/__del__that callscu*Destroy; structural dependenciesembedded in the C++ box (not
_parent_ref/_source_refPython keepalives);create_*_handle+get_last_error();TaggedHandlefor identical integerhandle types (
CUdeviceptr/CUtexObject/CUsurfObject). Points at_cpp/DESIGN.md,_cpp/REGISTRY_DESIGN.md, and_stream/_event/_bufferas reference consumers.
__dealloc__where possible" (the instruction that led to the divergent pattern), to scope
__dealloc__/__del__to non-resource finalization and defer resourcecleanup to the handle deleter.
Docs only; no code or behavior change.
🤖 Generated with Claude Code