@@ -12,6 +12,7 @@ from libc.string cimport memset, memcpy
1212from cuda.bindings cimport cydriver
1313
1414from cuda.core.experimental._stream cimport Stream as cyStream
15+ from cuda.core.experimental._stream cimport default_stream
1516from cuda.core.experimental._utils.cuda_utils cimport (
1617 _check_driver_error as raise_if_driver_error,
1718 check_or_create_options,
@@ -30,7 +31,7 @@ import platform
3031import weakref
3132
3233from cuda.core.experimental._dlpack import DLDeviceType, make_py_capsule
33- from cuda.core.experimental._stream import Stream, default_stream
34+ from cuda.core.experimental._stream import Stream
3435from cuda.core.experimental._utils.cuda_utils import ( driver, Transaction, get_binding_version )
3536
3637if platform.system() == " Linux" :
@@ -73,6 +74,8 @@ cdef class _cyMemoryResource:
7374
7475class MemoryResourceAttributes (abc.ABC ):
7576
77+ __slots__ = ()
78+
7679 @property
7780 @abc.abstractmethod
7881 def is_device_accessible (self ) -> bool:
@@ -107,8 +110,6 @@ cdef class Buffer(_cyBuffer, MemoryResourceAttributes):
107110
108111 Support for data interchange mechanisms are provided by DLPack.
109112 """
110- cdef dict __dict__ # required if inheriting from both Cython/Python classes
111-
112113 def __cinit__ (self ):
113114 self ._ptr = 0
114115 self ._size = 0
@@ -369,8 +370,6 @@ cdef class MemoryResource(_cyMemoryResource, MemoryResourceAttributes, abc.ABC):
369370 hold a reference to self, the buffer properties are retrieved simply by looking up the underlying
370371 memory resource's respective property.)
371372 """
372- cdef dict __dict__ # required if inheriting from both Cython/Python classes
373-
374373 cdef void _deallocate(self , intptr_t ptr, size_t size, cyStream stream) noexcept:
375374 self .deallocate(ptr, size, stream)
376375
@@ -585,7 +584,7 @@ class DeviceMemoryResourceAttributes:
585584# This enables buffer serialization, as buffers can reduce to a pair
586585# of comprising the memory resource UUID (the key into this registry)
587586# and the serialized buffer descriptor.
588- _ipc_registry = {}
587+ cdef object _ipc_registry = weakref.WeakValueDictionary()
589588
590589
591590cdef class DeviceMemoryResource(MemoryResource):
@@ -675,7 +674,6 @@ cdef class DeviceMemoryResource(MemoryResource):
675674 bint _is_mapped
676675 object _uuid
677676 IPCAllocationHandle _alloc_handle
678- dict __dict__ # required if inheriting from both Cython/Python classes
679677 object __weakref__
680678
681679 def __cinit__ (self ):
@@ -759,8 +757,6 @@ cdef class DeviceMemoryResource(MemoryResource):
759757 with nogil:
760758 HANDLE_RETURN(cydriver.cuMemPoolDestroy(self ._mempool_handle))
761759 finally :
762- if self .is_mapped:
763- self .unregister()
764760 self ._dev_id = cydriver.CU_DEVICE_INVALID
765761 self ._mempool_handle = NULL
766762 self ._attributes = None
@@ -806,13 +802,6 @@ cdef class DeviceMemoryResource(MemoryResource):
806802 self._uuid = uuid
807803 return self
808804
809- def unregister(self ):
810- """ Unregister this mapped memory resource."""
811- assert self .is_mapped
812- if _ipc_registry is not None : # can occur during shutdown catastrophe
813- with contextlib.suppress(KeyError ):
814- del _ipc_registry[self .uuid]
815-
816805 @property
817806 def uuid(self ) -> Optional[uuid.UUID]:
818807 """
@@ -1019,9 +1008,7 @@ class LegacyPinnedMemoryResource(MemoryResource):
10191008 APIs.
10201009 """
10211010
1022- def __init__ (self ):
1023- # TODO: support flags from cuMemHostAlloc?
1024- self ._handle = None
1011+ # TODO: support creating this MR with flags that are later passed to cuMemHostAlloc?
10251012
10261013 def allocate (self , size_t size , stream: Stream = None ) -> Buffer:
10271014 """Allocate a buffer of the requested size.
@@ -1080,7 +1067,6 @@ class _SynchronousMemoryResource(MemoryResource):
10801067 __slots__ = (" _dev_id" ,)
10811068
10821069 def __init__ (self , device_id : int | Device ):
1083- self ._handle = None
10841070 self ._dev_id = getattr (device_id, ' device_id' , device_id)
10851071
10861072 def allocate (self , size , stream = None ) -> Buffer:
0 commit comments