diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/DeserializationPasses.h | 46 | ||||
-rw-r--r-- | include/DeserializationPasses.td | 25 | ||||
-rw-r--r-- | include/SerializationPasses.h | 6 | ||||
-rw-r--r-- | include/SerializationPasses.td | 2 | ||||
-rw-r--r-- | include/operator.def | 22 | ||||
-rw-r--r-- | include/schema_operator.def | 103 |
6 files changed, 197 insertions, 7 deletions
diff --git a/include/DeserializationPasses.h b/include/DeserializationPasses.h new file mode 100644 index 0000000..1a38814 --- /dev/null +++ b/include/DeserializationPasses.h @@ -0,0 +1,46 @@ + +// Copyright (c) 2023, ARM Limited. +// +// Licensed under the Apache License, Version 2.0 with LLVM Exceptions +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://llvm.org/LICENSE.txt +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDE_DESERIALIZATION_PASSES_H +#define INCLUDE_DESERIALIZATION_PASSES_H + +#include <memory> + +#include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project +#include "mlir/IR/BuiltinOps.h" // from @llvm-project +#include "mlir/IR/OwningOpRef.h" // from @llvm-project +#include "mlir/Pass/Pass.h" // from @llvm-project + +namespace mlir { +namespace tosa { + +std::unique_ptr<Pass> createTosaDeserializePass(); +std::unique_ptr<Pass> createTosaDeserializeJSONPass(); + +// deserializes a tosa file and return an mlir module +// if file_is_fbs is true, then treat file_name as a tosa flatbuffer file +// otherwise, treat file_name as a tosa json file +mlir::OwningOpRef<mlir::ModuleOp> +BuildMlirFromTosaFile(const char *file_name, mlir::MLIRContext *context, + bool file_is_fbs = true); + +#define GEN_PASS_REGISTRATION +#define GEN_PASS_CLASSES +#include "include/DeserializationPasses.h.inc" + +} // namespace tosa +} // namespace mlir + +#endif // INCLUDE_DESERIALIZATION_PASSES_H diff --git a/include/DeserializationPasses.td b/include/DeserializationPasses.td new file mode 100644 index 0000000..999f0b4 --- /dev/null +++ b/include/DeserializationPasses.td @@ -0,0 +1,25 @@ +// Copyright (c) 2023, ARM Limited. +// +// Licensed under the Apache License, Version 2.0 with LLVM Exceptions +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://llvm.org/LICENSE.txt +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +include "mlir/Pass/PassBase.td" + +def TosaDeserializationPass : Pass<"tosa-deserialize", "func::FuncOp"> { + let summary = "Deserialize TOSA flatbuffer. Clear original MLIR graph and generate TOSA MLIR"; + let constructor = "createTosaDeserializePass()"; +} + +def TosaDeserializationJSONPass : Pass<"tosa-deserialize-json", "func::FuncOp"> { + let summary = "Deserialize TOSA flatbuffer JSON form. Clear original MLIR graph and generate TOSA MLIR"; + let constructor = "createTosaDeserializeJSONPass()"; +} diff --git a/include/SerializationPasses.h b/include/SerializationPasses.h index 66c6d80..c769b15 100644 --- a/include/SerializationPasses.h +++ b/include/SerializationPasses.h @@ -19,16 +19,18 @@ #include <memory> #include "mlir/Dialect/Func/IR/FuncOps.h" // from @llvm-project -#include "mlir/Pass/Pass.h" // from @llvm-project +#include "mlir/IR/BuiltinOps.h" +#include "mlir/Pass/Pass.h" // from @llvm-project namespace mlir { namespace tosa { -std::unique_ptr<Pass> createTosaSerializePass(); +std::unique_ptr<OperationPass<ModuleOp>> createTosaSerializePass(); std::unique_ptr<Pass> createTosaSerializeJSONPass(); #define GEN_PASS_REGISTRATION #define GEN_PASS_CLASSES +#define GEN_PASS_DECL_TOSASERIALIZEPASS #include "include/SerializationPasses.h.inc" } // namespace tosa diff --git a/include/SerializationPasses.td b/include/SerializationPasses.td index 3bdeb1b..9cfc204 100644 --- a/include/SerializationPasses.td +++ b/include/SerializationPasses.td @@ -14,7 +14,7 @@ include "mlir/Pass/PassBase.td" -def TosaSerializationPass : Pass<"tosa-serialize", "func::FuncOp"> { +def TosaSerializationPass : Pass<"tosa-serialize", "mlir::ModuleOp"> { let summary = "Generate TOSA flatbuffer serialized form"; let constructor = "createTosaSerializePass()"; } diff --git a/include/operator.def b/include/operator.def index 85bb5c9..0bd0d08 100644 --- a/include/operator.def +++ b/include/operator.def @@ -1,8 +1,8 @@ -// Copyright (c) 2020-2021, ARM Limited. +// Copyright (c) 2020-2024, ARM Limited. // -// Licensed under the Apache License, Version 2.0 with LLVM Exceptions -// (the "License"); you may not use this file except in compliance with +// Licensed under the Apache License, Version 2.0 with LLVM Exceptions +// (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // https://llvm.org/LICENSE.txt @@ -27,12 +27,15 @@ DEF_OPERATOR(AvgPool2d) DEF_OPERATOR(Conv2D) DEF_OPERATOR(Conv3D) DEF_OPERATOR(DepthwiseConv2D) +DEF_OPERATOR(FFT2d) DEF_OPERATOR(FullyConnected) DEF_OPERATOR(MatMul) DEF_OPERATOR(MaxPool2d) +DEF_OPERATOR(RFFT2d) DEF_OPERATOR(TransposeConv2D) /* activation */ +DEF_OPERATOR(Erf) DEF_OPERATOR(Clamp) DEF_OPERATOR(Sigmoid) DEF_OPERATOR(Tanh) @@ -43,7 +46,7 @@ DEF_OPERATOR(ArithmeticRightShift) DEF_OPERATOR(BitwiseAnd) DEF_OPERATOR(BitwiseOr) DEF_OPERATOR(BitwiseXor) -DEF_OPERATOR(Div) +DEF_OPERATOR(IntDiv) DEF_OPERATOR(LogicalAnd) DEF_OPERATOR(LogicalLeftShift) DEF_OPERATOR(LogicalRightShift) @@ -61,6 +64,7 @@ DEF_OPERATOR(Abs) DEF_OPERATOR(BitwiseNot) DEF_OPERATOR(Ceil) DEF_OPERATOR(Clz) +DEF_OPERATOR(Cos) DEF_OPERATOR(Exp) DEF_OPERATOR(Floor) DEF_OPERATOR(Log) @@ -68,6 +72,7 @@ DEF_OPERATOR(LogicalNot) DEF_OPERATOR(Negate) DEF_OPERATOR(Reciprocal) DEF_OPERATOR(Rsqrt) +DEF_OPERATOR(Sin) /* elementwise - ternary */ DEF_OPERATOR(Select) @@ -88,6 +93,7 @@ DEF_OPERATOR(ReduceSum) /* memory operation */ DEF_OPERATOR(Concat) DEF_OPERATOR(Pad) +DEF_OPERATOR(Dim) DEF_OPERATOR(Reshape) DEF_OPERATOR(Reverse) DEF_OPERATOR(Slice) @@ -115,3 +121,11 @@ DEF_OPERATOR(Custom) /* control flow operators */ DEF_OPERATOR(If) DEF_OPERATOR(While) + +/* shape operators */ +DEF_OPERATOR(ConstShape) +DEF_OPERATOR(ConcatShape) +DEF_OPERATOR(AddShape) +DEF_OPERATOR(SubShape) +DEF_OPERATOR(MulShape) +DEF_OPERATOR(DivShape) diff --git a/include/schema_operator.def b/include/schema_operator.def new file mode 100644 index 0000000..02b639e --- /dev/null +++ b/include/schema_operator.def @@ -0,0 +1,103 @@ +// Copyright (c) 2023-2024, ARM Limited. +// +// Licensed under the Apache License, Version 2.0 with LLVM Exceptions +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://llvm.org/LICENSE.txt +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* + Syntax: + DEF_SCHEMA_OPERATOR(SCHEMA_OP_NAME) + + Description: + SCHEMA_OP_NAME: the schema operator names, must match Op names in schema/tosa.fbs in serialization_lib repo +*/ + +/* schema operators */ +DEF_SCHEMA_OPERATOR(ARGMAX) +DEF_SCHEMA_OPERATOR(AVG_POOL2D) +DEF_SCHEMA_OPERATOR(CONV2D) +DEF_SCHEMA_OPERATOR(CONV3D) +DEF_SCHEMA_OPERATOR(DEPTHWISE_CONV2D) +DEF_SCHEMA_OPERATOR(FULLY_CONNECTED) +DEF_SCHEMA_OPERATOR(MATMUL) +DEF_SCHEMA_OPERATOR(MAX_POOL2D) +DEF_SCHEMA_OPERATOR(TRANSPOSE_CONV2D) +DEF_SCHEMA_OPERATOR(CLAMP) +DEF_SCHEMA_OPERATOR(RESERVED) +DEF_SCHEMA_OPERATOR(ERF) +DEF_SCHEMA_OPERATOR(SIGMOID) +DEF_SCHEMA_OPERATOR(TANH) +DEF_SCHEMA_OPERATOR(ADD) +DEF_SCHEMA_OPERATOR(ARITHMETIC_RIGHT_SHIFT) +DEF_SCHEMA_OPERATOR(BITWISE_AND) +DEF_SCHEMA_OPERATOR(BITWISE_OR) +DEF_SCHEMA_OPERATOR(BITWISE_XOR) +DEF_SCHEMA_OPERATOR(INTDIV) +DEF_SCHEMA_OPERATOR(LOGICAL_AND) +DEF_SCHEMA_OPERATOR(LOGICAL_LEFT_SHIFT) +DEF_SCHEMA_OPERATOR(LOGICAL_RIGHT_SHIFT) +DEF_SCHEMA_OPERATOR(LOGICAL_OR) +DEF_SCHEMA_OPERATOR(LOGICAL_XOR) +DEF_SCHEMA_OPERATOR(MAXIMUM) +DEF_SCHEMA_OPERATOR(MINIMUM) +DEF_SCHEMA_OPERATOR(MUL) +DEF_SCHEMA_OPERATOR(POW) +DEF_SCHEMA_OPERATOR(SUB) +DEF_SCHEMA_OPERATOR(TABLE) +DEF_SCHEMA_OPERATOR(ABS) +DEF_SCHEMA_OPERATOR(BITWISE_NOT) +DEF_SCHEMA_OPERATOR(CEIL) +DEF_SCHEMA_OPERATOR(CLZ) +DEF_SCHEMA_OPERATOR(EXP) +DEF_SCHEMA_OPERATOR(FLOOR) +DEF_SCHEMA_OPERATOR(LOG) +DEF_SCHEMA_OPERATOR(LOGICAL_NOT) +DEF_SCHEMA_OPERATOR(NEGATE) +DEF_SCHEMA_OPERATOR(RECIPROCAL) +DEF_SCHEMA_OPERATOR(RSQRT) +DEF_SCHEMA_OPERATOR(SELECT) +DEF_SCHEMA_OPERATOR(EQUAL) +DEF_SCHEMA_OPERATOR(GREATER) +DEF_SCHEMA_OPERATOR(GREATER_EQUAL) +DEF_SCHEMA_OPERATOR(REDUCE_ANY) +DEF_SCHEMA_OPERATOR(REDUCE_ALL) +DEF_SCHEMA_OPERATOR(REDUCE_MAX) +DEF_SCHEMA_OPERATOR(REDUCE_MIN) +DEF_SCHEMA_OPERATOR(REDUCE_PRODUCT) +DEF_SCHEMA_OPERATOR(REDUCE_SUM) +DEF_SCHEMA_OPERATOR(CONCAT) +DEF_SCHEMA_OPERATOR(PAD) +DEF_SCHEMA_OPERATOR(DIM) +DEF_SCHEMA_OPERATOR(RESHAPE) +DEF_SCHEMA_OPERATOR(REVERSE) +DEF_SCHEMA_OPERATOR(SLICE) +DEF_SCHEMA_OPERATOR(TILE) +DEF_SCHEMA_OPERATOR(TRANSPOSE) +DEF_SCHEMA_OPERATOR(GATHER) +DEF_SCHEMA_OPERATOR(SCATTER) +DEF_SCHEMA_OPERATOR(RESIZE) +DEF_SCHEMA_OPERATOR(CAST) +DEF_SCHEMA_OPERATOR(RESCALE) +DEF_SCHEMA_OPERATOR(CONST) +DEF_SCHEMA_OPERATOR(IDENTITY) +DEF_SCHEMA_OPERATOR(CUSTOM) +DEF_SCHEMA_OPERATOR(COND_IF) +DEF_SCHEMA_OPERATOR(WHILE_LOOP) +DEF_SCHEMA_OPERATOR(FFT2D) +DEF_SCHEMA_OPERATOR(RFFT2D) +DEF_SCHEMA_OPERATOR(CONST_SHAPE) +DEF_SCHEMA_OPERATOR(CONCAT_SHAPE) +DEF_SCHEMA_OPERATOR(ADD_SHAPE) +DEF_SCHEMA_OPERATOR(SUB_SHAPE) +DEF_SCHEMA_OPERATOR(MUL_SHAPE) +DEF_SCHEMA_OPERATOR(DIV_SHAPE) +DEF_SCHEMA_OPERATOR(COS) +DEF_SCHEMA_OPERATOR(SIN)
\ No newline at end of file |