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 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1126 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1127 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1128 | const std::string floorQueueDescString = "FloorQueueDescriptor"; |
| 1129 | |
| 1130 | ValidateNumInputs(workloadInfo, floorQueueDescString, 1); |
| 1131 | ValidateNumOutputs(workloadInfo, floorQueueDescString, 1); |
| 1132 | |
| 1133 | std::vector<DataType> supportedTypes = |
| 1134 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 1135 | DataType::Float32, |
| 1136 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1137 | }; |
| 1138 | |
| 1139 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, floorQueueDescString); |
| 1140 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, floorQueueDescString); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1141 | |
| 1142 | if (workloadInfo.m_InputTensorInfos[0] != workloadInfo.m_OutputTensorInfos[0]) |
| 1143 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1144 | throw InvalidArgumentException(floorQueueDescString + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1148 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1149 | { |
| 1150 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "LstmQueueDescriptor", 2, "input"); |
| 1151 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "LstmQueueDescriptor", 2, "output"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1152 | |
| 1153 | std::vector<DataType> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1154 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1155 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1156 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1157 | }; |
| 1158 | |
| 1159 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1160 | supportedTypes, |
| 1161 | "LstmQueueDescriptor"); |
| 1162 | |
| 1163 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1164 | supportedTypes, |
| 1165 | "LstmQueueDescriptor"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1169 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1170 | ValidateNumInputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
| 1171 | ValidateNumOutputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1172 | |
| 1173 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1174 | { |
| 1175 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Input tensor type must be Float32."); |
| 1176 | } |
| 1177 | |
| 1178 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1179 | { |
| 1180 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Output tensor type must be Float16."); |
| 1181 | } |
| 1182 | |
| 1183 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1184 | workloadInfo.m_OutputTensorInfos[0], |
| 1185 | "ConvertFp32ToFp16QueueDescriptor", |
| 1186 | "input", |
| 1187 | "output"); |
| 1188 | } |
| 1189 | |
| 1190 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1191 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1192 | ValidateNumInputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
| 1193 | ValidateNumOutputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1194 | |
| 1195 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1196 | { |
| 1197 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Input tensor type must be Float16."); |
| 1198 | } |
| 1199 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1200 | { |
| 1201 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Output tensor type must be Float32."); |
| 1202 | } |
| 1203 | |
| 1204 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1205 | workloadInfo.m_OutputTensorInfos[0], |
| 1206 | "ConvertFp16ToFp32QueueDescriptor", |
| 1207 | "input", |
| 1208 | "output"); |
| 1209 | } |
| 1210 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1211 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1212 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1213 | ValidateNumInputs(workloadInfo, "DivisionQueueDescriptor", 2); |
| 1214 | ValidateNumOutputs(workloadInfo, "DivisionQueueDescriptor", 1); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1215 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1216 | std::vector<DataType> supportedTypes = { |
| 1217 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1218 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1219 | DataType::QuantisedSymm16, |
| 1220 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1221 | }; |
| 1222 | |
| 1223 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1224 | supportedTypes, |
| 1225 | "DivisionQueueDescriptor"); |
| 1226 | |
| 1227 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1228 | supportedTypes, |
| 1229 | "DivisionQueueDescriptor"); |
| 1230 | |
| 1231 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1232 | supportedTypes, |
| 1233 | "DivisionQueueDescriptor"); |
| 1234 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1235 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1236 | workloadInfo.m_InputTensorInfos[1], |
| 1237 | workloadInfo.m_OutputTensorInfos[0], |
| 1238 | "DivisionQueueDescriptor", |
| 1239 | "first input", |
| 1240 | "second input"); |
| 1241 | } |
| 1242 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1243 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1244 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1245 | ValidateNumInputs(workloadInfo, "SubtractionQueueDescriptor", 2); |
| 1246 | ValidateNumOutputs(workloadInfo, "SubtractionQueueDescriptor", 1); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1247 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1248 | std::vector<DataType> supportedTypes = { |
| 1249 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1250 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1251 | DataType::QuantisedSymm16, |
| 1252 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1253 | }; |
| 1254 | |
| 1255 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1256 | supportedTypes, |
| 1257 | "SubtractionQueueDescriptor"); |
| 1258 | |
| 1259 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1260 | supportedTypes, |
| 1261 | "SubtractionQueueDescriptor"); |
| 1262 | |
| 1263 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1264 | supportedTypes, |
| 1265 | "SubtractionQueueDescriptor"); |
| 1266 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1267 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1268 | workloadInfo.m_InputTensorInfos[1], |
| 1269 | workloadInfo.m_OutputTensorInfos[0], |
| 1270 | "SubtractionQueueDescriptor", |
| 1271 | "first input", |
| 1272 | "second input"); |
| 1273 | } |
| 1274 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1275 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1276 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1277 | ValidateNumInputs(workloadInfo, "MaximumQueueDescriptor", 2); |
| 1278 | ValidateNumOutputs(workloadInfo, "MaximumQueueDescriptor", 1); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1279 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1280 | std::vector<DataType> supportedTypes = { |
| 1281 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1282 | DataType::QuantisedAsymm8, |
| 1283 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1284 | }; |
| 1285 | |
| 1286 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1287 | supportedTypes, |
| 1288 | "MaximumQueueDescriptor"); |
| 1289 | |
| 1290 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1291 | supportedTypes, |
| 1292 | "MaximumQueueDescriptor"); |
| 1293 | |
| 1294 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1295 | supportedTypes, |
| 1296 | "MaximumQueueDescriptor"); |
| 1297 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1298 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1299 | workloadInfo.m_InputTensorInfos[1], |
| 1300 | workloadInfo.m_OutputTensorInfos[0], |
| 1301 | "MaximumQueueDescriptor", |
| 1302 | "first input", |
| 1303 | "second input"); |
| 1304 | } |
| 1305 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1306 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1307 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1308 | const std::string meanQueueDescString = "MeanQueueDescriptor"; |
| 1309 | |
| 1310 | ValidateNumInputs(workloadInfo, meanQueueDescString, 1); |
| 1311 | ValidateNumOutputs(workloadInfo, meanQueueDescString, 1); |
| 1312 | |
| 1313 | std::vector<DataType> supportedTypes = |
| 1314 | { |
| 1315 | DataType::Float32, |
| 1316 | DataType::Float16, |
| 1317 | DataType::QuantisedAsymm8, |
| 1318 | DataType::QuantisedSymm16 |
| 1319 | }; |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1320 | |
| 1321 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1322 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1323 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1324 | // First check if input tensor data type is supported, then |
| 1325 | // check if this data type matches the output tensor data type |
| 1326 | ValidateDataTypes(input, supportedTypes, meanQueueDescString); |
| 1327 | ValidateTensorDataTypesMatch(input, output, meanQueueDescString, "input", "output"); |
| 1328 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1329 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1330 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1331 | ValidateTensorNumDimensions(output, meanQueueDescString, input.GetNumDimensions(), "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1332 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1333 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1334 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1335 | ValidateTensorNumDimensions(output, meanQueueDescString, 1, "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1336 | } |
| 1337 | else |
| 1338 | { |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1339 | 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] | 1340 | ValidateTensorNumDimensions(output, |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1341 | meanQueueDescString, |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1342 | outputDim > 0 ? outputDim : 1, |
| 1343 | "output"); |
| 1344 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1347 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1348 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1349 | ValidateNumInputs(workloadInfo, "PadQueueDescriptor", 1); |
| 1350 | ValidateNumOutputs(workloadInfo, "PadQueueDescriptor", 1); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1351 | |
| 1352 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1353 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1354 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1355 | // input and output should have the same number of dimensions |
| 1356 | ValidateTensorNumDimensions(output, "PadQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1357 | // there should be entry in the pad list for each dimension in the input tensor |
| 1358 | if (m_Parameters.m_PadList.size() != input.GetNumDimensions()) { |
| 1359 | throw InvalidArgumentException("Pad List should contain the same number of entries as there" |
| 1360 | " are dimensions in the input tensor that is " + |
| 1361 | to_string(input.GetNumDimensions()) + " entries " + |
| 1362 | " not " + to_string(m_Parameters.m_PadList.size()) + " entries."); |
| 1363 | } |
| 1364 | } |
| 1365 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1366 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1367 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1368 | ValidateNumInputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
| 1369 | ValidateNumOutputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1370 | |
| 1371 | |
| 1372 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1373 | { |
| 1374 | throw InvalidArgumentException("Quantize only accepts Float32 inputs."); |
| 1375 | } |
| 1376 | |
| 1377 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1378 | workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1379 | { |
| 1380 | throw InvalidArgumentException("Output of quantized layer must be quantized type."); |
| 1381 | } |
| 1382 | } |
| 1383 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1384 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1385 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1386 | ValidateNumInputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
| 1387 | ValidateNumOutputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1390 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1391 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1392 | ValidateNumInputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
| 1393 | ValidateNumOutputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1394 | |
| 1395 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1396 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1397 | |
| 1398 | std::vector<DataType> supportedTypes = |
| 1399 | { |
| 1400 | DataType::Float16, |
| 1401 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 1402 | DataType::QuantisedAsymm8, |
| 1403 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1404 | }; |
| 1405 | |
| 1406 | ValidateDataTypes(input, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1407 | ValidateDataTypes(output, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1408 | |
| 1409 | ValidateDataTypes(output, { input.GetDataType() }, "StridedSliceQueueDescriptor"); |
| 1410 | |
| 1411 | ValidateTensorQuantizationSpace(input, output, "StridedSliceQueueDescriptor", "input", "output"); |
| 1412 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1413 | const uint32_t rank = input.GetNumDimensions(); |
| 1414 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1415 | if (rank > 4) |
| 1416 | { |
| 1417 | throw InvalidArgumentException( |
| 1418 | "StridedSliceLayer: Input tensors with rank greater than 4 are not supported"); |
| 1419 | } |
| 1420 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1421 | // Begin, End & Stride length must be of rank(input0) |
| 1422 | if (m_Parameters.m_Begin.size() != rank) |
| 1423 | { |
| 1424 | throw InvalidArgumentException("StridedSliceLayer: Begin length must be of rank input0(" |
| 1425 | + to_string(rank) + ")"); |
| 1426 | } |
| 1427 | |
| 1428 | if (m_Parameters.m_End.size() != rank) |
| 1429 | { |
| 1430 | throw InvalidArgumentException("StridedSliceLayer: End length must be of rank input0(" |
| 1431 | + to_string(rank) + ")"); |
| 1432 | } |
| 1433 | |
| 1434 | if (m_Parameters.m_Stride.size() != rank) |
| 1435 | { |
| 1436 | throw InvalidArgumentException("StridedSliceLayer: Stride length must be of rank input0(" |
| 1437 | + to_string(rank) + ")"); |
| 1438 | } |
| 1439 | |
| 1440 | // Stride entries must be non-zero |
| 1441 | for (auto& stride : m_Parameters.m_Stride) |
| 1442 | { |
| 1443 | if (stride == 0) |
| 1444 | { |
| 1445 | throw InvalidArgumentException("StridedSliceLayer: Stride entries must be non-zero"); |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1450 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1451 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1452 | ValidateNumInputs(workloadInfo, "MinimumQueueDescriptor", 2); |
| 1453 | ValidateNumOutputs(workloadInfo, "MinimumQueueDescriptor", 1); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1454 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1455 | std::vector<DataType> supportedTypes = { |
| 1456 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1457 | DataType::QuantisedAsymm8, |
| 1458 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1459 | }; |
| 1460 | |
| 1461 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1462 | supportedTypes, |
| 1463 | "MinimumQueueDescriptor"); |
| 1464 | |
| 1465 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1466 | supportedTypes, |
| 1467 | "MinimumQueueDescriptor"); |
| 1468 | |
| 1469 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1470 | supportedTypes, |
| 1471 | "MinimumQueueDescriptor"); |
| 1472 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1473 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1474 | workloadInfo.m_InputTensorInfos[1], |
| 1475 | workloadInfo.m_OutputTensorInfos[0], |
| 1476 | "MinimumQueueDescriptor", |
| 1477 | "first input", |
| 1478 | "second input"); |
| 1479 | } |
| 1480 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1481 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1482 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1483 | ValidateNumInputs(workloadInfo, "DebugQueueDescriptor", 1); |
| 1484 | ValidateNumOutputs(workloadInfo, "DebugQueueDescriptor", 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1487 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1488 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1489 | ValidateNumInputs(workloadInfo, "EqualQueueDescriptor", 2); |
| 1490 | ValidateNumOutputs(workloadInfo, "EqualQueueDescriptor", 1); |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1491 | |
| 1492 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1493 | workloadInfo.m_InputTensorInfos[1], |
| 1494 | workloadInfo.m_OutputTensorInfos[0], |
| 1495 | "EqualQueueDescriptor", |
| 1496 | "first input", |
| 1497 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1498 | |
| 1499 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1500 | { |
| 1501 | throw InvalidArgumentException("EqualQueueDescriptor: Output tensor type must be Boolean."); |
| 1502 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1505 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1506 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1507 | ValidateNumInputs(workloadInfo, "GreaterQueueDescriptor", 2); |
| 1508 | ValidateNumOutputs(workloadInfo, "GreaterQueueDescriptor", 1); |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1509 | |
| 1510 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1511 | workloadInfo.m_InputTensorInfos[1], |
| 1512 | workloadInfo.m_OutputTensorInfos[0], |
| 1513 | "GreaterQueueDescriptor", |
| 1514 | "first input", |
| 1515 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1516 | |
| 1517 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1518 | { |
| 1519 | throw InvalidArgumentException("GreaterQueueDescriptor: Output tensor type must be Boolean."); |
| 1520 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1523 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1524 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1525 | ValidateNumInputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
| 1526 | ValidateNumOutputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1527 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1528 | workloadInfo.m_OutputTensorInfos[0], |
| 1529 | "RsqrtQueueDescriptor", |
| 1530 | "input", |
| 1531 | "output"); |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1532 | |
| 1533 | std::vector<DataType> supportedTypes = |
| 1534 | { |
| 1535 | DataType::Float16, |
| 1536 | DataType::Float32, |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 1537 | DataType::QuantisedAsymm8, |
| 1538 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1539 | }; |
| 1540 | |
| 1541 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1542 | supportedTypes, |
| 1543 | "RsqrtQueueDescriptor"); |
| 1544 | |
| 1545 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1546 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1547 | "RsqrtQueueDescriptor"); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1550 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1551 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1552 | ValidateNumInputs(workloadInfo, "GatherQueueDescriptor", 2); |
| 1553 | ValidateNumOutputs(workloadInfo, "GatherQueueDescriptor", 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1554 | |
| 1555 | const TensorInfo& indices = workloadInfo.m_InputTensorInfos[1]; |
| 1556 | |
| 1557 | if (indices.GetDataType() != DataType::Signed32) |
| 1558 | { |
| 1559 | throw InvalidArgumentException("GatherQueueDescriptor: Indices tensor type must be int32."); |
| 1560 | } |
| 1561 | |
| 1562 | const TensorInfo& params = workloadInfo.m_InputTensorInfos[0]; |
| 1563 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1564 | unsigned int paramsDim = params.GetNumDimensions(); |
| 1565 | unsigned int indicesDim = indices.GetNumDimensions(); |
| 1566 | unsigned int outputDim = paramsDim - 1 + indicesDim; |
| 1567 | |
| 1568 | ValidateTensorNumDimensions(output, "GatherQueueDescriptor", outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1571 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1572 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1573 | const std::string& descriptorName = " DetectionPostProcessQueueDescriptor"; |
| 1574 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1575 | |
| 1576 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1577 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1578 | throw InvalidArgumentException(descriptorName + ": Requires exactly four outputs. " + |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1579 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 1580 | } |
| 1581 | |
| 1582 | if (m_Anchors == nullptr) |
| 1583 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1584 | throw InvalidArgumentException(descriptorName + ": Anchors tensor descriptor is missing."); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1588 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 1589 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 1590 | |
| 1591 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 1592 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1593 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
| 1594 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1595 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1596 | ValidateTensorNumDimensions(boxEncodingsInfo, descriptorName, 3, "box encodings"); |
| 1597 | ValidateTensorNumDimensions(scoresInfo, descriptorName, 3, "scores"); |
| 1598 | ValidateTensorNumDimensions(anchorsInfo, descriptorName, 2, "anchors"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1599 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1600 | const std::vector<DataType> supportedInputTypes = |
| 1601 | { |
| 1602 | DataType::Float32, |
| 1603 | DataType::QuantisedAsymm8, |
| 1604 | DataType::QuantisedSymm16 |
| 1605 | }; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1606 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1607 | ValidateDataTypes(boxEncodingsInfo, supportedInputTypes, descriptorName); |
| 1608 | ValidateDataTypes(scoresInfo, supportedInputTypes, descriptorName); |
| 1609 | ValidateDataTypes(anchorsInfo, supportedInputTypes, descriptorName); |
| 1610 | |
| 1611 | ValidateTensorNumDimensions(detectionBoxesInfo, descriptorName, 3, "detection boxes"); |
| 1612 | ValidateTensorNumDimensions(detectionScoresInfo, descriptorName, 2, "detection scores"); |
| 1613 | ValidateTensorNumDimensions(detectionClassesInfo, descriptorName, 2, "detection classes"); |
| 1614 | ValidateTensorNumDimensions(numDetectionsInfo, descriptorName, 1, "num detections"); |
| 1615 | |
| 1616 | // NOTE: Output is always Float32 regardless of input type |
| 1617 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, descriptorName, "detection boxes"); |
| 1618 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, descriptorName, "detection scores"); |
| 1619 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, descriptorName, "detection classes"); |
| 1620 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, descriptorName, "num detections"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1621 | |
| 1622 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 1623 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1624 | throw InvalidArgumentException(descriptorName + ": Intersection over union threshold " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1625 | "must be positive and less than or equal to 1."); |
| 1626 | } |
| 1627 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 1628 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 1629 | throw InvalidArgumentException(descriptorName + ": Number of classes with background " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1630 | "should be equal to number of classes + 1."); |
| 1631 | } |
| 1632 | } |
| 1633 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1634 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1635 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1636 | ValidateNumInputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
| 1637 | ValidateNumOutputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1638 | |
| 1639 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1640 | workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1641 | { |
| 1642 | throw InvalidArgumentException("Input to dequantize layer must be quantized type."); |
| 1643 | } |
| 1644 | |
| 1645 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1646 | { |
| 1647 | throw InvalidArgumentException("Output of dequantize layer must be Float32 type."); |
| 1648 | } |
| 1649 | } |
| 1650 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1651 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1652 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1653 | ValidateNumInputs(workloadInfo, "MergeQueueDescriptor", 2); |
| 1654 | ValidateNumOutputs(workloadInfo, "MergeQueueDescriptor", 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1655 | |
| 1656 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1657 | workloadInfo.m_InputTensorInfos[1], |
| 1658 | "MergeQueueDescriptor", |
| 1659 | "input0", |
| 1660 | "input1"); |
| 1661 | |
| 1662 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1663 | workloadInfo.m_OutputTensorInfos[0], |
| 1664 | "MergeQueueDescriptor", |
| 1665 | "input0", |
| 1666 | "output"); |
| 1667 | |
| 1668 | const DataType dataType = workloadInfo.m_InputTensorInfos[0].GetDataType(); |
| 1669 | ValidateTensorDataType(workloadInfo.m_InputTensorInfos[1], dataType, "MergeQueueDescriptor", "input1"); |
| 1670 | ValidateTensorDataType(workloadInfo.m_OutputTensorInfos[0], dataType, "MergeQueueDescriptor", "output"); |
| 1671 | } |
| 1672 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1673 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1674 | { |
| 1675 | ValidateNumInputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1676 | ValidateNumOutputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1677 | |
| 1678 | std::vector<DataType> supportedTypes = { |
| 1679 | DataType::Float32, |
| 1680 | DataType::QuantisedAsymm8, |
| 1681 | DataType::QuantisedSymm16 |
| 1682 | }; |
| 1683 | |
| 1684 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1685 | supportedTypes, |
| 1686 | "SwitchQueueDescriptor"); |
| 1687 | |
| 1688 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1689 | supportedTypes, |
| 1690 | "SwitchQueueDescriptor"); |
| 1691 | |
| 1692 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1693 | supportedTypes, |
| 1694 | "SwitchQueueDescriptor"); |
| 1695 | |
| 1696 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1697 | workloadInfo.m_OutputTensorInfos[0], |
| 1698 | "SwitchQueueDescriptor", |
| 1699 | "input0", |
| 1700 | "output0"); |
| 1701 | |
| 1702 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1703 | workloadInfo.m_OutputTensorInfos[1], |
| 1704 | "SwitchQueueDescriptor", |
| 1705 | "input0", |
| 1706 | "output1"); |
| 1707 | } |
| 1708 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 1709 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1710 | { |
| 1711 | // This is internally generated so it should not need validation. |
| 1712 | } |
| 1713 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 1714 | void PreluQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1715 | { |
| 1716 | ValidateNumInputs(workloadInfo, "PreluQueueDescriptor", 2); |
| 1717 | ValidateNumOutputs(workloadInfo, "PreluQueueDescriptor", 1); |
| 1718 | |
| 1719 | std::vector<DataType> supportedTypes |
| 1720 | { |
| 1721 | DataType::Float16, |
| 1722 | DataType::Float32, |
| 1723 | DataType::QuantisedAsymm8 |
| 1724 | }; |
| 1725 | |
| 1726 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1727 | supportedTypes, |
| 1728 | "PreluQueueDescriptor"); |
| 1729 | |
| 1730 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1731 | supportedTypes, |
| 1732 | "PreluQueueDescriptor"); |
| 1733 | |
| 1734 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1735 | supportedTypes, |
| 1736 | "PreluQueueDescriptor"); |
| 1737 | |
| 1738 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1739 | { workloadInfo.m_InputTensorInfos[1].GetDataType() }, |
| 1740 | "PreluQueueDescriptor"); |
| 1741 | |
| 1742 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1743 | { workloadInfo.m_OutputTensorInfos[0].GetDataType() }, |
| 1744 | "PreluQueueDescriptor"); |
| 1745 | |
| 1746 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1747 | workloadInfo.m_InputTensorInfos[1], |
| 1748 | workloadInfo.m_OutputTensorInfos[0], |
| 1749 | "PreluQueueDescriptor", |
| 1750 | "input", |
| 1751 | "alpha"); |
| 1752 | } |
| 1753 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1754 | } //namespace armnn |