diff --git a/serve/telemetry.py b/serve/telemetry.py index 4dac2d77c4..c44efe5af6 100644 --- a/serve/telemetry.py +++ b/serve/telemetry.py @@ -330,7 +330,7 @@ class _Adl: def __init__(self): self.lib = None - if os.name != "nt": + if os.name != "nt" or sys.platform != "win32": # (sys.platform too: a test that sets os.name to "nt" on Linux must not reach a Windows DLL load) return try: self.lib = ctypes.CDLL("atiadlxx.dll") @@ -342,7 +342,7 @@ class _Adl: self.crt.malloc.restype = ctypes.c_void_p self.crt.malloc.argtypes = [ctypes.c_size_t] self.ALLOC = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_int)(self._alloc) - except (OSError, TypeError, ValueError, AttributeError): + except (OSError, TypeError, ValueError, AttributeError, ImportError): self.lib = None @@ -356,6 +356,8 @@ def _adl_cards(buf, count): if not nm or not (buf[i].Present or buf[i].Exist): continue udid = buf[i].UDID or b"" + if buf[i].VendorID not in (0x1002, 1002) and b"VEN_1002" not in udid.upper(): # ADL can list another vendor's adapter (an NVIDIA card beside the iGPU) + continue dev = udid.split(b"DEV_", 1)[1].split(b"&", 1)[0] if b"DEV_" in udid else None key = dev or nm if key in seen: @@ -537,13 +539,15 @@ class _AmdWin: def _pick_card(adl_names, index, hip_names): """Which of ADL's card rows is HIP's card `index`: the k-th row named like hip_names[index] (k = how many cards of - that name come before it in HIP's order), else row `index`; None when there is no such row.""" - if 0 <= index < len(hip_names): + that name come before it in HIP's order); None when no row has that name (the Monitor then shows what it showed before + rather than another card's readings). Only when the registry lists no AMD card at all: row `index`.""" + if hip_names: + if not 0 <= index < len(hip_names): + return None want = hip_names[index].strip().lower() k = sum(1 for n in hip_names[:index] if n.strip().lower() == want) rows = [r for r, n in enumerate(adl_names) if n.strip().lower() == want] - if k < len(rows): - return rows[k] + return rows[k] if k < len(rows) else None return index if 0 <= index < len(adl_names) else None diff --git a/serve/test_telemetry_adl.py b/serve/test_telemetry_adl.py index 5187bd4e7b..45714cb214 100644 --- a/serve/test_telemetry_adl.py +++ b/serve/test_telemetry_adl.py @@ -43,7 +43,7 @@ class OnlyTheMonitor(unittest.TestCase): with mock.patch.object(t.os, "name", "posix"), mock.patch.object(t, "_AmdWin") as win: self.assertIsInstance(t.monitor_reader(0, amd=True), t._Amd) win.assert_not_called() - with mock.patch.object(t.os, "name", "nt"), mock.patch.object(t, "_AmdWin") as win: + with mock.patch.object(t.os, "name", "nt"), mock.patch.object(t, "_AmdWin") as win, mock.patch.object(t, "_Nvml"), mock.patch.object(t, "_Metal"): t.monitor_reader(0, amd=False) # NVIDIA / Metal: never ADL2 win.assert_not_called() @@ -95,6 +95,7 @@ class Mapping(unittest.TestCase): self.assertEqual([t._pick_card(same, i, same) for i in (0, 1)], [0, 1]) # two of one name self.assertEqual(t._pick_card(adl, 1, []), 1) # no registry list self.assertIsNone(t._pick_card(adl, 2, [])) + self.assertIsNone(t._pick_card(["AMD Radeon(TM) Graphics"], 0, ["AMD Radeon RX 6900 XT"])) # no ADL row for the HIP card: no reading def test_cards_skip_the_igpu_beside_a_card_and_keep_an_apu_alone(self): A = t._Adl.AdapterInfo @@ -107,6 +108,9 @@ class Mapping(unittest.TestCase): buf = rows((b"AMD Radeon(TM) Graphics", b"164e"), (b"AMD Radeon RX 9070 XT", b"7550"), (b"AMD Radeon RX 9070 XT", b"7550")) self.assertEqual(t._adl_cards(buf, 3), [(1, "7550", "AMD Radeon RX 9070 XT", False)]) # one row per card, no iGPU apu = rows((b"AMD Radeon(TM) 8060S Graphics", b"1586"), (b"AMD Radeon(TM) 8060S Graphics", b"1586")) + nv = rows((b"NVIDIA GeForce RTX 5070", b"2F04"), (b"AMD Radeon(TM) Graphics", b"164E")) + nv[0].UDID = b"PCI_VEN_10DE&DEV_2F04" + self.assertEqual(t._adl_cards(nv, 2), [(1, "164E", "AMD Radeon(TM) Graphics", True)]) # another vendor's adapter is never a card self.assertEqual(t._adl_cards(apu, 2), [(0, "1586", "AMD Radeon(TM) 8060S Graphics", True)]) def test_link_fields(self): diff --git a/tests/terminal/test_no_debugger_children.py b/tests/terminal/test_no_debugger_children.py index c0b47299a4..4e305c3368 100644 --- a/tests/terminal/test_no_debugger_children.py +++ b/tests/terminal/test_no_debugger_children.py @@ -162,7 +162,7 @@ STRATA_PROGRAMS = { } OTHER_PROGRAMS = { "serve/mcp.py": 2, # the person's MCP servers and taskkill - "serve/telemetry.py": 2, # sysctl, a Metal tool + "serve/telemetry.py": 3, # sysctl, a Metal tool, PowerShell's Get-PnpDevice (the Windows AMD PCIe link, #4884) "strata_control/doctor.py": 1, "strata_control/engine_component.py": 4, # nvidia-smi, powershell, lspci-style probes "strata_control/gpu_roles.py": 1, # python -c