Skip to content

[AIROCMIR-446] Lower migraphx.clip into linalg.min (linalg.max(x, minValues),maxValues)#2232

Open
Mr-Anyone wants to merge 2 commits intopr-template-migraphx-to-linalg-4from
pr-template-migraphx-to-linalg-5
Open

[AIROCMIR-446] Lower migraphx.clip into linalg.min (linalg.max(x, minValues),maxValues)#2232
Mr-Anyone wants to merge 2 commits intopr-template-migraphx-to-linalg-4from
pr-template-migraphx-to-linalg-5

Conversation

@Mr-Anyone
Copy link
Member

Motivation

Lower migraphx.clip into two linalg operations.

Technical Details

Introduces a new ClipConverter that lowers migraphx.clip using a composition of linalg.max and linalg.min.

Implements the semantic equivalence:

clip(x, min, max) = min(max(x, min), max)

Test Plan

Added a lit test.

Test Result

Passed lit test.

Submission Checklist

@Mr-Anyone Mr-Anyone requested a review from causten as a code owner February 5, 2026 21:09
@Mr-Anyone
Copy link
Member Author

Loop fusions seems to work out of the box for this one.

@Mr-Anyone Mr-Anyone changed the title [AIROCMIR-446] Lower migraphx.clip into min(max(x, minValues),maxValues) [AIROCMIR-446] Lower migraphx.clip into linalg.min (linalg.max(x, minValues),maxValues) Feb 5, 2026
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-4 branch from c03e94c to c51ed1b Compare February 6, 2026 18:40
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-5 branch from 0d45610 to 032ff31 Compare February 6, 2026 18:41
// CHECK-DAG: %[[one:.*]] = linalg.min ins(%[[zero]], %[[expanded]] : {{.*}}) outs(%cst_2 : {{.*}})
// CHECK-DAG: %[[collapsed:.*]] = tensor.collapse_shape %[[one]]
// CHECK-DAG: return %[[collapsed]]
func.func @func_clip(%x: !migraphx.shaped<1x1xf32, 1x1>, %min: !migraphx.shaped<1x1xf32, 1x1>, %max: !migraphx.shaped<1x1xf32, 1x1>) -> !migraphx.shaped<1x1xf32, 1x1> {
Copy link
Member

Choose a reason for hiding this comment

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

Clip is also elemenetiwse op. Can you put that into same file as elementwise ?

@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-4 branch from c51ed1b to 1b70fe8 Compare February 11, 2026 14:49
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-5 branch from 032ff31 to d7c9be3 Compare February 11, 2026 14:57
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-4 branch from d9857f0 to 880e493 Compare February 11, 2026 15:14
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-5 branch from d7c9be3 to 5ba6cdb Compare February 11, 2026 15:17
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-4 branch from 880e493 to 51c5c87 Compare February 12, 2026 19:16
@Mr-Anyone Mr-Anyone force-pushed the pr-template-migraphx-to-linalg-5 branch from 5ba6cdb to 8659c1e Compare February 12, 2026 19:23
@Mr-Anyone Mr-Anyone requested a review from umangyadav February 12, 2026 19:26
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