From 2364dcd7241d730021bf68e000e5a6411b9f09d1 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Mon, 26 Apr 2021 11:06:57 -0700 Subject: Initial commit of serialization library code Change-Id: Ie09a7245176aa799e59622e5118b145833b23590 Signed-off-by: Eric Kunze --- schema/tosa.fbs | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 307 insertions(+) create mode 100644 schema/tosa.fbs (limited to 'schema/tosa.fbs') diff --git a/schema/tosa.fbs b/schema/tosa.fbs new file mode 100644 index 0000000..c02154d --- /dev/null +++ b/schema/tosa.fbs @@ -0,0 +1,307 @@ + +// Copyright (c) 2020-2021, ARM Limited. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. + +namespace tosa; + +// This corresponds to the version. +file_identifier "TOSA"; +// File extension of any written files. +file_extension "tosa"; + +enum DType:uint32 { + UNKNOWN = 0, + BOOL, + UINT8, + INT4, + INT8, + INT16, + INT32, + INT48, + FLOAT, +} + +enum ResizeMode:uint32 { + UNKNOWN = 0, + NEAREST, + BILINEAR, +} + +enum Op:uint32 { + UNKNOWN = 0, + + // Tensor Operator + ARGMAX, + AVG_POOL2D, + CONV2D, + CONV3D, + DEPTHWISE_CONV2D, + FULLY_CONNECTED, + MATMUL, + MAX_POOL2D, + TRANSPOSE_CONV2D, + + // Activation + CLAMP, + RELUN, + SIGMOID, + TANH, + + // Elementwise-Binary + ADD, + ARITHMETIC_RIGHT_SHIFT, + BITWISE_AND, + BITWISE_OR, + BITWISE_XOR, + LOGICAL_AND, + LOGICAL_LEFT_SHIFT, + LOGICAL_RIGHT_SHIFT, + LOGICAL_OR, + LOGICAL_XOR, + MAXIMUM, + MINIMUM, + MUL, + POW, + SUB, + TABLE, + + // Elementwise-Unary + ABS, + BITWISE_NOT, + CEIL, + CLZ, + EXP, + FLOOR, + LOG, + LOGICAL_NOT, + NEGATE, + RECIPROCAL, + RSQRT, + + // Elementwise-Ternary + SELECT, + + // Logical + EQUAL, + GREATER, + GREATER_EQUAL, + + // Reduction + REDUCE_ANY, + REDUCE_ALL, + REDUCE_MAX, + REDUCE_MIN, + REDUCE_PRODUCT, + REDUCE_SUM, + + // Data layout operation + CONCAT, + PAD, + RESHAPE, + REVERSE, + SLICE, + TILE, + TRANSPOSE, + + // Gather/scatter operation + GATHER, + SCATTER, + + // Image + RESIZE, + + // Type conversion + CAST, + RESCALE, + + // Data Nodes + CONST, + PLACEHOLDER, + IDENTITY, + IDENTITYN, + + // Custom operations + CUSTOM, + + // Control flow operators + COND_IF, + WHILE_LOOP, +} + +union Attribute { + Pool2dAttribute, + Conv2dAttribute, + TransposeConv2dAttribute, + ReluNAttribute, + AxisAttribute, + ReshapeAttribute, + SliceAttribute, + TileAttribute, + ResizeAttribute, + ClampAttribute, + RescaleAttribute, + MulAttribute, + ArithmeticRightShiftAttribute, + CondIfAttribute, + WhileLoopAttribute, +} + +table Pool2dAttribute { + padding: [int32]; + kernel: [int32]; + stride: [int32]; +} + +table Conv2dAttribute { + padding: [int32]; + stride: [int32]; + dilation: [int32]; +} + +table TransposeConv2dAttribute { + outpad: [int32]; + stride: [int32]; + dilation: [int32]; + output_shape: [int32]; +} + +table ReluNAttribute { + max_int: int32; + max_fp: float; +} + +table AxisAttribute { + axis: int32; +} + +table ReshapeAttribute { + shape: [int32]; +} + +table SliceAttribute { + begin: [int32]; + size: [int32]; +} + +table TileAttribute { + multiples: [int32]; +} + +table ResizeAttribute { + output_size: [int32]; + stride: [int32]; + offset: [int32]; + shift: int32; + stride_fp: [float]; + offset_fp: [float]; + mode: ResizeMode; +} + +table ClampAttribute { + min_int: int32; + max_int: int32; + min_fp: float; + max_fp: float; +} + +table RescaleAttribute { + input_zp: int32; + output_zp: int32; + multiplier: [int32]; + shift: [int32]; + scale32: bool; + double_round: bool; + per_channel: bool; +} + +table MulAttribute { + shift: int32; +} + +table ArithmeticRightShiftAttribute { + round: bool; +} + +table CondIfAttribute { + then_branch: string; + else_branch: string; +} + +table WhileLoopAttribute { + cond_branch: string; + body_branch: string; +} + +union QuantInfo { + UnaryQuantInfo, + ConvQuantInfo, + MatMulQuantInfo, + PadQuantInfo, +} + +table UnaryQuantInfo { + input_zp: int32; + output_zp: int32; +} + +table ConvQuantInfo { + input_zp: int32; + weight_zp: int32; +} + +table MatMulQuantInfo { + a_zp: int32; + b_zp: int32; +} + +table PadQuantInfo { + input_zp: int32; +} + +table Version { + _major: int32 = 0; + _minor: int32 = 21; + _patch: int32 = 0; + _experimental: bool = false; +} + +table TosaTensor { + name:string; // name of the tensor, used for solving dependency + shape:[int32]; // shape of the tensor + type:DType; // data type of the tensor + npy_filename: string; // numpy array filename +} + +table TosaOperator { + op:Op; // operator enum + attribute: Attribute; // union structure. operator attribute + inputs:[string]; // list of input tensor names + outputs:[string]; // list of output tensor names + quant_info: QuantInfo; // op-based quantization information +} + +table TosaBasicBlock { + name:string; // basic block name + operators:[TosaOperator]; // operators array + tensors:[TosaTensor]; // tensors array + inputs:[string]; // name of graph inputs + outputs:[string]; // name of graph outputs +} + +table TosaGraph { + version: Version; + blocks:[TosaBasicBlock]; // basic blocks array +} + +root_type TosaGraph; -- cgit v1.2.1