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 | |
| 7 | #include "WorkloadDataFwd.hpp" |
| 8 | |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 9 | #include <armnn/Types.hpp> |
| 10 | #include <armnn/Tensor.hpp> |
| 11 | #include <armnn/Descriptors.hpp> |
| 12 | #include <armnn/Exceptions.hpp> |
David Beck | dcb751f | 2018-10-03 11:42:42 +0100 | [diff] [blame] | 13 | #include <backends/WorkloadInfo.hpp> |
David Beck | 0dbe0ee | 2018-09-24 15:59:27 +0100 | [diff] [blame] | 14 | |
| 15 | #include <InternalTypes.hpp> |
| 16 | #include <backends/OutputHandler.hpp> |
| 17 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | #include "CpuTensorHandleFwd.hpp" |
| 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) |
Nikhil Raj | a05c210 | 2018-09-25 16:16:13 +0100 | [diff] [blame] | 163 | , m_DataLayout(DataLayout::NCHW) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 164 | { |
| 165 | } |
| 166 | |
| 167 | const ConstCpuTensorHandle* m_Weight; |
| 168 | const ConstCpuTensorHandle* m_Bias; |
Nikhil Raj | a05c210 | 2018-09-25 16:16:13 +0100 | [diff] [blame] | 169 | DataLayout m_DataLayout; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 170 | |
| 171 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 172 | }; |
| 173 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 174 | // Normalization layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 175 | struct NormalizationQueueDescriptor : QueueDescriptorWithParameters<NormalizationDescriptor> |
| 176 | { |
| 177 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 178 | }; |
| 179 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 180 | // Add layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 181 | struct AdditionQueueDescriptor : QueueDescriptor |
| 182 | { |
| 183 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 184 | }; |
| 185 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 186 | // Multiplication layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 187 | struct MultiplicationQueueDescriptor : QueueDescriptor |
| 188 | { |
| 189 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 190 | }; |
| 191 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 192 | // Division layer workload data. |
| 193 | struct DivisionQueueDescriptor : QueueDescriptor |
| 194 | { |
| 195 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 196 | }; |
| 197 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 198 | // Subtraction layer workload data. |
| 199 | struct SubtractionQueueDescriptor : QueueDescriptor |
| 200 | { |
| 201 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 202 | }; |
| 203 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 204 | // Mean layer workload data. |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 205 | struct MeanQueueDescriptor : QueueDescriptorWithParameters<MeanDescriptor> |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 206 | { |
| 207 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 208 | }; |
| 209 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 210 | // Pad layer workload data |
| 211 | struct PadQueueDescriptor : QueueDescriptorWithParameters<PadDescriptor> |
| 212 | { |
| 213 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 214 | }; |
| 215 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 216 | // Batch norm layer workload data. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 217 | struct BatchNormalizationQueueDescriptor : QueueDescriptorWithParameters<BatchNormalizationDescriptor> |
| 218 | { |
| 219 | BatchNormalizationQueueDescriptor() |
| 220 | : m_Mean(nullptr) |
| 221 | , m_Variance(nullptr) |
| 222 | , m_Beta(nullptr) |
| 223 | , m_Gamma(nullptr) |
| 224 | { |
| 225 | } |
| 226 | |
| 227 | const ConstCpuTensorHandle* m_Mean; |
| 228 | const ConstCpuTensorHandle* m_Variance; |
| 229 | const ConstCpuTensorHandle* m_Beta; |
| 230 | const ConstCpuTensorHandle* m_Gamma; |
| 231 | |
| 232 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 233 | }; |
| 234 | |
| 235 | struct ResizeBilinearQueueDescriptor : QueueDescriptorWithParameters<ResizeBilinearDescriptor> |
| 236 | { |
| 237 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 238 | }; |
| 239 | |
| 240 | struct FakeQuantizationQueueDescriptor : QueueDescriptorWithParameters<FakeQuantizationDescriptor> |
| 241 | { |
| 242 | FakeQuantizationQueueDescriptor() |
| 243 | : m_Min(nullptr) |
| 244 | , m_Max(nullptr) |
| 245 | { |
| 246 | } |
| 247 | |
| 248 | const ConstCpuTensorHandle* m_Min; |
| 249 | const ConstCpuTensorHandle* m_Max; |
| 250 | |
| 251 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 252 | }; |
| 253 | |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 254 | struct L2NormalizationQueueDescriptor : QueueDescriptorWithParameters<L2NormalizationDescriptor> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 255 | { |
| 256 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 257 | }; |
| 258 | |
| 259 | struct ConstantQueueDescriptor : QueueDescriptor |
| 260 | { |
| 261 | ConstantQueueDescriptor() |
| 262 | : m_LayerOutput(nullptr) |
| 263 | { |
| 264 | } |
| 265 | |
| 266 | const ConstCpuTensorHandle* m_LayerOutput; |
| 267 | |
| 268 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 269 | }; |
| 270 | |
| 271 | struct ReshapeQueueDescriptor : QueueDescriptorWithParameters<ReshapeDescriptor> |
| 272 | { |
| 273 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 274 | }; |
| 275 | |
| 276 | struct FloorQueueDescriptor : QueueDescriptor |
| 277 | { |
| 278 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 279 | }; |
| 280 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 281 | struct LstmQueueDescriptor : QueueDescriptorWithParameters<LstmDescriptor> |
| 282 | { |
| 283 | LstmQueueDescriptor() |
| 284 | : m_InputToInputWeights(nullptr) |
| 285 | , m_InputToForgetWeights(nullptr) |
| 286 | , m_InputToCellWeights(nullptr) |
| 287 | , m_InputToOutputWeights(nullptr) |
| 288 | , m_RecurrentToInputWeights(nullptr) |
| 289 | , m_RecurrentToForgetWeights(nullptr) |
| 290 | , m_RecurrentToCellWeights(nullptr) |
| 291 | , m_RecurrentToOutputWeights(nullptr) |
| 292 | , m_CellToInputWeights(nullptr) |
| 293 | , m_CellToForgetWeights(nullptr) |
| 294 | , m_CellToOutputWeights(nullptr) |
| 295 | , m_InputGateBias(nullptr) |
| 296 | , m_ForgetGateBias(nullptr) |
| 297 | , m_CellBias(nullptr) |
| 298 | , m_OutputGateBias(nullptr) |
| 299 | , m_ProjectionWeights(nullptr) |
| 300 | , m_ProjectionBias(nullptr) |
| 301 | { |
| 302 | } |
| 303 | |
| 304 | const ConstCpuTensorHandle* m_InputToInputWeights; |
| 305 | const ConstCpuTensorHandle* m_InputToForgetWeights; |
| 306 | const ConstCpuTensorHandle* m_InputToCellWeights; |
| 307 | const ConstCpuTensorHandle* m_InputToOutputWeights; |
| 308 | const ConstCpuTensorHandle* m_RecurrentToInputWeights; |
| 309 | const ConstCpuTensorHandle* m_RecurrentToForgetWeights; |
| 310 | const ConstCpuTensorHandle* m_RecurrentToCellWeights; |
| 311 | const ConstCpuTensorHandle* m_RecurrentToOutputWeights; |
| 312 | const ConstCpuTensorHandle* m_CellToInputWeights; |
| 313 | const ConstCpuTensorHandle* m_CellToForgetWeights; |
| 314 | const ConstCpuTensorHandle* m_CellToOutputWeights; |
| 315 | const ConstCpuTensorHandle* m_InputGateBias; |
| 316 | const ConstCpuTensorHandle* m_ForgetGateBias; |
| 317 | const ConstCpuTensorHandle* m_CellBias; |
| 318 | const ConstCpuTensorHandle* m_OutputGateBias; |
| 319 | const ConstCpuTensorHandle* m_ProjectionWeights; |
| 320 | const ConstCpuTensorHandle* m_ProjectionBias; |
| 321 | |
| 322 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 323 | }; |
| 324 | |
| 325 | struct ConvertFp16ToFp32QueueDescriptor : QueueDescriptor |
| 326 | { |
| 327 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 328 | }; |
| 329 | |
| 330 | struct ConvertFp32ToFp16QueueDescriptor : QueueDescriptor |
| 331 | { |
| 332 | void Validate(const WorkloadInfo& workloadInfo) const; |
| 333 | }; |
| 334 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 335 | } //namespace armnn |