okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-021-hip' into f-021-int468e3a625

main
3.4 KiB62 linesraw
1#!/usr/bin/env python3
2"""Put the hipBLASLt tuning tables into a staged AMD engine package and record the hipBLASLt version in its BUILD.json.
3
4    python packaging/stage_tuning.py --stage <stage folder> --archs "gfx1200 gfx1201" --rocm <ROCm devel root> [--tables tools/hip]
5                                     [--expect gfx1201]
6
7The stage folder is the one packaging/package_engine.py is pointed at. The hipBLASLt version is read from the ROCm tree the package's
8libraries come from (include/hipblaslt/hipblaslt-version.h; 1.5.0 is 100500), written to BUILD.json as ``hipblaslt_version``, and every
9table of tools/hip for one of --archs and exactly that version is copied to ``<stage>/tuning/``. An architecture without a table keeps plain
10hipBLAS: it is listed on stdout, and --expect makes it an error for the ones that must have one. The tables are measured per architecture and
11version (docs/AMD_HIP.md, Tuning table); nothing is calibrated or invented here. Windows packages do the same inside tools/hip/package_windows.py.
12"""
13from __future__ import annotations
14
15import argparse
16import json
17import re
18import sys
19from pathlib import Path
20
21ROOT = Path(__file__).resolve().parents[1]
22sys.path.insert(0, str(ROOT))
23
24from strata_control import hipblaslt_tuning as ht  # noqa: E402
25
26
27def stage(stage_dir: Path, archs: list[str], version: int | None, tables: Path, expect: list[str]) -> list[str]:
28    if version is None:
29        raise SystemExit("cannot read the hipBLASLt version of this ROCm tree (include/hipblaslt/hipblaslt-version.h): "
30                         "an AMD package must record hipblaslt_version")
31    info = stage_dir / "BUILD.json"
32    meta = json.loads(info.read_text(encoding="utf-8-sig")) if info.is_file() else {}
33    meta["hipblaslt_version"] = version
34    info.write_text(json.dumps(meta, indent=1) + "\n", encoding="utf-8")
35    copied = ht.stage_tables(stage_dir, archs, version, tables)
36    left = ht.missing_report(archs, version, tables)
37    for arch, have in left.items():
38        print(f"no hipBLASLt table for {arch} with hipBLASLt {version} (the repo has: {', '.join(map(str, have)) or 'none'}): plain hipBLAS there")
39    bad = [a for a in expect if a in left]
40    if bad:
41        raise SystemExit(f"required tables are missing for {', '.join(bad)} at hipBLASLt {version}")
42    return copied
43
44
45def main(argv=None) -> int:
46    ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
47    ap.add_argument("--stage", required=True, type=Path)
48    ap.add_argument("--archs", required=True, help="space, comma or semicolon separated")
49    ap.add_argument("--rocm", type=Path, help="the ROCm devel root (its include/hipblaslt/hipblaslt-version.h)")
50    ap.add_argument("--version", type=int, help="the hipBLASLt version number (100500), instead of --rocm")
51    ap.add_argument("--tables", type=Path, default=ROOT / "tools" / "hip")
52    ap.add_argument("--expect", default="", help="architectures that must have a table (an error when one is missing)")
53    a = ap.parse_args(argv)
54    archs = [x for x in re.split(r"[;, ]+", a.archs) if x]
55    version = a.version if a.version else ht.version_from_header(a.rocm) if a.rocm else None
56    copied = stage(a.stage, archs, version, a.tables, [x for x in re.split(r"[;, ]+", a.expect) if x])
57    print(f"hipBLASLt {version}: " + (", ".join(copied) if copied else "no tuning tables in this package"))
58    return 0
59
60
61if __name__ == "__main__":
62    raise SystemExit(main())