okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
468e3a625
main
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 4python 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 ]: 28if version is None : 29raise SystemExit ("cannot read the hipBLASLt version of this ROCm tree (include/hipblaslt/hipblaslt-version.h): " 30"an AMD package must record hipblaslt_version" ) 31info = stage_dir / "BUILD.json" 32meta = json .loads (info .read_text (encoding = "utf-8-sig" ))if info .is_file ()else {} 33meta ["hipblaslt_version" ]= version 34info .write_text (json .dumps (meta ,indent = 1 )+ "\n" ,encoding = "utf-8" ) 35copied = ht .stage_tables (stage_dir ,archs ,version ,tables ) 36left = ht .missing_report (archs ,version ,tables ) 37for arch ,have in left .items (): 38f"no hipBLASLt table for { arch } with hipBLASLt { version } (the repo has: { ', ' . join ( map ( str , have )) or 'none' } ): plain hipBLAS there" ) 39bad = [a for a in expect if a in left ] 40if bad : 41raise SystemExit (f"required tables are missing for { ', ' . join ( bad ) } at hipBLASLt { version } " ) 42return copied 43 44 45def main (argv = None )-> int : 46ap = argparse .ArgumentParser (description = __doc__ ,formatter_class = argparse .RawDescriptionHelpFormatter ) 47ap .add_argument ("--stage" ,required = True ,type = Path ) 48ap .add_argument ("--archs" ,required = True ,help = "space, comma or semicolon separated" ) 49ap .add_argument ("--rocm" ,type = Path ,help = "the ROCm devel root (its include/hipblaslt/hipblaslt-version.h)" ) 50ap .add_argument ("--version" ,type = int ,help = "the hipBLASLt version number (100500), instead of --rocm" ) 51ap .add_argument ("--tables" ,type = Path ,default = ROOT / "tools" / "hip" ) 52ap .add_argument ("--expect" ,default = "" ,help = "architectures that must have a table (an error when one is missing)" ) 53a = ap .parse_args (argv ) 54archs = [x for x in re .split (r"[;, ]+" ,a .archs )if x ] 55version = a .version if a .version else ht .version_from_header (a .rocm )if a .rocm else None 56copied = stage (a .stage ,archs ,version ,a .tables , [x for x in re .split (r"[;, ]+" ,a .expect )if x ]) 57f"hipBLASLt { version } : " + (", " .join (copied )if copied else "no tuning tables in this package" )) 58return 0 59 60 61if __name__ == "__main__" : 62raise SystemExit (main ())