diff --git a/fastdeploy/c_lib_wrap.py.in b/fastdeploy/c_lib_wrap.py.in index 99926b4bf..7ed11e92d 100644 --- a/fastdeploy/c_lib_wrap.py.in +++ b/fastdeploy/c_lib_wrap.py.in @@ -49,37 +49,15 @@ def add_dll_search_dir(dir_path): os.add_dll_directory(dir_path) -def load_dso_or_dll(dso_or_dll_name=None) -> bool: - from ctypes import cdll - if dso_or_dll_name is None: - 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}") +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 - - -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 - 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(): @@ -115,8 +93,8 @@ def add_cuda_shared_lib_dir_windows(): # path to cuda dlls cuda_shared_lib_dir = os.path.join(custom_cuda_dir, "bin") add_dll_search_dir(cuda_shared_lib_dir) - # try pre load cudart with major version, e.g 11.x/10.x - if not try_pre_load_cudart_dll(default_cuda_version): + # 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): custom_cuda_version = os.path.basename(custom_cuda_dir) logging.warnings.warn( f"\n--- FastDeploy was built with CUDA version {default_cuda_version}, \ @@ -138,7 +116,6 @@ if os.name == "nt": for d in dirs: if d == "lib" or d == "bin": add_dll_search_dir(os.path.join(dirname, root, d)) - try_pre_load_fastdeploy_dll() try: