44
55from __future__ import annotations
66
7- from libc.stdint cimport uintptr_t
7+ from libc.stdint cimport intptr_t
88from cuda.core.experimental._utils.cuda_utils cimport (
99 _check_driver_error as raise_if_driver_error,
1010 check_or_create_options,
@@ -51,7 +51,7 @@ cdef class Buffer:
5151 """
5252
5353 cdef:
54- uintptr_t _ptr
54+ intptr_t _ptr
5555 size_t _size
5656 object _mr
5757 object _ptr_obj
@@ -63,15 +63,15 @@ cdef class Buffer:
6363 @classmethod
6464 def _init (cls , ptr: DevicePointerT , size_t size , mr: MemoryResource | None = None , stream: Stream | None = None ):
6565 cdef Buffer self = Buffer.__new__ (cls )
66- self ._ptr = < uintptr_t > (int (ptr))
66+ self ._ptr = < intptr_t > (int (ptr))
6767 self ._ptr_obj = ptr
6868 self ._size = size
6969 self ._mr = mr
7070 self ._alloc_stream = stream
7171 return self
7272
7373 def __del__ (self ):
74- self .close()
74+ self .close(self ._alloc_stream )
7575
7676 cpdef close(self , stream: Stream = None ):
7777 """ Deallocate this buffer asynchronously on the given stream.
@@ -86,7 +86,7 @@ cdef class Buffer:
8686 the allocation stream is used.
8787 """
8888 if self ._ptr and self ._mr is not None :
89- if stream is None :
89+ if stream is None and self ._alloc_stream is not None :
9090 stream = self ._alloc_stream
9191 self ._mr.deallocate(self ._ptr, self ._size, stream)
9292 self ._ptr = 0
@@ -763,8 +763,8 @@ class DeviceMemoryResource(MemoryResource):
763763 The size of the buffer to deallocate, in bytes.
764764 stream : Stream
765765 The stream on which to perform the deallocation asynchronously.
766- When the buffer destructor is invoked by the gc instead of explicitly destroyed
767- via the :meth:`Buffer.close` method, the allocation stream is used.
766+ If the buffer is deallocated without an explicit stream, the allocation stream
767+ is used.
768768 """
769769 err, = driver.cuMemFreeAsync(ptr, stream.handle)
770770 raise_if_driver_error(err)
0 commit comments