@@ -46,39 +46,45 @@ cdef int cuPythonInit() except -1 nogil:
46
46
47
47
# Load library
48
48
{{if 'Windows' == platform.system()}}
49
- handle = NULL
50
49
with gil:
51
50
# First check if the DLL has been loaded by 3rd parties
52
51
try:
53
52
handle = win32api.GetModuleHandle("nvrtc64_120_0.dll")
54
53
except:
55
- pass
54
+ handle = None
56
55
57
56
# Try default search
58
- if handle == NULL :
57
+ if not handle :
59
58
LOAD_LIBRARY_SAFE_CURRENT_DIRS = 0x00002000
60
59
try:
61
60
handle = win32api.LoadLibraryEx("nvrtc64_120_0.dll", 0, LOAD_LIBRARY_SAFE_CURRENT_DIRS)
62
61
except:
63
62
pass
64
63
65
64
# Check if DLLs are found within pip installations
66
- if handle == NULL :
65
+ if not handle :
67
66
site_packages = [site.getusersitepackages()] + site.getsitepackages()
68
67
for sp in site_packages:
69
68
mod_path = os.path.join(sp, "nvidia", "cuda_nvrtc", "bin")
70
69
if not os.path.isdir(mod_path):
71
70
continue
72
71
os.add_dll_directory(mod_path)
72
+ LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000
73
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100
73
74
try:
74
75
handle = win32api.LoadLibraryEx(
75
76
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
76
77
os.path.join(mod_path, "nvrtc64_120_0.dll"),
77
78
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
79
+
80
+ # Note: nvrtc64_120_0.dll calls into nvrtc-builtins64_*.dll which is
81
+ # located in the same mod_path.
82
+ # Update PATH environ so that the two dlls can find each other
83
+ os.environ["PATH"] = os.pathsep.join((os.environ.get("PATH", ""), mod_path))
78
84
except:
79
85
pass
80
86
81
- if handle == NULL :
87
+ if not handle :
82
88
raise RuntimeError('Failed to LoadLibraryEx nvrtc64_120_0.dll')
83
89
{{else}}
84
90
handle = NULL
0 commit comments