Skip to content

Commit 8f00256

Browse files
committed
Fix amdsmi_init.py wrapper references
Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
1 parent 9639199 commit 8f00256

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

projects/amdsmi/amdsmi_cli/amdsmi_init.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
sys.path.insert(0, python_lib_path)
3636
# Only fallback to the python library if its a compatible version
3737
# multiple amdsmi versions installed on the system could cause issues
38-
# TODO Add version checking & debug to check pathing
38+
3939
# Ideally we want to identify if the installed python library is incompatible and log a solution to the user
4040
# LD library config or reinstall, etc...
4141
# The problem is coming from the switch over between the post install and pypi
@@ -48,20 +48,31 @@ def _log_version_and_path_diagnostics():
4848
pkg_version = getattr(_version, "__version__", "unknown")
4949
except Exception as exc: # pragma: no cover - defensive
5050
pkg_version = f"unavailable ({exc})"
51-
pkg_dir = Path(__file__).resolve().parent
52-
lib_candidate = pkg_dir / "libamd_smi_python.so"
51+
52+
# Resolve paths from the *wrapper* module, not from this CLI file.
53+
# The wrapper lives in the amdsmi package dir; the CLI lives elsewhere.
54+
try:
55+
import amdsmi.amdsmi_wrapper as _w
56+
wrapper_path = Path(_w.__file__).resolve()
57+
wrapper_dir = wrapper_path.parent
58+
except Exception:
59+
wrapper_dir = Path("<unknown>")
60+
5361
print(f"[amdsmi-cli] Python package version: {pkg_version}")
54-
print(f"[amdsmi-cli] Package dir: {pkg_dir}")
55-
print(f"[amdsmi-cli] Expected Python lib: {lib_candidate} (exists={lib_candidate.exists()})")
62+
print(f"[amdsmi-cli] CLI dir: {Path(__file__).resolve().parent}")
63+
print(f"[amdsmi-cli] Wrapper dir: {wrapper_dir}")
5664
print(f"[amdsmi-cli] sys.path[0]: {sys.path[0]}")
5765

5866

5967
def _check_version_compatibility(expected_version: Optional[str] = None) -> None:
6068
"""
6169
Verify that the Python package version matches the expected CLI/lib version (if provided).
6270
If mismatched, log guidance and abort to avoid loading an incompatible library.
71+
72+
The actual library loading (pip vs system context) is handled entirely by
73+
amdsmi_wrapper._load_library(). This function only checks version strings
74+
and that the wrapper can resolve *some* loadable library candidate.
6375
"""
64-
lib_locations = []
6576
try:
6677
from amdsmi import _version # type: ignore
6778
pkg_version = getattr(_version, "__version__", None)
@@ -77,27 +88,27 @@ def _check_version_compatibility(expected_version: Optional[str] = None) -> None
7788
print("[amdsmi-cli] and ensure LD_LIBRARY_PATH/ldconfig points to the matching shared library.")
7889
sys.exit(1)
7990

80-
# If the Python lib is missing, warn early with guidance.
81-
pkg_dir = Path(__file__).resolve().parent
82-
lib_candidate = pkg_dir / "libamd_smi_python.so"
83-
if lib_candidate.exists():
84-
return
85-
lib_locations.append(str(lib_candidate))
86-
87-
# Also consider the shared install path resolved via _find_lib.py
91+
# Delegate the library-existence check to the wrapper's own detection logic.
92+
# _build_candidate_paths() uses the wrapper's __file__ to correctly resolve
93+
# pip (libamd_smi_python.so next to wrapper) vs system (/opt/rocm/lib/libamd_smi.so).
8894
try:
89-
from amdsmi._find_lib import find_smi_library # type: ignore
90-
resolved = find_smi_library()
91-
if resolved.exists():
92-
return
93-
lib_locations.append(str(resolved))
95+
from amdsmi.amdsmi_wrapper import _build_candidate_paths
96+
candidates = _build_candidate_paths()
97+
for candidate in candidates:
98+
if isinstance(candidate, str):
99+
# bare "libamd_smi.so" — let the dynamic linker resolve it later
100+
return
101+
if candidate.exists():
102+
return
94103
except Exception:
95-
pass
104+
# If the wrapper isn't importable at all, fall through to the
105+
# ImportError handler in the try/except block below.
106+
return
96107

97108
_log_version_and_path_diagnostics()
98-
print("[amdsmi-cli] Unable to locate libamd_smi_python.so in expected locations:")
99-
for loc in lib_locations:
100-
print(f" - {loc}")
109+
print("[amdsmi-cli] Unable to locate the AMD SMI shared library in expected locations:")
110+
for c in candidates:
111+
print(f" - {c}")
101112
print("[amdsmi-cli] Install the amdsmi wheel that bundles the Python shared library,")
102113
print("[amdsmi-cli] or adjust LD_LIBRARY_PATH/ldconfig to point to a compatible lib.")
103114
sys.exit(1)

0 commit comments

Comments
 (0)