Skip to content

fix(cuda.core): route pool-backed MR buffers through deallocate() - #2620

Open
atiaomar1978-hub wants to merge 4 commits into
NVIDIA:mainfrom
atiaomar1978-hub:fix/pool-backed-mr-deallocate-2615
Open

fix(cuda.core): route pool-backed MR buffers through deallocate()#2620
atiaomar1978-hub wants to merge 4 commits into
NVIDIA:mainfrom
atiaomar1978-hub:fix/pool-backed-mr-deallocate-2615

Conversation

@atiaomar1978-hub

@atiaomar1978-hub atiaomar1978-hub commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

closes #2615

Pool-backed memory resources (DeviceMemoryResource, PinnedMemoryResource, ManagedMemoryResource) and GraphMemoryResource previously returned buffers whose C++ deleter called cuMemFreeAsync directly, bypassing Python deallocate() overrides.

This change wraps raw pool/async allocations with MR-owned device pointer handles (the same path as Buffer.from_handle(mr=...)), records the allocation stream at creation, and routes teardown through MemoryResource.deallocate().

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Test plan

  • pytest cuda_core/tests/test_memory.py -k "pool_backed_mr or dmr_deallocate_frees_pool_pointer or dmr_from_handle_deallocate"
  • CI source builds and GPU tests for cuda.core

Pool-backed and graph memory resources now wrap raw allocations with
MR-owned device pointer handles, matching Buffer.from_handle(mr=...).
Subclasses can observe or customize teardown via deallocate().

Fixes NVIDIA#2615

Signed-off-by: Omar Atie <atiaomar1978-hub@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 13, 2026
atiaomar1978-hub and others added 2 commits August 13, 2026 16:46
Use MR-owned handles only for Python subclasses so built-in pool/graph
MRs retain nogil cuMemFreeAsync teardown during interpreter shutdown.

Signed-off-by: Omar Atie <atiaomar1978-hub@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Thanks for filing #2615 — this PR addresses the inconsistent deallocation paths.

Approach

  • Python subclasses of pool-backed / graph MRs now wrap allocations with MR-owned handles (deviceptr_create_owned_by_mr), so overridden deallocate() is honored on close() / GC (matching Buffer.from_handle(mr=...)).
  • Built-in types keep the direct C++ cuMemFreeAsync deleter to preserve nogil teardown during interpreter shutdown.

Tests added

  • Subclass deallocate() invoked on close, GC, and with explicit stream (device + pinned pools)
  • Pool byte accounting for mr.allocate() and from_handle paths

Bugbot review: clean after the hybrid approach. Happy to adjust based on maintainer feedback.

Document MemoryResource subclass teardown behavior and add a 1.2.0
release note for pool-backed MR deallocate consistency.

Signed-off-by: Omar Atie <atiaomar1978-hub@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pool-backed MemoryResource buffers bypass overridden deallocate() methods

1 participant