Skip to content

[mlir][tosa] Rename Tosa Div op to IntDiv Op #80047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ def Tosa_BitwiseXorOp : Tosa_ElementwiseOp<"bitwise_xor", [
}

//===----------------------------------------------------------------------===//
// Operator: div
// Operator: int_div
//===----------------------------------------------------------------------===//
def Tosa_DivOp : Tosa_ElementwiseOp<"div", [SameOperandsAndResultElementType]> {
def Tosa_IntDivOp : Tosa_ElementwiseOp<"int_div", [SameOperandsAndResultElementType]> {
let summary = "Integer divide operator";

let description = [{
Expand Down Expand Up @@ -1502,7 +1502,7 @@ def Tosa_ReduceSumOp : Tosa_InferTensorTypeOp<"reduce_sum"> {

let hasFolder = 1;
let hasVerifier = 1;

let extraClassDeclaration = [{
/// Returns true when two result types are compatible for this op;
/// Method used by InferTypeOpInterface.
Expand Down Expand Up @@ -1652,7 +1652,7 @@ def Tosa_ReverseOp: Tosa_Op<"reverse", [

let hasFolder = 1;
let hasVerifier = 1;

let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
}

Expand Down Expand Up @@ -1835,9 +1835,9 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,

| Mode | Input | Output |
|--------------------------|---------|---------|
| signed 8 to bool | int8 | Boolean |
| signed 16 to bool | int16 | Boolean |
| signed 32 to bool | int32 | Boolean |
| signed 8 to bool | int8 | Boolean |
| signed 16 to bool | int16 | Boolean |
| signed 32 to bool | int32 | Boolean |
| bool to 8 | Boolean | int8 |
| bool to 16 | Boolean | int16 |
| bool to 32 | Boolean | int32 |
Expand All @@ -1851,8 +1851,8 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure,
| float to signed 16 | float | int16 |
| signed 8 to float | int8 | float |
| signed 16 to float | int16 | float |
| float 32 to float 64 | float32 | float64 |
| float 64 to float 32 | float64 | float32 |
| float 32 to float 64 | float32 | float64 |
| float 64 to float 32 | float64 | float32 |
}];

let arguments = (ins
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,
return rewriter.create<arith::MulFOp>(loc, resultTypes, args);
}

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

// tosa::ReciprocalOp
Expand Down Expand Up @@ -2568,7 +2568,7 @@ void mlir::tosa::populateTosaToLinalgConversionPatterns(
PointwiseConverter<tosa::AddOp>,
PointwiseConverter<tosa::SubOp>,
PointwiseConverter<tosa::MulOp>,
PointwiseConverter<tosa::DivOp>,
PointwiseConverter<tosa::IntDivOp>,
PointwiseConverter<tosa::NegateOp>,
PointwiseConverter<tosa::PowOp>,
PointwiseConverter<tosa::ReciprocalOp>,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/IR/ShardingInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void mlir::tosa::registerShardingInterfaceExternalModels(
registry.addExtension(+[](MLIRContext *ctx, TosaDialect *dialect) {
registerElemwiseAll<
ClampOp, SigmoidOp, TanhOp, AddOp, ArithmeticRightShiftOp, BitwiseAndOp,
BitwiseOrOp, BitwiseXorOp, DivOp, LogicalAndOp, LogicalLeftShiftOp,
BitwiseOrOp, BitwiseXorOp, IntDivOp, LogicalAndOp, LogicalLeftShiftOp,
LogicalRightShiftOp, LogicalOrOp, LogicalXorOp, MaximumOp, MinimumOp,
MulOp, PowOp, SubOp, AbsOp, BitwiseNotOp, CeilOp, ClzOp, ExpOp, FloorOp,
LogOp, LogicalNotOp, NegateOp, ReciprocalOp, RsqrtOp, SelectOp, EqualOp,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ OpFoldResult ArgMaxOp::fold(FoldAdaptor adaptor) {
return {};
}

OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
OpFoldResult IntDivOp::fold(FoldAdaptor adaptor) {
auto lhsTy = llvm::dyn_cast<RankedTensorType>(getInput1().getType());
auto rhsTy = llvm::dyn_cast<RankedTensorType>(getInput2().getType());
auto resultTy = llvm::dyn_cast<RankedTensorType>(getType());
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void TosaDialect::initialize() {
addInterfaces<TosaDialectBytecodeInterface, TosaInlinerInterface>();
declarePromisedInterfaces<
mesh::ShardingInterface, ClampOp, SigmoidOp, TanhOp, AddOp,
ArithmeticRightShiftOp, BitwiseAndOp, BitwiseOrOp, BitwiseXorOp, DivOp,
ArithmeticRightShiftOp, BitwiseAndOp, BitwiseOrOp, BitwiseXorOp, IntDivOp,
LogicalAndOp, LogicalLeftShiftOp, LogicalRightShiftOp, LogicalOrOp,
LogicalXorOp, MaximumOp, MinimumOp, MulOp, PowOp, SubOp, AbsOp,
BitwiseNotOp, CeilOp, ClzOp, ExpOp, FloorOp, LogOp, LogicalNotOp,
Expand Down Expand Up @@ -1354,12 +1354,12 @@ NARY_SHAPE_INFER(tosa::CeilOp)
NARY_SHAPE_INFER(tosa::ClampOp)
NARY_SHAPE_INFER(tosa::ClzOp)
NARY_SHAPE_INFER(tosa::CosOp)
NARY_SHAPE_INFER(tosa::DivOp)
NARY_SHAPE_INFER(tosa::ExpOp)
NARY_SHAPE_INFER(tosa::FloorOp)
NARY_SHAPE_INFER(tosa::GreaterEqualOp)
NARY_SHAPE_INFER(tosa::GreaterOp)
NARY_SHAPE_INFER(tosa::IdentityOp)
NARY_SHAPE_INFER(tosa::IntDivOp)
NARY_SHAPE_INFER(tosa::LogOp)
NARY_SHAPE_INFER(tosa::LogicalAndOp)
NARY_SHAPE_INFER(tosa::LogicalLeftShiftOp)
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaMakeBroadcastable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct TosaMakeBroadcastable
patterns.add<ConvertTosaOp<tosa::AddOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::SubOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::MulOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::DivOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::IntDivOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::MaximumOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::MinimumOp>>(ctx);
patterns.add<ConvertTosaOp<tosa::EqualOp>>(ctx);
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
CHECK_RANKS_FOR(BitwiseAnd);
CHECK_RANKS_FOR(BitwiseOr);
CHECK_RANKS_FOR(BitwiseXor);
CHECK_RANKS_FOR(Div);
CHECK_RANKS_FOR(IntDiv);
CHECK_RANKS_FOR(LogicalAnd);
CHECK_RANKS_FOR(LogicalLeftShift);
CHECK_RANKS_FOR(LogicalRightShift);
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func.func @test_simple_i32(%arg0: tensor<1xi32>) -> () {

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

// CHECK: linalg.generic
// CHECK: ^bb0(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32):
Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Dialect/Tosa/constant-op-fold.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func.func @fold_add_splat_f32() -> tensor<10xf32> {
func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
%zero = "tosa.const"() {value = dense<0> : tensor<i32>} : () -> tensor<i32>
// CHECK: %[[ZERO:.+]] = "tosa.const"() <{value = dense<0>
%div = tosa.div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
%div = tosa.int_div %zero, %arg0 : (tensor<i32>, tensor<i32>) -> tensor<i32>
// CHECK: return %[[ZERO]]
return %div : tensor<i32>
}
Expand All @@ -223,7 +223,7 @@ func.func @fold_div_zero_lhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
// CHECK-LABEL: @fold_div_one_rhs_i32
func.func @fold_div_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
%one = "tosa.const"() {value = dense<1> : tensor<i32>} : () -> tensor<i32>
%div = tosa.div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
%div = tosa.int_div %arg0, %one : (tensor<i32>, tensor<i32>) -> tensor<i32>
// CHECK: return %arg0
return %div : tensor<i32>
}
Expand All @@ -235,7 +235,7 @@ func.func @fold_div_splat_i32() -> tensor<i32> {
%lhs = "tosa.const"() {value = dense<10> : tensor<i32>} : () -> tensor<i32>
%rhs = "tosa.const"() {value = dense<-3> : tensor<i32>} : () -> tensor<i32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{value = dense<-3>
%div = tosa.div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
%div = tosa.int_div %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
// CHECK: return %[[SPLAT]]
return %div : tensor<i32>
}
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
// AGGRESIVE-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
// AGGRESIVE: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<4> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>
// AGGRESIVE: return %[[VAL_0:.*]] : tensor<1x3xi32>

// CHECK-LABEL: func.func @reduce_sum_constant_aggressive() -> tensor<1x3xi32> {
// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{value = dense<1> : tensor<2x3xi32>}> : () -> tensor<2x3xi32>
// CHECK: %[[VAL_1:.*]] = tosa.reduce_sum %[[VAL_0]] {axis = 0 : i32} : (tensor<2x3xi32>) -> tensor<1x3xi32>
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Dialect/Tosa/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ func.func @test_bitwise_xor(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi3
}

// -----
// CHECK-LABEL: div
func.func @test_div(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -> tensor<13x21x3xi32> {
%0 = tosa.div %arg0, %arg1 : (tensor<13x21x1xi32>, tensor<13x21x3xi32>) -> tensor<13x21x3xi32>
// CHECK-LABEL: int_div
func.func @test_int_div(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -> tensor<13x21x3xi32> {
%0 = tosa.int_div %arg0, %arg1 : (tensor<13x21x1xi32>, tensor<13x21x3xi32>) -> tensor<13x21x3xi32>
return %0 : tensor<13x21x3xi32>
}

Expand Down