Skip to content

Commit 88b2cc9

Browse files
authored
chore: backport remove of calling shared library close functions (#1115)
1 parent 2be0c15 commit 88b2cc9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cuda_bindings/cuda/bindings/cyruntime.pyx.in

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,13 +1905,19 @@ cdef cudaError_t getLocalRuntimeVersion(int* runtimeVersion) except ?cudaErrorCa
19051905
cdef cudaError_t err = cudaSuccess
19061906
err = (<cudaError_t (*)(int*) except ?cudaErrorCallRequiresNewerDriver nogil> __cudaRuntimeGetVersion)(runtimeVersion)
19071907

1908-
# Unload
1909-
{{if 'Windows' == platform.system()}}
1910-
windll.FreeLibrary(handle)
1911-
{{else}}
1912-
dlfcn.dlclose(handle)
1913-
{{endif}}
1908+
# We explicitly do *NOT* cleanup the library handle here, acknowledging
1909+
# that, yes, the handle leaks. The reason is that there's a
1910+
# `functools.cache` on the top-level caller of this function.
1911+
#
1912+
# This means this library would be opened once and then immediately closed,
1913+
# all the while remaining in the cache lurking there for people to call.
1914+
#
1915+
# Since we open the library one time (technically once per unique library name),
1916+
# there's not a ton of leakage, which we deem acceptable for the 1000x speedup
1917+
# achieved by caching (ultimately) `ctypes.CDLL` calls.
1918+
#
1919+
# Long(er)-term we can explore cleaning up the library using higher-level
1920+
# Python mechanisms, like `__del__` or `weakref.finalizer`s.
19141921

1915-
# Return
19161922
return err
19171923
{{endif}}

0 commit comments

Comments
 (0)