Skip to content

Improve find_permutation with ambiguous layouts - #5153

Open
pfultz2 wants to merge 5 commits into
developfrom
find-permutation-ambiguous-layout
Open

Improve find_permutation with ambiguous layouts#5153
pfultz2 wants to merge 5 commits into
developfrom
find-permutation-ambiguous-layout

Conversation

@pfultz2

@pfultz2 pfultz2 commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Motivation

When using find_permutation(std::vector<shape>), it pick the permutation that most shapes uses. However, with an ambiguous layout(such as shapes with dimensions of 1) a better choice can be found by considering what other layouts are compatible.

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.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@pfultz2
pfultz2 requested a review from causten as a code owner August 18, 2026 21:50
Copilot AI lite review requested due to automatic review settings August 18, 2026 21:50

Copilot AI 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.

Pull request overview

This PR improves MIGraphX’s find_permutation(std::vector<shape>) layout selection when some shapes are layout-ambiguous due to singleton dimensions, so that “definite” layouts can win even when ambiguous shapes are present. It also introduces a small output-iterator utility to enable in-place algorithm updates of tuple/pair elements (used to update std::map values), alongside new tests covering the updated behavior.

Changes:

  • Update find_permutation(std::vector<shape>) to vote based on which candidate permutations each shape can support (treating singleton dims as layout-ambiguous).
  • Add function_output_iterator_adaptor and element_output_iterator<N> to support algorithmic updates of container element subfields (e.g., map values).
  • Add/extend unit tests for ambiguous-layout permutation selection and a concat/layout-convolution scenario.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/permutation.cpp Updates multi-shape permutation selection to account for singleton-dim ambiguity via “supported permutation” voting.
src/include/migraphx/output_iterator.hpp Adds output-iterator adaptor utilities used to update map values via standard algorithms.
test/shape_test.cpp Adds new test cases for ambiguous singleton-dimension layout selection in find_permutation(vector<shape>).
test/op_shape_test.cpp Adds concat shape test ensuring NHWC wins when the other input is singleton-channel ambiguous.
test/layout_convolution.cpp Adds regression test ensuring concat with singleton-channel literal doesn’t force an unwanted relayout under channels-last convolution pass.
test/output_iterator_test.cpp Adds unit tests for the new output-iterator utilities.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/permutation.cpp
Comment thread src/include/migraphx/output_iterator.hpp
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/permutation.cpp 91.67% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5153      +/-   ##
===========================================
+ Coverage    93.12%   93.13%   +0.01%     
===========================================
  Files          625      625              
  Lines        33162    33282     +120     
===========================================
+ Hits         30879    30995     +116     
- Misses        2283     2287       +4     
Files with missing lines Coverage Δ
src/include/migraphx/output_iterator.hpp 100.00% <100.00%> (ø)
src/permutation.cpp 85.19% <91.67%> (+1.58%) ⬆️

... and 3 files with indirect coverage changes

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

pfultz2 and others added 2 commits August 19, 2026 11:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants