okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221WSL 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; tests7025a9979

main
3.2 KiB65 linesraw
1"""The Linux AMD (HIP) engines hang under WSL (/dev/dxg present, /dev/kfd absent: librocdxg never completes a barrier-AND packet).
2Setup and launch say so in plain words with one next step, as a warning, and never refuse."""
3
4from __future__ import annotations
5
6import tempfile
7import unittest
8from pathlib import Path
9from unittest import mock
10
11from strata_cli.launch import settings as S
12from strata_cli.launch.runner import Runner
13from strata_control import engine_component as ec
14
15
16def dev(root: str, dxg: bool = True, kfd: bool = False) -> str:
17    for name, on in (("dxg", dxg), ("kfd", kfd)):
18        if on:
19            Path(root, name).write_text("", encoding="utf-8")
20    return root
21
22
23class WslAmdNote(unittest.TestCase):
24    def test_wsl_with_dxg_and_no_kfd_on_hip_gets_one_plain_sentence_with_a_next_step(self):
25        with tempfile.TemporaryDirectory() as d:
26            note = ec.wsl_amd_note("hip", dev(d), wsl=True)
27        self.assertIn("do not run under WSL yet", note)
28        self.assertIn("Windows", note)                     # the one next step: the Windows app or Terminal
29
30    def test_nothing_to_say_elsewhere(self):
31        with tempfile.TemporaryDirectory() as d:
32            self.assertIsNone(ec.wsl_amd_note("hip", dev(d), wsl=False))                    # a real Linux box
33            self.assertIsNone(ec.wsl_amd_note("cuda", dev(d), wsl=True))                    # NVIDIA works under WSL
34            self.assertIsNone(ec.wsl_amd_note(None, dev(d), wsl=True))
35        with tempfile.TemporaryDirectory() as d:
36            self.assertIsNone(ec.wsl_amd_note("hip", dev(d, dxg=True, kfd=True), wsl=True))  # a /dev/kfd means the native driver
37        with tempfile.TemporaryDirectory() as d:
38            self.assertIsNone(ec.wsl_amd_note("hip", dev(d, dxg=False), wsl=True))           # no /dev/dxg: not the WSL GPU bridge
39
40    def test_launch_warns_and_goes_on(self):
41        events = []
42        r = Runner(S.LaunchSettings(family="qwen", model="Q2_0", context=32768), catalog=mock.Mock(), emit=events.append)
43        with mock.patch.object(ec, "wsl_amd_note", side_effect=lambda backend, *a, **k: "WSL note" if backend == "hip" else None), \
44                mock.patch.object(ec, "detect_backend", return_value=("hip", "test")):
45            r.warn_wsl_amd()
46        self.assertEqual([(e.level, e.text) for e in events], [("warn", "WSL note")])
47        self.assertIn("WSL note", r.notices)
48
49    def test_launch_is_silent_when_the_backend_is_not_hip(self):
50        events = []
51        r = Runner(S.LaunchSettings(family="qwen", model="Q2_0", context=32768), catalog=mock.Mock(), emit=events.append)
52        with mock.patch.object(ec, "wsl_amd_note", side_effect=lambda backend, *a, **k: "WSL note" if backend == "hip" else None), \
53                mock.patch.object(ec, "detect_backend", return_value=("cuda", "test")):
54            r.warn_wsl_amd()
55        self.assertEqual(events, [])
56
57    def test_setup_warns_in_the_hip_branch_and_does_not_fail_on_its_own(self):
58        text = (Path(__file__).resolve().parents[2] / "setup.py").read_text(encoding="utf-8")
59        i = text.index("wsl_amd_note(\"hip\", wsl=is_wsl())")
60        self.assertIn("warn(wsl_note)", text[i:i + 200])
61        self.assertLess(i, text.index("no AMD GPU Strata can use"))
62
63
64if __name__ == "__main__":
65    unittest.main()