Skip to content

[AIMIGRAPHX-408] Update intermediate ops to support dynamic shapes#4581

Merged
causten merged 55 commits intodevelopfrom
dyn_mlir_pw
Apr 9, 2026
Merged

[AIMIGRAPHX-408] Update intermediate ops to support dynamic shapes#4581
causten merged 55 commits intodevelopfrom
dyn_mlir_pw

Conversation

@shivadbhavsar
Copy link
Copy Markdown
Contributor

Motivation

Enable running fully dynamic graphs with gemm and pointwise ops

Technical Details

Update contiguous op to work with dynamic shapes. Required for running mlir gemms

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.

Should go in after #4549

Base automatically changed from dyn_code_obj to develop March 3, 2026 16:55
@shivadbhavsar shivadbhavsar marked this pull request as ready for review March 3, 2026 17:56
@shivadbhavsar shivadbhavsar requested a review from causten as a code owner March 3, 2026 17:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates GPU intermediate ops and MLIR fusion pipeline to better support fully dynamic-shape graphs (notably dot/gemm + pointwise), and adds/extends tests to validate behavior.

Changes:

  • Make GPU contiguous/unary device eval paths handle dynamic output shapes correctly.
  • Prevent reduce_dims from throwing on dynamic shapes and add coverage for dynamic-shape inputs.
  • Enable additional GPU compilation/fusion paths for dynamic graphs and add a dynamic GEMM+pointwise verify test.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/verify/test_dynamic_pointwise.cpp Minor comment formatting update in an existing dynamic pointwise verify test.
test/verify/test_dynamic_gemm_pointwise.cpp Adds a new verify test covering dynamic batch/K GEMM followed by broadcast + pointwise ops (MLIR-gated).
test/verify/main.cpp Registers the new dynamic GEMM+pointwise verify test instantiations and keeps dynamic pointwise tests listed.
test/reduce_dims.cpp Adds a dynamic-shape test case for reduce_dims plus a small dynamic-shape helper.
src/reduce_dims.cpp Early-return for dynamic shapes to avoid calling lens()/strides() on dynamic shapes.
src/targets/gpu/target.cpp Runs fuse_pointwise_reduce unconditionally and enables fuse_mlir whenever MLIR is enabled (including full dynamic).
src/targets/gpu/include/migraphx/gpu/oper.hpp Avoids reshaping through dynamic reduce_shapes and reshapes unary outputs using computed runtime shape when needed.
src/targets/gpu/include/migraphx/gpu/contiguous.hpp Allows dynamic shapes in gpu::contiguous and returns a dynamic output shape when input is dynamic.
src/targets/gpu/fuse_mlir.cpp Adjusts MLIR fusion matcher inheritance related to dynamic-shape matching.
src/targets/gpu/compile_ops.cpp Makes runtime module naming robust when module_args are empty and aligns parameter naming with the selected runtime module name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +708 to 709
struct find_mlir_fused_ops
{
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Removing match::supports_dynamic_shapes from find_mlir_fused_ops means matcher.hpp will wrap the matcher with not_dynamic_shape(...), so this fusion will no longer trigger on dynamic-shaped graphs (dot/conv -> reshapes -> pointwise). If the intent of this PR is to support dynamic gemm+pointwise via MLIR fusion, consider re-adding match::supports_dynamic_shapes (or otherwise making the matcher explicitly dynamic-safe) so dynamic graphs still get fused; if this is intentional, it likely needs an in-code explanation because it counteracts enabling fuse_mlir under MIGRAPHX_ENABLE_FULL_DYNAMIC.

Copilot uses AI. Check for mistakes.
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.

What was the intent here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this doesnt actually work till we fix multibroadcasts for the dynamic case. Either I have to rewrite the logic to hadle that or this will work as it is once we rewrite dynamic broadcasts as single input ops with symbolic dimensions. Plan is to do the latter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for now we are stuck with only using standalone ops

@shivadbhavsar shivadbhavsar requested a review from bdevorem March 4, 2026 20:05
Copy link
Copy Markdown
Member

@bdevorem bdevorem left a comment

Choose a reason for hiding this comment

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

lgtm. The only thing I'd say is I'd appreciate more inline comments. Also, are you waiting until the work is done to update the changelog? That makes sense, but if you aren't, then just fyi that it hasn't been updated here

Comment on lines +708 to 709
struct find_mlir_fused_ops
{
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.

What was the intent here?

@causten causten merged commit 56e1a32 into develop Apr 9, 2026
32 checks passed
@causten causten deleted the dyn_mlir_pw branch April 9, 2026 03:08
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.

5 participants