Skip to content

✨ Implement "drive-by" Method for Layout Conciliation - #2060

Merged
burgholzer merged 10 commits into
mainfrom
enh/better-voting-strategy
Aug 12, 2026
Merged

✨ Implement "drive-by" Method for Layout Conciliation #2060
burgholzer merged 10 commits into
mainfrom
enh/better-voting-strategy

Conversation

@MatthiasReumann

@MatthiasReumann MatthiasReumann commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

This function is a follow-up to the discussion had in #1951. Particularly, it removes the Borda rank method to find an "average" layout and replaces it with a "drive-by" strategy, which is significantly less computationally expensive than a mediod approach (especially for many cases) but respects the hardware-topology. Furthermore, it's rather trivial to implement.

Preliminary benchmarks (based on our very, very trivial unit-tests; average of 16 runs) show that the proposed method requires 5% less SWAPs than the "restore-to-parent" method and 98% than the Borda rank method1.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

Footnotes

  1. Highlighting the unsuitability of the Borda rank for this particular problem.

@MatthiasReumann MatthiasReumann changed the title ✨ Implement ✨ Implement "drive-by" Method for Layout Conciliation Aug 12, 2026
@MatthiasReumann MatthiasReumann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Aug 12, 2026
@MatthiasReumann MatthiasReumann self-assigned this Aug 12, 2026
@MatthiasReumann MatthiasReumann added this to the MLIR Support milestone Aug 12, 2026
@MatthiasReumann

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Improvements

    • Improved layout selection for indexed control-flow operations by using a compromise layout derived from child layouts.
    • Added forward and reverse layout adjustments to reduce unnecessary movement between layouts.
    • Updated mapping behavior to restore child layouts before inserting required SWAP operations.
  • Tests

    • Updated mapping expectations to reflect the revised number of inserted SWAP operations.

Walkthrough

The index-switch mapper now computes a compromise layout with iterative forward and reverse happy SWAP-chain passes. It restores each child layout to that compromise before inserting SWAPs. The related test now expects six SWAP operations.

Changes

Index-switch layout mapping

Layer / File(s) Summary
Drive-by compromise layout
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
The static Borda-count helper is replaced by driveby, which anchors on the first layout and applies forward and reverse happy SWAP-chain passes.
Index-switch restoration and validation
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp, mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
Index-switch child layouts use the drive-by compromise layout before SWAP insertion. The expected SWAP count changes from four to six.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: burgholzer, denialhaag

Sequence Diagram(s)

sequenceDiagram
  participant IndexSwitch
  participant driveby
  participant ChildLayouts
  participant SWAPInsertion
  IndexSwitch->>driveby: provide child layouts
  driveby->>ChildLayouts: apply forward and reverse happy SWAP chains
  driveby-->>IndexSwitch: return compromise layout
  IndexSwitch->>ChildLayouts: restore each layout to compromise
  IndexSwitch->>SWAPInsertion: insert required SWAP operations
Loading

Poem

A rabbit hops through layouts bright,
Forward, backward, left, and right.
Happy swaps align the way,
Six small hops complete the day.
The switch now shares one route. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: implementing the drive-by method for layout conciliation.
Description check ✅ Passed The description includes the change summary, motivation, benchmarks, tests, and checklist, but it lacks the required visible AI disclosure at the start.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch enh/better-voting-strategy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp`:
- Around line 1477-1485: Update the driveby call in the IndexSwitch compromise
mapping flow to pass the configured niterations value as its second argument,
ensuring convergence uses the requested iteration count instead of driveby’s
default.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: faae55a0-8a5c-4d43-9dd1-c770d47a0b43

📥 Commits

Reviewing files that changed from the base of the PR and between 6eaef17 and f2ad858.

📒 Files selected for processing (2)
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp

Comment thread mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Lukas Burgholzer <burgholzer@me.com>

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@burgholzer
burgholzer enabled auto-merge (squash) August 12, 2026 08:47
@burgholzer
burgholzer merged commit 315a3c0 into main Aug 12, 2026
33 checks passed
@burgholzer
burgholzer deleted the enh/better-voting-strategy branch August 12, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants