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