Improve find_permutation with ambiguous layouts - #5153
Conversation
There was a problem hiding this comment.
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_adaptorandelement_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.
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
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>
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.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.