File tree Expand file tree Collapse file tree
cuda_core/cuda/core/experimental Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ from cuda.core.experimental._utils.cuda_utils import (
1919 handle_return,
2020 is_shutting_down
2121)
22-
22+ import sys
2323if TYPE_CHECKING:
2424 import cuda.bindings
2525 from cuda.core.experimental._device import Device
@@ -109,7 +109,7 @@ cdef class Event:
109109 self ._ctx_handle = ctx_handle
110110 return self
111111
112- cpdef safe_close(self , is_shutting_down = is_shutting_down ):
112+ cpdef safe_close(self , is_shutting_down = sys.is_finalizing ):
113113 """ Destroy the event."""
114114 if self ._handle is not None :
115115 if not is_shutting_down():
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ from libc.stdint cimport uintptr_t
99from cuda.core.experimental._utils.cuda_utils cimport (
1010 _check_driver_error as raise_if_driver_error,
1111)
12-
12+ import sys
1313import abc
1414from typing import TypeVar, Union
1515
@@ -59,13 +59,10 @@ cdef class Buffer:
5959 def __del__ (self ):
6060 self .safe_close()
6161
62- cpdef safe_close(self , stream: Stream = None , is_shutting_down = is_shutting_down ):
62+ cpdef safe_close(self , stream: Stream = None , is_shutting_down = sys.is_finalizing ):
6363 if self ._ptr and self ._mr is not None :
6464 if not is_shutting_down():
6565 self ._mr.deallocate(self ._ptr, self ._size, stream)
66- self ._ptr = 0
67- self ._mr = None
68- self ._ptr_obj = None
6966
7067 cpdef close(self , stream: Stream = None ):
7168 """ Deallocate this buffer asynchronously on the given stream.
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ from cuda.core.experimental._utils.cuda_utils cimport (
88 _check_driver_error as raise_if_driver_error,
99 check_or_create_options,
1010)
11+ import sys
1112
1213import os
1314import warnings
@@ -25,7 +26,6 @@ from cuda.core.experimental._utils.cuda_utils import (
2526 driver,
2627 get_device_from_ctx,
2728 handle_return,
28- is_shutting_down
2929)
3030
3131
@@ -188,16 +188,13 @@ cdef class Stream:
188188 def __del__ (self ):
189189 self .safe_close()
190190
191- cpdef safe_close(self , is_shutting_down = is_shutting_down ):
191+ cpdef safe_close(self , is_shutting_down = sys.is_finalizing ):
192192 if self ._owner is None :
193193 if self ._handle and not self ._builtin:
194- if not is_shutting_down() :
194+ if not is_shutting_down:
195195 handle_return(driver.cuStreamDestroy(self ._handle))
196- else :
197- self ._owner = None
198- self ._handle = None
199196
200- cpdef close(self , is_shutting_down = is_shutting_down ):
197+ cpdef close(self ):
201198 """ Destroy the stream.
202199
203200 Destroy the stream if we own it. Borrowed foreign stream
Original file line number Diff line number Diff line change 22#
33# SPDX-License-Identifier: Apache-2.0
44
5- import atexit
65import functools
76import importlib.metadata
87from collections import namedtuple
@@ -223,25 +222,3 @@ def get_binding_version():
223222 except importlib.metadata.PackageNotFoundError:
224223 major_minor = importlib.metadata.version(" cuda-python" ).split(" ." )[:2 ]
225224 return tuple (int (v) for v in major_minor)
226-
227- # This code is to signal when the interpreter is in shutdown mode
228- # to prevent using globals that could be already deleted in
229- # objects `__del__` method
230- #
231- # This solution is taken from the Numba/llvmlite code
232- _shutting_down = [False ]
233-
234-
235- @atexit.register
236- def _at_shutdown ():
237- _shutting_down[0 ] = True
238-
239-
240- def is_shutting_down (_shutting_down = _shutting_down):
241- """
242- Whether the interpreter is currently shutting down.
243- For use in finalizers, __del__ methods, and similar; it is advised
244- to early bind this function rather than look it up when calling it,
245- since at shutdown module globals may be cleared.
246- """
247- return _shutting_down[0 ]
You can’t perform that action at this time.
0 commit comments