[AIROCMLIR-599] Lower migraphx.slice into tensor.slice#2281
[AIROCMLIR-599] Lower migraphx.slice into tensor.slice#2281
migraphx.slice into tensor.slice#2281Conversation
|
The models are the following, and can be found here: |
There was a problem hiding this comment.
Pull request overview
This PR adds support for lowering migraphx.slice ops to tensor.extract_slice during the MIGraphX→Linalg conversion, and updates lit tests to reflect the newly-supported operation.
Changes:
- Add a
SliceConverterto lowermigraphx.sliceintotensor.extract_slicein the MIGraphX→Linalg conversion. - Add lit coverage for slice lowering and remove
migraphx.slicefrom the “not implemented” negative test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
mlir/lib/Conversion/MIGraphXToLinalg/MIGraphXToLinalg.cpp |
Introduces SliceConverter pattern and registers it in the conversion pattern list. |
mlir/test/Conversion/MIGraphXToLinalg/mixr-to-linalg-ops.mlir |
Adds FileCheck assertions + MIGraphX slice test cases to validate lowering output. |
mlir/test/Conversion/MIGraphXToLinalg/migraphx-to-linalg-not-implemented.mlir |
Removes the expected-failure test for migraphx.slice now that it’s implemented. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // CHECK-DAG: %[[expanded:.*]] = tensor.expand_shape %[[arg0]] {{.*}} output_shape [10, 10] : tensor<100xf32> into tensor<10x10xf32> | ||
| // CHECK-DAG: %[[extracted_slice:.*]] = tensor.extract_slice %[[expanded]][2, 2] [8, 8] [1, 1] : tensor<10x10xf32> to tensor<8x8xf32> | ||
| // CHECK-DAG: %[[collapsed:.*]] = tensor.collapse_shape %[[extracted_slice]] {{.*}} : tensor<8x8xf32> into tensor<64xf32> |
There was a problem hiding this comment.
Is CHECK-DAG necessary here ? wouldn't CHECK be better ?
| func.func @func_slice1(%arg0: !migraphx.shaped<1x36x384x64xf32, 884736x24576x64x1>) -> !migraphx.shaped<1x12x384x64xf32, 294912x24576x64x1> attributes{kernel, arch = ""} { | ||
| %0 = migraphx.slice %arg0 {axes = [1], ends = [12], starts = [0]} : <1x36x384x64xf32, 884736x24576x64x1> -> <1x12x384x64xf32, 294912x24576x64x1> | ||
| return %0 : !migraphx.shaped<1x12x384x64xf32, 294912x24576x64x1> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @func_slice2 | ||
| // CHECK: tensor.extract_slice {{.*}}[0, 0, 184, 0] [1, 12, 100, 64] [1, 1, 1, 1] : tensor<1x36x384x64xf32> to tensor<1x12x100x64xf32> | ||
| func.func @func_slice2(%arg0: !migraphx.shaped<1x36x384x64xf32, 884736x24576x64x1>) -> !migraphx.shaped<1x12x100x64xf32, 76800x6400x64x1> attributes{kernel, arch = ""} { | ||
| %0 = migraphx.slice %arg0 {axes = [1, 2], ends = [12, 284], starts = [0, 184]} : <1x36x384x64xf32, 884736x24576x64x1> -> <1x12x100x64xf32, 76800x6400x64x1> | ||
| return %0 : !migraphx.shaped<1x12x100x64xf32, 76800x6400x64x1> |
There was a problem hiding this comment.
FYI - This testcase comes from tosa pass
37a8cf1 to
284c020
Compare
284c020 to
d397d5a
Compare
fc70bcb to
2cea6ef
Compare
f68bda2 to
d6a1e4d
Compare
| int64_t axisStartInt = cast<IntegerAttr>(axisS).getInt(); | ||
| int64_t axisEndInt = cast<IntegerAttr>(axisE).getInt(); |
There was a problem hiding this comment.
Right now it looks like we are assuming that start and end are non-negative and in-bounds. ONNX semantics allows for negative indices in slicing, so check with the MIGraphX folks (or in their source code) if this is something that they support as well.
There was a problem hiding this comment.
Also, once you have this information, can you add a verifier for the migraphx.slice op? I don't think it currently has one.
There was a problem hiding this comment.
Looking over the MIGraphX codebase, I believe the normalize_pass will transform those attribute into positive values.
There is also no negative values to my understanding of migraphx.slice. I am going to add the following as invariant:
- axes, start, end is the same size
- input and output is the same rank
- all attribute is non negative
- axis is small than input rank
- start is less than end
- end is less than input shape (prevent out of bound access)
- input + attribute infers output shape
There was a problem hiding this comment.
If we don't take negative values, then just make sure that we error out when we detect those.
umangyadav
left a comment
There was a problem hiding this comment.
Make sure to address justin's comments before merging.
It would be good to enable one E2E test with slice
b806ece to
ba4fcb0
Compare
16a5163 to
6622c52
Compare
Motivation
It is known that around 70 traces in fusion zoo requires the support of
migraphx.slice. Currently, 67.6% of the trace that cannot be compiled is known to havemigraphx.slicein them.Technical Details
Essentially transfer the attribute from
migraphx.sliceintotensor.extract_slice. The size attribute from tensor.extract_slice comes from subtract the end and start attribute from migraphx.slice (note that end is not included in the dimension). The stride is always one in this case.The code structure should look like the one found in
MIGraphXToTosa.cpp[here].Test Plan
Added a lit test
Test Result
Pass lit test.
Submission Checklist