Updates: an AMD card with an unknown gfx never gets the newest HIP build by version; read the gfx from the Windows display adapters, choose by GPU name, keep the installed variant
This commit is contained in:
1 parent
cbfd5b926b
commit
86620837b2
4 files changed
+234
-4
No files matched your search
@@ -485,9 +485,79 @@ WIN_AMD_IGPU_IDS = {0x150E, 0x1114, 0x1902, 0x15BF, 0x15C8, 0x164F, 0x1900, 0x19
|
||||
_WIN_DISPLAY_CLASS = r"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}"
|
||||
|
||||
|
||||
def gfx_from_name(name: str) -> str:
|
||||
"""The AMD architecture a card's marketing name implies ("" when the name says nothing): the fallback when the PCI device id is
|
||||
not in the table. Only names Strata knows a gfx for; an integrated Radeon with no supported build still maps (it then simply
|
||||
fits no package)."""
|
||||
text = re.sub(r"\s+", " ", str(name or "")).upper()
|
||||
if "AMD" not in text and "RADEON" not in text and "RYZEN" not in text:
|
||||
return ""
|
||||
if re.search(r"\b(?:8060S|8050S)\b", text) or "RYZEN AI MAX" in text:
|
||||
return "gfx1151"
|
||||
if re.search(r"\bR9700\b|\bR97\d\d\b|\bAI PRO R97", text) or re.search(r"\bRX 9070\b", text):
|
||||
return "gfx1201"
|
||||
if re.search(r"\bRX 906\d\b|\bR96\d\d\b|\bAI PRO R96", text):
|
||||
return "gfx1200"
|
||||
found = re.search(r"\b(?:RX |W)(7[5-9]\d\d)\b", text)
|
||||
if found:
|
||||
series = int(found.group(1)) // 100
|
||||
return {79: "gfx1100", 78: "gfx1101", 77: "gfx1101", 76: "gfx1102", 75: "gfx1102"}[series]
|
||||
if re.search(r"\b(?:780M|760M|740M)\b", text):
|
||||
return "gfx1103"
|
||||
if re.search(r"\b(?:880M|890M)\b", text):
|
||||
return "gfx1150"
|
||||
if re.search(r"\b860M\b", text):
|
||||
return "gfx1152"
|
||||
found = re.search(r"\bRX (6\d{3})\b", text)
|
||||
if found:
|
||||
number = int(found.group(1))
|
||||
if number >= 6800:
|
||||
return "gfx1030"
|
||||
if number in (6700, 6750) or "6700 XT" in text:
|
||||
return "gfx1031"
|
||||
if 6600 <= number < 6700:
|
||||
return "gfx1032"
|
||||
if number in (6500, 6400):
|
||||
return "gfx1034"
|
||||
return ""
|
||||
|
||||
|
||||
def _windows_adapters_cim() -> list[dict]:
|
||||
"""Second source when the registry key lists nothing: PowerShell's Win32_VideoController (PNPDeviceID has VEN_/DEV_). It can fail for
|
||||
a limited account, so every failure is an empty answer."""
|
||||
if os.name != "nt":
|
||||
return []
|
||||
shell = shutil.which("powershell") or shutil.which("pwsh")
|
||||
if not shell:
|
||||
return []
|
||||
try:
|
||||
done = subprocess.run([shell, "-NoProfile", "-NonInteractive", "-Command",
|
||||
"Get-CimInstance Win32_VideoController | ForEach-Object { $_.PNPDeviceID + '|' + $_.Name + '|' + $_.AdapterRAM }"],
|
||||
capture_output=True, text=True, timeout=15, stdin=subprocess.DEVNULL,
|
||||
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return []
|
||||
found = []
|
||||
for line in done.stdout.splitlines():
|
||||
match = re.search(r"VEN_([0-9A-F]{4})&DEV_([0-9A-F]{4})", line, re.I)
|
||||
if not match:
|
||||
continue
|
||||
parts = line.split("|")
|
||||
ram = int(parts[2]) if len(parts) > 2 and parts[2].strip().isdigit() else 0
|
||||
found.append({"vendor": match.group(1).lower(), "device": int(match.group(2), 16),
|
||||
"name": parts[1].strip() if len(parts) > 1 else "",
|
||||
"vram_gb": (ram / 2 ** 30) if ram > 0 else 0.0})
|
||||
return found
|
||||
|
||||
|
||||
def windows_display_adapters() -> list[dict]:
|
||||
"""The display adapters Windows has a driver for (the display-class registry key, readable without admin and without running
|
||||
anything): {"vendor": "10de"|"1002"|"8086"|..., "device": int, "name", "vram_gb"}. Empty off Windows or when it cannot be read."""
|
||||
"""The display adapters Windows has a driver for: the display-class registry key (readable without admin and without running
|
||||
anything), then Win32_VideoController when the key lists nothing: {"vendor": "10de"|"1002"|"8086"|..., "device": int, "name",
|
||||
"vram_gb"}. Empty off Windows or when neither can be read."""
|
||||
return _windows_display_adapters_registry() or _windows_adapters_cim()
|
||||
|
||||
|
||||
def _windows_display_adapters_registry() -> list[dict]:
|
||||
found: list[dict] = []
|
||||
try:
|
||||
import winreg
|
||||
@@ -534,6 +604,11 @@ def windows_amd_cards(adapters: list[dict] | None = None) -> list[dict]:
|
||||
continue
|
||||
device = adapter.get("device")
|
||||
arch = WIN_AMD_DEVICE_ARCH.get(device) or WIN_AMD_UMA_IDS.get(device) or ""
|
||||
if not arch and device not in WIN_AMD_IGPU_IDS:
|
||||
guess = gfx_from_name(adapter.get("name", "")) # a card whose id is not in the table: its name says
|
||||
if guess in ("gfx1103", "gfx1150", "gfx1152"): # (those are integrated Radeons)
|
||||
continue
|
||||
arch = guess
|
||||
if not arch and (device in WIN_AMD_IGPU_IDS or float(adapter.get("vram_gb") or 0) < 3.0):
|
||||
continue # an integrated Radeon (512 MB of carve-out)
|
||||
cards.append({"arch": arch, "name": adapter.get("name", ""), "device": device})
|
||||
|
||||
@@ -386,7 +386,44 @@ def select_engine(packages, hardware: dict) -> tuple[EnginePackage | None, list[
|
||||
reasons.extend(why)
|
||||
else:
|
||||
fitting.append(pkg)
|
||||
if not fitting:
|
||||
return None, reasons
|
||||
fitting = _settle_hip_variants(fitting, hardware, reasons)
|
||||
if not fitting:
|
||||
return None, reasons
|
||||
best = max(fitting, key=lambda p: (version_key(p.version), ec._version_key(p.min_driver.get("nvidia", "0"))))
|
||||
return best, reasons
|
||||
|
||||
|
||||
def _hip_variants(fitting) -> set[str]:
|
||||
return {p.variant for p in fitting if p.backend == "hip"}
|
||||
|
||||
|
||||
def _settle_hip_variants(fitting: list, hardware: dict, reasons: list[str]) -> list:
|
||||
"""Several HIP builds "fit" only when this PC's gfx is unknown (an empty list fits everything). Version must never decide
|
||||
between them: the newest build of the wrong card family would be refused at its test start. Order of evidence: the variant asked
|
||||
for, the GPU's name, the variant already installed (an update never switches card family), then give up with a plain reason."""
|
||||
if hardware.get("backend") != "hip" or hardware.get("gfx"):
|
||||
return fitting
|
||||
hip = [p for p in fitting if p.backend == "hip"]
|
||||
if len({p.variant for p in hip}) < 2:
|
||||
return fitting
|
||||
from strata_control import engine_component as ec
|
||||
chosen, why = [], ""
|
||||
wanted = str(hardware.get("variant_wanted") or "").lower()
|
||||
if wanted:
|
||||
chosen = [p for p in hip if p.variant.lower() == wanted]
|
||||
why = f"the {wanted} build was asked for"
|
||||
if not chosen:
|
||||
guesses = {g for g in (ec.gfx_from_name(n) for n in hardware.get("gpu_names") or []) if g}
|
||||
chosen = [p for p in hip if any(a in guesses for a in p.archs)]
|
||||
why = f"the GPU name ({', '.join(hardware.get('gpu_names') or [])}) is a {', '.join(sorted(guesses))}" if chosen else ""
|
||||
if not chosen and hardware.get("installed_variant"):
|
||||
chosen = [p for p in hip if p.variant == hardware["installed_variant"]]
|
||||
why = f"the installed {hardware['installed_variant']} build is kept, this PC's AMD card could not be identified"
|
||||
if not chosen:
|
||||
reasons.append("Strata cannot tell which AMD build this PC needs (" + ", ".join(sorted(_hip_variants(hip))) +
|
||||
"); the card was not recognised, so nothing was chosen. Name the build with STRATA_ENGINE_BACKEND=hip-<build>")
|
||||
return [p for p in fitting if p.backend != "hip"]
|
||||
reasons.append(f"several AMD builds fit; chose {chosen[0].variant}: {why}")
|
||||
return [p for p in fitting if p.backend != "hip" or p in chosen]
|
||||
@@ -190,22 +190,44 @@ def _gfx_names() -> list[str]:
|
||||
found = sorted(set(re.findall(r"\bgfx[0-9a-f]{3,4}\b", done.stdout)))
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
pass
|
||||
if not found and os.name == "nt":
|
||||
# a normal Windows PC has no hipInfo (it ships with the HIP SDK): the display adapters' PCI ids / names say which gfx it is
|
||||
try:
|
||||
found = ec.hip_archs_present()
|
||||
except Exception: # noqa: BLE001 - detection is best effort
|
||||
found = []
|
||||
return sorted(set(found))
|
||||
|
||||
|
||||
def _amd_card_names() -> list[str]:
|
||||
if os.name != "nt":
|
||||
return []
|
||||
try:
|
||||
return [c["name"] for c in ec.windows_amd_cards() if c.get("name")]
|
||||
except Exception: # noqa: BLE001
|
||||
return []
|
||||
|
||||
|
||||
def detect_hardware(environ=None) -> dict:
|
||||
"""What the package choice depends on. Read-only probes of tools that are already installed (nvidia-smi, rocminfo, sysfs);
|
||||
``STRATA_ENGINE_BACKEND`` overrides the backend like it does for a start. Anything unreadable is left empty, which the
|
||||
selection treats as "cannot tell", never as a refusal."""
|
||||
environ = os.environ if environ is None else environ
|
||||
prefer = ""
|
||||
forced = str(environ.get(ec.ENV_BACKEND, "")).strip().lower()
|
||||
if forced.startswith("hip-") and forced not in ec.BACKEND_MATRIX:
|
||||
# "hip-rx9070" is how the feed labels a package; accept it as "the hip family, this variant"
|
||||
prefer = forced[4:]
|
||||
environ = {**environ, ec.ENV_BACKEND: "hip"}
|
||||
backend, how = ec.detect_backend(environ)
|
||||
hw = {"platform": host_platform(), "backend": backend, "backend_source": how, "runtime": ec.runtime_version(),
|
||||
"nvidia_driver": None, "cuda_archs": [], "gfx": []}
|
||||
"nvidia_driver": None, "cuda_archs": [], "gfx": [], "gpu_names": [], "variant_wanted": prefer}
|
||||
if backend == "cuda":
|
||||
hw["nvidia_driver"] = ec.nvidia_driver_version()
|
||||
hw["cuda_archs"] = ec.cuda_archs_present()
|
||||
elif backend == "hip":
|
||||
hw["gfx"] = _gfx_names()
|
||||
hw["gpu_names"] = _amd_card_names()
|
||||
return hw
|
||||
|
||||
|
||||
@@ -454,7 +476,8 @@ def decide_engine(feed: feedmod.Feed, ctx: Context, state: State) -> dict:
|
||||
|
||||
def _choose_engine(feed: feedmod.Feed, ctx: Context, state: State) -> tuple[dict, feedmod.EnginePackage | None]:
|
||||
installed, missing_reason = installed_engine(ctx.components, ctx.hardware)
|
||||
offered, reasons = feedmod.select_engine([p for p in feed.engine], ctx.hardware)
|
||||
sticky = {**ctx.hardware, "installed_variant": installed.variant if installed is not None and installed.backend == "hip" else ""}
|
||||
offered, reasons = feedmod.select_engine([p for p in feed.engine], sticky)
|
||||
section = state.section("engine")
|
||||
report = {"installed": _engine_view(installed), "offered": offered.to_dict() if offered else None,
|
||||
"reasons": reasons, "status": "none-for-this-pc", "download_bytes": 0,
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
"""#3456 / #3486: an RX 9070 on Windows has no hipInfo, so the gfx list is empty and every HIP build "fits". The newest version (the rdna3
|
||||
build, 0.1.46.1) then won over the rx9070 one (0.1.46). Selection must follow the GPU name or the installed variant, never the version."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from strata_control import engine_component as ec, feed as feedmod, updater
|
||||
|
||||
WIN = "windows-x86_64"
|
||||
|
||||
|
||||
def pkg(version, variant, archs):
|
||||
return feedmod._engine_package({
|
||||
"version": version, "platform": WIN, "backend": "hip", "variant": variant, "archs": list(archs), "min_driver": {},
|
||||
"min_runtime": None, "build_id": f"b-{version}-{variant}", "format": "zip", "url": f"e-{version}-{variant}.zip", "size": 10,
|
||||
"sha256": "a" * 64, "manifest_sha256": "b" * 64, "installed_bytes": 20, "notes": ""})
|
||||
|
||||
|
||||
FEED = [pkg("0.1.46", "rx9070", ("gfx1200", "gfx1201")), pkg("0.1.46.1", "rdna3", ("gfx1100", "gfx1101", "gfx1102", "gfx1151"))]
|
||||
|
||||
|
||||
def hw(names=(), gfx=(), installed="", wanted=""):
|
||||
return {"platform": WIN, "backend": "hip", "runtime": "0.2.1.3", "nvidia_driver": None, "cuda_archs": [], "gfx": list(gfx),
|
||||
"gpu_names": list(names), "installed_variant": installed, "variant_wanted": wanted}
|
||||
|
||||
|
||||
class Selection(unittest.TestCase):
|
||||
def pick(self, hardware):
|
||||
best, reasons = feedmod.select_engine(FEED, hardware)
|
||||
return (best.variant if best else None), reasons
|
||||
|
||||
def test_rx9070_with_empty_gfx_gets_rx9070(self):
|
||||
for name in ("AMD Radeon RX 9070 XT", "AMD Radeon RX 9070", "AMD Radeon RX 9060 XT", "AMD Radeon AI PRO R9700"):
|
||||
self.assertEqual(self.pick(hw([name]))[0], "rx9070", name)
|
||||
|
||||
def test_strix_halo_and_rx7900_with_empty_gfx_get_rdna3(self):
|
||||
self.assertEqual(self.pick(hw(["AMD Radeon(TM) 8060S Graphics"]))[0], "rdna3")
|
||||
self.assertEqual(self.pick(hw(["AMD Radeon RX 7900 XTX"]))[0], "rdna3")
|
||||
self.assertEqual(self.pick(hw(["AMD Radeon RX 7600"]))[0], "rdna3")
|
||||
|
||||
def test_unknown_amd_keeps_the_installed_variant(self):
|
||||
got, why = self.pick(hw(["AMD Radeon Mystery"], installed="rx9070"))
|
||||
self.assertEqual(got, "rx9070")
|
||||
self.assertTrue(any("kept" in r for r in why))
|
||||
self.assertEqual(self.pick(hw([], installed="rdna3"))[0], "rdna3")
|
||||
|
||||
def test_unknown_amd_and_nothing_installed_chooses_nothing_instead_of_the_newest(self):
|
||||
got, why = self.pick(hw([]))
|
||||
self.assertIsNone(got)
|
||||
self.assertTrue(any("cannot tell" in r for r in why))
|
||||
|
||||
def test_the_name_beats_a_stale_installed_variant_when_the_card_changed(self):
|
||||
self.assertEqual(self.pick(hw(["AMD Radeon RX 9070 XT"], installed="rdna3"))[0], "rx9070")
|
||||
|
||||
def test_a_known_gfx_is_unchanged(self):
|
||||
self.assertEqual(self.pick(hw(gfx=["gfx1201"]))[0], "rx9070")
|
||||
self.assertEqual(self.pick(hw(gfx=["gfx1151"]))[0], "rdna3")
|
||||
|
||||
def test_the_variant_can_be_asked_for(self):
|
||||
self.assertEqual(self.pick(hw([], wanted="rx9070"))[0], "rx9070")
|
||||
|
||||
|
||||
class Names(unittest.TestCase):
|
||||
def test_names(self):
|
||||
table = {"AMD Radeon RX 9070 XT": "gfx1201", "AMD Radeon RX 9060 XT": "gfx1200", "AMD Radeon AI PRO R9700": "gfx1201",
|
||||
"AMD Radeon RX 7900 XTX": "gfx1100", "AMD Radeon RX 7800 XT": "gfx1101", "AMD Radeon RX 7700 XT": "gfx1101",
|
||||
"AMD Radeon RX 7600 XT": "gfx1102", "AMD Radeon(TM) 8060S Graphics": "gfx1151", "AMD Radeon 780M Graphics": "gfx1103",
|
||||
"AMD Radeon 890M Graphics": "gfx1150", "AMD Radeon RX 6800 XT": "gfx1030", "NVIDIA GeForce RTX 4090": "", "": ""}
|
||||
for name, gfx in table.items():
|
||||
self.assertEqual(ec.gfx_from_name(name), gfx, name)
|
||||
|
||||
def test_a_card_with_an_unlisted_pci_id_is_identified_by_its_name(self):
|
||||
cards = ec.windows_amd_cards([{"vendor": "1002", "device": 0x7551 + 0x100, "name": "AMD Radeon RX 9070 XT", "vram_gb": 0.0}])
|
||||
self.assertEqual([c["arch"] for c in cards], ["gfx1201"])
|
||||
self.assertEqual(ec.windows_amd_cards([{"vendor": "1002", "device": 0x9999, "name": "AMD Radeon(TM) Graphics", "vram_gb": 0.5}]), [])
|
||||
self.assertEqual(ec.windows_amd_cards([{"vendor": "1002", "device": 0x9999, "name": "AMD Radeon 890M Graphics", "vram_gb": 4.0}]), [])
|
||||
|
||||
|
||||
class Detection(unittest.TestCase):
|
||||
def test_windows_without_hipinfo_reads_the_gfx_from_the_adapters(self):
|
||||
adapters = [{"vendor": "1002", "device": 0x7550, "name": "AMD Radeon RX 9070 XT", "vram_gb": 16.0}]
|
||||
with mock.patch.object(updater.os, "name", "nt"), mock.patch.object(updater.shutil, "which", return_value=None), \
|
||||
mock.patch.object(ec, "windows_display_adapters", return_value=adapters):
|
||||
self.assertEqual(updater._gfx_names(), ["gfx1201"])
|
||||
self.assertEqual(updater._amd_card_names(), ["AMD Radeon RX 9070 XT"])
|
||||
|
||||
def test_the_feed_style_backend_name_is_accepted(self):
|
||||
with mock.patch.object(updater, "_gfx_names", return_value=[]), mock.patch.object(updater, "_amd_card_names", return_value=[]):
|
||||
got = updater.detect_hardware({ec.ENV_BACKEND: "hip-rx9070"})
|
||||
self.assertEqual((got["backend"], got["variant_wanted"]), ("hip", "rx9070"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user