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