Propagate layout with reshape after lowering#4976
Open
pfultz2 wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a GPU backend pass to preserve/propagate non-standard (permuted) layouts through a lowered reshape sequence, addressing cases where eliminate_contiguous keeps a standardizing gpu::contiguous before reshape_lazy and thereby discards the original permutation.
Changes:
- Introduces
gpu::propagate_reshape_layoutpass that replaces the surviving pre-reshape_lazystandardizinggpu::contiguouswith alayout(viagpu::precompile_op) +allocateto repack into the alias-friendly order. - Hooks the new pass into the GPU backend pipeline immediately after
eliminate_contiguous. - Adds a GPU unit test covering both the permutation-propagation case and a no-op case.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/gpu/propagate_reshape_layout.cpp | Adds coverage to ensure the pass inserts layout when permutation would otherwise be lost, and is a no-op when there’s no permutation to propagate. |
| src/targets/gpu/target.cpp | Inserts propagate_reshape_layout into the GPU compilation pipeline after eliminate_contiguous. |
| src/targets/gpu/propagate_reshape_layout.cpp | Implements the matcher-based rewrite from gpu::contiguous -> reshape_lazy into layout -> reshape_lazy for non-standard inputs. |
| src/targets/gpu/include/migraphx/gpu/propagate_reshape_layout.hpp | Declares the new GPU pass and documents its intent and placement. |
| src/targets/gpu/CMakeLists.txt | Adds the new pass source file to the GPU library build. |
CharlieL7
approved these changes
Jun 17, 2026
CharlieL7
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Though I'm wondering if there is a way to keep track of memory layout vs. shape. It is difficult to follow what's happening to both.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Even though
reshapepropagates the permutation after lowering its get lowered to contiguous->reshape_lazy, which will always use standard shape. Instead this adds a pass to insert alayoutso it will propagate the permutation inreshape_lazy.Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable