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