fix(local-runtime): find nvidia-smi in WSL driver path
This commit is contained in:
@@ -117,7 +117,7 @@ _smi_path_cache: "tuple[str | None] | None" = None
|
||||
|
||||
def _nvidia_smi_path() -> str | None:
|
||||
"""Absolute path to nvidia-smi, or None. PATH first (respects user overrides), then the
|
||||
driver's known Windows install locations; on Linux/WSL the PATH lookup is the whole ladder."""
|
||||
driver's known install locations on Windows and WSL."""
|
||||
global _smi_path_cache
|
||||
if _smi_path_cache is not None:
|
||||
return _smi_path_cache[0]
|
||||
@@ -132,6 +132,12 @@ def _nvidia_smi_path() -> str | None:
|
||||
/ "NVIDIA Corporation" / "NVSMI" / "nvidia-smi.exe",
|
||||
)
|
||||
found = next((str(c) for c in candidates if c.exists()), None)
|
||||
elif found is None and sys.platform.startswith("linux"):
|
||||
# The Windows display driver exposes nvidia-smi here inside WSL, but does not guarantee
|
||||
# that the directory is present on PATH.
|
||||
candidate = Path("/usr/lib/wsl/lib/nvidia-smi")
|
||||
if candidate.exists():
|
||||
found = str(candidate)
|
||||
_smi_path_cache = (found,)
|
||||
return found
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@ any discrete card."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import hermes_cli.local_runtime.hardware as hw
|
||||
|
||||
GIB = 1 << 30
|
||||
@@ -185,6 +189,18 @@ def test_smi_resolver_caches_and_survives_empty_path(monkeypatch):
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.linux_only
|
||||
def test_smi_resolver_uses_wsl_driver_path_when_path_is_empty(monkeypatch):
|
||||
"""WSL exposes nvidia-smi through the Windows driver directory even
|
||||
when a service PATH cannot resolve it."""
|
||||
wsl_smi = Path("/usr/lib/wsl/lib/nvidia-smi")
|
||||
monkeypatch.setattr(hw, "_smi_path_cache", None)
|
||||
monkeypatch.setattr(hw.shutil, "which", lambda name: None)
|
||||
monkeypatch.setattr(hw.Path, "exists", lambda candidate: candidate == wsl_smi)
|
||||
|
||||
assert hw._nvidia_smi_path() == str(wsl_smi)
|
||||
|
||||
|
||||
# ── probe cache ──────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user