okami.mom/strata

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

Niko1221Merge f-029-urgent (bc694233b)99866a47a

main
1.9 KiB52 linesraw
1"""A PC with only the amdgpu driver (no rocm-smi, no setup module) still counts every AMD card, from a fake sysfs.
2
3    python -m unittest tools.test_kfd_gpus
4"""
5import sys
6import tempfile
7import unittest
8from pathlib import Path
9
10ROOT = Path(__file__).resolve().parents[1]
11sys.path.insert(0, str(ROOT))
12sys.path.insert(0, str(ROOT / "tools"))
13import strata_mcp as M  # noqa: E402
14
15
16def node(root: Path, i: int, ver: int, simd: int, minor: int, vram: int = 0, name: str | None = None):
17    n = root / "class/kfd/kfd/topology/nodes" / str(i)
18    n.mkdir(parents=True)
19    (n / "properties").write_text(f"cpu_cores_count {0 if simd else 12}\nsimd_count {simd}\ngfx_target_version {ver}\ndrm_render_minor {minor}\n")
20    if simd:
21        d = root / f"class/drm/renderD{minor}/device"
22        d.mkdir(parents=True)
23        (d / "mem_info_vram_total").write_text(str(vram))
24        if name:
25            (d / "product_name").write_text(name + "\n")
26
27
28class KfdGpus(unittest.TestCase):
29    def test_four_cards_and_the_cpu_node(self):
30        with tempfile.TemporaryDirectory() as tmp:
31            root = Path(tmp)
32            node(root, 0, 0, 0, 0)
33            for k in range(4):
34                node(root, k + 1, 120001, 128, 128 + k, 32 << 30, "AMD Radeon AI PRO R9700")
35            gpus = M.kfd_gpus(tmp)
36        self.assertEqual([g["index"] for g in gpus], [0, 1, 2, 3])
37        self.assertTrue(all(g["usable"] and g["arch"] == "gfx1201" and g["vram_gb"] == 32.0 for g in gpus))
38
39    def test_an_unlisted_architecture_is_named_not_hidden(self):
40        with tempfile.TemporaryDirectory() as tmp:
41            node(Path(tmp), 0, 90010, 60, 128, 8 << 30)
42            (g,) = M.kfd_gpus(tmp)
43        self.assertFalse(g["usable"])
44        self.assertIn("gfx90a", g["problem"])
45
46    def test_no_amd_driver_is_an_empty_list(self):
47        with tempfile.TemporaryDirectory() as tmp:
48            self.assertEqual(M.kfd_gpus(tmp), [])
49
50
51if __name__ == "__main__":
52    unittest.main()