-
Notifications
You must be signed in to change notification settings - Fork 217
Add LoadedDL.found_via
#1049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LoadedDL.found_via
#1049
Changes from 11 commits
599ef39
b5d53c0
8746a22
bf44cdf
95d913c
9c5a059
7557d50
711179f
96574e5
936cd20
4f1abfd
a969731
8df1369
f7994fc
d0b9d65
e02bf25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,18 @@ class DynamicLibNotFoundError(RuntimeError): | |
pass | ||
|
||
|
||
@dataclass | ||
class FoundVia: | ||
name: str | ||
version: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class LoadedDL: | ||
abs_path: Optional[str] | ||
was_already_loaded_from_elsewhere: bool | ||
_handle_uint: int # Platform-agnostic unsigned pointer value | ||
foundvia: Optional[FoundVia] = None | ||
|
||
|
||
|
||
def load_dependencies(libname: str, load_func: Callable[[str], LoadedDL]) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import sys | ||
|
||
from cuda.pathfinder._dynamic_libs.find_nvidia_dynamic_lib import _FindNvidiaDynamicLib | ||
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL, load_dependencies | ||
from cuda.pathfinder._dynamic_libs.load_dl_common import FoundVia, LoadedDL, load_dependencies | ||
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS | ||
|
||
if IS_WINDOWS: | ||
|
@@ -26,13 +26,20 @@ | |
def _load_lib_no_cache(libname: str) -> LoadedDL: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to move this below the Also, this could be a one-liner:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect it'll be simpler (less code) to wrap this function in a helper that adds
Alternatively, we could pass |
||
finder = _FindNvidiaDynamicLib(libname) | ||
abs_path = finder.try_site_packages() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor but would be nice: keep the
|
||
|
||
if abs_path is None: | ||
abs_path = finder.try_with_conda_prefix() | ||
if abs_path is not None: | ||
found_via = FoundVia("conda") | ||
else: | ||
found_via = FoundVia("site-packages") | ||
|
||
# If the library was already loaded by someone else, reproduce any OS-specific | ||
# side-effects we would have applied on a direct absolute-path load (e.g., | ||
# AddDllDirectory on Windows for libs that require it). | ||
loaded = check_if_already_loaded_from_elsewhere(libname, abs_path is not None) | ||
loaded = check_if_already_loaded_from_elsewhere( | ||
libname, abs_path is not None, found_via if abs_path is not None else None | ||
) | ||
|
||
# Load dependencies regardless of who loaded the primary lib first. | ||
# Doing this *after* the side-effect ensures dependencies resolve consistently | ||
|
@@ -49,8 +56,10 @@ def _load_lib_no_cache(libname: str) -> LoadedDL: | |
abs_path = finder.try_with_cuda_home() | ||
if abs_path is None: | ||
finder.raise_not_found_error() | ||
else: | ||
found_via = FoundVia("CUDA_HOME") | ||
|
||
return load_with_abs_path(libname, abs_path) | ||
return load_with_abs_path(libname, abs_path, found_via) | ||
|
||
|
||
@functools.cache | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently not used: I'd lean towards not adding that in this PR, but only when we have an actual use case, which might give us ideas for a different name (or names).