okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f436dba81
main
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 ): 24return {"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 = [ 31pkg ("windows-x86_64" ,"cuda" ,"cuda13" ,SM_NEW ,"580.65" ), 32pkg ("windows-x86_64" ,"cuda" ,"cuda12" ,SM_OLD ,"576.02" ), 33pkg ("windows-x86_64" ,"hip" ,"rx9070" , ("gfx1200" ,"gfx1201" )), 34pkg ("windows-x86_64" ,"hip" ,"rdna3" , ("gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1151" )), 35pkg ("windows-x86_64" ,"hip" ,"rdna2" , ("gfx1030" ,"gfx1031" )), 36pkg ("linux-x86_64" ,"cuda" ,"cuda13" ,SM_NEW ,"580.65" ), 37pkg ("linux-x86_64" ,"cuda" ,"cuda12" ,SM_OLD ,"575.51" ), 38pkg ("linux-x86_64" ,"hip" ,"rx9070" , ("gfx1200" ,"gfx1201" )), 39pkg ("linux-x86_64" ,"hip" ,"rx7900" , ("gfx1100" ,"gfx1101" ,"gfx1102" )), 40pkg ("linux-x86_64" ,"hip" ,"halo" , ("gfx1151" ,)), 41pkg ("linux-x86_64" ,"hip" ,"rx6000" , ("gfx1030" ,"gfx1031" )), 42pkg ("linux-aarch64" ,"cuda" ,"cuda13" , ("sm_121" ,"compute_121" ),"580.65" ),# the NVIDIA DGX Spark (GB10), 0.2.7.1 43pkg ("linux-x86_64" ,"sycl" ,"" , ("intel-arc" ,)),# the Intel Arc (A and B series) engine, GPU code JIT-compiled 44pkg ("macos-arm64" ,"metal" ,"" , ("apple-gpu" ,)), 45] 46 47 48def pc (platform ,backend ,driver = None ,sm = (),gfx = ()): 49return {"platform" :platform ,"backend" :backend ,"runtime" :"0.2.0" ,"nvidia_driver" :driver ,"cuda_archs" :list (sm ),"gfx" :list (gfx )} 50 51 52class ReleaseSelection (unittest .TestCase ): 53def pick (self ,hardware ): 54best ,reasons = feedmod .select_engine ([feedmod ._engine_package (p )for p in RELEASE ],hardware ) 55return (best .platform ,best .backend ,best .variant )if best else None ,reasons 56 57def test_every_release_variant_is_chosen_by_some_pc (self ): 58chosen = { 59self .pick (pc ("windows-x86_64" ,"cuda" ,"590.10" , ["sm_120" ]))[0 ],# RTX 5070 60self .pick (pc ("windows-x86_64" ,"cuda" ,"576.02" , ["sm_61" ]))[0 ],# GTX 1080 on an older driver 61self .pick (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1201" ]))[0 ],# RX 9070 62self .pick (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1100" ]))[0 ],# RX 7900 XTX 63self .pick (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1030" ]))[0 ],# RX 6800 XT 64self .pick (pc ("linux-x86_64" ,"cuda" ,"615.71" , ["sm_86" ]))[0 ],# RTX 3060 65self .pick (pc ("linux-x86_64" ,"cuda" ,"575.51" , ["sm_60" ]))[0 ],# Tesla P100 66self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1201" ]))[0 ],# Radeon AI PRO R9700 67self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1100" ]))[0 ],# RX 7900 XTX 68self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1151" ]))[0 ],# Ryzen AI Max (Strix Halo) 69self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1031" ]))[0 ],# RX 6700 XT 70self .pick (pc ("linux-aarch64" ,"cuda" ,"580.173" , ["sm_121" ]))[0 ],# DGX Spark (GB10) 71self .pick (pc ("linux-x86_64" ,"sycl" ))[0 ],# Arc A750 / B580 / Pro B70 72self .pick (pc ("macos-arm64" ,"metal" ))[0 ], 73 } 74self .assertEqual (chosen , {(p ["platform" ],p ["backend" ],p ["variant" ])for p in RELEASE }) 75 76def test_cuda_13_or_12_follows_the_driver_and_the_card (self ): 77win = "windows-x86_64" 78self .assertEqual (self .pick (pc (win ,"cuda" ,"580.65" , ["sm_86" ]))[0 ][2 ],"cuda13" ) 79self .assertEqual (self .pick (pc (win ,"cuda" ,"590.10" , ["sm_120" ]))[0 ][2 ],"cuda13" ) 80got ,why = self .pick (pc (win ,"cuda" ,"576.02" , ["sm_120" ]))# a new card on an older driver: CUDA 12 reaches it by PTX 81self .assertEqual (got [2 ],"cuda12" ) 82self .assertTrue (any ("580.65" in r for r in why )) 83self .assertEqual (self .pick (pc (win ,"cuda" ,"615.71" , ["sm_70" ]))[0 ][2 ],"cuda12" ,"Volta is only in the CUDA 12 build" ) 84self .assertEqual (self .pick (pc ("linux-x86_64" ,"cuda" ,"575.51" , ["sm_75" ]))[0 ][2 ],"cuda12" ) 85self .assertEqual (self .pick (pc ("linux-x86_64" ,"cuda" ,"580.65" , ["sm_75" ]))[0 ][2 ],"cuda13" ) 86 87def test_the_dgx_spark_gets_the_aarch64_build_and_no_other_pc_does (self ): 88self .assertEqual (self .pick (pc ("linux-aarch64" ,"cuda" ,"580.173" , ["sm_121" ]))[0 ], ("linux-aarch64" ,"cuda" ,"cuda13" )) 89for hw in (pc ("linux-x86_64" ,"cuda" ,"590.10" , ["sm_120" ]),pc ("linux-x86_64" ,"cuda" ,"590.10" , ["sm_121" ]), 90pc ("windows-x86_64" ,"cuda" ,"590.10" , ["sm_121" ])): 91self .assertNotEqual (self .pick (hw )[0 ][0 ],"linux-aarch64" ,hw ) 92got ,why = self .pick (pc ("linux-aarch64" ,"cuda" ,"580.173" , ["sm_86" ]))# an arm64 server with an A-series card: no machine code for it 93self .assertIsNone (got ) 94self .assertTrue (any ("sm_121" in r for r in why )) 95got ,why = self .pick (pc ("linux-aarch64" ,"cuda" ,"570.10" , ["sm_121" ]))# the driver is too old 96self .assertIsNone (got ) 97self .assertTrue (any ("580.65" in r for r in why )) 98self .assertIsNone (self .pick (pc ("linux-aarch64" ,"hip" ,gfx = ["gfx1201" ]))[0 ])# no AMD engine for arm64 Linux 99 100def test_a_driver_that_is_too_old_gets_no_engine_and_a_reason (self ): 101got ,why = self .pick (pc ("windows-x86_64" ,"cuda" ,"551.00" , ["sm_86" ])) 102self .assertIsNone (got ) 103self .assertTrue (any ("576.02" in r for r in why )and any ("580.65" in r for r in why )) 104 105def test_amd_gets_its_own_build_and_never_a_cuda_one (self ): 106self .assertEqual (self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1200" ]))[0 ][2 ],"rx9070" ) 107self .assertEqual (self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1102" ]))[0 ][2 ],"rx7900" ) 108for hw in (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1201" ]),pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1201" ])): 109self .assertEqual (self .pick (hw )[0 ][1 ],"hip" ) 110 111def test_rx7000_and_strix_halo_on_windows_get_the_rdna3_build (self ): 112for gfx in ("gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1151" ): 113self .assertEqual (self .pick (pc ("windows-x86_64" ,"hip" ,gfx = [gfx ]))[0 ], ("windows-x86_64" ,"hip" ,"rdna3" ),gfx ) 114self .assertEqual (self .pick (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1201" ]))[0 ][2 ],"rx9070" ) 115self .assertEqual (self .pick (pc ("windows-x86_64" ,"hip" ,gfx = ["gfx1200" ]))[0 ][2 ],"rx9070" ) 116 117def test_strix_halo_on_linux_gets_the_halo_build_and_rx7000_keeps_rx7900 (self ): 118self .assertEqual (self .pick (pc ("linux-x86_64" ,"hip" ,gfx = ["gfx1151" ]))[0 ], ("linux-x86_64" ,"hip" ,"halo" )) 119for gfx in ("gfx1100" ,"gfx1101" ,"gfx1102" ): 120self .assertEqual (self .pick (pc ("linux-x86_64" ,"hip" ,gfx = [gfx ]))[0 ][2 ],"rx7900" ,gfx ) 121 122def 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.""" 124for platform in ("windows-x86_64" ,"linux-x86_64" ): 125seen = {} 126for p in RELEASE : 127if p ["platform" ]== platform and p ["backend" ]== "hip" : 128for arch in p ["archs" ]: 129self .assertNotIn (arch ,seen ,f" { arch } is in { seen . get ( arch ) } and { p [ 'variant' ] } on { platform } " ) 130seen [arch ]= p ["variant" ] 131 132def test_other_unified_memory_radeons_get_no_engine_and_the_plain_family_line (self ): 133from strata_control import engine_component as ec 134for platform in ("windows-x86_64" ,"linux-x86_64" ): 135for gfx in ("gfx1103" ,"gfx1150" ,"gfx1152" ,"gfx1032" ): 136got ,why = self .pick (pc (platform ,"hip" ,gfx = [gfx ])) 137self .assertIsNone (got ,f" { gfx } on { platform } " ) 138self .assertTrue (any (gfx in r for r in why )) 139self .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." ) 141self .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 144def 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.""" 146from strata_control import engine_component as ec 147want = {"windows-x86_64" :"rdna2" ,"linux-x86_64" :"rx6000" } 148for platform ,variant in want .items (): 149for gfx in ("gfx1030" ,"gfx1031" ): 150self .assertEqual (self .pick (pc (platform ,"hip" ,gfx = [gfx ]))[0 ], (platform ,"hip" ,variant ), (platform ,gfx )) 151for gfx in ("gfx1100" ,"gfx1101" ,"gfx1102" ,"gfx1151" ,"gfx1200" ,"gfx1201" ): 152got = self .pick (pc (platform ,"hip" ,gfx = [gfx ]))[0 ] 153self .assertNotEqual (got [2 ]if got else None ,variant , (platform ,gfx )) 154self .assertEqual (ec .NO_PACKAGE_HIP , {},"every card family setup supports has a package; the table is for the next family without one" ) 155covered = {a for p in RELEASE if p ["backend" ]== "hip" for a in p ["archs" ]} 156self .assertTrue ({"gfx1030" ,"gfx1031" }<= covered ) 157# the plain family line now names a build that exists 158self .assertIn ("Ask for the RX 6000 build." ,ec .arch_notice (("gfx1200" ,"gfx1201" ), ["gfx1030" ])) 159self .assertIsNone (ec .no_package_note (["gfx1030" ,"gfx1031" ])) 160 161def 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.""" 163for platform ,old ,new in (("windows-x86_64" ,"rdna3" ,"rdna2" ), ("linux-x86_64" ,"rx7900" ,"rx6000" )): 164hardware = pc (platform ,"hip" ,gfx = ["gfx1030" ,"gfx1100" ]) 165for order in (RELEASE ,list (reversed (RELEASE ))): 166best ,_ = feedmod .select_engine ([feedmod ._engine_package (p )for p in order ],hardware ) 167self .assertEqual (best .variant ,old , (platform ,new )) 168# a Radeon AI PRO (gfx1201) beside an RX 6800 keeps rx9070 too 169for platform in ("windows-x86_64" ,"linux-x86_64" ): 170for order in (RELEASE ,list (reversed (RELEASE ))): 171best ,_ = feedmod .select_engine ([feedmod ._engine_package (p )for p in order ],pc (platform ,"hip" ,gfx = ["gfx1201" ,"gfx1030" ])) 172self .assertEqual (best .variant ,"rx9070" ) 173 174def test_installed_packages_are_chosen_the_same_way (self ): 175from strata_control import engine_component as ec 176self .assertEqual (ec .hip_preference (("gfx1030" ,"gfx1031" )),0 ) 177self .assertEqual (ec .hip_preference (("gfx1100" ,"gfx1101" ,"gfx1102" )),1 ) 178self .assertEqual (ec .hip_preference (("gfx1030" ,"gfx1100" )),1 ) 179self .assertEqual (ec .hip_preference (()),1 ) 180 181def test_the_platform_decides_first (self ): 182self .assertIsNone (self .pick (pc ("macos-arm64" ,"cuda" ,"590.10" , ["sm_86" ]))[0 ]) 183self .assertEqual (self .pick (pc ("macos-arm64" ,"metal" ))[0 ], ("macos-arm64" ,"metal" ,"" )) 184 185 186class PackedOnWindows (unittest .TestCase ): 187def test_programs_are_recognised_by_their_header_so_a_linux_package_packed_on_windows_keeps_them_executable (self ): 188with tempfile .TemporaryDirectory ()as t : 189root = 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" ) 195names = ("strata-vision" ,"libx.dylib" ,"run.sh" ,"BUILD.json" ,"kernel.hsaco" ) 196self .assertEqual ([feed_tool ._is_native_executable (root / n )for n in names ], [True ,True ,True ,False ,False ]) 197if os .name == "nt" :# the owner's release PC: the archive is what matters 198archive = root / "a.tar.gz" 199feed_tool ._write_archive ([(n ,root / n )for n in ("strata-vision" ,"BUILD.json" )],archive ,"tar.gz" ,None ) 200with tarfile .open (archive )as tar : 201modes = {m .name :m .mode for m in tar .getmembers ()} 202self .assertEqual (modes , {"strata-vision" :0o755 ,"BUILD.json" :0o644 }) 203 204 205if __name__ == "__main__" : 206unittest .main ()