Skip to content

Commit b83da6e

Browse files
authored
Fix #1320: Backport cybind changes to 12.9.x branch (#1323)
* Fix #1320: Backport cybind changes to 12.9.x branch * Don't generate post 12.9 APIs
1 parent 805b254 commit b83da6e

21 files changed

Lines changed: 541 additions & 363 deletions

cuda_bindings/cuda/bindings/_internal/cufile.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.9.0 to 12.9.1. Do not modify it directly.
5+
# This code was automatically generated with version 12.9.1. Do not modify it directly.
66

77
from ..cycufile cimport *
88

@@ -18,6 +18,7 @@ cdef CUfileError_t _cuFileBufDeregister(const void* bufPtr_base) except?<CUfileE
1818
cdef ssize_t _cuFileRead(CUfileHandle_t fh, void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
1919
cdef ssize_t _cuFileWrite(CUfileHandle_t fh, const void* bufPtr_base, size_t size, off_t file_offset, off_t bufPtr_offset) except* nogil
2020
cdef CUfileError_t _cuFileDriverOpen() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
21+
cdef CUfileError_t _cuFileDriverClose() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
2122
cdef CUfileError_t _cuFileDriverClose_v2() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
2223
cdef long _cuFileUseCount() except* nogil
2324
cdef CUfileError_t _cuFileDriverGetProperties(CUfileDrvProps_t* props) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
@@ -41,4 +42,3 @@ cdef CUfileError_t _cuFileGetParameterString(CUFileStringConfigParameter_t param
4142
cdef CUfileError_t _cuFileSetParameterSizeT(CUFileSizeTConfigParameter_t param, size_t value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
4243
cdef CUfileError_t _cuFileSetParameterBool(CUFileBoolConfigParameter_t param, cpp_bool value) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
4344
cdef CUfileError_t _cuFileSetParameterString(CUFileStringConfigParameter_t param, const char* desc_str) except?<CUfileError_t>CUFILE_LOADING_ERROR nogil
44-
cdef CUfileError_t _cuFileDriverClose() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil

cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.9.0 to 12.9.1. Do not modify it directly.
5+
# This code was automatically generated with version 12.9.1. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t, uintptr_t
88
import threading
@@ -18,6 +18,8 @@ import cython
1818
# Extern
1919
###############################################################################
2020

21+
# You must 'from .utils import NotSupportedError' before using this template
22+
2123
cdef extern from "<dlfcn.h>" nogil:
2224
void* dlopen(const char*, int)
2325
char* dlerror()
@@ -32,14 +34,32 @@ cdef extern from "<dlfcn.h>" nogil:
3234

3335
const void* RTLD_DEFAULT 'RTLD_DEFAULT'
3436

37+
cdef int get_cuda_version():
38+
cdef void* handle = NULL
39+
cdef int err, driver_ver = 0
40+
41+
# Load driver to check version
42+
handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL)
43+
if handle == NULL:
44+
err_msg = dlerror()
45+
raise NotSupportedError(f'CUDA driver is not found ({err_msg.decode()})')
46+
cuDriverGetVersion = dlsym(handle, "cuDriverGetVersion")
47+
if cuDriverGetVersion == NULL:
48+
raise RuntimeError('Did not find cuDriverGetVersion symbol in libcuda.so.1')
49+
err = (<int (*)(int*) noexcept nogil>cuDriverGetVersion)(&driver_ver)
50+
if err != 0:
51+
raise RuntimeError(f'cuDriverGetVersion returned error code {err}')
52+
53+
return driver_ver
54+
55+
3556

3657
###############################################################################
3758
# Wrapper init
3859
###############################################################################
3960

4061
cdef object __symbol_lock = threading.Lock()
4162
cdef bint __py_cufile_init = False
42-
cdef void* __cuDriverGetVersion = NULL
4363

4464
cdef void* __cuFileHandleRegister = NULL
4565
cdef void* __cuFileHandleDeregister = NULL
@@ -48,6 +68,7 @@ cdef void* __cuFileBufDeregister = NULL
4868
cdef void* __cuFileRead = NULL
4969
cdef void* __cuFileWrite = NULL
5070
cdef void* __cuFileDriverOpen = NULL
71+
cdef void* __cuFileDriverClose = NULL
5172
cdef void* __cuFileDriverClose_v2 = NULL
5273
cdef void* __cuFileUseCount = NULL
5374
cdef void* __cuFileDriverGetProperties = NULL
@@ -71,20 +92,22 @@ cdef void* __cuFileGetParameterString = NULL
7192
cdef void* __cuFileSetParameterSizeT = NULL
7293
cdef void* __cuFileSetParameterBool = NULL
7394
cdef void* __cuFileSetParameterString = NULL
74-
cdef void* __cuFileDriverClose = NULL
7595

7696

7797
cdef void* load_library() except* with gil:
7898
cdef uintptr_t handle = load_nvidia_dynamic_lib("cufile")._handle_uint
7999
return <void*>handle
80100

81101

82-
cdef int __check_or_init_cufile() except -1 nogil:
102+
cdef int _init_cufile() except -1 nogil:
83103
global __py_cufile_init
84104

85105
cdef void* handle = NULL
86106

87107
with gil, __symbol_lock:
108+
# Recheck the flag after obtaining the locks
109+
if __py_cufile_init:
110+
return 0
88111
# Load function
89112
global __cuFileHandleRegister
90113
__cuFileHandleRegister = dlsym(RTLD_DEFAULT, 'cuFileHandleRegister')
@@ -135,6 +158,13 @@ cdef int __check_or_init_cufile() except -1 nogil:
135158
handle = load_library()
136159
__cuFileDriverOpen = dlsym(handle, 'cuFileDriverOpen')
137160

161+
global __cuFileDriverClose
162+
__cuFileDriverClose = dlsym(RTLD_DEFAULT, 'cuFileDriverClose')
163+
if __cuFileDriverClose == NULL:
164+
if handle == NULL:
165+
handle = load_library()
166+
__cuFileDriverClose = dlsym(handle, 'cuFileDriverClose')
167+
138168
global __cuFileDriverClose_v2
139169
__cuFileDriverClose_v2 = dlsym(RTLD_DEFAULT, 'cuFileDriverClose_v2')
140170
if __cuFileDriverClose_v2 == NULL:
@@ -296,13 +326,6 @@ cdef int __check_or_init_cufile() except -1 nogil:
296326
handle = load_library()
297327
__cuFileSetParameterString = dlsym(handle, 'cuFileSetParameterString')
298328

299-
global __cuFileDriverClose
300-
__cuFileDriverClose = dlsym(RTLD_DEFAULT, 'cuFileDriverClose')
301-
if __cuFileDriverClose == NULL:
302-
if handle == NULL:
303-
handle = load_library()
304-
__cuFileDriverClose = dlsym(handle, 'cuFileDriverClose')
305-
306329
__py_cufile_init = True
307330
return 0
308331

@@ -311,7 +334,7 @@ cdef inline int _check_or_init_cufile() except -1 nogil:
311334
if __py_cufile_init:
312335
return 0
313336

314-
return __check_or_init_cufile()
337+
return _init_cufile()
315338

316339

317340
cdef dict func_ptrs = None
@@ -346,6 +369,9 @@ cpdef dict _inspect_function_pointers():
346369
global __cuFileDriverOpen
347370
data["__cuFileDriverOpen"] = <intptr_t>__cuFileDriverOpen
348371

372+
global __cuFileDriverClose
373+
data["__cuFileDriverClose"] = <intptr_t>__cuFileDriverClose
374+
349375
global __cuFileDriverClose_v2
350376
data["__cuFileDriverClose_v2"] = <intptr_t>__cuFileDriverClose_v2
351377

@@ -415,9 +441,6 @@ cpdef dict _inspect_function_pointers():
415441
global __cuFileSetParameterString
416442
data["__cuFileSetParameterString"] = <intptr_t>__cuFileSetParameterString
417443

418-
global __cuFileDriverClose
419-
data["__cuFileDriverClose"] = <intptr_t>__cuFileDriverClose
420-
421444
func_ptrs = data
422445
return data
423446

@@ -504,6 +527,16 @@ cdef CUfileError_t _cuFileDriverOpen() except?<CUfileError_t>CUFILE_LOADING_ERRO
504527
)
505528

506529

530+
cdef CUfileError_t _cuFileDriverClose() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil:
531+
global __cuFileDriverClose
532+
_check_or_init_cufile()
533+
if __cuFileDriverClose == NULL:
534+
with gil:
535+
raise FunctionNotFoundError("function cuFileDriverClose is not found")
536+
return (<CUfileError_t (*)() noexcept nogil>__cuFileDriverClose)(
537+
)
538+
539+
507540
cdef CUfileError_t _cuFileDriverClose_v2() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil:
508541
global __cuFileDriverClose_v2
509542
_check_or_init_cufile()
@@ -733,13 +766,3 @@ cdef CUfileError_t _cuFileSetParameterString(CUFileStringConfigParameter_t param
733766
raise FunctionNotFoundError("function cuFileSetParameterString is not found")
734767
return (<CUfileError_t (*)(CUFileStringConfigParameter_t, const char*) noexcept nogil>__cuFileSetParameterString)(
735768
param, desc_str)
736-
737-
738-
cdef CUfileError_t _cuFileDriverClose() except?<CUfileError_t>CUFILE_LOADING_ERROR nogil:
739-
global __cuFileDriverClose
740-
_check_or_init_cufile()
741-
if __cuFileDriverClose == NULL:
742-
with gil:
743-
raise FunctionNotFoundError("function cuFileDriverClose is not found")
744-
return (<CUfileError_t (*)() noexcept nogil>__cuFileDriverClose)(
745-
)

cuda_bindings/cuda/bindings/_internal/nvjitlink.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from ..cynvjitlink cimport *
88

cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t, uintptr_t
88

cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t
88

cuda_bindings/cuda/bindings/_internal/nvvm.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from ..cynvvm cimport *
88

cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t, uintptr_t
88

cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.0.1 to 13.0.2. Do not modify it directly.
5+
# This code was automatically generated across versions from 12.0.1 to 13.1.0. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4-
__version__ = "12.9.4"
4+
__version__ = "12.9.5"

cuda_bindings/cuda/bindings/cufile.pxd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44
#
5-
# This code was automatically generated across versions from 12.9.0 to 12.9.1. Do not modify it directly.
5+
# This code was automatically generated with version 12.9.1. Do not modify it directly.
66

77
from libc.stdint cimport intptr_t
88

@@ -46,8 +46,6 @@ cpdef intptr_t handle_register(intptr_t descr) except? 0
4646
cpdef void handle_deregister(intptr_t fh) except*
4747
cpdef buf_register(intptr_t buf_ptr_base, size_t length, int flags)
4848
cpdef buf_deregister(intptr_t buf_ptr_base)
49-
cpdef read(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset)
50-
cpdef write(intptr_t fh, intptr_t buf_ptr_base, size_t size, off_t file_offset, off_t buf_ptr_offset)
5149
cpdef driver_open()
5250
cpdef use_count()
5351
cpdef driver_get_properties(intptr_t props)

0 commit comments

Comments
 (0)