Skip to content

Commit 3e7ca0e

Browse files
committed
Merge branch 'main' into load_nvidia_dynamic_lib_conda_specific
2 parents 22999d1 + bca9d77 commit 3e7ca0e

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

.github/workflows/build-wheel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ jobs:
208208
allow-prereleases: true
209209

210210
- name: verify free-threaded build
211-
if: endsWith(matrix.python-verison, 't')
211+
if: endsWith(matrix.python-version, 't')
212212
run: python -c 'import sys; assert not sys._is_gil_enabled()'
213213

214214
- name: Set up Python include paths

cuda_bindings/cuda/bindings/cyruntime.pyx.in

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

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

1927-
# Return
19281934
return err
19291935
{{endif}}

cuda_bindings/tests/test_cudart.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,10 +1404,12 @@ def test_struct_pointer_comparison(target):
14041404

14051405

14061406
def test_getLocalRuntimeVersion():
1407-
try:
1408-
err, version = cudart.getLocalRuntimeVersion()
1409-
except pathfinder.DynamicLibNotFoundError:
1410-
pytest.skip("cudart dynamic lib not available")
1411-
else:
1412-
assertSuccess(err)
1413-
assert version >= 12000 # CUDA 12.0
1407+
# verify that successive calls do not segfault the interpreter
1408+
for _ in range(10):
1409+
try:
1410+
err, version = cudart.getLocalRuntimeVersion()
1411+
except pathfinder.DynamicLibNotFoundError:
1412+
pytest.skip("cudart dynamic lib not available")
1413+
else:
1414+
assertSuccess(err)
1415+
assert version >= 12000 # CUDA 12.0

0 commit comments

Comments
 (0)