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