Skip to content

Commit 4754292

Browse files
authored
Avoid adding __dict__ to every child class (#1104)
* avoid adding potentially problematic __dict__ to every child class * remove unnecessary attribute initializaiton * nit: remove __init__
1 parent 7c8a395 commit 4754292

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

cuda_core/cuda/core/experimental/_memory.pyx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ cdef class _cyMemoryResource:
7373

7474
class MemoryResourceAttributes(abc.ABC):
7575

76+
__slots__ = ()
77+
7678
@property
7779
@abc.abstractmethod
7880
def is_device_accessible(self) -> bool:
@@ -107,8 +109,6 @@ cdef class Buffer(_cyBuffer, MemoryResourceAttributes):
107109
108110
Support for data interchange mechanisms are provided by DLPack.
109111
"""
110-
cdef dict __dict__ # required if inheriting from both Cython/Python classes
111-
112112
def __cinit__(self):
113113
self._ptr = 0
114114
self._size = 0
@@ -369,8 +369,6 @@ cdef class MemoryResource(_cyMemoryResource, MemoryResourceAttributes, abc.ABC):
369369
hold a reference to self, the buffer properties are retrieved simply by looking up the underlying
370370
memory resource's respective property.)
371371
"""
372-
cdef dict __dict__ # required if inheriting from both Cython/Python classes
373-
374372
cdef void _deallocate(self, intptr_t ptr, size_t size, cyStream stream) noexcept:
375373
self.deallocate(ptr, size, stream)
376374

@@ -675,7 +673,6 @@ cdef class DeviceMemoryResource(MemoryResource):
675673
bint _is_mapped
676674
object _uuid
677675
IPCAllocationHandle _alloc_handle
678-
dict __dict__ # required if inheriting from both Cython/Python classes
679676
object __weakref__
680677

681678
def __cinit__(self):
@@ -1010,9 +1007,7 @@ class LegacyPinnedMemoryResource(MemoryResource):
10101007
APIs.
10111008
"""
10121009

1013-
def __init__(self):
1014-
# TODO: support flags from cuMemHostAlloc?
1015-
self._handle = None
1010+
# TODO: support creating this MR with flags that are later passed to cuMemHostAlloc?
10161011

10171012
def allocate(self, size_t size, stream: Stream = None) -> Buffer:
10181013
"""Allocate a buffer of the requested size.
@@ -1071,7 +1066,6 @@ class _SynchronousMemoryResource(MemoryResource):
10711066
__slots__ = ("_dev_id",)
10721067

10731068
def __init__(self, device_id : int | Device):
1074-
self._handle = None
10751069
self._dev_id = getattr(device_id, 'device_id', device_id)
10761070

10771071
def allocate(self, size, stream=None) -> Buffer:

0 commit comments

Comments
 (0)