cuda.core: capture complete Buffer deallocation recipe at creation - #2526
Open
Andy-Jost wants to merge 4 commits into
Open
cuda.core: capture complete Buffer deallocation recipe at creation#2526Andy-Jost wants to merge 4 commits into
Andy-Jost wants to merge 4 commits into
Conversation
Record a DeallocationStream at device-pointer creation so default-stream tokens pin the allocation context (and PTDS the allocating thread) instead of relying on ambient state at free time.
Make the deallocation stream's context current around free/unmap/MR cleanup so destruction no longer depends on ambient CUDA context, and wire cuCtxSetCurrent into the resource-handles driver table.
Add keyword-only stream= on Buffer/ManagedBuffer.from_handle when mr owns the pointer, bind it at construction, and cover teardown with no or foreign current context.
Stop treating CUDA_ERROR_INVALID_CONTEXT as a successful pool free, and let explicit mr.deallocate() raise; destruction still contains errors in the callback. Document PTDS deallocation ordering on the stream parameters and note the context-safe Buffer teardown fix in the 1.2.0 release notes.
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
Closes #2497. Supersedes the approach in draft #2455.
Buffer / device-pointer destruction can run with no suitable CUDA context current (deferred graph cleanup, off-thread GC). Owning paths now capture a complete free-ordering recipe at allocation or binding time — a
StreamHandlewith a bound context for default-stream tokens — and activate that context at teardown instead of relying on ambient thread state.Changes
DeallocationStream(stream handle + optional PTDS host-thread id) and bind context into default-stream tokens when recording free ordering.stream=onBuffer.from_handle/ManagedBuffer.from_handlewhenmr=owns the pointer, so the destructor is not the first place a stream is chosen.CUDA_ERROR_INVALID_CONTEXTas success in_MemPool.deallocate, and let explicitmr.deallocate()raise; destruction still contains errors in the MR dealloc callback.streamparameters and note the fix in the 1.2.0 release notes.PTDS remains app-ordered for cross-thread / deferred free (no attach-time warning): graph kernel-arg retention cannot be detected completely without traversing argument objects, and an incomplete warning would fire on correct single-threaded PTDS usage.
Related