Skip to content

Commit

Permalink
[mlir][TOSA]Add optional attributes to TOSA custom op
Browse files Browse the repository at this point in the history
The implementation_attrs attr allows passing of backend specific
attributes to TOSA custom ops.

Also adds a config option to avoid namespace collisions on the
identifier.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D137133
  • Loading branch information
eric-k256 authored and rsuderman committed Nov 1, 2022
1 parent d71a8ad commit d94ee70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
Expand Up @@ -1793,10 +1793,26 @@ def Tosa_CustomOp : Tosa_Op<"custom"> {
that are not expressed in the existing TOSA operations. These operators are
not expected to be portable across TOSA implementations. The input and
output signatures must be expressed in the corresponding TOSA node.

`identifier` is a string that tells the backend which custom operator is being
called.

`config` is a string identifier which can help avoid name collisions on the
identifier field.

`implementation_attrs` is a string which is a backend and identifier specific
set of attributes to the custom operator.

`inputs` is the set of tensor inputs to the custom operator.

`outputs is the list of tensors returned by the operator. The number of operators
is backend specific.
}];

let arguments = (ins
StrAttr:$identifier,
StrAttr:$config,
StrAttr:$implementation_attrs,
Variadic<Tosa_Tensor>:$inputs
);

Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Dialect/Tosa/ops.mlir
Expand Up @@ -529,3 +529,10 @@ func.func @test_while_loop(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {
}) : (tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<10xi32>)
return
}

// -----
// CHECK-LABEL: custom
func.func @test_custom(%arg0: tensor<10xi32>) -> tensor<10xi32> {
%0 = "tosa.custom"(%arg0) {identifier="custom_test", config="tosa_mlir_test", implementation_attrs=""} : (tensor<10xi32>) -> (tensor<10xi32>)
return %0 : tensor<10xi32>
}

0 comments on commit d94ee70

Please sign in to comment.