Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

109 lines
3.3 KiB
Python

"""Driver for KernelBench: iterates the suite (level1 only for nightly),
collects a baseline, and runs perfxpert analysis on the captured trace.
Emits analysis_summary.json.
"""
import argparse
import json
import re
import subprocess
import sys
from pathlib import Path
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--suite-root", type=Path, required=True)
ap.add_argument("--level", default="level1")
ap.add_argument("--filter", default=".*")
args = ap.parse_args()
suite = args.suite_root
level_dir = suite / args.level
rx = re.compile(args.filter)
results = []
if not level_dir.exists():
print(f"[error] {level_dir} does not exist", file=sys.stderr)
return 1
for kernel_dir in sorted(level_dir.glob("*")):
if not kernel_dir.is_dir() or not rx.search(kernel_dir.name):
continue
try:
baseline_ns = _run_kernel_once(kernel_dir, "baseline")
analysis = _run_perfxpert_analysis(kernel_dir)
results.append({
"kernel": kernel_dir.name,
"baseline_ns": baseline_ns,
"analysis_succeeded": analysis["analysis_succeeded"],
"recommendation_count": analysis["recommendation_count"],
"report_path": analysis["report_path"],
})
except Exception as e:
print(f"[warn] {kernel_dir.name} failed: {e}", file=sys.stderr)
results.append({
"kernel": kernel_dir.name,
"baseline_ns": 0,
"analysis_succeeded": False,
"recommendation_count": 0,
"report_path": None,
"error": str(e),
})
(suite / "analysis_summary.json").write_text(json.dumps({
"suite": f"kernelbench-rocm:{args.level}",
"mode": "analysis_only",
"results": results,
}, indent=2))
return 0
def _run_kernel_once(kdir: Path, label: str) -> int:
out = subprocess.run(
["./run.sh"], cwd=kdir, capture_output=True, text=True, timeout=600
)
m = re.search(r"median_ns:\s*(\d+)", out.stdout)
if not m:
raise RuntimeError(f"no median_ns in {label} output:\n{out.stdout[-1000:]}")
return int(m.group(1))
def _run_perfxpert_analysis(kdir: Path) -> dict:
db = kdir / "rocprof.db"
if not db.exists():
return {
"analysis_succeeded": False,
"recommendation_count": 0,
"report_path": None,
}
report_dir = kdir / ".perfxpert"
report_dir.mkdir(exist_ok=True)
report_path = report_dir / "analysis.json"
if report_path.exists():
report_path.unlink()
r = subprocess.run([
"perfxpert", "analyze",
"-i", str(db),
"--format", "json",
"-d", str(report_dir),
"-o", "analysis",
], capture_output=True, text=True, timeout=300)
if r.returncode != 0 or not report_path.exists():
return {
"analysis_succeeded": False,
"recommendation_count": 0,
"report_path": str(report_path),
}
payload = json.loads(report_path.read_text())
return {
"analysis_succeeded": True,
"recommendation_count": len(payload.get("recommendations", [])),
"report_path": str(report_path),
}
if __name__ == "__main__":
sys.exit(main())