Skip to content

Commit d3e987c

Browse files
committed
[mlir][tosa] Added div op, variadic concat. Removed placeholder. Spec v0.22 alignment.
Nearly complete alignment to spec v0.22 - Adds Div op - Concat inputs now variadic - Removes Placeholder op Note: TF side PR tensorflow/tensorflow#48921 deletes Concat legalizations to avoid breaking TensorFlow CI. This must be merged only after the TF PR has merged. Reviewed By: rsuderman Differential Revision: https://reviews.llvm.org/D101958
1 parent 44ee974 commit d3e987c

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,28 @@ def Tosa_BitwiseXorOp : Tosa_Op<"bitwise_xor", [ResultsBroadcastableShape,
492492
);
493493
}
494494

495+
//===----------------------------------------------------------------------===//
496+
// Operator: div
497+
//===----------------------------------------------------------------------===//
498+
def Tosa_DivOp : Tosa_Op<"div", [ResultsBroadcastableShape,
499+
NoSideEffect]> {
500+
let summary = "Integer divide operator";
501+
502+
let description = [{
503+
Elementwise integer divide operator of input1 by input2. Axis of size 1
504+
will be broadcast, as necessary. Rank of input tensors must match.
505+
}];
506+
507+
let arguments = (ins
508+
Tosa_Int32TensorUpto4D:$input1,
509+
Tosa_Int32TensorUpto4D:$input2
510+
);
511+
512+
let results = (outs
513+
Tosa_Int32TensorUpto4D:$output
514+
);
515+
}
516+
495517
//===----------------------------------------------------------------------===//
496518
// Operator: logical_and
497519
//===----------------------------------------------------------------------===//
@@ -1206,13 +1228,12 @@ def Tosa_ConcatOp : Tosa_Op<"concat", [NoSideEffect]> {
12061228
let summary = "Concatenates tensors along one dimension.";
12071229

12081230
let description = [{
1209-
Concatenate two tensors along a given axis. No data conversion happens
1210-
during a concat operation.
1231+
Concatenate a variadic amount of tensors along a given axis. No data
1232+
conversion happens during a concat operation.
12111233
}];
12121234

12131235
let arguments = (ins
1214-
Tosa_Tensor1Dto4D:$input1,
1215-
Tosa_Tensor1Dto4D:$input2,
1236+
Variadic<Tosa_Tensor1Dto4D>:$input1,
12161237
I64Attr:$axis
12171238
);
12181239

@@ -1586,26 +1607,6 @@ def Tosa_IdentityNOp: Tosa_Op<"identityn", [NoSideEffect]> {
15861607
);
15871608
}
15881609

1589-
1590-
//===----------------------------------------------------------------------===//
1591-
// Operator: placeholder
1592-
//===----------------------------------------------------------------------===//
1593-
def Tosa_PlaceholderOp : Tosa_Op<"placeholder", [NoSideEffect]> {
1594-
let summary = "Placeholder op";
1595-
1596-
let description = [{
1597-
A node where data will be inserted into the network at runtime. Generally
1598-
used for inputs to the network.
1599-
}];
1600-
1601-
let arguments = (ins
1602-
);
1603-
1604-
let results = (outs
1605-
Tosa_Tensor1Dto4D:$output
1606-
);
1607-
}
1608-
16091610
//===----------------------------------------------------------------------===//
16101611
// TOSA Spec Section 2.14
16111612
// Operator Class: Custom Operators.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def Tosa_Tensor1Dto6D : TensorRankOf<[Tosa_AnyNumber], [1,2,3,4,5,6]>;
126126
def Tosa_TensorUpto4D : TensorRankOf<[Tosa_AnyNumber], [0,1,2,3,4]>;
127127
def Tosa_TensorUpto6D : TensorRankOf<[Tosa_AnyNumber], [0,1,2,3,4,5,6]>;
128128

129+
def Tosa_Int32TensorUpto4D : TensorRankOf<[Tosa_Int32], [0,1,2,3,4]>;
130+
129131
//===----------------------------------------------------------------------===//
130132
// Generic scalar, vector, or tensor of a particular type.
131133
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Tosa/ops.mlir

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ func @test_arithmetic_right_shift(%arg0: tensor<13x21x1xf32>, %arg1: tensor<13x2
101101
return %0 : tensor<13x21x3xf32>
102102
}
103103

104-
105104
// -----
106105
// CHECK-LABEL: bitwise_and
107106
func @test_bitwise_and(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x21x1xi32>) -> tensor<13x21x3xi32> {
@@ -123,6 +122,13 @@ func @test_bitwise_xor(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -
123122
return %0 : tensor<13x21x3xi32>
124123
}
125124

125+
// -----
126+
// CHECK-LABEL: div
127+
func @test_div(%arg0: tensor<13x21x1xi32>, %arg1: tensor<13x21x3xi32>) -> tensor<13x21x3xi32> {
128+
%0 = "tosa.div"(%arg0, %arg1) : (tensor<13x21x1xi32>, tensor<13x21x3xi32>) -> tensor<13x21x3xi32>
129+
return %0 : tensor<13x21x3xi32>
130+
}
131+
126132
// -----
127133
// CHECK-LABEL: logical_and
128134
func @test_logical_and(%arg0: tensor<13x21x3xi1>, %arg1: tensor<13x21x1xi1>) -> tensor<13x21x3xi1> {
@@ -474,13 +480,6 @@ func @test_identityn(%arg0: tensor<1xi32>, %arg1: tensor<1xi32>) -> tensor<1xi32
474480
return %0#0 : tensor<1xi32>
475481
}
476482

477-
// -----
478-
// CHECK-LABEL: placeholder
479-
func @test_placeholder() -> tensor<1xi32> {
480-
%0 = "tosa.placeholder"() : () -> tensor<1xi32>
481-
return %0 : tensor<1xi32>
482-
}
483-
484483
// -----
485484
// CHECK-LABEL: cond_if
486485
func @test_cond_if(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {

0 commit comments

Comments
 (0)