Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Optional

from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL
from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import SUPPORTED_LINUX_SONAMES

CDLL_MODE = os.RTLD_NOW | os.RTLD_GLOBAL

Expand Down Expand Up @@ -82,27 +83,30 @@ def check_if_already_loaded_from_elsewhere(libname: str) -> Optional[LoadedDL]:
return None


def load_with_system_search(libname: str, soname: str) -> Optional[LoadedDL]:
def load_with_system_search(libname: str) -> Optional[LoadedDL]:
"""Try to load a library using system search paths.

Args:
libname: The name of the library to load
soname: The soname to search for

Returns:
A LoadedDL object if successful, None if the library cannot be loaded

Raises:
RuntimeError: If the library is loaded but no expected symbol is found
"""
try:
handle = ctypes.CDLL(soname, CDLL_MODE)
abs_path = abs_path_for_dynamic_library(libname, handle)
if abs_path is None:
raise RuntimeError(f"No expected symbol for {libname=!r}")
return LoadedDL(abs_path, False, handle._handle)
except OSError:
return None
candidate_sonames = list(SUPPORTED_LINUX_SONAMES.get(libname, ()))
candidate_sonames.append(f"lib{libname}.so")
for soname in candidate_sonames:
try:
handle = ctypes.CDLL(soname, CDLL_MODE)
abs_path = abs_path_for_dynamic_library(libname, handle)
if abs_path is None:
raise RuntimeError(f"No expected symbol for {libname=!r}")
return LoadedDL(abs_path, False, handle._handle)
except OSError:
pass
return None


def load_with_abs_path(_libname: str, found_path: str) -> LoadedDL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ def check_if_already_loaded_from_elsewhere(libname: str) -> Optional[LoadedDL]:
return None


def load_with_system_search(libname: str, _soname: str) -> Optional[LoadedDL]:
def load_with_system_search(libname: str) -> Optional[LoadedDL]:
"""Try to load a DLL using system search paths.

Args:
libname: The name of the library to load
soname: Unused parameter (kept for interface consistency)

Returns:
A LoadedDL object if successful, None if the library cannot be loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _load_lib_no_cache(libname: str) -> LoadedDL:
# Find the library path
found = _FindNvidiaDynamicLib(libname)
if found.abs_path is None:
loaded = load_with_system_search(libname, found.lib_searched_for)
loaded = load_with_system_search(libname)
if loaded is not None:
return loaded
found.retry_with_cuda_home_priority_last()
Expand Down
Loading