|
24 | 24 |
|
25 | 25 |
|
26 | 26 | def _load_lib_no_cache(libname: str) -> LoadedDL: |
27 | | - # Check whether the library is already loaded into the current process by |
28 | | - # some other component. This check uses OS-level mechanisms (e.g., |
29 | | - # dlopen on Linux, GetModuleHandle on Windows). |
30 | | - loaded = check_if_already_loaded_from_elsewhere(libname) |
31 | | - if loaded is not None: |
32 | | - return loaded |
| 27 | + found = _FindNvidiaDynamicLib(libname) |
| 28 | + have_abs_path = found.abs_path is not None |
| 29 | + |
| 30 | + # If the library was already loaded by someone else, reproduce any OS-specific |
| 31 | + # side-effects we would have applied on a direct absolute-path load (e.g., |
| 32 | + # AddDllDirectory on Windows for libs that require it). |
| 33 | + loaded = check_if_already_loaded_from_elsewhere(libname, have_abs_path) |
33 | 34 |
|
34 | | - # Load dependencies first |
| 35 | + # Load dependencies regardless of who loaded the primary lib first. |
| 36 | + # Doing this *after* the side-effect ensures dependencies resolve consistently |
| 37 | + # relative to the actually loaded location. |
35 | 38 | load_dependencies(libname, load_nvidia_dynamic_lib) |
36 | 39 |
|
37 | | - # Find the library path |
38 | | - found = _FindNvidiaDynamicLib(libname) |
39 | | - if found.abs_path is None: |
| 40 | + if loaded is not None: |
| 41 | + return loaded |
| 42 | + |
| 43 | + if not have_abs_path: |
40 | 44 | loaded = load_with_system_search(libname) |
41 | 45 | if loaded is not None: |
42 | 46 | return loaded |
43 | 47 | found.retry_with_cuda_home_priority_last() |
44 | 48 | found.raise_if_abs_path_is_None() |
45 | 49 |
|
46 | | - # Load the library from the found path |
47 | 50 | assert found.abs_path is not None # for mypy |
48 | 51 | return load_with_abs_path(libname, found.abs_path) |
49 | 52 |
|
|
0 commit comments