Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def run(
timer: Callable[[], float] = perf_counter,
memory_reader: Callable[[], float] = current_memory_bytes,
memory_sampling_interval: float = 0.05,
cpp_binary: str | None = None,
) -> dict[str, Any]:
"""
Run the benchmark.
"""
solver = kspaceFirstOrder if solver is None else solver
cases = grid_sizes(options)
if max_cases is not None:
Expand All @@ -61,6 +65,11 @@ def run(
"error_reached": False,
"error_message": "",
}

# If the run() caller provided a cpp_binary override, record it in the saved options
if cpp_binary is not None:
result["options"]["cpp_binary"] = cpp_binary

if options.report_mem_usage:
# Probe early so unsupported combinations (e.g. Windows + cpp) fail
# before any output file is written. cpp probes the sampler class
Expand Down Expand Up @@ -103,6 +112,7 @@ def run(
pml_size=options.pml_size,
pml_inside=options.pml_inside,
smooth_p0=False,
binary_path=cpp_binary,
)
Comment on lines 112 to 116

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Binary configuration values diverge

When a programmatic caller sets BenchmarkOptions.cpp_binary but does not repeat it as run(cpp_binary=...), the saved options report the custom binary while execution passes None and uses the bundled binary, causing misleading benchmark provenance or a missing-binary failure.

Knowledge Base Used: Native solver integration

elapsed_time = timer() - start
loop_mem_usage = rolling_average(loop_mem_usage, memory_sampler.peak_bytes, loop_num)
Expand All @@ -119,6 +129,7 @@ def run(
pml_size=options.pml_size,
pml_inside=options.pml_inside,
smooth_p0=False,
binary_path=cpp_binary,
)
elapsed_time = timer() - start
loop_time = rolling_average(loop_time, elapsed_time, loop_num)
Expand All @@ -144,6 +155,7 @@ def _parse_args() -> argparse.Namespace:
parser.add_argument("--output-path", type=Path, default=None)
parser.add_argument("--report-mem-usage", action="store_true")
parser.add_argument("--verbose", action="store_true")
parser.add_argument("--cpp-binary", type=str, default=None, help="Path to a custom C++ binary to use for backend=cpp")
return parser.parse_args()


Expand All @@ -154,6 +166,7 @@ def main() -> int:
num_averages=args.num_averages,
number_time_points=args.number_time_points,
report_mem_usage=args.report_mem_usage,
cpp_binary=args.cpp_binary,
)
result = run(
benchmark_options,
Expand All @@ -162,6 +175,7 @@ def main() -> int:
max_cases=args.max_cases,
output_path=args.output_path,
quiet=not args.verbose,
cpp_binary=args.cpp_binary,
)
print(f"Benchmark results saved to {result['output_path']}")
if result["error_reached"]:
Expand All @@ -172,4 +186,4 @@ def main() -> int:


if __name__ == "__main__":
raise SystemExit(main())
raise SystemExit(main())
3 changes: 2 additions & 1 deletion benchmarks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BenchmarkOptions:
pml_size: int = 10
pml_inside: bool = True
report_mem_usage: bool = False
cpp_binary: str | None = None

def __post_init__(self) -> None:
if self.data_cast not in {"off", "single"}:
Expand Down Expand Up @@ -324,4 +325,4 @@ def _sample_until_stopped(self) -> None:
def _record_sample(self) -> None:
memory_bytes = validate_memory_bytes(self._reader())
with self._lock:
self._peak_bytes = max(self._peak_bytes, memory_bytes)
self._peak_bytes = max(self._peak_bytes, memory_bytes)
Loading