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