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