Skip to content

Commit feed101

Browse files
committed
Resolve cython error: object handle vs void* handle
``` Error compiling Cython file: ------------------------------------------------------------ ... err = (<int (*)(int*) nogil>__cuDriverGetVersion)(&driver_ver) if err != 0: raise RuntimeError('something went wrong') # Load library handle = load_library(driver_ver) ^ ------------------------------------------------------------ cuda\bindings\_internal\nvjitlink.pyx:72:29: Cannot convert 'void *' to Python object ```
1 parent da417da commit feed101

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ cdef int _check_or_init_nvjitlink() except -1 nogil:
5353
return 0
5454

5555
cdef int err, driver_ver
56+
cdef void* handle
5657
with gil:
5758
# Load driver to check version
5859
try:
59-
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
60+
nvcuda_handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
6061
except Exception as e:
6162
raise NotSupportedError(f'CUDA driver is not found ({e})')
6263
global __cuDriverGetVersion
6364
if __cuDriverGetVersion == NULL:
64-
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(handle, 'cuDriverGetVersion')
65+
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(nvcuda_handle, 'cuDriverGetVersion')
6566
if __cuDriverGetVersion == NULL:
6667
raise RuntimeError('something went wrong')
6768
err = (<int (*)(int*) nogil>__cuDriverGetVersion)(&driver_ver)

cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ cdef int _check_or_init_nvvm() except -1 nogil:
5151
return 0
5252

5353
cdef int err, driver_ver
54+
cdef void* handle
5455
with gil:
5556
# Load driver to check version
5657
try:
57-
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
58+
nvcuda_handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
5859
except Exception as e:
5960
raise NotSupportedError(f'CUDA driver is not found ({e})')
6061
global __cuDriverGetVersion
6162
if __cuDriverGetVersion == NULL:
62-
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(handle, 'cuDriverGetVersion')
63+
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(nvcuda_handle, 'cuDriverGetVersion')
6364
if __cuDriverGetVersion == NULL:
6465
raise RuntimeError('something went wrong')
6566
err = (<int (*)(int*) nogil>__cuDriverGetVersion)(&driver_ver)

0 commit comments

Comments
 (0)