diff --git a/packaging/ENGINE-COMPONENT.md b/packaging/ENGINE-COMPONENT.md index 84399aba..286d23b3 100644 --- a/packaging/ENGINE-COMPONENT.md +++ b/packaging/ENGINE-COMPONENT.md @@ -6,7 +6,7 @@ Metal. Control (`strata_control/engine_component.py`) reads it, checks it, and o ## Folder - /engine/--/ + /engine/--[-]/ engine-component.json strata | strata.exe the entrypoint lib*.so* | *.dll | *.dylib the GPU runtime libraries it loads from beside itself @@ -28,6 +28,7 @@ A package folder is immutable: a new build is a new folder. | `archs` | list of strings | what the build contains. CUDA: `sm_86` (machine code for that card), `compute_89` (PTX, runs on that generation or newer). HIP: `gfx1201`. SYCL and Metal: a descriptive tag (`intel-arc`, `apple-gpu`). Required for every non-`cpu` backend. Enforced for CUDA against `nvidia-smi` compute capability; recorded for the others | | `min_driver` | `{vendor: version}` | the oldest driver the build runs on, e.g. `{"nvidia": "580.65"}`. Enforced for NVIDIA where `nvidia-smi` answers; an unreadable driver is not a refusal | | `build_id` | string | which engine build this is: source commit and toolkit, e.g. `be885026f96a-cuda13.0`. Required | +| `variant` | string, optional | tag when one backend has several builds on a platform (`cuda13`, `cuda12`); goes in the folder name. With equal versions the build that needs the newer driver is preferred (CUDA 13 over CUDA 12) when both fit the card | | `min_runtime` | string, optional | the oldest Control that may start it | | `entrypoint` | string | relative path of the binary; must be in `files` | | `files` | list | `{path, sha256, bytes}` for **every** file of the package except the manifest; paths are plain relative POSIX paths that stay inside the folder; no duplicates | @@ -80,7 +81,7 @@ UTF-8). It contains every file hash, so one signature covers the whole package. python packaging/package_engine.py --src --backend cuda --version 0.1.45 \ --out /engine --arch sm_86 --arch compute_89 --min-driver nvidia=580.65 \ - [--build-id ] [--platform linux-x86_64] [--include 'rocm/**' --include strata-vision.exe | --tree] + [--build-id ] [--variant cuda13] [--platform linux-x86_64] [--include 'rocm/**' --include strata-vision.exe | --tree] python packaging/package_engine.py --verify # full hash check Without `--include`/`--tree` it takes the entrypoint, the libraries beside it, `BUILD.json` and `LICENSE*`. The build id diff --git a/packaging/package_engine.py b/packaging/package_engine.py index 3152472b..6dd5b125 100644 --- a/packaging/package_engine.py +++ b/packaging/package_engine.py @@ -82,7 +82,8 @@ def select(src: Path, entrypoint: str, *, tree: bool, include: list[str]) -> lis def build(src: Path, backend: str, version: str, target: str, out: Path, *, entry: str | None = None, archs: tuple[str, ...] = (), min_driver: dict | None = None, build_id: str | None = None, - min_runtime: str | None = None, notes: str = "", tree: bool = False, include: list[str] | None = None) -> Path: + min_runtime: str | None = None, notes: str = "", tree: bool = False, include: list[str] | None = None, + variant: str = "") -> Path: if backend not in BACKEND_MATRIX: raise SystemExit(f"unknown backend {backend!r}") if backend != "cpu" and not archs: @@ -90,7 +91,7 @@ def build(src: Path, backend: str, version: str, target: str, out: Path, *, entr entrypoint = entry or ("strata.exe" if target.startswith("windows") else "strata") if not (src / entrypoint).is_file(): raise SystemExit(f"{src / entrypoint} does not exist") - folder = out / f"{version}-{target}-{backend}" + folder = out / (f"{version}-{target}-{backend}" + (f"-{variant}" if variant else "")) if folder.exists(): raise SystemExit(f"{folder} already exists; remove it first (packages are immutable)") staging = out / f".{folder.name}.partial" @@ -108,6 +109,8 @@ def build(src: Path, backend: str, version: str, target: str, out: Path, *, entr "version": version, "platform": target, "backend": backend, "archs": list(archs), "min_driver": dict(min_driver or {}), "build_id": build_id or git_build_id(), "entrypoint": entrypoint, "files": files, "signature": None} + if variant: + manifest["variant"] = variant if min_runtime: manifest["min_runtime"] = min_runtime if notes: @@ -141,6 +144,7 @@ def main(argv: list[str] | None = None) -> int: help="sm_86 (code for that card), compute_89 (PTX), gfx1201, ...; repeat for several") ap.add_argument("--min-driver", action="append", default=[], metavar="VENDOR=VERSION", help="the oldest driver, e.g. nvidia=580.65; repeat for several vendors") + ap.add_argument("--variant", default="", help="tag when one backend has several builds (cuda13, cuda12); goes in the folder name") ap.add_argument("--build-id", default=None, help="default: the source commit of this checkout") ap.add_argument("--min-runtime", default=None) ap.add_argument("--notes", default="") @@ -168,7 +172,7 @@ def main(argv: list[str] | None = None) -> int: a.out.mkdir(parents=True, exist_ok=True) folder = build(a.src, a.backend, a.version, a.platform or host_platform(), a.out, entry=a.entrypoint, archs=tuple(a.arch), min_driver=drivers, build_id=a.build_id, min_runtime=a.min_runtime, - notes=a.notes, tree=a.tree, include=a.include) + notes=a.notes, tree=a.tree, include=a.include, variant=a.variant) entries = [p for p in folder.rglob("*") if p.is_file()] total = sum(p.stat().st_size for p in entries) print(f"{folder} ({total / (1 << 20):.1f} MiB, {len(entries)} files, manifest sha256 {package_sha256(folder)})") diff --git a/strata_control/engine_component.py b/strata_control/engine_component.py index aaf28f4f..78445d85 100644 --- a/strata_control/engine_component.py +++ b/strata_control/engine_component.py @@ -123,6 +123,7 @@ class EngineComponent: notes: str = "" min_driver: dict = field(default_factory=dict) # {"nvidia": "580.65"}: the oldest driver the build runs on build_id: str = "" # which engine build this is (source commit + toolkit) + variant: str = "" # optional tag when one backend has several builds (cuda13, cuda12) signature: dict | None = None # S6: {"alg", "key_id", "value"} over signing_payload() raw: dict = field(default_factory=dict, repr=False) # the manifest as read, for the signature check @@ -138,7 +139,7 @@ class EngineComponent: return {"id": self.id, "version": self.version, "platform": self.platform, "backend": self.backend, "entrypoint": self.entrypoint, "exe": str(self.exe), "root": str(self.root), "min_runtime": self.min_runtime, "archs": list(self.archs), "min_driver": dict(self.min_driver), - "build_id": self.build_id, "signed": bool(self.signature), "file_count": len(self.files), "bytes": sum(item[2] for item in self.files)} + "build_id": self.build_id, "variant": self.variant, "signed": bool(self.signature), "file_count": len(self.files), "bytes": sum(item[2] for item in self.files)} # ----------------------------------------------------------------------------------------------- where @@ -233,7 +234,8 @@ def read_manifest(folder: Path) -> EngineComponent: id=data["id"], version=data["version"], platform=data["platform"], backend=data["backend"], entrypoint=entry, files=tuple(parsed), root=folder, min_runtime=data.get("min_runtime"), archs=tuple(archs), notes=str(data.get("notes") or ""), min_driver=dict(driver), - build_id=str(data.get("build_id") or ""), signature=signature, raw=data) + build_id=str(data.get("build_id") or ""), variant=str(data.get("variant") or ""), signature=signature, + raw=data) # ----------------------------------------------------------------------------------------------- signature (S6) @@ -497,7 +499,8 @@ def resolve(root: Path | None = None, *, backend: str | None = None, target: str if broken and len(broken) == len(reasons): # every package that fits this PC failed its integrity check raise EngineIntegrityError("; ".join(broken), base, problems=problems) raise EngineMissing("; ".join(everything) or "nothing matched", base, problems=problems) - return max(usable, key=lambda item: _version_key(item.version)) + # newest version first; with equal versions the build for the newer driver (the CUDA 13 build beside the CUDA 12 one) + return max(usable, key=lambda item: (_version_key(item.version), _version_key(item.min_driver.get("nvidia", "0")))) #: A run config can name its engine as "component:strata-engine" instead of a path: the server then asks the diff --git a/tests/terminal/test_engine_manifest.py b/tests/terminal/test_engine_manifest.py index f79ece10..c71b8ab1 100644 --- a/tests/terminal/test_engine_manifest.py +++ b/tests/terminal/test_engine_manifest.py @@ -198,6 +198,15 @@ class Start(unittest.TestCase): with self.assertRaises(ec.EngineIntegrityError): self.start() + def test_two_builds_of_one_version_prefer_the_newer_driver_when_both_fit(self): + other = make_source(self.root / "src3") + old = package_engine.build(other, "cuda", "0.1.45", HERE, self.out, archs=("sm_86",), + min_driver={"nvidia": "575.51"}, build_id="b-12", variant="cuda12") + self.assertEqual(old.name, f"0.1.45-{HERE}-cuda-cuda12") + self.assertEqual(ec.read_manifest(old).variant, "cuda12") + self.assertEqual(Path(self.start(driver="610.0")).parent.resolve(), self.folder.resolve()) # 580.65 build wins + self.assertEqual(Path(self.start(driver="576.0")).parent.resolve(), old.resolve()) # only the CUDA 12 one fits + def test_a_good_package_does_not_hide_a_tampered_one(self): newer = package_engine.build(make_source(self.root / "src2"), "cuda", "0.1.46", HERE, self.out, archs=("sm_86",), build_id="b2")