Skip to content

Commit e244c52

Browse files
committed
[AutoBump] Merge with fixes of 7208649 (Dec 04)
2 parents 19f895e + 7208649 commit e244c52

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

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

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,22 +1893,23 @@ def Tosa_RescaleOp: Tosa_Op<"rescale", [Pure,
18931893
let description = [{
18941894
Rescale quantized values into a new domain. Supported rescalings are:
18951895

1896-
| Mode | Input | Output |
1897-
|------------------------|-------|--------|
1898-
| signed 8 to 8 | int8 | int8 |
1899-
| signed 8 to 16 | int8 | int16 |
1900-
| signed 8 to 32 | int8 | int32 |
1901-
| signed 16 to 8 | int16 | int8 |
1902-
| signed 16 to 16 | int16 | int16 |
1903-
| signed 16 to 32 | int16 | int32 |
1904-
| signed 32 to 8 | int32 | int8 |
1905-
| signed 32 to 16 | int32 | int16 |
1906-
| signed 32 to 32 | int32 | int32 |
1907-
| signed 48 to 8 | int48 | int8 |
1908-
| signed 48 to 16 | int48 | int16 |
1909-
| signed 48 to 32 | int48 | int32 |
1910-
| unsigned 8 to signed 8 | uint8 | int8 |
1911-
| signed 8 to unsigned 8 | int8 | uint8 |
1896+
| Mode | Input | Output | Unsigned | Unsigned |
1897+
| | | | input | output |
1898+
|------------------------|-------|--------|----------|----------|
1899+
| signed 8 to 8 | int8 | int8 | false | false |
1900+
| signed 8 to 16 | int8 | int16 | false | false |
1901+
| signed 8 to 32 | int8 | int32 | false | false |
1902+
| signed 16 to 8 | int16 | int8 | false | false |
1903+
| signed 16 to 16 | int16 | int16 | false | false |
1904+
| signed 16 to 32 | int16 | int32 | false | false |
1905+
| signed 32 to 8 | int32 | int8 | false | false |
1906+
| signed 32 to 16 | int32 | int16 | false | false |
1907+
| signed 32 to 32 | int32 | int32 | false | false |
1908+
| signed 48 to 8 | int48 | int8 | false | false |
1909+
| signed 48 to 16 | int48 | int16 | false | false |
1910+
| signed 48 to 32 | int48 | int32 | false | false |
1911+
| unsigned 8 to signed 8 | uint8 | int8 | true | false |
1912+
| signed 8 to unsigned 8 | int8 | uint8 | false | true |
19121913
}];
19131914

19141915
let arguments = (ins
@@ -1919,13 +1920,33 @@ def Tosa_RescaleOp: Tosa_Op<"rescale", [Pure,
19191920
DenseI8ArrayAttr:$shift,
19201921
BoolAttr:$scale32,
19211922
BoolAttr:$double_round,
1922-
BoolAttr:$per_channel
1923+
BoolAttr:$per_channel,
1924+
DefaultValuedOptionalAttr<BoolAttr, "false">:$input_unsigned,
1925+
DefaultValuedOptionalAttr<BoolAttr, "false">:$output_unsigned
19231926
);
19241927

19251928
let results = (outs
19261929
Tosa_Tensor:$output
19271930
);
19281931

1932+
// Custom builder that does not require optional input_unsigned and
1933+
// output_unsigned.
1934+
let builders = [
1935+
OpBuilder<(ins "::mlir::Type":$output,
1936+
"::mlir::Value":$input,
1937+
"::mlir::IntegerAttr":$input_zp,
1938+
"::mlir::IntegerAttr":$output_zp,
1939+
"::mlir::DenseI32ArrayAttr":$multiplier,
1940+
"::mlir::DenseI8ArrayAttr":$shift,
1941+
"::mlir::BoolAttr":$scale32,
1942+
"::mlir::BoolAttr":$double_round,
1943+
"::mlir::BoolAttr":$per_channel), [{
1944+
auto FalseAttr = BoolAttr::get($_builder.getContext(), false);
1945+
build($_builder, $_state, output, input, input_zp, output_zp, multiplier,
1946+
shift, scale32, double_round, per_channel, FalseAttr, FalseAttr);
1947+
}]>
1948+
];
1949+
19291950
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
19301951
}
19311952

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,9 +1264,6 @@ class RescaleConverter : public OpConversionPattern<tosa::RescaleOp> {
12641264
if (!outputTy) {
12651265
return rewriter.notifyMatchFailure(op, "unable to convert type");
12661266
}
1267-
bool inputAsUnsigned =
1268-
op.getInput().getType().getElementType().isUnsignedInteger();
1269-
bool outputAsUnsigned = op.getType().getElementType().isUnsignedInteger();
12701267
unsigned rank = inputTy.getRank();
12711268

12721269
// This is an illegal configuration. terminate and log an error
@@ -1382,7 +1379,7 @@ class RescaleConverter : public OpConversionPattern<tosa::RescaleOp> {
13821379
Value shift = shiftConstant ? shiftConstant : blockArgs[shiftArg];
13831380

13841381
if (valueTy.getIntOrFloatBitWidth() < 32) {
1385-
if (inputAsUnsigned) {
1382+
if (op.getInputUnsigned()) {
13861383
value = nestedBuilder.create<arith::ExtUIOp>(
13871384
nestedLoc, nestedBuilder.getI32Type(), value);
13881385
} else {
@@ -1411,7 +1408,7 @@ class RescaleConverter : public OpConversionPattern<tosa::RescaleOp> {
14111408
int32_t intMax = APInt::getSignedMaxValue(outBitWidth).getSExtValue();
14121409

14131410
// Unsigned integers have a difference output value.
1414-
if (outputAsUnsigned) {
1411+
if (op.getOutputUnsigned()) {
14151412
intMin = 0;
14161413
intMax = APInt::getMaxValue(outBitWidth).getZExtValue();
14171414
}

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,16 @@ func.func @rescale_i8(%arg0 : tensor<2xi8>) -> () {
12221222
// CHECK-DAG: linalg.yield [[TRUNC]]
12231223
%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>
12241224

1225+
// CHECK: return
1226+
return
1227+
}
1228+
1229+
// -----
1230+
// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>
1231+
1232+
// CHECK-LABEL: @rescale_i8_unsigned_output
1233+
// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:
1234+
func.func @rescale_i8_unsigned_output(%arg0 : tensor<2xi8>) -> () {
12251235
// CHECK: [[C0:%.+]] = arith.constant 19689
12261236
// CHECK: [[C1:%.+]] = arith.constant 15
12271237
// CHECK: [[INIT:%.+]] = tensor.empty()
@@ -1239,7 +1249,7 @@ func.func @rescale_i8(%arg0 : tensor<2xi8>) -> () {
12391249
// CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]
12401250
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
12411251
// CHECK: linalg.yield [[TRUNC]]
1242-
%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>
1252+
%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, output_unsigned = true} : (tensor<2xi8>) -> tensor<2xi8>
12431253

12441254
// CHECK: return
12451255
return
@@ -1262,7 +1272,7 @@ func.func @rescale_i8_dyn_batch(%arg0 : tensor<?x2xi8>) -> () {
12621272
// CHECK: %[[BATCH:.+]] = tensor.dim %[[ARG0]], %[[C0]]
12631273
// CHECK: %[[INIT:.+]] = tensor.empty(%[[BATCH]]) : tensor<?x2xi8>
12641274
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%[[ARG0]] : tensor<?x2xi8>) outs(%[[INIT]] : tensor<?x2xi8>)
1265-
%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>
1275+
%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, output_unsigned = true} : (tensor<?x2xi8>) -> tensor<?x2xi8>
12661276

12671277
return
12681278
}
@@ -1288,9 +1298,9 @@ func.func @rescale_dyn(%arg0 : tensor<1x?x?x32xi32>) -> () {
12881298

12891299
// CHECK: #[[$MAP0:.*]] = affine_map<(d0) -> (d0)>
12901300

1291-
// CHECK-LABEL: @rescale_ui8
1301+
// CHECK-LABEL: @rescale_i8_unsigned_input
12921302
// CHECK-SAME: (%[[ARG0:[0-9a-zA-Z_]*]]:
1293-
func.func @rescale_ui8(%arg0 : tensor<2xui8>) -> () {
1303+
func.func @rescale_i8_unsigned_input(%arg0 : tensor<2xi8>) -> () {
12941304
// CHECK: [[C0:%.+]] = arith.constant 19689
12951305
// CHECK: [[C1:%.+]] = arith.constant 15
12961306
// CHECK: [[INIT:%.+]] = tensor.empty()
@@ -1308,7 +1318,7 @@ func.func @rescale_ui8(%arg0 : tensor<2xui8>) -> () {
13081318
// CHECK-DAG: [[BOUNDED:%.+]] = arith.minsi [[CMAX]], [[LOWER]]
13091319
// CHECK-DAG: [[TRUNC:%.+]] = arith.trunci [[BOUNDED]]
13101320
// CHECK: linalg.yield [[TRUNC]]
1311-
%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>
1321+
%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, input_unsigned = true} : (tensor<2xi8>) -> tensor<2xi8>
13121322

13131323
return
13141324
}

0 commit comments

Comments
 (0)