Skip to content

Add a Python script to benchmark mxr files#4876

Open
ahsan-ca wants to merge 2 commits into
developfrom
benchmark-mxr-script
Open

Add a Python script to benchmark mxr files#4876
ahsan-ca wants to merge 2 commits into
developfrom
benchmark-mxr-script

Conversation

@ahsan-ca
Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

@ahsan-ca ahsan-ca requested a review from pfultz2 May 12, 2026 18:13
@ahsan-ca ahsan-ca self-assigned this May 12, 2026
@ahsan-ca ahsan-ca requested a review from causten as a code owner May 12, 2026 18:13
Copilot AI review requested due to automatic review settings May 12, 2026 18:13
@ahsan-ca ahsan-ca added the high priority A PR with high priority for review and merging. label May 12, 2026
@ahsan-ca
Copy link
Copy Markdown
Contributor Author

Script and other changes generated using AI.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a workflow to benchmark .mxr binaries dumped from GPU tuning and emit a MIGRAPHX_PROBLEM_CACHE-compatible JSON, supported by a small extension to the core program API and Python bindings so dumped programs can be made runnable without re-running GPU compile passes.

Changes:

  • Add tools/benchmark_mxr.py to load dumped .mxr files, benchmark candidates per (preop, problem), and write out the fastest solutions as a problem-cache JSON.
  • Add migraphx::program::finalize(const target&) to attach a target/context to deserialized, not-yet-compiled programs and finalize without running compilation passes.
  • Extend Python bindings to expose program.finalize(target) and to allow passing migraphx.argument directly to program.run() / run_async().

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tools/benchmark_mxr.py New script that parses @comment metadata, benchmarks dumped .mxr programs, and writes a problem-cache JSON.
src/py/migraphx_py.cpp Python binding updates: expose program.finalize(target) and accept migraphx.argument directly in run parameter maps.
src/program.cpp Implements program::finalize(const target&) by attaching target/context when needed and calling existing finalize.
src/include/migraphx/program.hpp Declares and documents the new program::finalize(const target&) overload.

Comment thread tools/benchmark_mxr.py
Comment on lines +84 to +96
_LITERAL_KEYWORDS = {
"null": None,
"true": True,
"false": True,
"nan": float("nan"),
"inf": float("inf"),
"infinity": float("inf"),
"-nan": float("nan"),
"-inf": float("-inf"),
"-infinity": float("-inf"),
}
_LITERAL_KEYWORDS["false"] = False

Comment thread tools/benchmark_mxr.py
Comment on lines +318 to +319
for name, shape in prog.get_parameter_shapes().items():
host_arg = migraphx.generate_argument(shape, next_seed)
Comment on lines 112 to +122
void finalize();

// Attach `t` to a program that hasn't been compiled yet (e.g. one loaded
// from an .mxr produced by `compile_plan::save_binaries`, which contains
// already-lowered GPU code objects but no targets/contexts), then
// finalize. Unlike `compile()`, this runs no passes -- it just sets up
// the target + context and calls `finalize()`. Mirrors what
// `time_program` (src/targets/gpu/time_op.cpp) does internally so the
// program becomes runnable without re-running any rewrites that would
// mutate already-lowered instructions.
void finalize(const target& t);
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/program.cpp 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4876   +/-   ##
========================================
  Coverage    92.85%   92.85%           
========================================
  Files          584      585    +1     
  Lines        30147    30126   -21     
========================================
- Hits         27992    27973   -19     
+ Misses        2155     2153    -2     
Files with missing lines Coverage Δ
src/include/migraphx/program.hpp 100.00% <ø> (ø)
src/program.cpp 80.48% <0.00%> (-0.65%) ⬇️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority A PR with high priority for review and merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants