Skip to content

Commit e86defd

Browse files
tatwaichongrsuderman
authored andcommitted
[mlir][tosa] Add type checking traits to the appropriate ops
Add the trait `SameOperandsAndResultElementType` and `SameOperandsElementType` to verify ops that are known to have the same input and output type rather than generate an invalid tosa IR with mixed data types like: "tosa.add"(%0, %1) : (tensor<nxbf16>, tensor<nxf32>) -> tensor<nxf32> Thus apply tosa.cast prior if needed. Change-Id: Ie866b84e371e3b571ec04f7abb090c216dd39c33 Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D150472
1 parent f75b735 commit e86defd

File tree

3 files changed

+49
-126
lines changed

3 files changed

+49
-126
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,18 @@ class Tosa_Op<string mnemonic, list<Trait> traits = []> :
215215
Op<Tosa_Dialect, mnemonic, !listconcat(traits, [TosaOpInterface])> {
216216
}
217217

218+
class Tosa_ElemWiseUnaryOp<string mnemonic, list<Trait> traits = []> :
219+
Tosa_Op<mnemonic, !listconcat(traits, [
220+
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
221+
["inferReturnTypeComponents"]>,
222+
Pure, SameOperandsAndResultElementType])> {
223+
}
224+
225+
class Tosa_ElemWiseBinaryOp<string mnemonic, list<Trait> traits = []> :
226+
Tosa_Op<mnemonic, !listconcat(traits, [
227+
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
228+
["inferReturnTypeComponents"]>,
229+
ResultsBroadcastableShape, Pure, SameOperandsAndResultElementType])> {
230+
}
231+
218232
#endif // TOSA_OP_BASE

0 commit comments

Comments
 (0)