Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 1 addition & 1 deletion cuda_core/cuda/core/graph/_utils.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from cuda.bindings cimport cydriver

cdef bint _is_py_host_trampoline(cydriver.CUhostFn fn) noexcept nogil

cdef void _py_host_destructor(void* data) noexcept with gil
cdef void _py_host_destructor(void* data) noexcept nogil

cdef void _attach_user_object(
cydriver.CUgraph graph, void* ptr,
Expand Down
31 changes: 29 additions & 2 deletions cuda_core/cuda/core/graph/_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,42 @@ from cuda.core._utils.cuda_utils cimport HANDLE_RETURN


cdef extern from "Python.h":
int Py_IsInitialized() nogil
void _py_decref "Py_DECREF" (void*)

cdef extern from *:
"""
#include <Python.h>

#if PY_VERSION_HEX < 0x030D0000
extern int _Py_IsFinalizing(void);
#endif

static inline int _py_runtime_is_finalizing(void) {
#if PY_VERSION_HEX >= 0x030D0000
return Py_IsFinalizing();
#else
return _Py_IsFinalizing();
#endif
}
"""
int _py_runtime_is_finalizing() nogil

Comment thread
aryanputta marked this conversation as resolved.
Outdated

cdef void _py_host_trampoline(void* data) noexcept with gil:
(<object>data)()


cdef void _py_host_destructor(void* data) noexcept with gil:
_py_decref(data)
cdef void _py_host_destructor(void* data) noexcept nogil:
if data == NULL:
return

# Leak once shutdown has started or completed.
if not Py_IsInitialized() or _py_runtime_is_finalizing():
return

with gil:
_py_decref(data)


cdef bint _is_py_host_trampoline(cydriver.CUhostFn fn) noexcept nogil:
Expand Down
Loading