Skip to content

[AIMIGRAPHX-839] support symbolic shapes for broadcast ops#4819

Open
shivadbhavsar wants to merge 15 commits intosym_dot_shapesfrom
sym_broadcasts
Open

[AIMIGRAPHX-839] support symbolic shapes for broadcast ops#4819
shivadbhavsar wants to merge 15 commits intosym_dot_shapesfrom
sym_broadcasts

Conversation

@shivadbhavsar
Copy link
Copy Markdown
Contributor

Motivation

Building on top of #4702: update broadcast op compute shapes to work with symbolic shapes. Symbolic shapes also mean we no longer need to pass a 2nd input for shape reference.

Technical Details

Infrastructure

  • matcher.hpp: new symbolic_shape predicate (mirrors static_shape / dynamic_shape).
  • shape.hpp / shape.cpp: new shape::to_symbolic() — promotes static lens/strides to dd{sym::lit(...)} / sym::lit(...); idempotent on symbolic, throws on range-based dynamic. Centralizes "no mixing" enforcement.
  • common.hpp / common.cpp: new make_bcast_shape(shape, vector<dd>) overload for symbolic targets, factored over a templated make_bcast_shape_impl shared with the static overload.

Op support (compute_shape)

  • multibroadcast.hpp: 1-input symbolic mode — opt-in via fully-symbolic output_dyn_dims attribute. Static inputs bridged via to_symbolic(); range-dyn rejected.
  • broadcast.hpp:
    • New output_dyn_dims attribute + 1-input symbolic mode (mirroring multibroadcast).
    • 2-input path now accepts symbolic inputs. Static s0 bridged via to_symbolic(); range-dyn + symbolic combos rejected via to_symbolic()'s throw.
    • Shared build_output lambda used by both the 1-input and 2-input symbolic paths.
  • binary.hpp: symbolic inputs now fall through to the existing packed/broadcasted/permutation logic instead of throwing; routes via dyn_dims()-based with_lens / from_permutation overloads.

Compiler pass (simplify_dyn_ops)

  • find_symbolic_2in_broadcasts: rewrites a 2-input broadcast / multibroadcast whose result is fully symbolic into the 1-input form by setting out_dyn_dims.
  • find_symbolic_broadcast_for_dot: rewrites symbolic broadcast_for_dot into a 1-input multibroadcast with 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.

Copilot AI review requested due to automatic review settings April 24, 2026 01:15
@shivadbhavsar shivadbhavsar requested a review from causten as a code owner April 24, 2026 01:15
@shivadbhavsar shivadbhavsar changed the title support sym shapes for braodcasts support symbolic shapes for broadcast ops Apr 24, 2026
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

Adds first-class symbolic-shape support for broadcast-style operators by introducing a shape::to_symbolic() conversion path, a symbolic broadcast-shape builder, and compiler-pass rewrites that canonicalize eligible 2-input broadcasts into 1-input forms carrying symbolic output dims.

Changes:

  • Introduce shape::to_symbolic() and a match::symbolic_shape() predicate to enable symbolic-aware matching and shape promotion.
  • Add a symbolic overload of make_bcast_shape(...) and update broadcast, multibroadcast, and binary compute-shape logic to support fully-symbolic shapes.
  • Extend simplify_dyn_ops to rewrite fully-symbolic 2-input broadcast/multibroadcast and broadcast_for_dot into 1-input ops with out_dyn_dims, plus add extensive tests.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/shape.cpp Implements shape::to_symbolic() promotion logic (static → symbolic; reject range-dyn).
src/include/migraphx/shape.hpp Declares the new to_symbolic() API.
src/include/migraphx/matcher.hpp Adds symbolic_shape matcher predicate for symbolic output shapes.
src/common.cpp Refactors broadcast-shape construction and adds symbolic make_bcast_shape overload.
src/include/migraphx/common.hpp Exposes the symbolic make_bcast_shape overload and documents its contract.
src/include/migraphx/op/broadcast.hpp Adds out_dyn_dims attribute and a symbolic 1-input mode; allows symbolic 2-input path.
src/include/migraphx/op/multibroadcast.hpp Adds symbolic 1-input mode via fully-symbolic out_dyn_dims and bridges static inputs with to_symbolic().
src/include/migraphx/op/binary.hpp Allows fully-symbolic inputs to flow through existing broadcast/permutation logic.
src/simplify_dyn_ops.cpp Adds symbolic broadcast canonicalizations in simplify_dyn_ops.
test/shape_test.cpp Adds unit tests for to_symbolic() and symbolic/static make_bcast_shape.
test/op_shape_test.cpp Adds shape tests for symbolic binary ops and symbolic broadcast/multibroadcast modes.
test/simplify_dyn_ops_test.cpp Adds tests covering symbolic rewrites for broadcast, multibroadcast, and broadcast_for_dot.

Comment thread src/common.cpp
Comment thread src/common.cpp
Comment thread src/include/migraphx/op/broadcast.hpp Outdated
Comment thread src/include/migraphx/op/multibroadcast.hpp
Comment thread src/simplify_dyn_ops.cpp
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 96.49123% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/include/migraphx/op/broadcast.hpp 96.23% 2 Missing ⚠️
src/include/migraphx/op/binary.hpp 80.00% 1 Missing ⚠️
src/include/migraphx/op/multibroadcast.hpp 95.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           sym_dot_shapes    #4819      +/-   ##
==================================================
- Coverage           92.80%   92.80%   -0.00%     
==================================================
  Files                 584      584              
  Lines               30146    30169      +23     
==================================================
+ Hits                27976    27996      +20     
- Misses               2170     2173       +3     
Files with missing lines Coverage Δ
src/common.cpp 97.46% <100.00%> (+0.14%) ⬆️
src/include/migraphx/matcher.hpp 87.57% <100.00%> (+0.04%) ⬆️
src/simplify_dyn_ops.cpp 99.40% <100.00%> (+0.03%) ⬆️
src/include/migraphx/op/binary.hpp 93.94% <80.00%> (-2.61%) ⬇️
src/include/migraphx/op/multibroadcast.hpp 97.50% <95.00%> (-2.50%) ⬇️
src/include/migraphx/op/broadcast.hpp 96.67% <96.23%> (-0.89%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from sym_dim_integration to develop April 25, 2026 21:06
@shivadbhavsar shivadbhavsar changed the base branch from develop to to_symbolic_helper April 29, 2026 19:39
@shivadbhavsar shivadbhavsar changed the title support symbolic shapes for broadcast ops [AIMIGRAPHX-839] support symbolic shapes for broadcast ops Apr 29, 2026
@shivadbhavsar shivadbhavsar changed the base branch from to_symbolic_helper to sym_dot_shapes April 30, 2026 00:09
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