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, |
| 78 | Convolution2d = 7 |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Base layer table to be used as part of other layers |
| 82 | table LayerBase { |
| 83 | index:uint; |
| 84 | layerName:string; |
| 85 | layerType:LayerType; |
| 86 | inputSlots:[InputSlot]; |
| 87 | outputSlots:[OutputSlot]; |
| 88 | } |
| 89 | |
| 90 | table BindableLayerBase { |
| 91 | base:LayerBase; |
| 92 | layerBindingId:int; |
| 93 | } |
| 94 | |
| 95 | // Table for each layer defined below |
| 96 | table AdditionLayer { |
| 97 | base:LayerBase; |
| 98 | } |
| 99 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame^] | 100 | table Convolution2dLayer { |
| 101 | base:LayerBase; |
| 102 | descriptor:Convolution2dDescriptor; |
| 103 | weights:ConstTensor; |
| 104 | biases:ConstTensor; |
| 105 | } |
| 106 | |
| 107 | table Convolution2dDescriptor { |
| 108 | padLeft:uint; |
| 109 | padRight:uint; |
| 110 | padTop:uint; |
| 111 | padBottom:uint; |
| 112 | strideX:uint; |
| 113 | strideY:uint; |
| 114 | biasEnabled:bool = false; |
| 115 | dataLayout:DataLayout = NCHW; |
| 116 | } |
| 117 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 118 | table InputLayer { |
| 119 | base:BindableLayerBase; |
| 120 | } |
| 121 | |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 122 | table MultiplicationLayer { |
| 123 | base:LayerBase; |
| 124 | } |
| 125 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 126 | table Pooling2dLayer { |
| 127 | base:LayerBase; |
| 128 | descriptor:Pooling2dDescriptor; |
| 129 | } |
| 130 | |
| 131 | enum PoolingAlgorithm : byte { |
| 132 | Max = 0, |
| 133 | Average = 1, |
| 134 | L2 = 2 |
| 135 | } |
| 136 | |
| 137 | enum OutputShapeRounding : byte { |
| 138 | Floor = 0, |
| 139 | Ceiling = 1 |
| 140 | } |
| 141 | |
| 142 | enum PaddingMethod : byte { |
| 143 | IgnoreValue = 0, |
| 144 | Exclude = 1 |
| 145 | } |
| 146 | |
| 147 | table Pooling2dDescriptor { |
| 148 | poolType:PoolingAlgorithm; |
| 149 | padLeft:uint; |
| 150 | padRight:uint; |
| 151 | padTop:uint; |
| 152 | padBottom:uint; |
| 153 | poolWidth:uint; |
| 154 | poolHeight:uint; |
| 155 | strideX:uint; |
| 156 | strideY:uint; |
| 157 | outputShapeRounding:OutputShapeRounding; |
| 158 | paddingMethod:PaddingMethod; |
| 159 | dataLayout:DataLayout; |
| 160 | } |
| 161 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 162 | table SoftmaxLayer { |
| 163 | base:LayerBase; |
| 164 | descriptor:SoftmaxDescriptor; |
| 165 | } |
| 166 | |
| 167 | table SoftmaxDescriptor { |
| 168 | beta:float; |
| 169 | } |
| 170 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 171 | table OutputLayer { |
| 172 | base:BindableLayerBase; |
| 173 | } |
| 174 | |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 175 | table ReshapeLayer { |
| 176 | base:LayerBase; |
| 177 | descriptor:ReshapeDescriptor; |
| 178 | } |
| 179 | |
| 180 | table ReshapeDescriptor { |
| 181 | targetShape:[uint]; |
| 182 | } |
| 183 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 184 | union Layer { |
| 185 | AdditionLayer, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame^] | 186 | Convolution2dLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 187 | InputLayer, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 188 | MultiplicationLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 189 | OutputLayer, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 190 | Pooling2dLayer, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 191 | ReshapeLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 192 | SoftmaxLayer |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 195 | table AnyLayer { |
| 196 | layer:Layer; |
| 197 | } |
| 198 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 199 | // Root type for serialized data is the graph of the network |
| 200 | table SerializedGraph { |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 201 | layers:[AnyLayer]; |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 202 | inputIds:[uint]; |
| 203 | outputIds:[uint]; |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | root_type SerializedGraph; |