diff --git a/strata_control/engine_component.py b/strata_control/engine_component.py index 90271127..5b784155 100644 --- a/strata_control/engine_component.py +++ b/strata_control/engine_component.py @@ -474,6 +474,12 @@ def _smi_query(field_name: str) -> list[str]: def nvidia_driver_version() -> str | None: """The NVIDIA driver version nvidia-smi reports (the oldest one when several cards disagree); None when unreadable.""" versions = _smi_query("driver_version") + if not versions: # Linux without nvidia-smi (Fedora: it is in xorg-x11-drv-nvidia-cuda): the kernel module says + try: + found = re.search(r"Kernel Module\s+(\d+(?:\.\d+)+)", Path("/proc/driver/nvidia/version").read_text()) + versions = [found.group(1)] if found else [] + except OSError: + versions = [] return min(versions, key=_version_key) if versions else None diff --git a/tests/terminal/test_engine_component.py b/tests/terminal/test_engine_component.py index 52064a86..49396d28 100644 --- a/tests/terminal/test_engine_component.py +++ b/tests/terminal/test_engine_component.py @@ -309,6 +309,15 @@ class NeverAcquires(unittest.TestCase): with mock.patch.object(ec, "nvidia_driver_version", return_value="580.178.04"): self.assertEqual(ec.resolve(self.root, backend="cuda", runtime="1").root.name, a.name, "the newer-driver build wins") + def test_the_driver_version_comes_from_the_kernel_module_when_there_is_no_nvidia_smi(self): + text = "NVRM version: NVIDIA UNIX x86_64 Kernel Module 580.95.05 Thu Sep 11 2026 GCC version: gcc 15" + with mock.patch.object(ec, "_smi_query", return_value=[]), mock.patch.object(Path, "read_text", return_value=text): + self.assertEqual(ec.nvidia_driver_version(), "580.95.05") + with mock.patch.object(ec, "_smi_query", return_value=["575.57.08", "580.95.05"]): + self.assertEqual(ec.nvidia_driver_version(), "575.57.08", "the oldest when cards disagree") + with mock.patch.object(ec, "_smi_query", return_value=[]), mock.patch.object(Path, "read_text", side_effect=OSError): + self.assertIsNone(ec.nvidia_driver_version()) + def test_the_component_fetcher_refuses_where_acquiring_is_forbidden(self): store = components.ComponentStore(self.root / "store") artifact = components.Artifact(name="engine.tar.gz", url="https://example.invalid/e.tgz", diff --git a/tools/strata_mcp.py b/tools/strata_mcp.py index 1ed5e25b..93fb8f9b 100644 --- a/tools/strata_mcp.py +++ b/tools/strata_mcp.py @@ -759,6 +759,10 @@ class Strata: amd = [] if not amd and shutil.which("rocm-smi"): amd = rocm_smi_gpus() + if any(g.get("usable") for g in nv): + for g in amd: # a Ryzen's integrated graphics beside an NVIDIA card: the engine runs on the NVIDIA card + if g.get("uma") and g.get("usable"): + g["usable"], g["problem"] = False, "integrated graphics: Strata uses the NVIDIA card in this computer" hw["gpus"] = nv + amd if WIN: hw["display_adapters"] = windows_video_controllers() diff --git a/tools/test_strata_mcp.py b/tools/test_strata_mcp.py index 0ce2afe4..fbcfff05 100644 --- a/tools/test_strata_mcp.py +++ b/tools/test_strata_mcp.py @@ -692,6 +692,25 @@ class MacCatalog(unittest.TestCase): self.assertIn("unsloth", [f["family"] for f in s.model_table({"ram_gb": 96, "gpus": []})]) +class MixedGraphics(unittest.TestCase): + def test_an_integrated_amd_gpu_beside_an_nvidia_card_is_not_offered(self): + s = M.Strata(HERE.parent) + S = s.setup_module() + nv = [{"index": 0, "name": "NVIDIA GeForce RTX 5090", "vram_gb": 31.8, "arch": "120", "driver": "580.95"}] + igpu = [{"index": 0, "name": "AMD Radeon Graphics", "vram_gb": 0.5, "arch": "gfx1036", "uma": True}] + with mock.patch.object(M.sys, "platform", "linux"), mock.patch.object(M, "WIN", False), mock.patch.object(S, "gpus", lambda: [dict(g) for g in nv]), mock.patch.object(S, "gpu_problem", lambda g: None), mock.patch.object(S, "amd_gpus", lambda: [dict(g) for g in igpu]), mock.patch.object(S, "amd_problem", lambda g: None): + hw = s._hardware() + by = {g["vendor"]: g for g in hw["gpus"]} + self.assertTrue(by["nvidia"]["usable"]) + self.assertFalse(by["amd"]["usable"]) + self.assertIn("NVIDIA card", by["amd"]["problem"]) + rec = s.recommend({**hw, "ram_gb": 92.0}) + self.assertEqual((rec["backend"], rec["gpu"]["name"]), ("cuda", "NVIDIA GeForce RTX 5090")) + # with no NVIDIA card the integrated GPU stays what it was + with mock.patch.object(M.sys, "platform", "linux"), mock.patch.object(M, "WIN", False), mock.patch.object(S, "gpus", lambda: []), mock.patch.object(S, "amd_gpus", lambda: [dict(g) for g in igpu]), mock.patch.object(S, "amd_problem", lambda g: None): + self.assertTrue(s._hardware()["gpus"][0]["usable"]) + + if __name__ == "__main__": unittest.main()