From 8672ee44a42f84d570b6ffc1b6b7403a1dbdc0af Mon Sep 17 00:00:00 2001 From: Jinfeng Date: Fri, 6 Nov 2026 22:23:19 +0000 Subject: [PATCH 1/4] add locking for _cyb_func_ptrs --- cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx | 6 ++++-- cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx index a1a4472fe91..f283c9a692e 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx @@ -53,6 +53,7 @@ ctypedef int (*_cyb_cuGetProcAddress_v2_T)(const char *, void **, int, cuuint64_ cdef int _cyb___py_driver_init = 0 cdef dict _cyb_func_ptrs = None cdef object _cyb_symbol_lock = _cyb_threading.Lock() +cdef object _cyb_func_ptrs_lock = _cyb_threading.Lock() # <<<< END OF PREAMBLE CONTENT >>>> @@ -3791,8 +3792,9 @@ cpdef dict _inspect_function_pointers(): cpdef _inspect_function_pointer(str name): global _cyb_func_ptrs - if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() + with _cyb_func_ptrs_lock: + if _cyb_func_ptrs is None: + _cyb_func_ptrs = _inspect_function_pointers() return _cyb_func_ptrs[name] diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx index 6b32bdba99a..30fcbc77b5a 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx @@ -54,6 +54,7 @@ ctypedef int (*_cyb_cuGetProcAddress_v2_T)(const char *, void **, int, cuuint64_ cdef int _cyb___py_driver_init = 0 cdef dict _cyb_func_ptrs = None cdef object _cyb_symbol_lock = _cyb_threading.Lock() +cdef object _cyb_func_ptrs_lock = _cyb_threading.Lock() # <<<< END OF PREAMBLE CONTENT >>>> @@ -3794,8 +3795,9 @@ cpdef dict _inspect_function_pointers(): cpdef _inspect_function_pointer(str name): global _cyb_func_ptrs - if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() + with _cyb_func_ptrs_lock: + if _cyb_func_ptrs is None: + _cyb_func_ptrs = _inspect_function_pointers() return _cyb_func_ptrs[name] From 3f2a5c8b64ffec5f3e7bd733f0a141042368fa56 Mon Sep 17 00:00:00 2001 From: Jinfeng Date: Fri, 6 Nov 2026 23:02:35 +0000 Subject: [PATCH 2/4] use cybind gen --- cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx | 5 +++-- cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx index f283c9a692e..98e49a00d79 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=855d1d0530ab58f150ca5fb8b9ec43262cf0df681f507e2b53feeb6cf77c7c17 +# !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=0bc6d0264818d8e1743ac975b3def902d8abfdce60a9dd0757b8dbfb0eb71cc2 # <<<< PREAMBLE CONTENT >>>> @@ -52,8 +53,8 @@ ctypedef int (*_cyb_cuGetProcAddress_v2_T)(const char *, void **, int, cuuint64_ cdef int _cyb___py_driver_init = 0 cdef dict _cyb_func_ptrs = None -cdef object _cyb_symbol_lock = _cyb_threading.Lock() cdef object _cyb_func_ptrs_lock = _cyb_threading.Lock() +cdef object _cyb_symbol_lock = _cyb_threading.Lock() # <<<< END OF PREAMBLE CONTENT >>>> diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx index 30fcbc77b5a..e1feaa7aea5 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=265db3de415ec26f7b9cfd9961c846938d258ff2c840d500316a3fd24266d6ac +# !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b37b85b769459d1cd959de858aea6995f9b06befd79aeceb945b819d206414fb # <<<< PREAMBLE CONTENT >>>> @@ -53,8 +54,8 @@ ctypedef int (*_cyb_cuGetProcAddress_v2_T)(const char *, void **, int, cuuint64_ cdef int _cyb___py_driver_init = 0 cdef dict _cyb_func_ptrs = None -cdef object _cyb_symbol_lock = _cyb_threading.Lock() cdef object _cyb_func_ptrs_lock = _cyb_threading.Lock() +cdef object _cyb_symbol_lock = _cyb_threading.Lock() # <<<< END OF PREAMBLE CONTENT >>>> From ab8ac534c72cf441adb529951230336c0ea51f38 Mon Sep 17 00:00:00 2001 From: Jinfeng Date: Sat, 7 Nov 2026 00:33:26 +0000 Subject: [PATCH 3/4] let read do not use lock --- .../cuda/bindings/_internal/driver_linux.pyx | 9 +++++---- .../cuda/bindings/_internal/driver_windows.pyx | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx index 98e49a00d79..4fda6cddff7 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx @@ -4,7 +4,7 @@ # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. # !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=0bc6d0264818d8e1743ac975b3def902d8abfdce60a9dd0757b8dbfb0eb71cc2 +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=4cb5d4dc3795831a0f50a8ecf92dbe9b963a2cb908cb657db98e7f14d7164512 # <<<< PREAMBLE CONTENT >>>> @@ -3793,9 +3793,10 @@ cpdef dict _inspect_function_pointers(): cpdef _inspect_function_pointer(str name): global _cyb_func_ptrs - with _cyb_func_ptrs_lock: - if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() + if _cyb_func_ptrs is None: + with _cyb_func_ptrs_lock: + if _cyb_func_ptrs is None: + _cyb_func_ptrs = _inspect_function_pointers() return _cyb_func_ptrs[name] diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx index e1feaa7aea5..61efd1b62d2 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx @@ -4,7 +4,7 @@ # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. # !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b37b85b769459d1cd959de858aea6995f9b06befd79aeceb945b819d206414fb +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=95db262e65cd453b232f6c9eb3b4574a4bc371eb384b224b3c2b6f85778bd38e # <<<< PREAMBLE CONTENT >>>> @@ -3796,9 +3796,10 @@ cpdef dict _inspect_function_pointers(): cpdef _inspect_function_pointer(str name): global _cyb_func_ptrs - with _cyb_func_ptrs_lock: - if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() + if _cyb_func_ptrs is None: + with _cyb_func_ptrs_lock: + if _cyb_func_ptrs is None: + _cyb_func_ptrs = _inspect_function_pointers() return _cyb_func_ptrs[name] From 45c27f2fc556b4ab72135cc685545a3cc15e3c01 Mon Sep 17 00:00:00 2001 From: Jinfeng Date: Sat, 7 Nov 2026 01:44:41 +0000 Subject: [PATCH 4/4] reroute both entry point _inspect_function_pointer(name) and _inspect_function_pointers() to a single build function having the fix --- .../cuda/bindings/_internal/driver_linux.pyx | 19 +++++++++---------- .../bindings/_internal/driver_windows.pyx | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx index 4fda6cddff7..0f2e86d82d1 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx @@ -4,7 +4,7 @@ # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. # !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=4cb5d4dc3795831a0f50a8ecf92dbe9b963a2cb908cb657db98e7f14d7164512 +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=bcb0306e1a5e714a98ec08dcce8b16f01459e21d6d2df027c1e7b5df0e392198 # <<<< PREAMBLE CONTENT >>>> @@ -2203,11 +2203,7 @@ cdef inline int _check_or_init_driver() except -1 nogil: return _init_driver() -cpdef dict _inspect_function_pointers(): - global _cyb_func_ptrs - if _cyb_func_ptrs is not None: - return _cyb_func_ptrs - +cdef dict _build_function_pointers(): _check_or_init_driver() cdef dict data = {} global __cuGetErrorString @@ -3787,17 +3783,20 @@ cpdef dict _inspect_function_pointers(): global __cuTensorMapSetAllocationClass data["__cuTensorMapSetAllocationClass"] = __cuTensorMapSetAllocationClass - _cyb_func_ptrs = data return data -cpdef _inspect_function_pointer(str name): +cpdef dict _inspect_function_pointers(): global _cyb_func_ptrs if _cyb_func_ptrs is None: with _cyb_func_ptrs_lock: if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() - return _cyb_func_ptrs[name] + _cyb_func_ptrs = _build_function_pointers() + return _cyb_func_ptrs + + +cpdef _inspect_function_pointer(str name): + return _inspect_function_pointers()[name] diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx index 61efd1b62d2..b540081bb6a 100644 --- a/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx +++ b/cuda_bindings_13/cuda/bindings/_internal/driver_windows.pyx @@ -4,7 +4,7 @@ # # This code was automatically generated across versions from 12.9.0 to 13.5.0. Do not modify it directly. # !!! WARNING: THIS FILE CONTAINS PRERELEASE APIs !!! -# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=95db262e65cd453b232f6c9eb3b4574a4bc371eb384b224b3c2b6f85778bd38e +# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=8b56814f7e4876ba0386c167c8bd1f0f024f3c5c5350557b4dfc72446fe38979 # <<<< PREAMBLE CONTENT >>>> @@ -2206,11 +2206,7 @@ cdef inline int _check_or_init_driver() except -1 nogil: return _init_driver() -cpdef dict _inspect_function_pointers(): - global _cyb_func_ptrs - if _cyb_func_ptrs is not None: - return _cyb_func_ptrs - +cdef dict _build_function_pointers(): _check_or_init_driver() cdef dict data = {} global __cuGetErrorString @@ -3790,17 +3786,20 @@ cpdef dict _inspect_function_pointers(): global __cuTensorMapSetAllocationClass data["__cuTensorMapSetAllocationClass"] = __cuTensorMapSetAllocationClass - _cyb_func_ptrs = data return data -cpdef _inspect_function_pointer(str name): +cpdef dict _inspect_function_pointers(): global _cyb_func_ptrs if _cyb_func_ptrs is None: with _cyb_func_ptrs_lock: if _cyb_func_ptrs is None: - _cyb_func_ptrs = _inspect_function_pointers() - return _cyb_func_ptrs[name] + _cyb_func_ptrs = _build_function_pointers() + return _cyb_func_ptrs + + +cpdef _inspect_function_pointer(str name): + return _inspect_function_pointers()[name]