dyn_slice operator for symbolics and data-dependent operators - #5112
Open
CharlieL7 wants to merge 6 commits into
Open
dyn_slice operator for symbolics and data-dependent operators#5112CharlieL7 wants to merge 6 commits into
dyn_slice operator for symbolics and data-dependent operators#5112CharlieL7 wants to merge 6 commits into
Conversation
dyn_slice operator for symbolics and data-dependent operators
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
CharlieL7
marked this pull request as ready for review
August 5, 2026 21:49
CharlieL7
requested review from
pfultz2 and
shivadbhavsar
and
a lite review from Copilot
August 5, 2026 21:49
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new dyn_slice operator to support compile-time symbolic output shapes while still allowing data-dependent slice bounds at runtime, and extends attribute normalization to optionally operate symbolically via a new use_sym normalize attribute.
Changes:
- Added
dyn_slice(data, starts, ends)op with symbolic bound attributes (vector<dim_like>) and runtime-bound execution. - Extended attribute normalization to support symbolic clamping when
use_symis enabled. - Updated slice behavior/tests to reject symbolic input shapes and route symbolic slicing use-cases through
dyn_sliceinstead.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/sym.cpp | Adds rewrite-rule coverage tests for redundant nested min/max clamping. |
| test/ref/dyn_slice.cpp | New ref backend tests validating dyn_slice runtime behavior with concrete and symbolic bounds. |
| test/op_shape_test.cpp | Adds shape-inference tests for dyn_slice and updates symbolic-shape expectations for slice. |
| test/normalize_ops_test.cpp | Adds normalization-pass tests for symbolic attribute clamping and use_sym opt-in enforcement. |
| test/gpu/dyn_slice_lowering.cpp | Adds GPU lowering test coverage for dyn_slice metadata-host-copy behavior. |
| src/targets/gpu/lowering.cpp | Extends runtime-metadata lowering to apply to both slice and dyn_slice. |
| src/sym.cpp | Adds rewrite rules to fold away redundant nested min/max clamps. |
| src/normalize_attributes.cpp | Implements symbolic attribute normalization path (use_sym) and refactors normalization helpers. |
| src/include/migraphx/operators.hpp | Registers the new dyn_slice operator header in the operator include set. |
| src/include/migraphx/op/slice.hpp | Rejects symbolic input shapes for slice (directing users to dyn_slice). |
| src/include/migraphx/op/normalize_attribute.hpp | Adds use_sym normalize attribute and documents symbolic normalization semantics. |
| src/include/migraphx/op/dyn_slice.hpp | New dyn_slice operator implementation and normalization attributes. |
| src/include/migraphx/dim_like.hpp | Adds helpers for converting dim_like vectors to concrete ints or symbolic expressions. |
| src/CMakeLists.txt | Registers dyn_slice for op build/registration. |
| CHANGELOG.md | Documents dyn_slice, use_sym, and slice symbolic-shape rejection behavior. |
Comment on lines
+25
to
+34
| #include <migraphx/instruction.hpp> | ||
| #include <migraphx/literal.hpp> | ||
| #include <migraphx/make_op.hpp> | ||
| #include <migraphx/program.hpp> | ||
| #include <migraphx/register_target.hpp> | ||
| #include <migraphx/serialize.hpp> | ||
| #include <migraphx/sym.hpp> | ||
| #include <migraphx/verify.hpp> | ||
|
|
||
| #include <test.hpp> |
Comment on lines
+146
to
+158
| const auto& input = args.front(); | ||
| auto input_shape = input.get_shape(); | ||
| auto read = [](const argument& arg) { | ||
| std::vector<int64_t> result; | ||
| arg.visit([&](auto values) { result = values.template to_vector<int64_t>(); }); | ||
| return result; | ||
| }; | ||
| auto axes_attrs = this->attributes().at("normalize_axes"); | ||
| // Only use the starts_input and ends_input for the output slice. Not the attributes. | ||
| auto norm_starts = normalize_indices( | ||
| read(args[1]), axes, input_shape, axes_attrs.at("starts"), "DYN_SLICE: starts input"); | ||
| auto norm_ends = normalize_indices( | ||
| read(args[2]), axes, input_shape, axes_attrs.at("ends"), "DYN_SLICE: ends input"); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5112 +/- ##
===========================================
+ Coverage 93.25% 93.27% +0.01%
===========================================
Files 623 624 +1
Lines 33002 33232 +230
===========================================
+ Hits 30776 30994 +218
- Misses 2226 2238 +12
🚀 New features to boost your workflow:
|
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
dyn_sliceoperator that is able to output symbolic shapes at compile time.Technical Details
Always called with three inputs
dyn_slice(input, starts, ends).startsandendsattribute arevector<dim_like>so that they can contain symbolic expressions.Use a literal for the starts or ends input if they should be constant.
slice.compute()is called, the value atends_inputis used to determine the output shape.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.