Skip to content

Commit 8c7ea2e

Browse files
committed
Address comments from PR
1 parent 7828876 commit 8c7ea2e

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ from cuda.pathfinder import load_nvidia_dynamic_lib
1616
# Extern
1717
###############################################################################
1818

19+
from .utils import NotSupportedError
20+
1921
cdef extern from "<dlfcn.h>" nogil:
2022
void* dlopen(const char*, int)
2123
char* dlerror()

cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ from .utils import FunctionNotFoundError, NotSupportedError
1212
from cuda.pathfinder import load_nvidia_dynamic_lib
1313

1414
from libc.stddef cimport wchar_t
15-
from libc.stdint cimport intptr_t, uintptr_t
15+
from libc.stdint cimport uintptr_t
1616
from cpython cimport PyUnicode_AsWideCharString
1717

1818
from .utils import NotSupportedError
1919

20-
cdef extern from "windows.h":
20+
cdef extern from "windows.h" nogil:
2121
ctypedef void* HMODULE
2222
ctypedef void* HANDLE
2323
ctypedef void* FARPROC
@@ -32,9 +32,13 @@ cdef extern from "windows.h":
3232
LPCWSTR lpLibFileName,
3333
HANDLE hFile,
3434
DWORD dwFlags
35-
) nogil
35+
)
36+
37+
HMODULE _LoadLibraryW "LoadLibraryW"(LPCWSTR lpLibFileName)
38+
39+
FARPROC _GetProcAddress "GetProcAddress"(HMODULE hModule, const char* lpProcName)
3640

37-
FARPROC _GetProcAddress "GetProcAddress"(HMODULE hModule, const char* lpProcName) nogil
41+
HMODULE _GetModuleHandleW "GetModuleHandleW"(LPCWSTR lpModuleName)
3842

3943
cdef inline uintptr_t LoadLibraryExW(str path, HANDLE hFile, DWORD dwFlags) nogil:
4044
cdef wchar_t* wpath
@@ -46,9 +50,21 @@ cdef inline uintptr_t LoadLibraryExW(str path, HANDLE hFile, DWORD dwFlags) nogi
4650
dwFlags
4751
)
4852

49-
cdef inline FARPROC GetProcAddress(uintptr_t hModule, const char* lpProcName) nogil:
53+
cdef inline uintptr_t LoadLibraryW(str path) nogil:
54+
cdef wchar_t* wpath
55+
with gil:
56+
wpath = PyUnicode_AsWideCharString(path, NULL)
57+
return <uintptr_t>_LoadLibraryW(wpath)
58+
59+
cdef inline void *GetProcAddress(uintptr_t hModule, const char* lpProcName) nogil:
5060
return _GetProcAddress(<HMODULE>hModule, lpProcName)
5161

62+
cdef inline uintptr_t GetModuleHandleW(str path) nogil:
63+
cdef wchar_t* wpath
64+
with gil:
65+
wpath = PyUnicode_AsWideCharString(path, NULL)
66+
return <uintptr_t>_GetModuleHandleW(wpath)
67+
5268
cdef int get_cuda_version():
5369
cdef int err, driver_ver = 0
5470

cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ from cuda.pathfinder import load_nvidia_dynamic_lib
1616
# Extern
1717
###############################################################################
1818

19+
from .utils import NotSupportedError
20+
1921
cdef extern from "<dlfcn.h>" nogil:
2022
void* dlopen(const char*, int)
2123
char* dlerror()

cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ from .utils import FunctionNotFoundError, NotSupportedError
1212
from cuda.pathfinder import load_nvidia_dynamic_lib
1313

1414
from libc.stddef cimport wchar_t
15-
from libc.stdint cimport intptr_t, uintptr_t
15+
from libc.stdint cimport uintptr_t
1616
from cpython cimport PyUnicode_AsWideCharString
1717

1818
from .utils import NotSupportedError
1919

20-
cdef extern from "windows.h":
20+
cdef extern from "windows.h" nogil:
2121
ctypedef void* HMODULE
2222
ctypedef void* HANDLE
2323
ctypedef void* FARPROC
@@ -32,9 +32,13 @@ cdef extern from "windows.h":
3232
LPCWSTR lpLibFileName,
3333
HANDLE hFile,
3434
DWORD dwFlags
35-
) nogil
35+
)
36+
37+
HMODULE _LoadLibraryW "LoadLibraryW"(LPCWSTR lpLibFileName)
38+
39+
FARPROC _GetProcAddress "GetProcAddress"(HMODULE hModule, const char* lpProcName)
3640

37-
FARPROC _GetProcAddress "GetProcAddress"(HMODULE hModule, const char* lpProcName) nogil
41+
HMODULE _GetModuleHandleW "GetModuleHandleW"(LPCWSTR lpModuleName)
3842

3943
cdef inline uintptr_t LoadLibraryExW(str path, HANDLE hFile, DWORD dwFlags) nogil:
4044
cdef wchar_t* wpath
@@ -46,9 +50,21 @@ cdef inline uintptr_t LoadLibraryExW(str path, HANDLE hFile, DWORD dwFlags) nogi
4650
dwFlags
4751
)
4852

49-
cdef inline FARPROC GetProcAddress(uintptr_t hModule, const char* lpProcName) nogil:
53+
cdef inline uintptr_t LoadLibraryW(str path) nogil:
54+
cdef wchar_t* wpath
55+
with gil:
56+
wpath = PyUnicode_AsWideCharString(path, NULL)
57+
return <uintptr_t>_LoadLibraryW(wpath)
58+
59+
cdef inline void *GetProcAddress(uintptr_t hModule, const char* lpProcName) nogil:
5060
return _GetProcAddress(<HMODULE>hModule, lpProcName)
5161

62+
cdef inline uintptr_t GetModuleHandleW(str path) nogil:
63+
cdef wchar_t* wpath
64+
with gil:
65+
wpath = PyUnicode_AsWideCharString(path, NULL)
66+
return <uintptr_t>_GetModuleHandleW(wpath)
67+
5268
cdef int get_cuda_version():
5369
cdef int err, driver_ver = 0
5470

0 commit comments

Comments
 (0)