Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 328
Fix Buffer.from_handle(mr=...) not calling mr.deallocate()#1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -39,7 +39,7 @@ | ||
| from cuda.core._utils.cuda_utils import CUDAError, handle_return | ||
| from cuda.core.utils import StridedMemoryView | ||
| from helpers import IS_WINDOWS, supports_ipc_mempool | ||
| from helpers.buffers import DummyUnifiedMemoryResource | ||
| from helpers.buffers import DummyUnifiedMemoryResource, TrackingMR | ||
| from conftest import ( | ||
| create_managed_memory_resource_or_skip, | ||
| @@ -471,6 +471,49 @@ def test_buffer_external_managed(change_device): | ||
| handle_return(driver.cuMemFree(ptr)) | ||
| def test_mr_deallocate_called_on_close(): | ||
| """Buffer.from_handle(mr=mr) calls mr.deallocate() on close (issue #1619).""" | ||
| device = Device() | ||
| device.set_current() | ||
| mr = TrackingMR() | ||
| buf = mr.allocate(1024) | ||
| assert len(mr.active) == 1 | ||
| buf.close() | ||
| assert len(mr.active) == 0 | ||
| def test_mr_deallocate_called_on_gc(): | ||
| """Buffer.from_handle(mr=mr) calls mr.deallocate() on GC (issue #1619).""" | ||
| import gc | ||
| device = Device() | ||
| device.set_current() | ||
| mr = TrackingMR() | ||
| buf = mr.allocate(1024) | ||
| assert len(mr.active) == 1 | ||
| del buf | ||
| gc.collect() | ||
| assert len(mr.active) == 0 | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two new tests cover deftest_mr_deallocate_receives_stream():
device=Device()
device.set_current()
stream=device.create_stream()
received= {}
classStreamCaptureMR(TrackingMR):
defdeallocate(self, ptr, size, stream=None):
received['stream'] =streamsuper().deallocate(ptr, size, stream)
mr=StreamCaptureMR()
buf=mr.allocate(1024)
buf.close(stream)
assertreceived['stream'] isnotNone | ||
| def test_mr_deallocate_receives_stream(): | ||
| """Buffer.close(stream) forwards the stream to mr.deallocate() (issue #1619).""" | ||
| device = Device() | ||
| device.set_current() | ||
| stream = device.create_stream() | ||
| received = {} | ||
| class StreamCaptureMR(TrackingMR): | ||
| def deallocate(self, ptr, size, stream=None): | ||
| received["stream"] = stream | ||
| super().deallocate(ptr, size, stream) | ||
| mr = StreamCaptureMR() | ||
| buf = mr.allocate(1024) | ||
| buf.close(stream) | ||
| assert received["stream"].handle == stream.handle | ||
| def test_memory_resource_and_owner_disallowed(): | ||
| with pytest.raises(ValueError, match="cannot be both specified together"): | ||
| a = (ctypes.c_byte * 20)() | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.