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