cuda.core: make buffer cleanup context-safe - #2455
Conversation
Ensure deferred and MR-backed buffer destruction activates the allocation or deallocation-stream context, preventing invalid-context leaks after callers clear their current context.
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
@Andy-Jost is there any performance concerns here? I vaguely remember some microbenchmarking you did but I don't recall if it was related to this PR. |
@kkraus14 I think you're referring to the discussion in #2311, which showed ~9ns for a current-context check and ~37ns for a check-and-switch. That came up when discussing |
|
/ok to test |
|
Restore fixture-managed contexts in direct cleanup tests and run deferred pending-call cleanup in a subprocess so parallel workers cannot leak thread-local state.
|
/ok to test |
Resolve allocation and stream contexts at the Buffer boundary so the C++ resource layer only retains and restores explicit context handles.
|
/ok to test |
Summary
Make device-pointer cleanup retain and activate the CUDA context required by the allocation or its deallocation stream. This prevents deferred graph attachment cleanup and ordinary
Bufferdestruction from leaking memory when no context is current on the cleanup thread.Changes
MemoryResource.deallocate()callbacks, then restore the caller's exact prior context.CUDA_ERROR_INVALID_CONTEXTas successful memory-pool deallocation.Review guide
resource_handles.cpp/.hppfor context ownership, selection, and scoped restoration._resource_handles.pyxfor driver function-pointer plumbing.Related Work