Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | namespace armnn.armnnSerializer; |
| 7 | |
| 8 | file_identifier "ARMN"; |
| 9 | |
| 10 | file_extension "armnn"; |
| 11 | |
| 12 | enum DataType : byte { |
| 13 | Float16 = 0, |
| 14 | Float32 = 1, |
| 15 | QuantisedAsymm8 = 2, |
| 16 | Signed32 = 3, |
| 17 | Boolean = 4 |
| 18 | } |
| 19 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 20 | enum DataLayout : byte { |
| 21 | NHWC = 0, |
| 22 | NCHW = 1 |
| 23 | } |
| 24 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 25 | table TensorInfo { |
| 26 | dimensions:[uint]; |
| 27 | dataType:DataType; |
| 28 | quantizationScale:float = 1.0; |
| 29 | quantizationOffset:int = 0; |
| 30 | } |
| 31 | |
| 32 | struct Connection { |
| 33 | sourceLayerIndex:uint; |
| 34 | outputSlotIndex:uint; |
| 35 | } |
| 36 | |
| 37 | table ByteData { |
| 38 | data:[byte]; |
| 39 | } |
| 40 | |
| 41 | table ShortData { |
| 42 | data:[short]; |
| 43 | } |
| 44 | |
| 45 | table IntData { |
| 46 | data:[int]; |
| 47 | } |
| 48 | |
| 49 | table LongData { |
| 50 | data:[long]; |
| 51 | } |
| 52 | |
| 53 | union ConstTensorData { ByteData, ShortData, IntData, LongData } |
| 54 | |
| 55 | table ConstTensor { |
| 56 | info:TensorInfo; |
| 57 | data:ConstTensorData; |
| 58 | } |
| 59 | |
| 60 | table InputSlot { |
| 61 | index:uint; |
| 62 | connection:Connection; |
| 63 | } |
| 64 | |
| 65 | table OutputSlot { |
| 66 | index:uint; |
| 67 | tensorInfo:TensorInfo; |
| 68 | } |
| 69 | |
| 70 | enum LayerType : uint { |
| 71 | Addition = 0, |
| 72 | Input = 1, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 73 | Multiplication = 2, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 74 | Output = 3, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 75 | Pooling2d = 4, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 76 | Reshape = 5, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 77 | Softmax = 6, |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame^] | 78 | Convolution2d = 7, |
| 79 | DepthwiseConvolution2d = 8 |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Base layer table to be used as part of other layers |
| 83 | table LayerBase { |
| 84 | index:uint; |
| 85 | layerName:string; |
| 86 | layerType:LayerType; |
| 87 | inputSlots:[InputSlot]; |
| 88 | outputSlots:[OutputSlot]; |
| 89 | } |
| 90 | |
| 91 | table BindableLayerBase { |
| 92 | base:LayerBase; |
| 93 | layerBindingId:int; |
| 94 | } |
| 95 | |
| 96 | // Table for each layer defined below |
| 97 | table AdditionLayer { |
| 98 | base:LayerBase; |
| 99 | } |
| 100 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 101 | table Convolution2dLayer { |
| 102 | base:LayerBase; |
| 103 | descriptor:Convolution2dDescriptor; |
| 104 | weights:ConstTensor; |
| 105 | biases:ConstTensor; |
| 106 | } |
| 107 | |
| 108 | table Convolution2dDescriptor { |
| 109 | padLeft:uint; |
| 110 | padRight:uint; |
| 111 | padTop:uint; |
| 112 | padBottom:uint; |
| 113 | strideX:uint; |
| 114 | strideY:uint; |
| 115 | biasEnabled:bool = false; |
| 116 | dataLayout:DataLayout = NCHW; |
| 117 | } |
| 118 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 119 | table InputLayer { |
| 120 | base:BindableLayerBase; |
| 121 | } |
| 122 | |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 123 | table MultiplicationLayer { |
| 124 | base:LayerBase; |
| 125 | } |
| 126 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 127 | table Pooling2dLayer { |
| 128 | base:LayerBase; |
| 129 | descriptor:Pooling2dDescriptor; |
| 130 | } |
| 131 | |
| 132 | enum PoolingAlgorithm : byte { |
| 133 | Max = 0, |
| 134 | Average = 1, |
| 135 | L2 = 2 |
| 136 | } |
| 137 | |
| 138 | enum OutputShapeRounding : byte { |
| 139 | Floor = 0, |
| 140 | Ceiling = 1 |
| 141 | } |
| 142 | |
| 143 | enum PaddingMethod : byte { |
| 144 | IgnoreValue = 0, |
| 145 | Exclude = 1 |
| 146 | } |
| 147 | |
| 148 | table Pooling2dDescriptor { |
| 149 | poolType:PoolingAlgorithm; |
| 150 | padLeft:uint; |
| 151 | padRight:uint; |
| 152 | padTop:uint; |
| 153 | padBottom:uint; |
| 154 | poolWidth:uint; |
| 155 | poolHeight:uint; |
| 156 | strideX:uint; |
| 157 | strideY:uint; |
| 158 | outputShapeRounding:OutputShapeRounding; |
| 159 | paddingMethod:PaddingMethod; |
| 160 | dataLayout:DataLayout; |
| 161 | } |
| 162 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 163 | table SoftmaxLayer { |
| 164 | base:LayerBase; |
| 165 | descriptor:SoftmaxDescriptor; |
| 166 | } |
| 167 | |
| 168 | table SoftmaxDescriptor { |
| 169 | beta:float; |
| 170 | } |
| 171 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame^] | 172 | table DepthwiseConvolution2dLayer { |
| 173 | base:LayerBase; |
| 174 | descriptor:DepthwiseConvolution2dDescriptor; |
| 175 | weights:ConstTensor; |
| 176 | biases:ConstTensor; |
| 177 | } |
| 178 | |
| 179 | table DepthwiseConvolution2dDescriptor { |
| 180 | padLeft:uint; |
| 181 | padRight:uint; |
| 182 | padTop:uint; |
| 183 | padBottom:uint; |
| 184 | strideX:uint; |
| 185 | strideY:uint; |
| 186 | biasEnabled:bool = false; |
| 187 | dataLayout:DataLayout = NCHW; |
| 188 | } |
| 189 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 190 | table OutputLayer { |
| 191 | base:BindableLayerBase; |
| 192 | } |
| 193 | |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 194 | table ReshapeLayer { |
| 195 | base:LayerBase; |
| 196 | descriptor:ReshapeDescriptor; |
| 197 | } |
| 198 | |
| 199 | table ReshapeDescriptor { |
| 200 | targetShape:[uint]; |
| 201 | } |
| 202 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 203 | union Layer { |
| 204 | AdditionLayer, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 205 | Convolution2dLayer, |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame^] | 206 | DepthwiseConvolution2dLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 207 | InputLayer, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 208 | MultiplicationLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 209 | OutputLayer, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 210 | Pooling2dLayer, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 211 | ReshapeLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 212 | SoftmaxLayer |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 215 | table AnyLayer { |
| 216 | layer:Layer; |
| 217 | } |
| 218 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 219 | // Root type for serialized data is the graph of the network |
| 220 | table SerializedGraph { |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 221 | layers:[AnyLayer]; |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 222 | inputIds:[uint]; |
| 223 | outputIds:[uint]; |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | root_type SerializedGraph; |