Skip to content

Commit 1513939

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 626fe71 commit 1513939

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
@@ -604,9 +604,9 @@ def Tosa_BitwiseXorOp : Tosa_ElementwiseOp<"bitwise_xor", [
604604
}
605605

606606
//===----------------------------------------------------------------------===//
607-
// Operator: div
607+
// Operator: int_div
608608
//===----------------------------------------------------------------------===//
609-
def Tosa_DivOp : Tosa_ElementwiseOp<"div", [SameOperandsAndResultElementType]> {
609+
def Tosa_IntDivOp : Tosa_ElementwiseOp<"int_div", [SameOperandsAndResultElementType]> {
610610
let summary = "Integer divide operator";
611611

612612
let description = [{
@@ -1461,7 +1461,7 @@ def Tosa_ReduceSumOp : Tosa_InferTensorTypeOp<"reduce_sum"> {
14611461

14621462
let hasFolder = 1;
14631463
let hasVerifier = 1;
1464-
1464+
14651465
let extraClassDeclaration = [{
14661466
/// Returns true when two result types are compatible for this op;
14671467
/// Method used by InferTypeOpInterface.
@@ -1611,7 +1611,7 @@ def Tosa_ReverseOp: Tosa_Op<"reverse", [
16111611

16121612
let hasFolder = 1;
16131613
let hasVerifier = 1;
1614-
1614+
16151615
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
16161616
}
16171617

@@ -1794,9 +1794,9 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
17941794

17951795
| Mode | Input | Output |
17961796
|--------------------------|---------|---------|
1797-
| signed 8 to bool | int8 | Boolean |
1798-
| signed 16 to bool | int16 | Boolean |
1799-
| signed 32 to bool | int32 | Boolean |
1797+
| signed 8 to bool | int8 | Boolean |
1798+
| signed 16 to bool | int16 | Boolean |
1799+
| signed 32 to bool | int32 | Boolean |
18001800
| bool to 8 | Boolean | int8 |
18011801
| bool to 16 | Boolean | int16 |
18021802
| bool to 32 | Boolean | int32 |
@@ -1810,8 +1810,8 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18101810
| float to signed 16 | float | int16 |
18111811
| signed 8 to float | int8 | float |
18121812
| signed 16 to float | int16 | float |
1813-
| float 32 to float 64 | float32 | float64 |
1814-
| float 64 to float 32 | float64 | float32 |
1813+
| float 32 to float 64 | float32 | float64 |
1814+
| float 64 to float 32 | float64 | float32 |
18151815
}];
18161816

18171817
let arguments = (ins

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

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

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

9898
// tosa::ReciprocalOp
@@ -2555,7 +2555,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
25552555
PointwiseConverter<tosa::AddOp>,
25562556
PointwiseConverter<tosa::SubOp>,
25572557
PointwiseConverter<tosa::MulOp>,
2558-
PointwiseConverter<tosa::DivOp>,
2558+
PointwiseConverter<tosa::IntDivOp>,
25592559
PointwiseConverter<tosa::NegateOp>,
25602560
PointwiseConverter<tosa::PowOp>,
25612561
PointwiseConverter<tosa::ReciprocalOp>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void mlir::tosa::registerShardingInterfaceExternalModels(
100100
registry.addExtension(+[](MLIRContext *ctx, TosaDialect *dialect) {
101101
registerElemwiseAll<
102102
ClampOp, SigmoidOp, TanhOp, AddOp, ArithmeticRightShiftOp, BitwiseAndOp,
103-
BitwiseOrOp, BitwiseXorOp, DivOp, LogicalAndOp, LogicalLeftShiftOp,
103+
BitwiseOrOp, BitwiseXorOp, IntDivOp, LogicalAndOp, LogicalLeftShiftOp,
104104
LogicalRightShiftOp, LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp,
105105
MulOp, PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp, FloorOp,
106106
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
@@ -507,7 +507,7 @@ OpFoldResult AddOp::fold(FoldAdaptor adaptor) {
507507
resultTy);
508508
}
509509

510-
OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
510+
OpFoldResult IntDivOp::fold(FoldAdaptor adaptor) {
511511
auto lhsTy = llvm::dyn_cast<RankedTensorType>(getInput1().getType());
512512
auto rhsTy = llvm::dyn_cast<RankedTensorType>(getInput2().getType());
513513
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
@@ -1330,7 +1330,7 @@ NARY_SHAPE_INFER(tosa::CastOp)
13301330
NARY_SHAPE_INFER(tosa::CeilOp)
13311331
NARY_SHAPE_INFER(tosa::ClampOp)
13321332
NARY_SHAPE_INFER(tosa::ClzOp)
1333-
NARY_SHAPE_INFER(tosa::DivOp)
1333+
NARY_SHAPE_INFER(tosa::IntDivOp)
13341334
NARY_SHAPE_INFER(tosa::ExpOp)
13351335
NARY_SHAPE_INFER(tosa::FloorOp)
13361336
NARY_SHAPE_INFER(tosa::GreaterEqualOp)

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
@@ -622,7 +622,7 @@ func.func @test_simple_i32(%arg0: tensor<1xi32>) -> () {
622622

623623
// CHECK: linalg.generic
624624
// CHECK: arith.divsi
625-
%4 = tosa.div %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>
625+
%40 = tosa.int_div %arg0, %arg0 : (tensor<1xi32>, tensor<1xi32>) -> tensor<1xi32>
626626

627627
// CHECK: linalg.generic
628628
// 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
@@ -182,7 +182,7 @@ func.func @fold_add_splat_f32() -> tensor<10xf32> {
182182
func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
183183
%zero = "tosa.const"() {value = dense<0> : tensor<i32>} : () -> tensor<i32>
184184
// CHECK: %[[ZERO:.+]] = "tosa.const"() <{value = dense<0>
185-
%div = tosa.div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
185+
%div = tosa.int_div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
186186
// CHECK: return %[[ZERO]]
187187
return %div : tensor<i32>
188188
}
@@ -192,7 +192,7 @@ func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
192192
// CHECK-LABEL: @fold_div_one_rhs_i32
193193
func.func @fold_div_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
194194
%one = "tosa.const"() {value = dense<1> : tensor<i32>} : () -> tensor<i32>
195-
%div = tosa.div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
195+
%div = tosa.int_div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
196196
// CHECK: return %arg0
197197
return %div : tensor<i32>
198198
}
@@ -204,7 +204,7 @@ func.func @fold_div_splat_i32() -> tensor<i32> {
204204
%lhs = "tosa.const"() {value = dense<10> : tensor<i32>} : () -> tensor<i32>
205205
%rhs = "tosa.const"() {value = dense<-3> : tensor<i32>} : () -> tensor<i32>
206206
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{value = dense<-3>
207-
%div = tosa.div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
207+
%div = tosa.int_div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
208208
// CHECK: return %[[SPLAT]]
209209
return %div : tensor<i32>
210210
}
@@ -1061,7 +1061,7 @@ func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10611061
// AGGRESIVE-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10621062
// AGGRESIVE: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<4> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>
10631063
// AGGRESIVE: return %[[VAL_0:.*]] : tensor<1x3xi32>
1064-
1064+
10651065
// CHECK-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
10661066
// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<1> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>
10671067
// 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)