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> |
James Conroy | c8724c7 | 2019-10-08 15:41:34 +0100 | [diff] [blame] | 18 | #include <TensorUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 20 | using namespace armnnUtils; |
| 21 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | namespace armnn |
| 23 | { |
| 24 | |
| 25 | //--------------------------------------------------------------- |
| 26 | DataType GetBiasDataType(DataType inputDataType) |
| 27 | { |
| 28 | switch (inputDataType) |
| 29 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | case DataType::Float16: |
| 31 | return DataType::Float16; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | case DataType::Float32: |
| 33 | return DataType::Float32; |
| 34 | case DataType::QuantisedAsymm8: |
| 35 | return DataType::Signed32; |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 36 | case DataType::QuantisedSymm16: |
| 37 | return DataType::Signed32; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 38 | default: |
| 39 | BOOST_ASSERT_MSG(false, "Invalid input data type"); |
| 40 | return DataType::Float32; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | namespace |
| 45 | { |
| 46 | |
| 47 | //--------------------------------------------------------------- |
| 48 | //android ndk does not support std::to_string function. |
| 49 | template <typename T> |
| 50 | std::string to_string(T value) |
| 51 | { |
| 52 | std::ostringstream os; |
| 53 | os << value; |
| 54 | return os.str(); |
| 55 | } |
| 56 | |
| 57 | //--------------------------------------------------------------- |
| 58 | void ValidatePointer(const void* ptr, std::string const& descName, std::string const& paramName) |
| 59 | { |
| 60 | if (!ptr) |
| 61 | { |
| 62 | throw InvalidArgumentException(descName + ": Invalid null pointer. The " + |
| 63 | paramName + " parameter must be set."); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | //--------------------------------------------------------------- |
| 68 | void ValidateTensorShapesMatch(const TensorInfo& first, |
| 69 | const TensorInfo& second, |
| 70 | std::string const& descName, |
| 71 | std::string const& firstName, |
| 72 | std::string const& secondName) |
| 73 | { |
| 74 | if (first.GetShape() != second.GetShape()) |
| 75 | { |
| 76 | throw InvalidArgumentException(descName + ": " |
| 77 | + firstName + " & " + secondName + " must have identical shapes"); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 82 | void ValidateNumInputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 84 | if (workloadInfo.m_InputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | { |
| 86 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 87 | ": Requires exactly " + to_string(expectedSize) + "input(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 88 | to_string(workloadInfo.m_InputTensorInfos.size()) + " have been provided."); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 93 | void ValidateNumOutputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 94 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 95 | if (workloadInfo.m_OutputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 96 | { |
| 97 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 98 | ": Requires exactly " + to_string(expectedSize) + " output(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 99 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 104 | void ValidateTensorNumDimensions(const TensorInfo& tensor, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 105 | std::string const& descName, |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 106 | unsigned int numDimensions, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 107 | std::string const& tensorName) |
| 108 | { |
| 109 | if (tensor.GetNumDimensions() != numDimensions) |
| 110 | { |
| 111 | throw InvalidArgumentException(descName + ": Expected " + to_string(numDimensions) + " but got " + |
| 112 | to_string(tensor.GetNumDimensions()) + " dimensions for " + |
| 113 | tensorName + " tensor."); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 118 | void ValidateTensorNumElements(const TensorInfo& tensor, |
| 119 | std::string const& descName, |
| 120 | unsigned int numElements, |
| 121 | std::string const& tensorName) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 122 | { |
| 123 | if (tensor.GetNumElements() != numElements) |
| 124 | { |
| 125 | throw InvalidArgumentException(descName + ": Expected " + to_string(numElements) + " but got " + |
James Conroy | ceda785 | 2019-08-22 11:41:07 +0100 | [diff] [blame] | 126 | to_string(tensor.GetNumElements()) + " elements for " + |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 127 | tensorName + " tensor."); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | //--------------------------------------------------------------- |
| 132 | void ValidateTensorNumDimNumElem(const TensorInfo& tensorInfo, |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 133 | unsigned int numDimension, |
| 134 | unsigned int numElements, |
| 135 | std::string const& tensorName) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 136 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 137 | const std::string functionName{"ValidateTensorNumDimNumElem"}; |
| 138 | ValidateTensorNumDimensions(tensorInfo, functionName, numDimension, tensorName); |
| 139 | ValidateTensorNumElements(tensorInfo, functionName, numElements, tensorName); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 143 | void ValidateTensorDataType(const TensorInfo& tensor, DataType dataType, |
| 144 | const std::string& descName, std::string const& tensorName) |
| 145 | { |
| 146 | if (tensor.GetDataType() != dataType) |
| 147 | { |
| 148 | throw InvalidArgumentException(descName + ": Expected data type " + GetDataTypeName(dataType) + " but got " + |
| 149 | GetDataTypeName(tensor.GetDataType()) + " for " + tensorName + " tensor."); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | //--------------------------------------------------------------- |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 154 | void ValidateTensorQuantizationSpace(const TensorInfo& first, |
| 155 | const TensorInfo& second, |
| 156 | const std::string& descName, |
| 157 | std::string const& firstName, |
| 158 | std::string const& secondName) |
| 159 | { |
| 160 | if (!first.IsQuantized() || |
| 161 | !second.IsQuantized()) |
| 162 | { |
| 163 | // Not a quantized type, ignore the validation |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | DataType firstDataType = first.GetDataType(); |
| 168 | DataType secondDataType = second.GetDataType(); |
| 169 | |
| 170 | if (firstDataType != secondDataType) |
| 171 | { |
| 172 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 173 | " must be of the same quantized type, " + |
| 174 | firstName + " is " + GetDataTypeName(firstDataType) + ", " + |
| 175 | secondName + " is " + GetDataTypeName(secondDataType)); |
| 176 | } |
| 177 | |
| 178 | if (!first.IsTypeSpaceMatch(second)) |
| 179 | { |
| 180 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 181 | " must have the same quantization space, " + |
| 182 | firstName + " has offset " + to_string(first.GetQuantizationOffset()) + |
| 183 | " and scale " + to_string(first.GetQuantizationScale()) + ", " + |
| 184 | secondName + " has offset " + to_string(second.GetQuantizationOffset()) + |
| 185 | " and scale " + to_string(second.GetQuantizationScale())); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 190 | void ValidateBiasTensorQuantization(const TensorInfo& biasTensor, |
| 191 | const TensorInfo& inputTensorInfo, |
| 192 | const TensorInfo& weightsTensorInfo, |
| 193 | const std::string& descName) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 194 | { |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 195 | // Helper lambda function to validate a single bias quantization scale value |
| 196 | auto VerifyBiasQuantizationScale = [&descName](float biasScale, float expectedScale) -> void |
| 197 | { |
ricbur01 | 3f4d710 | 2019-10-31 16:22:18 +0000 | [diff] [blame] | 198 | constexpr float tolerance = 0.000001f; |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 199 | if (std::abs(biasScale - expectedScale) > tolerance) |
| 200 | { |
| 201 | // Print the float values with extra precision to see very small differences |
| 202 | std::stringstream msg; |
| 203 | msg << std::setprecision(10) << descName << ": Expected " << expectedScale << |
| 204 | " quantization scale for bias tensor (the product of the input and weight scales), but got " << |
| 205 | biasScale; |
| 206 | throw InvalidArgumentException(msg.str(), CHECK_LOCATION()); |
| 207 | } |
| 208 | }; |
| 209 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 210 | if (biasTensor.GetQuantizationOffset() != 0) |
| 211 | { |
| 212 | throw InvalidArgumentException(descName + ": Expected zero quantization offset for bias tensor but got " + |
| 213 | to_string(biasTensor.GetQuantizationOffset())); |
| 214 | } |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 215 | |
| 216 | if (biasTensor.HasMultipleQuantizationScales()) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 217 | { |
Aron Virginas-Tar | d905307 | 2019-10-30 16:03:19 +0000 | [diff] [blame] | 218 | // Validate per-axis quantization scales |
| 219 | const std::vector<float>& weightScales = weightsTensorInfo.GetQuantizationScales(); |
| 220 | const std::vector<float>& biasScales = biasTensor.GetQuantizationScales(); |
| 221 | |
| 222 | if (weightScales.size() != biasScales.size()) |
| 223 | { |
| 224 | std::stringstream msg; |
| 225 | msg << descName << ": Expected matchhing number of per-axis quantization scales, but got different " |
| 226 | << "values: weights=" << weightScales.size() << ", biases=" << biasScales.size(); |
| 227 | throw InvalidArgumentException(msg.str(), CHECK_LOCATION()); |
| 228 | } |
| 229 | |
| 230 | for (size_t i = 0ul; i < biasScales.size(); ++i) |
| 231 | { |
| 232 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightScales[i]; |
| 233 | VerifyBiasQuantizationScale(biasScales[i], expectedScale); |
| 234 | } |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | // Validate per-tensor quantization scale |
| 239 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightsTensorInfo.GetQuantizationScale(); |
| 240 | VerifyBiasQuantizationScale(biasTensor.GetQuantizationScale(), expectedScale); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | //--------------------------------------------------------------- |
| 245 | void ValidateTensors(const std::vector<ITensorHandle*>& vec, |
| 246 | unsigned int numExpected, |
| 247 | const std::string& descName, |
| 248 | const std::string& varName) |
| 249 | { |
| 250 | if (vec.empty() && numExpected > 0) |
| 251 | { |
| 252 | throw InvalidArgumentException(descName + ": Invalid empty " + varName + " array."); |
| 253 | } |
| 254 | |
| 255 | for (unsigned int i = 0; i < numExpected; ++i) |
| 256 | { |
| 257 | if (!vec[i]) |
| 258 | { |
| 259 | throw InvalidArgumentException(descName + ": Invalid NULL for " + varName + to_string(i)); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | //--------------------------------------------------------------- |
| 265 | void ValidateBroadcastTensorShapesMatch(const TensorInfo& first, |
| 266 | const TensorInfo& second, |
| 267 | const TensorInfo& output, |
| 268 | std::string const& descName, |
| 269 | std::string const& firstName, |
| 270 | std::string const& secondName) |
| 271 | { |
| 272 | // Tensors must have the same number of dimensions in order to be explicit about which dimensions will get |
| 273 | // broadcasted. |
| 274 | if (first.GetNumDimensions() != second.GetNumDimensions()) |
| 275 | { |
| 276 | throw InvalidArgumentException(descName + ": Tensors " |
| 277 | + firstName + " & " + secondName |
| 278 | + " must have the same number of dimensions in order to be broadcasted"); |
| 279 | } |
| 280 | uint32_t numDims = first.GetNumDimensions(); |
| 281 | std::vector<uint32_t> outputDims(numDims, 0u); |
| 282 | for (uint32_t i = 0; i < numDims; i++) |
| 283 | { |
| 284 | const bool dimsNotEqual = first.GetShape()[i] != second.GetShape()[i]; |
| 285 | const bool dimsNotOne = (first.GetShape()[i] != 1) && (second.GetShape()[i] != 1); |
| 286 | if (dimsNotEqual && dimsNotOne) |
| 287 | { |
| 288 | throw InvalidArgumentException("Broadcasting is not possible for incompatible shapes"); |
| 289 | } |
| 290 | outputDims[i] = std::max(first.GetShape()[i], second.GetShape()[i]); |
| 291 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 292 | TensorShape broadcastShape = TensorShape(boost::numeric_cast<unsigned int>(outputDims.size()), outputDims.data()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 293 | if (broadcastShape != output.GetShape()) |
| 294 | { |
| 295 | throw InvalidArgumentException(descName + ": The tensor shape resulting from adding " |
| 296 | + firstName + " & " + secondName |
| 297 | + " does not match the output shape"); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 302 | void ValidateDataTypes(const TensorInfo& info, |
| 303 | const std::vector<armnn::DataType>& supportedTypes, |
| 304 | std::string const& descName) |
| 305 | { |
| 306 | auto iterator = std::find(supportedTypes.begin(), supportedTypes.end(), info.GetDataType()); |
| 307 | if (iterator == supportedTypes.end()) |
| 308 | { |
| 309 | throw InvalidArgumentException(descName + ": " + " Tensor type is not supported."); |
| 310 | } |
| 311 | } |
| 312 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 313 | //--------------------------------------------------------------- |
| 314 | void ValidateTensorDataTypesMatch(const TensorInfo& first, |
| 315 | const TensorInfo& second, |
| 316 | std::string const& descName, |
| 317 | std::string const& firstName, |
| 318 | std::string const& secondName) |
| 319 | { |
| 320 | if (first.GetDataType() != second.GetDataType()) |
| 321 | { |
| 322 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 323 | " must have identical data types."); |
| 324 | } |
| 325 | } |
| 326 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 327 | //--------------------------------------------------------------- |
| 328 | void ValidateTensorNumElementsMatch(const TensorInfo& first, |
| 329 | const TensorInfo& second, |
| 330 | std::string const& descName, |
| 331 | std::string const& firstName, |
| 332 | std::string const& secondName) |
| 333 | { |
| 334 | if (first.GetNumElements() != second.GetNumElements()) |
| 335 | { |
| 336 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 337 | " must have the same number of elements."); |
| 338 | } |
| 339 | } |
| 340 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 341 | void ValidateWeightDataType(const TensorInfo& inputInfo, |
| 342 | const TensorInfo& weightInfo, |
| 343 | const std::string& descName) |
| 344 | { |
| 345 | const DataType inputType = inputInfo.GetDataType(); |
| 346 | if (inputType == DataType::QuantisedAsymm8) |
| 347 | { |
| 348 | const std::vector<DataType> validTypes = |
| 349 | { |
| 350 | DataType::QuantisedAsymm8, |
| 351 | DataType::QuantizedSymm8PerAxis |
| 352 | }; |
| 353 | |
| 354 | ValidateDataTypes(weightInfo, validTypes, descName); |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | ValidateTensorDataTypesMatch(inputInfo, weightInfo, descName, "input", "weight"); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void ValidatePerAxisQuantizationDimension(const TensorInfo& tensorInfo, |
| 363 | const std::string& descName, |
| 364 | const std::string& tensorName) |
| 365 | { |
| 366 | const Optional<unsigned int>& quantizationDim = tensorInfo.GetQuantizationDim(); |
| 367 | if (!quantizationDim.has_value()) |
| 368 | { |
| 369 | throw InvalidArgumentException(boost::str( |
| 370 | boost::format("%1%: Quantization dimension for per-axis quantization not set on tensor %2%.") |
| 371 | % descName % tensorName)); |
| 372 | } |
| 373 | |
| 374 | if (quantizationDim.value() != 0) |
| 375 | { |
| 376 | throw InvalidArgumentException(boost::str( |
| 377 | boost::format("%1%: Quantization dimension for per-axis quantization expected to be 0 on tensor %2%, " |
| 378 | "but got: %3%") % descName % tensorName % quantizationDim.value())); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void ValidatePerAxisQuantizationOffset(const TensorInfo& tensorInfo, |
| 383 | const std::string& descName, |
| 384 | const std::string& tensorName) |
| 385 | { |
| 386 | int32_t quantizationOffset = tensorInfo.GetQuantizationOffset(); |
| 387 | if (quantizationOffset != 0) |
| 388 | { |
| 389 | throw InvalidArgumentException(boost::str( |
| 390 | boost::format("%1%: Quantization offset for per-axis quantization expected to be 0 on tensor %2%, " |
| 391 | "but got: %3%") % descName % tensorName % quantizationOffset)); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | void ValidatePerAxisQuantization(const TensorInfo& inputInfo, |
| 396 | const TensorInfo& outputInfo, |
| 397 | const TensorInfo& weightInfo, |
| 398 | const Optional<TensorInfo>& optionalBiasInfo, |
| 399 | const std::string& descName) |
| 400 | { |
| 401 | if (weightInfo.HasPerAxisQuantization()) |
| 402 | { |
| 403 | const DataType inputDataType = inputInfo.GetDataType(); |
| 404 | const DataType outputDataType = outputInfo.GetDataType(); |
| 405 | |
| 406 | const bool canHavePerAxisQuantization = |
| 407 | inputDataType == DataType::QuantisedAsymm8 && inputDataType == outputDataType; |
| 408 | |
| 409 | if (!canHavePerAxisQuantization) |
| 410 | { |
| 411 | throw InvalidArgumentException(boost::str( |
| 412 | boost::format("%1%: Per-axis quantization parameters set on tensor %2%, " |
| 413 | "but data type does not support per-axis quantization.") % descName % "weight")); |
| 414 | } |
| 415 | |
| 416 | ValidateTensorDataType(weightInfo, DataType::QuantizedSymm8PerAxis, descName, "weight"); |
| 417 | ValidatePerAxisQuantizationDimension(weightInfo, descName, "weight"); |
| 418 | ValidatePerAxisQuantizationOffset(weightInfo, descName, "weight"); |
| 419 | |
| 420 | if (optionalBiasInfo.has_value()) |
| 421 | { |
| 422 | const TensorInfo& biasInfo = optionalBiasInfo.value(); |
| 423 | if (!biasInfo.HasPerAxisQuantization()) |
| 424 | { |
| 425 | throw InvalidArgumentException(boost::str( |
| 426 | boost::format("%1%: Per-axis quantization parameters not set on bias tensor, despite being set on " |
| 427 | "weight tensor.") % descName)); |
| 428 | } |
| 429 | |
| 430 | ValidateTensorDataType(biasInfo, DataType::Signed32, descName, "bias"); |
| 431 | ValidatePerAxisQuantizationDimension(biasInfo, descName, "bias"); |
| 432 | ValidatePerAxisQuantizationOffset(biasInfo, descName, "bias"); |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 437 | } // anonymous namespace |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 438 | |
| 439 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 440 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 441 | { |
| 442 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 443 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 444 | } |
| 445 | |
| 446 | //--------------------------------------------------------------- |
| 447 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 448 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 449 | const std::string descriptorName{"MemCopyQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 450 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 451 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 452 | ValidateNumOutputs(workloadInfo, descriptorName , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 453 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 454 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 455 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 456 | |
| 457 | ValidateTensorNumElementsMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 458 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 459 | |
| 460 | if (m_Inputs.size() != m_Outputs.size()) |
| 461 | { |
| 462 | throw InvalidArgumentException(boost::str( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 463 | boost::format("%1%: Number of inputs (%2%) does not match the number of outputs (%3%).") % |
| 464 | descriptorName % m_Inputs.size() % m_Outputs.size())); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 468 | { |
| 469 | if (!m_Inputs[i]) |
| 470 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 471 | throw InvalidArgumentException(boost::str(boost::format("%1%: Invalid NULL input %2%.") % |
| 472 | descriptorName % i)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | if (!m_Outputs[i]) |
| 476 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 477 | throw InvalidArgumentException(boost::str(boost::format("%1%: Invalid NULL output %2%") % |
| 478 | descriptorName % i)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 483 | //--------------------------------------------------------------- |
| 484 | void MemImportQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 485 | { |
| 486 | ValidateNumInputs(workloadInfo, "MemImportQueueDescriptor", 1); |
| 487 | ValidateNumOutputs(workloadInfo, "MemImportQueueDescriptor" , 1); |
| 488 | |
| 489 | if (workloadInfo.m_InputTensorInfos.size() != 1) |
| 490 | { |
| 491 | throw InvalidArgumentException(boost::str( |
| 492 | boost::format("Number of input infos (%1%) is not 1.") |
| 493 | % workloadInfo.m_InputTensorInfos.size())); |
| 494 | |
| 495 | } |
| 496 | |
| 497 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 498 | { |
| 499 | throw InvalidArgumentException(boost::str( |
| 500 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 501 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 502 | } |
| 503 | |
| 504 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 505 | { |
| 506 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 507 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 508 | { |
| 509 | throw InvalidArgumentException(boost::str( |
| 510 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 511 | % i )); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | if (m_Inputs.size() != 1) |
| 516 | { |
| 517 | throw InvalidArgumentException(boost::str( |
| 518 | boost::format("Number of inputs (%1%) is not 1.") |
| 519 | % m_Inputs.size())); |
| 520 | } |
| 521 | |
| 522 | if (m_Inputs.size() != m_Outputs.size()) |
| 523 | { |
| 524 | throw InvalidArgumentException(boost::str( |
| 525 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 526 | % m_Inputs.size() % m_Outputs.size())); |
| 527 | } |
| 528 | |
| 529 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 530 | { |
| 531 | if (!m_Inputs[i]) |
| 532 | { |
| 533 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 534 | } |
| 535 | |
| 536 | if (!m_Outputs[i]) |
| 537 | { |
| 538 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | //--------------------------------------------------------------- |
| 544 | void MemSyncQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 545 | { |
| 546 | ValidateNumInputs(workloadInfo, "MemSyncQueueDescriptor", 1); |
| 547 | ValidateNumOutputs(workloadInfo, "MemSyncQueueDescriptor" , 1); |
| 548 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 549 | if (m_Inputs.size() != 1) |
| 550 | { |
| 551 | throw InvalidArgumentException(boost::str( |
| 552 | boost::format("Number of inputs (%1%) is not 1.") |
| 553 | % m_Inputs.size())); |
| 554 | } |
| 555 | |
| 556 | if (m_Outputs.size() != 0) |
| 557 | { |
| 558 | throw InvalidArgumentException(boost::str( |
| 559 | boost::format("Number of outputs (%1%) is not 0.") |
| 560 | % m_Inputs.size() % m_Outputs.size())); |
| 561 | } |
| 562 | |
| 563 | if (!m_Inputs[0]) |
| 564 | { |
| 565 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input 0"))); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 570 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 571 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 572 | const std::string descriptorName{"ActivationQueueDescriptor"}; |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 573 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 574 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 575 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 576 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 577 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 578 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 579 | |
| 580 | std::vector<DataType> supportedTypes = |
| 581 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 582 | DataType::Float16, |
| 583 | DataType::Float32, |
| 584 | DataType::QuantisedAsymm8, |
| 585 | DataType::QuantisedSymm16 |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 586 | }; |
| 587 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 588 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 589 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 590 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 593 | void ArgMinMaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 594 | { |
| 595 | const std::string descriptorName{"ArgMinMaxQueueDescriptor"}; |
| 596 | |
| 597 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 598 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 599 | |
| 600 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 601 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 602 | |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 603 | if (outputTensorInfo.GetDataType() != DataType::Signed32) |
| 604 | { |
| 605 | throw InvalidArgumentException(descriptorName + ": Output of ArgMinMax layer must be Int32."); |
| 606 | } |
| 607 | |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 608 | std::vector<DataType> supportedInputTypes = |
| 609 | { |
| 610 | DataType::Float16, |
| 611 | DataType::Float32, |
| 612 | DataType::QuantisedAsymm8, |
Francis Murtagh | 1939df5 | 2019-11-13 15:21:09 +0000 | [diff] [blame] | 613 | DataType::QuantisedSymm16, |
| 614 | DataType::Signed32 |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 615 | }; |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 616 | |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 617 | ValidateDataTypes(inputTensorInfo, supportedInputTypes, descriptorName); |
James Conroy | c8724c7 | 2019-10-08 15:41:34 +0100 | [diff] [blame] | 618 | |
| 619 | auto inputShape = inputTensorInfo.GetShape(); |
| 620 | auto outputShape = outputTensorInfo.GetShape(); |
| 621 | |
| 622 | auto inputNumDimensions = inputShape.GetNumDimensions(); |
| 623 | auto unsignedAxis = armnnUtils::GetUnsignedAxis(inputNumDimensions, m_Parameters.m_Axis); |
| 624 | |
| 625 | const std::string outputShapeError{": Output tensor shape does not match shape inferred from input tensor."}; |
| 626 | |
| 627 | // 1D input shape results in scalar output shape |
| 628 | if (inputShape.GetNumDimensions() == 1) |
| 629 | { |
| 630 | if (outputShape.GetNumDimensions() != 1 && outputShape[0] != 1) |
| 631 | { |
| 632 | throw InvalidArgumentException(descriptorName + outputShapeError); |
| 633 | } |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | for (unsigned int i = 0; i < unsignedAxis; ++i) |
| 638 | { |
| 639 | if (outputShape[i] != inputShape[i]) |
| 640 | { |
| 641 | throw InvalidArgumentException(descriptorName + outputShapeError); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | for (auto i = unsignedAxis + 1; i < inputNumDimensions; ++i) |
| 646 | { |
| 647 | if (outputShape[i - 1] != inputShape[i]) |
| 648 | { |
| 649 | throw InvalidArgumentException(descriptorName + outputShapeError); |
| 650 | } |
| 651 | } |
| 652 | } |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 653 | } |
| 654 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 655 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 656 | { |
| 657 | const std::string descriptorName{"SoftmaxQueueDescriptor"}; |
| 658 | |
| 659 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 660 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 661 | |
| 662 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 663 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 664 | |
| 665 | std::vector<DataType> supportedTypes = |
| 666 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 667 | DataType::Float16, |
| 668 | DataType::Float32, |
| 669 | DataType::QuantisedAsymm8, |
| 670 | DataType::QuantisedSymm16 |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 674 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 675 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 676 | } |
| 677 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 678 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 679 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 680 | const std::string descriptorName{"SplitterQueueDescriptor"}; |
| 681 | |
| 682 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 683 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 684 | // Check the supported data types |
| 685 | std::vector<DataType> supportedTypes = |
| 686 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 687 | DataType::Float32, |
| 688 | DataType::Float16, |
| 689 | DataType::Boolean, |
| 690 | DataType::Signed32, |
| 691 | DataType::QuantisedAsymm8, |
| 692 | DataType::QuantisedSymm16 |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 693 | }; |
| 694 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 695 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 696 | for (unsigned long i = 0ul; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 697 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 698 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[i]; |
| 699 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
| 700 | |
| 701 | const std::string outputName = "output_" + std::to_string(i); |
| 702 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", outputName); |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 703 | } |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 704 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 705 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 706 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 707 | throw InvalidArgumentException(descriptorName + ": At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 711 | { |
| 712 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 713 | descriptorName + ": Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 714 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 715 | "Number of windows: " + |
| 716 | to_string(m_ViewOrigins.size()) + |
| 717 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 718 | } |
| 719 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 720 | //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] | 721 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 722 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 723 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 724 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 725 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 726 | if (e.m_Origin.size() != inputDims) |
| 727 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 728 | throw InvalidArgumentException(descriptorName + ": Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 729 | "have the same dimensionality as the input tensor. " |
| 730 | "Window origin (index: " + |
| 731 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 732 | " dimensions, the input " |
| 733 | "tensor has " + |
| 734 | to_string(inputDims) + " dimensions."); |
| 735 | } |
| 736 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 737 | { |
| 738 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 739 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 740 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 741 | throw InvalidArgumentException(descriptorName + ": Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 742 | "be smaller or equal than the size of the input in that coord."); |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 748 | void ConcatQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 749 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 750 | const std::string descriptorName{"ConcatQueueDescriptor"}; |
| 751 | |
| 752 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 753 | |
| 754 | if (m_Inputs.size() <= 0) |
| 755 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 756 | throw InvalidArgumentException(descriptorName + ": At least one input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 757 | } |
| 758 | if (m_Outputs.size() <= 0) |
| 759 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 760 | throw InvalidArgumentException(descriptorName + ": At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 764 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 765 | throw InvalidArgumentException(descriptorName + ": At least one TensorInfo input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 766 | } |
| 767 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 768 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 769 | throw InvalidArgumentException(descriptorName + ": At least one TensorInfo output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 772 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 773 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 774 | throw InvalidArgumentException(descriptorName + ": Invalid concatenation axis provided."); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 778 | { |
| 779 | return; |
| 780 | } |
| 781 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 782 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 783 | { |
| 784 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 785 | descriptorName + ": Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 786 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 787 | "Number of windows: " + |
| 788 | to_string(m_ViewOrigins.size()) + |
| 789 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 790 | } |
| 791 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 792 | //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] | 793 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 794 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 795 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 796 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 797 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 798 | if (e.m_Origin.size() != outputDims) |
| 799 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 800 | throw InvalidArgumentException(descriptorName + ": Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 801 | "have the same dimensionality as the output tensor. " |
| 802 | "Window origin (index: " + |
| 803 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 804 | " dimensions, the output " |
| 805 | "tensor has " + |
| 806 | to_string(outputDims) + " dimensions."); |
| 807 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 808 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 809 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 810 | { |
| 811 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 812 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 813 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 814 | throw InvalidArgumentException(descriptorName + ": Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 815 | "be smaller or equal than the size of the output in that coord."); |
| 816 | } |
| 817 | } |
| 818 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 819 | |
| 820 | // Check the supported data types |
| 821 | std::vector<DataType> supportedTypes = |
| 822 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 823 | DataType::Float32, |
| 824 | DataType::Float16, |
| 825 | DataType::Boolean, |
| 826 | DataType::Signed32, |
| 827 | DataType::QuantisedAsymm8, |
| 828 | DataType::QuantisedSymm16 |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 829 | }; |
| 830 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 831 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 832 | for (unsigned long i = 0ul; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 833 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 834 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[i]; |
| 835 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 836 | |
| 837 | const std::string inputName = "input_" + std::to_string(i); |
| 838 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, inputName, "output"); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 839 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 842 | void StackQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 843 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 844 | const std::string descriptorName{"StackQueueDescriptor"}; |
| 845 | |
| 846 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 847 | |
| 848 | if (m_Parameters.m_NumInputs != workloadInfo.m_InputTensorInfos.size()) |
| 849 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 850 | throw InvalidArgumentException(descriptorName + ": Must have the defined number of input tensors."); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | // All inputs must have the same shape, which is defined in parameters |
| 854 | const TensorShape& inputShape = m_Parameters.m_InputShape; |
| 855 | for (unsigned int i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 856 | { |
| 857 | if (workloadInfo.m_InputTensorInfos[i].GetShape() != inputShape) |
| 858 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 859 | throw InvalidArgumentException(descriptorName + ": All input tensor shapes must match the defined shape."); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 863 | if (inputShape.GetNumDimensions() > 4) |
| 864 | { |
| 865 | throw InvalidArgumentException(descriptorName + ": Input tensor may have up to 4 dimensions."); |
| 866 | } |
| 867 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 868 | // m_Axis is 0-based and may take values from 0 to the number of input dimensions (inclusive), |
| 869 | // since the output tensor has an additional dimension. |
| 870 | if (m_Parameters.m_Axis > inputShape.GetNumDimensions()) |
| 871 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 872 | throw InvalidArgumentException(descriptorName + ": Axis may not be greater " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 873 | "than the number of input dimensions."); |
| 874 | } |
| 875 | |
| 876 | // Output shape must be as inferred from the input shape |
| 877 | const TensorShape& outputShape = workloadInfo.m_OutputTensorInfos[0].GetShape(); |
| 878 | for (unsigned int i = 0; i < m_Parameters.m_Axis; ++i) |
| 879 | { |
| 880 | if (outputShape[i] != inputShape[i]) |
| 881 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 882 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 883 | "match shape inferred from input tensor."); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | if (outputShape[m_Parameters.m_Axis] != m_Parameters.m_NumInputs) |
| 888 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 889 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 890 | "match shape inferred from input tensor."); |
| 891 | } |
| 892 | |
| 893 | for (unsigned int i = m_Parameters.m_Axis + 1; i < inputShape.GetNumDimensions() + 1; ++i) |
| 894 | { |
| 895 | if (outputShape[i] != inputShape[i-1]) |
| 896 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 897 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 898 | "match shape inferred from input tensor."); |
| 899 | } |
| 900 | } |
| 901 | |
Matthew Jackson | dba634f | 2019-08-15 15:14:18 +0100 | [diff] [blame] | 902 | if (outputShape.GetNumDimensions() > 5) |
| 903 | { |
| 904 | throw InvalidArgumentException(descriptorName + ": Output tensor may have up to 5 dimensions."); |
| 905 | } |
| 906 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 907 | // Check the supported data types |
| 908 | std::vector<DataType> supportedTypes = |
| 909 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 910 | DataType::Float32, |
| 911 | DataType::Float16, |
| 912 | DataType::Boolean, |
| 913 | DataType::Signed32, |
| 914 | DataType::QuantisedAsymm8, |
| 915 | DataType::QuantisedSymm16 |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 916 | }; |
| 917 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 918 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 919 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 920 | for (unsigned int i = 1ul; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 921 | { |
| 922 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 923 | workloadInfo.m_InputTensorInfos[i], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 924 | descriptorName, |
| 925 | "input_0", |
| 926 | "input_" + std::to_string(i)); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 927 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 928 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 929 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 930 | workloadInfo.m_OutputTensorInfos[0], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 931 | descriptorName, |
| 932 | "input_0", |
| 933 | "output"); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 934 | } |
| 935 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 936 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 937 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 938 | const std::string descriptorName{"FullyConnectedQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 939 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 940 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 941 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 942 | |
| 943 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 944 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 945 | |
| 946 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 2, "output"); |
| 947 | |
| 948 | if (!(inputTensorInfo.GetNumDimensions() == 2 || inputTensorInfo.GetNumDimensions() == 4)) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 949 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 950 | throw InvalidArgumentException(descriptorName + ": Input tensor must have 2 or 4 dimensions."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 953 | ValidatePointer(m_Weight, descriptorName, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 954 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 955 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 956 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 2, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 957 | |
| 958 | if (m_Parameters.m_BiasEnabled) |
| 959 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 960 | ValidatePointer(m_Bias, descriptorName, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 961 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 962 | // Validates type and quantization values. |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 963 | const TensorInfo& biasTensorInfo = m_Bias->GetTensorInfo(); |
| 964 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 965 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 966 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 967 | ValidateTensorNumDimensions(biasTensorInfo, descriptorName, 1, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 970 | // Check the supported data types |
| 971 | std::vector<DataType> supportedTypes = |
| 972 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 973 | DataType::Float32, |
| 974 | DataType::Float16, |
| 975 | DataType::QuantisedAsymm8, |
| 976 | DataType::QuantisedSymm16 |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 977 | }; |
| 978 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 979 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 980 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 981 | } |
| 982 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 983 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 984 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 985 | const std::string descriptorName{"NormalizationQueueDescriptor"}; |
| 986 | |
| 987 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 988 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 989 | |
| 990 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 991 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 992 | |
| 993 | // Check the supported data types |
| 994 | std::vector<DataType> supportedTypes = |
| 995 | { |
| 996 | DataType::Float16, |
| 997 | DataType::Float32, |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 998 | DataType::QuantisedAsymm8, |
| 999 | DataType::QuantisedSymm16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1000 | }; |
| 1001 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1002 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1003 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1004 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1005 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1006 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1010 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1011 | const std::string descriptorName{"AdditionQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1012 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1013 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 1014 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1015 | |
| 1016 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 1017 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 1018 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1019 | |
| 1020 | std::vector<DataType> supportedTypes = |
| 1021 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1022 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1023 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1024 | DataType::QuantisedSymm16, |
| 1025 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1026 | }; |
| 1027 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1028 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 1029 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 1030 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1031 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1032 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 1033 | ValidateTensorDataTypesMatch(inputTensorInfo1, outputTensorInfo, descriptorName, "input_1", "output"); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1034 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1035 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 1036 | inputTensorInfo1, |
| 1037 | outputTensorInfo, |
| 1038 | descriptorName, |
| 1039 | "input_0", |
| 1040 | "input_1"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1043 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1044 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1045 | const std::string descriptorName{"MultiplicationQueueDescriptor"}; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 1046 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1047 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 1048 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1049 | |
| 1050 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 1051 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 1052 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1053 | |
| 1054 | std::vector<DataType> supportedTypes = |
| 1055 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1056 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1057 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1058 | DataType::QuantisedSymm16, |
| 1059 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1060 | }; |
| 1061 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1062 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 1063 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 1064 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1065 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1066 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 1067 | ValidateTensorDataTypesMatch(inputTensorInfo1, outputTensorInfo, descriptorName, "input_1", "output"); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1068 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1069 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 1070 | inputTensorInfo1, |
| 1071 | outputTensorInfo, |
| 1072 | descriptorName, |
| 1073 | "input_0", |
| 1074 | "input_1"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1078 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1079 | const std::string descriptorName{"BatchNormalizationQueueDescriptor"}; |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1080 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1081 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1082 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1083 | |
| 1084 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1085 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1086 | |
| 1087 | std::vector<DataType> supportedTypes = |
| 1088 | { |
| 1089 | DataType::Float16, |
| 1090 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 1091 | DataType::QuantisedAsymm8, |
| 1092 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1093 | }; |
| 1094 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1095 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1096 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1097 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1098 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1099 | ValidateTensorQuantizationSpace(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1100 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1101 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1102 | ValidatePointer(m_Mean, descriptorName, "mean"); |
| 1103 | ValidatePointer(m_Variance, descriptorName, "variance"); |
| 1104 | ValidatePointer(m_Beta, descriptorName, "beta"); |
| 1105 | ValidatePointer(m_Gamma, descriptorName, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1106 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 1107 | const TensorInfo& mean = m_Mean->GetTensorInfo(); |
| 1108 | const TensorInfo& variance = m_Variance->GetTensorInfo(); |
| 1109 | const TensorInfo& beta = m_Beta->GetTensorInfo(); |
| 1110 | const TensorInfo& gamma = m_Gamma->GetTensorInfo(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1111 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1112 | ValidateTensorNumDimensions(mean, descriptorName, 1, "mean"); |
| 1113 | ValidateTensorNumDimensions(variance, descriptorName, 1, "variance"); |
| 1114 | ValidateTensorNumDimensions(beta, descriptorName, 1, "beta"); |
| 1115 | ValidateTensorNumDimensions(gamma, descriptorName, 1, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1116 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1117 | ValidateTensorShapesMatch(mean, variance, descriptorName, "mean", "variance"); |
| 1118 | ValidateTensorShapesMatch(mean, beta, descriptorName, "mean", "beta"); |
| 1119 | ValidateTensorShapesMatch(mean, gamma, descriptorName, "mean", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1123 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1124 | const std::string descriptorName{"Convolution2dQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1125 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1126 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1127 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1128 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1129 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1130 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1131 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1132 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1133 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1134 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1135 | ValidatePointer(m_Weight, descriptorName, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1136 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1137 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 1138 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1139 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1140 | ValidateWeightDataType(inputTensorInfo, weightTensorInfo, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1141 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1142 | Optional<TensorInfo> optionalBiasTensorInfo; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1143 | if (m_Parameters.m_BiasEnabled) |
| 1144 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1145 | ValidatePointer(m_Bias, descriptorName, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1146 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1147 | optionalBiasTensorInfo = MakeOptional<TensorInfo>(m_Bias->GetTensorInfo()); |
| 1148 | const TensorInfo& biasTensorInfo = optionalBiasTensorInfo.value(); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1149 | |
| 1150 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 1151 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1154 | ValidatePerAxisQuantization(inputTensorInfo, |
| 1155 | outputTensorInfo, |
| 1156 | weightTensorInfo, |
| 1157 | optionalBiasTensorInfo, |
| 1158 | descriptorName); |
| 1159 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1160 | std::vector<DataType> supportedTypes = |
| 1161 | { |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 1162 | DataType::Float32, |
| 1163 | DataType::QuantisedAsymm8, |
| 1164 | DataType::QuantisedSymm16, |
| 1165 | DataType::Float16 |
| 1166 | }; |
| 1167 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1168 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1169 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1170 | } |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 1171 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1172 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1173 | { |
| 1174 | const std::string descriptorName{"DepthwiseConvolution2dQueueDescriptor"}; |
| 1175 | |
| 1176 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1177 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1178 | |
| 1179 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1180 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1181 | |
| 1182 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1183 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
| 1184 | |
| 1185 | ValidatePointer(m_Weight, descriptorName, "weight"); |
| 1186 | |
| 1187 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 1188 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
| 1189 | |
| 1190 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 1191 | { |
| 1192 | throw InvalidArgumentException( |
| 1193 | boost::str(boost::format("%1%: dilationX (provided %2%) and dilationY (provided %3%) " |
| 1194 | "cannot be smaller than 1.") % descriptorName % |
| 1195 | m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 1196 | } |
| 1197 | |
| 1198 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 1199 | |
| 1200 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 1201 | // inputChannels * channelMultiplier should be equal to outputChannels. |
| 1202 | const unsigned int numWeightChannelMultiplier = weightTensorInfo.GetShape()[0]; |
| 1203 | const unsigned int numWeightInputChannels = weightTensorInfo.GetShape()[1]; |
| 1204 | const unsigned int numWeightOutputChannels = outputTensorInfo.GetShape()[channelIndex]; |
| 1205 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 1206 | { |
| 1207 | throw InvalidArgumentException( |
| 1208 | boost::str(boost::format("%1%: output_channels (provided %2%) should be " |
| 1209 | "equal to input_channels (provided %3%) multiplied by channel_multiplier " |
| 1210 | "(provided %4%).") % descriptorName % numWeightOutputChannels % |
| 1211 | numWeightInputChannels % numWeightChannelMultiplier)); |
| 1212 | } |
| 1213 | |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1214 | ValidateWeightDataType(inputTensorInfo, weightTensorInfo, descriptorName); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1215 | |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1216 | Optional<TensorInfo> optionalBiasTensorInfo; |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1217 | if (m_Parameters.m_BiasEnabled) |
| 1218 | { |
| 1219 | ValidatePointer(m_Bias, descriptorName, "bias"); |
| 1220 | |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1221 | optionalBiasTensorInfo = MakeOptional<TensorInfo>(m_Bias->GetTensorInfo()); |
| 1222 | const TensorInfo& biasTensorInfo = optionalBiasTensorInfo.value(); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1223 | |
| 1224 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
| 1225 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 1226 | } |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1227 | ValidatePerAxisQuantization(inputTensorInfo, |
| 1228 | outputTensorInfo, |
| 1229 | weightTensorInfo, |
| 1230 | optionalBiasTensorInfo, |
| 1231 | descriptorName); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1232 | |
| 1233 | std::vector<DataType> supportedTypes = |
| 1234 | { |
| 1235 | DataType::Float32, |
| 1236 | DataType::QuantisedAsymm8, |
| 1237 | DataType::QuantisedSymm16, |
| 1238 | DataType::Float16 |
| 1239 | }; |
| 1240 | |
| 1241 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1242 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1246 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1247 | const std::string descriptorName{"PermuteQueueDescriptor"}; |
| 1248 | |
| 1249 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1250 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1251 | |
| 1252 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 1253 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1254 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1255 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1256 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1257 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, mapping.GetSize(), "input"); |
| 1258 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, mapping.GetSize(), "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1259 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1260 | for (unsigned int i = 0u; i < mapping.GetSize(); ++i) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1261 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1262 | if (inputTensorInfo.GetShape()[i] != outputTensorInfo.GetShape()[mapping[i]]) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1263 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1264 | throw InvalidArgumentException(descriptorName + ": src dimension " + to_string(i) + |
| 1265 | " (=" + to_string(inputTensorInfo.GetShape()[i]) + ") " + |
| 1266 | "must match dst dimension " + to_string(mapping[i]) + |
| 1267 | " (=" + to_string(outputTensorInfo.GetShape()[mapping[i]]) + ")"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1268 | } |
| 1269 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1270 | |
| 1271 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1275 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1276 | const std::string descriptorName{"Pooling2dQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1277 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1278 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1279 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1280 | |
| 1281 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1282 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1283 | |
| 1284 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1285 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1286 | |
| 1287 | std::vector<DataType> supportedTypes = |
| 1288 | { |
| 1289 | DataType::Float32, |
| 1290 | DataType::Float16, |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 1291 | DataType::QuantisedAsymm8, |
| 1292 | DataType::QuantisedSymm16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1293 | }; |
| 1294 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1295 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1296 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1300 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1301 | const std::string descriptorName{"ResizeBilinearQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1302 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1303 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1304 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1305 | |
| 1306 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1307 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1308 | |
| 1309 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1310 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1311 | |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1312 | std::vector<DataType> supportedTypes = |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1313 | { |
| 1314 | DataType::Float16, |
| 1315 | DataType::Float32, |
| 1316 | DataType::QuantisedAsymm8, |
| 1317 | DataType::QuantisedSymm16 |
| 1318 | }; |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1319 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1320 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1321 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1322 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1323 | // ResizeBilinear only changes width and height: batch and channel count must match. |
| 1324 | const unsigned int inputBatchSize = inputTensorInfo.GetShape()[0]; |
| 1325 | const unsigned int outputBatchSize = outputTensorInfo.GetShape()[0]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1326 | if (inputBatchSize != outputBatchSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1327 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1328 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1329 | boost::str(boost::format("%1%: Input batch size (%2%) " |
| 1330 | "does not match output batch size (%3%)") % |
| 1331 | descriptorName % inputBatchSize % outputBatchSize)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1334 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1335 | const unsigned int inputChannelCount = inputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1336 | const unsigned int outputChannelCount = outputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1337 | if (inputChannelCount != outputChannelCount) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1338 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1339 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1340 | boost::str(boost::format("%1%: Input channel count (%2%) " |
| 1341 | "does not match output channel count (%3%)") % |
| 1342 | descriptorName % inputChannelCount % outputChannelCount)); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | void ResizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1347 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1348 | const std::string descriptorName{"ResizeQueueDescriptor"}; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1349 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1350 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1351 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1352 | |
| 1353 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1354 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1355 | |
| 1356 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1357 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1358 | |
| 1359 | std::vector<DataType> supportedTypes = |
| 1360 | { |
| 1361 | DataType::Float16, |
| 1362 | DataType::Float32, |
| 1363 | DataType::QuantisedAsymm8, |
| 1364 | DataType::QuantisedSymm16 |
| 1365 | }; |
| 1366 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1367 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1368 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1369 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1370 | // Resize only changes width and height: batch and channel count must match. |
| 1371 | const unsigned int inputBatchSize = inputTensorInfo.GetShape()[0]; |
| 1372 | const unsigned int outputBatchSize = outputTensorInfo.GetShape()[0]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1373 | if (inputBatchSize != outputBatchSize) |
| 1374 | { |
| 1375 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1376 | boost::str(boost::format("%1%: Input batch size (%2%) " |
| 1377 | "does not match output batch size (%3%)") % |
| 1378 | descriptorName % inputBatchSize % outputBatchSize)); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1382 | const unsigned int inputChannelCount = inputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1383 | const unsigned int outputChannelCount = outputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1384 | if (inputChannelCount != outputChannelCount) |
| 1385 | { |
| 1386 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1387 | boost::str(boost::format("%1%: Input channel count (%2%) " |
| 1388 | "does not match output channel count (%3%)") % |
| 1389 | descriptorName % inputChannelCount % outputChannelCount)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1394 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1395 | const std::string descriptorName{"FakeQuantizationQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1396 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1397 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1398 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1399 | |
| 1400 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1401 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1402 | |
| 1403 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 2, "input"); |
| 1404 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 2, "output"); |
| 1405 | |
| 1406 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1407 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1408 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 1409 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1410 | throw InvalidArgumentException(descriptorName + ": min cannot be greater than max"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1411 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 1414 | void InstanceNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1415 | { |
| 1416 | const std::string descriptorName{"InstanceNormalizationQueueDescriptor"}; |
| 1417 | |
| 1418 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1419 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1420 | |
| 1421 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1422 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1423 | |
| 1424 | if (inputTensorInfo.GetNumDimensions() > 4) |
| 1425 | { |
| 1426 | throw InvalidArgumentException(descriptorName + ": Input tensors with rank greater than 4 are not supported."); |
| 1427 | } |
| 1428 | |
| 1429 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1430 | |
| 1431 | // Check the supported data types |
| 1432 | std::vector<DataType> supportedTypes = |
| 1433 | { |
| 1434 | DataType::Float32, |
| 1435 | DataType::Float16 |
| 1436 | }; |
| 1437 | |
| 1438 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 1439 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1442 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1443 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1444 | const std::string descriptorName{"L2NormalizationQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1445 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1446 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1447 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1448 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1449 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1450 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1451 | |
Matthew Jackson | 82b15ed | 2019-07-25 16:14:30 +0100 | [diff] [blame] | 1452 | if (inputTensorInfo.GetNumDimensions() > 4) |
| 1453 | { |
| 1454 | throw InvalidArgumentException(descriptorName + ": Input tensors with rank greater than 4 are not supported."); |
| 1455 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1456 | |
| 1457 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1458 | |
| 1459 | // Check the supported data types |
| 1460 | std::vector<DataType> supportedTypes = |
| 1461 | { |
| 1462 | DataType::Float32, |
| 1463 | DataType::Float16, |
| 1464 | DataType::QuantisedAsymm8, |
| 1465 | DataType::QuantisedSymm16 |
| 1466 | }; |
| 1467 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1468 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Aron Virginas-Tar | f982dea | 2019-10-11 14:07:53 +0100 | [diff] [blame] | 1469 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1470 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1471 | |
Aron Virginas-Tar | f982dea | 2019-10-11 14:07:53 +0100 | [diff] [blame] | 1472 | void LogSoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1473 | { |
| 1474 | const std::string descriptorName{"LogSoftmaxQueueDescriptor"}; |
| 1475 | |
| 1476 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1477 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1478 | |
| 1479 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1480 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1481 | |
| 1482 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1483 | |
| 1484 | std::vector<DataType> supportedTypes = |
| 1485 | { |
| 1486 | DataType::Float32, |
| 1487 | DataType::Float16, |
| 1488 | }; |
| 1489 | |
| 1490 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1491 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1495 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1496 | const std::string descriptorName{"ConstantQueueDescriptor"}; |
| 1497 | |
| 1498 | ValidateNumInputs(workloadInfo, descriptorName, 0); |
| 1499 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1500 | |
| 1501 | if (!m_LayerOutput) |
| 1502 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1503 | throw InvalidArgumentException(descriptorName + ": No const input specified."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1506 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1507 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), outputTensorInfo, descriptorName, "constant", "output"); |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1508 | |
| 1509 | // Check the supported data types |
| 1510 | std::vector<DataType> supportedTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1511 | { |
| 1512 | DataType::Float32, |
| 1513 | DataType::Float16, |
| 1514 | DataType::Signed32, |
| 1515 | DataType::QuantisedAsymm8, |
| 1516 | DataType::QuantisedSymm16 |
| 1517 | }; |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1518 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1519 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1523 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1524 | const std::string descriptorName{"ReshapeQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1525 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1526 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1527 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1528 | |
| 1529 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1530 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1531 | |
| 1532 | ValidateTensorNumElementsMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1533 | |
| 1534 | // Check the supported data types |
| 1535 | std::vector<DataType> supportedTypes = |
| 1536 | { |
| 1537 | DataType::Float32, |
| 1538 | DataType::Float16, |
Narumol Prangnawarat | 0718ee9 | 2019-09-13 16:53:38 +0100 | [diff] [blame] | 1539 | DataType::Signed32, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1540 | DataType::QuantisedAsymm8, |
| 1541 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1542 | }; |
| 1543 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1544 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1545 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1548 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1549 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1550 | const std::string descriptorName{"SpaceToBatchNdQueueDescriptor"}; |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1551 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1552 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1553 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1554 | |
| 1555 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1556 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1557 | |
| 1558 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1559 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1560 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1561 | if (m_Parameters.m_BlockShape.size() != 2) |
| 1562 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1563 | throw InvalidArgumentException(descriptorName + ": Block Shape must contain 2 spatial dimensions."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 1567 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1568 | throw InvalidArgumentException(descriptorName + ": Pad List must contain the same number of " |
| 1569 | "dimensions as Block Shape."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1572 | const TensorShape& inputShape = inputTensorInfo.GetShape(); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1573 | |
| 1574 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1575 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1576 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1577 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1578 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1579 | const unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] + |
| 1580 | widthPad.first + widthPad.second; |
| 1581 | const unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] + |
| 1582 | heightPad.first + heightPad.second; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1583 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1584 | const unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth * |
| 1585 | inputShape[dimensionIndices.GetChannelsIndex()]; |
| 1586 | const unsigned int numOutputElements = outputTensorInfo.GetNumElements(); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1587 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1588 | if (numOutputElements != numInputElements) |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1589 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1590 | throw InvalidArgumentException(descriptorName + ": Input tensor has " + |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1591 | to_string(numInputElements) + " after padding but output tensor has " + |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1592 | to_string(numOutputElements) + " elements."); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | 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] | 1596 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1597 | throw InvalidArgumentException(descriptorName + ": Input shape after padding must be " |
| 1598 | "divisible by Block Shape in all spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1599 | } |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1600 | |
| 1601 | std::vector<DataType> supportedTypes = |
| 1602 | { |
| 1603 | DataType::Float16, |
| 1604 | DataType::Float32, |
| 1605 | DataType::QuantisedAsymm8, |
| 1606 | DataType::QuantisedSymm16 |
| 1607 | }; |
| 1608 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1609 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1610 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1613 | void SpaceToDepthQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1614 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1615 | const std::string descriptorName{"SpaceToDepthQueueDescriptor"}; |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1616 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1617 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1618 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1619 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1620 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1621 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1622 | |
| 1623 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1624 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1625 | |
| 1626 | std::vector<DataType> supportedTypes = |
| 1627 | { |
| 1628 | DataType::Float32, |
| 1629 | DataType::Float16, |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame] | 1630 | DataType::QuantisedAsymm8, |
| 1631 | DataType::QuantisedSymm16 |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1632 | }; |
| 1633 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1634 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1635 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1636 | |
Aron Virginas-Tar | 8a1b218 | 2019-09-19 14:39:37 +0100 | [diff] [blame] | 1637 | ValidateTensorNumElementsMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1638 | |
| 1639 | if (m_Parameters.m_BlockSize == 0) |
| 1640 | { |
| 1641 | throw InvalidArgumentException(descriptorName + ": Block size cannot be 0."); |
| 1642 | } |
| 1643 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1644 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1645 | const unsigned int wIndex = dimensionIndices.GetWidthIndex(); |
| 1646 | const unsigned int hIndex = dimensionIndices.GetHeightIndex(); |
| 1647 | const unsigned int cIndex = dimensionIndices.GetChannelsIndex(); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1648 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1649 | const TensorShape& inputShape = inputTensorInfo.GetShape(); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1650 | if (inputShape[hIndex] % m_Parameters.m_BlockSize != 0 || inputShape[wIndex] % m_Parameters.m_BlockSize != 0) |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1651 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1652 | throw InvalidArgumentException(descriptorName + ": Input shape must be divisible " |
| 1653 | "by block size in all spatial dimensions"); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1654 | } |
Aron Virginas-Tar | 8a1b218 | 2019-09-19 14:39:37 +0100 | [diff] [blame] | 1655 | |
| 1656 | const TensorShape& outputShape = outputTensorInfo.GetShape(); |
| 1657 | if (outputShape[cIndex] % (m_Parameters.m_BlockSize * m_Parameters.m_BlockSize) != 0) |
| 1658 | { |
| 1659 | throw InvalidArgumentException(descriptorName + ": The depth of the output tensor" |
| 1660 | "must be divisible by the square of block size." ); |
| 1661 | } |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1664 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1665 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1666 | const std::string descriptorName{"FloorQueueDescriptor"}; |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1667 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1668 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1669 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1670 | |
| 1671 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1672 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1673 | |
| 1674 | std::vector<DataType> supportedTypes = |
| 1675 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1676 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 1677 | DataType::Float16, |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1678 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1679 | }; |
| 1680 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1681 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1682 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1683 | if (inputTensorInfo != outputTensorInfo) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1684 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1685 | throw InvalidArgumentException(descriptorName + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1689 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1690 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1691 | // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions() |
| 1692 | |
| 1693 | const std::string descriptorName{"LstmQueueDescriptor"}; |
| 1694 | |
| 1695 | // check dimensions of all inputs and outputs |
| 1696 | if (workloadInfo.m_InputTensorInfos.size() != 3) |
| 1697 | { |
| 1698 | throw InvalidArgumentException(descriptorName + ": Invalid number of inputs."); |
| 1699 | } |
| 1700 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1701 | { |
| 1702 | throw InvalidArgumentException(descriptorName + ": Invalid number of outputs."); |
| 1703 | } |
| 1704 | |
| 1705 | std::vector<DataType> supportedTypes = |
| 1706 | { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1707 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1708 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1709 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1710 | }; |
| 1711 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1712 | // check for supported type of one input and match them with all the other input and output |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1713 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
| 1714 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1715 | // type matches all other inputs |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1716 | for (uint32_t i = 1u; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1717 | { |
| 1718 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1719 | workloadInfo.m_InputTensorInfos[i], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1720 | descriptorName, |
| 1721 | "input_0", |
| 1722 | "input_" + std::to_string(i)); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1723 | } |
| 1724 | // type matches all other outputs |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1725 | for (uint32_t i = 0u; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1726 | { |
| 1727 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1728 | workloadInfo.m_OutputTensorInfos[i], |
| 1729 | "LstmQueueDescriptor", |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1730 | "input_0", |
| 1731 | "output_" + std::to_string(i)); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1732 | } |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1733 | |
janeil01 | 17d8d85 | 2019-11-15 15:00:16 +0000 | [diff] [blame] | 1734 | // Making sure clipping parameters have valid values. |
| 1735 | // == 0 means no clipping |
| 1736 | // > 0 means clipping |
| 1737 | if (m_Parameters.m_ClippingThresCell < 0.0f) |
| 1738 | { |
| 1739 | throw InvalidArgumentException(descriptorName + ": negative cell clipping threshold is invalid"); |
| 1740 | } |
| 1741 | if (m_Parameters.m_ClippingThresProj < 0.0f) |
| 1742 | { |
| 1743 | throw InvalidArgumentException(descriptorName + ": negative projection clipping threshold is invalid"); |
| 1744 | } |
| 1745 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1746 | |
| 1747 | // Inferring batch size, number of outputs and number of cells from the inputs. |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1748 | const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1]; |
| 1749 | const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 1750 | ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights"); |
| 1751 | const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0]; |
| 1752 | ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights"); |
| 1753 | const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1]; |
| 1754 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1755 | // input tensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1756 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input), |
| 1757 | descriptorName + " input_0"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1758 | // outputStateInTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1759 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output), |
| 1760 | descriptorName + " input_1"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1761 | // outputStateInTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1762 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell), |
| 1763 | descriptorName + " input_2"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1764 | // scratchBufferTensor |
| 1765 | unsigned int scratchBufferSize = m_Parameters.m_CifgEnabled ? n_cell * 3 : n_cell * 4; |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1766 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize), |
| 1767 | descriptorName + " output_0"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1768 | // outputStateOutTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1769 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output), |
| 1770 | descriptorName + " output_1"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1771 | // cellStateOutTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1772 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell), |
| 1773 | descriptorName + " output_2"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1774 | // outputTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1775 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output), |
| 1776 | descriptorName + " output_3"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1777 | |
| 1778 | |
| 1779 | // check that dimensions of inputs/outputs and QueueDescriptor data match with each other |
| 1780 | if ( m_InputToInputWeights ) |
| 1781 | { |
| 1782 | ValidateTensorNumDimNumElem(m_InputToInputWeights->GetTensorInfo(), 2, |
| 1783 | (n_cell * n_input), "InputLayerNormWeights"); |
| 1784 | } |
| 1785 | |
| 1786 | ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights"); |
| 1787 | ValidateTensorNumDimNumElem(m_InputToForgetWeights->GetTensorInfo(), 2, |
| 1788 | (n_cell * n_input), "InputToForgetWeights"); |
| 1789 | |
| 1790 | ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights"); |
| 1791 | ValidateTensorNumDimNumElem(m_InputToCellWeights->GetTensorInfo(), 2, |
| 1792 | (n_cell * n_input), "InputToCellWeights"); |
| 1793 | |
| 1794 | if ( m_RecurrentToInputWeights ) |
| 1795 | { |
| 1796 | ValidateTensorNumDimNumElem(m_RecurrentToInputWeights->GetTensorInfo(), 2, |
| 1797 | (n_cell * n_output), "RecurrentToInputWeights"); |
| 1798 | } |
| 1799 | |
| 1800 | ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights"); |
| 1801 | ValidateTensorNumDimNumElem(m_RecurrentToForgetWeights->GetTensorInfo(), 2, |
| 1802 | (n_cell * n_output), "RecurrentToForgetWeights"); |
| 1803 | |
| 1804 | ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights"); |
| 1805 | ValidateTensorNumDimNumElem(m_RecurrentToCellWeights->GetTensorInfo(), 2, |
| 1806 | (n_cell * n_output), "RecurrentToCellWeights"); |
| 1807 | |
| 1808 | // Make sure the input-gate's parameters are either both present (regular |
| 1809 | // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly. |
| 1810 | bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights && |
| 1811 | !m_Parameters.m_CifgEnabled) || |
| 1812 | (!m_InputToInputWeights && !m_RecurrentToInputWeights && |
| 1813 | m_Parameters.m_CifgEnabled)); |
| 1814 | if (!cifg_weights_all_or_none) |
| 1815 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1816 | throw InvalidArgumentException(descriptorName + ": Input-Gate's parameters InputToInputWeights and " |
| 1817 | "RecurrentToInputWeights must either both be present (regular LSTM) " |
| 1818 | "or both not present (CIFG-LSTM). In addition CifgEnable must be set " |
| 1819 | "accordingly."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | if ( m_CellToInputWeights ) |
| 1823 | { |
| 1824 | ValidateTensorNumDimNumElem(m_CellToInputWeights->GetTensorInfo(), 1, |
| 1825 | n_cell, "CellToInputWeights"); |
| 1826 | } |
| 1827 | if ( m_CellToForgetWeights ) |
| 1828 | { |
| 1829 | ValidateTensorNumDimNumElem(m_CellToForgetWeights->GetTensorInfo(), 1, |
| 1830 | n_cell, "CellToForgetWeights"); |
| 1831 | } |
| 1832 | if ( m_CellToOutputWeights ) |
| 1833 | { |
| 1834 | ValidateTensorNumDimNumElem(m_CellToOutputWeights->GetTensorInfo(), 1, |
| 1835 | n_cell, "CellToOutputWeights"); |
| 1836 | } |
| 1837 | |
| 1838 | // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly. |
| 1839 | bool peephole_weights_all_or_none = |
| 1840 | (((m_CellToInputWeights || m_Parameters.m_CifgEnabled) && m_CellToForgetWeights |
| 1841 | && m_CellToOutputWeights && m_Parameters.m_PeepholeEnabled) |
| 1842 | || ( !m_CellToInputWeights && !m_CellToForgetWeights |
| 1843 | && !m_CellToOutputWeights && !m_Parameters.m_PeepholeEnabled)); |
| 1844 | if (!peephole_weights_all_or_none) |
| 1845 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1846 | throw InvalidArgumentException(descriptorName + ": Invalid combination of peephole parameters."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | // Make sure the input gate bias is present only when not a CIFG-LSTM. |
| 1850 | if (m_Parameters.m_CifgEnabled) |
| 1851 | { |
| 1852 | if (m_InputGateBias) |
| 1853 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1854 | throw InvalidArgumentException(descriptorName + ": InputGateBias is present and CIFG-LSTM is enabled."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | else |
| 1858 | { |
| 1859 | if (!m_InputGateBias) |
| 1860 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1861 | throw InvalidArgumentException(descriptorName + ": If CIFG-LSTM is disabled InputGateBias " |
| 1862 | "must be present."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1863 | } |
| 1864 | ValidateTensorNumDimNumElem(m_InputGateBias->GetTensorInfo(), 1, |
| 1865 | n_cell, "InputGateBias"); |
| 1866 | } |
| 1867 | |
| 1868 | ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias"); |
| 1869 | ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias"); |
| 1870 | |
| 1871 | ValidatePointer(m_CellBias, "Null pointer check", "CellBias"); |
| 1872 | ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias"); |
| 1873 | |
| 1874 | ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias"); |
| 1875 | ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias"); |
| 1876 | |
| 1877 | if (m_ProjectionWeights) |
| 1878 | { |
| 1879 | ValidateTensorNumDimNumElem(m_ProjectionWeights->GetTensorInfo(), 2, |
| 1880 | (n_cell * n_output), "ProjectionWeights"); |
| 1881 | } |
| 1882 | if (m_ProjectionBias) |
| 1883 | { |
| 1884 | ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias"); |
| 1885 | } |
| 1886 | |
| 1887 | // Making sure the projection tensors are consistent: |
| 1888 | // 1) If projection weight is not present, then projection bias should not be |
| 1889 | // present. |
| 1890 | // 2) If projection weight is present, then projection bias is optional. |
| 1891 | bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias && |
| 1892 | !m_Parameters.m_ProjectionEnabled) |
| 1893 | || (m_ProjectionWeights && !m_ProjectionBias && |
| 1894 | m_Parameters.m_ProjectionEnabled) |
| 1895 | || (m_ProjectionWeights && m_ProjectionBias && |
| 1896 | m_Parameters.m_ProjectionEnabled)); |
| 1897 | if (!projecton_tensors_consistent) |
| 1898 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1899 | throw InvalidArgumentException(descriptorName + ": Projection tensors are inconsistent."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | // The four layer normalization weights either all have values or none of them have values. Additionally, if |
| 1903 | // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights |
| 1904 | // either all have values or none of them have values. Layer normalization is used when the values of all the |
| 1905 | // layer normalization weights are present |
| 1906 | if (m_InputLayerNormWeights) |
| 1907 | { |
| 1908 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights"); |
| 1909 | } |
| 1910 | if (m_ForgetLayerNormWeights) |
| 1911 | { |
| 1912 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1913 | } |
| 1914 | if (m_CellLayerNormWeights) |
| 1915 | { |
| 1916 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1917 | } |
| 1918 | if (m_OutputLayerNormWeights) |
| 1919 | { |
| 1920 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1921 | } |
| 1922 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1923 | if (m_Parameters.m_LayerNormEnabled) |
| 1924 | { |
| 1925 | if (!m_Parameters.m_CifgEnabled) |
| 1926 | { |
| 1927 | if (!m_InputLayerNormWeights) |
| 1928 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1929 | throw InvalidArgumentException(descriptorName + ": Layer normalisation is enabled and CIFG-LSTM is " |
| 1930 | "disabled but InputLayerNormWeights are not present"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1931 | } |
| 1932 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), |
| 1933 | 1, n_cell, "InputLayerNormWeights"); |
| 1934 | } |
| 1935 | else if (m_InputLayerNormWeights) |
| 1936 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1937 | throw InvalidArgumentException(descriptorName + ":InputLayerNormWeights are present while CIFG is " |
| 1938 | "enabled"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1942 | "ForgetLayerNormWeights"); |
| 1943 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1944 | |
| 1945 | ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1946 | "OutputLayerNormWeights"); |
| 1947 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1948 | |
| 1949 | ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1950 | "CellLayerNormWeights"); |
| 1951 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1952 | } |
| 1953 | else if (m_InputLayerNormWeights || m_ForgetLayerNormWeights || m_OutputLayerNormWeights || m_CellLayerNormWeights) |
| 1954 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1955 | throw InvalidArgumentException(descriptorName + ": Layer normalisation is disabled but one or more layer " |
| 1956 | "normalisation weights are present."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1957 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1961 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1962 | const std::string descriptorName{"ConvertFp32ToFp16QueueDescriptor"}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1963 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1964 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1965 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1966 | |
| 1967 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1968 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1969 | |
| 1970 | if (inputTensorInfo.GetDataType() != DataType::Float32) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1971 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1972 | throw InvalidArgumentException(descriptorName + ": Input tensor type must be Float32."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1973 | } |
| 1974 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1975 | if (outputTensorInfo.GetDataType() != DataType::Float16) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1976 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1977 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Float16."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1978 | } |
| 1979 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1980 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1984 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1985 | const std::string descriptorName{"ConvertFp16ToFp32QueueDescriptor"}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1986 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1987 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1988 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1989 | |
| 1990 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1991 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1992 | |
| 1993 | if (inputTensorInfo.GetDataType() != DataType::Float16) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1994 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1995 | throw InvalidArgumentException(descriptorName + ": Input tensor type must be Float16."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1996 | } |
| 1997 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1998 | if (outputTensorInfo.GetDataType() != DataType::Float32) |
| 1999 | { |
| 2000 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Float32."); |
| 2001 | } |
| 2002 | |
| 2003 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 2004 | } |
| 2005 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 2006 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2007 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2008 | const std::string descriptorName{"DivisionQueueDescriptor"}; |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 2009 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2010 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2011 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2012 | |
| 2013 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2014 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2015 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2016 | |
| 2017 | std::vector<DataType> supportedTypes = |
| 2018 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2019 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2020 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 2021 | DataType::QuantisedSymm16, |
| 2022 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2023 | }; |
| 2024 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2025 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2026 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 2027 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2028 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2029 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2030 | inputTensorInfo1, |
| 2031 | outputTensorInfo, |
| 2032 | descriptorName, |
| 2033 | "input_0", |
| 2034 | "input_1"); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 2035 | } |
| 2036 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 2037 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2038 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2039 | const std::string descriptorName{"SubtractionQueueDescriptor"}; |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 2040 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2041 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2042 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2043 | |
| 2044 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2045 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2046 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2047 | |
| 2048 | std::vector<DataType> supportedTypes = |
| 2049 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2050 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2051 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 2052 | DataType::QuantisedSymm16, |
| 2053 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2054 | }; |
| 2055 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2056 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2057 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 2058 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2059 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2060 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2061 | inputTensorInfo1, |
| 2062 | outputTensorInfo, |
| 2063 | descriptorName, |
| 2064 | "input_0", |
| 2065 | "input_1"); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 2068 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2069 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2070 | const std::string descriptorName{"MaximumQueueDescriptor"}; |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 2071 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2072 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2073 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2074 | |
| 2075 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2076 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2077 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2078 | |
| 2079 | std::vector<DataType> supportedTypes = |
| 2080 | { |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2081 | DataType::Float16, |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2082 | DataType::Float32, |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2083 | DataType::Signed32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2084 | DataType::QuantisedAsymm8, |
| 2085 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2086 | }; |
| 2087 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2088 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2089 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 2090 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2091 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2092 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2093 | inputTensorInfo1, |
| 2094 | outputTensorInfo, |
| 2095 | descriptorName, |
| 2096 | "input_0", |
| 2097 | "input_1"); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 2100 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2101 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2102 | const std::string descriptorName{"MeanQueueDescriptor"}; |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 2103 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2104 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2105 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2106 | |
| 2107 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2108 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 2109 | |
| 2110 | std::vector<DataType> supportedTypes = |
| 2111 | { |
| 2112 | DataType::Float32, |
| 2113 | DataType::Float16, |
| 2114 | DataType::QuantisedAsymm8, |
| 2115 | DataType::QuantisedSymm16 |
| 2116 | }; |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2117 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 2118 | // First check if input tensor data type is supported, then |
| 2119 | // check if this data type matches the output tensor data type |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2120 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2121 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 2122 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 2123 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2124 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2125 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, inputTensorInfo.GetNumDimensions(), "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2126 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 2127 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2128 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2129 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 1, "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2130 | } |
| 2131 | else |
| 2132 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2133 | unsigned int outputDim = |
| 2134 | inputTensorInfo.GetNumDimensions() - boost::numeric_cast<unsigned int>(m_Parameters.m_Axis.size()); |
| 2135 | ValidateTensorNumDimensions(outputTensorInfo, |
| 2136 | descriptorName, |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 2137 | outputDim > 0 ? outputDim : 1, |
| 2138 | "output"); |
| 2139 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 2142 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2143 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2144 | const std::string descriptorName{"PadQueueDescriptor"}; |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 2145 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2146 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2147 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2148 | |
| 2149 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2150 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 2151 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 2152 | // input and output should have the same number of dimensions |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2153 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, inputTensorInfo.GetNumDimensions(), "output"); |
| 2154 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 2155 | // there should be entry in the pad list for each dimension in the input tensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2156 | if (m_Parameters.m_PadList.size() != inputTensorInfo.GetNumDimensions()) { |
| 2157 | throw InvalidArgumentException(descriptorName + ":Pad List should contain the same number of entries " |
| 2158 | "as there are dimensions in the input tensor that is " + |
| 2159 | std::to_string(inputTensorInfo.GetNumDimensions()) + " entries " + |
| 2160 | " not " + std::to_string(m_Parameters.m_PadList.size()) + " entries."); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2164 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2165 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2166 | const std::string descriptorName{"QuantizeQueueDescriptor"}; |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2167 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2168 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2169 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2170 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2171 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2172 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2173 | |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2174 | std::vector<DataType> supportedTypes = |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2175 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2176 | DataType::Float32, |
| 2177 | DataType::Float16 |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2178 | }; |
| 2179 | |
| 2180 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2181 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2182 | if (outputTensorInfo.GetDataType() != DataType::QuantisedAsymm8 && |
| 2183 | outputTensorInfo.GetDataType() != DataType::QuantisedSymm16) |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2184 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2185 | throw InvalidArgumentException(descriptorName + ": Output of quantized layer must be quantized type."); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 2189 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2190 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2191 | const std::string descriptorName{"BatchToSpaceNdQueueDescriptor"}; |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 2192 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2193 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2194 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 2195 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2196 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2197 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 2198 | |
| 2199 | std::vector<DataType> supportedTypes = |
| 2200 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2201 | DataType::Float32, |
| 2202 | DataType::Float16, |
| 2203 | DataType::QuantisedAsymm8, |
| 2204 | DataType::QuantisedSymm16 |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 2205 | }; |
| 2206 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2207 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2208 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2211 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2212 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2213 | const std::string descriptorName{"StridedSliceQueueDescriptor"}; |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2214 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2215 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2216 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2217 | |
| 2218 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2219 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 2220 | |
| 2221 | std::vector<DataType> supportedTypes = |
| 2222 | { |
| 2223 | DataType::Float16, |
| 2224 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 2225 | DataType::QuantisedAsymm8, |
| 2226 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 2227 | }; |
| 2228 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2229 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2230 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 2231 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2232 | ValidateTensorQuantizationSpace(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 2233 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2234 | const uint32_t rank = inputTensorInfo.GetNumDimensions(); |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 2235 | if (rank > 4) |
| 2236 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2237 | throw InvalidArgumentException(descriptorName + ": Input tensors with rank greater than 4 are not supported."); |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2240 | // Begin, End & Stride length must be of rank(input0) |
| 2241 | if (m_Parameters.m_Begin.size() != rank) |
| 2242 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2243 | throw InvalidArgumentException(descriptorName + ": Begin length must be of rank " + std::to_string(rank)); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | if (m_Parameters.m_End.size() != rank) |
| 2247 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2248 | throw InvalidArgumentException(descriptorName + ": End length must be of rank " + std::to_string(rank)); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | if (m_Parameters.m_Stride.size() != rank) |
| 2252 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2253 | throw InvalidArgumentException(descriptorName + ": Stride length must be of rank " + std::to_string(rank)); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | // Stride entries must be non-zero |
| 2257 | for (auto& stride : m_Parameters.m_Stride) |
| 2258 | { |
| 2259 | if (stride == 0) |
| 2260 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2261 | throw InvalidArgumentException(descriptorName + ": Stride entries must be non-zero."); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2266 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2267 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2268 | const std::string descriptorName{"MinimumQueueDescriptor"}; |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2269 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2270 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2271 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2272 | |
| 2273 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2274 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2275 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2276 | |
| 2277 | std::vector<DataType> supportedTypes = |
| 2278 | { |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2279 | DataType::Float16, |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2280 | DataType::Float32, |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2281 | DataType::Signed32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2282 | DataType::QuantisedAsymm8, |
| 2283 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2284 | }; |
| 2285 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2286 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2287 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 2288 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2289 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2290 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2291 | inputTensorInfo1, |
| 2292 | outputTensorInfo, |
| 2293 | descriptorName, |
| 2294 | "input_0", |
| 2295 | "input_1"); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 2298 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2299 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2300 | const std::string descriptorName{"DebugQueueDescriptor"}; |
| 2301 | |
| 2302 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2303 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2306 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2307 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2308 | const std::string descriptorName{"EqualQueueDescriptor"}; |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2309 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2310 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2311 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2312 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2313 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2314 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2315 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2316 | |
| 2317 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2318 | inputTensorInfo1, |
| 2319 | outputTensorInfo, |
| 2320 | descriptorName, |
| 2321 | "input_0", |
| 2322 | "input_1"); |
| 2323 | |
| 2324 | if (outputTensorInfo.GetDataType() != DataType::Boolean) |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2325 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2326 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Boolean."); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2327 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2330 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2331 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2332 | const std::string descriptorName{"GreaterQueueDescriptor"}; |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2333 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2334 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2335 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2336 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2337 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2338 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2339 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2340 | |
| 2341 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2342 | inputTensorInfo1, |
| 2343 | outputTensorInfo, |
| 2344 | descriptorName, |
| 2345 | "input_0", |
| 2346 | "input_1"); |
| 2347 | |
| 2348 | if (outputTensorInfo.GetDataType() != DataType::Boolean) |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2349 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2350 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Boolean."); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2351 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 2354 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2355 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2356 | const std::string descriptorName{"RsqrtQueueDescriptor"}; |
| 2357 | |
| 2358 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2359 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2360 | |
| 2361 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2362 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2363 | |
| 2364 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 2365 | |
| 2366 | std::vector<DataType> supportedTypes = |
| 2367 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2368 | DataType::Float16, |
| 2369 | DataType::Float32, |
| 2370 | DataType::QuantisedAsymm8, |
| 2371 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 2372 | }; |
| 2373 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2374 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2375 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 2376 | } |
| 2377 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2378 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2379 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2380 | const std::string descriptorName{"GatherQueueDescriptor"}; |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2381 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2382 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2383 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2384 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2385 | const TensorInfo& indicesTensorInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2386 | if (indicesTensorInfo.GetDataType() != DataType::Signed32) |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2387 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2388 | throw InvalidArgumentException(descriptorName + ": Indices tensor type must be Int32."); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2391 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2392 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2393 | |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2394 | std::vector<DataType> supportedTypes = |
| 2395 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2396 | DataType::Float16, |
| 2397 | DataType::Float32, |
| 2398 | DataType::QuantisedAsymm8, |
| 2399 | DataType::QuantisedSymm16 |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2400 | }; |
| 2401 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2402 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2403 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2404 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2405 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2406 | unsigned int outputDim = inputTensorInfo.GetNumDimensions() + indicesTensorInfo.GetNumDimensions() - 1; |
| 2407 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2410 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2411 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2412 | const std::string& descriptorName{"DetectionPostProcessQueueDescriptor"}; |
| 2413 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2414 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2415 | |
| 2416 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 2417 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2418 | throw InvalidArgumentException(descriptorName + ": Requires exactly four outputs. " + |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2419 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 2420 | } |
| 2421 | |
| 2422 | if (m_Anchors == nullptr) |
| 2423 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2424 | throw InvalidArgumentException(descriptorName + ": Anchors tensor descriptor is missing."); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2428 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2429 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 2430 | |
| 2431 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 2432 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2433 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
| 2434 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2435 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2436 | ValidateTensorNumDimensions(boxEncodingsInfo, descriptorName, 3, "box encodings"); |
| 2437 | ValidateTensorNumDimensions(scoresInfo, descriptorName, 3, "scores"); |
| 2438 | ValidateTensorNumDimensions(anchorsInfo, descriptorName, 2, "anchors"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2439 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2440 | const std::vector<DataType> supportedInputTypes = |
| 2441 | { |
| 2442 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2443 | DataType::Float16, |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2444 | DataType::QuantisedAsymm8, |
| 2445 | DataType::QuantisedSymm16 |
| 2446 | }; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2447 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2448 | ValidateDataTypes(boxEncodingsInfo, supportedInputTypes, descriptorName); |
| 2449 | ValidateDataTypes(scoresInfo, supportedInputTypes, descriptorName); |
| 2450 | ValidateDataTypes(anchorsInfo, supportedInputTypes, descriptorName); |
| 2451 | |
| 2452 | ValidateTensorNumDimensions(detectionBoxesInfo, descriptorName, 3, "detection boxes"); |
| 2453 | ValidateTensorNumDimensions(detectionScoresInfo, descriptorName, 2, "detection scores"); |
| 2454 | ValidateTensorNumDimensions(detectionClassesInfo, descriptorName, 2, "detection classes"); |
| 2455 | ValidateTensorNumDimensions(numDetectionsInfo, descriptorName, 1, "num detections"); |
| 2456 | |
| 2457 | // NOTE: Output is always Float32 regardless of input type |
| 2458 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, descriptorName, "detection boxes"); |
| 2459 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, descriptorName, "detection scores"); |
| 2460 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, descriptorName, "detection classes"); |
| 2461 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, descriptorName, "num detections"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2462 | |
| 2463 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 2464 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2465 | throw InvalidArgumentException(descriptorName + ": Intersection over union threshold " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2466 | "must be positive and less than or equal to 1."); |
| 2467 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2468 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2469 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 2470 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2471 | throw InvalidArgumentException(descriptorName + ": Number of classes with background " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2472 | "should be equal to number of classes + 1."); |
| 2473 | } |
| 2474 | } |
| 2475 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2476 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2477 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2478 | const std::string& descriptorName{"DequantizeQueueDescriptor"}; |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2479 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2480 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2481 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2482 | |
| 2483 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2484 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2485 | |
| 2486 | if (inputTensorInfo.GetDataType() != DataType::QuantisedAsymm8 && |
Sadik Armagan | cf7c1c6 | 2019-11-20 16:18:55 +0000 | [diff] [blame] | 2487 | inputTensorInfo.GetDataType() != DataType::QuantisedSymm8 && |
| 2488 | inputTensorInfo.GetDataType() != DataType::QuantizedSymm8PerAxis && |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2489 | inputTensorInfo.GetDataType() != DataType::QuantisedSymm16) |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2490 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2491 | throw InvalidArgumentException(descriptorName + ": Input to dequantize layer must be quantized type."); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2494 | std::vector<DataType> supportedTypes = |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2495 | { |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2496 | DataType::Float32, |
| 2497 | DataType::Float16 |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2498 | }; |
| 2499 | |
| 2500 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2503 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2504 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2505 | const std::string& descriptorName{"MergeQueueDescriptor"}; |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2506 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2507 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2508 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2509 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2510 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2511 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2512 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2513 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2514 | ValidateTensorShapesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 2515 | ValidateTensorShapesMatch(inputTensorInfo0, outputTensorInfo, descriptorName, "input_0", "output"); |
| 2516 | |
| 2517 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 2518 | ValidateTensorDataTypesMatch(inputTensorInfo0, outputTensorInfo, descriptorName, "input_0", "output"); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2519 | } |
| 2520 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2521 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2522 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2523 | const std::string& descriptorName{"SwitchQueueDescriptor"}; |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2524 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2525 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2526 | ValidateNumOutputs(workloadInfo, descriptorName, 2); |
| 2527 | |
| 2528 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2529 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2530 | |
| 2531 | const TensorInfo& outputTensorInfo0 = workloadInfo.m_OutputTensorInfos[0]; |
| 2532 | const TensorInfo& outputTensorInfo1 = workloadInfo.m_OutputTensorInfos[1]; |
| 2533 | |
| 2534 | std::vector<DataType> supportedTypes = |
| 2535 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2536 | DataType::Float32, |
| 2537 | DataType::QuantisedAsymm8, |
| 2538 | DataType::QuantisedSymm16 |
| 2539 | }; |
| 2540 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2541 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2542 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2543 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2544 | ValidateDataTypes(outputTensorInfo0, supportedTypes, descriptorName); |
| 2545 | ValidateDataTypes(outputTensorInfo1, supportedTypes, descriptorName); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2546 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2547 | ValidateTensorShapesMatch(inputTensorInfo0, |
| 2548 | outputTensorInfo0, |
| 2549 | descriptorName, |
| 2550 | "input_0", |
| 2551 | "output_0"); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2552 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2553 | ValidateTensorShapesMatch(inputTensorInfo0, |
| 2554 | outputTensorInfo1, |
| 2555 | descriptorName, |
| 2556 | "input_0", |
| 2557 | "output_1"); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2558 | } |
| 2559 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 2560 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2561 | { |
| 2562 | // This is internally generated so it should not need validation. |
| 2563 | } |
| 2564 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2565 | void PreluQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2566 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2567 | const std::string& descriptorName{"PreluQueueDescriptor"}; |
| 2568 | |
| 2569 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2570 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2571 | |
| 2572 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2573 | const TensorInfo& alphaTensorInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2574 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2575 | |
| 2576 | std::vector<DataType> supportedTypes |
| 2577 | { |
| 2578 | DataType::Float16, |
| 2579 | DataType::Float32, |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2580 | DataType::QuantisedAsymm8, |
| 2581 | DataType::QuantisedSymm16 |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2582 | }; |
| 2583 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2584 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2585 | ValidateDataTypes(alphaTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2586 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2587 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2588 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2589 | ValidateTensorDataTypesMatch(inputTensorInfo, alphaTensorInfo, descriptorName, "input", "alpha"); |
| 2590 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "ouptut"); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2591 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2592 | ValidateBroadcastTensorShapesMatch(inputTensorInfo, |
| 2593 | alphaTensorInfo, |
| 2594 | outputTensorInfo, |
| 2595 | descriptorName, |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2596 | "input", |
| 2597 | "alpha"); |
| 2598 | } |
| 2599 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2600 | void TransposeConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2601 | { |
| 2602 | const std::string descriptorName{"TransposeConvolution2dQueueDescriptor"}; |
| 2603 | |
| 2604 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2605 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2606 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2607 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2608 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2609 | |
| 2610 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 2611 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2612 | |
| 2613 | ValidatePointer(m_Weight, descriptorName, "weight"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2614 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2615 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 2616 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2617 | |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2618 | ValidateWeightDataType(inputTensorInfo, weightTensorInfo, descriptorName); |
| 2619 | |
| 2620 | Optional<TensorInfo> optionalBiasTensorInfo; |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2621 | if (m_Parameters.m_BiasEnabled) |
| 2622 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2623 | ValidatePointer(m_Bias, descriptorName, "bias"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2624 | |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2625 | optionalBiasTensorInfo = MakeOptional<TensorInfo>(m_Bias->GetTensorInfo()); |
| 2626 | const TensorInfo& biasTensorInfo = optionalBiasTensorInfo.value(); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2627 | |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2628 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2629 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2630 | } |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2631 | |
| 2632 | ValidatePerAxisQuantization(inputTensorInfo, |
| 2633 | outputTensorInfo, |
| 2634 | weightTensorInfo, |
| 2635 | optionalBiasTensorInfo, |
| 2636 | descriptorName); |
| 2637 | |
| 2638 | std::vector<DataType> supportedTypes = |
| 2639 | { |
| 2640 | DataType::Float32, |
| 2641 | DataType::Float16, |
| 2642 | DataType::QuantisedAsymm8, |
| 2643 | DataType::QuantisedSymm16 |
| 2644 | }; |
| 2645 | |
| 2646 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2647 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2648 | } |
| 2649 | |
James Conroy | 9c3cae8 | 2019-08-01 16:01:48 +0100 | [diff] [blame] | 2650 | void QuantizedLstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2651 | { |
| 2652 | const std::string descriptorName{"QuantizedLstmQueueDescriptor"}; |
| 2653 | |
| 2654 | // Validate number of inputs/outputs |
| 2655 | ValidateNumInputs(workloadInfo, descriptorName, 3); |
| 2656 | ValidateNumOutputs(workloadInfo, descriptorName, 2); |
| 2657 | |
| 2658 | // Input/output tensor infos |
| 2659 | auto inputInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2660 | auto cellStateInInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2661 | auto outputStateInInfo = workloadInfo.m_InputTensorInfos[2]; |
| 2662 | |
| 2663 | auto cellStateOutInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2664 | auto outputStateOutInfo = workloadInfo.m_OutputTensorInfos[1]; |
| 2665 | |
| 2666 | std::vector<DataType> inputOutputSupportedTypes = |
| 2667 | { |
| 2668 | DataType::QuantisedAsymm8 |
| 2669 | }; |
| 2670 | |
| 2671 | std::vector<DataType> cellStateSupportedTypes = |
| 2672 | { |
| 2673 | DataType::QuantisedSymm16 |
| 2674 | }; |
| 2675 | |
| 2676 | std::vector<DataType> weightsSupportedTypes = |
| 2677 | { |
| 2678 | DataType::QuantisedAsymm8 |
| 2679 | }; |
| 2680 | |
| 2681 | std::vector<DataType> biasSupportedTypes = |
| 2682 | { |
| 2683 | DataType::Signed32 |
| 2684 | }; |
| 2685 | |
| 2686 | // Validate types of input/output tensors |
| 2687 | ValidateDataTypes(inputInfo, inputOutputSupportedTypes, descriptorName); |
| 2688 | ValidateDataTypes(cellStateInInfo, cellStateSupportedTypes, descriptorName); |
| 2689 | ValidateDataTypes(outputStateInInfo, inputOutputSupportedTypes, descriptorName); |
| 2690 | |
| 2691 | ValidateDataTypes(cellStateOutInfo, cellStateSupportedTypes, descriptorName); |
| 2692 | ValidateDataTypes(outputStateOutInfo, inputOutputSupportedTypes, descriptorName); |
| 2693 | |
| 2694 | // Validate matching types of input/output tensors |
| 2695 | ValidateTensorDataTypesMatch(inputInfo, outputStateInInfo, descriptorName, "input", "outputStateIn"); |
| 2696 | ValidateTensorDataTypesMatch(outputStateInInfo, outputStateOutInfo, descriptorName, |
| 2697 | "outputStateIn", "outputStateOut"); |
| 2698 | ValidateTensorDataTypesMatch(cellStateInInfo, cellStateOutInfo, descriptorName, "cellStateIn", "cellStateOut"); |
| 2699 | |
| 2700 | // Validate matching quantization info for input/output tensors |
| 2701 | ValidateTensorQuantizationSpace(inputInfo, outputStateInInfo, descriptorName, "input", "outputStateIn"); |
| 2702 | ValidateTensorQuantizationSpace(inputInfo, outputStateOutInfo, descriptorName, "input", "outputStateOut"); |
| 2703 | ValidateTensorQuantizationSpace(cellStateInInfo, cellStateOutInfo, descriptorName, "cellStateIn", "cellStateOut"); |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 2704 | |
James Conroy | 9c3cae8 | 2019-08-01 16:01:48 +0100 | [diff] [blame] | 2705 | // Infer number of batches, input size and output size from tensor dimensions |
| 2706 | const uint32_t numBatches = inputInfo.GetShape()[0]; |
| 2707 | const uint32_t inputSize = inputInfo.GetShape()[1]; |
| 2708 | const uint32_t outputSize = cellStateInInfo.GetShape()[1]; |
| 2709 | |
| 2710 | // Validate number of dimensions and number of elements for input/output tensors |
| 2711 | ValidateTensorNumDimNumElem(inputInfo, 2, (numBatches * inputSize), descriptorName + " input"); |
| 2712 | ValidateTensorNumDimNumElem(cellStateInInfo, 2, (numBatches * outputSize), descriptorName + " cellStateIn"); |
| 2713 | ValidateTensorNumDimNumElem(outputStateInInfo, 2, (numBatches * outputSize), descriptorName + " outputStateIn"); |
| 2714 | ValidateTensorNumDimNumElem(cellStateOutInfo, 2, (numBatches * outputSize), descriptorName + " cellStateOut"); |
| 2715 | ValidateTensorNumDimNumElem(outputStateOutInfo, 2, (numBatches * outputSize), descriptorName + " outputStateOut"); |
| 2716 | |
| 2717 | // Validate number of dimensions and number of elements for weights tensors |
| 2718 | ValidatePointer(m_InputToInputWeights, descriptorName, "InputToInputWeights"); |
| 2719 | auto inputToInputWeightsInfo = m_InputToInputWeights->GetTensorInfo(); |
| 2720 | ValidateTensorNumDimNumElem(inputToInputWeightsInfo, 2, (outputSize * inputSize), " InputToInputWeights"); |
| 2721 | |
| 2722 | ValidatePointer(m_InputToForgetWeights, descriptorName, "InputToForgetWeights"); |
| 2723 | auto inputToForgetWeightsInfo = m_InputToForgetWeights->GetTensorInfo(); |
| 2724 | ValidateTensorNumDimNumElem(inputToForgetWeightsInfo, 2, (outputSize * inputSize), " InputToForgetWeights"); |
| 2725 | |
| 2726 | ValidatePointer(m_InputToCellWeights, descriptorName, "InputToCellWeights"); |
| 2727 | auto inputToCellWeightsInfo = m_InputToCellWeights->GetTensorInfo(); |
| 2728 | ValidateTensorNumDimNumElem(inputToCellWeightsInfo, 2, (outputSize * inputSize), " InputToCellWeights"); |
| 2729 | |
| 2730 | ValidatePointer(m_InputToOutputWeights, descriptorName, "InputToOutputWeights"); |
| 2731 | auto inputToOutputWeightsInfo = m_InputToOutputWeights->GetTensorInfo(); |
| 2732 | ValidateTensorNumDimNumElem(inputToOutputWeightsInfo, 2, (outputSize * inputSize), " InputToOutputWeights"); |
| 2733 | |
| 2734 | ValidatePointer(m_RecurrentToInputWeights, descriptorName, "RecurrentToInputWeights"); |
| 2735 | auto recurrentToInputWeightsInfo = m_RecurrentToInputWeights->GetTensorInfo(); |
| 2736 | ValidateTensorNumDimNumElem(recurrentToInputWeightsInfo, 2, (outputSize * outputSize), " RecurrentToInputWeights"); |
| 2737 | |
| 2738 | ValidatePointer(m_RecurrentToForgetWeights, descriptorName, "RecurrentToForgetWeights"); |
| 2739 | auto recurrentToForgetWeightsInfo = m_RecurrentToForgetWeights->GetTensorInfo(); |
| 2740 | ValidateTensorNumDimNumElem(recurrentToForgetWeightsInfo, 2, (outputSize * outputSize), |
| 2741 | " RecurrentToForgetWeights"); |
| 2742 | |
| 2743 | ValidatePointer(m_RecurrentToCellWeights, descriptorName, "RecurrentToCellWeights"); |
| 2744 | auto recurrentToCellWeightsInfo = m_RecurrentToCellWeights->GetTensorInfo(); |
| 2745 | ValidateTensorNumDimNumElem(recurrentToCellWeightsInfo, 2, (outputSize * outputSize), " RecurrentToCellWeights"); |
| 2746 | |
| 2747 | ValidatePointer(m_RecurrentToOutputWeights, descriptorName, "RecurrentToOutputWeights"); |
| 2748 | auto recurrentToOutputWeightsInfo = m_RecurrentToOutputWeights->GetTensorInfo(); |
| 2749 | ValidateTensorNumDimNumElem(recurrentToOutputWeightsInfo, 2, (outputSize * outputSize), " RecurrentToCellWeights"); |
| 2750 | |
| 2751 | // Validate data types for weights tensors (all should match each other) |
| 2752 | ValidateDataTypes(inputToInputWeightsInfo, weightsSupportedTypes, descriptorName); |
| 2753 | |
| 2754 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToForgetWeightsInfo, descriptorName, |
| 2755 | "inputToInputWeights", "inputToForgetWeights"); |
| 2756 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToCellWeightsInfo, descriptorName, |
| 2757 | "inputToInputWeights", "inputToCellWeights"); |
| 2758 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToOutputWeightsInfo, descriptorName, |
| 2759 | "inputToInputWeights", "inputToOutputWeights"); |
| 2760 | |
| 2761 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToInputWeightsInfo, descriptorName, |
| 2762 | "inputToInputWeights", "recurrentToInputWeights"); |
| 2763 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToForgetWeightsInfo, descriptorName, |
| 2764 | "inputToInputWeights", "recurrentToForgeteights"); |
| 2765 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToCellWeightsInfo, descriptorName, |
| 2766 | "inputToInputWeights", "recurrentToCellWeights"); |
| 2767 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToOutputWeightsInfo, descriptorName, |
| 2768 | "inputToInputWeights", "recurrentToOutputWeights"); |
| 2769 | |
| 2770 | // Validate matching quantization info for weight tensors (all should match each other) |
| 2771 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToForgetWeightsInfo, |
| 2772 | descriptorName, "inputToInputWeights", "inputToForgetWeights"); |
| 2773 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToCellWeightsInfo, |
| 2774 | descriptorName, "inputToInputWeights", "inputToCellWeights"); |
| 2775 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToOutputWeightsInfo, |
| 2776 | descriptorName, "inputToInputWeights", "inputToOutputWeights"); |
| 2777 | |
| 2778 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToInputWeightsInfo, |
| 2779 | descriptorName, "inputToInputWeights", "recurrentToInputWeights"); |
| 2780 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToForgetWeightsInfo, |
| 2781 | descriptorName, "inputToInputWeights", "recurrentToForgetWeights"); |
| 2782 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToCellWeightsInfo, |
| 2783 | descriptorName, "inputToInputWeights", "recurrentToCellWeights"); |
| 2784 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToOutputWeightsInfo, |
| 2785 | descriptorName, "inputToInputWeights", "recurrentToOutputWeights"); |
| 2786 | |
| 2787 | // Validate number of dimensions and number of elements in bias tensors |
| 2788 | ValidatePointer(m_InputGateBias, descriptorName, "InputGateBias"); |
| 2789 | auto inputGateBiasInfo = m_InputGateBias->GetTensorInfo(); |
| 2790 | ValidateTensorNumDimNumElem(inputGateBiasInfo, 1, outputSize, " InputGateBias"); |
| 2791 | |
| 2792 | ValidatePointer(m_ForgetGateBias, descriptorName, "ForgetGateBias"); |
| 2793 | auto forgetGateBiasInfo = m_ForgetGateBias->GetTensorInfo(); |
| 2794 | ValidateTensorNumDimNumElem(forgetGateBiasInfo, 1, outputSize, " ForgetGateBias"); |
| 2795 | |
| 2796 | ValidatePointer(m_CellBias, descriptorName, "CellBias"); |
| 2797 | auto cellBiasInfo = m_CellBias->GetTensorInfo(); |
| 2798 | ValidateTensorNumDimNumElem(cellBiasInfo, 1, outputSize, " CellBias"); |
| 2799 | |
| 2800 | ValidatePointer(m_OutputGateBias, descriptorName, "OutputGateBias"); |
| 2801 | auto outputGateBiasInfo = m_OutputGateBias->GetTensorInfo(); |
| 2802 | ValidateTensorNumDimNumElem(outputGateBiasInfo, 1, outputSize, " OutputGateBias"); |
| 2803 | |
| 2804 | // Validate data types for bias tensors (all should match each other) |
| 2805 | ValidateDataTypes(inputGateBiasInfo, biasSupportedTypes, descriptorName); |
| 2806 | |
| 2807 | ValidateTensorDataTypesMatch(inputGateBiasInfo, forgetGateBiasInfo, descriptorName, |
| 2808 | "inputGateBias", "forgetGateBias"); |
| 2809 | ValidateTensorDataTypesMatch(inputGateBiasInfo, cellBiasInfo, descriptorName, |
| 2810 | "inputGateBias", "cellBias"); |
| 2811 | ValidateTensorDataTypesMatch(inputGateBiasInfo, outputGateBiasInfo, descriptorName, |
| 2812 | "inputGateBias", "outputGateBias"); |
| 2813 | |
| 2814 | // Validate bias tensor quantization info |
| 2815 | ValidateBiasTensorQuantization(inputGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2816 | ValidateBiasTensorQuantization(forgetGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2817 | ValidateBiasTensorQuantization(cellBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2818 | ValidateBiasTensorQuantization(outputGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2819 | } |
| 2820 | |
Kevin May | 868eb14 | 2019-09-04 17:29:31 +0100 | [diff] [blame] | 2821 | void AbsQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2822 | { |
| 2823 | const std::string descriptorName{"AbsQueueDescriptor"}; |
| 2824 | |
| 2825 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2826 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2827 | |
| 2828 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2829 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2830 | |
| 2831 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 2832 | |
| 2833 | std::vector<DataType> supportedTypes = |
James Conroy | d47a064 | 2019-09-17 14:22:06 +0100 | [diff] [blame] | 2834 | { |
| 2835 | DataType::Float16, |
| 2836 | DataType::Float32, |
| 2837 | DataType::QuantisedAsymm8, |
| 2838 | DataType::QuantisedSymm16 |
| 2839 | }; |
Kevin May | 868eb14 | 2019-09-04 17:29:31 +0100 | [diff] [blame] | 2840 | |
| 2841 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2842 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 2843 | } |
| 2844 | |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 2845 | void SliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2846 | { |
| 2847 | const std::string descriptorName{"SliceQueueDescriptor"}; |
| 2848 | |
| 2849 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2850 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2851 | |
| 2852 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2853 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2854 | |
| 2855 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 2856 | |
| 2857 | const unsigned int rank = inputTensorInfo.GetNumDimensions(); |
| 2858 | if (rank > 4) |
| 2859 | { |
| 2860 | throw InvalidArgumentException(descriptorName + ": Input tensors with rank greater than 4 are not supported."); |
| 2861 | } |
| 2862 | |
| 2863 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, rank, "output"); |
| 2864 | |
| 2865 | // Check if m_Begin and m_Size have the expected length |
| 2866 | if (m_Parameters.m_Begin.size() != rank) |
| 2867 | { |
| 2868 | throw InvalidArgumentException(descriptorName + |
| 2869 | ": Length of begin offset descriptor must equal rank " + std::to_string(rank)); |
| 2870 | } |
| 2871 | if (m_Parameters.m_Size.size() != rank) |
| 2872 | { |
| 2873 | throw InvalidArgumentException(descriptorName + |
| 2874 | ": Length of size descriptor must equal rank " + std::to_string(rank)); |
| 2875 | } |
| 2876 | |
| 2877 | // Check if the shape of the output tensor matches m_Size |
| 2878 | const TensorShape& outputShape = outputTensorInfo.GetShape(); |
| 2879 | for (unsigned int i = 0u; i < rank; ++i) |
| 2880 | { |
| 2881 | if (m_Parameters.m_Size[i] != outputShape[i]) |
| 2882 | { |
| 2883 | throw InvalidArgumentException(descriptorName + ": Size descriptor does not match output tensor."); |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | // Check if the sum of begin offset and size in a given dimension |
| 2888 | // does not exceed the size of corresponding input |
| 2889 | const TensorShape& inputShape = inputTensorInfo.GetShape(); |
| 2890 | for(unsigned int i = 0u; i < rank; ++i) |
| 2891 | { |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2892 | if (m_Parameters.m_Begin[i] + m_Parameters.m_Size[i] > inputShape[i]) |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 2893 | { |
| 2894 | throw InvalidArgumentException(descriptorName + ": Sum of begin offset and size for dimension " + |
| 2895 | std::to_string(i) + " exceeds input size."); |
| 2896 | } |
| 2897 | } |
| 2898 | } |
| 2899 | |
Aron Virginas-Tar | dd6247f | 2019-09-19 14:31:17 +0100 | [diff] [blame] | 2900 | void DepthToSpaceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2901 | { |
| 2902 | const std::string descriptorName{"DepthToSpaceQueueDescriptor"}; |
| 2903 | |
| 2904 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2905 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2906 | |
| 2907 | const TensorInfo& inputInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2908 | const TensorInfo& outputInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2909 | |
| 2910 | ValidateTensorNumDimensions(inputInfo, descriptorName, 4, "input"); |
| 2911 | ValidateTensorNumDimensions(outputInfo, descriptorName, 4, "output"); |
| 2912 | |
| 2913 | std::vector<DataType> supportedTypes = |
| 2914 | { |
| 2915 | DataType::Float32, |
| 2916 | DataType::Float16, |
| 2917 | DataType::QuantisedAsymm8, |
| 2918 | DataType::QuantisedSymm16 |
| 2919 | }; |
| 2920 | |
| 2921 | ValidateDataTypes(inputInfo, supportedTypes, descriptorName); |
| 2922 | ValidateDataTypes(outputInfo, supportedTypes, descriptorName); |
| 2923 | |
| 2924 | ValidateTensorNumElementsMatch(inputInfo, outputInfo, descriptorName, "input", "output"); |
| 2925 | |
| 2926 | if (m_Parameters.m_BlockSize == 0) |
| 2927 | { |
| 2928 | throw InvalidArgumentException(descriptorName + ": Block size cannot be 0."); |
| 2929 | } |
| 2930 | |
| 2931 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 2932 | const unsigned int wIndex = dimensionIndices.GetWidthIndex(); |
| 2933 | const unsigned int hIndex = dimensionIndices.GetHeightIndex(); |
| 2934 | const unsigned int cIndex = dimensionIndices.GetChannelsIndex(); |
| 2935 | |
| 2936 | const TensorShape& outputShape = outputInfo.GetShape(); |
| 2937 | if (outputShape[hIndex] % m_Parameters.m_BlockSize != 0 || outputShape[wIndex] % m_Parameters.m_BlockSize != 0) |
| 2938 | { |
| 2939 | throw InvalidArgumentException(descriptorName + ": Output width and height shape" |
| 2940 | "must be divisible by block size."); |
| 2941 | } |
| 2942 | |
| 2943 | const TensorShape& inputShape = inputInfo.GetShape(); |
| 2944 | if (inputShape[cIndex] % (m_Parameters.m_BlockSize * m_Parameters.m_BlockSize) != 0) |
| 2945 | { |
| 2946 | throw InvalidArgumentException(descriptorName + ": The depth of the input tensor" |
| 2947 | "must be divisible by the square of block size." ); |
| 2948 | } |
| 2949 | } |
| 2950 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 2951 | void ComparisonQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2952 | { |
| 2953 | const std::string descriptorName{"ComparisonQueueDescriptor"}; |
| 2954 | |
| 2955 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2956 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2957 | |
| 2958 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2959 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2960 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2961 | |
| 2962 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2963 | inputTensorInfo1, |
| 2964 | outputTensorInfo, |
| 2965 | descriptorName, |
| 2966 | "input_0", |
| 2967 | "input_1"); |
| 2968 | |
| 2969 | if (outputTensorInfo.GetDataType() != DataType::Boolean) |
| 2970 | { |
| 2971 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Boolean."); |
| 2972 | } |
| 2973 | } |
| 2974 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2975 | } // namespace armnn |