Skip to content

Sym reshapes#4832

Draft
shivadbhavsar wants to merge 9 commits into
developfrom
sym_reshapes
Draft

Sym reshapes#4832
shivadbhavsar wants to merge 9 commits into
developfrom
sym_reshapes

Conversation

@shivadbhavsar
Copy link
Copy Markdown
Contributor

Motivation

Refactor reshape ops to use dim-like variant to handle symbolic shapes. This will be required when trying to enable simplification passes for symbolic shapes.

Technical Details

Add dim_like variant that works out of the box for current int64 representation for static shapes but can be extended to dyn_dims for symbolic shapes to allow symbolic target dims.

compute_shape will be modified in a later PR, the purpose here is to just introduce the new variant and ensure it causes no regressions with existing static shape compilation.

Later we would want to use this similarly for other ops such as slice, resize, etc. We can also consider refactoring broadcast ops to consolidate the current dual attribute implementation with out_lens and out_dyn_dims

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.

@shivadbhavsar shivadbhavsar changed the base branch from develop to to_symbolic_helper April 29, 2026 23:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4832      +/-   ##
===========================================
+ Coverage    92.79%   92.80%   +0.01%     
===========================================
  Files          584      586       +2     
  Lines        30111    30140      +29     
===========================================
+ Hits         27941    27970      +29     
  Misses        2170     2170              
Files with missing lines Coverage Δ
src/dim_like.cpp 100.00% <100.00%> (ø)
src/include/migraphx/dim_like.hpp 100.00% <100.00%> (ø)
src/include/migraphx/op/reshape.hpp 100.00% <100.00%> (ø)
src/include/migraphx/op/reshape_lazy.hpp 95.92% <100.00%> (+0.09%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from to_symbolic_helper to develop April 30, 2026 17:04
@shivadbhavsar shivadbhavsar requested a review from CharlieL7 May 1, 2026 16:53
@pfultz2
Copy link
Copy Markdown
Collaborator

pfultz2 commented May 5, 2026

I would like to merge in #3753 first which unifies the reshape calculation for both reshape and reshape_lazy and it also propagates the permutation.

// A dim attribute entry that may be either a plain int64_t or a
// dynamic_dimension. Used by ops whose dim-valued attributes need to carry
// either static integers or dynamic/symbolic dimensions.
struct MIGRAPHX_EXPORT dim_like
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.

Why do you wrap it in the class instead of using the variant directly? If its for implicit constructor for SLES maybe we need to create our own variant wrapper.

But if we do make it a seperate class we can try to make it more friendly to use.

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.

I think the main issue was that a lot of passes will pass some shape.lens() (size_t) to the dims attribute which would require modifying too many callsites.

Can you explain a little more about what this variant wrapper would look like? It should like a good idea since I had to do similar wrapping for scalar in sym

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.

I am thinking something like this:

template <class Picker, class... Ts>
struct picked_variant : std::variant<Ts...> 
{
    using base = std::variant<Ts...>;
    using base::base;   // inherit default, in_place_type, in_place_index ctors

    template <class T,
              MIGRAPHX_REQUIRES(std::is_base_of<T, base>{})>
    picked_variant(T&& x) : base(Picker::apply(std::forward<T>(x))) {}
};

But std::visit wont work directly without p2162r2 from C++23, so we may need to write a custom visit method that downcasts the variants.

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.

I dont quite get the meaning of MIGRAPHX_REQUIRES(std::is_base_of<T, base>{})>. Shouldn't it be something like not std::is_constructible<base, T&&>{} so it only got to the picker for types that are not supported by default?

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