[FEA]: Add a `release()` method to `cuda.core.Buffer` to side-step the Python garbage collector
Nobody has claimed this yet.
- Dominant language
- Cython
- Stars
- 3.4k
- Forks
- 329
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 116
Description
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct
Area
cuda.core
Is your feature request related to a problem? Please describe.
@realarnavgoel brought up this issue offline that we currently have a fallback weak finalizer
https://github.com/NVIDIA/cuda-python/blob/d425a8895bd778fffb993263dbf5d9bc631fea22/cuda_core/cuda/core/experimental/_memory.py#L51
in case users forget to explicitly call .close() to free the memory. This could interfere with projects such as nvmath-python and nvSHMEM who require explicit control over the buffer lifetime and deallocation timing.
Describe the solution you'd like
We discussed offline and came up with this proposal that we'll add a .release() method to the buffer object. The idea is that if it is called, the weak finalizer will be unregistered, so that the only way to free the buffer is to call .close() explicitly later.
Describe alternatives you've considered
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in cuda_core/cuda/core/experimental/_memory.py around line 51, where the fallback weak finalizer is defined, and trace how the Buffer object's close path manages it. The work is done when release() unregisters that finalizer while close() remains the explicit way to free the buffer; check nearby Buffer implementation details for the relevant behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100