Skip to content

Commit cf2299a

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 d81db0e commit cf2299a

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 = [{
@@ -1501,7 +1501,7 @@ def Tosa_ReduceSumOp : Tosa_InferTensorTypeOp<"reduce_sum"> {
15011501

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

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

@@ -1834,9 +1834,9 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18341834

18351835
| Mode | Input | Output |
18361836
|--------------------------|---------|---------|
1837-
| signed 8 to bool | int8 | Boolean |
1838-
| signed 16 to bool | int16 | Boolean |
1839-
| signed 32 to bool | int32 | Boolean |
1837+
| signed 8 to bool | int8 | Boolean |
1838+
| signed 16 to bool | int16 | Boolean |
1839+
| signed 32 to bool | int32 | Boolean |
18401840
| bool to 8 | Boolean | int8 |
18411841
| bool to 16 | Boolean | int16 |
18421842
| bool to 32 | Boolean | int32 |
@@ -1850,8 +1850,8 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
18501850
| float to signed 16 | float | int16 |
18511851
| signed 8 to float | int8 | float |
18521852
| signed 16 to float | int16 | float |
1853-
| float 32 to float 64 | float32 | float64 |
1854-
| float 64 to float 32 | float64 | float32 |
1853+
| float 32 to float 64 | float32 | float64 |
1854+
| float 64 to float 32 | float64 | float32 |
18551855
}];
18561856

18571857
let arguments = (ins

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

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

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

9696
// tosa::ReciprocalOp
@@ -2549,7 +2549,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
25492549
PointwiseConverter<tosa::AddOp>,
25502550
PointwiseConverter<tosa::SubOp>,
25512551
PointwiseConverter<tosa::MulOp>,
2552-
PointwiseConverter<tosa::DivOp>,
2552+
PointwiseConverter<tosa::IntDivOp>,
25532553
PointwiseConverter<tosa::NegateOp>,
25542554
PointwiseConverter<tosa::PowOp>,
25552555
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
@@ -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
@@ -1331,12 +1331,12 @@ NARY_SHAPE_INFER(tosa::CeilOp)
13311331
NARY_SHAPE_INFER(tosa::ClampOp)
13321332
NARY_SHAPE_INFER(tosa::ClzOp)
13331333
NARY_SHAPE_INFER(tosa::CosOp)
1334-
NARY_SHAPE_INFER(tosa::DivOp)
13351334
NARY_SHAPE_INFER(tosa::ExpOp)
13361335
NARY_SHAPE_INFER(tosa::FloorOp)
13371336
NARY_SHAPE_INFER(tosa::GreaterEqualOp)
13381337
NARY_SHAPE_INFER(tosa::GreaterOp)
13391338
NARY_SHAPE_INFER(tosa::IdentityOp)
1339+
NARY_SHAPE_INFER(tosa::IntDivOp)
13401340
NARY_SHAPE_INFER(tosa::LogOp)
13411341
NARY_SHAPE_INFER(tosa::LogicalAndOp)
13421342
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
@@ -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)