Skip to content

Commit d13ad8e

Browse files
committed
load_dl_linux.py: factor out get_candidate_sonames() and also use from check_if_already_loaded_from_elsewhere(), for consistency with load_with_system_search()
1 parent 72f22ff commit d13ad8e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def abs_path_for_dynamic_library(libname: str, handle: ctypes.CDLL) -> str:
4444
raise OSError(f"abs_path_for_dynamic_library failed for {libname=!r}")
4545

4646

47+
def get_candidate_sonames(libname: str) -> list[str]:
48+
candidate_sonames = list(SUPPORTED_LINUX_SONAMES.get(libname, ()))
49+
candidate_sonames.append(f"lib{libname}.so")
50+
return candidate_sonames
51+
52+
4753
def check_if_already_loaded_from_elsewhere(libname: str) -> Optional[LoadedDL]:
4854
"""Check if the library is already loaded in the process.
4955
@@ -58,9 +64,8 @@ def check_if_already_loaded_from_elsewhere(libname: str) -> Optional[LoadedDL]:
5864
>>> if loaded is not None:
5965
... print(f"Library already loaded from {loaded.abs_path}")
6066
"""
61-
from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import SUPPORTED_LINUX_SONAMES
6267

63-
for soname in SUPPORTED_LINUX_SONAMES.get(libname, ()):
68+
for soname in get_candidate_sonames(libname):
6469
try:
6570
handle = ctypes.CDLL(soname, mode=os.RTLD_NOLOAD)
6671
except OSError:
@@ -82,9 +87,7 @@ def load_with_system_search(libname: str) -> Optional[LoadedDL]:
8287
Raises:
8388
RuntimeError: If the library is loaded but no expected symbol is found
8489
"""
85-
candidate_sonames = list(SUPPORTED_LINUX_SONAMES.get(libname, ()))
86-
candidate_sonames.append(f"lib{libname}.so")
87-
for soname in candidate_sonames:
90+
for soname in get_candidate_sonames(libname):
8891
try:
8992
handle = ctypes.CDLL(soname, CDLL_MODE)
9093
abs_path = abs_path_for_dynamic_library(libname, handle)

0 commit comments

Comments
 (0)