25 lines
929 B
Python
25 lines
929 B
Python
# PyInstaller runtime hook for CUDA DLL loading
|
|
# Must run BEFORE any CuPy import
|
|
#
|
|
# Problem: Windows Python 3.8+ requires os.add_dll_directory() for DLL search
|
|
# PyInstaller ONEDIR mode puts DLLs in _internal/ which isn't in the search path
|
|
|
|
import os
|
|
import sys
|
|
|
|
if sys.platform == 'win32' and getattr(sys, 'frozen', False):
|
|
# _MEIPASS points to _internal/ in ONEDIR mode
|
|
base = getattr(sys, '_MEIPASS', None)
|
|
if base and os.path.isdir(base):
|
|
os.add_dll_directory(base)
|
|
print(f"[CUDA DLL Hook] Added DLL directory: {base}")
|
|
|
|
# Also add CUDA_PATH if available (fallback to system CUDA)
|
|
cuda_path = os.environ.get('CUDA_PATH', '')
|
|
if cuda_path:
|
|
for subdir in ['bin', os.path.join('bin', 'x64')]:
|
|
d = os.path.join(cuda_path, subdir)
|
|
if os.path.isdir(d):
|
|
os.add_dll_directory(d)
|
|
print(f"[CUDA DLL Hook] Added CUDA_PATH: {d}")
|