mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-17 06:00:59 +08:00
[win] Compatible cudatoolkit 11.x and cudnn 8.x from conda (#178)
[win] compatiable condatoolkit 11.x and cudnn 8.x from conda
This commit is contained in:
@@ -42,6 +42,41 @@ def get_default_cuda_directory() -> str:
|
||||
return r"@CUDA_DIRECTORY@".strip()
|
||||
|
||||
|
||||
def get_default_cuda_major_version() -> str:
|
||||
if not is_built_with_gpu():
|
||||
return ""
|
||||
# TODO(qiuyanjun): get cuda version from cmake.
|
||||
return "11"
|
||||
|
||||
|
||||
def find_cudart(search_dir: str) -> bool:
|
||||
if search_dir is None:
|
||||
print("[FastDeploy][ERROR]: search_dir can not be NoneTpye.")
|
||||
return False
|
||||
# TODO(qiuyanjun): add Linux cudart *.so check
|
||||
cudart_lib_name = f"cudart64_{get_default_cuda_major_version()}0.dll"
|
||||
cudart_lib_path = os.path.join(search_dir, cudart_lib_name)
|
||||
return os.path.exists(cudart_lib_path)
|
||||
|
||||
|
||||
def find_cudart_from_sys() -> bool:
|
||||
# TODO(qiuyanjun): add Linux system paths
|
||||
sys_paths = os.environ["path"].strip().split(";")
|
||||
for sys_path in sys_paths:
|
||||
if find_cudart(sys_path):
|
||||
print(f"[FastDeploy][INFO]: Successfully found CUDA ToolKit from system PATH env -> {sys_path}")
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def add_system_search_paths():
|
||||
# TODO(qiuyanjun): add Linux system paths
|
||||
sys_paths = os.environ["path"].strip().split(";")
|
||||
for sys_path in sys_paths:
|
||||
if os.path.exists(sys_path) and sys.version_info[:2] >= (3, 8):
|
||||
os.add_dll_directory(sys_path)
|
||||
|
||||
|
||||
def add_dll_search_dir(dir_path):
|
||||
os.environ["path"] = dir_path + ";" + os.environ["path"]
|
||||
sys.path.insert(0, dir_path)
|
||||
@@ -49,18 +84,7 @@ def add_dll_search_dir(dir_path):
|
||||
os.add_dll_directory(dir_path)
|
||||
|
||||
|
||||
def try_pre_find_cudart_dll(cuda_shared_lib_dir: str, cuda_version: str) -> bool:
|
||||
if cuda_shared_lib_dir is None or cuda_version is None:
|
||||
print("[FastDeploy][ERROR]: cuda_shared_lib_dir and cuda_version can not be NoneTpye.")
|
||||
return False
|
||||
# TODO(qiuyanjun): add Linux and Mac cudart *.so|*.dylib check
|
||||
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_custom_cuda_path():
|
||||
if is_built_with_gpu():
|
||||
# if FastDeploy built with gpu and want to run
|
||||
# in windows, we need to add CUDA_DIRECTORY into
|
||||
@@ -72,7 +96,7 @@ def add_cuda_shared_lib_dir_windows():
|
||||
# path we assume.
|
||||
base_url = "https://github.com/PaddlePaddle/FastDeploy/blob/"
|
||||
default_cuda_dir = get_default_cuda_directory()
|
||||
default_cuda_version = os.path.basename(default_cuda_dir) # v11.2
|
||||
default_cuda_version = get_default_cuda_major_version() # 11
|
||||
cuda_shared_lib_dir = os.path.join(default_cuda_dir, "bin")
|
||||
custom_cuda_envs = ["CUDA_DIRECTORY", "CUDA_HOME", "CUDA_ROOT", "CUDA_PATH"]
|
||||
custom_cuda_dir = "NOTFOUNDED"
|
||||
@@ -94,10 +118,10 @@ def add_cuda_shared_lib_dir_windows():
|
||||
cuda_shared_lib_dir = os.path.join(custom_cuda_dir, "bin")
|
||||
add_dll_search_dir(cuda_shared_lib_dir)
|
||||
# try pre find cudart with major version, e.g 11.x/10.x
|
||||
if not try_pre_find_cudart_dll(cuda_shared_lib_dir, default_cuda_version):
|
||||
if not find_cudart(cuda_shared_lib_dir):
|
||||
custom_cuda_version = os.path.basename(custom_cuda_dir)
|
||||
logging.warnings.warn(
|
||||
f"\n--- FastDeploy was built with CUDA version {default_cuda_version}, \
|
||||
f"\n--- FastDeploy was built with CUDA major version {default_cuda_version}, \
|
||||
\n--- but found custom CUDA version {custom_cuda_version} at {custom_cuda_dir} \
|
||||
\n--- Please setup one of {custom_cuda_envs} manually, \
|
||||
\n--- this path should look like: {default_cuda_dir}. \
|
||||
@@ -107,7 +131,12 @@ def add_cuda_shared_lib_dir_windows():
|
||||
|
||||
|
||||
if os.name == "nt":
|
||||
add_cuda_shared_lib_dir_windows()
|
||||
# cuda/cudnn libs
|
||||
if is_built_with_gpu():
|
||||
add_system_search_paths()
|
||||
if not find_cudart_from_sys():
|
||||
add_custom_cuda_path()
|
||||
|
||||
current_path = os.path.abspath(__file__)
|
||||
dirname = os.path.dirname(current_path)
|
||||
third_libs_dir = os.path.join(dirname, "libs")
|
||||
|
Reference in New Issue
Block a user