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 | //--------------------------------------------------------------- |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 117 | void ValidateTensorNumElements(const TensorInfo& tensor, |
| 118 | std::string const& descName, |
| 119 | unsigned int numElements, |
| 120 | std::string const& tensorName) |
| 121 | { |
| 122 | if (tensor.GetNumElements() != numElements) |
| 123 | { |
| 124 | throw InvalidArgumentException(descName + ": Expected " + to_string(numElements) + " but got " + |
| 125 | to_string(tensor.GetNumDimensions()) + " elements for " + |
| 126 | tensorName + " tensor."); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | //--------------------------------------------------------------- |
| 131 | void ValidateTensorNumDimNumElem(const TensorInfo& tensorInfo, |
| 132 | unsigned int numDimension, |
| 133 | unsigned int numElements, |
| 134 | std::string const& tensorName) |
| 135 | { |
| 136 | ValidateTensorNumDimensions(tensorInfo, "ValidateTensorNumDimNumElem: NumDimensionCheck", numDimension, tensorName); |
| 137 | ValidateTensorNumElements(tensorInfo, "ValidateTensorNumDimNumElem: NumElementsCheck", numElements, tensorName); |
| 138 | } |
| 139 | |
| 140 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 141 | void ValidateTensorDataType(const TensorInfo& tensor, DataType dataType, |
| 142 | const std::string& descName, std::string const& tensorName) |
| 143 | { |
| 144 | if (tensor.GetDataType() != dataType) |
| 145 | { |
| 146 | throw InvalidArgumentException(descName + ": Expected data type " + GetDataTypeName(dataType) + " but got " + |
| 147 | GetDataTypeName(tensor.GetDataType()) + " for " + tensorName + " tensor."); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | //--------------------------------------------------------------- |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 152 | void ValidateTensorQuantizationSpace(const TensorInfo& first, |
| 153 | const TensorInfo& second, |
| 154 | const std::string& descName, |
| 155 | std::string const& firstName, |
| 156 | std::string const& secondName) |
| 157 | { |
| 158 | if (!first.IsQuantized() || |
| 159 | !second.IsQuantized()) |
| 160 | { |
| 161 | // Not a quantized type, ignore the validation |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | DataType firstDataType = first.GetDataType(); |
| 166 | DataType secondDataType = second.GetDataType(); |
| 167 | |
| 168 | if (firstDataType != secondDataType) |
| 169 | { |
| 170 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 171 | " must be of the same quantized type, " + |
| 172 | firstName + " is " + GetDataTypeName(firstDataType) + ", " + |
| 173 | secondName + " is " + GetDataTypeName(secondDataType)); |
| 174 | } |
| 175 | |
| 176 | if (!first.IsTypeSpaceMatch(second)) |
| 177 | { |
| 178 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 179 | " must have the same quantization space, " + |
| 180 | firstName + " has offset " + to_string(first.GetQuantizationOffset()) + |
| 181 | " and scale " + to_string(first.GetQuantizationScale()) + ", " + |
| 182 | secondName + " has offset " + to_string(second.GetQuantizationOffset()) + |
| 183 | " and scale " + to_string(second.GetQuantizationScale())); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 188 | void ValidateBiasTensorQuantization(const TensorInfo& biasTensor, const TensorInfo& inputTensorInfo, |
| 189 | const TensorInfo& weightsTensorInfo, const std::string& descName) |
| 190 | { |
| 191 | if (biasTensor.GetQuantizationOffset() != 0) |
| 192 | { |
| 193 | throw InvalidArgumentException(descName + ": Expected zero quantization offset for bias tensor but got " + |
| 194 | to_string(biasTensor.GetQuantizationOffset())); |
| 195 | } |
| 196 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightsTensorInfo.GetQuantizationScale(); |
kevmay01 | 6c46dd3 | 2018-12-17 15:32:45 +0000 | [diff] [blame] | 197 | if (std::abs(biasTensor.GetQuantizationScale() - expectedScale) > 0.00000001f) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 198 | { |
| 199 | // Print the float values with extra precision to see very small differences |
| 200 | std::stringstream msg; |
| 201 | msg << std::setprecision(10) << descName << ": Expected " << expectedScale << |
| 202 | " quantization scale for bias tensor (the product of the input and weight scales), but got " << |
| 203 | biasTensor.GetQuantizationScale(); |
| 204 | throw InvalidArgumentException(msg.str()); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | //--------------------------------------------------------------- |
| 209 | void ValidateTensors(const std::vector<ITensorHandle*>& vec, |
| 210 | unsigned int numExpected, |
| 211 | const std::string& descName, |
| 212 | const std::string& varName) |
| 213 | { |
| 214 | if (vec.empty() && numExpected > 0) |
| 215 | { |
| 216 | throw InvalidArgumentException(descName + ": Invalid empty " + varName + " array."); |
| 217 | } |
| 218 | |
| 219 | for (unsigned int i = 0; i < numExpected; ++i) |
| 220 | { |
| 221 | if (!vec[i]) |
| 222 | { |
| 223 | throw InvalidArgumentException(descName + ": Invalid NULL for " + varName + to_string(i)); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | //--------------------------------------------------------------- |
| 229 | void ValidateBroadcastTensorShapesMatch(const TensorInfo& first, |
| 230 | const TensorInfo& second, |
| 231 | const TensorInfo& output, |
| 232 | std::string const& descName, |
| 233 | std::string const& firstName, |
| 234 | std::string const& secondName) |
| 235 | { |
| 236 | // Tensors must have the same number of dimensions in order to be explicit about which dimensions will get |
| 237 | // broadcasted. |
| 238 | if (first.GetNumDimensions() != second.GetNumDimensions()) |
| 239 | { |
| 240 | throw InvalidArgumentException(descName + ": Tensors " |
| 241 | + firstName + " & " + secondName |
| 242 | + " must have the same number of dimensions in order to be broadcasted"); |
| 243 | } |
| 244 | uint32_t numDims = first.GetNumDimensions(); |
| 245 | std::vector<uint32_t> outputDims(numDims, 0u); |
| 246 | for (uint32_t i = 0; i < numDims; i++) |
| 247 | { |
| 248 | const bool dimsNotEqual = first.GetShape()[i] != second.GetShape()[i]; |
| 249 | const bool dimsNotOne = (first.GetShape()[i] != 1) && (second.GetShape()[i] != 1); |
| 250 | if (dimsNotEqual && dimsNotOne) |
| 251 | { |
| 252 | throw InvalidArgumentException("Broadcasting is not possible for incompatible shapes"); |
| 253 | } |
| 254 | outputDims[i] = std::max(first.GetShape()[i], second.GetShape()[i]); |
| 255 | } |
| 256 | TensorShape broadcastShape = TensorShape(boost::numeric_cast<unsigned int>(outputDims.size()), outputDims.data()); |
| 257 | if (broadcastShape != output.GetShape()) |
| 258 | { |
| 259 | throw InvalidArgumentException(descName + ": The tensor shape resulting from adding " |
| 260 | + firstName + " & " + secondName |
| 261 | + " does not match the output shape"); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | //--------------------------------------------------------------- |
| 266 | /// Validates that the output tensor's quantization scale is greater than the product |
| 267 | /// of the two input tensors' quantization scales. This is a requirement of the implementation of |
| 268 | /// the quantized multiplication. |
| 269 | void ValidateTensorQuantizationMultiplier(const TensorInfo& inputTensor1, const TensorInfo& inputTensor2, |
| 270 | const TensorInfo& outputTensorInfo, std::string const& descName, |
| 271 | const std::string& inputTensor1Name, const std::string& inputTensor2Name, const std::string& outputTensorName) |
| 272 | { |
| 273 | if (outputTensorInfo.GetDataType() == DataType::QuantisedAsymm8) |
| 274 | { |
| 275 | if (outputTensorInfo.GetQuantizationScale() <= |
| 276 | inputTensor1.GetQuantizationScale() * inputTensor2.GetQuantizationScale()) |
| 277 | { |
| 278 | std::stringstream msg; |
| 279 | msg << descName << ": Quantization scale of " << outputTensorName << " is not greater than " << |
| 280 | "the product of the " << inputTensor1Name << " and " << inputTensor2Name << " tensors"; |
| 281 | throw InvalidArgumentException(msg.str()); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 286 | //--------------------------------------------------------------- |
| 287 | void ValidateDataTypes(const TensorInfo& info, |
| 288 | const std::vector<armnn::DataType>& supportedTypes, |
| 289 | std::string const& descName) |
| 290 | { |
| 291 | auto iterator = std::find(supportedTypes.begin(), supportedTypes.end(), info.GetDataType()); |
| 292 | if (iterator == supportedTypes.end()) |
| 293 | { |
| 294 | throw InvalidArgumentException(descName + ": " + " Tensor type is not supported."); |
| 295 | } |
| 296 | } |
| 297 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 298 | //--------------------------------------------------------------- |
| 299 | void ValidateTensorDataTypesMatch(const TensorInfo& first, |
| 300 | const TensorInfo& second, |
| 301 | std::string const& descName, |
| 302 | std::string const& firstName, |
| 303 | std::string const& secondName) |
| 304 | { |
| 305 | if (first.GetDataType() != second.GetDataType()) |
| 306 | { |
| 307 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 308 | " must have identical data types."); |
| 309 | } |
| 310 | } |
| 311 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 312 | } //namespace |
| 313 | |
| 314 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 315 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 316 | { |
| 317 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 318 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 319 | } |
| 320 | |
| 321 | //--------------------------------------------------------------- |
| 322 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 323 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 324 | ValidateNumInputs(workloadInfo, "MemCopyQueueDescriptor", 1); |
| 325 | ValidateNumOutputs(workloadInfo, "MemCopyQueueDescriptor" , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 326 | |
| 327 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 328 | { |
| 329 | throw InvalidArgumentException(boost::str( |
| 330 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 331 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 332 | } |
| 333 | |
| 334 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 335 | { |
| 336 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 337 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 338 | { |
| 339 | throw InvalidArgumentException(boost::str( |
| 340 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 341 | % i )); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if (m_Inputs.size() != m_Outputs.size()) |
| 346 | { |
| 347 | throw InvalidArgumentException(boost::str( |
| 348 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 349 | % m_Inputs.size() % m_Outputs.size())); |
| 350 | } |
| 351 | |
| 352 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 353 | { |
| 354 | if (!m_Inputs[i]) |
| 355 | { |
| 356 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 357 | } |
| 358 | |
| 359 | if (!m_Outputs[i]) |
| 360 | { |
| 361 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | //--------------------------------------------------------------- |
| 367 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 368 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 369 | ValidateNumInputs(workloadInfo, "ActivationQueueDescriptor", 1); |
| 370 | ValidateNumOutputs(workloadInfo, "ActivationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 371 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 372 | workloadInfo.m_OutputTensorInfos[0], |
| 373 | "ActivationQueueDescriptor", |
| 374 | "input", |
| 375 | "output"); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 376 | |
| 377 | std::vector<DataType> supportedTypes = { |
| 378 | DataType::Float32, |
| 379 | DataType::Float16, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 380 | DataType::QuantisedAsymm8, |
| 381 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 385 | supportedTypes, |
| 386 | "ActivationQueueDescriptor"); |
| 387 | |
| 388 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 389 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 390 | "ActivationQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | //--------------------------------------------------------------- |
| 394 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 395 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 396 | ValidateNumInputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
| 397 | ValidateNumOutputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 398 | |
| 399 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 400 | workloadInfo.m_OutputTensorInfos[0], |
| 401 | "SoftmaxQueueDescriptor", |
| 402 | "input", |
| 403 | "output"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 404 | |
| 405 | std::vector<DataType> supportedTypes = |
| 406 | { |
| 407 | DataType::Float16, |
| 408 | DataType::Float32, |
| 409 | DataType::QuantisedAsymm8, |
| 410 | DataType::QuantisedSymm16 |
| 411 | }; |
| 412 | |
| 413 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 414 | supportedTypes, |
| 415 | "SoftmaxQueueDescriptor"); |
| 416 | |
| 417 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 418 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 419 | "SoftmaxQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | //--------------------------------------------------------------- |
| 423 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 424 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 425 | ValidateNumInputs(workloadInfo, "SplitterQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 426 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 427 | // Check the supported data types |
| 428 | std::vector<DataType> supportedTypes = |
| 429 | { |
| 430 | DataType::Float32, |
| 431 | DataType::Float16, |
| 432 | DataType::Boolean, |
| 433 | DataType::Signed32, |
| 434 | DataType::QuantisedAsymm8, |
| 435 | DataType::QuantisedSymm16 |
| 436 | }; |
| 437 | |
| 438 | for (unsigned long i = 0; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
| 439 | { |
| 440 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[i], |
| 441 | supportedTypes, |
| 442 | "SplitterQueueDescriptor"); |
| 443 | } |
| 444 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 445 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 446 | "SplitterQueueDescriptor"); |
| 447 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 448 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 449 | { |
| 450 | throw InvalidArgumentException("SplitterQueueDescriptor: At least one output needs to be provided."); |
| 451 | } |
| 452 | |
| 453 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 454 | { |
| 455 | throw InvalidArgumentException( |
| 456 | "SplitterQueueDescriptor: Number of split windows " |
| 457 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 458 | "Number of windows: " + |
| 459 | to_string(m_ViewOrigins.size()) + |
| 460 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 461 | } |
| 462 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 463 | //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] | 464 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 465 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 466 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 467 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 468 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 469 | if (e.m_Origin.size() != inputDims) |
| 470 | { |
| 471 | throw InvalidArgumentException("SplitterQueueDescriptor: Window origin have to " |
| 472 | "have the same dimensionality as the input tensor. " |
| 473 | "Window origin (index: " + |
| 474 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 475 | " dimensions, the input " |
| 476 | "tensor has " + |
| 477 | to_string(inputDims) + " dimensions."); |
| 478 | } |
| 479 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 480 | { |
| 481 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 482 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 483 | { |
| 484 | throw InvalidArgumentException("SplitterQueueDescriptor: Window extent coordinates have to " |
| 485 | "be smaller or equal than the size of the input in that coord."); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | //--------------------------------------------------------------- |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 492 | void ConcatQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 493 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 494 | ValidateNumOutputs(workloadInfo, "ConcatQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 495 | |
| 496 | if (m_Inputs.size() <= 0) |
| 497 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 498 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 499 | } |
| 500 | if (m_Outputs.size() <= 0) |
| 501 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 502 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 506 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 507 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 508 | } |
| 509 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 510 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 511 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 514 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 515 | { |
| 516 | throw InvalidArgumentException("Invalid Concatenation Axis provided"); |
| 517 | } |
| 518 | |
| 519 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 520 | { |
| 521 | return; |
| 522 | } |
| 523 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 524 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 525 | { |
| 526 | throw InvalidArgumentException( |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 527 | "ConcatQueueDescriptor: Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 528 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 529 | "Number of windows: " + |
| 530 | to_string(m_ViewOrigins.size()) + |
| 531 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 532 | } |
| 533 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 534 | //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] | 535 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 536 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 537 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 538 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 539 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 540 | if (e.m_Origin.size() != outputDims) |
| 541 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 542 | throw InvalidArgumentException("ConcatQueueDescriptor: Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 543 | "have the same dimensionality as the output tensor. " |
| 544 | "Window origin (index: " + |
| 545 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 546 | " dimensions, the output " |
| 547 | "tensor has " + |
| 548 | to_string(outputDims) + " dimensions."); |
| 549 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 550 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 551 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 552 | { |
| 553 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 554 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 555 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 556 | throw InvalidArgumentException("ConcatQueueDescriptor: Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 557 | "be smaller or equal than the size of the output in that coord."); |
| 558 | } |
| 559 | } |
| 560 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 561 | |
| 562 | // Check the supported data types |
| 563 | std::vector<DataType> supportedTypes = |
| 564 | { |
| 565 | DataType::Float32, |
| 566 | DataType::Float16, |
| 567 | DataType::Boolean, |
| 568 | DataType::Signed32, |
| 569 | DataType::QuantisedAsymm8, |
| 570 | DataType::QuantisedSymm16 |
| 571 | }; |
| 572 | |
| 573 | for (unsigned long i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 574 | { |
| 575 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[i], |
| 576 | supportedTypes, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 577 | "ConcatQueueDescriptor"); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 578 | } |
| 579 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 580 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 581 | "ConcatQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | //--------------------------------------------------------------- |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame^] | 585 | void StackQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 586 | { |
| 587 | ValidateNumOutputs(workloadInfo, "StackQueueDescriptor", 1); |
| 588 | |
| 589 | if (m_Parameters.m_NumInputs != workloadInfo.m_InputTensorInfos.size()) |
| 590 | { |
| 591 | throw InvalidArgumentException("StackQueueDescriptor: Must have the defined number of input tensors."); |
| 592 | } |
| 593 | |
| 594 | // All inputs must have the same shape, which is defined in parameters |
| 595 | const TensorShape& inputShape = m_Parameters.m_InputShape; |
| 596 | for (unsigned int i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 597 | { |
| 598 | if (workloadInfo.m_InputTensorInfos[i].GetShape() != inputShape) |
| 599 | { |
| 600 | throw InvalidArgumentException("StackQueueDescriptor: All input tensor shapes " |
| 601 | "must match the defined shape."); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // m_Axis is 0-based and may take values from 0 to the number of input dimensions (inclusive), |
| 606 | // since the output tensor has an additional dimension. |
| 607 | if (m_Parameters.m_Axis > inputShape.GetNumDimensions()) |
| 608 | { |
| 609 | throw InvalidArgumentException("StackQueueDescriptor: Axis may not be greater " |
| 610 | "than the number of input dimensions."); |
| 611 | } |
| 612 | |
| 613 | // Output shape must be as inferred from the input shape |
| 614 | const TensorShape& outputShape = workloadInfo.m_OutputTensorInfos[0].GetShape(); |
| 615 | for (unsigned int i = 0; i < m_Parameters.m_Axis; ++i) |
| 616 | { |
| 617 | if (outputShape[i] != inputShape[i]) |
| 618 | { |
| 619 | throw InvalidArgumentException("StackQueueDescriptor: Output tensor must " |
| 620 | "match shape inferred from input tensor."); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | if (outputShape[m_Parameters.m_Axis] != m_Parameters.m_NumInputs) |
| 625 | { |
| 626 | throw InvalidArgumentException("StackQueueDescriptor: Output tensor must " |
| 627 | "match shape inferred from input tensor."); |
| 628 | } |
| 629 | |
| 630 | for (unsigned int i = m_Parameters.m_Axis + 1; i < inputShape.GetNumDimensions() + 1; ++i) |
| 631 | { |
| 632 | if (outputShape[i] != inputShape[i-1]) |
| 633 | { |
| 634 | throw InvalidArgumentException("StackQueueDescriptor: Output tensor must " |
| 635 | "match shape inferred from input tensor."); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | // Check the supported data types |
| 640 | std::vector<DataType> supportedTypes = |
| 641 | { |
| 642 | DataType::Float32, |
| 643 | DataType::Float16, |
| 644 | DataType::Boolean, |
| 645 | DataType::Signed32, |
| 646 | DataType::QuantisedAsymm8, |
| 647 | DataType::QuantisedSymm16 |
| 648 | }; |
| 649 | |
| 650 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 651 | supportedTypes, |
| 652 | "StackQueueDescriptor"); |
| 653 | |
| 654 | for (unsigned int i = 1; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 655 | { |
| 656 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 657 | workloadInfo.m_InputTensorInfos[i], |
| 658 | "StackQueueDescriptor", |
| 659 | "InputTensor[0]", |
| 660 | "InputTensor[" + std::to_string(i) + "]"); |
| 661 | } |
| 662 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 663 | workloadInfo.m_OutputTensorInfos[0], |
| 664 | "StackQueueDescriptor", |
| 665 | "InputTensor[0]", |
| 666 | "OutputTensor[0]"); |
| 667 | } |
| 668 | |
| 669 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 670 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 671 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 672 | ValidateNumInputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
| 673 | ValidateNumOutputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 674 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", 2, "output"); |
| 675 | |
| 676 | if (!(workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 2 || |
| 677 | workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 4)) |
| 678 | { |
| 679 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Input tensor must have 2 or 4 dimensions."); |
| 680 | } |
| 681 | |
| 682 | if (m_Weight == nullptr) |
| 683 | { |
| 684 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Weight tensor descriptor is missing."); |
| 685 | } |
| 686 | |
| 687 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor", 2, "weight"); |
| 688 | |
| 689 | if (m_Parameters.m_BiasEnabled) |
| 690 | { |
| 691 | if (m_Bias == nullptr) |
| 692 | { |
| 693 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Bias is enabled but " |
| 694 | "bias value tensor descriptor is missing."); |
| 695 | } |
| 696 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 697 | // Validates type and quantization values. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 698 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 699 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor"); |
| 700 | |
| 701 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 702 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 703 | "FullyConnectedQueueDescriptor", "bias"); |
| 704 | |
| 705 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "FullyConnectedQueueDescriptor", 1, "bias"); |
| 706 | } |
| 707 | |
| 708 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 709 | workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", "input", "weights", "output"); |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 710 | |
| 711 | // Check the supported data types |
| 712 | std::vector<DataType> supportedTypes = |
| 713 | { |
| 714 | DataType::Float32, |
| 715 | DataType::Float16, |
| 716 | DataType::QuantisedAsymm8, |
| 717 | DataType::QuantisedSymm16 |
| 718 | }; |
| 719 | |
| 720 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 721 | supportedTypes, |
| 722 | "FullyConnectedQueueDescriptor"); |
| 723 | |
| 724 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 725 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 726 | "FullyConnectedQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | //--------------------------------------------------------------- |
| 730 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 731 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 732 | ValidateNumInputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
| 733 | ValidateNumOutputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 734 | |
| 735 | // Check the supported data types |
| 736 | std::vector<DataType> supportedTypes = |
| 737 | { |
| 738 | DataType::Float16, |
| 739 | DataType::Float32, |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 740 | DataType::QuantisedAsymm8, |
| 741 | DataType::QuantisedSymm16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 742 | }; |
| 743 | |
| 744 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 745 | supportedTypes, |
| 746 | "NormalizationQueueDescriptor"); |
| 747 | |
| 748 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 749 | { workloadInfo.m_InputTensorInfos[0].GetDataType() }, |
| 750 | "NormalizationQueueDescriptor"); |
| 751 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 752 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 753 | workloadInfo.m_OutputTensorInfos[0], |
| 754 | "NormalizationQueueDescriptor", |
| 755 | "input", |
| 756 | "output"); |
| 757 | } |
| 758 | |
| 759 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 760 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 761 | ValidateNumInputs(workloadInfo, "AdditionQueueDescriptor", 2); |
| 762 | ValidateNumOutputs(workloadInfo, "AdditionQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 763 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 764 | std::vector<DataType> supportedTypes = { |
| 765 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 766 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 767 | DataType::QuantisedSymm16, |
| 768 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 769 | }; |
| 770 | |
| 771 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 772 | supportedTypes, |
| 773 | "AdditionQueueDescriptor"); |
| 774 | |
| 775 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 776 | supportedTypes, |
| 777 | "AdditionQueueDescriptor"); |
| 778 | |
| 779 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 780 | supportedTypes, |
| 781 | "AdditionQueueDescriptor"); |
| 782 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 783 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 784 | workloadInfo.m_InputTensorInfos[1], |
| 785 | workloadInfo.m_OutputTensorInfos[0], |
| 786 | "AdditionQueueDescriptor", |
| 787 | "first input", |
| 788 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | //--------------------------------------------------------------- |
| 792 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 793 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 794 | ValidateNumInputs(workloadInfo, "MultiplicationQueueDescriptor", 2); |
| 795 | ValidateNumOutputs(workloadInfo, "MultiplicationQueueDescriptor", 1); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 796 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 797 | std::vector<DataType> supportedTypes = { |
| 798 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 799 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 800 | DataType::QuantisedSymm16, |
| 801 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 802 | }; |
| 803 | |
| 804 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 805 | supportedTypes, |
| 806 | "MultiplicationQueueDescriptor"); |
| 807 | |
| 808 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 809 | supportedTypes, |
| 810 | "MultiplicationQueueDescriptor"); |
| 811 | |
| 812 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 813 | supportedTypes, |
| 814 | "MultiplicationQueueDescriptor"); |
| 815 | |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 816 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 817 | workloadInfo.m_InputTensorInfos[1], |
| 818 | workloadInfo.m_OutputTensorInfos[0], |
| 819 | "MultiplicationQueueDescriptor", |
| 820 | "first input", |
| 821 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 825 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 826 | ValidateNumInputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
| 827 | ValidateNumOutputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 828 | |
| 829 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 830 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 831 | |
| 832 | std::vector<DataType> supportedTypes = |
| 833 | { |
| 834 | DataType::Float16, |
| 835 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 836 | DataType::QuantisedAsymm8, |
| 837 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 838 | }; |
| 839 | |
| 840 | ValidateDataTypes(input, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 841 | ValidateDataTypes(output, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 842 | |
| 843 | ValidateDataTypes(output, { input.GetDataType() }, "BatchNormalizationQueueDescriptor"); |
| 844 | |
| 845 | ValidateTensorQuantizationSpace(input, output, "BatchNormalizationQueueDescriptor", "input", "output"); |
| 846 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 847 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 848 | workloadInfo.m_OutputTensorInfos[0], |
| 849 | "BatchNormalizationQueueDescriptor", |
| 850 | "input", |
| 851 | "output"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 852 | |
| 853 | ValidatePointer(m_Mean, "BatchNormalizationQueueDescriptor", "mean"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 854 | ValidatePointer(m_Variance, "BatchNormalizationQueueDescriptor", "variance"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 855 | ValidatePointer(m_Beta, "BatchNormalizationQueueDescriptor", "beta"); |
| 856 | ValidatePointer(m_Gamma, "BatchNormalizationQueueDescriptor", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 857 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 858 | const TensorInfo& mean = m_Mean->GetTensorInfo(); |
| 859 | const TensorInfo& variance = m_Variance->GetTensorInfo(); |
| 860 | const TensorInfo& beta = m_Beta->GetTensorInfo(); |
| 861 | const TensorInfo& gamma = m_Gamma->GetTensorInfo(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 862 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 863 | ValidateTensorNumDimensions(mean, "BatchNormalizationQueueDescriptor", 1, "mean"); |
| 864 | ValidateTensorNumDimensions(variance, "BatchNormalizationQueueDescriptor", 1, "variance"); |
| 865 | ValidateTensorNumDimensions(beta, "BatchNormalizationQueueDescriptor", 1, "beta"); |
| 866 | ValidateTensorNumDimensions(gamma, "BatchNormalizationQueueDescriptor", 1, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 867 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 868 | ValidateTensorShapesMatch(mean, variance, "BatchNormalizationQueueDescriptor", "mean", "variance"); |
| 869 | ValidateTensorShapesMatch(mean, beta, "BatchNormalizationQueueDescriptor", "mean", "beta"); |
| 870 | ValidateTensorShapesMatch(mean, gamma, "BatchNormalizationQueueDescriptor", "mean", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 874 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 875 | ValidateNumInputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
| 876 | ValidateNumOutputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 877 | |
| 878 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "input"); |
| 879 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "output"); |
| 880 | |
| 881 | ValidatePointer(m_Weight, "Convolution2dQueueDescriptor", "weight"); |
| 882 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor", 4, "weight"); |
| 883 | ValidateTensorDataType(m_Weight->GetTensorInfo(), workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 884 | "Convolution2dQueueDescriptor", "weight"); |
| 885 | if (m_Parameters.m_BiasEnabled) |
| 886 | { |
| 887 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "Convolution2dQueueDescriptor", 1, "bias"); |
| 888 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 889 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 890 | "Convolution2dQueueDescriptor", "bias"); |
| 891 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 892 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor"); |
| 893 | } |
| 894 | |
| 895 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 896 | workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", "input", "weights", "output"); |
| 897 | } |
| 898 | |
| 899 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 900 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 901 | ValidateNumInputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
| 902 | ValidateNumOutputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 903 | |
| 904 | ValidateTensorNumDimensions( |
| 905 | workloadInfo.m_InputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "input"); |
| 906 | ValidateTensorNumDimensions( |
| 907 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "output"); |
| 908 | |
| 909 | ValidatePointer(m_Weight, "DepthwiseConvolution2dQueueDescriptor", "weight"); |
| 910 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 4, "weight"); |
| 911 | |
Bruno Goncalves | 22972f0 | 2019-04-26 21:03:24 -0300 | [diff] [blame] | 912 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 913 | { |
| 914 | throw InvalidArgumentException( |
| 915 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: dilationX (provided %1%) " |
| 916 | "and dilationY (provided %2%) cannot be smaller than 1.") |
| 917 | % m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 918 | } |
| 919 | |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 920 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 921 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 922 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 923 | // inputChannels * channelMultiplier should be equal to outputChannels. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 924 | const unsigned int numWeightChannelMultiplier = m_Weight->GetTensorInfo().GetShape()[0]; |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 925 | const unsigned int numWeightInputChannels = m_Weight->GetTensorInfo().GetShape()[1]; |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 926 | const unsigned int numWeightOutputChannels = workloadInfo.m_OutputTensorInfos[0].GetShape()[channelIndex]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 927 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 928 | { |
| 929 | throw InvalidArgumentException( |
| 930 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: output_channels (provided %1%) should be " |
| 931 | "equal to input_channels (provided %2%) multiplied by channel_multiplier " |
| 932 | "(provided %3%).") |
| 933 | % numWeightOutputChannels % numWeightInputChannels % numWeightChannelMultiplier)); |
| 934 | } |
| 935 | |
| 936 | if (m_Parameters.m_BiasEnabled) |
| 937 | { |
| 938 | ValidatePointer(m_Bias, "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 939 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 1, "bias"); |
| 940 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 941 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor"); |
| 942 | |
| 943 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 944 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 945 | "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 946 | } |
| 947 | |
| 948 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 949 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", "input", "weights", "output"); |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 950 | |
| 951 | // Check the supported data types |
| 952 | std::vector<DataType> supportedTypes = { |
| 953 | DataType::Float32, |
| 954 | DataType::QuantisedAsymm8, |
| 955 | DataType::QuantisedSymm16, |
| 956 | DataType::Float16 |
| 957 | }; |
| 958 | |
| 959 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 960 | supportedTypes, |
| 961 | "DepthwiseConvolution2dQueueDescriptor"); |
| 962 | |
| 963 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 964 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 965 | "DepthwiseConvolution2dQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 969 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 970 | ValidateNumInputs(workloadInfo, "PermuteQueueDescriptor", 1); |
| 971 | ValidateNumOutputs(workloadInfo, "PermuteQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 972 | |
| 973 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 974 | |
| 975 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 976 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 977 | |
| 978 | ValidateTensorNumDimensions(input, "PermuteQueueDescriptor", mapping.GetSize(), "input"); |
| 979 | ValidateTensorNumDimensions(output, "PermuteQueueDescriptor", mapping.GetSize(), "output"); |
| 980 | |
| 981 | for (unsigned int i = 0; i < mapping.GetSize(); ++i) |
| 982 | { |
| 983 | if (input.GetShape()[i] != output.GetShape()[mapping[i]]) |
| 984 | { |
| 985 | throw InvalidArgumentException("PermuteQueueDescriptor: src dimension " + to_string(i) + |
| 986 | " (=" + to_string(input.GetShape()[i]) + ") " + |
| 987 | "must match dst dimension " + to_string(mapping[i]) + |
| 988 | " (=" + to_string(output.GetShape()[mapping[i]]) + ")"); |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 994 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 995 | ValidateNumInputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
| 996 | ValidateNumOutputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 997 | |
| 998 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "input"); |
| 999 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "output"); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1000 | |
| 1001 | std::vector<DataType> supportedTypes = |
| 1002 | { |
| 1003 | DataType::Float32, |
| 1004 | DataType::Float16, |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 1005 | DataType::QuantisedAsymm8, |
| 1006 | DataType::QuantisedSymm16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1007 | }; |
| 1008 | |
| 1009 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1010 | supportedTypes, |
| 1011 | "Pooling2dQueueDescriptor"); |
| 1012 | |
| 1013 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1014 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1015 | "Pooling2dQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1019 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1020 | ValidateNumInputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
| 1021 | ValidateNumOutputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1022 | |
| 1023 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "input"); |
| 1024 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "output"); |
| 1025 | |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1026 | std::vector<DataType> supportedTypes = |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1027 | { |
| 1028 | DataType::Float16, |
| 1029 | DataType::Float32, |
| 1030 | DataType::QuantisedAsymm8, |
| 1031 | DataType::QuantisedSymm16 |
| 1032 | }; |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1033 | |
| 1034 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1035 | supportedTypes, |
| 1036 | "ResizeBilinearQueueDescriptor"); |
| 1037 | |
| 1038 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1039 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1040 | "ResizeBilinearQueueDescriptor"); |
| 1041 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1042 | // Resizes bilinear only changes width and height: batch and channel count must match. |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1043 | const unsigned int inputBatchSize = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 1044 | const unsigned int outputBatchSize = workloadInfo.m_OutputTensorInfos[0].GetShape()[0]; |
| 1045 | if (inputBatchSize != outputBatchSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1046 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1047 | throw InvalidArgumentException( |
| 1048 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input batch size (%1%) " |
| 1049 | "does not match output batch size (%2%)") % inputBatchSize % outputBatchSize)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1052 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1053 | const unsigned int inputChannelCount = |
| 1054 | workloadInfo.m_InputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1055 | const unsigned int outputChannelCount = |
| 1056 | workloadInfo.m_OutputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1057 | if (inputChannelCount != outputChannelCount) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1058 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1059 | throw InvalidArgumentException( |
| 1060 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input channel count (%1%) " |
| 1061 | "does not match output channel count (%2%)") % inputChannelCount % outputChannelCount)); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | void ResizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1066 | { |
| 1067 | ValidateNumInputs(workloadInfo, "ResizeQueueDescriptor", 1); |
| 1068 | ValidateNumOutputs(workloadInfo, "ResizeQueueDescriptor", 1); |
| 1069 | |
| 1070 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "ResizeQueueDescriptor", 4, "input"); |
| 1071 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "ResizeQueueDescriptor", 4, "output"); |
| 1072 | |
| 1073 | std::vector<DataType> supportedTypes = |
| 1074 | { |
| 1075 | DataType::Float16, |
| 1076 | DataType::Float32, |
| 1077 | DataType::QuantisedAsymm8, |
| 1078 | DataType::QuantisedSymm16 |
| 1079 | }; |
| 1080 | |
| 1081 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1082 | supportedTypes, |
| 1083 | "ResizeQueueDescriptor"); |
| 1084 | |
| 1085 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1086 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1087 | "ResizeQueueDescriptor"); |
| 1088 | |
| 1089 | // Resizes only changes width and height: batch and channel count must match. |
| 1090 | const unsigned int inputBatchSize = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 1091 | const unsigned int outputBatchSize = workloadInfo.m_OutputTensorInfos[0].GetShape()[0]; |
| 1092 | if (inputBatchSize != outputBatchSize) |
| 1093 | { |
| 1094 | throw InvalidArgumentException( |
| 1095 | boost::str(boost::format("ResizeQueueDescriptor: Input batch size (%1%) " |
| 1096 | "does not match output batch size (%2%)") % inputBatchSize % outputBatchSize)); |
| 1097 | } |
| 1098 | |
| 1099 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1100 | const unsigned int inputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1101 | workloadInfo.m_InputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1102 | const unsigned int outputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1103 | workloadInfo.m_OutputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1104 | if (inputChannelCount != outputChannelCount) |
| 1105 | { |
| 1106 | throw InvalidArgumentException( |
| 1107 | boost::str(boost::format("ResizeQueueDescriptor: Input channel count (%1%) " |
| 1108 | "does not match output channel count (%2%)") % inputChannelCount % outputChannelCount)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1113 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1114 | ValidateNumInputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
| 1115 | ValidateNumOutputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1116 | |
| 1117 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "input"); |
| 1118 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "output"); |
| 1119 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1120 | workloadInfo.m_OutputTensorInfos[0], |
| 1121 | "FakeQuantizationQueueDescriptor", |
| 1122 | "input", |
| 1123 | "output"); |
| 1124 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 1125 | { |
| 1126 | throw InvalidArgumentException("FakeQuantizationQueueDescriptor: min cannot be greater than max"); |
| 1127 | } |
| 1128 | |
| 1129 | } |
| 1130 | |
| 1131 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1132 | { |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1133 | const std::string& descriptorName = "L2NormalizationQueueDescriptor"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1134 | |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1135 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1136 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1137 | |
| 1138 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], descriptorName, 4, "input"); |
| 1139 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1140 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1141 | workloadInfo.m_OutputTensorInfos[0], |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1142 | descriptorName, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1143 | "input", |
| 1144 | "output"); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1145 | |
| 1146 | // Check the supported data types |
| 1147 | std::vector<DataType> supportedTypes = |
| 1148 | { |
| 1149 | DataType::Float32, |
| 1150 | DataType::Float16, |
| 1151 | DataType::QuantisedAsymm8, |
| 1152 | DataType::QuantisedSymm16 |
| 1153 | }; |
| 1154 | |
| 1155 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
| 1156 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, descriptorName); |
| 1157 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1158 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1162 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1163 | ValidateNumInputs(workloadInfo, "ConstantQueueDescriptor", 0); |
| 1164 | ValidateNumOutputs(workloadInfo, "ConstantQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1165 | |
| 1166 | if (!m_LayerOutput) |
| 1167 | { |
| 1168 | throw InvalidArgumentException("ConstantQueueDescriptor: No const input specified"); |
| 1169 | } |
| 1170 | |
| 1171 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), |
| 1172 | workloadInfo.m_OutputTensorInfos[0], |
| 1173 | "ConstantQueueDescriptor", |
| 1174 | "constant", |
| 1175 | "output"); |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1176 | |
| 1177 | // Check the supported data types |
| 1178 | std::vector<DataType> supportedTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1179 | { |
| 1180 | DataType::Float32, |
| 1181 | DataType::Float16, |
| 1182 | DataType::Signed32, |
| 1183 | DataType::QuantisedAsymm8, |
| 1184 | DataType::QuantisedSymm16 |
| 1185 | }; |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1186 | |
| 1187 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ConstantQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1191 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1192 | ValidateNumInputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
| 1193 | ValidateNumOutputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1194 | |
| 1195 | if (workloadInfo.m_InputTensorInfos[0].GetNumElements() != workloadInfo.m_OutputTensorInfos[0].GetNumElements()) |
| 1196 | { |
| 1197 | throw InvalidArgumentException("ReshapeQueueDescriptor: Input tensor has " + |
| 1198 | to_string(workloadInfo.m_InputTensorInfos[0].GetNumElements()) + " but output tensor has " + |
| 1199 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1200 | } |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1201 | |
| 1202 | // Check the supported data types |
| 1203 | std::vector<DataType> supportedTypes = |
| 1204 | { |
| 1205 | DataType::Float32, |
| 1206 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1207 | DataType::QuantisedAsymm8, |
| 1208 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1209 | }; |
| 1210 | |
| 1211 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
| 1212 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1215 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1216 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1217 | ValidateNumInputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
| 1218 | ValidateNumOutputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1219 | |
| 1220 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "input"); |
| 1221 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "output"); |
| 1222 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1223 | if (m_Parameters.m_BlockShape.size() != 2) |
| 1224 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1225 | throw InvalidArgumentException("Block Shape must contain 2 spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 1229 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1230 | 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] | 1231 | } |
| 1232 | |
| 1233 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 1234 | |
| 1235 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
| 1236 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
| 1237 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1238 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1239 | unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1240 | + heightPad.first + heightPad.second; |
| 1241 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1242 | unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1243 | + widthPad.first + widthPad.second; |
| 1244 | |
| 1245 | unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1246 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1247 | |
| 1248 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 1249 | { |
| 1250 | throw InvalidArgumentException("SpaceToBatchNdQueueDescriptor: Input tensor has " + |
| 1251 | to_string(numInputElements) + " after padding but output tensor has " + |
| 1252 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1253 | } |
| 1254 | |
| 1255 | 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] | 1256 | { |
| 1257 | throw InvalidArgumentException( |
| 1258 | "Input shape after padding must be divisible by Block Shape in all spatial dimensions"); |
| 1259 | } |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1260 | |
| 1261 | std::vector<DataType> supportedTypes = |
| 1262 | { |
| 1263 | DataType::Float16, |
| 1264 | DataType::Float32, |
| 1265 | DataType::QuantisedAsymm8, |
| 1266 | DataType::QuantisedSymm16 |
| 1267 | }; |
| 1268 | |
| 1269 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1270 | supportedTypes, |
| 1271 | "SpaceToBatchNdQueueDescriptor"); |
| 1272 | |
| 1273 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1274 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1275 | "SpaceToBatchNdQueueDescriptor"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1278 | void SpaceToDepthQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1279 | { |
| 1280 | ValidateNumInputs(workloadInfo, "SpaceToDepthQueueDescriptor", 1); |
| 1281 | ValidateNumOutputs(workloadInfo, "SpaceToDepthQueueDescriptor", 1); |
| 1282 | |
| 1283 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], |
| 1284 | "SpaceToDepthQueueDescriptor", 4, "input"); |
| 1285 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], |
| 1286 | "SpaceToDepthQueueDescriptor", 4, "output"); |
| 1287 | |
| 1288 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1289 | |
| 1290 | std::vector<DataType> supportedTypes = |
| 1291 | { |
| 1292 | DataType::Float32, |
| 1293 | DataType::Float16, |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame] | 1294 | DataType::QuantisedAsymm8, |
| 1295 | DataType::QuantisedSymm16 |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1296 | }; |
| 1297 | |
| 1298 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1299 | supportedTypes, |
| 1300 | "SpaceToDepthQueueDescriptor"); |
| 1301 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1302 | supportedTypes, |
| 1303 | "SpaceToDepthQueueDescriptor"); |
| 1304 | |
| 1305 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 1306 | |
| 1307 | unsigned int numInputElements = inputShape[0] |
| 1308 | * inputShape[dimensionIndices.GetWidthIndex()] |
| 1309 | * inputShape[dimensionIndices.GetHeightIndex()] |
| 1310 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
| 1311 | |
| 1312 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 1313 | { |
| 1314 | throw InvalidArgumentException("SpaceToDepthQueueDescriptor: Input tensor has " + |
| 1315 | to_string(numInputElements) + " but output tensor has " + |
| 1316 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1317 | } |
| 1318 | |
| 1319 | if (inputShape[dimensionIndices.GetHeightIndex()] % m_Parameters.m_BlockSize != 0 || |
| 1320 | inputShape[dimensionIndices.GetWidthIndex()] % m_Parameters.m_BlockSize != 0) |
| 1321 | { |
| 1322 | throw InvalidArgumentException( |
| 1323 | "Input shape must be divisible by block size in all spatial dimensions"); |
| 1324 | } |
| 1325 | } |
| 1326 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1327 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1328 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1329 | const std::string floorQueueDescString = "FloorQueueDescriptor"; |
| 1330 | |
| 1331 | ValidateNumInputs(workloadInfo, floorQueueDescString, 1); |
| 1332 | ValidateNumOutputs(workloadInfo, floorQueueDescString, 1); |
| 1333 | |
| 1334 | std::vector<DataType> supportedTypes = |
| 1335 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 1336 | DataType::Float32, |
| 1337 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1338 | }; |
| 1339 | |
| 1340 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, floorQueueDescString); |
| 1341 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, floorQueueDescString); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1342 | |
| 1343 | if (workloadInfo.m_InputTensorInfos[0] != workloadInfo.m_OutputTensorInfos[0]) |
| 1344 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1345 | throw InvalidArgumentException(floorQueueDescString + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1349 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1350 | { |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1351 | std::vector<DataType> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1352 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1353 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1354 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1355 | }; |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1356 | // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions() |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1357 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1358 | // check for supported type of one input and match them with all the other input and output |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1359 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1360 | supportedTypes, |
| 1361 | "LstmQueueDescriptor"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1362 | // type matches all other inputs |
| 1363 | for (uint32_t i = 1; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 1364 | { |
| 1365 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1366 | workloadInfo.m_InputTensorInfos[i], |
| 1367 | "LstmQueueDescriptor", |
| 1368 | "InputTensor[0]", |
| 1369 | "InputTensor[" + std::to_string(i) + "]"); |
| 1370 | } |
| 1371 | // type matches all other outputs |
| 1372 | for (uint32_t i = 0; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
| 1373 | { |
| 1374 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1375 | workloadInfo.m_OutputTensorInfos[i], |
| 1376 | "LstmQueueDescriptor", |
| 1377 | "InputTensor[0]", |
| 1378 | "OutputTensor[" + std::to_string(i) + "]"); |
| 1379 | } |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1380 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1381 | // TODO: check clipping parameter is valid |
| 1382 | |
| 1383 | // Inferring batch size, number of outputs and number of cells from the inputs. |
| 1384 | // TODO: figure out if there is a way to make sure the specific inputs are at that index of workloadInfo |
| 1385 | const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1]; |
| 1386 | const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 1387 | ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights"); |
| 1388 | const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0]; |
| 1389 | ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights"); |
| 1390 | const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1]; |
| 1391 | |
| 1392 | // check dimensions of all inputs and outputs |
| 1393 | if (workloadInfo.m_InputTensorInfos.size() != 3) |
| 1394 | { |
| 1395 | throw InvalidArgumentException("Invalid number of inputs."); |
| 1396 | } |
| 1397 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1398 | { |
| 1399 | throw InvalidArgumentException("Invalid number of outputs."); |
| 1400 | } |
| 1401 | // input tensor |
| 1402 | ValidateTensorNumDimNumElem( workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input), |
| 1403 | "LstmQueueDescriptor input[0]"); |
| 1404 | // outputStateInTensor |
| 1405 | ValidateTensorNumDimNumElem( workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output), |
| 1406 | "LstmQueueDescriptor input[1]"); |
| 1407 | // outputStateInTensor |
| 1408 | ValidateTensorNumDimNumElem( workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell), |
| 1409 | "LstmQueueDescriptor input[2]"); |
| 1410 | // scratchBufferTensor |
| 1411 | unsigned int scratchBufferSize = m_Parameters.m_CifgEnabled ? n_cell * 3 : n_cell * 4; |
| 1412 | ValidateTensorNumDimNumElem( workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize), |
| 1413 | "LstmQueueDescriptor output[0]"); |
| 1414 | // outputStateOutTensor |
| 1415 | ValidateTensorNumDimNumElem( workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output), |
| 1416 | "LstmQueueDescriptor output[1]"); |
| 1417 | // cellStateOutTensor |
| 1418 | ValidateTensorNumDimNumElem( workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell), |
| 1419 | "LstmQueueDescriptor output[2]"); |
| 1420 | // outputTensor |
| 1421 | ValidateTensorNumDimNumElem( workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output), |
| 1422 | "LstmQueueDescriptor output[3]"); |
| 1423 | |
| 1424 | |
| 1425 | // check that dimensions of inputs/outputs and QueueDescriptor data match with each other |
| 1426 | if ( m_InputToInputWeights ) |
| 1427 | { |
| 1428 | ValidateTensorNumDimNumElem(m_InputToInputWeights->GetTensorInfo(), 2, |
| 1429 | (n_cell * n_input), "InputLayerNormWeights"); |
| 1430 | } |
| 1431 | |
| 1432 | ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights"); |
| 1433 | ValidateTensorNumDimNumElem(m_InputToForgetWeights->GetTensorInfo(), 2, |
| 1434 | (n_cell * n_input), "InputToForgetWeights"); |
| 1435 | |
| 1436 | ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights"); |
| 1437 | ValidateTensorNumDimNumElem(m_InputToCellWeights->GetTensorInfo(), 2, |
| 1438 | (n_cell * n_input), "InputToCellWeights"); |
| 1439 | |
| 1440 | if ( m_RecurrentToInputWeights ) |
| 1441 | { |
| 1442 | ValidateTensorNumDimNumElem(m_RecurrentToInputWeights->GetTensorInfo(), 2, |
| 1443 | (n_cell * n_output), "RecurrentToInputWeights"); |
| 1444 | } |
| 1445 | |
| 1446 | ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights"); |
| 1447 | ValidateTensorNumDimNumElem(m_RecurrentToForgetWeights->GetTensorInfo(), 2, |
| 1448 | (n_cell * n_output), "RecurrentToForgetWeights"); |
| 1449 | |
| 1450 | ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights"); |
| 1451 | ValidateTensorNumDimNumElem(m_RecurrentToCellWeights->GetTensorInfo(), 2, |
| 1452 | (n_cell * n_output), "RecurrentToCellWeights"); |
| 1453 | |
| 1454 | // Make sure the input-gate's parameters are either both present (regular |
| 1455 | // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly. |
| 1456 | bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights && |
| 1457 | !m_Parameters.m_CifgEnabled) || |
| 1458 | (!m_InputToInputWeights && !m_RecurrentToInputWeights && |
| 1459 | m_Parameters.m_CifgEnabled)); |
| 1460 | if (!cifg_weights_all_or_none) |
| 1461 | { |
| 1462 | throw InvalidArgumentException("Input-Gate's parameters InputToInputWeights and RecurrentToInputWeights must " |
| 1463 | "either both be present (regular LSTM) or both not present (CIFG-LSTM). In " |
| 1464 | "addition CifgEnable must be set accordingly"); |
| 1465 | } |
| 1466 | |
| 1467 | if ( m_CellToInputWeights ) |
| 1468 | { |
| 1469 | ValidateTensorNumDimNumElem(m_CellToInputWeights->GetTensorInfo(), 1, |
| 1470 | n_cell, "CellToInputWeights"); |
| 1471 | } |
| 1472 | if ( m_CellToForgetWeights ) |
| 1473 | { |
| 1474 | ValidateTensorNumDimNumElem(m_CellToForgetWeights->GetTensorInfo(), 1, |
| 1475 | n_cell, "CellToForgetWeights"); |
| 1476 | } |
| 1477 | if ( m_CellToOutputWeights ) |
| 1478 | { |
| 1479 | ValidateTensorNumDimNumElem(m_CellToOutputWeights->GetTensorInfo(), 1, |
| 1480 | n_cell, "CellToOutputWeights"); |
| 1481 | } |
| 1482 | |
| 1483 | // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly. |
| 1484 | bool peephole_weights_all_or_none = |
| 1485 | (((m_CellToInputWeights || m_Parameters.m_CifgEnabled) && m_CellToForgetWeights |
| 1486 | && m_CellToOutputWeights && m_Parameters.m_PeepholeEnabled) |
| 1487 | || ( !m_CellToInputWeights && !m_CellToForgetWeights |
| 1488 | && !m_CellToOutputWeights && !m_Parameters.m_PeepholeEnabled)); |
| 1489 | if (!peephole_weights_all_or_none) |
| 1490 | { |
| 1491 | throw InvalidArgumentException("Invalid combination of peephole parameters"); |
| 1492 | } |
| 1493 | |
| 1494 | // Make sure the input gate bias is present only when not a CIFG-LSTM. |
| 1495 | if (m_Parameters.m_CifgEnabled) |
| 1496 | { |
| 1497 | if (m_InputGateBias) |
| 1498 | { |
| 1499 | throw InvalidArgumentException("InputGateBias is present and CIFG-LSTM is enabled"); |
| 1500 | } |
| 1501 | } |
| 1502 | else |
| 1503 | { |
| 1504 | if (!m_InputGateBias) |
| 1505 | { |
| 1506 | throw InvalidArgumentException("If CIFG-LSTM is disabled InputGateBias must be present."); |
| 1507 | } |
| 1508 | ValidateTensorNumDimNumElem(m_InputGateBias->GetTensorInfo(), 1, |
| 1509 | n_cell, "InputGateBias"); |
| 1510 | } |
| 1511 | |
| 1512 | ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias"); |
| 1513 | ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias"); |
| 1514 | |
| 1515 | ValidatePointer(m_CellBias, "Null pointer check", "CellBias"); |
| 1516 | ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias"); |
| 1517 | |
| 1518 | ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias"); |
| 1519 | ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias"); |
| 1520 | |
| 1521 | if (m_ProjectionWeights) |
| 1522 | { |
| 1523 | ValidateTensorNumDimNumElem(m_ProjectionWeights->GetTensorInfo(), 2, |
| 1524 | (n_cell * n_output), "ProjectionWeights"); |
| 1525 | } |
| 1526 | if (m_ProjectionBias) |
| 1527 | { |
| 1528 | ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias"); |
| 1529 | } |
| 1530 | |
| 1531 | // Making sure the projection tensors are consistent: |
| 1532 | // 1) If projection weight is not present, then projection bias should not be |
| 1533 | // present. |
| 1534 | // 2) If projection weight is present, then projection bias is optional. |
| 1535 | bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias && |
| 1536 | !m_Parameters.m_ProjectionEnabled) |
| 1537 | || (m_ProjectionWeights && !m_ProjectionBias && |
| 1538 | m_Parameters.m_ProjectionEnabled) |
| 1539 | || (m_ProjectionWeights && m_ProjectionBias && |
| 1540 | m_Parameters.m_ProjectionEnabled)); |
| 1541 | if (!projecton_tensors_consistent) |
| 1542 | { |
| 1543 | throw InvalidArgumentException("Projection tensors are inconsistent."); |
| 1544 | } |
| 1545 | |
| 1546 | // The four layer normalization weights either all have values or none of them have values. Additionally, if |
| 1547 | // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights |
| 1548 | // either all have values or none of them have values. Layer normalization is used when the values of all the |
| 1549 | // layer normalization weights are present |
| 1550 | if (m_InputLayerNormWeights) |
| 1551 | { |
| 1552 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights"); |
| 1553 | } |
| 1554 | if (m_ForgetLayerNormWeights) |
| 1555 | { |
| 1556 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1557 | } |
| 1558 | if (m_CellLayerNormWeights) |
| 1559 | { |
| 1560 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1561 | } |
| 1562 | if (m_OutputLayerNormWeights) |
| 1563 | { |
| 1564 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | if (m_Parameters.m_LayerNormEnabled) |
| 1569 | { |
| 1570 | if (!m_Parameters.m_CifgEnabled) |
| 1571 | { |
| 1572 | if (!m_InputLayerNormWeights) |
| 1573 | { |
| 1574 | throw InvalidArgumentException("Layer normalisation is enabled and CIFG-LSTM is disabled but " |
| 1575 | "InputLayerNormWeights are not present"); |
| 1576 | } |
| 1577 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), |
| 1578 | 1, n_cell, "InputLayerNormWeights"); |
| 1579 | } |
| 1580 | else if (m_InputLayerNormWeights) |
| 1581 | { |
| 1582 | throw InvalidArgumentException("InputLayerNormWeights are present while CIFG is enabled"); |
| 1583 | } |
| 1584 | |
| 1585 | ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1586 | "ForgetLayerNormWeights"); |
| 1587 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1588 | |
| 1589 | ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1590 | "OutputLayerNormWeights"); |
| 1591 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1592 | |
| 1593 | ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1594 | "CellLayerNormWeights"); |
| 1595 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1596 | } |
| 1597 | else if (m_InputLayerNormWeights || m_ForgetLayerNormWeights || m_OutputLayerNormWeights || m_CellLayerNormWeights) |
| 1598 | { |
| 1599 | throw InvalidArgumentException("Layer normalisation is disabled but one or more layer normalisation weights " |
| 1600 | "are present."); |
| 1601 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1605 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1606 | ValidateNumInputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
| 1607 | ValidateNumOutputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1608 | |
| 1609 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1610 | { |
| 1611 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Input tensor type must be Float32."); |
| 1612 | } |
| 1613 | |
| 1614 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1615 | { |
| 1616 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Output tensor type must be Float16."); |
| 1617 | } |
| 1618 | |
| 1619 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1620 | workloadInfo.m_OutputTensorInfos[0], |
| 1621 | "ConvertFp32ToFp16QueueDescriptor", |
| 1622 | "input", |
| 1623 | "output"); |
| 1624 | } |
| 1625 | |
| 1626 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1627 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1628 | ValidateNumInputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
| 1629 | ValidateNumOutputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1630 | |
| 1631 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1632 | { |
| 1633 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Input tensor type must be Float16."); |
| 1634 | } |
| 1635 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1636 | { |
| 1637 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Output tensor type must be Float32."); |
| 1638 | } |
| 1639 | |
| 1640 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1641 | workloadInfo.m_OutputTensorInfos[0], |
| 1642 | "ConvertFp16ToFp32QueueDescriptor", |
| 1643 | "input", |
| 1644 | "output"); |
| 1645 | } |
| 1646 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1647 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1648 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1649 | ValidateNumInputs(workloadInfo, "DivisionQueueDescriptor", 2); |
| 1650 | ValidateNumOutputs(workloadInfo, "DivisionQueueDescriptor", 1); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1651 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1652 | std::vector<DataType> supportedTypes = { |
| 1653 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1654 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1655 | DataType::QuantisedSymm16, |
| 1656 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1657 | }; |
| 1658 | |
| 1659 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1660 | supportedTypes, |
| 1661 | "DivisionQueueDescriptor"); |
| 1662 | |
| 1663 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1664 | supportedTypes, |
| 1665 | "DivisionQueueDescriptor"); |
| 1666 | |
| 1667 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1668 | supportedTypes, |
| 1669 | "DivisionQueueDescriptor"); |
| 1670 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1671 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1672 | workloadInfo.m_InputTensorInfos[1], |
| 1673 | workloadInfo.m_OutputTensorInfos[0], |
| 1674 | "DivisionQueueDescriptor", |
| 1675 | "first input", |
| 1676 | "second input"); |
| 1677 | } |
| 1678 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1679 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1680 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1681 | ValidateNumInputs(workloadInfo, "SubtractionQueueDescriptor", 2); |
| 1682 | ValidateNumOutputs(workloadInfo, "SubtractionQueueDescriptor", 1); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1683 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1684 | std::vector<DataType> supportedTypes = { |
| 1685 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1686 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1687 | DataType::QuantisedSymm16, |
| 1688 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1689 | }; |
| 1690 | |
| 1691 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1692 | supportedTypes, |
| 1693 | "SubtractionQueueDescriptor"); |
| 1694 | |
| 1695 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1696 | supportedTypes, |
| 1697 | "SubtractionQueueDescriptor"); |
| 1698 | |
| 1699 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1700 | supportedTypes, |
| 1701 | "SubtractionQueueDescriptor"); |
| 1702 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1703 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1704 | workloadInfo.m_InputTensorInfos[1], |
| 1705 | workloadInfo.m_OutputTensorInfos[0], |
| 1706 | "SubtractionQueueDescriptor", |
| 1707 | "first input", |
| 1708 | "second input"); |
| 1709 | } |
| 1710 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1711 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1712 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1713 | ValidateNumInputs(workloadInfo, "MaximumQueueDescriptor", 2); |
| 1714 | ValidateNumOutputs(workloadInfo, "MaximumQueueDescriptor", 1); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1715 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1716 | std::vector<DataType> supportedTypes = { |
| 1717 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1718 | DataType::QuantisedAsymm8, |
| 1719 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1720 | }; |
| 1721 | |
| 1722 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1723 | supportedTypes, |
| 1724 | "MaximumQueueDescriptor"); |
| 1725 | |
| 1726 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1727 | supportedTypes, |
| 1728 | "MaximumQueueDescriptor"); |
| 1729 | |
| 1730 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1731 | supportedTypes, |
| 1732 | "MaximumQueueDescriptor"); |
| 1733 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1734 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1735 | workloadInfo.m_InputTensorInfos[1], |
| 1736 | workloadInfo.m_OutputTensorInfos[0], |
| 1737 | "MaximumQueueDescriptor", |
| 1738 | "first input", |
| 1739 | "second input"); |
| 1740 | } |
| 1741 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1742 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1743 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1744 | const std::string meanQueueDescString = "MeanQueueDescriptor"; |
| 1745 | |
| 1746 | ValidateNumInputs(workloadInfo, meanQueueDescString, 1); |
| 1747 | ValidateNumOutputs(workloadInfo, meanQueueDescString, 1); |
| 1748 | |
| 1749 | std::vector<DataType> supportedTypes = |
| 1750 | { |
| 1751 | DataType::Float32, |
| 1752 | DataType::Float16, |
| 1753 | DataType::QuantisedAsymm8, |
| 1754 | DataType::QuantisedSymm16 |
| 1755 | }; |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1756 | |
| 1757 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1758 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1759 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1760 | // First check if input tensor data type is supported, then |
| 1761 | // check if this data type matches the output tensor data type |
| 1762 | ValidateDataTypes(input, supportedTypes, meanQueueDescString); |
| 1763 | ValidateTensorDataTypesMatch(input, output, meanQueueDescString, "input", "output"); |
| 1764 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1765 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1766 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1767 | ValidateTensorNumDimensions(output, meanQueueDescString, input.GetNumDimensions(), "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1768 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1769 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1770 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1771 | ValidateTensorNumDimensions(output, meanQueueDescString, 1, "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1772 | } |
| 1773 | else |
| 1774 | { |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1775 | 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] | 1776 | ValidateTensorNumDimensions(output, |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1777 | meanQueueDescString, |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1778 | outputDim > 0 ? outputDim : 1, |
| 1779 | "output"); |
| 1780 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1783 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1784 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1785 | ValidateNumInputs(workloadInfo, "PadQueueDescriptor", 1); |
| 1786 | ValidateNumOutputs(workloadInfo, "PadQueueDescriptor", 1); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1787 | |
| 1788 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1789 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1790 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1791 | // input and output should have the same number of dimensions |
| 1792 | ValidateTensorNumDimensions(output, "PadQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1793 | // there should be entry in the pad list for each dimension in the input tensor |
| 1794 | if (m_Parameters.m_PadList.size() != input.GetNumDimensions()) { |
| 1795 | throw InvalidArgumentException("Pad List should contain the same number of entries as there" |
| 1796 | " are dimensions in the input tensor that is " + |
| 1797 | to_string(input.GetNumDimensions()) + " entries " + |
| 1798 | " not " + to_string(m_Parameters.m_PadList.size()) + " entries."); |
| 1799 | } |
| 1800 | } |
| 1801 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1802 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1803 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1804 | ValidateNumInputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
| 1805 | ValidateNumOutputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1806 | |
| 1807 | |
| 1808 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1809 | { |
| 1810 | throw InvalidArgumentException("Quantize only accepts Float32 inputs."); |
| 1811 | } |
| 1812 | |
| 1813 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1814 | workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1815 | { |
| 1816 | throw InvalidArgumentException("Output of quantized layer must be quantized type."); |
| 1817 | } |
| 1818 | } |
| 1819 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1820 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1821 | { |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 1822 | const std::string batchToSpaceNdQueueDescriptorStr = "BatchToSpaceNdQueueDescriptor"; |
| 1823 | |
| 1824 | ValidateNumInputs(workloadInfo, batchToSpaceNdQueueDescriptorStr, 1); |
| 1825 | ValidateNumOutputs(workloadInfo, batchToSpaceNdQueueDescriptorStr, 1); |
| 1826 | |
| 1827 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1828 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1829 | |
| 1830 | std::vector<DataType> supportedTypes = |
| 1831 | { |
| 1832 | DataType::Float32, |
| 1833 | DataType::QuantisedAsymm8, |
| 1834 | DataType::QuantisedSymm16 |
| 1835 | }; |
| 1836 | |
| 1837 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1838 | supportedTypes, |
| 1839 | batchToSpaceNdQueueDescriptorStr); |
| 1840 | |
| 1841 | ValidateTensorDataTypesMatch(input, output, batchToSpaceNdQueueDescriptorStr, "input", "output"); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1844 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1845 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1846 | ValidateNumInputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
| 1847 | ValidateNumOutputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1848 | |
| 1849 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1850 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1851 | |
| 1852 | std::vector<DataType> supportedTypes = |
| 1853 | { |
| 1854 | DataType::Float16, |
| 1855 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 1856 | DataType::QuantisedAsymm8, |
| 1857 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1858 | }; |
| 1859 | |
| 1860 | ValidateDataTypes(input, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1861 | ValidateDataTypes(output, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1862 | |
| 1863 | ValidateDataTypes(output, { input.GetDataType() }, "StridedSliceQueueDescriptor"); |
| 1864 | |
| 1865 | ValidateTensorQuantizationSpace(input, output, "StridedSliceQueueDescriptor", "input", "output"); |
| 1866 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1867 | const uint32_t rank = input.GetNumDimensions(); |
| 1868 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1869 | if (rank > 4) |
| 1870 | { |
| 1871 | throw InvalidArgumentException( |
| 1872 | "StridedSliceLayer: Input tensors with rank greater than 4 are not supported"); |
| 1873 | } |
| 1874 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1875 | // Begin, End & Stride length must be of rank(input0) |
| 1876 | if (m_Parameters.m_Begin.size() != rank) |
| 1877 | { |
| 1878 | throw InvalidArgumentException("StridedSliceLayer: Begin length must be of rank input0(" |
| 1879 | + to_string(rank) + ")"); |
| 1880 | } |
| 1881 | |
| 1882 | if (m_Parameters.m_End.size() != rank) |
| 1883 | { |
| 1884 | throw InvalidArgumentException("StridedSliceLayer: End length must be of rank input0(" |
| 1885 | + to_string(rank) + ")"); |
| 1886 | } |
| 1887 | |
| 1888 | if (m_Parameters.m_Stride.size() != rank) |
| 1889 | { |
| 1890 | throw InvalidArgumentException("StridedSliceLayer: Stride length must be of rank input0(" |
| 1891 | + to_string(rank) + ")"); |
| 1892 | } |
| 1893 | |
| 1894 | // Stride entries must be non-zero |
| 1895 | for (auto& stride : m_Parameters.m_Stride) |
| 1896 | { |
| 1897 | if (stride == 0) |
| 1898 | { |
| 1899 | throw InvalidArgumentException("StridedSliceLayer: Stride entries must be non-zero"); |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1904 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1905 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1906 | ValidateNumInputs(workloadInfo, "MinimumQueueDescriptor", 2); |
| 1907 | ValidateNumOutputs(workloadInfo, "MinimumQueueDescriptor", 1); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1908 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1909 | std::vector<DataType> supportedTypes = { |
| 1910 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1911 | DataType::QuantisedAsymm8, |
| 1912 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1913 | }; |
| 1914 | |
| 1915 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1916 | supportedTypes, |
| 1917 | "MinimumQueueDescriptor"); |
| 1918 | |
| 1919 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1920 | supportedTypes, |
| 1921 | "MinimumQueueDescriptor"); |
| 1922 | |
| 1923 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1924 | supportedTypes, |
| 1925 | "MinimumQueueDescriptor"); |
| 1926 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1927 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1928 | workloadInfo.m_InputTensorInfos[1], |
| 1929 | workloadInfo.m_OutputTensorInfos[0], |
| 1930 | "MinimumQueueDescriptor", |
| 1931 | "first input", |
| 1932 | "second input"); |
| 1933 | } |
| 1934 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1935 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1936 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1937 | ValidateNumInputs(workloadInfo, "DebugQueueDescriptor", 1); |
| 1938 | ValidateNumOutputs(workloadInfo, "DebugQueueDescriptor", 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1941 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1942 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1943 | ValidateNumInputs(workloadInfo, "EqualQueueDescriptor", 2); |
| 1944 | ValidateNumOutputs(workloadInfo, "EqualQueueDescriptor", 1); |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1945 | |
| 1946 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1947 | workloadInfo.m_InputTensorInfos[1], |
| 1948 | workloadInfo.m_OutputTensorInfos[0], |
| 1949 | "EqualQueueDescriptor", |
| 1950 | "first input", |
| 1951 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1952 | |
| 1953 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1954 | { |
| 1955 | throw InvalidArgumentException("EqualQueueDescriptor: Output tensor type must be Boolean."); |
| 1956 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1959 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1960 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1961 | ValidateNumInputs(workloadInfo, "GreaterQueueDescriptor", 2); |
| 1962 | ValidateNumOutputs(workloadInfo, "GreaterQueueDescriptor", 1); |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1963 | |
| 1964 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1965 | workloadInfo.m_InputTensorInfos[1], |
| 1966 | workloadInfo.m_OutputTensorInfos[0], |
| 1967 | "GreaterQueueDescriptor", |
| 1968 | "first input", |
| 1969 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1970 | |
| 1971 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1972 | { |
| 1973 | throw InvalidArgumentException("GreaterQueueDescriptor: Output tensor type must be Boolean."); |
| 1974 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1977 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1978 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1979 | ValidateNumInputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
| 1980 | ValidateNumOutputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1981 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1982 | workloadInfo.m_OutputTensorInfos[0], |
| 1983 | "RsqrtQueueDescriptor", |
| 1984 | "input", |
| 1985 | "output"); |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1986 | |
| 1987 | std::vector<DataType> supportedTypes = |
| 1988 | { |
| 1989 | DataType::Float16, |
| 1990 | DataType::Float32, |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 1991 | DataType::QuantisedAsymm8, |
| 1992 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1993 | }; |
| 1994 | |
| 1995 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1996 | supportedTypes, |
| 1997 | "RsqrtQueueDescriptor"); |
| 1998 | |
| 1999 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 2000 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 2001 | "RsqrtQueueDescriptor"); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2004 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2005 | { |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2006 | const std::string GatherQueueDescriptorStr = "GatherQueueDescriptor"; |
| 2007 | |
| 2008 | ValidateNumInputs(workloadInfo, GatherQueueDescriptorStr, 2); |
| 2009 | ValidateNumOutputs(workloadInfo, GatherQueueDescriptorStr, 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2010 | |
| 2011 | const TensorInfo& indices = workloadInfo.m_InputTensorInfos[1]; |
| 2012 | |
| 2013 | if (indices.GetDataType() != DataType::Signed32) |
| 2014 | { |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2015 | throw InvalidArgumentException(GatherQueueDescriptorStr + ": Indices tensor type must be int32."); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2018 | std::vector<DataType> supportedTypes = |
| 2019 | { |
| 2020 | DataType::Float16, |
| 2021 | DataType::Float32, |
| 2022 | DataType::QuantisedAsymm8, |
| 2023 | DataType::QuantisedSymm16 |
| 2024 | }; |
| 2025 | |
| 2026 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 2027 | supportedTypes, |
| 2028 | GatherQueueDescriptorStr); |
| 2029 | |
| 2030 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2031 | workloadInfo.m_OutputTensorInfos[0], |
| 2032 | GatherQueueDescriptorStr, "Input", "Output"); |
| 2033 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2034 | const TensorInfo& params = workloadInfo.m_InputTensorInfos[0]; |
| 2035 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 2036 | unsigned int paramsDim = params.GetNumDimensions(); |
| 2037 | unsigned int indicesDim = indices.GetNumDimensions(); |
| 2038 | unsigned int outputDim = paramsDim - 1 + indicesDim; |
| 2039 | |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2040 | ValidateTensorNumDimensions(output, GatherQueueDescriptorStr, outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2043 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2044 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2045 | const std::string& descriptorName = " DetectionPostProcessQueueDescriptor"; |
| 2046 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2047 | |
| 2048 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 2049 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2050 | throw InvalidArgumentException(descriptorName + ": Requires exactly four outputs. " + |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2051 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 2052 | } |
| 2053 | |
| 2054 | if (m_Anchors == nullptr) |
| 2055 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2056 | throw InvalidArgumentException(descriptorName + ": Anchors tensor descriptor is missing."); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2060 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2061 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 2062 | |
| 2063 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 2064 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2065 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
| 2066 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2067 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2068 | ValidateTensorNumDimensions(boxEncodingsInfo, descriptorName, 3, "box encodings"); |
| 2069 | ValidateTensorNumDimensions(scoresInfo, descriptorName, 3, "scores"); |
| 2070 | ValidateTensorNumDimensions(anchorsInfo, descriptorName, 2, "anchors"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2071 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2072 | const std::vector<DataType> supportedInputTypes = |
| 2073 | { |
| 2074 | DataType::Float32, |
| 2075 | DataType::QuantisedAsymm8, |
| 2076 | DataType::QuantisedSymm16 |
| 2077 | }; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2078 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2079 | ValidateDataTypes(boxEncodingsInfo, supportedInputTypes, descriptorName); |
| 2080 | ValidateDataTypes(scoresInfo, supportedInputTypes, descriptorName); |
| 2081 | ValidateDataTypes(anchorsInfo, supportedInputTypes, descriptorName); |
| 2082 | |
| 2083 | ValidateTensorNumDimensions(detectionBoxesInfo, descriptorName, 3, "detection boxes"); |
| 2084 | ValidateTensorNumDimensions(detectionScoresInfo, descriptorName, 2, "detection scores"); |
| 2085 | ValidateTensorNumDimensions(detectionClassesInfo, descriptorName, 2, "detection classes"); |
| 2086 | ValidateTensorNumDimensions(numDetectionsInfo, descriptorName, 1, "num detections"); |
| 2087 | |
| 2088 | // NOTE: Output is always Float32 regardless of input type |
| 2089 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, descriptorName, "detection boxes"); |
| 2090 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, descriptorName, "detection scores"); |
| 2091 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, descriptorName, "detection classes"); |
| 2092 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, descriptorName, "num detections"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2093 | |
| 2094 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 2095 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2096 | throw InvalidArgumentException(descriptorName + ": Intersection over union threshold " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2097 | "must be positive and less than or equal to 1."); |
| 2098 | } |
| 2099 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 2100 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2101 | throw InvalidArgumentException(descriptorName + ": Number of classes with background " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2102 | "should be equal to number of classes + 1."); |
| 2103 | } |
| 2104 | } |
| 2105 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2106 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2107 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2108 | ValidateNumInputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
| 2109 | ValidateNumOutputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2110 | |
| 2111 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 2112 | workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 2113 | { |
| 2114 | throw InvalidArgumentException("Input to dequantize layer must be quantized type."); |
| 2115 | } |
| 2116 | |
| 2117 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 2118 | { |
| 2119 | throw InvalidArgumentException("Output of dequantize layer must be Float32 type."); |
| 2120 | } |
| 2121 | } |
| 2122 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2123 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2124 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2125 | ValidateNumInputs(workloadInfo, "MergeQueueDescriptor", 2); |
| 2126 | ValidateNumOutputs(workloadInfo, "MergeQueueDescriptor", 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2127 | |
| 2128 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2129 | workloadInfo.m_InputTensorInfos[1], |
| 2130 | "MergeQueueDescriptor", |
| 2131 | "input0", |
| 2132 | "input1"); |
| 2133 | |
| 2134 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2135 | workloadInfo.m_OutputTensorInfos[0], |
| 2136 | "MergeQueueDescriptor", |
| 2137 | "input0", |
| 2138 | "output"); |
| 2139 | |
| 2140 | const DataType dataType = workloadInfo.m_InputTensorInfos[0].GetDataType(); |
| 2141 | ValidateTensorDataType(workloadInfo.m_InputTensorInfos[1], dataType, "MergeQueueDescriptor", "input1"); |
| 2142 | ValidateTensorDataType(workloadInfo.m_OutputTensorInfos[0], dataType, "MergeQueueDescriptor", "output"); |
| 2143 | } |
| 2144 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2145 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2146 | { |
| 2147 | ValidateNumInputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 2148 | ValidateNumOutputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 2149 | |
| 2150 | std::vector<DataType> supportedTypes = { |
| 2151 | DataType::Float32, |
| 2152 | DataType::QuantisedAsymm8, |
| 2153 | DataType::QuantisedSymm16 |
| 2154 | }; |
| 2155 | |
| 2156 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 2157 | supportedTypes, |
| 2158 | "SwitchQueueDescriptor"); |
| 2159 | |
| 2160 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 2161 | supportedTypes, |
| 2162 | "SwitchQueueDescriptor"); |
| 2163 | |
| 2164 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 2165 | supportedTypes, |
| 2166 | "SwitchQueueDescriptor"); |
| 2167 | |
| 2168 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2169 | workloadInfo.m_OutputTensorInfos[0], |
| 2170 | "SwitchQueueDescriptor", |
| 2171 | "input0", |
| 2172 | "output0"); |
| 2173 | |
| 2174 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2175 | workloadInfo.m_OutputTensorInfos[1], |
| 2176 | "SwitchQueueDescriptor", |
| 2177 | "input0", |
| 2178 | "output1"); |
| 2179 | } |
| 2180 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 2181 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2182 | { |
| 2183 | // This is internally generated so it should not need validation. |
| 2184 | } |
| 2185 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2186 | void PreluQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2187 | { |
| 2188 | ValidateNumInputs(workloadInfo, "PreluQueueDescriptor", 2); |
| 2189 | ValidateNumOutputs(workloadInfo, "PreluQueueDescriptor", 1); |
| 2190 | |
| 2191 | std::vector<DataType> supportedTypes |
| 2192 | { |
| 2193 | DataType::Float16, |
| 2194 | DataType::Float32, |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2195 | DataType::QuantisedAsymm8, |
| 2196 | DataType::QuantisedSymm16 |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2197 | }; |
| 2198 | |
| 2199 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 2200 | supportedTypes, |
| 2201 | "PreluQueueDescriptor"); |
| 2202 | |
| 2203 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 2204 | supportedTypes, |
| 2205 | "PreluQueueDescriptor"); |
| 2206 | |
| 2207 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 2208 | supportedTypes, |
| 2209 | "PreluQueueDescriptor"); |
| 2210 | |
| 2211 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 2212 | { workloadInfo.m_InputTensorInfos[1].GetDataType() }, |
| 2213 | "PreluQueueDescriptor"); |
| 2214 | |
| 2215 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 2216 | { workloadInfo.m_OutputTensorInfos[0].GetDataType() }, |
| 2217 | "PreluQueueDescriptor"); |
| 2218 | |
| 2219 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 2220 | workloadInfo.m_InputTensorInfos[1], |
| 2221 | workloadInfo.m_OutputTensorInfos[0], |
| 2222 | "PreluQueueDescriptor", |
| 2223 | "input", |
| 2224 | "alpha"); |
| 2225 | } |
| 2226 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2227 | void TransposeConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2228 | { |
| 2229 | const std::string descriptorName{"TransposeConvolution2dQueueDescriptor"}; |
| 2230 | |
| 2231 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2232 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2233 | |
| 2234 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], descriptorName, 4, "input"); |
| 2235 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], descriptorName, 4, "output"); |
| 2236 | |
| 2237 | ValidatePointer(m_Weight, descriptorName, "weight"); |
| 2238 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), descriptorName, 4, "weight"); |
| 2239 | |
| 2240 | ValidateTensorDataType(m_Weight->GetTensorInfo(), |
| 2241 | workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 2242 | descriptorName, |
| 2243 | "weight"); |
| 2244 | |
| 2245 | if (m_Parameters.m_BiasEnabled) |
| 2246 | { |
| 2247 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), descriptorName, 1, "bias"); |
| 2248 | |
| 2249 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 2250 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 2251 | descriptorName, "bias"); |
| 2252 | |
| 2253 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 2254 | workloadInfo.m_InputTensorInfos[0], |
| 2255 | m_Weight->GetTensorInfo(), |
| 2256 | descriptorName); |
| 2257 | } |
| 2258 | |
| 2259 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], |
| 2260 | m_Weight->GetTensorInfo(), |
| 2261 | workloadInfo.m_OutputTensorInfos[0], |
| 2262 | descriptorName, |
| 2263 | "input", |
| 2264 | "weights", |
| 2265 | "output"); |
| 2266 | } |
| 2267 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 2268 | } //namespace armnn |