mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
packaging: build_sycl_windows.py, the Windows Intel Arc package of the Qwen3.8-Flash-Next engine
Builds engine/sycl with icx (or takes a finished strata.exe), stages it with the Unified Runtime adapters (ur_*.dll, umf*.dll, loaded by name at run time), lets package_engine.py bundle sycl9.dll, libhwloc, libmmd, svml and the Visual C++ runtime, then runs --verify, binary_deps.py and a minimal-PATH smoke (PATH=System32, ONEAPI_ROOT empty). The Level Zero loader and compute runtime stay the PC's own (graphics driver).
This commit is contained in:
1 parent
1109ad7b3e
commit
d8f2977968
1 file changed
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the Windows Intel Arc (SYCL) engine package of the Qwen3.8-Flash-Next engine (strata.exe, entry strata-engine). Local only: nothing is uploaded.
|
||||
|
||||
python tools/packaging/build_sycl_windows.py --oneapi C:/oneapi --vcvars "C:/.../VC/Auxiliary/Build/vcvars64.bat" --out out-engine-sycl-win
|
||||
python tools/packaging/build_sycl_windows.py --oneapi ... --vcvars ... --exe C:/path/strata.exe --out ... # package a strata.exe that is already built
|
||||
|
||||
Without --exe it configures and builds engine/sycl (icx 2026.x under the Visual Studio environment of --vcvars, AOT for --aot, default bmg-g31 = Arc Pro B70)
|
||||
with `-DSTRATA_SYCL_PARITY=OFF` and no oneMKL (the Windows build uses the engine's own XMX dense GEMM), at most --jobs compile jobs (default 8: the AOT device
|
||||
code is memory hungry; start with 20 GB of RAM free). Then it stages strata.exe + BUILD.json + licences, copies the Unified Runtime adapters (ur_*.dll,
|
||||
umf*.dll: loaded by name at run time), lets package_engine.py bundle everything strata.exe imports (sycl9.dll and its friends from the oneAPI runtime, the
|
||||
Visual C++ runtime), and checks the result with package_engine.py --verify and binary_deps.py. The Level Zero loader (ze_loader.dll) and the compute runtime stay the
|
||||
PC's own (the Intel graphics driver). The package runs with a minimal PATH and no ONEAPI_ROOT: `--smoke` does that (strata.exe --help under `cmd /c` with PATH=System32 only).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
PACK = REPO / "tools" / "packaging"
|
||||
|
||||
|
||||
def engine_version() -> str:
|
||||
text = (REPO / "engine" / "CMakeLists.txt").read_text(encoding="utf-8", errors="replace")
|
||||
m = re.search(r"^\s*project\s*\([^)]*VERSION\s+([0-9][0-9.]*)", text, re.M)
|
||||
if not m:
|
||||
raise SystemExit("build_sycl_windows.py: no project VERSION in engine/CMakeLists.txt")
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def run(cmd: list[str], vcvars: str | None, setvars: str | None, cwd: Path | None = None) -> None:
|
||||
if vcvars:
|
||||
line = 'call "{}" >nul && '.format(vcvars.replace("/", "\\"))
|
||||
if setvars:
|
||||
line += 'call "{}" --force >nul && '.format(setvars.replace("/", "\\"))
|
||||
line += subprocess.list2cmdline(cmd)
|
||||
print("+", line, flush=True)
|
||||
subprocess.run('cmd /d /s /c "' + line + '"', check=True, cwd=cwd)
|
||||
else:
|
||||
print("+", subprocess.list2cmdline(cmd), flush=True)
|
||||
subprocess.run(cmd, check=True, cwd=cwd)
|
||||
|
||||
|
||||
def vc_redist_dirs(vcvars: str) -> list[str]:
|
||||
""".../VC/Redist/MSVC/<newest>/x64/Microsoft.VC14x.CRT of the Visual Studio of `vcvars` (msvcp140, vcruntime140, vcruntime140_1)."""
|
||||
if not vcvars:
|
||||
return []
|
||||
vc = Path(vcvars).resolve().parents[2]
|
||||
found = sorted((vc / "Redist" / "MSVC").glob("*/x64/Microsoft.VC*.CRT"))
|
||||
return [str(found[-1])] if found else []
|
||||
|
||||
|
||||
def smoke(folder: Path, exe_name: str) -> int:
|
||||
"""strata.exe --help with a minimal PATH (System32 only) and ONEAPI_ROOT empty: every DLL must come from the package (or the OS / driver)."""
|
||||
env = {"SystemRoot": os.environ.get("SystemRoot", r"C:\Windows"), "PATH": os.environ.get("SystemRoot", r"C:\Windows") + r"\System32", "ONEAPI_ROOT": ""}
|
||||
r = subprocess.run([str(folder / exe_name), "--help"], capture_output=True, text=True, timeout=120, env=env, cwd=str(folder))
|
||||
first = (r.stdout or r.stderr).strip().splitlines()[:1]
|
||||
print("smoke:", exe_name, "--help with PATH=System32 and ONEAPI_ROOT empty ->", r.returncode, first)
|
||||
return 0 if first and "strata generate" in first[0] else 1
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--oneapi", required=True, help="the Intel oneAPI folder (setvars.bat, compiler/latest/bin; DPC++ icx 2026.x)")
|
||||
ap.add_argument("--vcvars", required=True, help="vcvars64.bat of Visual Studio")
|
||||
ap.add_argument("--aot", default="bmg-g31", help="the AOT device list of the GPU code, e.g. bmg-g31 (Arc Pro B70); the Windows package has no SPIR-V fallback")
|
||||
ap.add_argument("--exe", type=Path, default=None, help="package this strata.exe instead of building (its build must be the Windows no-oneMKL one)")
|
||||
ap.add_argument("--build-dir", type=Path, default=None)
|
||||
ap.add_argument("--out", type=Path, default=None)
|
||||
ap.add_argument("--jobs", type=int, default=8)
|
||||
ap.add_argument("--python", default=sys.executable)
|
||||
ap.add_argument("--extra-cmake", default="")
|
||||
ap.add_argument("--smoke", action="store_true", help="after packaging, run the minimal-PATH check")
|
||||
a = ap.parse_args(argv)
|
||||
|
||||
ver = engine_version()
|
||||
setvars = str(Path(a.oneapi) / "setvars.bat")
|
||||
if not Path(setvars).is_file():
|
||||
ap.error(f"no setvars.bat in {a.oneapi}")
|
||||
out = a.out or REPO / "out-engine-sycl-win"
|
||||
build = a.build_dir or REPO / "engine" / "build-sycl-win"
|
||||
exe = a.exe
|
||||
if exe is None:
|
||||
cfg = ["-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_C_COMPILER=icx", "-DCMAKE_CXX_COMPILER=icx", "-DSTRATA_SYCL_PARITY=OFF", f"-DSTRATA_SYCL_AOT={a.aot}"] + a.extra_cmake.split()
|
||||
run(["cmake", "-G", "Ninja", "-S", str(REPO / "engine" / "sycl"), "-B", str(build), *cfg], a.vcvars, setvars)
|
||||
run(["cmake", "--build", str(build), "--target", "strata", "--", "-j", str(a.jobs)], a.vcvars, setvars)
|
||||
exe = build / "strata.exe"
|
||||
if not exe.is_file():
|
||||
print(f"build_sycl_windows.py: {exe} does not exist", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
stage = Path(tempfile.mkdtemp(prefix="strata-sycl-win-stage-"))
|
||||
try:
|
||||
shutil.copy2(exe, stage / "strata.exe")
|
||||
(stage / "BUILD.json").write_text(
|
||||
'{"version": "%s", "source": "tools/packaging/build_sycl_windows.py", "backend": "sycl", "sycl": "oneAPI DPC++ (AOT %s)", "portable": false}\n' % (ver, a.aot),
|
||||
encoding="utf-8")
|
||||
(stage / "licenses").mkdir()
|
||||
lic = REPO / "LICENSE"
|
||||
if lic.is_file():
|
||||
shutil.copy2(lic, stage / "licenses" / "LICENSE-strata.txt")
|
||||
sbin = Path(a.oneapi) / "compiler" / "latest" / "bin"
|
||||
# the Unified Runtime loads its Level Zero adapter by name at run time (not an import of the exe): copy it, and the memory-framework pieces it needs
|
||||
for pattern in ("ur_*.dll", "umf*.dll"):
|
||||
for dll in sorted(sbin.glob(pattern)):
|
||||
if dll.stem.lower().endswith("d"): # the debug builds need the debug C runtime: never shipped
|
||||
continue
|
||||
shutil.copy2(dll, stage / dll.name)
|
||||
search = ["--search", str(sbin), "--search", str(Path(a.oneapi) / "tcm" / "latest" / "bin")]
|
||||
for d in vc_redist_dirs(a.vcvars):
|
||||
search += ["--search", d]
|
||||
archs = [x.strip() for x in a.aot.replace(";", ",").split(",") if x.strip()]
|
||||
arch_args = [item for x in archs for item in ("--arch", x)]
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [a.python, str(PACK / "package_engine.py"), "--src", str(stage), "--backend", "sycl", "--version", ver, "--out", str(out), *arch_args,
|
||||
"--platform", "windows-x86_64", "--build-id", f"release-{ver}-sycl-win", "--entrypoint", "strata.exe", "--include", "licenses/*", *search]
|
||||
print("+", subprocess.list2cmdline(cmd), flush=True)
|
||||
subprocess.run(cmd, check=True)
|
||||
finally:
|
||||
shutil.rmtree(stage, ignore_errors=True)
|
||||
folders = sorted(p for p in out.iterdir() if p.is_dir() and not p.name.startswith("."))
|
||||
for folder in folders:
|
||||
subprocess.run([a.python, str(PACK / "package_engine.py"), "--verify", str(folder)], check=True)
|
||||
subprocess.run([a.python, str(PACK / "binary_deps.py"), str(folder)], check=True)
|
||||
if a.smoke and smoke(folder, "strata.exe") != 0:
|
||||
return 1
|
||||
print("built:", out)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user