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