Skip to content

Commit fd15451

Browse files
committed
[mlir][tosa] Rename Tosa Div op to IntDiv Op
This patch renames Tosa Div Op to IntDiv Op to align with the TOSA Spec. Signed-off-by: Tai Ly <[email protected]> Change-Id: I2a30d915435e43d05ed28a49345644eeaef00656
1 parent 44713f1 commit fd15451

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ def Tosa_BitwiseXorOp : Tosa_ElementwiseOp<"bitwise_xor", [
605605
}
606606

607607
//===----------------------------------------------------------------------===//
608-
// Operator: div
608+
// Operator: int_div
609609
//===----------------------------------------------------------------------===//
610-
def Tosa_DivOp : Tosa_ElementwiseOp<"div", [SameOperandsAndResultElementType]> {
610+
def Tosa_IntDivOp : Tosa_ElementwiseOp<"int_div", [SameOperandsAndResultElementType]> {
611611
let summary = "Integer divide operator";
612612

613613
let description = [{
@@ -1502,7 +1502,7 @@ def Tosa_ReduceSumOp : Tosa_InferTensorTypeOp<"reduce_sum"> {
15021502

15031503
let hasFolder = 1;
15041504
let hasVerifier = 1;
1505-
1505+
15061506
let extraClassDeclaration = [{
15071507
/// Returns true when two result types are compatible for this op;
15081508
/// Method used by InferTypeOpInterface.
@@ -1652,7 +1652,7 @@ def Tosa_ReverseOp: Tosa_Op<"reverse", [
16521652

16531653
let hasFolder = 1;
16541654
let hasVerifier = 1;
1655-
1655+
16561656
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
16571657
}
16581658

@@ -1835,9 +1835,9 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18351835

18361836
| Mode | Input | Output |
18371837
|--------------------------|---------|---------|
1838-
| signed 8 to bool | int8 | Boolean |
1839-
| signed 16 to bool | int16 | Boolean |
1840-
| signed 32 to bool | int32 | Boolean |
1838+
| signed 8 to bool | int8 | Boolean |
1839+
| signed 16 to bool | int16 | Boolean |
1840+
| signed 32 to bool | int32 | Boolean |
18411841
| bool to 8 | Boolean | int8 |
18421842
| bool to 16 | Boolean | int16 |
18431843
| bool to 32 | Boolean | int32 |
@@ -1851,8 +1851,8 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18511851
| float to signed 16 | float | int16 |
18521852
| signed 8 to float | int8 | float |
18531853
| signed 16 to float | int16 | float |
1854-
| float 32 to float 64 | float32 | float64 |
1855-
| float 64 to float 32 | float64 | float32 |
1854+
| float 32 to float 64 | float32 | float64 |
1855+
| float 64 to float 32 | float64 | float32 |
18561856
}];
18571857

18581858
let arguments = (ins

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
9090
return rewriter.create<arith::MulFOp>(loc, resultTypes, args);
9191
}
9292

93-
// tosa::DivOp
94-
if (isa<tosa::DivOp>(op) && isa<IntegerType>(elementTy))
93+
// tosa::IntDivOp
94+
if (isa<tosa::IntDivOp>(op) && isa<IntegerType>(elementTy))
9595
return rewriter.create<arith::DivSIOp>(loc, resultTypes, args);
9696

9797
// tosa::ReciprocalOp
@@ -2570,7 +2570,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
25702570
PointwiseConverter<tosa::AddOp>,
25712571
PointwiseConverter<tosa::SubOp>,
25722572
PointwiseConverter<tosa::MulOp>,
2573-
PointwiseConverter<tosa::DivOp>,
2573+
PointwiseConverter<tosa::IntDivOp>,
25742574
PointwiseConverter<tosa::NegateOp>,
25752575
PointwiseConverter<tosa::PowOp>,
25762576
PointwiseConverter<tosa::ReciprocalOp>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void mlir::tosa::registerShardingInterfaceExternalModels(
7979
registry.addExtension(+[](MLIRContext *ctx, TosaDialect *dialect) {
8080
registerElemwiseAll<
8181
ClampOp, SigmoidOp, TanhOp, AddOp, ArithmeticRightShiftOp, BitwiseAndOp,
82-
BitwiseOrOp, BitwiseXorOp, DivOp, LogicalAndOp, LogicalLeftShiftOp,
82+
BitwiseOrOp, BitwiseXorOp, IntDivOp, LogicalAndOp, LogicalLeftShiftOp,
8383
LogicalRightShiftOp, LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp,
8484
MulOp, PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp, FloorOp,
8585
LogOp, LogicalNotOp, NegateOp, ReciprocalOp, RsqrtOp, SelectOp, EqualOp,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ OpFoldResult ArgMaxOp::fold(FoldAdaptor adaptor) {
520520
return {};
521521
}
522522

523-
OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
523+
OpFoldResult IntDivOp::fold(FoldAdaptor adaptor) {
524524
auto lhsTy = llvm::dyn_cast<RankedTensorType>(getInput1().getType());
525525
auto rhsTy = llvm::dyn_cast<RankedTensorType>(getInput2().getType());
526526
auto resultTy = llvm::dyn_cast<RankedTensorType>(getType());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,12 +1354,12 @@ NARY_SHAPE_INFER(tosa::CeilOp)
13541354
NARY_SHAPE_INFER(tosa::ClampOp)
13551355
NARY_SHAPE_INFER(tosa::ClzOp)
13561356
NARY_SHAPE_INFER(tosa::CosOp)
1357-
NARY_SHAPE_INFER(tosa::DivOp)
13581357
NARY_SHAPE_INFER(tosa::ExpOp)
13591358
NARY_SHAPE_INFER(tosa::FloorOp)
13601359
NARY_SHAPE_INFER(tosa::GreaterEqualOp)
13611360
NARY_SHAPE_INFER(tosa::GreaterOp)
13621361
NARY_SHAPE_INFER(tosa::IdentityOp)
1362+
NARY_SHAPE_INFER(tosa::IntDivOp)
13631363
NARY_SHAPE_INFER(tosa::LogOp)
13641364
NARY_SHAPE_INFER(tosa::LogicalAndOp)
13651365
NARY_SHAPE_INFER(tosa::LogicalLeftShiftOp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ struct TosaMakeBroadcastable
232232
patterns.add<ConvertTosaOp<tosa::AddOp>>(ctx);
233233
patterns.add<ConvertTosaOp<tosa::SubOp>>(ctx);
234234
patterns.add<ConvertTosaOp<tosa::MulOp>>(ctx);
235-
patterns.add<ConvertTosaOp<tosa::DivOp>>(ctx);
235+
patterns.add<ConvertTosaOp<tosa::IntDivOp>>(ctx);
236236
patterns.add<ConvertTosaOp<tosa::MaximumOp>>(ctx);
237237
patterns.add<ConvertTosaOp<tosa::MinimumOp>>(ctx);
238238
patterns.add<ConvertTosaOp<tosa::EqualOp>>(ctx);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
200200
CHECK_RANKS_FOR(BitwiseAnd);
201201
CHECK_RANKS_FOR(BitwiseOr);
202202
CHECK_RANKS_FOR(BitwiseXor);
203-
CHECK_RANKS_FOR(Div);
203+
CHECK_RANKS_FOR(IntDiv);
204204
CHECK_RANKS_FOR(LogicalAnd);
205205
CHECK_RANKS_FOR(LogicalLeftShift);
206206
CHECK_RANKS_FOR(LogicalRightShift);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ func.func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
626626

627627
// CHECK: linalg.generic
628628
// CHECK: arith.divsi
629-
%4 = tosa.div %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>
629+
%40 = tosa.int_div %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>
630630

631631
// CHECK: linalg.generic
632632
// CHECK: ^bb0(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32):

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func.func @fold_add_splat_f32() -> tensor<10xf32> {
213213
func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
214214
%zero = "tosa.const"() {value = dense<0> : tensor<i32>} : () -> tensor<i32>
215215
// CHECK: %[[ZERO:.+]] = "tosa.const"() <{value = dense<0>
216-
%div = tosa.div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
216+
%div = tosa.int_div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
217217
// CHECK: return %[[ZERO]]
218218
return %div : tensor<i32>
219219
}
@@ -223,7 +223,7 @@ func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
223223
// CHECK-LABEL: @fold_div_one_rhs_i32
224224
func.func @fold_div_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
225225
%one = "tosa.const"() {value = dense<1> : tensor<i32>} : () -> tensor<i32>
226-
%div = tosa.div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
226+
%div = tosa.int_div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
227227
// CHECK: return %arg0
228228
return %div : tensor<i32>
229229
}
@@ -235,7 +235,7 @@ func.func @fold_div_splat_i32() -> tensor<i32> {
235235
%lhs = "tosa.const"() {value = dense<10> : tensor<i32>} : () -> tensor<i32>
236236
%rhs = "tosa.const"() {value = dense<-3> : tensor<i32>} : () -> tensor<i32>
237237
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{value = dense<-3>
238-
%div = tosa.div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
238+
%div = tosa.int_div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
239239
// CHECK: return %[[SPLAT]]
240240
return %div : tensor<i32>
241241
}
@@ -1092,7 +1092,7 @@ func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10921092
// AGGRESIVE-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10931093
// AGGRESIVE: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<4> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>
10941094
// AGGRESIVE: return %[[VAL_0:.*]] : tensor<1x3xi32>
1095-
1095+
10961096
// CHECK-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10971097
// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<1> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>
10981098
// CHECK: %[[VAL_1:.*]] = tosa.reduce_sum %[[VAL_0]] {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>

mlir/test/Dialect/Tosa/ops.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ func.func @test_bitwise_xor(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi3
257257
}
258258

259259
// -----
260-
// CHECK-LABEL: div
261-
func.func @test_div(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -> tensor<13x21x3xi32> {
262-
%0 = tosa.div %arg0, %arg1 : (tensor<13x21x1xi32>, tensor<13x21x3xi32>) -> tensor<13x21x3xi32>
260+
// CHECK-LABEL: int_div
261+
func.func @test_int_div(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -> tensor<13x21x3xi32> {
262+
%0 = tosa.int_div %arg0, %arg1 : (tensor<13x21x1xi32>, tensor<13x21x3xi32>) -> tensor<13x21x3xi32>
263263
return %0 : tensor<13x21x3xi32>
264264
}
265265

0 commit comments

Comments
 (0)