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 | #include "WorkloadData.hpp" |
| 6 | |
| 7 | #include "CpuTensorHandle.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 9 | #include <DataLayoutIndexed.hpp> |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 10 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <algorithm> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 12 | #include <iomanip> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <sstream> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | #include <boost/format.hpp> |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 17 | #include <boost/numeric/conversion/cast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 19 | using namespace armnnUtils; |
| 20 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | //--------------------------------------------------------------- |
| 25 | DataType GetBiasDataType(DataType inputDataType) |
| 26 | { |
| 27 | switch (inputDataType) |
| 28 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | case DataType::Float16: |
| 30 | return DataType::Float16; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | case DataType::Float32: |
| 32 | return DataType::Float32; |
| 33 | case DataType::QuantisedAsymm8: |
| 34 | return DataType::Signed32; |
| 35 | default: |
| 36 | BOOST_ASSERT_MSG(false, "Invalid input data type"); |
| 37 | return DataType::Float32; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | namespace |
| 42 | { |
| 43 | |
| 44 | //--------------------------------------------------------------- |
| 45 | //android ndk does not support std::to_string function. |
| 46 | template <typename T> |
| 47 | std::string to_string(T value) |
| 48 | { |
| 49 | std::ostringstream os; |
| 50 | os << value; |
| 51 | return os.str(); |
| 52 | } |
| 53 | |
| 54 | //--------------------------------------------------------------- |
| 55 | void ValidatePointer(const void* ptr, std::string const& descName, std::string const& paramName) |
| 56 | { |
| 57 | if (!ptr) |
| 58 | { |
| 59 | throw InvalidArgumentException(descName + ": Invalid null pointer. The " + |
| 60 | paramName + " parameter must be set."); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | //--------------------------------------------------------------- |
| 65 | void ValidateTensorShapesMatch(const TensorInfo& first, |
| 66 | const TensorInfo& second, |
| 67 | std::string const& descName, |
| 68 | std::string const& firstName, |
| 69 | std::string const& secondName) |
| 70 | { |
| 71 | if (first.GetShape() != second.GetShape()) |
| 72 | { |
| 73 | throw InvalidArgumentException(descName + ": " |
| 74 | + firstName + " & " + secondName + " must have identical shapes"); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 79 | void ValidateNumInputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 80 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 81 | if (workloadInfo.m_InputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | { |
| 83 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 84 | ": Requires exactly " + to_string(expectedSize) + "input(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | to_string(workloadInfo.m_InputTensorInfos.size()) + " have been provided."); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 90 | void ValidateNumOutputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 92 | if (workloadInfo.m_OutputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | { |
| 94 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 95 | ": Requires exactly " + to_string(expectedSize) + " output(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 96 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | //--------------------------------------------------------------- |
| 101 | void ValidateTensorNumDimensions(const TensorInfo& tensor, |
| 102 | std::string const& descName, |
| 103 | unsigned int numDimensions, |
| 104 | std::string const& tensorName) |
| 105 | { |
| 106 | if (tensor.GetNumDimensions() != numDimensions) |
| 107 | { |
| 108 | throw InvalidArgumentException(descName + ": Expected " + to_string(numDimensions) + " but got " + |
| 109 | to_string(tensor.GetNumDimensions()) + " dimensions for " + |
| 110 | tensorName + " tensor."); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | //--------------------------------------------------------------- |
| 115 | void ValidateTensorDataType(const TensorInfo& tensor, DataType dataType, |
| 116 | const std::string& descName, std::string const& tensorName) |
| 117 | { |
| 118 | if (tensor.GetDataType() != dataType) |
| 119 | { |
| 120 | throw InvalidArgumentException(descName + ": Expected data type " + GetDataTypeName(dataType) + " but got " + |
| 121 | GetDataTypeName(tensor.GetDataType()) + " for " + tensorName + " tensor."); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | //--------------------------------------------------------------- |
| 126 | void ValidateBiasTensorQuantization(const TensorInfo& biasTensor, const TensorInfo& inputTensorInfo, |
| 127 | const TensorInfo& weightsTensorInfo, const std::string& descName) |
| 128 | { |
| 129 | if (biasTensor.GetQuantizationOffset() != 0) |
| 130 | { |
| 131 | throw InvalidArgumentException(descName + ": Expected zero quantization offset for bias tensor but got " + |
| 132 | to_string(biasTensor.GetQuantizationOffset())); |
| 133 | } |
| 134 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightsTensorInfo.GetQuantizationScale(); |
kevmay01 | 6c46dd3 | 2018-12-17 15:32:45 +0000 | [diff] [blame] | 135 | if (std::abs(biasTensor.GetQuantizationScale() - expectedScale) > 0.00000001f) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 136 | { |
| 137 | // Print the float values with extra precision to see very small differences |
| 138 | std::stringstream msg; |
| 139 | msg << std::setprecision(10) << descName << ": Expected " << expectedScale << |
| 140 | " quantization scale for bias tensor (the product of the input and weight scales), but got " << |
| 141 | biasTensor.GetQuantizationScale(); |
| 142 | throw InvalidArgumentException(msg.str()); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | //--------------------------------------------------------------- |
| 147 | void ValidateTensors(const std::vector<ITensorHandle*>& vec, |
| 148 | unsigned int numExpected, |
| 149 | const std::string& descName, |
| 150 | const std::string& varName) |
| 151 | { |
| 152 | if (vec.empty() && numExpected > 0) |
| 153 | { |
| 154 | throw InvalidArgumentException(descName + ": Invalid empty " + varName + " array."); |
| 155 | } |
| 156 | |
| 157 | for (unsigned int i = 0; i < numExpected; ++i) |
| 158 | { |
| 159 | if (!vec[i]) |
| 160 | { |
| 161 | throw InvalidArgumentException(descName + ": Invalid NULL for " + varName + to_string(i)); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | //--------------------------------------------------------------- |
| 167 | void ValidateBroadcastTensorShapesMatch(const TensorInfo& first, |
| 168 | const TensorInfo& second, |
| 169 | const TensorInfo& output, |
| 170 | std::string const& descName, |
| 171 | std::string const& firstName, |
| 172 | std::string const& secondName) |
| 173 | { |
| 174 | // Tensors must have the same number of dimensions in order to be explicit about which dimensions will get |
| 175 | // broadcasted. |
| 176 | if (first.GetNumDimensions() != second.GetNumDimensions()) |
| 177 | { |
| 178 | throw InvalidArgumentException(descName + ": Tensors " |
| 179 | + firstName + " & " + secondName |
| 180 | + " must have the same number of dimensions in order to be broadcasted"); |
| 181 | } |
| 182 | uint32_t numDims = first.GetNumDimensions(); |
| 183 | std::vector<uint32_t> outputDims(numDims, 0u); |
| 184 | for (uint32_t i = 0; i < numDims; i++) |
| 185 | { |
| 186 | const bool dimsNotEqual = first.GetShape()[i] != second.GetShape()[i]; |
| 187 | const bool dimsNotOne = (first.GetShape()[i] != 1) && (second.GetShape()[i] != 1); |
| 188 | if (dimsNotEqual && dimsNotOne) |
| 189 | { |
| 190 | throw InvalidArgumentException("Broadcasting is not possible for incompatible shapes"); |
| 191 | } |
| 192 | outputDims[i] = std::max(first.GetShape()[i], second.GetShape()[i]); |
| 193 | } |
| 194 | TensorShape broadcastShape = TensorShape(boost::numeric_cast<unsigned int>(outputDims.size()), outputDims.data()); |
| 195 | if (broadcastShape != output.GetShape()) |
| 196 | { |
| 197 | throw InvalidArgumentException(descName + ": The tensor shape resulting from adding " |
| 198 | + firstName + " & " + secondName |
| 199 | + " does not match the output shape"); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | //--------------------------------------------------------------- |
| 204 | /// Validates that the output tensor's quantization scale is greater than the product |
| 205 | /// of the two input tensors' quantization scales. This is a requirement of the implementation of |
| 206 | /// the quantized multiplication. |
| 207 | void ValidateTensorQuantizationMultiplier(const TensorInfo& inputTensor1, const TensorInfo& inputTensor2, |
| 208 | const TensorInfo& outputTensorInfo, std::string const& descName, |
| 209 | const std::string& inputTensor1Name, const std::string& inputTensor2Name, const std::string& outputTensorName) |
| 210 | { |
| 211 | if (outputTensorInfo.GetDataType() == DataType::QuantisedAsymm8) |
| 212 | { |
| 213 | if (outputTensorInfo.GetQuantizationScale() <= |
| 214 | inputTensor1.GetQuantizationScale() * inputTensor2.GetQuantizationScale()) |
| 215 | { |
| 216 | std::stringstream msg; |
| 217 | msg << descName << ": Quantization scale of " << outputTensorName << " is not greater than " << |
| 218 | "the product of the " << inputTensor1Name << " and " << inputTensor2Name << " tensors"; |
| 219 | throw InvalidArgumentException(msg.str()); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 224 | //--------------------------------------------------------------- |
| 225 | void ValidateDataTypes(const TensorInfo& info, |
| 226 | const std::vector<armnn::DataType>& supportedTypes, |
| 227 | std::string const& descName) |
| 228 | { |
| 229 | auto iterator = std::find(supportedTypes.begin(), supportedTypes.end(), info.GetDataType()); |
| 230 | if (iterator == supportedTypes.end()) |
| 231 | { |
| 232 | throw InvalidArgumentException(descName + ": " + " Tensor type is not supported."); |
| 233 | } |
| 234 | } |
| 235 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 236 | } //namespace |
| 237 | |
| 238 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 239 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 240 | { |
| 241 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 242 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 243 | } |
| 244 | |
| 245 | //--------------------------------------------------------------- |
| 246 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 247 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 248 | ValidateNumInputs(workloadInfo, "MemCopyQueueDescriptor", 1); |
| 249 | ValidateNumOutputs(workloadInfo, "MemCopyQueueDescriptor" , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 250 | |
| 251 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 252 | { |
| 253 | throw InvalidArgumentException(boost::str( |
| 254 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 255 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 256 | } |
| 257 | |
| 258 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 259 | { |
| 260 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 261 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 262 | { |
| 263 | throw InvalidArgumentException(boost::str( |
| 264 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 265 | % i )); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if (m_Inputs.size() != m_Outputs.size()) |
| 270 | { |
| 271 | throw InvalidArgumentException(boost::str( |
| 272 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 273 | % m_Inputs.size() % m_Outputs.size())); |
| 274 | } |
| 275 | |
| 276 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 277 | { |
| 278 | if (!m_Inputs[i]) |
| 279 | { |
| 280 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 281 | } |
| 282 | |
| 283 | if (!m_Outputs[i]) |
| 284 | { |
| 285 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | //--------------------------------------------------------------- |
| 291 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 292 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 293 | ValidateNumInputs(workloadInfo, "ActivationQueueDescriptor", 1); |
| 294 | ValidateNumOutputs(workloadInfo, "ActivationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 295 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 296 | workloadInfo.m_OutputTensorInfos[0], |
| 297 | "ActivationQueueDescriptor", |
| 298 | "input", |
| 299 | "output"); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 300 | |
| 301 | std::vector<DataType> supportedTypes = { |
| 302 | DataType::Float32, |
| 303 | DataType::Float16, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 304 | DataType::QuantisedAsymm8, |
| 305 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 309 | supportedTypes, |
| 310 | "ActivationQueueDescriptor"); |
| 311 | |
| 312 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 313 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 314 | "ActivationQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | //--------------------------------------------------------------- |
| 318 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 319 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 320 | ValidateNumInputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
| 321 | ValidateNumOutputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 322 | |
| 323 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 324 | workloadInfo.m_OutputTensorInfos[0], |
| 325 | "SoftmaxQueueDescriptor", |
| 326 | "input", |
| 327 | "output"); |
| 328 | } |
| 329 | |
| 330 | //--------------------------------------------------------------- |
| 331 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 332 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 333 | ValidateNumInputs(workloadInfo, "SplitterQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 334 | |
| 335 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 336 | { |
| 337 | throw InvalidArgumentException("SplitterQueueDescriptor: At least one output needs to be provided."); |
| 338 | } |
| 339 | |
| 340 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 341 | { |
| 342 | throw InvalidArgumentException( |
| 343 | "SplitterQueueDescriptor: Number of split windows " |
| 344 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 345 | "Number of windows: " + |
| 346 | to_string(m_ViewOrigins.size()) + |
| 347 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 348 | } |
| 349 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 350 | //The dimensionality of all the windows has to match the dimensionality (not shape) of the input. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 351 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 352 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 353 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 354 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 355 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 356 | if (e.m_Origin.size() != inputDims) |
| 357 | { |
| 358 | throw InvalidArgumentException("SplitterQueueDescriptor: Window origin have to " |
| 359 | "have the same dimensionality as the input tensor. " |
| 360 | "Window origin (index: " + |
| 361 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 362 | " dimensions, the input " |
| 363 | "tensor has " + |
| 364 | to_string(inputDims) + " dimensions."); |
| 365 | } |
| 366 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 367 | { |
| 368 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 369 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 370 | { |
| 371 | throw InvalidArgumentException("SplitterQueueDescriptor: Window extent coordinates have to " |
| 372 | "be smaller or equal than the size of the input in that coord."); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | //--------------------------------------------------------------- |
| 379 | void MergerQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 380 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 381 | ValidateNumOutputs(workloadInfo, "MergerQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 382 | |
| 383 | if (m_Inputs.size() <= 0) |
| 384 | { |
| 385 | throw InvalidArgumentException("MergerQueueDescriptor: At least one input needs to be provided."); |
| 386 | } |
| 387 | if (m_Outputs.size() <= 0) |
| 388 | { |
| 389 | throw InvalidArgumentException("MergerQueueDescriptor: At least one output needs to be provided."); |
| 390 | } |
| 391 | |
| 392 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 393 | { |
| 394 | throw InvalidArgumentException("MergerQueueDescriptor: At least one TensorInfo input needs to be provided."); |
| 395 | } |
| 396 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 397 | { |
| 398 | throw InvalidArgumentException("MergerQueueDescriptor: At least one TensorInfo output needs to be provided."); |
| 399 | } |
| 400 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 401 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 402 | { |
| 403 | throw InvalidArgumentException("Invalid Concatenation Axis provided"); |
| 404 | } |
| 405 | |
| 406 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 407 | { |
| 408 | return; |
| 409 | } |
| 410 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 411 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 412 | { |
| 413 | throw InvalidArgumentException( |
| 414 | "MergerQueueDescriptor: Number of split windows " |
| 415 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 416 | "Number of windows: " + |
| 417 | to_string(m_ViewOrigins.size()) + |
| 418 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 419 | } |
| 420 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 421 | //The dimensionality of all the windows has to match the dimensionality (not shape) of the output. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 422 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 423 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 424 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 425 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 426 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 427 | if (e.m_Origin.size() != outputDims) |
| 428 | { |
| 429 | throw InvalidArgumentException("MergerQueueDescriptor: Window origin have to " |
| 430 | "have the same dimensionality as the output tensor. " |
| 431 | "Window origin (index: " + |
| 432 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 433 | " dimensions, the output " |
| 434 | "tensor has " + |
| 435 | to_string(outputDims) + " dimensions."); |
| 436 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 437 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 438 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 439 | { |
| 440 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 441 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 442 | { |
| 443 | throw InvalidArgumentException("MergerQueueDescriptor: Window extent coordinates have to " |
| 444 | "be smaller or equal than the size of the output in that coord."); |
| 445 | } |
| 446 | } |
| 447 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame^] | 448 | |
| 449 | // Check the supported data types |
| 450 | std::vector<DataType> supportedTypes = |
| 451 | { |
| 452 | DataType::Float32, |
| 453 | DataType::Float16, |
| 454 | DataType::Boolean, |
| 455 | DataType::Signed32, |
| 456 | DataType::QuantisedAsymm8, |
| 457 | DataType::QuantisedSymm16 |
| 458 | }; |
| 459 | |
| 460 | for (unsigned long i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 461 | { |
| 462 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[i], |
| 463 | supportedTypes, |
| 464 | "MergerQueueDescriptor"); |
| 465 | } |
| 466 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 467 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 468 | "MergerQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | //--------------------------------------------------------------- |
| 472 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 473 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 474 | ValidateNumInputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
| 475 | ValidateNumOutputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 476 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", 2, "output"); |
| 477 | |
| 478 | if (!(workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 2 || |
| 479 | workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 4)) |
| 480 | { |
| 481 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Input tensor must have 2 or 4 dimensions."); |
| 482 | } |
| 483 | |
| 484 | if (m_Weight == nullptr) |
| 485 | { |
| 486 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Weight tensor descriptor is missing."); |
| 487 | } |
| 488 | |
| 489 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor", 2, "weight"); |
| 490 | |
| 491 | if (m_Parameters.m_BiasEnabled) |
| 492 | { |
| 493 | if (m_Bias == nullptr) |
| 494 | { |
| 495 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Bias is enabled but " |
| 496 | "bias value tensor descriptor is missing."); |
| 497 | } |
| 498 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 499 | // Validates type and quantization values. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 500 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 501 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor"); |
| 502 | |
| 503 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 504 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 505 | "FullyConnectedQueueDescriptor", "bias"); |
| 506 | |
| 507 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "FullyConnectedQueueDescriptor", 1, "bias"); |
| 508 | } |
| 509 | |
| 510 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 511 | workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", "input", "weights", "output"); |
| 512 | } |
| 513 | |
| 514 | //--------------------------------------------------------------- |
| 515 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 516 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 517 | ValidateNumInputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
| 518 | ValidateNumOutputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 519 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 520 | workloadInfo.m_OutputTensorInfos[0], |
| 521 | "NormalizationQueueDescriptor", |
| 522 | "input", |
| 523 | "output"); |
| 524 | } |
| 525 | |
| 526 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 527 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 528 | ValidateNumInputs(workloadInfo, "AdditionQueueDescriptor", 2); |
| 529 | ValidateNumOutputs(workloadInfo, "AdditionQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 530 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 531 | std::vector<DataType> supportedTypes = { |
| 532 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 533 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 534 | DataType::QuantisedSymm16, |
| 535 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 536 | }; |
| 537 | |
| 538 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 539 | supportedTypes, |
| 540 | "AdditionQueueDescriptor"); |
| 541 | |
| 542 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 543 | supportedTypes, |
| 544 | "AdditionQueueDescriptor"); |
| 545 | |
| 546 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 547 | supportedTypes, |
| 548 | "AdditionQueueDescriptor"); |
| 549 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 550 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 551 | workloadInfo.m_InputTensorInfos[1], |
| 552 | workloadInfo.m_OutputTensorInfos[0], |
| 553 | "AdditionQueueDescriptor", |
| 554 | "first input", |
| 555 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | //--------------------------------------------------------------- |
| 559 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 560 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 561 | ValidateNumInputs(workloadInfo, "MultiplicationQueueDescriptor", 2); |
| 562 | ValidateNumOutputs(workloadInfo, "MultiplicationQueueDescriptor", 1); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 563 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 564 | std::vector<DataType> supportedTypes = { |
| 565 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 566 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 567 | DataType::QuantisedSymm16, |
| 568 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 572 | supportedTypes, |
| 573 | "MultiplicationQueueDescriptor"); |
| 574 | |
| 575 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 576 | supportedTypes, |
| 577 | "MultiplicationQueueDescriptor"); |
| 578 | |
| 579 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 580 | supportedTypes, |
| 581 | "MultiplicationQueueDescriptor"); |
| 582 | |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 583 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 584 | workloadInfo.m_InputTensorInfos[1], |
| 585 | workloadInfo.m_OutputTensorInfos[0], |
| 586 | "MultiplicationQueueDescriptor", |
| 587 | "first input", |
| 588 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 592 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 593 | ValidateNumInputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
| 594 | ValidateNumOutputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 595 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 596 | workloadInfo.m_OutputTensorInfos[0], |
| 597 | "BatchNormalizationQueueDescriptor", |
| 598 | "input", |
| 599 | "output"); |
| 600 | ValidatePointer(m_Mean, "BatchNormalizationQueueDescriptor", "mean"); |
| 601 | ValidatePointer(m_Variance, "BatchNormalizationQueueDescriptor", "variance"); |
| 602 | ValidatePointer(m_Beta, "BatchNormalizationQueueDescriptor", "beta"); |
| 603 | ValidatePointer(m_Gamma, "BatchNormalizationQueueDescriptor", "gamma"); |
| 604 | |
| 605 | |
| 606 | ValidateTensorNumDimensions(m_Mean->GetTensorInfo(), "BatchNormalizationQueueDescriptor", 1, "mean"); |
| 607 | ValidateTensorNumDimensions(m_Variance->GetTensorInfo(), "BatchNormalizationQueueDescriptor", 1, "variance"); |
| 608 | ValidateTensorNumDimensions(m_Beta->GetTensorInfo(), "BatchNormalizationQueueDescriptor", 1, "beta"); |
| 609 | ValidateTensorNumDimensions(m_Gamma->GetTensorInfo(), "BatchNormalizationQueueDescriptor", 1, "gamma"); |
| 610 | |
| 611 | ValidateTensorShapesMatch( |
| 612 | m_Mean->GetTensorInfo(), m_Variance->GetTensorInfo(), "BatchNormalizationQueueDescriptor", "mean", "variance"); |
| 613 | ValidateTensorShapesMatch( |
| 614 | m_Mean->GetTensorInfo(), m_Beta->GetTensorInfo(), "BatchNormalizationQueueDescriptor", "mean", "beta"); |
| 615 | ValidateTensorShapesMatch( |
| 616 | m_Mean->GetTensorInfo(), m_Gamma->GetTensorInfo(), "BatchNormalizationQueueDescriptor", "mean", "gamma"); |
| 617 | } |
| 618 | |
| 619 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 620 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 621 | ValidateNumInputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
| 622 | ValidateNumOutputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 623 | |
| 624 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "input"); |
| 625 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "output"); |
| 626 | |
| 627 | ValidatePointer(m_Weight, "Convolution2dQueueDescriptor", "weight"); |
| 628 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor", 4, "weight"); |
| 629 | ValidateTensorDataType(m_Weight->GetTensorInfo(), workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 630 | "Convolution2dQueueDescriptor", "weight"); |
| 631 | if (m_Parameters.m_BiasEnabled) |
| 632 | { |
| 633 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "Convolution2dQueueDescriptor", 1, "bias"); |
| 634 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 635 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 636 | "Convolution2dQueueDescriptor", "bias"); |
| 637 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 638 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor"); |
| 639 | } |
| 640 | |
| 641 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 642 | workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", "input", "weights", "output"); |
| 643 | } |
| 644 | |
| 645 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 646 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 647 | ValidateNumInputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
| 648 | ValidateNumOutputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 649 | |
| 650 | ValidateTensorNumDimensions( |
| 651 | workloadInfo.m_InputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "input"); |
| 652 | ValidateTensorNumDimensions( |
| 653 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "output"); |
| 654 | |
| 655 | ValidatePointer(m_Weight, "DepthwiseConvolution2dQueueDescriptor", "weight"); |
| 656 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 4, "weight"); |
| 657 | |
Bruno Goncalves | 22972f0 | 2019-04-26 21:03:24 -0300 | [diff] [blame] | 658 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 659 | { |
| 660 | throw InvalidArgumentException( |
| 661 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: dilationX (provided %1%) " |
| 662 | "and dilationY (provided %2%) cannot be smaller than 1.") |
| 663 | % m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 664 | } |
| 665 | |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 666 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 667 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 668 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 669 | // inputChannels * channelMultiplier should be equal to outputChannels. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 670 | const unsigned int numWeightChannelMultiplier = m_Weight->GetTensorInfo().GetShape()[0]; |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 671 | const unsigned int numWeightInputChannels = m_Weight->GetTensorInfo().GetShape()[1]; |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 672 | const unsigned int numWeightOutputChannels = workloadInfo.m_OutputTensorInfos[0].GetShape()[channelIndex]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 673 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 674 | { |
| 675 | throw InvalidArgumentException( |
| 676 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: output_channels (provided %1%) should be " |
| 677 | "equal to input_channels (provided %2%) multiplied by channel_multiplier " |
| 678 | "(provided %3%).") |
| 679 | % numWeightOutputChannels % numWeightInputChannels % numWeightChannelMultiplier)); |
| 680 | } |
| 681 | |
| 682 | if (m_Parameters.m_BiasEnabled) |
| 683 | { |
| 684 | ValidatePointer(m_Bias, "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 685 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 1, "bias"); |
| 686 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 687 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor"); |
| 688 | |
| 689 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 690 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 691 | "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 692 | } |
| 693 | |
| 694 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 695 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", "input", "weights", "output"); |
| 696 | } |
| 697 | |
| 698 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 699 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 700 | ValidateNumInputs(workloadInfo, "PermuteQueueDescriptor", 1); |
| 701 | ValidateNumOutputs(workloadInfo, "PermuteQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 702 | |
| 703 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 704 | |
| 705 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 706 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 707 | |
| 708 | ValidateTensorNumDimensions(input, "PermuteQueueDescriptor", mapping.GetSize(), "input"); |
| 709 | ValidateTensorNumDimensions(output, "PermuteQueueDescriptor", mapping.GetSize(), "output"); |
| 710 | |
| 711 | for (unsigned int i = 0; i < mapping.GetSize(); ++i) |
| 712 | { |
| 713 | if (input.GetShape()[i] != output.GetShape()[mapping[i]]) |
| 714 | { |
| 715 | throw InvalidArgumentException("PermuteQueueDescriptor: src dimension " + to_string(i) + |
| 716 | " (=" + to_string(input.GetShape()[i]) + ") " + |
| 717 | "must match dst dimension " + to_string(mapping[i]) + |
| 718 | " (=" + to_string(output.GetShape()[mapping[i]]) + ")"); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 724 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 725 | ValidateNumInputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
| 726 | ValidateNumOutputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 727 | |
| 728 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "input"); |
| 729 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "output"); |
| 730 | } |
| 731 | |
| 732 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 733 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 734 | ValidateNumInputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
| 735 | ValidateNumOutputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 736 | |
| 737 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "input"); |
| 738 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "output"); |
| 739 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 740 | // Resizes bilinear only changes width and height: batch and channel count must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 741 | { |
| 742 | const unsigned int inputBatchSize = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 743 | const unsigned int outputBatchSize = workloadInfo.m_OutputTensorInfos[0].GetShape()[0]; |
| 744 | if (inputBatchSize != outputBatchSize) |
| 745 | { |
| 746 | throw InvalidArgumentException( |
| 747 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input batch size (%1%) " |
| 748 | "does not match output batch size (%2%)") % inputBatchSize % outputBatchSize)); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | { |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 753 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 754 | const unsigned int inputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 755 | workloadInfo.m_InputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 756 | const unsigned int outputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 757 | workloadInfo.m_OutputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 758 | if (inputChannelCount != outputChannelCount) |
| 759 | { |
| 760 | throw InvalidArgumentException( |
| 761 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input channel count (%1%) " |
| 762 | "does not match output channel count (%2%)") % inputChannelCount % outputChannelCount)); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 768 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 769 | ValidateNumInputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
| 770 | ValidateNumOutputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 771 | |
| 772 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "input"); |
| 773 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "output"); |
| 774 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 775 | workloadInfo.m_OutputTensorInfos[0], |
| 776 | "FakeQuantizationQueueDescriptor", |
| 777 | "input", |
| 778 | "output"); |
| 779 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 780 | { |
| 781 | throw InvalidArgumentException("FakeQuantizationQueueDescriptor: min cannot be greater than max"); |
| 782 | } |
| 783 | |
| 784 | } |
| 785 | |
| 786 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 787 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 788 | ValidateNumInputs(workloadInfo, "L2NormalizationQueueDescriptor", 1); |
| 789 | ValidateNumOutputs(workloadInfo, "L2NormalizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 790 | |
| 791 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "L2NormalizationQueueDescriptor", 4, "input"); |
| 792 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "L2NormalizationQueueDescriptor", 4, "output"); |
| 793 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 794 | workloadInfo.m_OutputTensorInfos[0], |
| 795 | "L2NormalizationQueueDescriptor", |
| 796 | "input", |
| 797 | "output"); |
| 798 | } |
| 799 | |
| 800 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 801 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 802 | ValidateNumInputs(workloadInfo, "ConstantQueueDescriptor", 0); |
| 803 | ValidateNumOutputs(workloadInfo, "ConstantQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 804 | |
| 805 | if (!m_LayerOutput) |
| 806 | { |
| 807 | throw InvalidArgumentException("ConstantQueueDescriptor: No const input specified"); |
| 808 | } |
| 809 | |
| 810 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), |
| 811 | workloadInfo.m_OutputTensorInfos[0], |
| 812 | "ConstantQueueDescriptor", |
| 813 | "constant", |
| 814 | "output"); |
| 815 | } |
| 816 | |
| 817 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 818 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 819 | ValidateNumInputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
| 820 | ValidateNumOutputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 821 | |
| 822 | if (workloadInfo.m_InputTensorInfos[0].GetNumElements() != workloadInfo.m_OutputTensorInfos[0].GetNumElements()) |
| 823 | { |
| 824 | throw InvalidArgumentException("ReshapeQueueDescriptor: Input tensor has " + |
| 825 | to_string(workloadInfo.m_InputTensorInfos[0].GetNumElements()) + " but output tensor has " + |
| 826 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 827 | } |
| 828 | } |
| 829 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 830 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 831 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 832 | ValidateNumInputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
| 833 | ValidateNumOutputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 834 | |
| 835 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "input"); |
| 836 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "output"); |
| 837 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 838 | if (m_Parameters.m_BlockShape.size() != 2) |
| 839 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 840 | throw InvalidArgumentException("Block Shape must contain 2 spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 844 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 845 | throw InvalidArgumentException("Pad List must contain the same number of dimensions as Block Shape."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 849 | |
| 850 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
| 851 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
| 852 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 853 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 854 | unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 855 | + heightPad.first + heightPad.second; |
| 856 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 857 | unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 858 | + widthPad.first + widthPad.second; |
| 859 | |
| 860 | unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 861 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 862 | |
| 863 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 864 | { |
| 865 | throw InvalidArgumentException("SpaceToBatchNdQueueDescriptor: Input tensor has " + |
| 866 | to_string(numInputElements) + " after padding but output tensor has " + |
| 867 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 868 | } |
| 869 | |
| 870 | if (inputHeight % m_Parameters.m_BlockShape[0] != 0 || inputWidth % m_Parameters.m_BlockShape[1] != 0) |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 871 | { |
| 872 | throw InvalidArgumentException( |
| 873 | "Input shape after padding must be divisible by Block Shape in all spatial dimensions"); |
| 874 | } |
| 875 | } |
| 876 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 877 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 878 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 879 | ValidateNumInputs(workloadInfo, "FloorQueueDescriptor", 1); |
| 880 | ValidateNumOutputs(workloadInfo, "FlootQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 881 | |
| 882 | if (workloadInfo.m_InputTensorInfos[0] != workloadInfo.m_OutputTensorInfos[0]) |
| 883 | { |
| 884 | throw InvalidArgumentException("FloorQueueDescriptor: Input and output tensor infos do not match."); |
| 885 | } |
| 886 | } |
| 887 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 888 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 889 | { |
| 890 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "LstmQueueDescriptor", 2, "input"); |
| 891 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "LstmQueueDescriptor", 2, "output"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 892 | |
| 893 | std::vector<DataType> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 894 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 895 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 896 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 897 | }; |
| 898 | |
| 899 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 900 | supportedTypes, |
| 901 | "LstmQueueDescriptor"); |
| 902 | |
| 903 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 904 | supportedTypes, |
| 905 | "LstmQueueDescriptor"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 909 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 910 | ValidateNumInputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
| 911 | ValidateNumOutputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 912 | |
| 913 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 914 | { |
| 915 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Input tensor type must be Float32."); |
| 916 | } |
| 917 | |
| 918 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float16) |
| 919 | { |
| 920 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Output tensor type must be Float16."); |
| 921 | } |
| 922 | |
| 923 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 924 | workloadInfo.m_OutputTensorInfos[0], |
| 925 | "ConvertFp32ToFp16QueueDescriptor", |
| 926 | "input", |
| 927 | "output"); |
| 928 | } |
| 929 | |
| 930 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 931 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 932 | ValidateNumInputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
| 933 | ValidateNumOutputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 934 | |
| 935 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float16) |
| 936 | { |
| 937 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Input tensor type must be Float16."); |
| 938 | } |
| 939 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 940 | { |
| 941 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Output tensor type must be Float32."); |
| 942 | } |
| 943 | |
| 944 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 945 | workloadInfo.m_OutputTensorInfos[0], |
| 946 | "ConvertFp16ToFp32QueueDescriptor", |
| 947 | "input", |
| 948 | "output"); |
| 949 | } |
| 950 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 951 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 952 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 953 | ValidateNumInputs(workloadInfo, "DivisionQueueDescriptor", 2); |
| 954 | ValidateNumOutputs(workloadInfo, "DivisionQueueDescriptor", 1); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 955 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 956 | std::vector<DataType> supportedTypes = { |
| 957 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 958 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 959 | DataType::QuantisedSymm16, |
| 960 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 961 | }; |
| 962 | |
| 963 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 964 | supportedTypes, |
| 965 | "DivisionQueueDescriptor"); |
| 966 | |
| 967 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 968 | supportedTypes, |
| 969 | "DivisionQueueDescriptor"); |
| 970 | |
| 971 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 972 | supportedTypes, |
| 973 | "DivisionQueueDescriptor"); |
| 974 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 975 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 976 | workloadInfo.m_InputTensorInfos[1], |
| 977 | workloadInfo.m_OutputTensorInfos[0], |
| 978 | "DivisionQueueDescriptor", |
| 979 | "first input", |
| 980 | "second input"); |
| 981 | } |
| 982 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 983 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 984 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 985 | ValidateNumInputs(workloadInfo, "SubtractionQueueDescriptor", 2); |
| 986 | ValidateNumOutputs(workloadInfo, "SubtractionQueueDescriptor", 1); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 987 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 988 | std::vector<DataType> supportedTypes = { |
| 989 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 990 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 991 | DataType::QuantisedSymm16, |
| 992 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 993 | }; |
| 994 | |
| 995 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 996 | supportedTypes, |
| 997 | "SubtractionQueueDescriptor"); |
| 998 | |
| 999 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1000 | supportedTypes, |
| 1001 | "SubtractionQueueDescriptor"); |
| 1002 | |
| 1003 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1004 | supportedTypes, |
| 1005 | "SubtractionQueueDescriptor"); |
| 1006 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1007 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1008 | workloadInfo.m_InputTensorInfos[1], |
| 1009 | workloadInfo.m_OutputTensorInfos[0], |
| 1010 | "SubtractionQueueDescriptor", |
| 1011 | "first input", |
| 1012 | "second input"); |
| 1013 | } |
| 1014 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1015 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1016 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1017 | ValidateNumInputs(workloadInfo, "MaximumQueueDescriptor", 2); |
| 1018 | ValidateNumOutputs(workloadInfo, "MaximumQueueDescriptor", 1); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1019 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1020 | std::vector<DataType> supportedTypes = { |
| 1021 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1022 | DataType::QuantisedAsymm8, |
| 1023 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1027 | supportedTypes, |
| 1028 | "MaximumQueueDescriptor"); |
| 1029 | |
| 1030 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1031 | supportedTypes, |
| 1032 | "MaximumQueueDescriptor"); |
| 1033 | |
| 1034 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1035 | supportedTypes, |
| 1036 | "MaximumQueueDescriptor"); |
| 1037 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1038 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1039 | workloadInfo.m_InputTensorInfos[1], |
| 1040 | workloadInfo.m_OutputTensorInfos[0], |
| 1041 | "MaximumQueueDescriptor", |
| 1042 | "first input", |
| 1043 | "second input"); |
| 1044 | } |
| 1045 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1046 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1047 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1048 | ValidateNumInputs(workloadInfo, "MeanQueueDescriptor", 1); |
| 1049 | ValidateNumOutputs(workloadInfo, "MeanQueueDescriptor", 1); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1050 | |
| 1051 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1052 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1053 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1054 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1055 | { |
| 1056 | ValidateTensorNumDimensions(output, "MeanQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1057 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1058 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1059 | { |
| 1060 | ValidateTensorNumDimensions(output, "MeanQueueDescriptor", 1, "output"); |
| 1061 | } |
| 1062 | else |
| 1063 | { |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1064 | auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(m_Parameters.m_Axis.size()); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1065 | ValidateTensorNumDimensions(output, |
| 1066 | "MeanQueueDescriptor", |
| 1067 | outputDim > 0 ? outputDim : 1, |
| 1068 | "output"); |
| 1069 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1072 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1073 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1074 | ValidateNumInputs(workloadInfo, "PadQueueDescriptor", 1); |
| 1075 | ValidateNumOutputs(workloadInfo, "PadQueueDescriptor", 1); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1076 | |
| 1077 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1078 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1079 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1080 | // input and output should have the same number of dimensions |
| 1081 | ValidateTensorNumDimensions(output, "PadQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1082 | // there should be entry in the pad list for each dimension in the input tensor |
| 1083 | if (m_Parameters.m_PadList.size() != input.GetNumDimensions()) { |
| 1084 | throw InvalidArgumentException("Pad List should contain the same number of entries as there" |
| 1085 | " are dimensions in the input tensor that is " + |
| 1086 | to_string(input.GetNumDimensions()) + " entries " + |
| 1087 | " not " + to_string(m_Parameters.m_PadList.size()) + " entries."); |
| 1088 | } |
| 1089 | } |
| 1090 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1091 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1092 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1093 | ValidateNumInputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
| 1094 | ValidateNumOutputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1095 | |
| 1096 | |
| 1097 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1098 | { |
| 1099 | throw InvalidArgumentException("Quantize only accepts Float32 inputs."); |
| 1100 | } |
| 1101 | |
| 1102 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1103 | workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1104 | { |
| 1105 | throw InvalidArgumentException("Output of quantized layer must be quantized type."); |
| 1106 | } |
| 1107 | } |
| 1108 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1109 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1110 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1111 | ValidateNumInputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
| 1112 | ValidateNumOutputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1115 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1116 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1117 | ValidateNumInputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
| 1118 | ValidateNumOutputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1119 | |
| 1120 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1121 | const uint32_t rank = input.GetNumDimensions(); |
| 1122 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1123 | if (rank > 4) |
| 1124 | { |
| 1125 | throw InvalidArgumentException( |
| 1126 | "StridedSliceLayer: Input tensors with rank greater than 4 are not supported"); |
| 1127 | } |
| 1128 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1129 | // Begin, End & Stride length must be of rank(input0) |
| 1130 | if (m_Parameters.m_Begin.size() != rank) |
| 1131 | { |
| 1132 | throw InvalidArgumentException("StridedSliceLayer: Begin length must be of rank input0(" |
| 1133 | + to_string(rank) + ")"); |
| 1134 | } |
| 1135 | |
| 1136 | if (m_Parameters.m_End.size() != rank) |
| 1137 | { |
| 1138 | throw InvalidArgumentException("StridedSliceLayer: End length must be of rank input0(" |
| 1139 | + to_string(rank) + ")"); |
| 1140 | } |
| 1141 | |
| 1142 | if (m_Parameters.m_Stride.size() != rank) |
| 1143 | { |
| 1144 | throw InvalidArgumentException("StridedSliceLayer: Stride length must be of rank input0(" |
| 1145 | + to_string(rank) + ")"); |
| 1146 | } |
| 1147 | |
| 1148 | // Stride entries must be non-zero |
| 1149 | for (auto& stride : m_Parameters.m_Stride) |
| 1150 | { |
| 1151 | if (stride == 0) |
| 1152 | { |
| 1153 | throw InvalidArgumentException("StridedSliceLayer: Stride entries must be non-zero"); |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1158 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1159 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1160 | ValidateNumInputs(workloadInfo, "MinimumQueueDescriptor", 2); |
| 1161 | ValidateNumOutputs(workloadInfo, "MinimumQueueDescriptor", 1); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1162 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1163 | std::vector<DataType> supportedTypes = { |
| 1164 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1165 | DataType::QuantisedAsymm8, |
| 1166 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1167 | }; |
| 1168 | |
| 1169 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1170 | supportedTypes, |
| 1171 | "MinimumQueueDescriptor"); |
| 1172 | |
| 1173 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1174 | supportedTypes, |
| 1175 | "MinimumQueueDescriptor"); |
| 1176 | |
| 1177 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1178 | supportedTypes, |
| 1179 | "MinimumQueueDescriptor"); |
| 1180 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1181 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1182 | workloadInfo.m_InputTensorInfos[1], |
| 1183 | workloadInfo.m_OutputTensorInfos[0], |
| 1184 | "MinimumQueueDescriptor", |
| 1185 | "first input", |
| 1186 | "second input"); |
| 1187 | } |
| 1188 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1189 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1190 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1191 | ValidateNumInputs(workloadInfo, "DebugQueueDescriptor", 1); |
| 1192 | ValidateNumOutputs(workloadInfo, "DebugQueueDescriptor", 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1195 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1196 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1197 | ValidateNumInputs(workloadInfo, "EqualQueueDescriptor", 2); |
| 1198 | ValidateNumOutputs(workloadInfo, "EqualQueueDescriptor", 1); |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1199 | |
| 1200 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1201 | workloadInfo.m_InputTensorInfos[1], |
| 1202 | workloadInfo.m_OutputTensorInfos[0], |
| 1203 | "EqualQueueDescriptor", |
| 1204 | "first input", |
| 1205 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1206 | |
| 1207 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1208 | { |
| 1209 | throw InvalidArgumentException("EqualQueueDescriptor: Output tensor type must be Boolean."); |
| 1210 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1213 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1214 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1215 | ValidateNumInputs(workloadInfo, "GreaterQueueDescriptor", 2); |
| 1216 | ValidateNumOutputs(workloadInfo, "GreaterQueueDescriptor", 1); |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1217 | |
| 1218 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1219 | workloadInfo.m_InputTensorInfos[1], |
| 1220 | workloadInfo.m_OutputTensorInfos[0], |
| 1221 | "GreaterQueueDescriptor", |
| 1222 | "first input", |
| 1223 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1224 | |
| 1225 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1226 | { |
| 1227 | throw InvalidArgumentException("GreaterQueueDescriptor: Output tensor type must be Boolean."); |
| 1228 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1231 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1232 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1233 | ValidateNumInputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
| 1234 | ValidateNumOutputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1235 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1236 | workloadInfo.m_OutputTensorInfos[0], |
| 1237 | "RsqrtQueueDescriptor", |
| 1238 | "input", |
| 1239 | "output"); |
| 1240 | } |
| 1241 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1242 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1243 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1244 | ValidateNumInputs(workloadInfo, "GatherQueueDescriptor", 2); |
| 1245 | ValidateNumOutputs(workloadInfo, "GatherQueueDescriptor", 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1246 | |
| 1247 | const TensorInfo& indices = workloadInfo.m_InputTensorInfos[1]; |
| 1248 | |
| 1249 | if (indices.GetDataType() != DataType::Signed32) |
| 1250 | { |
| 1251 | throw InvalidArgumentException("GatherQueueDescriptor: Indices tensor type must be int32."); |
| 1252 | } |
| 1253 | |
| 1254 | const TensorInfo& params = workloadInfo.m_InputTensorInfos[0]; |
| 1255 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1256 | unsigned int paramsDim = params.GetNumDimensions(); |
| 1257 | unsigned int indicesDim = indices.GetNumDimensions(); |
| 1258 | unsigned int outputDim = paramsDim - 1 + indicesDim; |
| 1259 | |
| 1260 | ValidateTensorNumDimensions(output, "GatherQueueDescriptor", outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1263 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1264 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1265 | ValidateNumInputs(workloadInfo, "DetectionPostProcessQueueDescriptor", 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1266 | |
| 1267 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1268 | { |
| 1269 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Requires exactly four outputs. " + |
| 1270 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 1271 | } |
| 1272 | |
| 1273 | if (m_Anchors == nullptr) |
| 1274 | { |
| 1275 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Anchors tensor descriptor is missing."); |
| 1276 | } |
| 1277 | |
| 1278 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1279 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 1280 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 1281 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 1282 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
| 1283 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1284 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
| 1285 | |
| 1286 | ValidateTensorNumDimensions(boxEncodingsInfo, "DetectionPostProcessQueueDescriptor", 3, "box encodings"); |
| 1287 | ValidateTensorNumDimensions(scoresInfo, "DetectionPostProcessQueueDescriptor", 3, "scores"); |
| 1288 | ValidateTensorNumDimensions(anchorsInfo, "DetectionPostProcessQueueDescriptor", 2, "anchors"); |
| 1289 | |
| 1290 | ValidateTensorNumDimensions(detectionBoxesInfo, "DetectionPostProcessQueueDescriptor", 3, "detection boxes"); |
| 1291 | ValidateTensorNumDimensions(detectionScoresInfo, "DetectionPostProcessQueueDescriptor", 2, "detection scores"); |
| 1292 | ValidateTensorNumDimensions(detectionClassesInfo, "DetectionPostProcessQueueDescriptor", 2, "detection classes"); |
| 1293 | ValidateTensorNumDimensions(numDetectionsInfo, "DetectionPostProcessQueueDescriptor", 1, "num detections"); |
| 1294 | |
| 1295 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, |
| 1296 | "DetectionPostProcessQueueDescriptor", "detection boxes"); |
| 1297 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, |
| 1298 | "DetectionPostProcessQueueDescriptor", "detection scores"); |
| 1299 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, |
| 1300 | "DetectionPostProcessQueueDescriptor", "detection classes"); |
| 1301 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, |
| 1302 | "DetectionPostProcessQueueDescriptor", "num detections"); |
| 1303 | |
| 1304 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 1305 | { |
| 1306 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Intersection over union threshold " |
| 1307 | "must be positive and less than or equal to 1."); |
| 1308 | } |
| 1309 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 1310 | { |
| 1311 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Number of classes with background " |
| 1312 | "should be equal to number of classes + 1."); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1316 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1317 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1318 | ValidateNumInputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
| 1319 | ValidateNumOutputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1320 | |
| 1321 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1322 | workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1323 | { |
| 1324 | throw InvalidArgumentException("Input to dequantize layer must be quantized type."); |
| 1325 | } |
| 1326 | |
| 1327 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1328 | { |
| 1329 | throw InvalidArgumentException("Output of dequantize layer must be Float32 type."); |
| 1330 | } |
| 1331 | } |
| 1332 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1333 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1334 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1335 | ValidateNumInputs(workloadInfo, "MergeQueueDescriptor", 2); |
| 1336 | ValidateNumOutputs(workloadInfo, "MergeQueueDescriptor", 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1337 | |
| 1338 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1339 | workloadInfo.m_InputTensorInfos[1], |
| 1340 | "MergeQueueDescriptor", |
| 1341 | "input0", |
| 1342 | "input1"); |
| 1343 | |
| 1344 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1345 | workloadInfo.m_OutputTensorInfos[0], |
| 1346 | "MergeQueueDescriptor", |
| 1347 | "input0", |
| 1348 | "output"); |
| 1349 | |
| 1350 | const DataType dataType = workloadInfo.m_InputTensorInfos[0].GetDataType(); |
| 1351 | ValidateTensorDataType(workloadInfo.m_InputTensorInfos[1], dataType, "MergeQueueDescriptor", "input1"); |
| 1352 | ValidateTensorDataType(workloadInfo.m_OutputTensorInfos[0], dataType, "MergeQueueDescriptor", "output"); |
| 1353 | } |
| 1354 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1355 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1356 | { |
| 1357 | ValidateNumInputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1358 | ValidateNumOutputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1359 | |
| 1360 | std::vector<DataType> supportedTypes = { |
| 1361 | DataType::Float32, |
| 1362 | DataType::QuantisedAsymm8, |
| 1363 | DataType::QuantisedSymm16 |
| 1364 | }; |
| 1365 | |
| 1366 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1367 | supportedTypes, |
| 1368 | "SwitchQueueDescriptor"); |
| 1369 | |
| 1370 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1371 | supportedTypes, |
| 1372 | "SwitchQueueDescriptor"); |
| 1373 | |
| 1374 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1375 | supportedTypes, |
| 1376 | "SwitchQueueDescriptor"); |
| 1377 | |
| 1378 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1379 | workloadInfo.m_OutputTensorInfos[0], |
| 1380 | "SwitchQueueDescriptor", |
| 1381 | "input0", |
| 1382 | "output0"); |
| 1383 | |
| 1384 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1385 | workloadInfo.m_OutputTensorInfos[1], |
| 1386 | "SwitchQueueDescriptor", |
| 1387 | "input0", |
| 1388 | "output1"); |
| 1389 | } |
| 1390 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 1391 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1392 | { |
| 1393 | // This is internally generated so it should not need validation. |
| 1394 | } |
| 1395 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1396 | } //namespace armnn |