okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
66331f9bc
main
1"""Which OS and backend combinations the project commits to, and what this machine is. 2 3Pure and tiny on purpose: the engine resolver on the start path (engine_component.py) needs these answers, and the 4start path must not import the component fetcher (components.py) to get them. 5""" 6 7from __future__import annotations 8 9import platform # noqa: F401 - kept: tests replace targets.platform's functions 10 11from strata_control import sysinfo 12 13 14class ComponentError (RuntimeError ): 15"""A component could not be used. The message names the reason and nothing was changed.""" 16 17def __init__ (self ,message :str ,code :int = 6 )-> None : 18super ().__init__ (message ) 19self .code = code 20 21 22#: The OS × backend families the handoff commits to. A component may only be activated where its 23#: family is listed here, so an unqualified combination is refused rather than attempted: the packet 24#: is explicit that Windows SYCL and Intel Macs are not supported rather than merely untested. 25BACKEND_MATRIX :dict [str ,tuple [str , ...]]= { 26"metal" : ("macos-arm64" ,), 27"cuda" : ("windows-x86_64" ,"linux-x86_64" ,"linux-aarch64" ),# linux-aarch64: the NVIDIA DGX Spark (GB10, sm_121) only 28"hip" : ("windows-x86_64" ,"linux-x86_64" ), 29"sycl" : ("linux-x86_64" ,), 30"cpu" : ("macos-arm64" ,"macos-x86_64" ,"windows-x86_64" ,"linux-x86_64" ), 31} 32 33def host_platform ()-> str : 34"""This machine as an `os-arch` key, matching `BACKEND_MATRIX`.""" 35# sysinfo, not platform: on Windows `platform.system()` and `.machine()` query WMI with no timeout, and a stuck winmgmt 36# froze every command that resolves the engine (#4975) 37system = {"Darwin" :"macos" ,"Linux" :"linux" ,"Windows" :"windows" }.get (sysinfo .system ()) 38if system is None : 39raise ComponentError (f"unsupported operating system: { sysinfo . system () } " ) 40machine = sysinfo .machine ().lower () 41arch = {"arm64" :"arm64" ,"aarch64" :"arm64" , 42"x86_64" :"x86_64" ,"amd64" :"x86_64" }.get (machine ,machine ) 43if system == "linux" and arch == "arm64" : 44return "linux-aarch64" # Linux names its ARM64 machines as uname does (the Tauri target and the Python build too); a Mac stays macos-arm64 45return f" { system } - { arch } " 46 47 48def backend_supported (backend :str ,target :str | None = None )-> tuple [bool ,str ]: 49"""Whether a backend family is committed to on a platform, with the reason if not.""" 50target = target or host_platform () 51if backend not in BACKEND_MATRIX : 52return False ,f"unknown backend family { backend !r } " 53platforms = BACKEND_MATRIX [backend ] 54if target in platforms : 55return True ,"" 56return False , (f" { backend } is not a supported combination on { target } ; it is supported on " 57f" { ', ' . join ( platforms ) } . Unsupported combinations are not attempted." ) 58 59