okami.mom/strata

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

Niko1221The linux-aarch64 platform: engine packages, Control (Terminal) and the signed feed for the DGX Sparkf436dba81

main
13.4 KiB206 linesraw
1"""The 0.2.0-beta release set as a signed feed offers it: one engine package per platform/backend/variant (values copied from the
2packages' engine-component.json), and what `feed.select_engine` hands each kind of PC. This is the evidence that engine updates
3reach every installer variant by card, so the app update can stay engine-less (tauri.update.conf.json)."""
4from __future__ import annotations
5
6import os
7import sys
8import tarfile
9import tempfile
10import unittest
11from pathlib import Path
12
13from strata_control import feed as feedmod
14
15sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "packaging"))
16import feed_tool  # noqa: E402
17
18V = "0.1.45.3"
19SM_NEW = ("sm_75", "sm_86", "sm_89", "sm_120", "compute_120")                       # the CUDA 13 packages
20SM_OLD = ("sm_60", "sm_61", "sm_70", "sm_75", "sm_80", "sm_86", "sm_89", "compute_89")   # the CUDA 12 packages (Pascal and Volta)
21
22
23def pkg(platform, backend, variant, archs, driver=None):
24    return {"version": V, "platform": platform, "backend": backend, "variant": variant, "archs": list(archs),
25            "min_driver": {"nvidia": driver} if driver else {}, "min_runtime": None,
26            "build_id": f"rel-{platform}-{backend}-{variant}", "format": "tar.gz", "url": f"strata-engine-{platform}-{variant}.tar.gz",
27            "size": 1000, "sha256": "a" * 64, "manifest_sha256": "b" * 64, "installed_bytes": 2000, "notes": ""}
28
29
30RELEASE = [
31    pkg("windows-x86_64", "cuda", "cuda13", SM_NEW, "580.65"),
32    pkg("windows-x86_64", "cuda", "cuda12", SM_OLD, "576.02"),
33    pkg("windows-x86_64", "hip", "rx9070", ("gfx1200", "gfx1201")),
34    pkg("windows-x86_64", "hip", "rdna3", ("gfx1100", "gfx1101", "gfx1102", "gfx1151")),
35    pkg("windows-x86_64", "hip", "rdna2", ("gfx1030", "gfx1031")),
36    pkg("linux-x86_64", "cuda", "cuda13", SM_NEW, "580.65"),
37    pkg("linux-x86_64", "cuda", "cuda12", SM_OLD, "575.51"),
38    pkg("linux-x86_64", "hip", "rx9070", ("gfx1200", "gfx1201")),
39    pkg("linux-x86_64", "hip", "rx7900", ("gfx1100", "gfx1101", "gfx1102")),
40    pkg("linux-x86_64", "hip", "halo", ("gfx1151",)),
41    pkg("linux-x86_64", "hip", "rx6000", ("gfx1030", "gfx1031")),
42    pkg("linux-aarch64", "cuda", "cuda13", ("sm_121", "compute_121"), "580.65"),     # the NVIDIA DGX Spark (GB10), 0.2.7.1
43    pkg("linux-x86_64", "sycl", "", ("intel-arc",)),                 # the Intel Arc (A and B series) engine, GPU code JIT-compiled
44    pkg("macos-arm64", "metal", "", ("apple-gpu",)),
45]
46
47
48def pc(platform, backend, driver=None, sm=(), gfx=()):
49    return {"platform": platform, "backend": backend, "runtime": "0.2.0", "nvidia_driver": driver, "cuda_archs": list(sm), "gfx": list(gfx)}
50
51
52class ReleaseSelection(unittest.TestCase):
53    def pick(self, hardware):
54        best, reasons = feedmod.select_engine([feedmod._engine_package(p) for p in RELEASE], hardware)
55        return (best.platform, best.backend, best.variant) if best else None, reasons
56
57    def test_every_release_variant_is_chosen_by_some_pc(self):
58        chosen = {
59            self.pick(pc("windows-x86_64", "cuda", "590.10", ["sm_120"]))[0],     # RTX 5070
60            self.pick(pc("windows-x86_64", "cuda", "576.02", ["sm_61"]))[0],      # GTX 1080 on an older driver
61            self.pick(pc("windows-x86_64", "hip", gfx=["gfx1201"]))[0],           # RX 9070
62            self.pick(pc("windows-x86_64", "hip", gfx=["gfx1100"]))[0],           # RX 7900 XTX
63            self.pick(pc("windows-x86_64", "hip", gfx=["gfx1030"]))[0],           # RX 6800 XT
64            self.pick(pc("linux-x86_64", "cuda", "615.71", ["sm_86"]))[0],        # RTX 3060
65            self.pick(pc("linux-x86_64", "cuda", "575.51", ["sm_60"]))[0],        # Tesla P100
66            self.pick(pc("linux-x86_64", "hip", gfx=["gfx1201"]))[0],             # Radeon AI PRO R9700
67            self.pick(pc("linux-x86_64", "hip", gfx=["gfx1100"]))[0],             # RX 7900 XTX
68            self.pick(pc("linux-x86_64", "hip", gfx=["gfx1151"]))[0],             # Ryzen AI Max (Strix Halo)
69            self.pick(pc("linux-x86_64", "hip", gfx=["gfx1031"]))[0],             # RX 6700 XT
70            self.pick(pc("linux-aarch64", "cuda", "580.173", ["sm_121"]))[0],     # DGX Spark (GB10)
71            self.pick(pc("linux-x86_64", "sycl"))[0],                             # Arc A750 / B580 / Pro B70
72            self.pick(pc("macos-arm64", "metal"))[0],
73        }
74        self.assertEqual(chosen, {(p["platform"], p["backend"], p["variant"]) for p in RELEASE})
75
76    def test_cuda_13_or_12_follows_the_driver_and_the_card(self):
77        win = "windows-x86_64"
78        self.assertEqual(self.pick(pc(win, "cuda", "580.65", ["sm_86"]))[0][2], "cuda13")
79        self.assertEqual(self.pick(pc(win, "cuda", "590.10", ["sm_120"]))[0][2], "cuda13")
80        got, why = self.pick(pc(win, "cuda", "576.02", ["sm_120"]))                 # a new card on an older driver: CUDA 12 reaches it by PTX
81        self.assertEqual(got[2], "cuda12")
82        self.assertTrue(any("580.65" in r for r in why))
83        self.assertEqual(self.pick(pc(win, "cuda", "615.71", ["sm_70"]))[0][2], "cuda12", "Volta is only in the CUDA 12 build")
84        self.assertEqual(self.pick(pc("linux-x86_64", "cuda", "575.51", ["sm_75"]))[0][2], "cuda12")
85        self.assertEqual(self.pick(pc("linux-x86_64", "cuda", "580.65", ["sm_75"]))[0][2], "cuda13")
86
87    def test_the_dgx_spark_gets_the_aarch64_build_and_no_other_pc_does(self):
88        self.assertEqual(self.pick(pc("linux-aarch64", "cuda", "580.173", ["sm_121"]))[0], ("linux-aarch64", "cuda", "cuda13"))
89        for hw in (pc("linux-x86_64", "cuda", "590.10", ["sm_120"]), pc("linux-x86_64", "cuda", "590.10", ["sm_121"]),
90                   pc("windows-x86_64", "cuda", "590.10", ["sm_121"])):
91            self.assertNotEqual(self.pick(hw)[0][0], "linux-aarch64", hw)
92        got, why = self.pick(pc("linux-aarch64", "cuda", "580.173", ["sm_86"]))      # an arm64 server with an A-series card: no machine code for it
93        self.assertIsNone(got)
94        self.assertTrue(any("sm_121" in r for r in why))
95        got, why = self.pick(pc("linux-aarch64", "cuda", "570.10", ["sm_121"]))      # the driver is too old
96        self.assertIsNone(got)
97        self.assertTrue(any("580.65" in r for r in why))
98        self.assertIsNone(self.pick(pc("linux-aarch64", "hip", gfx=["gfx1201"]))[0])    # no AMD engine for arm64 Linux
99
100    def test_a_driver_that_is_too_old_gets_no_engine_and_a_reason(self):
101        got, why = self.pick(pc("windows-x86_64", "cuda", "551.00", ["sm_86"]))
102        self.assertIsNone(got)
103        self.assertTrue(any("576.02" in r for r in why) and any("580.65" in r for r in why))
104
105    def test_amd_gets_its_own_build_and_never_a_cuda_one(self):
106        self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=["gfx1200"]))[0][2], "rx9070")
107        self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=["gfx1102"]))[0][2], "rx7900")
108        for hw in (pc("windows-x86_64", "hip", gfx=["gfx1201"]), pc("linux-x86_64", "hip", gfx=["gfx1201"])):
109            self.assertEqual(self.pick(hw)[0][1], "hip")
110
111    def test_rx7000_and_strix_halo_on_windows_get_the_rdna3_build(self):
112        for gfx in ("gfx1100", "gfx1101", "gfx1102", "gfx1151"):
113            self.assertEqual(self.pick(pc("windows-x86_64", "hip", gfx=[gfx]))[0], ("windows-x86_64", "hip", "rdna3"), gfx)
114        self.assertEqual(self.pick(pc("windows-x86_64", "hip", gfx=["gfx1201"]))[0][2], "rx9070")
115        self.assertEqual(self.pick(pc("windows-x86_64", "hip", gfx=["gfx1200"]))[0][2], "rx9070")
116
117    def test_strix_halo_on_linux_gets_the_halo_build_and_rx7000_keeps_rx7900(self):
118        self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=["gfx1151"]))[0], ("linux-x86_64", "hip", "halo"))
119        for gfx in ("gfx1100", "gfx1101", "gfx1102"):
120            self.assertEqual(self.pick(pc("linux-x86_64", "hip", gfx=[gfx]))[0][2], "rx7900", gfx)
121
122    def test_no_amd_card_matches_two_hip_builds_of_one_platform(self):
123        """A tie between two builds of the same version would be settled by list order: no arch may be in two hip builds of a platform."""
124        for platform in ("windows-x86_64", "linux-x86_64"):
125            seen = {}
126            for p in RELEASE:
127                if p["platform"] == platform and p["backend"] == "hip":
128                    for arch in p["archs"]:
129                        self.assertNotIn(arch, seen, f"{arch} is in {seen.get(arch)} and {p['variant']} on {platform}")
130                        seen[arch] = p["variant"]
131
132    def test_other_unified_memory_radeons_get_no_engine_and_the_plain_family_line(self):
133        from strata_control import engine_component as ec
134        for platform in ("windows-x86_64", "linux-x86_64"):
135            for gfx in ("gfx1103", "gfx1150", "gfx1152", "gfx1032"):
136                got, why = self.pick(pc(platform, "hip", gfx=[gfx]))
137                self.assertIsNone(got, f"{gfx} on {platform}")
138                self.assertTrue(any(gfx in r for r in why))
139        self.assertEqual(ec.arch_notice(("gfx1100", "gfx1151"), ["gfx1201"]),
140                         "This build of Strata is for AMD RX 7000 and Ryzen AI Max cards. This computer has an AMD RX 9000 card (gfx1201). Ask for the RX 9000 build.")
141        self.assertEqual(ec.arch_notice(("gfx1151",), ["gfx1201"]),
142                         "This build of Strata is for AMD Ryzen AI Max cards. This computer has an AMD RX 9000 card (gfx1201). Ask for the RX 9000 build.")
143
144    def test_rx6000_has_its_own_package_and_only_gfx103x_cards_get_it(self):
145        """0.2.2: gfx1030 / gfx1031 are in the RX 6000 package (Linux rx6000, Windows rdna2) and in no other; no RX 7000 / 9000 card gets it."""
146        from strata_control import engine_component as ec
147        want = {"windows-x86_64": "rdna2", "linux-x86_64": "rx6000"}
148        for platform, variant in want.items():
149            for gfx in ("gfx1030", "gfx1031"):
150                self.assertEqual(self.pick(pc(platform, "hip", gfx=[gfx]))[0], (platform, "hip", variant), (platform, gfx))
151            for gfx in ("gfx1100", "gfx1101", "gfx1102", "gfx1151", "gfx1200", "gfx1201"):
152                got = self.pick(pc(platform, "hip", gfx=[gfx]))[0]
153                self.assertNotEqual(got[2] if got else None, variant, (platform, gfx))
154        self.assertEqual(ec.NO_PACKAGE_HIP, {}, "every card family setup supports has a package; the table is for the next family without one")
155        covered = {a for p in RELEASE if p["backend"] == "hip" for a in p["archs"]}
156        self.assertTrue({"gfx1030", "gfx1031"} <= covered)
157        # the plain family line now names a build that exists
158        self.assertIn("Ask for the RX 6000 build.", ec.arch_notice(("gfx1200", "gfx1201"), ["gfx1030"]))
159        self.assertIsNone(ec.no_package_note(["gfx1030", "gfx1031"]))
160
161    def test_a_pc_with_an_rx7000_beside_an_rx6000_keeps_the_package_it_always_got(self):
162        """Before the RX 6000 package a PC with both cards got the RX 7000 one: the new package must not win that tie, in any feed order."""
163        for platform, old, new in (("windows-x86_64", "rdna3", "rdna2"), ("linux-x86_64", "rx7900", "rx6000")):
164            hardware = pc(platform, "hip", gfx=["gfx1030", "gfx1100"])
165            for order in (RELEASE, list(reversed(RELEASE))):
166                best, _ = feedmod.select_engine([feedmod._engine_package(p) for p in order], hardware)
167                self.assertEqual(best.variant, old, (platform, new))
168        # a Radeon AI PRO (gfx1201) beside an RX 6800 keeps rx9070 too
169        for platform in ("windows-x86_64", "linux-x86_64"):
170            for order in (RELEASE, list(reversed(RELEASE))):
171                best, _ = feedmod.select_engine([feedmod._engine_package(p) for p in order], pc(platform, "hip", gfx=["gfx1201", "gfx1030"]))
172                self.assertEqual(best.variant, "rx9070")
173
174    def test_installed_packages_are_chosen_the_same_way(self):
175        from strata_control import engine_component as ec
176        self.assertEqual(ec.hip_preference(("gfx1030", "gfx1031")), 0)
177        self.assertEqual(ec.hip_preference(("gfx1100", "gfx1101", "gfx1102")), 1)
178        self.assertEqual(ec.hip_preference(("gfx1030", "gfx1100")), 1)
179        self.assertEqual(ec.hip_preference(()), 1)
180
181    def test_the_platform_decides_first(self):
182        self.assertIsNone(self.pick(pc("macos-arm64", "cuda", "590.10", ["sm_86"]))[0])
183        self.assertEqual(self.pick(pc("macos-arm64", "metal"))[0], ("macos-arm64", "metal", ""))
184
185
186class PackedOnWindows(unittest.TestCase):
187    def test_programs_are_recognised_by_their_header_so_a_linux_package_packed_on_windows_keeps_them_executable(self):
188        with tempfile.TemporaryDirectory() as t:
189            root = Path(t)
190            (root / "strata-vision").write_bytes(b"\x7fELF\x02\x01" + bytes(20))
191            (root / "libx.dylib").write_bytes(b"\xcf\xfa\xed\xfe" + bytes(20))
192            (root / "run.sh").write_bytes(b"#!/bin/sh\n")
193            (root / "BUILD.json").write_text("{}")
194            (root / "kernel.hsaco").write_bytes(b"\x00\x01\x02\x03")
195            names = ("strata-vision", "libx.dylib", "run.sh", "BUILD.json", "kernel.hsaco")
196            self.assertEqual([feed_tool._is_native_executable(root / n) for n in names], [True, True, True, False, False])
197            if os.name == "nt":                     # the owner's release PC: the archive is what matters
198                archive = root / "a.tar.gz"
199                feed_tool._write_archive([(n, root / n) for n in ("strata-vision", "BUILD.json")], archive, "tar.gz", None)
200                with tarfile.open(archive) as tar:
201                    modes = {m.name: m.mode for m in tar.getmembers()}
202                self.assertEqual(modes, {"strata-vision": 0o755, "BUILD.json": 0o644})
203
204
205if __name__ == "__main__":
206    unittest.main()