Skip to content

Propagate layout with reshape after lowering#4976

Open
pfultz2 wants to merge 5 commits into
developfrom
lower-reshape-propagate-layout
Open

Propagate layout with reshape after lowering#4976
pfultz2 wants to merge 5 commits into
developfrom
lower-reshape-propagate-layout

Conversation

@pfultz2

@pfultz2 pfultz2 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Even though reshape propagates the permutation after lowering its get lowered to contiguous->reshape_lazy, which will always use standard shape. Instead this adds a pass to insert a layout so it will propagate the permutation in reshape_lazy.

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.

@pfultz2 pfultz2 marked this pull request as ready for review June 16, 2026 23:46
@pfultz2 pfultz2 requested a review from causten as a code owner June 16, 2026 23:46

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 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_layout pass that replaces the surviving pre-reshape_lazy standardizing gpu::contiguous with a layout (via gpu::precompile_op) + allocate to 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 CharlieL7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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.

3 participants