okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3b8dc8fa3
main
1"""The oldest NVIDIA driver the CUDA 12 engine package runs on, taken from the package's own metadata (#4247, #4188). 2 3Setup used to say "the CUDA 12 engine works from driver 528 (525 on Linux)", a number copied from NVIDIA's minor-version-compatibility table, 4while the signed feed's cuda12 packages (built with CUDA 12.9) carry `min_driver` 575.51 / 576.02 and `strata update` refuses them below 5that: a PC on driver 556 was told its engine would work and then told the feed had no engine for it. The floor is now read from 6the package that would run: 7 81. an installed cuda12 package of this platform (the components folder, setup's own engine-feed folder): its manifest's `min_driver`; 92. else the signed feed (best effort, a few seconds, never an error): the newest cuda12 package of this platform; 103. else FALLBACK, the figure the shipped packages carry today (packaging/ENGINE-COMPONENT.md). 11 12Nothing here refuses anything: the callers say the number, and say where it came from. 13""" 14from __future__import annotations 15 16import threading 17from pathlib import Path 18 19#: What the cuda12 packages carry (packaging/ENGINE-COMPONENT.md: min_driver nvidia 575.51). Only used when no package or feed can be read. 20FALLBACK = "575.51" 21VARIANT = "cuda12" 22FEED_SECONDS = 10.0 23 24 25def major (version :str | None )-> int : 26"""The leading number of a driver version ("576.02" -> 576); 0 when there is none.""" 27try : 28return int (str (version or "" ).strip ().split ("." )[0 ]) 29except ValueError : 30return 0 31 32 33def _key (version :str )-> tuple : 34return tuple (int (p )if p .isdigit ()else 0 for p in str (version ).replace ("-" ,"." ).split ("." )) 35 36 37def _floor_of (packages ,platform :str ,variant :str ): 38"""The `min_driver` (nvidia) of the newest package of `variant` for `platform`: items with .version, .platform, .backend, .variant, .min_driver.""" 39best = None 40for item in packages : 41if item .backend != "cuda" or item .variant != variant or (platform and item .platform != platform ): 42continue 43need = (item .min_driver or {}).get ("nvidia" ) 44if not need or not major (need ): 45continue 46if best is None or _key (item .version )> _key (best .version ): 47best = item 48return None if best is None else str (best .min_driver ["nvidia" ]) 49 50 51def installed (roots ,platform :str ,variant :str = VARIANT )-> str | None : 52"""The floor of a cuda12 package already on this PC, from its manifest (no network).""" 53from strata_control import engine_component as ec 54found = [] 55for root in roots or (): 56try : 57components ,_problems = ec .scan (Path (root )) 58except Exception :# noqa: BLE001 - a folder that cannot be read has no answer 59continue 60found .extend (components ) 61return _floor_of (found ,platform ,variant ) 62 63 64def from_feed (source :str ,platform :str ,variant :str = VARIANT ,* ,seconds :float = FEED_SECONDS )-> str | None : 65"""The floor the signed feed gives a cuda12 package of this platform; None when the feed cannot be read in `seconds` (offline, no key, 66a feed with no such package). Runs the read on a thread so a hung connection never holds setup up.""" 67answer :list = [] 68 69def read ()-> None : 70try : 71from strata_control import feed as feedmod 72from strata_control import signing 73loaded = feedmod .fetch (source ,signing .load_trusted_keys ()) 74answer .append (_floor_of (loaded .engine ,platform ,variant )) 75except Exception :# noqa: BLE001 - the floor is a convenience, never a reason to stop 76answer .append (None ) 77 78worker = threading .Thread (target = read ,daemon = True ) 79worker .start () 80worker .join (seconds ) 81return answer [0 ]if answer else None 82 83 84def cuda12_floor (platform :str ,* ,roots = (),feed_source :str | None = None )-> tuple [str ,str ]: 85"""(floor, where it came from): "576.02", "as the signed update feed says".""" 86got = installed (roots ,platform ) 87if got : 88return got ,"as the installed engine package says" 89if feed_source : 90got = from_feed (feed_source ,platform ) 91if got : 92return got ,"as the signed update feed says" 93return FALLBACK ,"the figure the published CUDA 12 packages carry"