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