11// RUN: onnx-mlir-opt --shape-inference --convert-onnx-to-tosa -cse %s -split-input-file | FileCheck %s
2+ // RUN: onnx-mlir-opt --shape-inference --convert-onnx-to-tosa="convert-slice-only-when-step-one=true" -cse %s -split-input-file | FileCheck %s --check-prefix=ONLY-STEP1
23
34
45func.func @test_slice_constant_default_steps (%arg0 : tensor <2 x4 xf32 >) -> tensor <1 x3 xf32 > {
@@ -74,6 +75,9 @@ func.func @slice_just_steps(%arg0: tensor<100x200xf32>) -> tensor<20x20xf32> {
7475// CHECK: %2 = tosa.reshape %1 {new_shape = array<i64: 20, 20>} : (tensor<20x1x20x1xf32>) -> tensor<20x20xf32>
7576// CHECK: return %2 : tensor<20x20xf32>
7677
78+ // ONLY-STEP1-LABEL: func @slice_just_steps
79+ // ONLY-STEP1: tosa.slice
80+
7781// -----
7882
7983func.func @slice_steps_and_edges (%arg0: tensor <100 x200 xf32 >) -> tensor <16 x17 xf32 > {
@@ -91,6 +95,9 @@ func.func @slice_steps_and_edges(%arg0: tensor<100x200xf32>) -> tensor<16x17xf32
9195// CHECK: %3 = tosa.reshape %2 {new_shape = array<i64: 16, 17>} : (tensor<16x1x17x1xf32>) -> tensor<16x17xf32>
9296// CHECK: return %3 : tensor<16x17xf32>
9397
98+ // ONLY-STEP1-LABEL: func @slice_steps_and_edges
99+ // ONLY-STEP1: tosa.slice
100+
94101// -----
95102
96103func.func @slice_steps_and_edges_with_padding (%arg0: tensor <99 x195 xf32 >) -> tensor <19 x19 xf32 > {
@@ -111,6 +118,9 @@ func.func @slice_steps_and_edges_with_padding(%arg0: tensor<99x195xf32>) -> tens
111118// CHECK: %6 = tosa.reshape %5 {new_shape = array<i64: 19, 19>} : (tensor<19x1x19x1xf32>) -> tensor<19x19xf32>
112119// CHECK: return %6 : tensor<19x19xf32>
113120
121+ // ONLY-STEP1-LABEL: func @slice_steps_and_edges_with_padding
122+ // ONLY-STEP1: tosa.slice
123+
114124// -----
115125
116126func.func @slice_just_steps_with_padding (%arg0: tensor <99 x195 xf32 >) -> tensor <20 x20 xf32 > {
@@ -130,6 +140,9 @@ func.func @slice_just_steps_with_padding(%arg0: tensor<99x195xf32>) -> tensor<20
130140// CHECK: %5 = tosa.reshape %4 {new_shape = array<i64: 20, 20>} : (tensor<20x1x20x1xf32>) -> tensor<20x20xf32>
131141// CHECK: return %5 : tensor<20x20xf32>
132142
143+ // ONLY-STEP1-LABEL: func @slice_just_steps_with_padding
144+ // ONLY-STEP1: tosa.slice
145+
133146// -----
134147
135148func.func @slice_negative_steps (%arg0: tensor <100 x200 xf32 >) -> tensor <20 x20 xf32 > {
@@ -195,3 +208,25 @@ func.func @slice_4d(%arg0: tensor<1x56x56x92xf32>) -> tensor<1x28x28x92xf32> {
195208// CHECK: %5 = tosa.slice %4 {size = array<i64: 1, 28, 1, 28, 1, 92>, start = array<i64: 0, 0, 0, 0, 0, 0>} : (tensor<1x28x2x28x2x92xf32>) -> tensor<1x28x1x28x1x92xf32>
196209// CHECK: %6 = tosa.reshape %5 {new_shape = array<i64: 1, 28, 28, 92>} : (tensor<1x28x1x28x1x92xf32>) -> tensor<1x28x28x92xf32>
197210// CHECK: return %6 : tensor<1x28x28x92xf32>
211+
212+ // ONLY-STEP1-LABEL: func @slice_4d
213+ // ONLY-STEP1: tosa.slice
214+
215+ // -----
216+
217+ func.func @slice_4d_step2_1sliced_dim (%arg0: tensor <1 x3 x640 x640 xbf16 >) -> tensor <1 x3 x320 x640 xbf16 > {
218+ %starts = " tosa.const" () <{value = dense <0 > : tensor <1 xi64 >}> : () -> tensor <1 xi64 >
219+ %ends = " tosa.const" () <{value = dense <9223372036854775807 > : tensor <1 xi64 >}> : () -> tensor <1 xi64 >
220+ %axes_steps = " tosa.const" () <{value = dense <2 > : tensor <1 xi64 >}> : () -> tensor <1 xi64 >
221+ %3 = " onnx.Slice" (%arg0 , %starts , %ends , %axes_steps , %axes_steps ) : (tensor <1 x3 x640 x640 xbf16 >, tensor <1 xi64 >, tensor <1 xi64 >, tensor <1 xi64 >, tensor <1 xi64 >) -> tensor <1 x3 x320 x640 xbf16 >
222+ return %3 : tensor <1 x3 x320 x640 xbf16 >
223+ }
224+ // CHECK-LABEL: func @slice_4d_step2_1sliced_dim
225+ // CHECK-SAME: (%[[ARG_0:.*]]: tensor<1x3x640x640xbf16>) -> tensor<1x3x320x640xbf16>
226+ // CHECK: %[[VAL_0:.*]] = tosa.reshape %[[ARG_0]] {new_shape = array<i64: 1, 3, 320, 2, 640>} : (tensor<1x3x640x640xbf16>) -> tensor<1x3x320x2x640xbf16>
227+ // CHECK: %[[VAL_1:.*]] = tosa.slice %[[VAL_0]] {size = array<i64: 1, 3, 320, 1, 640>, start = array<i64: 0, 0, 0, 0, 0>} : (tensor<1x3x320x2x640xbf16>) -> tensor<1x3x320x1x640xbf16>
228+ // CHECK: %[[VAL_2:.*]] = tosa.reshape %[[VAL_1]] {new_shape = array<i64: 1, 3, 320, 640>} : (tensor<1x3x320x1x640xbf16>) -> tensor<1x3x320x640xbf16>
229+ // CHECK: return %[[VAL_2]] : tensor<1x3x320x640xbf16>
230+
231+ // ONLY-STEP1-LABEL: func @slice_4d_step2_1sliced_dim
232+ // ONLY-STEP1-NOT: tosa.slice
0 commit comments