Fix Buffer.from_handle(mr=...) not calling mr.deallocate()#1625
Open
Andy-Jost wants to merge 1 commit intoNVIDIA:mainfrom
Open
Fix Buffer.from_handle(mr=...) not calling mr.deallocate()#1625Andy-Jost wants to merge 1 commit intoNVIDIA:mainfrom
Andy-Jost wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
The RAII resource handle migration broke the contract where Buffer.from_handle(mr=mr) calls mr.deallocate() on close or GC. Add deviceptr_create_with_mr() which invokes a registered callback at destruction time, passing the deallocation stream from the handle. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Contributor
Author
|
/ok to test c7fdab7 |
|
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
Buffer.from_handle(ptr, size, mr=mr)now callsmr.deallocate(ptr, size, stream)when the buffer is closed or garbage collected, restoring the pre-RAII behavior.deviceptr_create_with_mr()to the resource handle infrastructure, whose shared_ptr deleter invokes a registered callback with the pointer, size, and deallocation stream.cuda.core.Streambefore callingmr.deallocate().streamparameter fromBuffer._init.Closes #1619
Changes
resource_handles.hpp/.cpp: AddMRDeallocCallbacktype,register_mr_dealloc_callback(), anddeviceptr_create_with_mr()._resource_handles.pxd/.pyx: Expose the new types and functions to Cython._buffer.pyx: Register the deallocation callback at module init; usedeviceptr_create_with_mrwhenmris provided inBuffer._init; update docstrings._legacy.py: Remove unusedstreamargument fromBuffer._initcalls.tests/helpers/buffers.py: AddTrackingMRtest helper.tests/test_memory.py: Addtest_mr_deallocate_called_on_closeandtest_mr_deallocate_called_on_gc.Test Plan
mr.deallocate()is called on explicitclose()and on GCMade with Cursor