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