telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include "CpuTensorHandleFwd.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | #include "WorkloadDataFwd.hpp" |
| 9 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <InternalTypes.hpp> |
| 11 | |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 12 | #include <armnn/Descriptors.hpp> |
| 13 | #include <armnn/Exceptions.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 14 | #include <armnn/Types.hpp> |
| 15 | #include <armnn/Tensor.hpp> |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 16 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 17 | #include <backendsCommon/OutputHandler.hpp> |
| 18 | #include <backendsCommon/WorkloadInfo.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | |
| 20 | namespace armnn |
| 21 | { |
| 22 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 23 | //A helper function that returns the bias data type required for given input data type. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | DataType GetBiasDataType(DataType inputDataType); |
| 25 | |
| 26 | struct WorkloadInfo; |
| 27 | |
| 28 | struct QueueDescriptor |
| 29 | { |
| 30 | std::vector<ITensorHandle*> m_Inputs; |
| 31 | std::vector<ITensorHandle*> m_Outputs; |
| 32 | |
| 33 | void ValidateInputsOutputs(const std::string& descName, |
| 34 | unsigned int numExpectedIn, unsigned int numExpectedOut) const; |
| 35 | |
| 36 | |
| 37 | protected: |
| 38 | ~QueueDescriptor() = default; |
| 39 | QueueDescriptor() = default; |
| 40 | QueueDescriptor(QueueDescriptor const&) = default; |
| 41 | QueueDescriptor& operator=(QueueDescriptor const&) = default; |
| 42 | }; |
| 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | // Base class for queue descriptors which contain parameters. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | template <typename LayerDescriptor> |
| 46 | struct QueueDescriptorWithParameters : public QueueDescriptor |
| 47 | { |
| 48 | LayerDescriptor m_Parameters; |
| 49 | |
| 50 | protected: |
| 51 | ~QueueDescriptorWithParameters() = default; |
| 52 | QueueDescriptorWithParameters() = default; |
| 53 | QueueDescriptorWithParameters(QueueDescriptorWithParameters const&) = default; |
| 54 | QueueDescriptorWithParameters& operator=(QueueDescriptorWithParameters const&) = default; |
| 55 | }; |
| 56 | |
| 57 | struct MemCopyQueueDescriptor : QueueDescriptor |
| 58 | { |
| 59 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 60 | }; |
| 61 | |
| 62 | using InputQueueDescriptor = MemCopyQueueDescriptor; |
| 63 | using OutputQueueDescriptor = MemCopyQueueDescriptor; |
| 64 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 65 | // Softmax layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 66 | struct SoftmaxQueueDescriptor : QueueDescriptorWithParameters<SoftmaxDescriptor> |
| 67 | { |
| 68 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 69 | }; |
| 70 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 71 | // Splitter layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | struct SplitterQueueDescriptor : QueueDescriptorWithParameters<ViewsDescriptor> |
| 73 | { |
| 74 | struct ViewOrigin |
| 75 | { |
| 76 | ViewOrigin() {} |
| 77 | ViewOrigin(std::vector<unsigned int> const& origin) : m_Origin(origin) {} |
| 78 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 79 | //View origin (size of the vector is the same as number of dimensions of the view). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 80 | std::vector<unsigned int> m_Origin; |
| 81 | }; |
| 82 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 83 | //View defines a tensor that will be carved from the input tensor. |
| 84 | //View origins are stored here, the extents are defined by sizes of the output tensors. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | std::vector<ViewOrigin> m_ViewOrigins; |
| 86 | |
| 87 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 88 | }; |
| 89 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 90 | // Merger layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | struct MergerQueueDescriptor : QueueDescriptorWithParameters<OriginsDescriptor> |
| 92 | { |
| 93 | struct ViewOrigin |
| 94 | { |
| 95 | ViewOrigin() {} |
| 96 | ViewOrigin(const std::vector<unsigned int>& origin) : m_Origin(origin) {} |
| 97 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 98 | //View origin (size of the vector is the same as number of dimensions of the view). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 99 | std::vector<unsigned int> m_Origin; |
| 100 | }; |
| 101 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 102 | //View defines a sub-area of the output tensor that will be filled with the corresponding input tensor. |
| 103 | //View origins are stored here, the extents are defined by sizes of the input tensors. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 104 | std::vector<ViewOrigin> m_ViewOrigins; |
| 105 | |
| 106 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 107 | }; |
| 108 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 109 | // Activation layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 110 | struct ActivationQueueDescriptor : QueueDescriptorWithParameters<ActivationDescriptor> |
| 111 | { |
| 112 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 113 | }; |
| 114 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 115 | // Fully connected layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 116 | struct FullyConnectedQueueDescriptor : QueueDescriptorWithParameters<FullyConnectedDescriptor> |
| 117 | { |
| 118 | FullyConnectedQueueDescriptor() |
| 119 | : m_Weight(nullptr) |
| 120 | , m_Bias(nullptr) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | const ConstCpuTensorHandle* m_Weight; |
| 125 | const ConstCpuTensorHandle* m_Bias; |
| 126 | |
| 127 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 128 | }; |
| 129 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 130 | // Permute layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 131 | struct PermuteQueueDescriptor : QueueDescriptorWithParameters<PermuteDescriptor> |
| 132 | { |
| 133 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 134 | }; |
| 135 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 136 | // Pooling 2D layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 137 | struct Pooling2dQueueDescriptor : QueueDescriptorWithParameters<Pooling2dDescriptor> |
| 138 | { |
| 139 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 140 | }; |
| 141 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 142 | // Convolution 2D layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 143 | struct Convolution2dQueueDescriptor : QueueDescriptorWithParameters<Convolution2dDescriptor> |
| 144 | { |
| 145 | Convolution2dQueueDescriptor() |
| 146 | : m_Weight(nullptr) |
| 147 | , m_Bias(nullptr) |
| 148 | { |
| 149 | } |
| 150 | |
| 151 | const ConstCpuTensorHandle* m_Weight; |
| 152 | const ConstCpuTensorHandle* m_Bias; |
| 153 | |
| 154 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 155 | }; |
| 156 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 157 | // Depthwise Convolution 2D layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 158 | struct DepthwiseConvolution2dQueueDescriptor : QueueDescriptorWithParameters<DepthwiseConvolution2dDescriptor> |
| 159 | { |
| 160 | DepthwiseConvolution2dQueueDescriptor() |
| 161 | : m_Weight(nullptr) |
| 162 | , m_Bias(nullptr) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | const ConstCpuTensorHandle* m_Weight; |
| 167 | const ConstCpuTensorHandle* m_Bias; |
| 168 | |
| 169 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 170 | }; |
| 171 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 172 | // Normalization layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 173 | struct NormalizationQueueDescriptor : QueueDescriptorWithParameters<NormalizationDescriptor> |
| 174 | { |
| 175 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 176 | }; |
| 177 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 178 | // Add layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 179 | struct AdditionQueueDescriptor : QueueDescriptor |
| 180 | { |
| 181 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 182 | }; |
| 183 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 184 | // Multiplication layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 185 | struct MultiplicationQueueDescriptor : QueueDescriptor |
| 186 | { |
| 187 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 188 | }; |
| 189 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 190 | // Division layer workload data. |
| 191 | struct DivisionQueueDescriptor : QueueDescriptor |
| 192 | { |
| 193 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 194 | }; |
| 195 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 196 | // Subtraction layer workload data. |
| 197 | struct SubtractionQueueDescriptor : QueueDescriptor |
| 198 | { |
| 199 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 200 | }; |
| 201 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 202 | // Maximum layer workload data. |
| 203 | struct MaximumQueueDescriptor : QueueDescriptor |
| 204 | { |
| 205 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 206 | }; |
| 207 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 208 | // Mean layer workload data. |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 209 | struct MeanQueueDescriptor : QueueDescriptorWithParameters<MeanDescriptor> |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 210 | { |
| 211 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 212 | }; |
| 213 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 214 | // Pad layer workload data |
| 215 | struct PadQueueDescriptor : QueueDescriptorWithParameters<PadDescriptor> |
| 216 | { |
| 217 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 218 | }; |
| 219 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 220 | // Batch norm layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 221 | struct BatchNormalizationQueueDescriptor : QueueDescriptorWithParameters<BatchNormalizationDescriptor> |
| 222 | { |
| 223 | BatchNormalizationQueueDescriptor() |
| 224 | : m_Mean(nullptr) |
| 225 | , m_Variance(nullptr) |
| 226 | , m_Beta(nullptr) |
| 227 | , m_Gamma(nullptr) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | const ConstCpuTensorHandle* m_Mean; |
| 232 | const ConstCpuTensorHandle* m_Variance; |
| 233 | const ConstCpuTensorHandle* m_Beta; |
| 234 | const ConstCpuTensorHandle* m_Gamma; |
| 235 | |
| 236 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 237 | }; |
| 238 | |
| 239 | struct ResizeBilinearQueueDescriptor : QueueDescriptorWithParameters<ResizeBilinearDescriptor> |
| 240 | { |
| 241 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 242 | }; |
| 243 | |
| 244 | struct FakeQuantizationQueueDescriptor : QueueDescriptorWithParameters<FakeQuantizationDescriptor> |
| 245 | { |
| 246 | FakeQuantizationQueueDescriptor() |
| 247 | : m_Min(nullptr) |
| 248 | , m_Max(nullptr) |
| 249 | { |
| 250 | } |
| 251 | |
| 252 | const ConstCpuTensorHandle* m_Min; |
| 253 | const ConstCpuTensorHandle* m_Max; |
| 254 | |
| 255 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 256 | }; |
| 257 | |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 258 | struct L2NormalizationQueueDescriptor : QueueDescriptorWithParameters<L2NormalizationDescriptor> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 259 | { |
| 260 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 261 | }; |
| 262 | |
| 263 | struct ConstantQueueDescriptor : QueueDescriptor |
| 264 | { |
| 265 | ConstantQueueDescriptor() |
| 266 | : m_LayerOutput(nullptr) |
| 267 | { |
| 268 | } |
| 269 | |
| 270 | const ConstCpuTensorHandle* m_LayerOutput; |
| 271 | |
| 272 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 273 | }; |
| 274 | |
| 275 | struct ReshapeQueueDescriptor : QueueDescriptorWithParameters<ReshapeDescriptor> |
| 276 | { |
| 277 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 278 | }; |
| 279 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 280 | struct SpaceToBatchNdQueueDescriptor : QueueDescriptorWithParameters<SpaceToBatchNdDescriptor> |
| 281 | { |
| 282 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 283 | }; |
| 284 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 285 | struct FloorQueueDescriptor : QueueDescriptor |
| 286 | { |
| 287 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 288 | }; |
| 289 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 290 | struct LstmQueueDescriptor : QueueDescriptorWithParameters<LstmDescriptor> |
| 291 | { |
| 292 | LstmQueueDescriptor() |
| 293 | : m_InputToInputWeights(nullptr) |
| 294 | , m_InputToForgetWeights(nullptr) |
| 295 | , m_InputToCellWeights(nullptr) |
| 296 | , m_InputToOutputWeights(nullptr) |
| 297 | , m_RecurrentToInputWeights(nullptr) |
| 298 | , m_RecurrentToForgetWeights(nullptr) |
| 299 | , m_RecurrentToCellWeights(nullptr) |
| 300 | , m_RecurrentToOutputWeights(nullptr) |
| 301 | , m_CellToInputWeights(nullptr) |
| 302 | , m_CellToForgetWeights(nullptr) |
| 303 | , m_CellToOutputWeights(nullptr) |
| 304 | , m_InputGateBias(nullptr) |
| 305 | , m_ForgetGateBias(nullptr) |
| 306 | , m_CellBias(nullptr) |
| 307 | , m_OutputGateBias(nullptr) |
| 308 | , m_ProjectionWeights(nullptr) |
| 309 | , m_ProjectionBias(nullptr) |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | const ConstCpuTensorHandle* m_InputToInputWeights; |
| 314 | const ConstCpuTensorHandle* m_InputToForgetWeights; |
| 315 | const ConstCpuTensorHandle* m_InputToCellWeights; |
| 316 | const ConstCpuTensorHandle* m_InputToOutputWeights; |
| 317 | const ConstCpuTensorHandle* m_RecurrentToInputWeights; |
| 318 | const ConstCpuTensorHandle* m_RecurrentToForgetWeights; |
| 319 | const ConstCpuTensorHandle* m_RecurrentToCellWeights; |
| 320 | const ConstCpuTensorHandle* m_RecurrentToOutputWeights; |
| 321 | const ConstCpuTensorHandle* m_CellToInputWeights; |
| 322 | const ConstCpuTensorHandle* m_CellToForgetWeights; |
| 323 | const ConstCpuTensorHandle* m_CellToOutputWeights; |
| 324 | const ConstCpuTensorHandle* m_InputGateBias; |
| 325 | const ConstCpuTensorHandle* m_ForgetGateBias; |
| 326 | const ConstCpuTensorHandle* m_CellBias; |
| 327 | const ConstCpuTensorHandle* m_OutputGateBias; |
| 328 | const ConstCpuTensorHandle* m_ProjectionWeights; |
| 329 | const ConstCpuTensorHandle* m_ProjectionBias; |
| 330 | |
| 331 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 332 | }; |
| 333 | |
| 334 | struct ConvertFp16ToFp32QueueDescriptor : QueueDescriptor |
| 335 | { |
| 336 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 337 | }; |
| 338 | |
| 339 | struct ConvertFp32ToFp16QueueDescriptor : QueueDescriptor |
| 340 | { |
| 341 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 342 | }; |
| 343 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 344 | struct BatchToSpaceNdQueueDescriptor : QueueDescriptorWithParameters<BatchToSpaceNdDescriptor> |
| 345 | { |
| 346 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 347 | }; |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 348 | |
| 349 | struct StridedSliceQueueDescriptor : QueueDescriptorWithParameters<StridedSliceDescriptor> |
| 350 | { |
| 351 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 352 | }; |
| 353 | |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 354 | // Minimum layer workload data. |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 355 | struct MinimumQueueDescriptor : QueueDescriptor |
| 356 | { |
| 357 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 358 | }; |
| 359 | |
Nattapat Chaimanowong | ac5aa1f | 2018-12-05 15:17:18 +0000 | [diff] [blame] | 360 | struct DebugQueueDescriptor : QueueDescriptorWithParameters<DebugDescriptor> |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 361 | { |
| 362 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 363 | }; |
| 364 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 365 | } //namespace armnn |