From f3c9d0f277d90e21c75aefbbc82dfd40e85bf96e Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Wed, 8 Oct 2025 13:31:56 +0000 Subject: [PATCH 1/3] avoid adding potentially problematic __dict__ to every child class --- cuda_core/cuda/core/experimental/_memory.pyx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cuda_core/cuda/core/experimental/_memory.pyx b/cuda_core/cuda/core/experimental/_memory.pyx index c535ca5682..62160e1cca 100644 --- a/cuda_core/cuda/core/experimental/_memory.pyx +++ b/cuda_core/cuda/core/experimental/_memory.pyx @@ -73,6 +73,8 @@ cdef class _cyMemoryResource: class MemoryResourceAttributes(abc.ABC): + __slots__ = () + @property @abc.abstractmethod def is_device_accessible(self) -> bool: @@ -107,8 +109,6 @@ cdef class Buffer(_cyBuffer, MemoryResourceAttributes): Support for data interchange mechanisms are provided by DLPack. """ - cdef dict __dict__ # required if inheriting from both Cython/Python classes - def __cinit__(self): self._ptr = 0 self._size = 0 @@ -369,8 +369,6 @@ cdef class MemoryResource(_cyMemoryResource, MemoryResourceAttributes, abc.ABC): hold a reference to self, the buffer properties are retrieved simply by looking up the underlying memory resource's respective property.) """ - cdef dict __dict__ # required if inheriting from both Cython/Python classes - cdef void _deallocate(self, intptr_t ptr, size_t size, cyStream stream) noexcept: self.deallocate(ptr, size, stream) @@ -675,7 +673,6 @@ cdef class DeviceMemoryResource(MemoryResource): bint _is_mapped object _uuid IPCAllocationHandle _alloc_handle - dict __dict__ # required if inheriting from both Cython/Python classes object __weakref__ def __cinit__(self): From 5d64b517eb7c46e8c8e08d8f3d9c345bf789de17 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Wed, 8 Oct 2025 15:01:57 +0000 Subject: [PATCH 2/3] remove unnecessary attribute initializaiton --- cuda_core/cuda/core/experimental/_memory.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cuda_core/cuda/core/experimental/_memory.pyx b/cuda_core/cuda/core/experimental/_memory.pyx index 62160e1cca..f46f78bc1e 100644 --- a/cuda_core/cuda/core/experimental/_memory.pyx +++ b/cuda_core/cuda/core/experimental/_memory.pyx @@ -1018,7 +1018,7 @@ class LegacyPinnedMemoryResource(MemoryResource): def __init__(self): # TODO: support flags from cuMemHostAlloc? - self._handle = None + pass def allocate(self, size_t size, stream: Stream = None) -> Buffer: """Allocate a buffer of the requested size. @@ -1077,7 +1077,6 @@ class _SynchronousMemoryResource(MemoryResource): __slots__ = ("_dev_id",) def __init__(self, device_id : int | Device): - self._handle = None self._dev_id = getattr(device_id, 'device_id', device_id) def allocate(self, size, stream=None) -> Buffer: From 46d1e3439fe737a753832a13f334cb1b47ab8843 Mon Sep 17 00:00:00 2001 From: Leo Fang Date: Wed, 8 Oct 2025 11:55:44 -0400 Subject: [PATCH 3/3] nit: remove __init__ --- cuda_core/cuda/core/experimental/_memory.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cuda_core/cuda/core/experimental/_memory.pyx b/cuda_core/cuda/core/experimental/_memory.pyx index f46f78bc1e..cd2956ea28 100644 --- a/cuda_core/cuda/core/experimental/_memory.pyx +++ b/cuda_core/cuda/core/experimental/_memory.pyx @@ -1016,9 +1016,7 @@ class LegacyPinnedMemoryResource(MemoryResource): APIs. """ - def __init__(self): - # TODO: support flags from cuMemHostAlloc? - pass + # TODO: support creating this MR with flags that are later passed to cuMemHostAlloc? def allocate(self, size_t size, stream: Stream = None) -> Buffer: """Allocate a buffer of the requested size.