Skip to content

[AIROCMLIR-599] Lower migraphx.slice into tensor.slice#2281

Open
Mr-Anyone wants to merge 3 commits intodevelopfrom
pr-migraphx-slice
Open

[AIROCMLIR-599] Lower migraphx.slice into tensor.slice#2281
Mr-Anyone wants to merge 3 commits intodevelopfrom
pr-migraphx-slice

Conversation

@Mr-Anyone
Copy link
Member

@Mr-Anyone Mr-Anyone commented Mar 11, 2026

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 have migraphx.slice in them.

Technical Details

Essentially transfer the attribute from migraphx.slice into tensor.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

@Mr-Anyone Mr-Anyone requested a review from causten as a code owner March 11, 2026 19:22
@Mr-Anyone
Copy link
Member Author

The models are the following, and can be found here:

models/ORT/onnx_models/bert_base_cased_1/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_softmax_slice_reshape_transpose_dot_1x12x384x64s294912x64x768x1_1x12x64x384s294912x64x1x768_1x12x384x384_1x12x384x64s294912x64x768x1.mxr
models/ORT/onnx_models/bert_large_uncased_1_fp16_gpu/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_softmax_slice_reshape_transpose_dot_1x16x384x64s393216x64x1024x1_1x16x64x384s393216x64x1x1024_1x16x384x384_1x16x384x64s393216x64x1024x1.mxr
models/bert/bert-large-uncased/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_softmax_slice_reshape_transpose_dot_32x16x32x64s32768x64x1024x1_32x16x64x32s32768x64x1x1024_32x16x32x32_32x16x32x64s32768x64x1024x1.mxr
models/bert/bertsquad-12/mlir_first/mxr/mlir_slice_reshape_add_slice_reshape_add_slice_reshape_add_reshape_transpose_reshape_transpose_dot_mul_add_softmax_reshape_transpose_dot_1x12x256x64s196608x64x768x1_1x12x64x256s196608x64x1x768_1x12x256x256_1x12x256x64s196608x64x768x1.mxr
models/bert/bertsquad-12/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_softmax_slice_reshape_transpose_dot_1x12x256x64s196608x64x768x1_1x12x64x256s196608x64x1x768_1x12x256x256_1x12x256x64s196608x64x768x1.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_16x384x8x8s49152x64x8x1_256x384x1x3.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_16x192x17x17s110976x289x17x1_192x192x7x1.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_16x192x17x17s110976x289x17x1_224x192x1x7.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_16x384x8x8s49152x64x8x1_256x384x1x3.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_16x384x8x8s49152x64x8x1_448x384x3x1.mxr
models/cadene/inceptionv4i16/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_16x64x73x73s682112x5329x73x1_64x64x1x7.mxr
models/cadene/resnext101_64x4di1/mlir_first/mxr/mlir_convolution_slice_broadcast_add_add_relu_1x256x56x56_256x256x1x1.mxr
models/cadene/resnext101_64x4di1/mlir_first/mxr/mlir_slice_broadcast_add_relu_convolution_broadcast_add_relu_1x256x56x56_256x4x3x3.mxr
models/cadene/resnext101_64x4di16/mlir_first/mxr/mlir_convolution_slice_broadcast_add_add_relu_16x256x56x56_256x256x1x1.mxr
models/cadene/resnext101_64x4di16/mlir_first/mxr/mlir_slice_broadcast_add_relu_convolution_broadcast_add_relu_16x256x56x56_256x4x3x3.mxr
models/huggingface-transformers/bert_mrpc8/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_softmax_slice_reshape_transpose_dot_8x12x128x64s98304x64x768x1_8x12x64x128s98304x64x1x768_8x12x128x128_8x12x128x64s98304x64x768x1.mxr
models/llama2-13b/decoder_model/mlir_first/mxr/mlir_slice_reshape_transpose_dot_1x40x1x1_1x40x1x128.mxr
models/llama2-13b/decoder_model/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_sub_exp_div_1x40x1x128_1x40x128x1.mxr
models/llama2_7b/decoder_model/mlir_first/mxr/mlir_slice_reshape_transpose_dot_1x32x1x1_1x32x1x128.mxr
models/llama2_7b/decoder_model/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_sub_exp_div_1x32x1x128_1x32x128x1.mxr
models/llama3_8b/model/mlir_first/mxr/mlir_slice_reshape_transpose_reshape_dot_1x32x1x1_1x32x1x128.mxr
models/llama3_8b/model/mlir_first/mxr/mlir_unsqueeze_slice_reshape_transpose_unsqueeze_mul_mul_add_mul_unsqueeze_transpose_reshape_mul_dot_add_sub_exp_div_1x32x1x128_1x32x128x1.mxr
models/mlperf/bert_large_mlperf/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_softmax_slice_reshape_transpose_dot_1x16x384x64s393216x64x1024x1_1x16x64x384s393216x64x1x1024_1x16x384x384_1x16x384x64s393216x64x1024x1.mxr
models/onnx-model-zoo/gpt2-10/mlir_first/mxr/mlir_slice_reshape_transpose_dot_1x12x1x1_1x12x1x64.mxr
models/onnx-model-zoo/gpt2-10/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_sub_exp_div_1x12x1x64_1x12x64x1.mxr
models/pytorch-examples/wlang_gru/mlir_first/mxr/mlir_slice_squeeze_dot_add_1x200_200x600s1x200.mxr
models/pytorch-examples/wlang_gru/mlir_first/mxr/mlir_squeeze_slice_squeeze_dot_add_1x200_200x600s1x200.mxr
models/sd/unet/model/mlir_first/mxr/mlir_add_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x256x64s327680x64x1280x1_2x20x64x64s81920x64x1x1280_40x256x64_40x64x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_add_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x64x64s81920x64x1280x1_2x20x64x64s81920x64x1x1280_40x64x64_40x64x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_add_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x256x64s327680x64x1280x1_2x20x64x256s327680x64x1x1280_40x256x256_40x256x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_add_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x64x64s81920x64x1280x1_2x20x64x64s81920x64x1x1280_40x64x64_40x64x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x10x1024x64s655360x64x640x1_2x10x64x64s40960x64x1x640_20x1024x64_20x64x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x5x4096x64s1310720x64x320x1_2x5x64x64s20480x64x1x320_10x4096x64_10x64x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x10x1024x64s655360x64x640x1_2x10x64x1024s655360x64x1x640_20x1024x1024_20x1024x64.mxr
models/sd/unet/model/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x5x4096x64s1310720x64x320x1_2x5x64x4096s1310720x64x1x320_10x4096x4096_10x4096x64.mxr
models/sdxl/unet/model/mlir_first/mxr/mlir_add_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x1024x64s1310720x64x1280x1_2x20x64x77s98560x64x1x1280_40x1024x77_40x77x64.mxr
models/sdxl/unet/model/mlir_first/mxr/mlir_add_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x20x1024x64s1310720x64x1280x1_2x20x64x1024s1310720x64x1x1280_40x1024x1024_40x1024x64.mxr
models/sdxl/unet/model/mlir_first/mxr/mlir_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x10x4096x64s2621440x64x640x1_2x10x64x77s49280x64x1x640_20x4096x77_20x77x64.mxr
models/sdxl/unet/model/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_reshape_mul_softmax_slice_reshape_transpose_reshape_dot_2x10x4096x64s2621440x64x640x1_2x10x64x4096s2621440x64x1x640_20x4096x4096_20x4096x64.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_1x384x8x8_256x384x1x3.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x192x17x17_192x192x7x1.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x192x17x17_224x192x1x7.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x384x8x8_256x384x1x3.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x384x8x8_448x384x3x1.mxr
models/slim/inceptionv4_i1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x64x73x73_64x64x1x7.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_add_64x168x42x42_168x168x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_add_64x336x21x21_336x336x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_add_64x672x11x11_672x672x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_broadcast_add_add_64x168x42x42_168x168x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_broadcast_add_add_64x336x21x21_336x336x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_convolution_slice_broadcast_add_add_64x672x11x11_672x672x1x1.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x168x42x42s592704x1764x42x1_168x1x3x3.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x168x42x42s592704x1764x42x1_168x1x5x5.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x336x21x21s296352x441x21x1_336x1x3x3.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x336x21x21s296352x441x21x1_336x1x5x5.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x672x11x11s162624x121x11x1_672x1x3x3.mxr
models/slim/nasnet_i64/mlir_first/mxr/mlir_slice_convolution_64x672x11x11s162624x121x11x1_672x1x5x5.mxr
models/tf-misc/bert_mrpc1/mlir_first/mxr/mlir_reshape_slice_squeeze_dot_add_tanh_1x768_768x768.mxr
models/tf-misc/bert_mrpc1/mlir_first/mxr/mlir_slice_reshape_transpose_slice_reshape_transpose_dot_mul_add_softmax_slice_reshape_transpose_dot_1x12x128x64s98304x64x768x1_1x12x64x128s98304x64x1x768_1x12x128x128_1x12x128x64s98304x64x768x1.mxr
models/torchvision/inceptioni1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x128x17x17_128x128x1x7.mxr
models/torchvision/inceptioni1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x128x17x17_128x128x7x1.mxr
models/torchvision/inceptioni1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x160x17x17_160x160x1x7.mxr
models/torchvision/inceptioni1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x160x17x17_160x160x7x1.mxr
models/torchvision/inceptioni1/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_1x192x17x17_192x192x1x7.mxr
models/torchvision/inceptioni32/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_32x128x17x17s73984x289x17x1_128x128x1x7.mxr
models/torchvision/inceptioni32/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_32x128x17x17s73984x289x17x1_128x128x7x1.mxr
models/torchvision/inceptioni32/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_32x160x17x17s92480x289x17x1_160x160x1x7.mxr
models/torchvision/inceptioni32/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_32x160x17x17s92480x289x17x1_160x160x7x1.mxr
models/torchvision/inceptioni32/mlir_first/mxr/mlir_slice_convolution_broadcast_add_relu_32x192x17x17s110976x289x17x1_192x192x1x7.mxr

Copy link
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

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 SliceConverter to lower migraphx.slice into tensor.extract_slice in the MIGraphX→Linalg conversion.
  • Add lit coverage for slice lowering and remove migraphx.slice from 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.

Comment on lines +275 to +277
// 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>
Copy link
Member

Choose a reason for hiding this comment

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

Is CHECK-DAG necessary here ? wouldn't CHECK be better ?

Copy link
Member

@umangyadav umangyadav left a comment

Choose a reason for hiding this comment

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

Looks good

Comment on lines +282 to +291
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>
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI - This testcase comes from tosa pass

@Mr-Anyone Mr-Anyone requested a review from umangyadav March 16, 2026 17:23
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.

3 participants