WSL on AMD: setup and launch say plainly that the AMD (HIP) engines do not run under WSL yet (no /dev/kfd, the GPU bridge never finishes a command) and name the Windows app or Terminal as the next step; a warning, nothing is refused; tests

This commit is contained in:
Niko1221 committed 2026-10-25 11:12:59 +01:00
1 parent 36c6dd9ef5
commit 7025a99799
4 files changed
+100

No files matched your search

+5
View File
@@ -8842,6 +8842,11 @@ def main() -> int:
else "the amdgpu driver's KFD topology is empty)."))
for g in amd:
say(f" GPU {g['index']}: {g['name']}, {amd_mem_text(g)} - " + (amd_problem(g) or "can be used"))
if not WIN: # WSL: the Linux HIP engines hang there; a warning, the run goes on
from strata_control.engine_component import wsl_amd_note
wsl_note = wsl_amd_note("hip", wsl=is_wsl())
if wsl_note:
warn(wsl_note)
usable = [g for g in amd if amd_problem(g) is None]
if not WIN and (amd or amd_pci_devices()): # a warning only: recommend, never force
acc = amd_device_access_problem()
+14
View File
@@ -666,8 +666,22 @@ class Runner:
def _cli(self, *args: str) -> list[str]:
return [self.python, str(ROOT / "strata.py"), *args]
def warn_wsl_amd(self) -> None:
"""Under WSL the Linux AMD engines hang (no /dev/kfd, librocdxg never completes a GPU command): say so plainly with one next step,
and go on (a warning, never a refusal)."""
try:
from strata_control import engine_component as ec
note = ec.wsl_amd_note("hip") and ec.wsl_amd_note(ec.detect_backend()[0]) # the cheap file test first: no GPU tool is run on other systems
except Exception: # noqa: BLE001 - a nicety, never a reason to stop
return
if note:
self.emit("engine", note, level="warn")
if note not in self.notices:
self.notices.append(note)
# ---- 1. the engine
def ensure_engine(self) -> None:
self.warn_wsl_amd()
if self.multi_file(): # DeepSeek: its own engine package (setup fetches it); the Strata engine is not used
self.emit("engine", "DeepSeek runs on its own engine package, so the Strata engine is not downloaded for it.", 100)
return
+16
View File
@@ -524,6 +524,22 @@ def _drm_vendor_makes(root: str = "/sys/class/drm") -> set[str]:
return {backend for vendor, backend in (("0x10de", "cuda"), ("0x1002", "hip"), ("0x8086", "sycl")) if vendor in vendors}
def wsl_amd_note(backend: str | None, dev_root: str = "/dev", wsl: bool | None = None) -> str | None:
"""Under WSL (the GPU is reached through /dev/dxg, there is no /dev/kfd) the Linux AMD (HIP) engines hang: librocdxg 1.2.2
never completes a barrier-AND packet, so the first GPU command never returns. A plain sentence with one next step for that
case, else None. A warning only: the caller goes on (recommend, never force)."""
if backend != "hip":
return None
if wsl is None:
import platform
import sys
wsl = sys.platform.startswith("linux") and "microsoft" in platform.uname().release.lower()
if not wsl or not Path(dev_root, "dxg").exists() or Path(dev_root, "kfd").exists():
return None
return ("The AMD engines do not run under WSL yet: the driver layer WSL uses for the card never finishes a GPU command, so the engine "
"would hang at its first step. Use the Strata app or Terminal for Windows, which run the AMD engine directly.")
def _drm_vendor_backend(root: str = "/sys/class/drm") -> str | None:
"""Linux without the vendor tools on PATH (a HIP box that runs ROCm from Python wheels has no rocminfo): the PCI
vendor of the display adapters decides. NVIDIA 0x10de -> cuda, AMD 0x1002 -> hip, Intel 0x8086 -> sycl, in that
+65
View File
@@ -0,0 +1,65 @@
"""The Linux AMD (HIP) engines hang under WSL (/dev/dxg present, /dev/kfd absent: librocdxg never completes a barrier-AND packet).
Setup and launch say so in plain words with one next step, as a warning, and never refuse."""
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from strata_cli.launch import settings as S
from strata_cli.launch.runner import Runner
from strata_control import engine_component as ec
def dev(root: str, dxg: bool = True, kfd: bool = False) -> str:
for name, on in (("dxg", dxg), ("kfd", kfd)):
if on:
Path(root, name).write_text("", encoding="utf-8")
return root
class WslAmdNote(unittest.TestCase):
def test_wsl_with_dxg_and_no_kfd_on_hip_gets_one_plain_sentence_with_a_next_step(self):
with tempfile.TemporaryDirectory() as d:
note = ec.wsl_amd_note("hip", dev(d), wsl=True)
self.assertIn("do not run under WSL yet", note)
self.assertIn("Windows", note) # the one next step: the Windows app or Terminal
def test_nothing_to_say_elsewhere(self):
with tempfile.TemporaryDirectory() as d:
self.assertIsNone(ec.wsl_amd_note("hip", dev(d), wsl=False)) # a real Linux box
self.assertIsNone(ec.wsl_amd_note("cuda", dev(d), wsl=True)) # NVIDIA works under WSL
self.assertIsNone(ec.wsl_amd_note(None, dev(d), wsl=True))
with tempfile.TemporaryDirectory() as d:
self.assertIsNone(ec.wsl_amd_note("hip", dev(d, dxg=True, kfd=True), wsl=True)) # a /dev/kfd means the native driver
with tempfile.TemporaryDirectory() as d:
self.assertIsNone(ec.wsl_amd_note("hip", dev(d, dxg=False), wsl=True)) # no /dev/dxg: not the WSL GPU bridge
def test_launch_warns_and_goes_on(self):
events = []
r = Runner(S.LaunchSettings(family="qwen", model="Q2_0", context=32768), catalog=mock.Mock(), emit=events.append)
with mock.patch.object(ec, "wsl_amd_note", side_effect=lambda backend, *a, **k: "WSL note" if backend == "hip" else None), \
mock.patch.object(ec, "detect_backend", return_value=("hip", "test")):
r.warn_wsl_amd()
self.assertEqual([(e.level, e.text) for e in events], [("warn", "WSL note")])
self.assertIn("WSL note", r.notices)
def test_launch_is_silent_when_the_backend_is_not_hip(self):
events = []
r = Runner(S.LaunchSettings(family="qwen", model="Q2_0", context=32768), catalog=mock.Mock(), emit=events.append)
with mock.patch.object(ec, "wsl_amd_note", side_effect=lambda backend, *a, **k: "WSL note" if backend == "hip" else None), \
mock.patch.object(ec, "detect_backend", return_value=("cuda", "test")):
r.warn_wsl_amd()
self.assertEqual(events, [])
def test_setup_warns_in_the_hip_branch_and_does_not_fail_on_its_own(self):
text = (Path(__file__).resolve().parents[2] / "setup.py").read_text(encoding="utf-8")
i = text.index("wsl_amd_note(\"hip\", wsl=is_wsl())")
self.assertIn("warn(wsl_note)", text[i:i + 200])
self.assertLess(i, text.index("no AMD GPU Strata can use"))
if __name__ == "__main__":
unittest.main()