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