Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace a few more __del__ by __dealloc__
  • Loading branch information
leofang committed Oct 3, 2025
commit b713c5c4160324e401c0587e244f0f94097e182a
24 changes: 8 additions & 16 deletions cuda_core/cuda/core/experimental/_memory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from cuda.core.experimental._utils.cuda_utils cimport (
_check_driver_error as raise_if_driver_error,
check_or_create_options,
)
import sys

from dataclasses import dataclass
from typing import Optional, TypeVar, Union, TYPE_CHECKING
Expand All @@ -20,7 +19,6 @@ import cython
import multiprocessing
import os
import platform
import sys
import weakref
from cuda.core.experimental._dlpack import DLDeviceType, make_py_capsule
from cuda.core.experimental._stream import Stream, default_stream
Expand Down Expand Up @@ -72,17 +70,8 @@ cdef class Buffer:
self._mr = mr
return self

def __del__(self):
self._shutdown_safe_close()

cdef _shutdown_safe_close(self, stream: Stream = None, is_shutting_down=sys.is_finalizing):
if is_shutting_down and is_shutting_down():
return
if self._ptr and self._mr is not None:
self._mr.deallocate(self._ptr, self._size, stream)
self._ptr = 0
self._mr = None
self._ptr_obj = None
def __dealloc__(self):
self.close()

def __reduce__(self):
return Buffer.from_ipc_descriptor, (self.memory_resource, self.get_ipc_descriptor())
Expand All @@ -99,7 +88,11 @@ cdef class Buffer:
The stream object to use for asynchronous deallocation. If None,
the behavior depends on the underlying memory resource.
"""
self._shutdown_safe_close(stream, is_shutting_down=None)
if self._ptr and self._mr is not None:
Comment thread
leofang marked this conversation as resolved.
Resolved
self._mr.deallocate(self._ptr, self._size, stream)
self._ptr = 0
self._mr = None
self._ptr_obj = None

@property
def handle(self) -> DevicePointerT:
Expand Down Expand Up @@ -424,8 +417,7 @@ cdef class IPCAllocationHandle:
self._handle = -1
self._uuid = None

def __del__(self):
"""Close the handle."""
def __dealloc__(self):
self.close()

def __int__(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion cuda_core/cuda/core/experimental/_stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ cdef class Stream:
self._device_id = device_id if device_id is not None else self._device_id
return self

def __del__(self):
def __dealloc__(self):
self.close()
Comment thread
leofang marked this conversation as resolved.
Resolved

cpdef close(self):
Expand Down