-
Notifications
You must be signed in to change notification settings - Fork 39
Add unified benchmarking harness (iris.bench) #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/add-unified-benchmarking-harness
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4beb34e
Initial plan
Copilot 789dfb2
Add unified benchmarking harness (iris.bench)
Copilot 0aa03b8
Add migration documentation and fix linting issues
Copilot 74d3c62
Add README for bench module
Copilot c137b81
Refactor to decorator-only approach per feedback
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # iris.bench - Unified Benchmarking Harness | ||
|
|
||
| A standardized benchmarking infrastructure for Iris that reduces code duplication and provides consistent performance measurement across examples and benchmarks. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```python | ||
| import iris | ||
| from iris.bench import benchmark | ||
|
|
||
| # Simple decorator-based benchmarking | ||
| @benchmark(name="my_kernel", warmup=5, iters=50) | ||
| def run_kernel(): | ||
| kernel[grid](buffer, size) | ||
|
|
||
| result = run_kernel() | ||
| result.print_summary() | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| - ✅ **Automatic warmup and timing** - No more manual warmup loops | ||
| - ✅ **Rich statistics** - mean, median, p50, p99, min, max | ||
| - ✅ **Parameter sweeps** - Easy iteration over configurations | ||
| - ✅ **Multi-GPU support** - Built-in barrier synchronization | ||
| - ✅ **JSON export** - Structured results for CI/CD integration | ||
| - ✅ **Utility functions** - `torch_dtype_from_str`, `compute_bandwidth_gbps` | ||
|
|
||
| ## What Problem Does This Solve? | ||
|
|
||
| Before `iris.bench`, every benchmark had ~100 lines of duplicated code for: | ||
| - Argument parsing (datatype, warmup, iterations) | ||
| - Dtype string-to-torch conversion | ||
| - Manual warmup loops | ||
| - Timing and synchronization | ||
| - Result formatting and printing | ||
|
|
||
| This led to: | ||
| - 🔴 Copy-pasted code across 20+ benchmark files | ||
| - 🔴 Inconsistent measurement patterns | ||
| - 🔴 No standardized statistics (p50, p99) | ||
| - 🔴 Hard to maintain and extend | ||
|
|
||
| With `iris.bench`: | ||
| - ✅ ~50% less code per benchmark | ||
| - ✅ Standardized API across all benchmarks | ||
| - ✅ Easy to add new benchmarks | ||
| - ✅ CI-ready JSON export | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Example 1: Simple Benchmark | ||
| ```python | ||
| from iris.bench import BenchmarkRunner | ||
|
|
||
| runner = BenchmarkRunner(name="test", barrier_fn=shmem.barrier) | ||
|
|
||
| def operation(): | ||
| kernel[grid](buffer) | ||
|
|
||
| result = runner.run(fn=operation, warmup=5, iters=50) | ||
| result.print_summary() | ||
| ``` | ||
|
|
||
| ### Example 2: Parameter Sweep | ||
| ```python | ||
| from iris.bench import BenchmarkRunner, torch_dtype_from_str | ||
|
|
||
| runner = BenchmarkRunner(name="dtype_sweep") | ||
|
|
||
| for dtype_str in ["fp16", "fp32"]: | ||
| for size in [1024, 2048]: | ||
| dtype = torch_dtype_from_str(dtype_str) | ||
|
|
||
| def op(): | ||
| tensor = torch.zeros(size, size, dtype=dtype, device="cuda") | ||
| result = tensor @ tensor | ||
|
|
||
| runner.run(fn=op, warmup=5, iters=20, | ||
| params={"size": size, "dtype": dtype_str}) | ||
|
|
||
| runner.save_json("results.json") | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| - 📖 [Full API Documentation](bench_harness.md) | ||
| - 📖 [Migration Guide](bench_migration_example.md) | ||
| - 💻 [Complete Examples](../examples/benchmark/bench_harness_example.py) | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # Run basic tests (no GPU required) | ||
| python3 tests/unittests/test_bench_basic.py | ||
|
|
||
| # Run full test suite (requires GPU) | ||
| pytest tests/unittests/test_bench.py | ||
| ``` | ||
|
|
||
| ## API Overview | ||
|
|
||
| ### BenchmarkResult | ||
| Stores benchmark results with automatic statistics computation. | ||
|
|
||
| ### BenchmarkRunner | ||
| Main class for running benchmarks with parameter sweeps. | ||
|
|
||
| ### @benchmark | ||
| Decorator for simple function benchmarking. | ||
|
|
||
| ### Utilities | ||
| - `torch_dtype_from_str(dtype_str)` - Convert string to torch.dtype | ||
| - `compute_bandwidth_gbps(bytes, time_ms)` - Calculate bandwidth | ||
|
|
||
| ## Integration | ||
|
|
||
| The harness is designed to work alongside existing `iris.do_bench` usage: | ||
| - `BenchmarkRunner` internally uses `iris.do_bench` | ||
| - All existing barrier functions work with `barrier_fn` parameter | ||
| - Gradual migration path - old benchmarks continue to work | ||
|
|
||
| ## Contributing | ||
|
|
||
| When adding new benchmarks: | ||
| 1. Use `iris.bench` for all new code | ||
| 2. Consider migrating nearby old benchmarks | ||
| 3. Export results to JSON for CI integration | ||
| 4. Follow examples in `examples/benchmark/` | ||
|
|
||
| ## License | ||
|
|
||
| MIT License - Copyright (c) 2025-2026 Advanced Micro Devices, Inc. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot the decorator way is the only way we need. Remove everything else. Also, it is safe to assume that the bench harness will construct the iris instance and pass it to the user benchmark function. When using the decorator the user will need to also annotate parts of the code that are presetup (eg tensor allocation), preamble per run (eg resetting flags) and code to actually benchmark (kernel launch ).