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 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 274 | //--------------------------------------------------------------- |
| 275 | void ValidateTensorDataTypesMatch(const TensorInfo& first, |
| 276 | const TensorInfo& second, |
| 277 | std::string const& descName, |
| 278 | std::string const& firstName, |
| 279 | std::string const& secondName) |
| 280 | { |
| 281 | if (first.GetDataType() != second.GetDataType()) |
| 282 | { |
| 283 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 284 | " must have identical data types."); |
| 285 | } |
| 286 | } |
| 287 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 288 | } //namespace |
| 289 | |
| 290 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 291 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 292 | { |
| 293 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 294 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 295 | } |
| 296 | |
| 297 | //--------------------------------------------------------------- |
| 298 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 299 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 300 | ValidateNumInputs(workloadInfo, "MemCopyQueueDescriptor", 1); |
| 301 | ValidateNumOutputs(workloadInfo, "MemCopyQueueDescriptor" , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 302 | |
| 303 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 304 | { |
| 305 | throw InvalidArgumentException(boost::str( |
| 306 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 307 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 308 | } |
| 309 | |
| 310 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 311 | { |
| 312 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 313 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 314 | { |
| 315 | throw InvalidArgumentException(boost::str( |
| 316 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 317 | % i )); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | if (m_Inputs.size() != m_Outputs.size()) |
| 322 | { |
| 323 | throw InvalidArgumentException(boost::str( |
| 324 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 325 | % m_Inputs.size() % m_Outputs.size())); |
| 326 | } |
| 327 | |
| 328 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 329 | { |
| 330 | if (!m_Inputs[i]) |
| 331 | { |
| 332 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 333 | } |
| 334 | |
| 335 | if (!m_Outputs[i]) |
| 336 | { |
| 337 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | //--------------------------------------------------------------- |
| 343 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 344 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 345 | ValidateNumInputs(workloadInfo, "ActivationQueueDescriptor", 1); |
| 346 | ValidateNumOutputs(workloadInfo, "ActivationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 347 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 348 | workloadInfo.m_OutputTensorInfos[0], |
| 349 | "ActivationQueueDescriptor", |
| 350 | "input", |
| 351 | "output"); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 352 | |
| 353 | std::vector<DataType> supportedTypes = { |
| 354 | DataType::Float32, |
| 355 | DataType::Float16, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 356 | DataType::QuantisedAsymm8, |
| 357 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 358 | }; |
| 359 | |
| 360 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 361 | supportedTypes, |
| 362 | "ActivationQueueDescriptor"); |
| 363 | |
| 364 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 365 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 366 | "ActivationQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | //--------------------------------------------------------------- |
| 370 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 371 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 372 | ValidateNumInputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
| 373 | ValidateNumOutputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 374 | |
| 375 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 376 | workloadInfo.m_OutputTensorInfos[0], |
| 377 | "SoftmaxQueueDescriptor", |
| 378 | "input", |
| 379 | "output"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 380 | |
| 381 | std::vector<DataType> supportedTypes = |
| 382 | { |
| 383 | DataType::Float16, |
| 384 | DataType::Float32, |
| 385 | DataType::QuantisedAsymm8, |
| 386 | DataType::QuantisedSymm16 |
| 387 | }; |
| 388 | |
| 389 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 390 | supportedTypes, |
| 391 | "SoftmaxQueueDescriptor"); |
| 392 | |
| 393 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 394 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 395 | "SoftmaxQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | //--------------------------------------------------------------- |
| 399 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 400 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 401 | ValidateNumInputs(workloadInfo, "SplitterQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 402 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 403 | // Check the supported data types |
| 404 | std::vector<DataType> supportedTypes = |
| 405 | { |
| 406 | DataType::Float32, |
| 407 | DataType::Float16, |
| 408 | DataType::Boolean, |
| 409 | DataType::Signed32, |
| 410 | DataType::QuantisedAsymm8, |
| 411 | DataType::QuantisedSymm16 |
| 412 | }; |
| 413 | |
| 414 | for (unsigned long i = 0; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
| 415 | { |
| 416 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[i], |
| 417 | supportedTypes, |
| 418 | "SplitterQueueDescriptor"); |
| 419 | } |
| 420 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 421 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 422 | "SplitterQueueDescriptor"); |
| 423 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 424 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 425 | { |
| 426 | throw InvalidArgumentException("SplitterQueueDescriptor: At least one output needs to be provided."); |
| 427 | } |
| 428 | |
| 429 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 430 | { |
| 431 | throw InvalidArgumentException( |
| 432 | "SplitterQueueDescriptor: Number of split windows " |
| 433 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 434 | "Number of windows: " + |
| 435 | to_string(m_ViewOrigins.size()) + |
| 436 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 437 | } |
| 438 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 439 | //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] | 440 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 441 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 442 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 443 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 444 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 445 | if (e.m_Origin.size() != inputDims) |
| 446 | { |
| 447 | throw InvalidArgumentException("SplitterQueueDescriptor: Window origin have to " |
| 448 | "have the same dimensionality as the input tensor. " |
| 449 | "Window origin (index: " + |
| 450 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 451 | " dimensions, the input " |
| 452 | "tensor has " + |
| 453 | to_string(inputDims) + " dimensions."); |
| 454 | } |
| 455 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 456 | { |
| 457 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 458 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 459 | { |
| 460 | throw InvalidArgumentException("SplitterQueueDescriptor: Window extent coordinates have to " |
| 461 | "be smaller or equal than the size of the input in that coord."); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | //--------------------------------------------------------------- |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 468 | void ConcatQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 469 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 470 | ValidateNumOutputs(workloadInfo, "ConcatQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 471 | |
| 472 | if (m_Inputs.size() <= 0) |
| 473 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 474 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 475 | } |
| 476 | if (m_Outputs.size() <= 0) |
| 477 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 478 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 482 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 483 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 484 | } |
| 485 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 486 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 487 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 490 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 491 | { |
| 492 | throw InvalidArgumentException("Invalid Concatenation Axis provided"); |
| 493 | } |
| 494 | |
| 495 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 496 | { |
| 497 | return; |
| 498 | } |
| 499 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 500 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 501 | { |
| 502 | throw InvalidArgumentException( |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 503 | "ConcatQueueDescriptor: Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 504 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 505 | "Number of windows: " + |
| 506 | to_string(m_ViewOrigins.size()) + |
| 507 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 508 | } |
| 509 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 510 | //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] | 511 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 512 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 513 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 514 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 515 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 516 | if (e.m_Origin.size() != outputDims) |
| 517 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 518 | throw InvalidArgumentException("ConcatQueueDescriptor: Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 519 | "have the same dimensionality as the output tensor. " |
| 520 | "Window origin (index: " + |
| 521 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 522 | " dimensions, the output " |
| 523 | "tensor has " + |
| 524 | to_string(outputDims) + " dimensions."); |
| 525 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 526 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 527 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 528 | { |
| 529 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 530 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 531 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 532 | throw InvalidArgumentException("ConcatQueueDescriptor: Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 533 | "be smaller or equal than the size of the output in that coord."); |
| 534 | } |
| 535 | } |
| 536 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 537 | |
| 538 | // Check the supported data types |
| 539 | std::vector<DataType> supportedTypes = |
| 540 | { |
| 541 | DataType::Float32, |
| 542 | DataType::Float16, |
| 543 | DataType::Boolean, |
| 544 | DataType::Signed32, |
| 545 | DataType::QuantisedAsymm8, |
| 546 | DataType::QuantisedSymm16 |
| 547 | }; |
| 548 | |
| 549 | for (unsigned long i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 550 | { |
| 551 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[i], |
| 552 | supportedTypes, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 553 | "ConcatQueueDescriptor"); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 554 | } |
| 555 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 556 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 557 | "ConcatQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | //--------------------------------------------------------------- |
| 561 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 562 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 563 | ValidateNumInputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
| 564 | ValidateNumOutputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 565 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", 2, "output"); |
| 566 | |
| 567 | if (!(workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 2 || |
| 568 | workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 4)) |
| 569 | { |
| 570 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Input tensor must have 2 or 4 dimensions."); |
| 571 | } |
| 572 | |
| 573 | if (m_Weight == nullptr) |
| 574 | { |
| 575 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Weight tensor descriptor is missing."); |
| 576 | } |
| 577 | |
| 578 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor", 2, "weight"); |
| 579 | |
| 580 | if (m_Parameters.m_BiasEnabled) |
| 581 | { |
| 582 | if (m_Bias == nullptr) |
| 583 | { |
| 584 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Bias is enabled but " |
| 585 | "bias value tensor descriptor is missing."); |
| 586 | } |
| 587 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 588 | // Validates type and quantization values. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 589 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 590 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor"); |
| 591 | |
| 592 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 593 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 594 | "FullyConnectedQueueDescriptor", "bias"); |
| 595 | |
| 596 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "FullyConnectedQueueDescriptor", 1, "bias"); |
| 597 | } |
| 598 | |
| 599 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 600 | workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", "input", "weights", "output"); |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 601 | |
| 602 | // Check the supported data types |
| 603 | std::vector<DataType> supportedTypes = |
| 604 | { |
| 605 | DataType::Float32, |
| 606 | DataType::Float16, |
| 607 | DataType::QuantisedAsymm8, |
| 608 | DataType::QuantisedSymm16 |
| 609 | }; |
| 610 | |
| 611 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 612 | supportedTypes, |
| 613 | "FullyConnectedQueueDescriptor"); |
| 614 | |
| 615 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 616 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 617 | "FullyConnectedQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | //--------------------------------------------------------------- |
| 621 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 622 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 623 | ValidateNumInputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
| 624 | ValidateNumOutputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 625 | |
| 626 | // Check the supported data types |
| 627 | std::vector<DataType> supportedTypes = |
| 628 | { |
| 629 | DataType::Float16, |
| 630 | DataType::Float32, |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 631 | DataType::QuantisedAsymm8, |
| 632 | DataType::QuantisedSymm16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 633 | }; |
| 634 | |
| 635 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 636 | supportedTypes, |
| 637 | "NormalizationQueueDescriptor"); |
| 638 | |
| 639 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 640 | { workloadInfo.m_InputTensorInfos[0].GetDataType() }, |
| 641 | "NormalizationQueueDescriptor"); |
| 642 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 643 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 644 | workloadInfo.m_OutputTensorInfos[0], |
| 645 | "NormalizationQueueDescriptor", |
| 646 | "input", |
| 647 | "output"); |
| 648 | } |
| 649 | |
| 650 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 651 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 652 | ValidateNumInputs(workloadInfo, "AdditionQueueDescriptor", 2); |
| 653 | ValidateNumOutputs(workloadInfo, "AdditionQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 654 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 655 | std::vector<DataType> supportedTypes = { |
| 656 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 657 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 658 | DataType::QuantisedSymm16, |
| 659 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 663 | supportedTypes, |
| 664 | "AdditionQueueDescriptor"); |
| 665 | |
| 666 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 667 | supportedTypes, |
| 668 | "AdditionQueueDescriptor"); |
| 669 | |
| 670 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 671 | supportedTypes, |
| 672 | "AdditionQueueDescriptor"); |
| 673 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 674 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 675 | workloadInfo.m_InputTensorInfos[1], |
| 676 | workloadInfo.m_OutputTensorInfos[0], |
| 677 | "AdditionQueueDescriptor", |
| 678 | "first input", |
| 679 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | //--------------------------------------------------------------- |
| 683 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 684 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 685 | ValidateNumInputs(workloadInfo, "MultiplicationQueueDescriptor", 2); |
| 686 | ValidateNumOutputs(workloadInfo, "MultiplicationQueueDescriptor", 1); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 687 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 688 | std::vector<DataType> supportedTypes = { |
| 689 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 690 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 691 | DataType::QuantisedSymm16, |
| 692 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 696 | supportedTypes, |
| 697 | "MultiplicationQueueDescriptor"); |
| 698 | |
| 699 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 700 | supportedTypes, |
| 701 | "MultiplicationQueueDescriptor"); |
| 702 | |
| 703 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 704 | supportedTypes, |
| 705 | "MultiplicationQueueDescriptor"); |
| 706 | |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 707 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 708 | workloadInfo.m_InputTensorInfos[1], |
| 709 | workloadInfo.m_OutputTensorInfos[0], |
| 710 | "MultiplicationQueueDescriptor", |
| 711 | "first input", |
| 712 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 716 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 717 | ValidateNumInputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
| 718 | ValidateNumOutputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 719 | |
| 720 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 721 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 722 | |
| 723 | std::vector<DataType> supportedTypes = |
| 724 | { |
| 725 | DataType::Float16, |
| 726 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 727 | DataType::QuantisedAsymm8, |
| 728 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | ValidateDataTypes(input, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 732 | ValidateDataTypes(output, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 733 | |
| 734 | ValidateDataTypes(output, { input.GetDataType() }, "BatchNormalizationQueueDescriptor"); |
| 735 | |
| 736 | ValidateTensorQuantizationSpace(input, output, "BatchNormalizationQueueDescriptor", "input", "output"); |
| 737 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 738 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 739 | workloadInfo.m_OutputTensorInfos[0], |
| 740 | "BatchNormalizationQueueDescriptor", |
| 741 | "input", |
| 742 | "output"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 743 | |
| 744 | ValidatePointer(m_Mean, "BatchNormalizationQueueDescriptor", "mean"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 745 | ValidatePointer(m_Variance, "BatchNormalizationQueueDescriptor", "variance"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 746 | ValidatePointer(m_Beta, "BatchNormalizationQueueDescriptor", "beta"); |
| 747 | ValidatePointer(m_Gamma, "BatchNormalizationQueueDescriptor", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 748 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 749 | const TensorInfo& mean = m_Mean->GetTensorInfo(); |
| 750 | const TensorInfo& variance = m_Variance->GetTensorInfo(); |
| 751 | const TensorInfo& beta = m_Beta->GetTensorInfo(); |
| 752 | const TensorInfo& gamma = m_Gamma->GetTensorInfo(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 753 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 754 | ValidateTensorNumDimensions(mean, "BatchNormalizationQueueDescriptor", 1, "mean"); |
| 755 | ValidateTensorNumDimensions(variance, "BatchNormalizationQueueDescriptor", 1, "variance"); |
| 756 | ValidateTensorNumDimensions(beta, "BatchNormalizationQueueDescriptor", 1, "beta"); |
| 757 | ValidateTensorNumDimensions(gamma, "BatchNormalizationQueueDescriptor", 1, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 758 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 759 | ValidateTensorShapesMatch(mean, variance, "BatchNormalizationQueueDescriptor", "mean", "variance"); |
| 760 | ValidateTensorShapesMatch(mean, beta, "BatchNormalizationQueueDescriptor", "mean", "beta"); |
| 761 | ValidateTensorShapesMatch(mean, gamma, "BatchNormalizationQueueDescriptor", "mean", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 765 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 766 | ValidateNumInputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
| 767 | ValidateNumOutputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 768 | |
| 769 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "input"); |
| 770 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "output"); |
| 771 | |
| 772 | ValidatePointer(m_Weight, "Convolution2dQueueDescriptor", "weight"); |
| 773 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor", 4, "weight"); |
| 774 | ValidateTensorDataType(m_Weight->GetTensorInfo(), workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 775 | "Convolution2dQueueDescriptor", "weight"); |
| 776 | if (m_Parameters.m_BiasEnabled) |
| 777 | { |
| 778 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "Convolution2dQueueDescriptor", 1, "bias"); |
| 779 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 780 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 781 | "Convolution2dQueueDescriptor", "bias"); |
| 782 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 783 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor"); |
| 784 | } |
| 785 | |
| 786 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 787 | workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", "input", "weights", "output"); |
| 788 | } |
| 789 | |
| 790 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 791 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 792 | ValidateNumInputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
| 793 | ValidateNumOutputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 794 | |
| 795 | ValidateTensorNumDimensions( |
| 796 | workloadInfo.m_InputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "input"); |
| 797 | ValidateTensorNumDimensions( |
| 798 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "output"); |
| 799 | |
| 800 | ValidatePointer(m_Weight, "DepthwiseConvolution2dQueueDescriptor", "weight"); |
| 801 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 4, "weight"); |
| 802 | |
Bruno Goncalves | 22972f0 | 2019-04-26 21:03:24 -0300 | [diff] [blame] | 803 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 804 | { |
| 805 | throw InvalidArgumentException( |
| 806 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: dilationX (provided %1%) " |
| 807 | "and dilationY (provided %2%) cannot be smaller than 1.") |
| 808 | % m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 809 | } |
| 810 | |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 811 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 812 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 813 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 814 | // inputChannels * channelMultiplier should be equal to outputChannels. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 815 | const unsigned int numWeightChannelMultiplier = m_Weight->GetTensorInfo().GetShape()[0]; |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 816 | const unsigned int numWeightInputChannels = m_Weight->GetTensorInfo().GetShape()[1]; |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 817 | const unsigned int numWeightOutputChannels = workloadInfo.m_OutputTensorInfos[0].GetShape()[channelIndex]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 818 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 819 | { |
| 820 | throw InvalidArgumentException( |
| 821 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: output_channels (provided %1%) should be " |
| 822 | "equal to input_channels (provided %2%) multiplied by channel_multiplier " |
| 823 | "(provided %3%).") |
| 824 | % numWeightOutputChannels % numWeightInputChannels % numWeightChannelMultiplier)); |
| 825 | } |
| 826 | |
| 827 | if (m_Parameters.m_BiasEnabled) |
| 828 | { |
| 829 | ValidatePointer(m_Bias, "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 830 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 1, "bias"); |
| 831 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 832 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor"); |
| 833 | |
| 834 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 835 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 836 | "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 837 | } |
| 838 | |
| 839 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 840 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", "input", "weights", "output"); |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 841 | |
| 842 | // Check the supported data types |
| 843 | std::vector<DataType> supportedTypes = { |
| 844 | DataType::Float32, |
| 845 | DataType::QuantisedAsymm8, |
| 846 | DataType::QuantisedSymm16, |
| 847 | DataType::Float16 |
| 848 | }; |
| 849 | |
| 850 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 851 | supportedTypes, |
| 852 | "DepthwiseConvolution2dQueueDescriptor"); |
| 853 | |
| 854 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 855 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 856 | "DepthwiseConvolution2dQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 860 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 861 | ValidateNumInputs(workloadInfo, "PermuteQueueDescriptor", 1); |
| 862 | ValidateNumOutputs(workloadInfo, "PermuteQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 863 | |
| 864 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 865 | |
| 866 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 867 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 868 | |
| 869 | ValidateTensorNumDimensions(input, "PermuteQueueDescriptor", mapping.GetSize(), "input"); |
| 870 | ValidateTensorNumDimensions(output, "PermuteQueueDescriptor", mapping.GetSize(), "output"); |
| 871 | |
| 872 | for (unsigned int i = 0; i < mapping.GetSize(); ++i) |
| 873 | { |
| 874 | if (input.GetShape()[i] != output.GetShape()[mapping[i]]) |
| 875 | { |
| 876 | throw InvalidArgumentException("PermuteQueueDescriptor: src dimension " + to_string(i) + |
| 877 | " (=" + to_string(input.GetShape()[i]) + ") " + |
| 878 | "must match dst dimension " + to_string(mapping[i]) + |
| 879 | " (=" + to_string(output.GetShape()[mapping[i]]) + ")"); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 885 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 886 | ValidateNumInputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
| 887 | ValidateNumOutputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 888 | |
| 889 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "input"); |
| 890 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "output"); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 891 | |
| 892 | std::vector<DataType> supportedTypes = |
| 893 | { |
| 894 | DataType::Float32, |
| 895 | DataType::Float16, |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 896 | DataType::QuantisedAsymm8, |
| 897 | DataType::QuantisedSymm16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 898 | }; |
| 899 | |
| 900 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 901 | supportedTypes, |
| 902 | "Pooling2dQueueDescriptor"); |
| 903 | |
| 904 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 905 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 906 | "Pooling2dQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 910 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 911 | ValidateNumInputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
| 912 | ValidateNumOutputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 913 | |
| 914 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "input"); |
| 915 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "output"); |
| 916 | |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 917 | std::vector<DataType> supportedTypes = |
| 918 | { |
| 919 | DataType::Float16, |
| 920 | DataType::Float32, |
| 921 | DataType::QuantisedAsymm8, |
| 922 | DataType::QuantisedSymm16 |
| 923 | }; |
| 924 | |
| 925 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 926 | supportedTypes, |
| 927 | "ResizeBilinearQueueDescriptor"); |
| 928 | |
| 929 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 930 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 931 | "ResizeBilinearQueueDescriptor"); |
| 932 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 933 | // Resizes bilinear only changes width and height: batch and channel count must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 934 | { |
| 935 | const unsigned int inputBatchSize = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 936 | const unsigned int outputBatchSize = workloadInfo.m_OutputTensorInfos[0].GetShape()[0]; |
| 937 | if (inputBatchSize != outputBatchSize) |
| 938 | { |
| 939 | throw InvalidArgumentException( |
| 940 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input batch size (%1%) " |
| 941 | "does not match output batch size (%2%)") % inputBatchSize % outputBatchSize)); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | { |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 946 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 947 | const unsigned int inputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 948 | workloadInfo.m_InputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 949 | const unsigned int outputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 950 | workloadInfo.m_OutputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 951 | if (inputChannelCount != outputChannelCount) |
| 952 | { |
| 953 | throw InvalidArgumentException( |
| 954 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input channel count (%1%) " |
| 955 | "does not match output channel count (%2%)") % inputChannelCount % outputChannelCount)); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 961 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 962 | ValidateNumInputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
| 963 | ValidateNumOutputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 964 | |
| 965 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "input"); |
| 966 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "output"); |
| 967 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 968 | workloadInfo.m_OutputTensorInfos[0], |
| 969 | "FakeQuantizationQueueDescriptor", |
| 970 | "input", |
| 971 | "output"); |
| 972 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 973 | { |
| 974 | throw InvalidArgumentException("FakeQuantizationQueueDescriptor: min cannot be greater than max"); |
| 975 | } |
| 976 | |
| 977 | } |
| 978 | |
| 979 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 980 | { |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 981 | const std::string& descriptorName = "L2NormalizationQueueDescriptor"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 982 | |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 983 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 984 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 985 | |
| 986 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], descriptorName, 4, "input"); |
| 987 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 988 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 989 | workloadInfo.m_OutputTensorInfos[0], |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 990 | descriptorName, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 991 | "input", |
| 992 | "output"); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 993 | |
| 994 | // Check the supported data types |
| 995 | std::vector<DataType> supportedTypes = |
| 996 | { |
| 997 | DataType::Float32, |
| 998 | DataType::Float16, |
| 999 | DataType::QuantisedAsymm8, |
| 1000 | DataType::QuantisedSymm16 |
| 1001 | }; |
| 1002 | |
| 1003 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
| 1004 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, descriptorName); |
| 1005 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1006 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1010 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1011 | ValidateNumInputs(workloadInfo, "ConstantQueueDescriptor", 0); |
| 1012 | ValidateNumOutputs(workloadInfo, "ConstantQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1013 | |
| 1014 | if (!m_LayerOutput) |
| 1015 | { |
| 1016 | throw InvalidArgumentException("ConstantQueueDescriptor: No const input specified"); |
| 1017 | } |
| 1018 | |
| 1019 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), |
| 1020 | workloadInfo.m_OutputTensorInfos[0], |
| 1021 | "ConstantQueueDescriptor", |
| 1022 | "constant", |
| 1023 | "output"); |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1024 | |
| 1025 | // Check the supported data types |
| 1026 | std::vector<DataType> supportedTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1027 | { |
| 1028 | DataType::Float32, |
| 1029 | DataType::Float16, |
| 1030 | DataType::Signed32, |
| 1031 | DataType::QuantisedAsymm8, |
| 1032 | DataType::QuantisedSymm16 |
| 1033 | }; |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1034 | |
| 1035 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ConstantQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1039 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1040 | ValidateNumInputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
| 1041 | ValidateNumOutputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1042 | |
| 1043 | if (workloadInfo.m_InputTensorInfos[0].GetNumElements() != workloadInfo.m_OutputTensorInfos[0].GetNumElements()) |
| 1044 | { |
| 1045 | throw InvalidArgumentException("ReshapeQueueDescriptor: Input tensor has " + |
| 1046 | to_string(workloadInfo.m_InputTensorInfos[0].GetNumElements()) + " but output tensor has " + |
| 1047 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1048 | } |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1049 | |
| 1050 | // Check the supported data types |
| 1051 | std::vector<DataType> supportedTypes = |
| 1052 | { |
| 1053 | DataType::Float32, |
| 1054 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1055 | DataType::QuantisedAsymm8, |
| 1056 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1057 | }; |
| 1058 | |
| 1059 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
| 1060 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1063 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1064 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1065 | ValidateNumInputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
| 1066 | ValidateNumOutputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1067 | |
| 1068 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "input"); |
| 1069 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "output"); |
| 1070 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1071 | if (m_Parameters.m_BlockShape.size() != 2) |
| 1072 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1073 | throw InvalidArgumentException("Block Shape must contain 2 spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 1077 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1078 | 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] | 1079 | } |
| 1080 | |
| 1081 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 1082 | |
| 1083 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
| 1084 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
| 1085 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1086 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1087 | unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1088 | + heightPad.first + heightPad.second; |
| 1089 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1090 | unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1091 | + widthPad.first + widthPad.second; |
| 1092 | |
| 1093 | unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1094 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1095 | |
| 1096 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 1097 | { |
| 1098 | throw InvalidArgumentException("SpaceToBatchNdQueueDescriptor: Input tensor has " + |
| 1099 | to_string(numInputElements) + " after padding but output tensor has " + |
| 1100 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1101 | } |
| 1102 | |
| 1103 | 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] | 1104 | { |
| 1105 | throw InvalidArgumentException( |
| 1106 | "Input shape after padding must be divisible by Block Shape in all spatial dimensions"); |
| 1107 | } |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1108 | |
| 1109 | std::vector<DataType> supportedTypes = |
| 1110 | { |
| 1111 | DataType::Float16, |
| 1112 | DataType::Float32, |
| 1113 | DataType::QuantisedAsymm8, |
| 1114 | DataType::QuantisedSymm16 |
| 1115 | }; |
| 1116 | |
| 1117 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1118 | supportedTypes, |
| 1119 | "SpaceToBatchNdQueueDescriptor"); |
| 1120 | |
| 1121 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1122 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1123 | "SpaceToBatchNdQueueDescriptor"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1126 | void SpaceToDepthQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1127 | { |
| 1128 | ValidateNumInputs(workloadInfo, "SpaceToDepthQueueDescriptor", 1); |
| 1129 | ValidateNumOutputs(workloadInfo, "SpaceToDepthQueueDescriptor", 1); |
| 1130 | |
| 1131 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], |
| 1132 | "SpaceToDepthQueueDescriptor", 4, "input"); |
| 1133 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], |
| 1134 | "SpaceToDepthQueueDescriptor", 4, "output"); |
| 1135 | |
| 1136 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1137 | |
| 1138 | std::vector<DataType> supportedTypes = |
| 1139 | { |
| 1140 | DataType::Float32, |
| 1141 | DataType::Float16, |
| 1142 | DataType::QuantisedAsymm8 |
| 1143 | }; |
| 1144 | |
| 1145 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1146 | supportedTypes, |
| 1147 | "SpaceToDepthQueueDescriptor"); |
| 1148 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1149 | supportedTypes, |
| 1150 | "SpaceToDepthQueueDescriptor"); |
| 1151 | |
| 1152 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 1153 | |
| 1154 | unsigned int numInputElements = inputShape[0] |
| 1155 | * inputShape[dimensionIndices.GetWidthIndex()] |
| 1156 | * inputShape[dimensionIndices.GetHeightIndex()] |
| 1157 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
| 1158 | |
| 1159 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 1160 | { |
| 1161 | throw InvalidArgumentException("SpaceToDepthQueueDescriptor: Input tensor has " + |
| 1162 | to_string(numInputElements) + " but output tensor has " + |
| 1163 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1164 | } |
| 1165 | |
| 1166 | if (inputShape[dimensionIndices.GetHeightIndex()] % m_Parameters.m_BlockSize != 0 || |
| 1167 | inputShape[dimensionIndices.GetWidthIndex()] % m_Parameters.m_BlockSize != 0) |
| 1168 | { |
| 1169 | throw InvalidArgumentException( |
| 1170 | "Input shape must be divisible by block size in all spatial dimensions"); |
| 1171 | } |
| 1172 | } |
| 1173 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1174 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1175 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1176 | const std::string floorQueueDescString = "FloorQueueDescriptor"; |
| 1177 | |
| 1178 | ValidateNumInputs(workloadInfo, floorQueueDescString, 1); |
| 1179 | ValidateNumOutputs(workloadInfo, floorQueueDescString, 1); |
| 1180 | |
| 1181 | std::vector<DataType> supportedTypes = |
| 1182 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 1183 | DataType::Float32, |
| 1184 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1185 | }; |
| 1186 | |
| 1187 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, floorQueueDescString); |
| 1188 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, floorQueueDescString); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (workloadInfo.m_InputTensorInfos[0] != workloadInfo.m_OutputTensorInfos[0]) |
| 1191 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1192 | throw InvalidArgumentException(floorQueueDescString + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1196 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1197 | { |
| 1198 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "LstmQueueDescriptor", 2, "input"); |
| 1199 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "LstmQueueDescriptor", 2, "output"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1200 | |
| 1201 | std::vector<DataType> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1202 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1203 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1204 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1205 | }; |
| 1206 | |
| 1207 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1208 | supportedTypes, |
| 1209 | "LstmQueueDescriptor"); |
| 1210 | |
| 1211 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1212 | supportedTypes, |
| 1213 | "LstmQueueDescriptor"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1217 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1218 | ValidateNumInputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
| 1219 | ValidateNumOutputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1220 | |
| 1221 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1222 | { |
| 1223 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Input tensor type must be Float32."); |
| 1224 | } |
| 1225 | |
| 1226 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1227 | { |
| 1228 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Output tensor type must be Float16."); |
| 1229 | } |
| 1230 | |
| 1231 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1232 | workloadInfo.m_OutputTensorInfos[0], |
| 1233 | "ConvertFp32ToFp16QueueDescriptor", |
| 1234 | "input", |
| 1235 | "output"); |
| 1236 | } |
| 1237 | |
| 1238 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1239 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1240 | ValidateNumInputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
| 1241 | ValidateNumOutputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1242 | |
| 1243 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1244 | { |
| 1245 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Input tensor type must be Float16."); |
| 1246 | } |
| 1247 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1248 | { |
| 1249 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Output tensor type must be Float32."); |
| 1250 | } |
| 1251 | |
| 1252 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1253 | workloadInfo.m_OutputTensorInfos[0], |
| 1254 | "ConvertFp16ToFp32QueueDescriptor", |
| 1255 | "input", |
| 1256 | "output"); |
| 1257 | } |
| 1258 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1259 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1260 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1261 | ValidateNumInputs(workloadInfo, "DivisionQueueDescriptor", 2); |
| 1262 | ValidateNumOutputs(workloadInfo, "DivisionQueueDescriptor", 1); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1263 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1264 | std::vector<DataType> supportedTypes = { |
| 1265 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1266 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1267 | DataType::QuantisedSymm16, |
| 1268 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1269 | }; |
| 1270 | |
| 1271 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1272 | supportedTypes, |
| 1273 | "DivisionQueueDescriptor"); |
| 1274 | |
| 1275 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1276 | supportedTypes, |
| 1277 | "DivisionQueueDescriptor"); |
| 1278 | |
| 1279 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1280 | supportedTypes, |
| 1281 | "DivisionQueueDescriptor"); |
| 1282 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1283 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1284 | workloadInfo.m_InputTensorInfos[1], |
| 1285 | workloadInfo.m_OutputTensorInfos[0], |
| 1286 | "DivisionQueueDescriptor", |
| 1287 | "first input", |
| 1288 | "second input"); |
| 1289 | } |
| 1290 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1291 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1292 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1293 | ValidateNumInputs(workloadInfo, "SubtractionQueueDescriptor", 2); |
| 1294 | ValidateNumOutputs(workloadInfo, "SubtractionQueueDescriptor", 1); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1295 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1296 | std::vector<DataType> supportedTypes = { |
| 1297 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1298 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1299 | DataType::QuantisedSymm16, |
| 1300 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1301 | }; |
| 1302 | |
| 1303 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1304 | supportedTypes, |
| 1305 | "SubtractionQueueDescriptor"); |
| 1306 | |
| 1307 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1308 | supportedTypes, |
| 1309 | "SubtractionQueueDescriptor"); |
| 1310 | |
| 1311 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1312 | supportedTypes, |
| 1313 | "SubtractionQueueDescriptor"); |
| 1314 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1315 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1316 | workloadInfo.m_InputTensorInfos[1], |
| 1317 | workloadInfo.m_OutputTensorInfos[0], |
| 1318 | "SubtractionQueueDescriptor", |
| 1319 | "first input", |
| 1320 | "second input"); |
| 1321 | } |
| 1322 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1323 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1324 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1325 | ValidateNumInputs(workloadInfo, "MaximumQueueDescriptor", 2); |
| 1326 | ValidateNumOutputs(workloadInfo, "MaximumQueueDescriptor", 1); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1327 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1328 | std::vector<DataType> supportedTypes = { |
| 1329 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1330 | DataType::QuantisedAsymm8, |
| 1331 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1332 | }; |
| 1333 | |
| 1334 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1335 | supportedTypes, |
| 1336 | "MaximumQueueDescriptor"); |
| 1337 | |
| 1338 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1339 | supportedTypes, |
| 1340 | "MaximumQueueDescriptor"); |
| 1341 | |
| 1342 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1343 | supportedTypes, |
| 1344 | "MaximumQueueDescriptor"); |
| 1345 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1346 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1347 | workloadInfo.m_InputTensorInfos[1], |
| 1348 | workloadInfo.m_OutputTensorInfos[0], |
| 1349 | "MaximumQueueDescriptor", |
| 1350 | "first input", |
| 1351 | "second input"); |
| 1352 | } |
| 1353 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1354 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1355 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1356 | const std::string meanQueueDescString = "MeanQueueDescriptor"; |
| 1357 | |
| 1358 | ValidateNumInputs(workloadInfo, meanQueueDescString, 1); |
| 1359 | ValidateNumOutputs(workloadInfo, meanQueueDescString, 1); |
| 1360 | |
| 1361 | std::vector<DataType> supportedTypes = |
| 1362 | { |
| 1363 | DataType::Float32, |
| 1364 | DataType::Float16, |
| 1365 | DataType::QuantisedAsymm8, |
| 1366 | DataType::QuantisedSymm16 |
| 1367 | }; |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1368 | |
| 1369 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1370 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1371 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1372 | // First check if input tensor data type is supported, then |
| 1373 | // check if this data type matches the output tensor data type |
| 1374 | ValidateDataTypes(input, supportedTypes, meanQueueDescString); |
| 1375 | ValidateTensorDataTypesMatch(input, output, meanQueueDescString, "input", "output"); |
| 1376 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1377 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1378 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1379 | ValidateTensorNumDimensions(output, meanQueueDescString, input.GetNumDimensions(), "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1380 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1381 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1382 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1383 | ValidateTensorNumDimensions(output, meanQueueDescString, 1, "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1384 | } |
| 1385 | else |
| 1386 | { |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1387 | 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] | 1388 | ValidateTensorNumDimensions(output, |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1389 | meanQueueDescString, |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1390 | outputDim > 0 ? outputDim : 1, |
| 1391 | "output"); |
| 1392 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1395 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1396 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1397 | ValidateNumInputs(workloadInfo, "PadQueueDescriptor", 1); |
| 1398 | ValidateNumOutputs(workloadInfo, "PadQueueDescriptor", 1); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1399 | |
| 1400 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1401 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1402 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1403 | // input and output should have the same number of dimensions |
| 1404 | ValidateTensorNumDimensions(output, "PadQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1405 | // there should be entry in the pad list for each dimension in the input tensor |
| 1406 | if (m_Parameters.m_PadList.size() != input.GetNumDimensions()) { |
| 1407 | throw InvalidArgumentException("Pad List should contain the same number of entries as there" |
| 1408 | " are dimensions in the input tensor that is " + |
| 1409 | to_string(input.GetNumDimensions()) + " entries " + |
| 1410 | " not " + to_string(m_Parameters.m_PadList.size()) + " entries."); |
| 1411 | } |
| 1412 | } |
| 1413 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1414 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1415 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1416 | ValidateNumInputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
| 1417 | ValidateNumOutputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1418 | |
| 1419 | |
| 1420 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1421 | { |
| 1422 | throw InvalidArgumentException("Quantize only accepts Float32 inputs."); |
| 1423 | } |
| 1424 | |
| 1425 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1426 | workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1427 | { |
| 1428 | throw InvalidArgumentException("Output of quantized layer must be quantized type."); |
| 1429 | } |
| 1430 | } |
| 1431 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1432 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1433 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1434 | ValidateNumInputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
| 1435 | ValidateNumOutputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1438 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1439 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1440 | ValidateNumInputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
| 1441 | ValidateNumOutputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1442 | |
| 1443 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1444 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1445 | |
| 1446 | std::vector<DataType> supportedTypes = |
| 1447 | { |
| 1448 | DataType::Float16, |
| 1449 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 1450 | DataType::QuantisedAsymm8, |
| 1451 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1452 | }; |
| 1453 | |
| 1454 | ValidateDataTypes(input, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1455 | ValidateDataTypes(output, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1456 | |
| 1457 | ValidateDataTypes(output, { input.GetDataType() }, "StridedSliceQueueDescriptor"); |
| 1458 | |
| 1459 | ValidateTensorQuantizationSpace(input, output, "StridedSliceQueueDescriptor", "input", "output"); |
| 1460 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1461 | const uint32_t rank = input.GetNumDimensions(); |
| 1462 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1463 | if (rank > 4) |
| 1464 | { |
| 1465 | throw InvalidArgumentException( |
| 1466 | "StridedSliceLayer: Input tensors with rank greater than 4 are not supported"); |
| 1467 | } |
| 1468 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1469 | // Begin, End & Stride length must be of rank(input0) |
| 1470 | if (m_Parameters.m_Begin.size() != rank) |
| 1471 | { |
| 1472 | throw InvalidArgumentException("StridedSliceLayer: Begin length must be of rank input0(" |
| 1473 | + to_string(rank) + ")"); |
| 1474 | } |
| 1475 | |
| 1476 | if (m_Parameters.m_End.size() != rank) |
| 1477 | { |
| 1478 | throw InvalidArgumentException("StridedSliceLayer: End length must be of rank input0(" |
| 1479 | + to_string(rank) + ")"); |
| 1480 | } |
| 1481 | |
| 1482 | if (m_Parameters.m_Stride.size() != rank) |
| 1483 | { |
| 1484 | throw InvalidArgumentException("StridedSliceLayer: Stride length must be of rank input0(" |
| 1485 | + to_string(rank) + ")"); |
| 1486 | } |
| 1487 | |
| 1488 | // Stride entries must be non-zero |
| 1489 | for (auto& stride : m_Parameters.m_Stride) |
| 1490 | { |
| 1491 | if (stride == 0) |
| 1492 | { |
| 1493 | throw InvalidArgumentException("StridedSliceLayer: Stride entries must be non-zero"); |
| 1494 | } |
| 1495 | } |
| 1496 | } |
| 1497 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1498 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1499 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1500 | ValidateNumInputs(workloadInfo, "MinimumQueueDescriptor", 2); |
| 1501 | ValidateNumOutputs(workloadInfo, "MinimumQueueDescriptor", 1); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1502 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1503 | std::vector<DataType> supportedTypes = { |
| 1504 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1505 | DataType::QuantisedAsymm8, |
| 1506 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1507 | }; |
| 1508 | |
| 1509 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1510 | supportedTypes, |
| 1511 | "MinimumQueueDescriptor"); |
| 1512 | |
| 1513 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1514 | supportedTypes, |
| 1515 | "MinimumQueueDescriptor"); |
| 1516 | |
| 1517 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1518 | supportedTypes, |
| 1519 | "MinimumQueueDescriptor"); |
| 1520 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1521 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1522 | workloadInfo.m_InputTensorInfos[1], |
| 1523 | workloadInfo.m_OutputTensorInfos[0], |
| 1524 | "MinimumQueueDescriptor", |
| 1525 | "first input", |
| 1526 | "second input"); |
| 1527 | } |
| 1528 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1529 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1530 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1531 | ValidateNumInputs(workloadInfo, "DebugQueueDescriptor", 1); |
| 1532 | ValidateNumOutputs(workloadInfo, "DebugQueueDescriptor", 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1535 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1536 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1537 | ValidateNumInputs(workloadInfo, "EqualQueueDescriptor", 2); |
| 1538 | ValidateNumOutputs(workloadInfo, "EqualQueueDescriptor", 1); |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1539 | |
| 1540 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1541 | workloadInfo.m_InputTensorInfos[1], |
| 1542 | workloadInfo.m_OutputTensorInfos[0], |
| 1543 | "EqualQueueDescriptor", |
| 1544 | "first input", |
| 1545 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1546 | |
| 1547 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1548 | { |
| 1549 | throw InvalidArgumentException("EqualQueueDescriptor: Output tensor type must be Boolean."); |
| 1550 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1553 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1554 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1555 | ValidateNumInputs(workloadInfo, "GreaterQueueDescriptor", 2); |
| 1556 | ValidateNumOutputs(workloadInfo, "GreaterQueueDescriptor", 1); |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1557 | |
| 1558 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1559 | workloadInfo.m_InputTensorInfos[1], |
| 1560 | workloadInfo.m_OutputTensorInfos[0], |
| 1561 | "GreaterQueueDescriptor", |
| 1562 | "first input", |
| 1563 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1564 | |
| 1565 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1566 | { |
| 1567 | throw InvalidArgumentException("GreaterQueueDescriptor: Output tensor type must be Boolean."); |
| 1568 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1571 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1572 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1573 | ValidateNumInputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
| 1574 | ValidateNumOutputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1575 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1576 | workloadInfo.m_OutputTensorInfos[0], |
| 1577 | "RsqrtQueueDescriptor", |
| 1578 | "input", |
| 1579 | "output"); |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1580 | |
| 1581 | std::vector<DataType> supportedTypes = |
| 1582 | { |
| 1583 | DataType::Float16, |
| 1584 | DataType::Float32, |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 1585 | DataType::QuantisedAsymm8, |
| 1586 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1587 | }; |
| 1588 | |
| 1589 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1590 | supportedTypes, |
| 1591 | "RsqrtQueueDescriptor"); |
| 1592 | |
| 1593 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1594 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1595 | "RsqrtQueueDescriptor"); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1598 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1599 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1600 | ValidateNumInputs(workloadInfo, "GatherQueueDescriptor", 2); |
| 1601 | ValidateNumOutputs(workloadInfo, "GatherQueueDescriptor", 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1602 | |
| 1603 | const TensorInfo& indices = workloadInfo.m_InputTensorInfos[1]; |
| 1604 | |
| 1605 | if (indices.GetDataType() != DataType::Signed32) |
| 1606 | { |
| 1607 | throw InvalidArgumentException("GatherQueueDescriptor: Indices tensor type must be int32."); |
| 1608 | } |
| 1609 | |
| 1610 | const TensorInfo& params = workloadInfo.m_InputTensorInfos[0]; |
| 1611 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1612 | unsigned int paramsDim = params.GetNumDimensions(); |
| 1613 | unsigned int indicesDim = indices.GetNumDimensions(); |
| 1614 | unsigned int outputDim = paramsDim - 1 + indicesDim; |
| 1615 | |
| 1616 | ValidateTensorNumDimensions(output, "GatherQueueDescriptor", outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1619 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1620 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1621 | const std::string& descriptorName = " DetectionPostProcessQueueDescriptor"; |
| 1622 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1623 | |
| 1624 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1625 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1626 | throw InvalidArgumentException(descriptorName + ": Requires exactly four outputs. " + |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1627 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 1628 | } |
| 1629 | |
| 1630 | if (m_Anchors == nullptr) |
| 1631 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1632 | throw InvalidArgumentException(descriptorName + ": Anchors tensor descriptor is missing."); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1636 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 1637 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 1638 | |
| 1639 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 1640 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1641 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
| 1642 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1643 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1644 | ValidateTensorNumDimensions(boxEncodingsInfo, descriptorName, 3, "box encodings"); |
| 1645 | ValidateTensorNumDimensions(scoresInfo, descriptorName, 3, "scores"); |
| 1646 | ValidateTensorNumDimensions(anchorsInfo, descriptorName, 2, "anchors"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1647 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1648 | const std::vector<DataType> supportedInputTypes = |
| 1649 | { |
| 1650 | DataType::Float32, |
| 1651 | DataType::QuantisedAsymm8, |
| 1652 | DataType::QuantisedSymm16 |
| 1653 | }; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1654 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1655 | ValidateDataTypes(boxEncodingsInfo, supportedInputTypes, descriptorName); |
| 1656 | ValidateDataTypes(scoresInfo, supportedInputTypes, descriptorName); |
| 1657 | ValidateDataTypes(anchorsInfo, supportedInputTypes, descriptorName); |
| 1658 | |
| 1659 | ValidateTensorNumDimensions(detectionBoxesInfo, descriptorName, 3, "detection boxes"); |
| 1660 | ValidateTensorNumDimensions(detectionScoresInfo, descriptorName, 2, "detection scores"); |
| 1661 | ValidateTensorNumDimensions(detectionClassesInfo, descriptorName, 2, "detection classes"); |
| 1662 | ValidateTensorNumDimensions(numDetectionsInfo, descriptorName, 1, "num detections"); |
| 1663 | |
| 1664 | // NOTE: Output is always Float32 regardless of input type |
| 1665 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, descriptorName, "detection boxes"); |
| 1666 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, descriptorName, "detection scores"); |
| 1667 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, descriptorName, "detection classes"); |
| 1668 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, descriptorName, "num detections"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1669 | |
| 1670 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 1671 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1672 | throw InvalidArgumentException(descriptorName + ": Intersection over union threshold " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1673 | "must be positive and less than or equal to 1."); |
| 1674 | } |
| 1675 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 1676 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1677 | throw InvalidArgumentException(descriptorName + ": Number of classes with background " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1678 | "should be equal to number of classes + 1."); |
| 1679 | } |
| 1680 | } |
| 1681 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1682 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1683 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1684 | ValidateNumInputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
| 1685 | ValidateNumOutputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1686 | |
| 1687 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1688 | workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1689 | { |
| 1690 | throw InvalidArgumentException("Input to dequantize layer must be quantized type."); |
| 1691 | } |
| 1692 | |
| 1693 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1694 | { |
| 1695 | throw InvalidArgumentException("Output of dequantize layer must be Float32 type."); |
| 1696 | } |
| 1697 | } |
| 1698 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1699 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1700 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1701 | ValidateNumInputs(workloadInfo, "MergeQueueDescriptor", 2); |
| 1702 | ValidateNumOutputs(workloadInfo, "MergeQueueDescriptor", 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1703 | |
| 1704 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1705 | workloadInfo.m_InputTensorInfos[1], |
| 1706 | "MergeQueueDescriptor", |
| 1707 | "input0", |
| 1708 | "input1"); |
| 1709 | |
| 1710 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1711 | workloadInfo.m_OutputTensorInfos[0], |
| 1712 | "MergeQueueDescriptor", |
| 1713 | "input0", |
| 1714 | "output"); |
| 1715 | |
| 1716 | const DataType dataType = workloadInfo.m_InputTensorInfos[0].GetDataType(); |
| 1717 | ValidateTensorDataType(workloadInfo.m_InputTensorInfos[1], dataType, "MergeQueueDescriptor", "input1"); |
| 1718 | ValidateTensorDataType(workloadInfo.m_OutputTensorInfos[0], dataType, "MergeQueueDescriptor", "output"); |
| 1719 | } |
| 1720 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1721 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1722 | { |
| 1723 | ValidateNumInputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1724 | ValidateNumOutputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1725 | |
| 1726 | std::vector<DataType> supportedTypes = { |
| 1727 | DataType::Float32, |
| 1728 | DataType::QuantisedAsymm8, |
| 1729 | DataType::QuantisedSymm16 |
| 1730 | }; |
| 1731 | |
| 1732 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1733 | supportedTypes, |
| 1734 | "SwitchQueueDescriptor"); |
| 1735 | |
| 1736 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1737 | supportedTypes, |
| 1738 | "SwitchQueueDescriptor"); |
| 1739 | |
| 1740 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1741 | supportedTypes, |
| 1742 | "SwitchQueueDescriptor"); |
| 1743 | |
| 1744 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1745 | workloadInfo.m_OutputTensorInfos[0], |
| 1746 | "SwitchQueueDescriptor", |
| 1747 | "input0", |
| 1748 | "output0"); |
| 1749 | |
| 1750 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1751 | workloadInfo.m_OutputTensorInfos[1], |
| 1752 | "SwitchQueueDescriptor", |
| 1753 | "input0", |
| 1754 | "output1"); |
| 1755 | } |
| 1756 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 1757 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1758 | { |
| 1759 | // This is internally generated so it should not need validation. |
| 1760 | } |
| 1761 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 1762 | void PreluQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1763 | { |
| 1764 | ValidateNumInputs(workloadInfo, "PreluQueueDescriptor", 2); |
| 1765 | ValidateNumOutputs(workloadInfo, "PreluQueueDescriptor", 1); |
| 1766 | |
| 1767 | std::vector<DataType> supportedTypes |
| 1768 | { |
| 1769 | DataType::Float16, |
| 1770 | DataType::Float32, |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 1771 | DataType::QuantisedAsymm8, |
| 1772 | DataType::QuantisedSymm16 |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 1773 | }; |
| 1774 | |
| 1775 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1776 | supportedTypes, |
| 1777 | "PreluQueueDescriptor"); |
| 1778 | |
| 1779 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1780 | supportedTypes, |
| 1781 | "PreluQueueDescriptor"); |
| 1782 | |
| 1783 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1784 | supportedTypes, |
| 1785 | "PreluQueueDescriptor"); |
| 1786 | |
| 1787 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1788 | { workloadInfo.m_InputTensorInfos[1].GetDataType() }, |
| 1789 | "PreluQueueDescriptor"); |
| 1790 | |
| 1791 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1792 | { workloadInfo.m_OutputTensorInfos[0].GetDataType() }, |
| 1793 | "PreluQueueDescriptor"); |
| 1794 | |
| 1795 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1796 | workloadInfo.m_InputTensorInfos[1], |
| 1797 | workloadInfo.m_OutputTensorInfos[0], |
| 1798 | "PreluQueueDescriptor", |
| 1799 | "input", |
| 1800 | "alpha"); |
| 1801 | } |
| 1802 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame^] | 1803 | void TransposeConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1804 | { |
| 1805 | const std::string descriptorName{"TransposeConvolution2dQueueDescriptor"}; |
| 1806 | |
| 1807 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1808 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1809 | |
| 1810 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], descriptorName, 4, "input"); |
| 1811 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], descriptorName, 4, "output"); |
| 1812 | |
| 1813 | ValidatePointer(m_Weight, descriptorName, "weight"); |
| 1814 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), descriptorName, 4, "weight"); |
| 1815 | |
| 1816 | ValidateTensorDataType(m_Weight->GetTensorInfo(), |
| 1817 | workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 1818 | descriptorName, |
| 1819 | "weight"); |
| 1820 | |
| 1821 | if (m_Parameters.m_BiasEnabled) |
| 1822 | { |
| 1823 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), descriptorName, 1, "bias"); |
| 1824 | |
| 1825 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 1826 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 1827 | descriptorName, "bias"); |
| 1828 | |
| 1829 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 1830 | workloadInfo.m_InputTensorInfos[0], |
| 1831 | m_Weight->GetTensorInfo(), |
| 1832 | descriptorName); |
| 1833 | } |
| 1834 | |
| 1835 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], |
| 1836 | m_Weight->GetTensorInfo(), |
| 1837 | workloadInfo.m_OutputTensorInfos[0], |
| 1838 | descriptorName, |
| 1839 | "input", |
| 1840 | "weights", |
| 1841 | "output"); |
| 1842 | } |
| 1843 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1844 | } //namespace armnn |