Skip to content

cuda.core: close the old buffer when a VMM grow moves the mapping - #2880

Open
Andy-Jost wants to merge 2 commits into
NVIDIA:mainfrom
Andy-Jost:ajost/issue-2877
Open

Andy-Jost wants to merge 2 commits into
NVIDIA:mainfrom
Andy-Jost:ajost/issue-2877

Conversation

@Andy-Jost

@Andy-Jost Andy-Jost commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2877. The slow path of VirtualMemoryResource.modify_allocation() unmapped the old VA range, remapped the physical memory into the new range, freed the old reservation by hand, and then reset the old buffer's handle with Buffer._clear(). That reset runs the handle's deleter, which calls mr.deallocate() on the range that was just freed; since #2759 the failing cuMemRetainAllocationHandle is reported as a CUDAWarning (visible in CI on test_vmm_allocator_grow_allocation), and before that it was silently swallowed.

Changes

  • _virtual_memory_resource.py: the slow path maps the old physical memory into the new range as a second mapping (virtual aliasing, which the VMM APIs support) and then closes the old buffer. Closing runs deallocate() on a range that is still mapped, so the old range is unmapped, its reservation freed, and its handle reference released through the normal path. The remap-on-rollback undo step, which swallowed its own errors, is gone: the old mapping is never removed before the transaction commits, so a failure leaves the old buffer untouched.
  • tests/test_memory.py: forces the slow path by reserving the address range right after the buffer, grows it under assert_no_cuda_warning(), and checks that the old buffer is closed and the old contents are readable through the new mapping.
  • Release note for 1.3.0.

Related Work

🤖 Generated with Claude Code

@Andy-Jost Andy-Jost added this to the cuda.core 1.3.0 milestone Sep 16, 2026
@Andy-Jost Andy-Jost added bug Something isn't working P0 High priority - Must do! cuda.core Everything related to the cuda.core module labels Sep 16, 2026
@Andy-Jost Andy-Jost self-assigned this Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@copy-pr-bot

copy-pr-bot Bot commented Sep 16, 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.

@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test bd6b7d1

@Andy-Jost

Copy link
Copy Markdown
Contributor Author

/ok to test 23599fb

Andy-Jost and others added 2 commits September 17, 2026 16:13
The slow path of VirtualMemoryResource.modify_allocation unmapped the
old VA range, remapped the physical memory into the new range, freed
the old reservation by hand and then reset the old buffer's handle with
Buffer._clear(). That reset runs the handle's deleter, which calls
mr.deallocate() on the range that was just freed. The failing
cuMemRetainAllocationHandle is reported as a CUDAWarning since NVIDIA#2759
and was silently swallowed before.

Map the old physical memory into the new range as a second mapping
instead, which the VMM APIs allow (virtual aliasing), and then close the
old buffer. Closing runs deallocate() on a range that is still mapped,
so the old range is unmapped, its reservation freed and its handle
reference released through the normal path. The remap-on-rollback undo
step, which swallowed its own errors, is no longer needed because the
old mapping is never removed before the transaction commits.

Issue NVIDIA#2877

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
The slow-path regression test fills the buffer with cuMemsetD8 and grows
it at once. Memset is asynchronous with respect to the host, and on WDDM
the batched kernel can still be pending when the grow unmaps the old
range, so it faults with a sticky CUDA_ERROR_ILLEGAL_ADDRESS that took
every later test in the job down with it. Synchronize before the grow.

Issue NVIDIA#2877

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.core: VirtualMemoryResource grow path's Buffer._clear() re-triggers mr.deallocate() on an already-freed VA range

1 participant