|
| 1 | +import os |
| 2 | +import json |
| 3 | +import argparse |
| 4 | +import subprocess |
| 5 | + |
| 6 | +# Parse arguments |
| 7 | +parser = argparse.ArgumentParser(description="Benchmark script") |
| 8 | +parser.add_argument('--presets', nargs='*', default=[], help="Whitelist of presets, defaults to all presets if not specified") |
| 9 | +parser.add_argument('--models', default="", help="Path to embree models repository, accepts 'git clone' to clone into current path") |
| 10 | +parser.add_argument('--size', nargs=2, type=int, default=[2048, 2048], help="Width and height (default: 2048 2048)") |
| 11 | +parser.add_argument('--out', default="./benchmarks_out", help="Output directory for benchmark results (default: benchmarks_out)") |
| 12 | +args = parser.parse_args() |
| 13 | + |
| 14 | + |
| 15 | +# Ensure the current working directory is the root directory of the repository |
| 16 | +repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) |
| 17 | +os.chdir(repo_root) |
| 18 | +print(f"Changed working directory to repository root: {repo_root}") |
| 19 | + |
| 20 | + |
| 21 | +# PRESETS # |
| 22 | +########### |
| 23 | +with open("./scripts/benchmark/presets.json", 'r') as file: |
| 24 | + presets_data = json.load(file) |
| 25 | + |
| 26 | +presets = [] |
| 27 | +for p in presets_data["configurePresets"]: |
| 28 | + if not args.presets or p["name"] in args.presets: |
| 29 | + presets.append(p["name"]) |
| 30 | + |
| 31 | +for p in args.presets: |
| 32 | + if p not in presets: |
| 33 | + print(f"WARNING: Unknown preset '{p}' ignored.") |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +# BUILD EMBREE # |
| 38 | +################ |
| 39 | +for preset in presets: |
| 40 | + print(f"Building embree with preset: {preset}") |
| 41 | + try: |
| 42 | + subprocess.run(["cmake", "-S", ".", "-B", f"build-{preset}", "--preset", preset], check=True) |
| 43 | + subprocess.run(["cmake", "--build", f"build-{preset}", "-j8"], check=True) |
| 44 | + except subprocess.CalledProcessError as e: |
| 45 | + print(f"Error while building embree with preset {preset}:\n{e.stderr}") |
| 46 | + continue |
| 47 | + |
| 48 | + |
| 49 | +# MODELS # |
| 50 | +########## |
| 51 | +if args.models == "git clone": |
| 52 | + print("Cloning embree models repository...") |
| 53 | + os.system(f"git lfs install") |
| 54 | + os.system(f"git clone https://github.com/intel-innersource/libraries.graphics.renderkit.embree.models.git ./embree-models") |
| 55 | + models_repo = os.path.abspath("./embree-models") |
| 56 | +else: |
| 57 | + models_repo = os.path.abspath(args.models) |
| 58 | + |
| 59 | +ecs_files = [] |
| 60 | +for root, _, files in os.walk(models_repo): |
| 61 | + for file in files: |
| 62 | + if file.endswith(".ecs"): |
| 63 | + ecs_files.append(os.path.join(root, file)) |
| 64 | + |
| 65 | +# Check for duplicate filenames in ecs_files |
| 66 | +filenames = [os.path.basename(ecs) for ecs in ecs_files] |
| 67 | +duplicates = set([name for name in filenames if filenames.count(name) > 1]) |
| 68 | + |
| 69 | +if duplicates: |
| 70 | + for duplicate in duplicates: |
| 71 | + print(f"WARNING: Duplicate filename detected: {duplicate}") |
| 72 | + |
| 73 | + |
| 74 | +# RUN BENCHMARKS # |
| 75 | +################## |
| 76 | + |
| 77 | +def runbench(preset, exe, ecs): |
| 78 | + print(os.path.abspath(f"./{args.out}/viewer_{preset}_{os.path.basename(ecs)[:-4]}.json")) |
| 79 | + cmd = [ |
| 80 | + f"./build-{preset}/{exe}", |
| 81 | + "-c", ecs, |
| 82 | + "--size", f"{args.size[0]}", f"{args.size[1]}", |
| 83 | + "--benchmark", "1", "8", f"--benchmark_out={os.path.abspath(f"./{args.out}/viewer_{preset}_{os.path.basename(ecs)[:-4]}.json")}" |
| 84 | + ] |
| 85 | + try: |
| 86 | + print(f"embree viewer {preset}: {ecs} ...") |
| 87 | + result = subprocess.run(cmd, check=True, text=True, capture_output=True) |
| 88 | + print(result.stdout) |
| 89 | + except subprocess.CalledProcessError as e: |
| 90 | + print(f"Error while processing {ecs} with preset {preset}:\n{e.stderr}") |
| 91 | + |
| 92 | + |
| 93 | +# Ensure the output directory exists |
| 94 | +if not os.path.exists(args.out): |
| 95 | + os.makedirs(args.out) |
| 96 | + print(f"Created output directory: {args.out}") |
| 97 | + |
| 98 | + |
| 99 | +for preset in presets: |
| 100 | + for ecs in ecs_files: |
| 101 | + if not "crown.ecs" in ecs: |
| 102 | + continue |
| 103 | + |
| 104 | + runbench(preset, "embree_viewer", ecs) |
| 105 | + #runbench(preset, "embree_pathtracer", ecs) |
| 106 | + |
| 107 | + |
| 108 | + |
0 commit comments