Files
TheRock/rocm-libraries/shared/rocroller/scripts/lib/rrperf/profile.py
T
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

166 lines
4.2 KiB
Python

# Copyright Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT
"""
Run Omniperf against a RocRoller kernel or a Tensile guidepost.
Specify a YAML config file to invoke Tensile to build a kernel to be profiled.
Alternatively, specify an rrperf suite to profile a RocRoller kernel.
These kernels are profiled with Omniperf.
"""
import argparse
import shutil
import subprocess
import tempfile
from pathlib import Path
import rrperf
from rrperf.problems import GEMMRun
def has_omniperf() -> bool:
return shutil.which("omniperf")
def run_omniperf(
working_dir: Path,
executable: list[str],
output: Path,
omniperf_workload_dir: Path = "profiling",
cwd: Path = ".",
env: dict[str, str] = None,
):
cmd = [
"omniperf",
"profile",
"-n",
str(omniperf_workload_dir),
"-p",
str(working_dir),
"--",
] + executable
print(" ".join(cmd))
subprocess.run(
cmd,
cwd=cwd,
env=env,
)
omniperf_workload_dir = next((Path(working_dir) / omniperf_workload_dir).glob("*"))
cmd = [
"omniperf",
"analyze",
"-p",
str(omniperf_workload_dir),
"-o",
str(output),
]
print(" ".join(cmd))
subprocess.run(
cmd,
env=env,
)
def profile_tensile(config: Path, output_dir: Path, tensile_repo: Path):
tensile_path: Path = tensile_repo / "Tensile/bin/Tensile"
omniperf_workload: Path = Path("profile_tensile")
if not tensile_path.exists():
raise FileNotFoundError(f"Tensile not found at {tensile_path}")
with tempfile.TemporaryDirectory() as working_dir_name:
print("Created temporary directory", working_dir_name)
subprocess.run(
[str(tensile_path), str(config), working_dir_name],
check=True,
)
run_scripts = list(Path(working_dir_name).rglob("*/00_Final/build/run.sh"))
if len(run_scripts) != 1:
print(f"Bad config: found {len(run_scripts)} run.sh files", run_scripts)
return
output: Path = output_dir / "results_tensile.txt"
run_omniperf(working_dir_name, [str(run_scripts[0])], output, omniperf_workload)
def profile_rr(
problem: GEMMRun, name: str, output_dir: Path, build_dir: Path, env: dict[str, str]
):
i = 0
output = output_dir / f"results_{name}.txt"
while True:
working_dir = output_dir / f"data_{i:02}"
try:
working_dir.mkdir()
break
except FileExistsError:
i += 1
print("Created working directory", working_dir)
run_omniperf(
working_dir,
problem.command(),
output,
"profile_" + name,
build_dir,
env,
)
def get_args(parser: argparse.ArgumentParser):
common_args = [
rrperf.args.suite,
]
for arg in common_args:
arg(parser)
parser.add_argument("--config", help="Location of Tensile YAML config file.")
parser.add_argument(
"--output_dir",
help="Directory where the Omniperf results are written.",
default=".",
)
parser.add_argument(
"--tensile_repo",
help="Directory where Tensile repository is located.",
default="/home/tensile",
)
def run(args):
"""Run Omniperf against a RocRoller kernel or a Tensile guidepost."""
profile(**args.__dict__)
def profile(
output_dir: str,
tensile_repo: str,
build_dir: str = None,
suite: str = None,
config: Path = None,
**kwargs,
):
output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
tensile_repo = Path(tensile_repo)
if not has_omniperf():
raise FileNotFoundError("Could not find omniperf")
if config is not None:
profile_tensile(config, output_dir, tensile_repo)
if suite is not None:
if build_dir is None:
build_dir = rrperf.utils.get_build_dir()
else:
build_dir = Path(build_dir)
for i, problem in enumerate(rrperf.utils.load_suite(suite)):
profile_rr(
problem,
f"{i:02}",
output_dir,
build_dir,
)