Skip to content

Commit 7ea6688

Browse files
committed
Revert "[mlir][tosa]Fix Rescale shift attr data type (llvm#71084)"
This reverts commit af78e5d.
1 parent 0cb024b commit 7ea6688

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ def Tosa_RescaleOp: Tosa_Op<"rescale", [Pure,
18481848
I32Attr:$input_zp,
18491849
I32Attr:$output_zp,
18501850
DenseI32ArrayAttr:$multiplier,
1851-
DenseI8ArrayAttr:$shift,
1851+
DenseI32ArrayAttr:$shift,
18521852
BoolAttr:$scale32,
18531853
BoolAttr:$double_round,
18541854
BoolAttr:$per_channel

mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func.func @test_add_0d(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {
9393
// CHECK: linalg.yield [[ADDF]] : f32
9494
// CHECK: } -> tensor<f32>
9595
%0 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>
96-
96+
9797
// CHECK: return [[RESULT]] : tensor<f32>
9898
return %0 : tensor<f32>
9999
}
@@ -223,7 +223,7 @@ func.func @test_add_1d_broadcast_static_to_static(%arg0: tensor<1xf32>, %arg1: t
223223
// CHECK: linalg.yield %[[VAL_4]] : f32
224224
// CHECK: } -> tensor<3xf32>
225225
%0 = tosa.add %arg0, %arg1 : (tensor<1xf32>, tensor<3xf32>) -> tensor<3xf32>
226-
226+
227227
// CHECK: return %[[RESULT]] : tensor<3xf32>
228228
return %0 : tensor<3xf32>
229229
}
@@ -352,7 +352,7 @@ func.func @test_add_2d_different_ranks(%arg0: tensor<3x4xf32>, %arg1: tensor<2x3
352352
// CHECK: linalg.yield %[[VAL_4]] : f32
353353
// CHECK: } -> tensor<2x3x4xf32>
354354
%0 = tosa.add %arg0, %arg1 : (tensor<3x4xf32>, tensor<2x3x4xf32>) -> tensor<2x3x4xf32>
355-
355+
356356
// CHECK: return %[[RESULT]] : tensor<2x3x4xf32>
357357
return %0 : tensor<2x3x4xf32>
358358
}
@@ -1057,7 +1057,7 @@ func.func @rescale_i8(%arg0 : tensor<2xi8>) -> () {
10571057
// CHECK-DAG: [[BOUNDED:%.+]] = arith.select [[MAXLT]], [[CMAX]], [[LOWER]]
10581058
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
10591059
// CHECK-DAG: linalg.yield [[TRUNC]]
1060-
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
1060+
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
10611061

10621062
// CHECK: [[C0:%.+]] = arith.constant 19689
10631063
// CHECK: [[C1:%.+]] = arith.constant 15
@@ -1079,7 +1079,7 @@ func.func @rescale_i8(%arg0 : tensor<2xi8>) -> () {
10791079
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
10801080
// CHECK-DAG: [[CAST:%.+]] = builtin.unrealized_conversion_cast [[TRUNC]] : i8 to ui8
10811081
// CHECK: linalg.yield [[CAST]]
1082-
%1 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xi8>) -> tensor<2xui8>
1082+
%1 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xi8>) -> tensor<2xui8>
10831083

10841084
// CHECK: return
10851085
return
@@ -1096,13 +1096,13 @@ func.func @rescale_i8_dyn_batch(%arg0 : tensor<?x2xi8>) -> () {
10961096
// CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]
10971097
// CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]]) : tensor<?x2xi8>
10981098
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x2xi8>) outs(%[[INIT]] : tensor<?x2xi8>)
1099-
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<?x2xi8>) -> tensor<?x2xi8>
1099+
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<?x2xi8>) -> tensor<?x2xi8>
11001100

11011101
// CHECK: %[[C0:.+]] = arith.constant 0
11021102
// CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]
11031103
// CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]]) : tensor<?x2xui8>
11041104
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x2xi8>) outs(%[[INIT]] : tensor<?x2xui8>)
1105-
%1 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<?x2xi8>) -> tensor<?x2xui8>
1105+
%1 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<?x2xi8>) -> tensor<?x2xui8>
11061106

11071107
return
11081108
}
@@ -1120,7 +1120,7 @@ func.func @rescale_dyn(%arg0 : tensor<1x?x?x32xi32>) -> () {
11201120
// CHECK: %[[DIM2:.+]] = tensor.dim %[[ARG0]], %[[C2]]
11211121
// CHECK: %[[INIT:.+]] = tensor.empty(%[[DIM1]], %[[DIM2]])
11221122
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP1]], #[[$MAP1]]], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[ARG0]] : tensor<1x?x?x32xi32>) outs(%[[INIT]] : tensor<1x?x?x32xi8>)
1123-
%0 = tosa.rescale %arg0 {double_round = true, input_zp = 0 : i32, multiplier = array<i32: 1376784203>, output_zp = 0 : i32, per_channel = false, scale32 = true, shift = array<i8: 38>} : (tensor<1x?x?x32xi32>) -> tensor<1x?x?x32xi8>
1123+
%0 = tosa.rescale %arg0 {double_round = true, input_zp = 0 : i32, multiplier = array<i32: 1376784203>, output_zp = 0 : i32, per_channel = false, scale32 = true, shift = array<i32: 38>} : (tensor<1x?x?x32xi32>) -> tensor<1x?x?x32xi8>
11241124
return
11251125
}
11261126

@@ -1151,7 +1151,7 @@ func.func @rescale_ui8(%arg0 : tensor<2xui8>) -> () {
11511151
// CHECK-DAG: [[BOUNDED:%.+]] = arith.select [[MAXLT]], [[CMAX]], [[LOWER]]
11521152
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
11531153
// CHECK: linalg.yield [[TRUNC]]
1154-
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xui8>) -> tensor<2xi8>
1154+
%0 = tosa.rescale %arg0 {input_zp = 17 : i32, output_zp = 22 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<2xui8>) -> tensor<2xi8>
11551155

11561156
return
11571157
}
@@ -1183,7 +1183,7 @@ func.func @rescale_per_channel(%arg0 : tensor<3xi8>) -> (tensor<3xi8>) {
11831183
// CHECK-DAG: [[BOUNDED:%.+]] = arith.select [[MAXLT]], [[CMAX]], [[LOWER]]
11841184
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
11851185
// CHECK-DAG: linalg.yield [[TRUNC]]
1186-
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 42, 43, 44>, shift = array<i8: 14, 15, 64>, scale32 = false, double_round = false, per_channel = false} : (tensor<3xi8>) -> tensor<3xi8>
1186+
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 42, 43, 44>, shift = array<i32: 14, 15, 64>, scale32 = false, double_round = false, per_channel = false} : (tensor<3xi8>) -> tensor<3xi8>
11871187

11881188
// CHECK: return [[GENERIC]]
11891189
return %0 : tensor<3xi8>
@@ -1194,18 +1194,18 @@ func.func @rescale_per_channel(%arg0 : tensor<3xi8>) -> (tensor<3xi8>) {
11941194
// CHECK-LABEL: @rescaleDoubleRound
11951195
func.func @rescaleDoubleRound(%arg0 : tensor<2xi8>) -> (tensor<2xi8>) {
11961196
// CHECK: linalg.generic
1197-
// CHECK: tosa.apply_scale
1197+
// CHECK: tosa.apply_scale
11981198
// CHECK-SAME: {double_round = true}
1199-
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 19689>, shift = array<i8: 33>, scale32 = true, double_round = true, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
1199+
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 19689>, shift = array<i32: 33>, scale32 = true, double_round = true, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
12001200
return %0 : tensor<2xi8>
12011201
}
12021202

12031203
// CHECK-LABEL: @rescaleUnnecessaryDoubleRound
12041204
func.func @rescaleUnnecessaryDoubleRound(%arg0 : tensor<2xi8>) -> (tensor<2xi8>) {
12051205
// CHECK: linalg.generic
1206-
// CHECK: tosa.apply_scale
1206+
// CHECK: tosa.apply_scale
12071207
// CHECK-SAME: {double_round = false}
1208-
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 19689>, shift = array<i8: 15>, scale32 = true, double_round = true, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
1208+
%0 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 19689>, shift = array<i32: 15>, scale32 = true, double_round = true, per_channel = false} : (tensor<2xi8>) -> tensor<2xi8>
12091209
return %0 : tensor<2xi8>
12101210
}
12111211

mlir/test/Dialect/Tosa/ops.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func.func @test_conv2d_q8xi4(%arg0: tensor<1x11x11x3xi8>) -> tensor<1x1x1x3xi8>
6464
%0 = "tosa.const"() {value = dense<0> : tensor<3x11x11x3xi4>} : () -> tensor<3x11x11x3xi4>
6565
%1 = "tosa.const"() {value = dense<[12, 23, 55]> : tensor<3xi32>} : () -> tensor<3xi32>
6666
%2 = "tosa.conv2d"(%arg0, %0, %1) {dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>, stride = array<i64: 1, 1>} : (tensor<1x11x11x3xi8>, tensor<3x11x11x3xi4>, tensor<3xi32>) -> tensor<1x1x1x3xi32>
67-
%3 = "tosa.rescale"(%2) {double_round = true, input_zp = 0 : i32, multiplier = array<i32: 2026291432, 1079222024, 1693132724>, output_zp = 27 : i32, per_channel = true, scale32 = true, shift = array<i8: 37, 36, 37>} : (tensor<1x1x1x3xi32>) -> tensor<1x1x1x3xi8>
67+
%3 = "tosa.rescale"(%2) {double_round = true, input_zp = 0 : i32, multiplier = array<i32: 2026291432, 1079222024, 1693132724>, output_zp = 27 : i32, per_channel = true, scale32 = true, shift = array<i32: 37, 36, 37>} : (tensor<1x1x1x3xi32>) -> tensor<1x1x1x3xi8>
6868
return %3 : tensor<1x1x1x3xi8>
6969
}
7070

@@ -604,7 +604,7 @@ func.func @test_cast3(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.unifo
604604
// -----
605605
// CHECK-LABEL: rescale
606606
func.func @test_rescale(%arg0: tensor<13x21x3x!quant.uniform<u8:f32, 0.015655439347028732:127>>) -> tensor<13x21x3x!quant.uniform<i8:f32, 0.015655439347028732:-1>> {
607-
%0 = tosa.rescale %arg0 {double_round = false, input_zp = 127 : i32, multiplier = array<i32: 1073741824>, output_zp = -1 : i32, per_channel = false, scale32 = true, shift = array<i8: 30>} : (tensor<13x21x3x!quant.uniform<u8:f32, 0.015655439347028732:127>>) -> tensor<13x21x3x!quant.uniform<i8:f32, 0.015655439347028732:-1>>
607+
%0 = tosa.rescale %arg0 {double_round = false, input_zp = 127 : i32, multiplier = array<i32: 1073741824>, output_zp = -1 : i32, per_channel = false, scale32 = true, shift = array<i32: 30>} : (tensor<13x21x3x!quant.uniform<u8:f32, 0.015655439347028732:127>>) -> tensor<13x21x3x!quant.uniform<i8:f32, 0.015655439347028732:-1>>
608608
return %0 : tensor<13x21x3x!quant.uniform<i8:f32, 0.015655439347028732:-1>>
609609
}
610610

mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func.func @test_unary_i32(%arg0 : tensor<4xi32>) -> () {
9494
%5 = tosa.reverse %arg0 { axis = 0 : i32 } : (tensor<4xi32>) -> tensor<?xi32>
9595

9696
// CHECK: tosa.rescale %arg0 {{.+}} : (tensor<4xi32>) -> tensor<4xi16>
97-
%6 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 42, 43>, shift = array<i8: 14, 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<4xi32>) -> tensor<*xi16>
97+
%6 = tosa.rescale %arg0 {input_zp = 243 : i32, output_zp = 252 : i32, multiplier = array<i32: 42, 43>, shift = array<i32: 14, 15>, scale32 = false, double_round = false, per_channel = false} : (tensor<4xi32>) -> tensor<*xi16>
9898

9999
// CHECK: tosa.identity %arg0 : (tensor<4xi32>) -> tensor<4xi32>
100100
%7 = tosa.identity %arg0 : (tensor<4xi32>) -> tensor<?xi32>

mlir/test/lib/Dialect/Tosa/TosaTestPasses.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ ConvertTosaConv2DOp::matchAndRewrite(Operation *op,
169169
op->getLoc(), outputType, newTosaConv2DOp.getResult(),
170170
rewriter.getI32IntegerAttr(0), rewriter.getI32IntegerAttr(outputZp),
171171
rewriter.getDenseI32ArrayAttr({multiplier}),
172-
rewriter.getDenseI8ArrayAttr({static_cast<int8_t>(shift)}),
173-
rewriter.getBoolAttr(true), rewriter.getBoolAttr(true),
174-
rewriter.getBoolAttr(false));
172+
rewriter.getDenseI32ArrayAttr({shift}), rewriter.getBoolAttr(true),
173+
rewriter.getBoolAttr(true), rewriter.getBoolAttr(false));
175174

176175
rewriter.replaceOp(op, {newTosaRescaleOp.getResult()});
177176
return success();

0 commit comments

Comments
 (0)