okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""Linux on ARM64 (the NVIDIA DGX Spark, 0.2.7.1): the platform name, the CUDA engine package for it, and the release tools that make 2the Terminal and the engine packages for it. Nothing here needs an ARM machine; tests/terminal/test_release_matrix.py holds the feed 3selection rows.""" 4from __future__import annotations 5 6import re 7import sys 8import unittest 9from pathlib import Path 10from unittest import mock 11 12ROOT = Path (__file__ ).resolve ().parents [2 ] 13sys .path .insert (0 ,str (ROOT )) 14sys .path .insert (0 ,str (ROOT / "packaging" )) 15 16from strata_control import engine_component as ec # noqa: E402 17from strata_control import feed as feedmod # noqa: E402 18from strata_control import targets # noqa: E402 19import feed_tool # noqa: E402 20import lock_wheels # noqa: E402 21import package_terminal # noqa: E402 22 23 24def host (system :str ,machine :str )-> str : 25# the name and the architecture come from strata_control.sysinfo: on Windows from sys.platform and the environment (no WMI, #4975), 26# elsewhere from the platform module 27win = system == "Windows" 28env = {"PROCESSOR_ARCHITECTURE" :machine ,"PROCESSOR_ARCHITEW6432" :"" }if win else {} 29with mock .patch .object (targets .platform ,"system" ,return_value = system ),mock .patch .object (targets .platform ,"machine" ,return_value = machine ), \ 30mock .patch .object (sys ,"platform" ,"win32" if win else ("darwin" if system == "Darwin" else "linux" )), \ 31mock .patch .dict ("os.environ" ,env ): 32return targets .host_platform () 33 34 35class PlatformName (unittest .TestCase ): 36def test_linux_arm64_is_linux_aarch64_and_nothing_else_changed (self ): 37self .assertEqual (host ("Linux" ,"aarch64" ),"linux-aarch64" ) 38self .assertEqual (host ("Linux" ,"arm64" ),"linux-aarch64" ) 39self .assertEqual (host ("Linux" ,"x86_64" ),"linux-x86_64" ) 40self .assertEqual (host ("Windows" ,"AMD64" ),"windows-x86_64" ) 41self .assertEqual (host ("Darwin" ,"arm64" ),"macos-arm64" )# a Mac keeps its name 42self .assertEqual (host ("Darwin" ,"x86_64" ),"macos-x86_64" ) 43 44def test_cuda_is_committed_to_on_linux_aarch64_and_no_other_backend_is (self ): 45self .assertTrue (targets .backend_supported ("cuda" ,"linux-aarch64" )[0 ]) 46for backend in ("hip" ,"sycl" ,"metal" ,"cpu" ): 47self .assertFalse (targets .backend_supported (backend ,"linux-aarch64" )[0 ],backend ) 48# the rows that were there are still there 49self .assertTrue (targets .backend_supported ("cuda" ,"linux-x86_64" )[0 ]) 50self .assertTrue (targets .backend_supported ("hip" ,"linux-x86_64" )[0 ]) 51self .assertTrue (targets .backend_supported ("metal" ,"macos-arm64" )[0 ]) 52 53def test_the_feed_knows_the_platform (self ): 54self .assertIn ("linux-aarch64" ,feedmod .PLATFORMS ) 55self .assertEqual (feedmod .TAURI_TARGETS ["linux-aarch64" ],"linux-aarch64" ) 56self .assertEqual (feedmod .PLATFORMS [:2 ], ("windows-x86_64" ,"linux-x86_64" )) 57 58 59class GB10Cards (unittest .TestCase ): 60def test_sm_121_code_covers_a_gb10_and_only_a_12_x_card (self ): 61archs = ("sm_121" ,"compute_121" ) 62self .assertTrue (ec .arch_covers (archs , ["sm_121" ])) 63self .assertFalse (ec .arch_covers (archs , ["sm_120" ]))# machine code is for the card's own minor or a newer one; PTX needs >= 121 64self .assertFalse (ec .arch_covers (archs , ["sm_86" ])) 65self .assertTrue (ec .arch_native (archs , ["sm_121" ])) 66 67 68class ReleaseTools (unittest .TestCase ): 69def test_the_terminal_has_a_pinned_interpreter_for_linux_aarch64 (self ): 70pin = package_terminal .PYTHON_PINS ["linux-aarch64" ] 71self .assertIn ("aarch64-unknown-linux-gnu-install_only.tar.gz" ,pin ["file" ]) 72self .assertRegex (pin ["sha256" ],r"^[0-9a-f]{64}$" ) 73self .assertNotEqual (pin ["sha256" ],package_terminal .PYTHON_PINS ["linux-x86_64" ]["sha256" ]) 74self .assertTrue (pin ["url" ].startswith (package_terminal .PBS_BASE )and "%2B" in pin ["url" ]) 75self .assertEqual (pin ["python" ],"python/bin/python3" ) 76 77def test_host_target_names_linux_arm64 (self ): 78with mock .patch .object (package_terminal .sys ,"platform" ,"linux" ),mock .patch .object (package_terminal .platform ,"machine" ,return_value = "aarch64" ): 79self .assertEqual (package_terminal .host_target (),"linux-aarch64" ) 80with mock .patch .object (package_terminal .sys ,"platform" ,"linux" ),mock .patch .object (package_terminal .platform ,"machine" ,return_value = "x86_64" ): 81self .assertEqual (package_terminal .host_target (),"linux-x86_64" ) 82 83def test_the_runtime_lock_for_linux_aarch64_is_made_the_same_way_and_is_complete (self ): 84spec = lock_wheels .TARGETS ["linux-aarch64" ] 85self .assertTrue (all (p .endswith ("aarch64" )for p in spec ["platforms" ])) 86self .assertEqual (spec ["env" ],lock_wheels .TARGETS ["linux-x86_64" ]["env" ]) 87lock = ROOT / "packaging" / "locks" / "runtime-linux-aarch64-cp312.txt" 88self .assertTrue (lock .is_file (),"run packaging/lock_wheels.py --target linux-aarch64 on the Spark" ) 89names = package_terminal .lock_names (lock ) 90x86 = package_terminal .lock_names (ROOT / "packaging" / "locks" / "runtime-linux-x86_64-cp312.txt" ) 91self .assertEqual (set (names ),set (x86 ),"the same packages as the x86_64 Linux lock" ) 92text = lock .read_text (encoding = "utf-8" ) 93self .assertEqual (len (re .findall (r"^[A-Za-z0-9_.-]+==" ,text ,re .M )),len (names )) 94hashed = re .findall (r"^[A-Za-z0-9_.-]+==\S+ \\\n(?:\s+--hash=sha256:[0-9a-f]{64}(?: \\)?\n?)+" ,text ,re .M ) 95self .assertEqual (len (hashed ),len (names ),"every package of the lock names the SHA-256 of its wheel" ) 96 97def test_pack_control_takes_the_platform (self ): 98parser_choices = feedmod .PLATFORMS 99self .assertIn ("linux-aarch64" ,parser_choices ) 100# the installers' one-line manifest wants tar.gz for every non-Windows platform 101self .assertTrue (feed_tool .feedmod .PLATFORMS is feedmod .PLATFORMS ) 102 103def test_install_sh_installs_on_linux_arm64_and_says_what_the_engine_is_for (self ): 104text = (ROOT / "packaging" / "install.sh" ).read_text (encoding = "utf-8" ) 105self .assertIn ("Linux-aarch64|Linux-arm64) platform=linux-aarch64" ,text ) 106self .assertNotIn ("has no engine for ARM Linux" ,text ) 107self .assertIn ("GB10" ,text ) 108self .assertIn ("Linux-x86_64|Linux-amd64) platform=linux-x86_64" ,text )# unchanged 109self .assertIn ("Darwin-x86_64) die" ,text ) 110 111def test_the_spark_build_script_is_lf_and_names_the_platform (self ): 112raw = (ROOT / "spark" / "build_engine.sh" ).read_bytes () 113self .assertNotIn (b"\r" ,raw ) 114self .assertIn (b'linux-aarch64' ,raw ) 115self .assertIn (b"-DSTRATA_PORTABLE=ON" ,raw ) 116 117 118class GB10Probes (unittest .TestCase ): 119"""nvidia-smi gives a GB10's memory.total as [N/A]: the probes the Terminal reads must neither drop the card nor invent a size.""" 120LINE = "0, NVIDIA GB10, GPU-0a1b2c3d-0000-1111-2222-333344445555, [N/A], 580.173.02\n" 121 122def cards (self ,machine ): 123from strata_control import doctor 124done = mock .Mock (returncode = 0 ,stdout = self .LINE ) 125with mock .patch .object (doctor .shutil ,"which" ,return_value = "/usr/bin/nvidia-smi" ), \ 126mock .patch .object (doctor .subprocess ,"run" ,return_value = done ), \ 127mock .patch .object (doctor .platform ,"machine" ,return_value = machine ),mock .patch .object (sys ,"platform" ,"linux" ):# (sysinfo answers from the platform module only off Windows) 128return doctor ._nvidia_cards () 129 130def test_doctor_lists_a_gb10_with_no_memory_figure (self ): 131cards ,why = self .cards ("aarch64" ) 132self .assertIsNone (why ) 133self .assertEqual (cards [0 ]["name" ],"NVIDIA GB10" ) 134self .assertIsNone (cards [0 ]["memory_mib" ]) 135 136def test_doctor_on_x86_still_refuses_a_card_without_a_memory_figure (self ): 137cards ,why = self .cards ("x86_64" ) 138self .assertIsNone (cards ) 139self .assertIn ("unrecognized" ,why ) 140 141def test_the_launch_probe_counts_a_gb10_as_unified_memory (self ): 142sys .path .insert (0 ,str (ROOT / "tools" )) 143import strata_mcp 144smi = "0, NVIDIA GB10, [N/A], 12.1, 580.173.02\n" 145with mock .patch .object (strata_mcp ,"run_quiet" ,return_value = smi ), \ 146mock .patch .object (strata_mcp ,"own_ram_gb" ,return_value = 121.6 ), \ 147mock .patch .object (strata_mcp .platform ,"machine" ,return_value = "aarch64" ): 148found = strata_mcp .own_nvidia_gpus () 149self .assertEqual (len (found ),1 ) 150self .assertTrue (found [0 ]["uma" ]) 151self .assertEqual (found [0 ]["arch" ],"121" ) 152self .assertAlmostEqual (found [0 ]["vram_gb" ],115.6 ,places = 1 ) 153self .assertEqual (found [0 ]["dedicated_gb" ],0.0 ) 154with mock .patch .object (strata_mcp ,"run_quiet" ,return_value = smi ), \ 155mock .patch .object (strata_mcp .platform ,"machine" ,return_value = "x86_64" ): 156self .assertEqual (strata_mcp .own_nvidia_gpus (), []) 157 158 159if __name__ == "__main__" : 160unittest .main ()