Skip to content

Commit 561ded2

Browse files
committed
[mlir][tosa] Change the shift of mul to be required
Set the shift to be a mandatory operand. Change-Id: Ic8f6e2f653c6f5875f8b789a2da27d2834aa442a Signed-off-by: Tai Ly <[email protected]>
1 parent ffe3129 commit 561ded2

File tree

12 files changed

+125
-62
lines changed

12 files changed

+125
-62
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ def Tosa_MulOp : Tosa_Op<"mul", [
812812
let arguments = (ins
813813
Tosa_Tensor:$input1,
814814
Tosa_Tensor:$input2,
815-
Optional<TosaTensorRankOf<[Tosa_Int8], [1]>>:$shift
815+
// Apply right shift on i32_t input data only
816+
Tosa_ScalarInt8Tensor:$shift
816817
);
817818

818819
let results = (outs

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def HasNo0Dimensions : And<[
9393
IsRankedTensorTypePred,
9494
CPred<"::llvm::all_of(::llvm::cast<::mlir::RankedTensorType>($_self).getShape(), [](auto v) { return v != 0; })">]>;
9595

96+
def AllDimensionsAreSizeOne : And<[
97+
IsRankedTensorTypePred,
98+
CPred<"::llvm::all_of(::llvm::cast<::mlir::RankedTensorType>($_self).getShape(), [](auto v) { return v == 1; })">]>;
99+
96100
class TosaTensorOf<
97101
list<Type> allowedTypes, string summary = "tosa-conformant tensor">
98102
: TensorOf<allowedTypes, [Or<[HasNo0Dimensions, IsUnrankedTensorTypePred]>], summary>;
@@ -109,6 +113,11 @@ class TosaTensorRankOf<list<Type> allowedTypes, list<int> ranks>
109113
[HasAnyRankOfPred<ranks>],
110114
!interleave(!foreach(rank, ranks, rank # "D"), "/") # " tensor">;
111115

116+
class TosaScalarTensorOf<list<Type> allowedTypes, list<int> ranks>
117+
: TosaRankedTensorOf<allowedTypes,
118+
[HasAnyRankOfPred<ranks>, AllDimensionsAreSizeOne],
119+
"tosa-conformant scalar tensor">;
120+
112121
//===----------------------------------------------------------------------===//
113122
// Tensor types
114123
//===----------------------------------------------------------------------===//
@@ -139,6 +148,9 @@ class Tosa_TensorOfOrNone<list<Type> allowedTypes, string description = ""> :
139148
// Rank-0 (scalar) tensor
140149
def Tosa_ScalarTensor : TosaTensorRankOf<[Tosa_AnyNumber], [0]>;
141150

151+
// Scalar tensors: Rank-1 (with only one element)
152+
def Tosa_ScalarInt8Tensor : TosaScalarTensorOf<[Tosa_Int8], [1]>;
153+
142154
// We include unranked tensors as a supported type for all possible tosa
143155
// Tensors as unranked does not guarantee invalid. If unranked tensors exist
144156
// they should be shape propagate used Tosa's shape inference pass and verified

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,27 @@ static Value createLinalgBodyCalculationForElementwiseOp(
9292
// tosa::MulOp
9393
if (isa<tosa::MulOp>(op)) {
9494
auto shift_val = cast<tosa::MulOp>(op).getShift();
95+
ElementsAttr shift_elem;
96+
if (!shift_val.getImpl() ||
97+
!matchPattern(shift_val, m_Constant(&shift_elem))) {
98+
(void)rewriter.notifyMatchFailure(op, "shift value of mul not found");
99+
}
100+
101+
int32_t shift = shift_elem.getValues<IntegerAttr>()[0].getInt();
95102

96103
if (isa<FloatType>(elementTy)) {
104+
if (shift != 0) {
105+
(void)rewriter.notifyMatchFailure(op,
106+
"Cannot have shift value for float");
107+
return nullptr;
108+
}
97109
return rewriter.create<arith::MulFOp>(loc, resultTypes, args[0], args[1]);
98110
}
99111

100112
if (isa<IntegerType>(elementTy)) {
101-
int32_t shift = 0;
102-
ElementsAttr shift_elem;
103-
if (shift_val.getImpl() &&
104-
matchPattern(shift_val, m_Constant(&shift_elem))) {
105-
// Explicit shift is set.
106-
shift = shift_elem.getValues<IntegerAttr>()[0].getInt();
107-
}
108-
109113
Value a = args[0];
110114
Value b = args[1];
115+
111116
if (shift > 0) {
112117
auto shiftConst =
113118
rewriter.create<arith::ConstantIntOp>(loc, shift, /*bitwidth=*/8);

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,16 +963,10 @@ LogicalResult tosa::MulOp::inferReturnTypeComponents(
963963
ValueShapeRange operands, DictionaryAttr attributes,
964964
OpaqueProperties properties, RegionRange regions,
965965
SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) {
966-
LogicalResult status = success();
966+
// mul op's output shape only depend on input1 and input2, not on shift
967+
ValueShapeRange twoInputs = operands.drop_back();
967968
llvm::SmallVector<int64_t> outShape;
968-
if (operands.size() == 2) {
969-
status = resolveBroadcastShape(operands, outShape);
970-
} else {
971-
// mul op's output shape only depend on input1 and input2, not on shift
972-
ValueShapeRange two_inputs = operands.drop_back();
973-
status = resolveBroadcastShape(two_inputs, outShape);
974-
}
975-
if (status.failed()) {
969+
if (resolveBroadcastShape(twoInputs, outShape).failed()) {
976970
inferredReturnShapes.push_back(ShapedTypeComponents());
977971
} else {
978972
inferredReturnShapes.push_back(ShapedTypeComponents(outShape));
@@ -1007,6 +1001,15 @@ LogicalResult tosa::MulOp::verify() {
10071001
return emitOpError(
10081002
"requires the same element type for all operands and results");
10091003
}
1004+
1005+
// verify shift has value 0 for non-integer types
1006+
ElementsAttr shift_elem;
1007+
if (matchPattern(getShift(), m_Constant(&shift_elem))) {
1008+
int32_t shift = shift_elem.getValues<IntegerAttr>()[0].getInt();
1009+
if (shift != 0) {
1010+
return emitOpError() << "require shift to be 0 for float type";
1011+
}
1012+
}
10101013
}
10111014

10121015
// Verify the op has same ranks for all main operands (excludes extra operands

mlir/lib/Dialect/Tosa/Transforms/TosaReduceTransposes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ bool TosaReduceTransposes::collectFanIn(Operation *op,
287287

288288
for (Value operand : op->getOperands()) {
289289
// If this is a problem in future, think about alternatives to recursion.
290-
if (llvm::isa<tosa::MulOp>(op) && op->getNumOperands() == 3 &&
291-
operand == op->getOperand(2)) {
290+
if (llvm::isa<tosa::MulOp>(op) && operand == op->getOperand(2)) {
292291
// do not recurse into MulOp's shift operand
293292
continue;
294293
}
@@ -332,8 +331,7 @@ std::optional<Value> TosaReduceTransposes::buildMappedToValue(
332331
for (Value v : op->getOperands()) {
333332
if (valuesMap.contains(v)) {
334333
operands.push_back(valuesMap.at(v));
335-
} else if (llvm::isa<tosa::MulOp>(op) && op->getNumOperands() == 3 &&
336-
v == op->getOperand(2)) {
334+
} else if (llvm::isa<tosa::MulOp>(op) && v == op->getOperand(2)) {
337335
// special case for MulOp's shift operand
338336
operands.push_back(v);
339337
} else {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
472472

473473
// CHECK: linalg.generic
474474
// CHECK: arith.mulf
475-
%4 = tosa.mul %0, %1 : (tensor<1xf32>, tensor<1xf32>) -> tensor<1xf32>
475+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
476+
%4 = tosa.mul %0, %1, %shift : (tensor<1xf32>, tensor<1xf32>, tensor<1xi8>) -> tensor<1xf32>
476477

477478
// CHECK: linalg.generic
478479
// CHECK: arith.negf
@@ -618,7 +619,8 @@ func.func @test_simple_i16(%arg0: tensor<1xi16>) -> () {
618619
// CHECK: arith.extsi
619620
// CHECK: arith.extsi
620621
// CHECK: arith.muli
621-
%0 = tosa.mul %arg0, %arg0 : (tensor<1xi16>, tensor<1xi16>) -> tensor<1xi32>
622+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
623+
%0 = tosa.mul %arg0, %arg0, %shift : (tensor<1xi16>, tensor<1xi16>, tensor<1xi8>) -> tensor<1xi32>
622624

623625
return
624626
}

mlir/test/Dialect/Tosa/canonicalize.mlir

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ func.func @pad_determine_val_quant(%arg0: tensor<?x?xi32>, %arg1 : tensor<2x2xi3
331331
func.func @mul_one_float(%arg0: tensor<2x3xf32>) -> tensor<2x3xf32> {
332332
// CHECK: return %arg0
333333
// CHECK-NOT: tosa.mul
334+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
334335
%ones = "tosa.const"() {value = dense<1.0> : tensor<2x3xf32>} : () -> tensor<2x3xf32>
335-
%1 = tosa.mul %arg0, %ones : (tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
336+
%1 = tosa.mul %arg0, %ones, %shift : (tensor<2x3xf32>, tensor<2x3xf32>, tensor<1xi8>) -> tensor<2x3xf32>
336337
return %1 : tensor<2x3xf32>
337338
}
338339

@@ -343,7 +344,8 @@ func.func @mul_bcast_one_float(%arg0: tensor<2x3xf32>) -> tensor<2x3xf32> {
343344
// CHECK: return %arg0
344345
// CHECK-NOT: tosa.mul
345346
%ones = "tosa.const"() {value = dense<1.0> : tensor<1x1xf32>} : () -> tensor<1x1xf32>
346-
%1 = tosa.mul %ones, %arg0 : (tensor<1x1xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
347+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
348+
%1 = tosa.mul %ones, %arg0, %shift : (tensor<1x1xf32>, tensor<2x3xf32>, tensor<1xi8>) -> tensor<2x3xf32>
347349
return %1 : tensor<2x3xf32>
348350
}
349351

@@ -379,11 +381,12 @@ func.func @mul_zero_broadcast(%arg0: tensor<2x3xf32>) -> (tensor<2x3xf32>, tenso
379381
// CHECK: %[[ZERO:.*]] = "tosa.const"() <{value = dense<0.000000e+00> : tensor<2x3xf32>}
380382
// CHECK-NOT: tosa.mul
381383
%zeros = "tosa.const"() {value = dense<0.0> : tensor<1x1xf32>} : () -> tensor<1x1xf32>
382-
%1 = tosa.mul %arg0, %zeros : (tensor<2x3xf32>, tensor<1x1xf32>) -> tensor<2x3xf32>
384+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
385+
%1 = tosa.mul %arg0, %zeros, %shift : (tensor<2x3xf32>, tensor<1x1xf32>, tensor<1xi8>) -> tensor<2x3xf32>
383386

384387
// CHECK-NOT: tosa.mul
385388
// CHECK: return %[[ZERO]], %[[ZERO]]
386-
%2 = tosa.mul %zeros, %arg0 : (tensor<1x1xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
389+
%2 = tosa.mul %zeros, %arg0, %shift : (tensor<1x1xf32>, tensor<2x3xf32>, tensor<1xi8>) -> tensor<2x3xf32>
387390
return %1, %2 : tensor<2x3xf32>, tensor<2x3xf32>
388391
}
389392

@@ -966,7 +969,8 @@ func.func @mul_quant_nofold() -> tensor<1x!quant.uniform<i8:f32, 3.0757404601899
966969
// CHECK: tosa.mul
967970
%0 = "tosa.const"() {value = dense<0> : tensor<1xi8>} : () -> tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
968971
%1 = "tosa.const"() {value = dense<1> : tensor<1xi8>} : () -> tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
969-
%2 = tosa.mul %0, %1 : (tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>, tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>)-> tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
972+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
973+
%2 = tosa.mul %0, %1, %shift : (tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>, tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>, tensor<1xi8>) -> tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
970974
return %2 : tensor<1x!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
971975
}
972976

mlir/test/Dialect/Tosa/constant-op-fold.mlir

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ func.func @fold_div_splat_i32() -> tensor<i32> {
238238
func.func @fold_mul_zero_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
239239
%zero = "tosa.const"() {value = dense<0.0> : tensor<f32>} : () -> tensor<f32>
240240
// CHECK: %[[ZERO:.+]] = "tosa.const"() <{value = dense<0.000000e+00>
241-
%mul = tosa.mul %arg0, %zero : (tensor<f32>, tensor<f32>) -> tensor<f32>
241+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
242+
%mul = tosa.mul %arg0, %zero, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
242243
// CHECK: return %[[ZERO]]
243244
return %mul : tensor<f32>
244245
}
@@ -249,7 +250,8 @@ func.func @fold_mul_zero_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
249250
func.func @fold_mul_zero_lhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
250251
%zero = "tosa.const"() {value = dense<0.0> : tensor<f32>} : () -> tensor<f32>
251252
// CHECK: %[[ZERO:.+]] = "tosa.const"() <{value = dense<0.000000e+00>
252-
%mul = tosa.mul %zero, %arg0 : (tensor<f32>, tensor<f32>) -> tensor<f32>
253+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
254+
%mul = tosa.mul %zero, %arg0, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
253255
// CHECK: return %[[ZERO]]
254256
return %mul : tensor<f32>
255257
}
@@ -283,7 +285,8 @@ func.func @fold_mul_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
283285
// CHECK-LABEL: @fold_mul_one_rhs_f32
284286
func.func @fold_mul_one_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
285287
%one = "tosa.const"() {value = dense<1.0> : tensor<f32>} : () -> tensor<f32>
286-
%mul = tosa.mul %arg0, %one : (tensor<f32>, tensor<f32>) -> tensor<f32>
288+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
289+
%mul = tosa.mul %arg0, %one, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
287290
// CHECK: return %arg0
288291
return %mul : tensor<f32>
289292
}
@@ -293,7 +296,8 @@ func.func @fold_mul_one_rhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
293296
// CHECK-LABEL: @fold_mul_one_lhs_f32
294297
func.func @fold_mul_one_lhs_f32(%arg0: tensor<f32>) -> tensor<f32> {
295298
%one = "tosa.const"() {value = dense<1.0> : tensor<f32>} : () -> tensor<f32>
296-
%mul = tosa.mul %one, %arg0 : (tensor<f32>, tensor<f32>) -> tensor<f32>
299+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
300+
%mul = tosa.mul %one, %arg0, %shift : (tensor<f32>, tensor<f32>, tensor<1xi8>) -> tensor<f32>
297301
// CHECK: return %arg0
298302
return %mul : tensor<f32>
299303
}
@@ -339,7 +343,8 @@ func.func @fold_mul_splat_i8() -> tensor<10xi32> {
339343
func.func @fold_mul_splat_f32() -> tensor<10xf32> {
340344
%one = "tosa.const"() {value = dense<3.0> : tensor<10xf32>} : () -> tensor<10xf32>
341345
%two = "tosa.const"() {value = dense<2.0> : tensor<10xf32>} : () -> tensor<10xf32>
342-
%mul = tosa.mul %one, %two : (tensor<10xf32>, tensor<10xf32>) -> tensor<10xf32>
346+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
347+
%mul = tosa.mul %one, %two, %shift : (tensor<10xf32>, tensor<10xf32>, tensor<1xi8>) -> tensor<10xf32>
343348
// CHECK: %[[THREE:.+]] = "tosa.const"() <{value = dense<6.000000e+00> : tensor<10xf32>}
344349
// CHECK: return %[[THREE]]
345350
return %mul : tensor<10xf32>

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,26 +730,27 @@ func.func @test_transpose_conv2d_invalid_outshape(%arg0: tensor<1x32x32x8xf32>,
730730

731731
// CHECK-LABEL: test_mul_type_mismatch
732732
func.func @test_mul_type_mismatch(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf16>) -> tensor<13x21x3xf32> {
733+
%shift = "tosa.const"() {value = dense<0> : tensor<1xi8>} : () -> tensor<1xi8>
733734
// expected-error@+1 {{'tosa.mul' op requires the same element type for all operands}}
734-
%0 = tosa.mul %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x1x3xf16>) -> tensor<13x21x3xf32>
735+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf16>, tensor<1xi8>) -> tensor<13x21x3xf32>
735736
return %0 : tensor<13x21x3xf32>
736737
}
737738

738739
// -----
739740

740741
// CHECK-LABEL: test_mul_invalid_shift
741-
func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x1x3xi32>) -> tensor<13x21x3xi32> {
742-
%shift = "tosa.const"() {value = dense<0.0> : tensor<f32>} : () -> tensor<f32>
743-
// expected-error@+1 {{'tosa.mul' op operand #2 must be 1D tensor of 8-bit signless integer values, but got 'tensor<f32>'}}
744-
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xi32>, tensor<13x1x3xi32>, tensor<f32>) -> tensor<13x21x3xi32>
745-
return %0 : tensor<13x21x3xi32>
742+
func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
743+
%shift = "tosa.const"() {value = dense<1> : tensor<1xi8>} : () -> tensor<1xi8>
744+
// expected-error@+1 {{'tosa.mul' op require shift to be 0 for float type}}
745+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<1xi8>) -> tensor<13x21x3xf32>
746+
return %0 : tensor<13x21x3xf32>
746747
}
747748

748749
// -----
749750

750751
// CHECK-LABEL: test_mul_missing_shift
751752
func.func @test_mul_missing_shift(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x1x3xi32>) -> tensor<13x21x3xi32> {
752-
// this is ok because mul's shift operand is optional for now
753+
// expected-error@+1 {{'tosa.mul' op expected 3 operands, but found 2}}
753754
%0 = tosa.mul %arg0, %arg1 : (tensor<13x21x3xi32>, tensor<13x1x3xi32>) -> tensor<13x21x3xi32>
754755
return %0 : tensor<13x21x3xi32>
755756
}
@@ -1061,3 +1062,30 @@ func.func @test_sub_with_unequal_result_ranks(%arg0: tensor<1x21x3xf32>, %arg1:
10611062
%0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<13x21x3xf32>) -> tensor<1x13x21x3xf32>
10621063
return %0 : tensor<1x13x21x3xf32>
10631064
}
1065+
1066+
// -----
1067+
// CHECK-LABEL: test_mul_non_scalar_shift_2d
1068+
func.func @test_mul_non_scalar_shift_2d(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
1069+
%shift = "tosa.const"() <{value = dense<0> : tensor<1x1xi8>}> : () -> tensor<1x1xi8>
1070+
// expected-error@+1 {{'tosa.mul' op operand #2 must be tosa-conformant scalar tensor of 8-bit signless integer values, but got 'tensor<1x1xi8>'}}
1071+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<1x1xi8>) -> tensor<13x21x3xf32>
1072+
return %0 : tensor<13x21x3xf32>
1073+
}
1074+
1075+
// -----
1076+
// CHECK-LABEL: test_mul_non_scalar_shift_1d
1077+
func.func @test_mul_non_scalar_shift_1d(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
1078+
%shift = "tosa.const"() <{value = dense<0> : tensor<2xi8>}> : () -> tensor<2xi8>
1079+
// expected-error@+1 {{'tosa.mul' op operand #2 must be tosa-conformant scalar tensor of 8-bit signless integer values, but got 'tensor<2xi8>'}}
1080+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<2xi8>) -> tensor<13x21x3xf32>
1081+
return %0 : tensor<13x21x3xf32>
1082+
}
1083+
1084+
// -----
1085+
// CHECK-LABEL: test_mul_non_broadcast
1086+
func.func @test_mul_non_broadcast(%arg0: tensor<13x21x2xf32>, %arg1: tensor<3x1x3xf32>) -> tensor<13x21x3xf32> {
1087+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
1088+
// expected-error@+1 {{'tosa.mul' op operands don't have broadcast-compatible shapes}}
1089+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x2xf32>, tensor<3x1x3xf32>, tensor<1xi8>) -> tensor<13x21x3xf32>
1090+
return %0 : tensor<13x21x3xf32>
1091+
}

mlir/test/Dialect/Tosa/ops.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ func.func @test_mul_scalar_with_unranked_output(%arg0: tensor<f32>, %arg1: tenso
338338
// -----
339339
// CHECK-LABEL: mul
340340
func.func @test_mul(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
341-
%0 = tosa.mul %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x1x3xf32>) -> tensor<13x21x3xf32>
341+
%shift = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
342+
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<1xi8>) -> tensor<13x21x3xf32>
342343
return %0 : tensor<13x21x3xf32>
343344
}
344345

0 commit comments

Comments
 (0)