mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 09:07:10 +08:00
[win] optimize cudart and dll check (#170)
* [win] fix win build error and optimize cuda version check * [win] optimize cudart and dll check
This commit is contained in:
@@ -49,37 +49,15 @@ def add_dll_search_dir(dir_path):
|
|||||||
os.add_dll_directory(dir_path)
|
os.add_dll_directory(dir_path)
|
||||||
|
|
||||||
|
|
||||||
def load_dso_or_dll(dso_or_dll_name=None) -> bool:
|
def try_pre_find_cudart_dll(cuda_shared_lib_dir: str, cuda_version: str) -> bool:
|
||||||
from ctypes import cdll
|
if cuda_shared_lib_dir is None or cuda_version is None:
|
||||||
if dso_or_dll_name is None:
|
print("[FastDeploy][ERROR]: cuda_shared_lib_dir and cuda_version can not be NoneTpye.")
|
||||||
dso_or_dll_name = "fastdeploy.dll"
|
|
||||||
try:
|
|
||||||
dso_or_dll = cdll.LoadLibrary(dso_or_dll_name)
|
|
||||||
del dso_or_dll
|
|
||||||
print(f"[FastDeploy][INFO]: Successfully pre load {dso_or_dll_name}.")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[FastDeploy][ERROR]: Can not pre load dll/dso: {dso_or_dll_name}. {e}")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def try_pre_load_fastdeploy_dll() -> bool:
|
|
||||||
# Try pre-load fastdeploy dll in windows to
|
|
||||||
# make sure the added custom dll directory
|
|
||||||
# has been activated. Reference:
|
|
||||||
# [1] https://github.com/conda/conda/issues/10897
|
|
||||||
# [2] https://github.com/dhermes/bezier/issues/237
|
|
||||||
# TODO(qiuyanjun): add Linux and Mac *.so|*.dylib check
|
|
||||||
return load_dso_or_dll("fastdeploy.dll")
|
|
||||||
|
|
||||||
|
|
||||||
def try_pre_load_cudart_dll(cuda_version: str) -> bool:
|
|
||||||
if cuda_version is None:
|
|
||||||
print("[FastDeploy][ERROR]: CUDA version can not be NoneTpye.")
|
|
||||||
return False
|
|
||||||
major_version_number = int(cuda_version.strip().strip("v").split(".")[0])
|
|
||||||
# TODO(qiuyanjun): add Linux and Mac cudart *.so|*.dylib check
|
# TODO(qiuyanjun): add Linux and Mac cudart *.so|*.dylib check
|
||||||
return load_dso_or_dll(f"cudart64_{major_version_number}0.dll")
|
major_version_number = int(cuda_version.strip().strip("v").split(".")[0])
|
||||||
|
cudart_lib_name = f"cudart64_{major_version_number}0.dll"
|
||||||
|
cudart_lib_path = os.path.join(cuda_shared_lib_dir, cudart_lib_name)
|
||||||
|
return os.path.exists(cudart_lib_path)
|
||||||
|
|
||||||
|
|
||||||
def add_cuda_shared_lib_dir_windows():
|
def add_cuda_shared_lib_dir_windows():
|
||||||
@@ -115,8 +93,8 @@ def add_cuda_shared_lib_dir_windows():
|
|||||||
# path to cuda dlls
|
# path to cuda dlls
|
||||||
cuda_shared_lib_dir = os.path.join(custom_cuda_dir, "bin")
|
cuda_shared_lib_dir = os.path.join(custom_cuda_dir, "bin")
|
||||||
add_dll_search_dir(cuda_shared_lib_dir)
|
add_dll_search_dir(cuda_shared_lib_dir)
|
||||||
# try pre load cudart with major version, e.g 11.x/10.x
|
# try pre find cudart with major version, e.g 11.x/10.x
|
||||||
if not try_pre_load_cudart_dll(default_cuda_version):
|
if not try_pre_find_cudart_dll(cuda_shared_lib_dir, default_cuda_version):
|
||||||
custom_cuda_version = os.path.basename(custom_cuda_dir)
|
custom_cuda_version = os.path.basename(custom_cuda_dir)
|
||||||
logging.warnings.warn(
|
logging.warnings.warn(
|
||||||
f"\n--- FastDeploy was built with CUDA version {default_cuda_version}, \
|
f"\n--- FastDeploy was built with CUDA version {default_cuda_version}, \
|
||||||
@@ -138,7 +116,6 @@ if os.name == "nt":
|
|||||||
for d in dirs:
|
for d in dirs:
|
||||||
if d == "lib" or d == "bin":
|
if d == "lib" or d == "bin":
|
||||||
add_dll_search_dir(os.path.join(dirname, root, d))
|
add_dll_search_dir(os.path.join(dirname, root, d))
|
||||||
try_pre_load_fastdeploy_dll()
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user