|
| 1 | +import argparse |
| 2 | +import subprocess |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | +def run_command(command, cwd=None): |
| 7 | + """Run a shell command and print its output.""" |
| 8 | + try: |
| 9 | + result = subprocess.run( |
| 10 | + command, |
| 11 | + shell=True, |
| 12 | + cwd=cwd, |
| 13 | + text=True, |
| 14 | + check=True, |
| 15 | + executable='/bin/bash', |
| 16 | + stdout=subprocess.PIPE, |
| 17 | + stderr=subprocess.PIPE, |
| 18 | + ) |
| 19 | + print(result.stdout) |
| 20 | + except subprocess.CalledProcessError as e: |
| 21 | + print(f"Command '{command}' failed with error:\n{e.stderr}") |
| 22 | + sys.exit(1) |
| 23 | + |
| 24 | +def main(): |
| 25 | + parser = argparse.ArgumentParser(description="Run benchmark with build command.") |
| 26 | + parser.add_argument("benchmark", type=str, help="The benchmark name (folder).") |
| 27 | + parser.add_argument("model", type=str, help="The model name (folder).") |
| 28 | + parser.add_argument( |
| 29 | + "--args", type=str, help="Additional program arguments.", default="" |
| 30 | + ) |
| 31 | + parser.add_argument( |
| 32 | + "--build_cmd", type=str, help="Custom build command.", default="make" |
| 33 | + ) |
| 34 | + parser.add_argument( |
| 35 | + "--run_cmd", type=str, help="Custom run command.", default="./upmem_test" |
| 36 | + ) |
| 37 | + parser.add_argument( |
| 38 | + "--time_output", type=str, help="Timing output file", default="output.run" |
| 39 | + ) |
| 40 | + parser.add_argument( |
| 41 | + "--compile_defines", type=str, help="Compiler Defines.", default="" |
| 42 | + ) |
| 43 | + |
| 44 | + args = parser.parse_args() |
| 45 | + |
| 46 | + # Construct the paths to the benchmark and subcategory folders |
| 47 | + benchmark_path = os.path.join(args.benchmark, args.model) |
| 48 | + |
| 49 | + if not os.path.exists(benchmark_path): |
| 50 | + print(f"Error: The path '{benchmark_path}' does not exist.") |
| 51 | + sys.exit(1) |
| 52 | + |
| 53 | + # Step 1: Run the build command |
| 54 | + print(f"Building in: {benchmark_path}") |
| 55 | + build_cmd = f"{args.compile_defines} {args.build_cmd}" |
| 56 | + run_command(build_cmd, cwd=benchmark_path) |
| 57 | + |
| 58 | + # Step 2: Run the benchmark with additional arguments |
| 59 | + print(f"Running benchmark in: {benchmark_path}") |
| 60 | + benchmark_command = f"/usr/bin/time -o {args.time_output} {args.run_cmd} {args.args}" |
| 61 | + print(f"Benchmark command: {benchmark_command}") |
| 62 | + run_command(benchmark_command, cwd=benchmark_path) |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + main() |
0 commit comments