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