telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #include "WorkloadData.hpp" |
| 6 | |
| 7 | #include "CpuTensorHandle.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 9 | #include <DataLayoutIndexed.hpp> |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 10 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <algorithm> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 12 | #include <iomanip> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <sstream> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | #include <boost/format.hpp> |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 17 | #include <boost/numeric/conversion/cast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 19 | using namespace armnnUtils; |
| 20 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | //--------------------------------------------------------------- |
| 25 | DataType GetBiasDataType(DataType inputDataType) |
| 26 | { |
| 27 | switch (inputDataType) |
| 28 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | case DataType::Float16: |
| 30 | return DataType::Float16; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | case DataType::Float32: |
| 32 | return DataType::Float32; |
| 33 | case DataType::QuantisedAsymm8: |
| 34 | return DataType::Signed32; |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 35 | case DataType::QuantisedSymm16: |
| 36 | return DataType::Signed32; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | default: |
| 38 | BOOST_ASSERT_MSG(false, "Invalid input data type"); |
| 39 | return DataType::Float32; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | namespace |
| 44 | { |
| 45 | |
| 46 | //--------------------------------------------------------------- |
| 47 | //android ndk does not support std::to_string function. |
| 48 | template <typename T> |
| 49 | std::string to_string(T value) |
| 50 | { |
| 51 | std::ostringstream os; |
| 52 | os << value; |
| 53 | return os.str(); |
| 54 | } |
| 55 | |
| 56 | //--------------------------------------------------------------- |
| 57 | void ValidatePointer(const void* ptr, std::string const& descName, std::string const& paramName) |
| 58 | { |
| 59 | if (!ptr) |
| 60 | { |
| 61 | throw InvalidArgumentException(descName + ": Invalid null pointer. The " + |
| 62 | paramName + " parameter must be set."); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | //--------------------------------------------------------------- |
| 67 | void ValidateTensorShapesMatch(const TensorInfo& first, |
| 68 | const TensorInfo& second, |
| 69 | std::string const& descName, |
| 70 | std::string const& firstName, |
| 71 | std::string const& secondName) |
| 72 | { |
| 73 | if (first.GetShape() != second.GetShape()) |
| 74 | { |
| 75 | throw InvalidArgumentException(descName + ": " |
| 76 | + firstName + " & " + secondName + " must have identical shapes"); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 81 | void ValidateNumInputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 83 | if (workloadInfo.m_InputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 84 | { |
| 85 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 86 | ": Requires exactly " + to_string(expectedSize) + "input(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 87 | to_string(workloadInfo.m_InputTensorInfos.size()) + " have been provided."); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 92 | void ValidateNumOutputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 94 | if (workloadInfo.m_OutputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | { |
| 96 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 97 | ": Requires exactly " + to_string(expectedSize) + " output(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 98 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 103 | void ValidateTensorNumDimensions(const TensorInfo& tensor, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 104 | std::string const& descName, |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 105 | unsigned int numDimensions, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 106 | std::string const& tensorName) |
| 107 | { |
| 108 | if (tensor.GetNumDimensions() != numDimensions) |
| 109 | { |
| 110 | throw InvalidArgumentException(descName + ": Expected " + to_string(numDimensions) + " but got " + |
| 111 | to_string(tensor.GetNumDimensions()) + " dimensions for " + |
| 112 | tensorName + " tensor."); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 117 | void ValidateTensorNumElements(const TensorInfo& tensor, |
| 118 | std::string const& descName, |
| 119 | unsigned int numElements, |
| 120 | std::string const& tensorName) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 121 | { |
| 122 | if (tensor.GetNumElements() != numElements) |
| 123 | { |
| 124 | throw InvalidArgumentException(descName + ": Expected " + to_string(numElements) + " but got " + |
| 125 | to_string(tensor.GetNumDimensions()) + " elements for " + |
| 126 | tensorName + " tensor."); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | //--------------------------------------------------------------- |
| 131 | void ValidateTensorNumDimNumElem(const TensorInfo& tensorInfo, |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 132 | unsigned int numDimension, |
| 133 | unsigned int numElements, |
| 134 | std::string const& tensorName) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 135 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 136 | const std::string functionName{"ValidateTensorNumDimNumElem"}; |
| 137 | ValidateTensorNumDimensions(tensorInfo, functionName, numDimension, tensorName); |
| 138 | ValidateTensorNumElements(tensorInfo, functionName, numElements, tensorName); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 142 | void ValidateTensorDataType(const TensorInfo& tensor, DataType dataType, |
| 143 | const std::string& descName, std::string const& tensorName) |
| 144 | { |
| 145 | if (tensor.GetDataType() != dataType) |
| 146 | { |
| 147 | throw InvalidArgumentException(descName + ": Expected data type " + GetDataTypeName(dataType) + " but got " + |
| 148 | GetDataTypeName(tensor.GetDataType()) + " for " + tensorName + " tensor."); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | //--------------------------------------------------------------- |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 153 | void ValidateTensorQuantizationSpace(const TensorInfo& first, |
| 154 | const TensorInfo& second, |
| 155 | const std::string& descName, |
| 156 | std::string const& firstName, |
| 157 | std::string const& secondName) |
| 158 | { |
| 159 | if (!first.IsQuantized() || |
| 160 | !second.IsQuantized()) |
| 161 | { |
| 162 | // Not a quantized type, ignore the validation |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | DataType firstDataType = first.GetDataType(); |
| 167 | DataType secondDataType = second.GetDataType(); |
| 168 | |
| 169 | if (firstDataType != secondDataType) |
| 170 | { |
| 171 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 172 | " must be of the same quantized type, " + |
| 173 | firstName + " is " + GetDataTypeName(firstDataType) + ", " + |
| 174 | secondName + " is " + GetDataTypeName(secondDataType)); |
| 175 | } |
| 176 | |
| 177 | if (!first.IsTypeSpaceMatch(second)) |
| 178 | { |
| 179 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 180 | " must have the same quantization space, " + |
| 181 | firstName + " has offset " + to_string(first.GetQuantizationOffset()) + |
| 182 | " and scale " + to_string(first.GetQuantizationScale()) + ", " + |
| 183 | secondName + " has offset " + to_string(second.GetQuantizationOffset()) + |
| 184 | " and scale " + to_string(second.GetQuantizationScale())); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | //--------------------------------------------------------------- |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 189 | void ValidateBiasTensorQuantization(const TensorInfo& biasTensor, |
| 190 | const TensorInfo& inputTensorInfo, |
| 191 | const TensorInfo& weightsTensorInfo, |
| 192 | const std::string& descName) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 193 | { |
| 194 | if (biasTensor.GetQuantizationOffset() != 0) |
| 195 | { |
| 196 | throw InvalidArgumentException(descName + ": Expected zero quantization offset for bias tensor but got " + |
| 197 | to_string(biasTensor.GetQuantizationOffset())); |
| 198 | } |
| 199 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightsTensorInfo.GetQuantizationScale(); |
kevmay01 | 6c46dd3 | 2018-12-17 15:32:45 +0000 | [diff] [blame] | 200 | if (std::abs(biasTensor.GetQuantizationScale() - expectedScale) > 0.00000001f) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 201 | { |
| 202 | // Print the float values with extra precision to see very small differences |
| 203 | std::stringstream msg; |
| 204 | msg << std::setprecision(10) << descName << ": Expected " << expectedScale << |
| 205 | " quantization scale for bias tensor (the product of the input and weight scales), but got " << |
| 206 | biasTensor.GetQuantizationScale(); |
| 207 | throw InvalidArgumentException(msg.str()); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | //--------------------------------------------------------------- |
| 212 | void ValidateTensors(const std::vector<ITensorHandle*>& vec, |
| 213 | unsigned int numExpected, |
| 214 | const std::string& descName, |
| 215 | const std::string& varName) |
| 216 | { |
| 217 | if (vec.empty() && numExpected > 0) |
| 218 | { |
| 219 | throw InvalidArgumentException(descName + ": Invalid empty " + varName + " array."); |
| 220 | } |
| 221 | |
| 222 | for (unsigned int i = 0; i < numExpected; ++i) |
| 223 | { |
| 224 | if (!vec[i]) |
| 225 | { |
| 226 | throw InvalidArgumentException(descName + ": Invalid NULL for " + varName + to_string(i)); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | //--------------------------------------------------------------- |
| 232 | void ValidateBroadcastTensorShapesMatch(const TensorInfo& first, |
| 233 | const TensorInfo& second, |
| 234 | const TensorInfo& output, |
| 235 | std::string const& descName, |
| 236 | std::string const& firstName, |
| 237 | std::string const& secondName) |
| 238 | { |
| 239 | // Tensors must have the same number of dimensions in order to be explicit about which dimensions will get |
| 240 | // broadcasted. |
| 241 | if (first.GetNumDimensions() != second.GetNumDimensions()) |
| 242 | { |
| 243 | throw InvalidArgumentException(descName + ": Tensors " |
| 244 | + firstName + " & " + secondName |
| 245 | + " must have the same number of dimensions in order to be broadcasted"); |
| 246 | } |
| 247 | uint32_t numDims = first.GetNumDimensions(); |
| 248 | std::vector<uint32_t> outputDims(numDims, 0u); |
| 249 | for (uint32_t i = 0; i < numDims; i++) |
| 250 | { |
| 251 | const bool dimsNotEqual = first.GetShape()[i] != second.GetShape()[i]; |
| 252 | const bool dimsNotOne = (first.GetShape()[i] != 1) && (second.GetShape()[i] != 1); |
| 253 | if (dimsNotEqual && dimsNotOne) |
| 254 | { |
| 255 | throw InvalidArgumentException("Broadcasting is not possible for incompatible shapes"); |
| 256 | } |
| 257 | outputDims[i] = std::max(first.GetShape()[i], second.GetShape()[i]); |
| 258 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 259 | TensorShape broadcastShape = TensorShape(boost::numeric_cast<unsigned int>(outputDims.size()), outputDims.data()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 260 | if (broadcastShape != output.GetShape()) |
| 261 | { |
| 262 | throw InvalidArgumentException(descName + ": The tensor shape resulting from adding " |
| 263 | + firstName + " & " + secondName |
| 264 | + " does not match the output shape"); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 269 | void ValidateDataTypes(const TensorInfo& info, |
| 270 | const std::vector<armnn::DataType>& supportedTypes, |
| 271 | std::string const& descName) |
| 272 | { |
| 273 | auto iterator = std::find(supportedTypes.begin(), supportedTypes.end(), info.GetDataType()); |
| 274 | if (iterator == supportedTypes.end()) |
| 275 | { |
| 276 | throw InvalidArgumentException(descName + ": " + " Tensor type is not supported."); |
| 277 | } |
| 278 | } |
| 279 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 280 | //--------------------------------------------------------------- |
| 281 | void ValidateTensorDataTypesMatch(const TensorInfo& first, |
| 282 | const TensorInfo& second, |
| 283 | std::string const& descName, |
| 284 | std::string const& firstName, |
| 285 | std::string const& secondName) |
| 286 | { |
| 287 | if (first.GetDataType() != second.GetDataType()) |
| 288 | { |
| 289 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 290 | " must have identical data types."); |
| 291 | } |
| 292 | } |
| 293 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 294 | //--------------------------------------------------------------- |
| 295 | void ValidateTensorNumElementsMatch(const TensorInfo& first, |
| 296 | const TensorInfo& second, |
| 297 | std::string const& descName, |
| 298 | std::string const& firstName, |
| 299 | std::string const& secondName) |
| 300 | { |
| 301 | if (first.GetNumElements() != second.GetNumElements()) |
| 302 | { |
| 303 | throw InvalidArgumentException(descName + ": " + firstName + " & " + secondName + |
| 304 | " must have the same number of elements."); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | } // anonymous namespace |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 309 | |
| 310 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 311 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 312 | { |
| 313 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 314 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 315 | } |
| 316 | |
| 317 | //--------------------------------------------------------------- |
| 318 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 319 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 320 | const std::string descriptorName{"MemCopyQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 321 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 322 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 323 | ValidateNumOutputs(workloadInfo, descriptorName , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 324 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 325 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 326 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 327 | |
| 328 | ValidateTensorNumElementsMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 329 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 330 | |
| 331 | if (m_Inputs.size() != m_Outputs.size()) |
| 332 | { |
| 333 | throw InvalidArgumentException(boost::str( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 334 | boost::format("%1%: Number of inputs (%2%) does not match the number of outputs (%3%).") % |
| 335 | descriptorName % m_Inputs.size() % m_Outputs.size())); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 339 | { |
| 340 | if (!m_Inputs[i]) |
| 341 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 342 | throw InvalidArgumentException(boost::str(boost::format("%1%: Invalid NULL input %2%.") % |
| 343 | descriptorName % i)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | if (!m_Outputs[i]) |
| 347 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 348 | throw InvalidArgumentException(boost::str(boost::format("%1%: Invalid NULL output %2%") % |
| 349 | descriptorName % i)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 354 | //--------------------------------------------------------------- |
| 355 | void MemImportQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 356 | { |
| 357 | ValidateNumInputs(workloadInfo, "MemImportQueueDescriptor", 1); |
| 358 | ValidateNumOutputs(workloadInfo, "MemImportQueueDescriptor" , 1); |
| 359 | |
| 360 | if (workloadInfo.m_InputTensorInfos.size() != 1) |
| 361 | { |
| 362 | throw InvalidArgumentException(boost::str( |
| 363 | boost::format("Number of input infos (%1%) is not 1.") |
| 364 | % workloadInfo.m_InputTensorInfos.size())); |
| 365 | |
| 366 | } |
| 367 | |
| 368 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 369 | { |
| 370 | throw InvalidArgumentException(boost::str( |
| 371 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 372 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 373 | } |
| 374 | |
| 375 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 376 | { |
| 377 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 378 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 379 | { |
| 380 | throw InvalidArgumentException(boost::str( |
| 381 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 382 | % i )); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | if (m_Inputs.size() != 1) |
| 387 | { |
| 388 | throw InvalidArgumentException(boost::str( |
| 389 | boost::format("Number of inputs (%1%) is not 1.") |
| 390 | % m_Inputs.size())); |
| 391 | } |
| 392 | |
| 393 | if (m_Inputs.size() != m_Outputs.size()) |
| 394 | { |
| 395 | throw InvalidArgumentException(boost::str( |
| 396 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 397 | % m_Inputs.size() % m_Outputs.size())); |
| 398 | } |
| 399 | |
| 400 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 401 | { |
| 402 | if (!m_Inputs[i]) |
| 403 | { |
| 404 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 405 | } |
| 406 | |
| 407 | if (!m_Outputs[i]) |
| 408 | { |
| 409 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | //--------------------------------------------------------------- |
| 415 | void MemSyncQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 416 | { |
| 417 | ValidateNumInputs(workloadInfo, "MemSyncQueueDescriptor", 1); |
| 418 | ValidateNumOutputs(workloadInfo, "MemSyncQueueDescriptor" , 1); |
| 419 | |
| 420 | if (workloadInfo.m_InputTensorInfos.size() != 1) |
| 421 | { |
| 422 | throw InvalidArgumentException(boost::str( |
| 423 | boost::format("Number of input infos (%1%) is not 1.") |
| 424 | % workloadInfo.m_InputTensorInfos.size())); |
| 425 | |
| 426 | } |
| 427 | |
| 428 | if (workloadInfo.m_OutputTensorInfos.size() != 0) |
| 429 | { |
| 430 | throw InvalidArgumentException(boost::str( |
| 431 | boost::format("Number of output infos (%1%) is not 0.") |
| 432 | % workloadInfo.m_InputTensorInfos.size())); |
| 433 | |
| 434 | } |
| 435 | |
| 436 | if (m_Inputs.size() != 1) |
| 437 | { |
| 438 | throw InvalidArgumentException(boost::str( |
| 439 | boost::format("Number of inputs (%1%) is not 1.") |
| 440 | % m_Inputs.size())); |
| 441 | } |
| 442 | |
| 443 | if (m_Outputs.size() != 0) |
| 444 | { |
| 445 | throw InvalidArgumentException(boost::str( |
| 446 | boost::format("Number of outputs (%1%) is not 0.") |
| 447 | % m_Inputs.size() % m_Outputs.size())); |
| 448 | } |
| 449 | |
| 450 | if (!m_Inputs[0]) |
| 451 | { |
| 452 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input 0"))); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 457 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 458 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 459 | const std::string descriptorName{"ActivationQueueDescriptor"}; |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 460 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 461 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 462 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 463 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 464 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 465 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 466 | |
| 467 | std::vector<DataType> supportedTypes = |
| 468 | { |
| 469 | DataType::Float16, |
| 470 | DataType::Float32, |
| 471 | DataType::QuantisedAsymm8, |
| 472 | DataType::QuantisedSymm16 |
| 473 | }; |
| 474 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 475 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 476 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 477 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 480 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 481 | { |
| 482 | const std::string descriptorName{"SoftmaxQueueDescriptor"}; |
| 483 | |
| 484 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 485 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 486 | |
| 487 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 488 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 489 | |
| 490 | std::vector<DataType> supportedTypes = |
| 491 | { |
| 492 | DataType::Float16, |
| 493 | DataType::Float32, |
| 494 | DataType::QuantisedAsymm8, |
| 495 | DataType::QuantisedSymm16 |
| 496 | }; |
| 497 | |
| 498 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 499 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 500 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 501 | } |
| 502 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 503 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 504 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 505 | const std::string descriptorName{"SplitterQueueDescriptor"}; |
| 506 | |
| 507 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 508 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 509 | // Check the supported data types |
| 510 | std::vector<DataType> supportedTypes = |
| 511 | { |
| 512 | DataType::Float32, |
| 513 | DataType::Float16, |
| 514 | DataType::Boolean, |
| 515 | DataType::Signed32, |
| 516 | DataType::QuantisedAsymm8, |
| 517 | DataType::QuantisedSymm16 |
| 518 | }; |
| 519 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 520 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 521 | for (unsigned long i = 0ul; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 522 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 523 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[i]; |
| 524 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
| 525 | |
| 526 | const std::string outputName = "output_" + std::to_string(i); |
| 527 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", outputName); |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 528 | } |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 529 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 530 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 531 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 532 | throw InvalidArgumentException(descriptorName + ": At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 536 | { |
| 537 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 538 | descriptorName + ": Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 539 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 540 | "Number of windows: " + |
| 541 | to_string(m_ViewOrigins.size()) + |
| 542 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 543 | } |
| 544 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 545 | //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] | 546 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 547 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 548 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 549 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 550 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 551 | if (e.m_Origin.size() != inputDims) |
| 552 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 553 | throw InvalidArgumentException(descriptorName + ": Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 554 | "have the same dimensionality as the input tensor. " |
| 555 | "Window origin (index: " + |
| 556 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 557 | " dimensions, the input " |
| 558 | "tensor has " + |
| 559 | to_string(inputDims) + " dimensions."); |
| 560 | } |
| 561 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 562 | { |
| 563 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 564 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 565 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 566 | throw InvalidArgumentException(descriptorName + ": Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 567 | "be smaller or equal than the size of the input in that coord."); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 573 | void ConcatQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 574 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 575 | const std::string descriptorName{"ConcatQueueDescriptor"}; |
| 576 | |
| 577 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 578 | |
| 579 | if (m_Inputs.size() <= 0) |
| 580 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 581 | throw InvalidArgumentException(descriptorName + ": At least one input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 582 | } |
| 583 | if (m_Outputs.size() <= 0) |
| 584 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 585 | throw InvalidArgumentException(descriptorName + ": At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 589 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 590 | throw InvalidArgumentException(descriptorName + ": At least one TensorInfo input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 591 | } |
| 592 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 593 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 594 | throw InvalidArgumentException(descriptorName + ": At least one TensorInfo output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 597 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 598 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 599 | throw InvalidArgumentException(descriptorName + ": Invalid concatenation axis provided."); |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 603 | { |
| 604 | return; |
| 605 | } |
| 606 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 607 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 608 | { |
| 609 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 610 | descriptorName + ": Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 611 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 612 | "Number of windows: " + |
| 613 | to_string(m_ViewOrigins.size()) + |
| 614 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 615 | } |
| 616 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 617 | //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] | 618 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 619 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 620 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 621 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 622 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 623 | if (e.m_Origin.size() != outputDims) |
| 624 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 625 | throw InvalidArgumentException(descriptorName + ": Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 626 | "have the same dimensionality as the output tensor. " |
| 627 | "Window origin (index: " + |
| 628 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 629 | " dimensions, the output " |
| 630 | "tensor has " + |
| 631 | to_string(outputDims) + " dimensions."); |
| 632 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 633 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 634 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 635 | { |
| 636 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 637 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 638 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 639 | throw InvalidArgumentException(descriptorName + ": Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 640 | "be smaller or equal than the size of the output in that coord."); |
| 641 | } |
| 642 | } |
| 643 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 644 | |
| 645 | // Check the supported data types |
| 646 | std::vector<DataType> supportedTypes = |
| 647 | { |
| 648 | DataType::Float32, |
| 649 | DataType::Float16, |
| 650 | DataType::Boolean, |
| 651 | DataType::Signed32, |
| 652 | DataType::QuantisedAsymm8, |
| 653 | DataType::QuantisedSymm16 |
| 654 | }; |
| 655 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 656 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 657 | for (unsigned long i = 0ul; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 658 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 659 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[i]; |
| 660 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 661 | |
| 662 | const std::string inputName = "input_" + std::to_string(i); |
| 663 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, inputName, "output"); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 664 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 667 | void StackQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 668 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 669 | const std::string descriptorName{"StackQueueDescriptor"}; |
| 670 | |
| 671 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 672 | |
| 673 | if (m_Parameters.m_NumInputs != workloadInfo.m_InputTensorInfos.size()) |
| 674 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 675 | throw InvalidArgumentException(descriptorName + ": Must have the defined number of input tensors."); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | // All inputs must have the same shape, which is defined in parameters |
| 679 | const TensorShape& inputShape = m_Parameters.m_InputShape; |
| 680 | for (unsigned int i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 681 | { |
| 682 | if (workloadInfo.m_InputTensorInfos[i].GetShape() != inputShape) |
| 683 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 684 | throw InvalidArgumentException(descriptorName + ": All input tensor shapes must match the defined shape."); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | // m_Axis is 0-based and may take values from 0 to the number of input dimensions (inclusive), |
| 689 | // since the output tensor has an additional dimension. |
| 690 | if (m_Parameters.m_Axis > inputShape.GetNumDimensions()) |
| 691 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 692 | throw InvalidArgumentException(descriptorName + ": Axis may not be greater " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 693 | "than the number of input dimensions."); |
| 694 | } |
| 695 | |
| 696 | // Output shape must be as inferred from the input shape |
| 697 | const TensorShape& outputShape = workloadInfo.m_OutputTensorInfos[0].GetShape(); |
| 698 | for (unsigned int i = 0; i < m_Parameters.m_Axis; ++i) |
| 699 | { |
| 700 | if (outputShape[i] != inputShape[i]) |
| 701 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 702 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 703 | "match shape inferred from input tensor."); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | if (outputShape[m_Parameters.m_Axis] != m_Parameters.m_NumInputs) |
| 708 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 709 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 710 | "match shape inferred from input tensor."); |
| 711 | } |
| 712 | |
| 713 | for (unsigned int i = m_Parameters.m_Axis + 1; i < inputShape.GetNumDimensions() + 1; ++i) |
| 714 | { |
| 715 | if (outputShape[i] != inputShape[i-1]) |
| 716 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 717 | throw InvalidArgumentException(descriptorName + ": Output tensor must " |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 718 | "match shape inferred from input tensor."); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // Check the supported data types |
| 723 | std::vector<DataType> supportedTypes = |
| 724 | { |
| 725 | DataType::Float32, |
| 726 | DataType::Float16, |
| 727 | DataType::Boolean, |
| 728 | DataType::Signed32, |
| 729 | DataType::QuantisedAsymm8, |
| 730 | DataType::QuantisedSymm16 |
| 731 | }; |
| 732 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 733 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 734 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 735 | for (unsigned int i = 1ul; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 736 | { |
| 737 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 738 | workloadInfo.m_InputTensorInfos[i], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 739 | descriptorName, |
| 740 | "input_0", |
| 741 | "input_" + std::to_string(i)); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 742 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 743 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 744 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 745 | workloadInfo.m_OutputTensorInfos[0], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 746 | descriptorName, |
| 747 | "input_0", |
| 748 | "output"); |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 749 | } |
| 750 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 751 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 752 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 753 | const std::string descriptorName{"FullyConnectedQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 754 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 755 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 756 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 757 | |
| 758 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 759 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 760 | |
| 761 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 2, "output"); |
| 762 | |
| 763 | if (!(inputTensorInfo.GetNumDimensions() == 2 || inputTensorInfo.GetNumDimensions() == 4)) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 764 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 765 | throw InvalidArgumentException(descriptorName + ": Input tensor must have 2 or 4 dimensions."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 766 | } |
| 767 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 768 | ValidatePointer(m_Weight, descriptorName, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 769 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 770 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 771 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 2, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 772 | |
| 773 | if (m_Parameters.m_BiasEnabled) |
| 774 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 775 | ValidatePointer(m_Bias, descriptorName, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 776 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 777 | // Validates type and quantization values. |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 778 | const TensorInfo& biasTensorInfo = m_Bias->GetTensorInfo(); |
| 779 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 780 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 781 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 782 | ValidateTensorNumDimensions(biasTensorInfo, descriptorName, 1, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 785 | // Check the supported data types |
| 786 | std::vector<DataType> supportedTypes = |
| 787 | { |
| 788 | DataType::Float32, |
| 789 | DataType::Float16, |
| 790 | DataType::QuantisedAsymm8, |
| 791 | DataType::QuantisedSymm16 |
| 792 | }; |
| 793 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 794 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 795 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 796 | } |
| 797 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 798 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 799 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 800 | const std::string descriptorName{"NormalizationQueueDescriptor"}; |
| 801 | |
| 802 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 803 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 804 | |
| 805 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 806 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 807 | |
| 808 | // Check the supported data types |
| 809 | std::vector<DataType> supportedTypes = |
| 810 | { |
| 811 | DataType::Float16, |
| 812 | DataType::Float32, |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 813 | DataType::QuantisedAsymm8, |
| 814 | DataType::QuantisedSymm16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 815 | }; |
| 816 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 817 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 818 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 819 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 820 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 821 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 825 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 826 | const std::string descriptorName{"AdditionQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 827 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 828 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 829 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 830 | |
| 831 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 832 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 833 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 834 | |
| 835 | std::vector<DataType> supportedTypes = |
| 836 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 837 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 838 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 839 | DataType::QuantisedSymm16, |
| 840 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 841 | }; |
| 842 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 843 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 844 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 845 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 846 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 847 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 848 | ValidateTensorDataTypesMatch(inputTensorInfo1, outputTensorInfo, descriptorName, "input_1", "output"); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 849 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 850 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 851 | inputTensorInfo1, |
| 852 | outputTensorInfo, |
| 853 | descriptorName, |
| 854 | "input_0", |
| 855 | "input_1"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 856 | } |
| 857 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 858 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 859 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 860 | const std::string descriptorName{"MultiplicationQueueDescriptor"}; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 861 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 862 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 863 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 864 | |
| 865 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 866 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 867 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 868 | |
| 869 | std::vector<DataType> supportedTypes = |
| 870 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 871 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 872 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 873 | DataType::QuantisedSymm16, |
| 874 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 875 | }; |
| 876 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 877 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 878 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 879 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 880 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 881 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 882 | ValidateTensorDataTypesMatch(inputTensorInfo1, outputTensorInfo, descriptorName, "input_1", "output"); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 883 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 884 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 885 | inputTensorInfo1, |
| 886 | outputTensorInfo, |
| 887 | descriptorName, |
| 888 | "input_0", |
| 889 | "input_1"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 893 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 894 | const std::string descriptorName{"BatchNormalizationQueueDescriptor"}; |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 895 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 896 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 897 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 898 | |
| 899 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 900 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 901 | |
| 902 | std::vector<DataType> supportedTypes = |
| 903 | { |
| 904 | DataType::Float16, |
| 905 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 906 | DataType::QuantisedAsymm8, |
| 907 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 908 | }; |
| 909 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 910 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 911 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 912 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 913 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 914 | ValidateTensorQuantizationSpace(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 915 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 916 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 917 | ValidatePointer(m_Mean, descriptorName, "mean"); |
| 918 | ValidatePointer(m_Variance, descriptorName, "variance"); |
| 919 | ValidatePointer(m_Beta, descriptorName, "beta"); |
| 920 | ValidatePointer(m_Gamma, descriptorName, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 921 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 922 | const TensorInfo& mean = m_Mean->GetTensorInfo(); |
| 923 | const TensorInfo& variance = m_Variance->GetTensorInfo(); |
| 924 | const TensorInfo& beta = m_Beta->GetTensorInfo(); |
| 925 | const TensorInfo& gamma = m_Gamma->GetTensorInfo(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 926 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 927 | ValidateTensorNumDimensions(mean, descriptorName, 1, "mean"); |
| 928 | ValidateTensorNumDimensions(variance, descriptorName, 1, "variance"); |
| 929 | ValidateTensorNumDimensions(beta, descriptorName, 1, "beta"); |
| 930 | ValidateTensorNumDimensions(gamma, descriptorName, 1, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 931 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 932 | ValidateTensorShapesMatch(mean, variance, descriptorName, "mean", "variance"); |
| 933 | ValidateTensorShapesMatch(mean, beta, descriptorName, "mean", "beta"); |
| 934 | ValidateTensorShapesMatch(mean, gamma, descriptorName, "mean", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 938 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 939 | const std::string descriptorName{"Convolution2dQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 940 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 941 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 942 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 943 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 944 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 945 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 946 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 947 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 948 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 949 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 950 | ValidatePointer(m_Weight, descriptorName, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 951 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 952 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 953 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 954 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 955 | ValidateTensorDataTypesMatch(inputTensorInfo, weightTensorInfo, descriptorName, "input", "weight"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 956 | |
| 957 | if (m_Parameters.m_BiasEnabled) |
| 958 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 959 | ValidatePointer(m_Bias, descriptorName, "bias"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 960 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 961 | const TensorInfo& biasTensorInfo = m_Bias->GetTensorInfo(); |
| 962 | ValidateTensorNumDimensions(biasTensorInfo, descriptorName, 1, "bias"); |
| 963 | |
| 964 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 965 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 968 | std::vector<DataType> supportedTypes = |
| 969 | { |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 970 | DataType::Float32, |
| 971 | DataType::QuantisedAsymm8, |
| 972 | DataType::QuantisedSymm16, |
| 973 | DataType::Float16 |
| 974 | }; |
| 975 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 976 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 977 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 978 | } |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 979 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 980 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 981 | { |
| 982 | const std::string descriptorName{"DepthwiseConvolution2dQueueDescriptor"}; |
| 983 | |
| 984 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 985 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 986 | |
| 987 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 988 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 989 | |
| 990 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 991 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
| 992 | |
| 993 | ValidatePointer(m_Weight, descriptorName, "weight"); |
| 994 | |
| 995 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 996 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
| 997 | |
| 998 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 999 | { |
| 1000 | throw InvalidArgumentException( |
| 1001 | boost::str(boost::format("%1%: dilationX (provided %2%) and dilationY (provided %3%) " |
| 1002 | "cannot be smaller than 1.") % descriptorName % |
| 1003 | m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 1004 | } |
| 1005 | |
| 1006 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 1007 | |
| 1008 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 1009 | // inputChannels * channelMultiplier should be equal to outputChannels. |
| 1010 | const unsigned int numWeightChannelMultiplier = weightTensorInfo.GetShape()[0]; |
| 1011 | const unsigned int numWeightInputChannels = weightTensorInfo.GetShape()[1]; |
| 1012 | const unsigned int numWeightOutputChannels = outputTensorInfo.GetShape()[channelIndex]; |
| 1013 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 1014 | { |
| 1015 | throw InvalidArgumentException( |
| 1016 | boost::str(boost::format("%1%: output_channels (provided %2%) should be " |
| 1017 | "equal to input_channels (provided %3%) multiplied by channel_multiplier " |
| 1018 | "(provided %4%).") % descriptorName % numWeightOutputChannels % |
| 1019 | numWeightInputChannels % numWeightChannelMultiplier)); |
| 1020 | } |
| 1021 | |
| 1022 | ValidateTensorDataTypesMatch(inputTensorInfo, weightTensorInfo, descriptorName, "input", "weight"); |
| 1023 | |
| 1024 | if (m_Parameters.m_BiasEnabled) |
| 1025 | { |
| 1026 | ValidatePointer(m_Bias, descriptorName, "bias"); |
| 1027 | |
| 1028 | const TensorInfo& biasTensorInfo = m_Bias->GetTensorInfo(); |
| 1029 | ValidateTensorNumDimensions(biasTensorInfo, descriptorName, 1, "bias"); |
| 1030 | |
| 1031 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
| 1032 | ValidateTensorDataType(biasTensorInfo, GetBiasDataType(inputTensorInfo.GetDataType()), descriptorName, "bias"); |
| 1033 | } |
| 1034 | |
| 1035 | std::vector<DataType> supportedTypes = |
| 1036 | { |
| 1037 | DataType::Float32, |
| 1038 | DataType::QuantisedAsymm8, |
| 1039 | DataType::QuantisedSymm16, |
| 1040 | DataType::Float16 |
| 1041 | }; |
| 1042 | |
| 1043 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1044 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1048 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1049 | const std::string descriptorName{"PermuteQueueDescriptor"}; |
| 1050 | |
| 1051 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1052 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1053 | |
| 1054 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 1055 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1056 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1057 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1058 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1059 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, mapping.GetSize(), "input"); |
| 1060 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, mapping.GetSize(), "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1061 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1062 | for (unsigned int i = 0u; i < mapping.GetSize(); ++i) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1063 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1064 | if (inputTensorInfo.GetShape()[i] != outputTensorInfo.GetShape()[mapping[i]]) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1065 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1066 | throw InvalidArgumentException(descriptorName + ": src dimension " + to_string(i) + |
| 1067 | " (=" + to_string(inputTensorInfo.GetShape()[i]) + ") " + |
| 1068 | "must match dst dimension " + to_string(mapping[i]) + |
| 1069 | " (=" + to_string(outputTensorInfo.GetShape()[mapping[i]]) + ")"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1070 | } |
| 1071 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1072 | |
| 1073 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1077 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1078 | const std::string descriptorName{"Pooling2dQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1079 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1080 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1081 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1082 | |
| 1083 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1084 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1085 | |
| 1086 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1087 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1088 | |
| 1089 | std::vector<DataType> supportedTypes = |
| 1090 | { |
| 1091 | DataType::Float32, |
| 1092 | DataType::Float16, |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 1093 | DataType::QuantisedAsymm8, |
| 1094 | DataType::QuantisedSymm16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1095 | }; |
| 1096 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1097 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1098 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1102 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1103 | const std::string descriptorName{"ResizeBilinearQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1104 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 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]; |
| 1110 | |
| 1111 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1112 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1113 | |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1114 | std::vector<DataType> supportedTypes = |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1115 | { |
| 1116 | DataType::Float16, |
| 1117 | DataType::Float32, |
| 1118 | DataType::QuantisedAsymm8, |
| 1119 | DataType::QuantisedSymm16 |
| 1120 | }; |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1121 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1122 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1123 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1124 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1125 | // ResizeBilinear only changes width and height: batch and channel count must match. |
| 1126 | const unsigned int inputBatchSize = inputTensorInfo.GetShape()[0]; |
| 1127 | const unsigned int outputBatchSize = outputTensorInfo.GetShape()[0]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1128 | if (inputBatchSize != outputBatchSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1129 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1130 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1131 | boost::str(boost::format("%1%: Input batch size (%2%) " |
| 1132 | "does not match output batch size (%3%)") % |
| 1133 | descriptorName % inputBatchSize % outputBatchSize)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1136 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1137 | const unsigned int inputChannelCount = inputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1138 | const unsigned int outputChannelCount = outputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1139 | if (inputChannelCount != outputChannelCount) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1140 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1141 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1142 | boost::str(boost::format("%1%: Input channel count (%2%) " |
| 1143 | "does not match output channel count (%3%)") % |
| 1144 | descriptorName % inputChannelCount % outputChannelCount)); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | void ResizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1149 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1150 | const std::string descriptorName{"ResizeQueueDescriptor"}; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1151 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1152 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1153 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1154 | |
| 1155 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1156 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1157 | |
| 1158 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1159 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1160 | |
| 1161 | std::vector<DataType> supportedTypes = |
| 1162 | { |
| 1163 | DataType::Float16, |
| 1164 | DataType::Float32, |
| 1165 | DataType::QuantisedAsymm8, |
| 1166 | DataType::QuantisedSymm16 |
| 1167 | }; |
| 1168 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1169 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1170 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1171 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1172 | // Resize only changes width and height: batch and channel count must match. |
| 1173 | const unsigned int inputBatchSize = inputTensorInfo.GetShape()[0]; |
| 1174 | const unsigned int outputBatchSize = outputTensorInfo.GetShape()[0]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1175 | if (inputBatchSize != outputBatchSize) |
| 1176 | { |
| 1177 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1178 | boost::str(boost::format("%1%: Input batch size (%2%) " |
| 1179 | "does not match output batch size (%3%)") % |
| 1180 | descriptorName % inputBatchSize % outputBatchSize)); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1184 | const unsigned int inputChannelCount = inputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
| 1185 | const unsigned int outputChannelCount = outputTensorInfo.GetShape()[dimensionIndices.GetChannelsIndex()]; |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1186 | if (inputChannelCount != outputChannelCount) |
| 1187 | { |
| 1188 | throw InvalidArgumentException( |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1189 | boost::str(boost::format("%1%: Input channel count (%2%) " |
| 1190 | "does not match output channel count (%3%)") % |
| 1191 | descriptorName % inputChannelCount % outputChannelCount)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1196 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1197 | const std::string descriptorName{"FakeQuantizationQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1198 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1199 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1200 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1201 | |
| 1202 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1203 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1204 | |
| 1205 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 2, "input"); |
| 1206 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 2, "output"); |
| 1207 | |
| 1208 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
| 1209 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1210 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 1211 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1212 | throw InvalidArgumentException(descriptorName + ": min cannot be greater than max"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1213 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1217 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1218 | const std::string descriptorName{"L2NormalizationQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1219 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1220 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1221 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1222 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1223 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1224 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1225 | |
Matthew Jackson | 82b15ed | 2019-07-25 16:14:30 +0100 | [diff] [blame] | 1226 | if (inputTensorInfo.GetNumDimensions() > 4) |
| 1227 | { |
| 1228 | throw InvalidArgumentException(descriptorName + ": Input tensors with rank greater than 4 are not supported."); |
| 1229 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1230 | |
| 1231 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1232 | |
| 1233 | // Check the supported data types |
| 1234 | std::vector<DataType> supportedTypes = |
| 1235 | { |
| 1236 | DataType::Float32, |
| 1237 | DataType::Float16, |
| 1238 | DataType::QuantisedAsymm8, |
| 1239 | DataType::QuantisedSymm16 |
| 1240 | }; |
| 1241 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1242 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1243 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
| 1244 | |
| 1245 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1249 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1250 | const std::string descriptorName{"ConstantQueueDescriptor"}; |
| 1251 | |
| 1252 | ValidateNumInputs(workloadInfo, descriptorName, 0); |
| 1253 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1254 | |
| 1255 | if (!m_LayerOutput) |
| 1256 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1257 | throw InvalidArgumentException(descriptorName + ": No const input specified."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1260 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1261 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), outputTensorInfo, descriptorName, "constant", "output"); |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1262 | |
| 1263 | // Check the supported data types |
| 1264 | std::vector<DataType> supportedTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1265 | { |
| 1266 | DataType::Float32, |
| 1267 | DataType::Float16, |
| 1268 | DataType::Signed32, |
| 1269 | DataType::QuantisedAsymm8, |
| 1270 | DataType::QuantisedSymm16 |
| 1271 | }; |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 1272 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1273 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1277 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1278 | const std::string descriptorName{"ReshapeQueueDescriptor"}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1279 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1280 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1281 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1282 | |
| 1283 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1284 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1285 | |
| 1286 | ValidateTensorNumElementsMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1287 | |
| 1288 | // Check the supported data types |
| 1289 | std::vector<DataType> supportedTypes = |
| 1290 | { |
| 1291 | DataType::Float32, |
| 1292 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1293 | DataType::QuantisedAsymm8, |
| 1294 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1295 | }; |
| 1296 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1297 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1298 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1301 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1302 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1303 | const std::string descriptorName{"SpaceToBatchNdQueueDescriptor"}; |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1304 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1305 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1306 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1307 | |
| 1308 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1309 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1310 | |
| 1311 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1312 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1313 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1314 | if (m_Parameters.m_BlockShape.size() != 2) |
| 1315 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1316 | throw InvalidArgumentException(descriptorName + ": Block Shape must contain 2 spatial dimensions."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 1320 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1321 | throw InvalidArgumentException(descriptorName + ": Pad List must contain the same number of " |
| 1322 | "dimensions as Block Shape."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1325 | const TensorShape& inputShape = inputTensorInfo.GetShape(); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1326 | |
| 1327 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1328 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1329 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1330 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1331 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1332 | const unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] + |
| 1333 | widthPad.first + widthPad.second; |
| 1334 | const unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] + |
| 1335 | heightPad.first + heightPad.second; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1336 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1337 | const unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth * |
| 1338 | inputShape[dimensionIndices.GetChannelsIndex()]; |
| 1339 | const unsigned int numOutputElements = outputTensorInfo.GetNumElements(); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1340 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1341 | if (numOutputElements != numInputElements) |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1342 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1343 | throw InvalidArgumentException(descriptorName + ": Input tensor has " + |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1344 | to_string(numInputElements) + " after padding but output tensor has " + |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1345 | to_string(numOutputElements) + " elements."); |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | if (inputHeight % m_Parameters.m_BlockShape[0] != 0 || inputWidth % m_Parameters.m_BlockShape[1] != 0) |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1349 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1350 | throw InvalidArgumentException(descriptorName + ": Input shape after padding must be " |
| 1351 | "divisible by Block Shape in all spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1352 | } |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1353 | |
| 1354 | std::vector<DataType> supportedTypes = |
| 1355 | { |
| 1356 | DataType::Float16, |
| 1357 | DataType::Float32, |
| 1358 | DataType::QuantisedAsymm8, |
| 1359 | DataType::QuantisedSymm16 |
| 1360 | }; |
| 1361 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1362 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1363 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1366 | void SpaceToDepthQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1367 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1368 | const std::string descriptorName{"SpaceToDepthQueueDescriptor"}; |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1369 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1370 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1371 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1372 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1373 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1374 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1375 | |
| 1376 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 1377 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1378 | |
| 1379 | std::vector<DataType> supportedTypes = |
| 1380 | { |
| 1381 | DataType::Float32, |
| 1382 | DataType::Float16, |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame] | 1383 | DataType::QuantisedAsymm8, |
| 1384 | DataType::QuantisedSymm16 |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1385 | }; |
| 1386 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1387 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1388 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1389 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1390 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1391 | const unsigned int wIndex = dimensionIndices.GetWidthIndex(); |
| 1392 | const unsigned int hIndex = dimensionIndices.GetHeightIndex(); |
| 1393 | const unsigned int cIndex = dimensionIndices.GetChannelsIndex(); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1394 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1395 | const TensorShape& inputShape = inputTensorInfo.GetShape(); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1396 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1397 | const unsigned int numInputElements = |
| 1398 | inputShape[0] * inputShape[wIndex] * inputShape[hIndex] * inputShape[cIndex]; |
| 1399 | const unsigned int numOutputElements = outputTensorInfo.GetNumElements(); |
| 1400 | |
| 1401 | if (numOutputElements != numInputElements) |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1402 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1403 | throw InvalidArgumentException(descriptorName + ": Input tensor has " + |
| 1404 | std::to_string(numInputElements) + " but output tensor has " + |
| 1405 | std::to_string(numOutputElements) + " elements."); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1408 | 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] | 1409 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1410 | throw InvalidArgumentException(descriptorName + ": Input shape must be divisible " |
| 1411 | "by block size in all spatial dimensions"); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1415 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1416 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1417 | const std::string descriptorName{"FloorQueueDescriptor"}; |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1418 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1419 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1420 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1421 | |
| 1422 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1423 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1424 | |
| 1425 | std::vector<DataType> supportedTypes = |
| 1426 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1427 | DataType::Float32, |
| 1428 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1429 | }; |
| 1430 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1431 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1432 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1433 | if (inputTensorInfo != outputTensorInfo) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1434 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1435 | throw InvalidArgumentException(descriptorName + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1439 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1440 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1441 | // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions() |
| 1442 | |
| 1443 | const std::string descriptorName{"LstmQueueDescriptor"}; |
| 1444 | |
| 1445 | // check dimensions of all inputs and outputs |
| 1446 | if (workloadInfo.m_InputTensorInfos.size() != 3) |
| 1447 | { |
| 1448 | throw InvalidArgumentException(descriptorName + ": Invalid number of inputs."); |
| 1449 | } |
| 1450 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1451 | { |
| 1452 | throw InvalidArgumentException(descriptorName + ": Invalid number of outputs."); |
| 1453 | } |
| 1454 | |
| 1455 | std::vector<DataType> supportedTypes = |
| 1456 | { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1457 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1458 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1459 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1460 | }; |
| 1461 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1462 | // 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] | 1463 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName); |
| 1464 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1465 | // type matches all other inputs |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1466 | for (uint32_t i = 1u; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1467 | { |
| 1468 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1469 | workloadInfo.m_InputTensorInfos[i], |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1470 | descriptorName, |
| 1471 | "input_0", |
| 1472 | "input_" + std::to_string(i)); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1473 | } |
| 1474 | // type matches all other outputs |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1475 | for (uint32_t i = 0u; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1476 | { |
| 1477 | ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1478 | workloadInfo.m_OutputTensorInfos[i], |
| 1479 | "LstmQueueDescriptor", |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1480 | "input_0", |
| 1481 | "output_" + std::to_string(i)); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1482 | } |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1483 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1484 | // TODO: check clipping parameter is valid |
| 1485 | |
| 1486 | // Inferring batch size, number of outputs and number of cells from the inputs. |
| 1487 | // TODO: figure out if there is a way to make sure the specific inputs are at that index of workloadInfo |
| 1488 | const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1]; |
| 1489 | const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 1490 | ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights"); |
| 1491 | const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0]; |
| 1492 | ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights"); |
| 1493 | const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1]; |
| 1494 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1495 | // input tensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1496 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input), |
| 1497 | descriptorName + " input_0"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1498 | // outputStateInTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1499 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output), |
| 1500 | descriptorName + " input_1"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1501 | // outputStateInTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1502 | ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell), |
| 1503 | descriptorName + " input_2"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1504 | // scratchBufferTensor |
| 1505 | 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] | 1506 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize), |
| 1507 | descriptorName + " output_0"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1508 | // outputStateOutTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1509 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output), |
| 1510 | descriptorName + " output_1"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1511 | // cellStateOutTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1512 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell), |
| 1513 | descriptorName + " output_2"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1514 | // outputTensor |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1515 | ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output), |
| 1516 | descriptorName + " output_3"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1517 | |
| 1518 | |
| 1519 | // check that dimensions of inputs/outputs and QueueDescriptor data match with each other |
| 1520 | if ( m_InputToInputWeights ) |
| 1521 | { |
| 1522 | ValidateTensorNumDimNumElem(m_InputToInputWeights->GetTensorInfo(), 2, |
| 1523 | (n_cell * n_input), "InputLayerNormWeights"); |
| 1524 | } |
| 1525 | |
| 1526 | ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights"); |
| 1527 | ValidateTensorNumDimNumElem(m_InputToForgetWeights->GetTensorInfo(), 2, |
| 1528 | (n_cell * n_input), "InputToForgetWeights"); |
| 1529 | |
| 1530 | ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights"); |
| 1531 | ValidateTensorNumDimNumElem(m_InputToCellWeights->GetTensorInfo(), 2, |
| 1532 | (n_cell * n_input), "InputToCellWeights"); |
| 1533 | |
| 1534 | if ( m_RecurrentToInputWeights ) |
| 1535 | { |
| 1536 | ValidateTensorNumDimNumElem(m_RecurrentToInputWeights->GetTensorInfo(), 2, |
| 1537 | (n_cell * n_output), "RecurrentToInputWeights"); |
| 1538 | } |
| 1539 | |
| 1540 | ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights"); |
| 1541 | ValidateTensorNumDimNumElem(m_RecurrentToForgetWeights->GetTensorInfo(), 2, |
| 1542 | (n_cell * n_output), "RecurrentToForgetWeights"); |
| 1543 | |
| 1544 | ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights"); |
| 1545 | ValidateTensorNumDimNumElem(m_RecurrentToCellWeights->GetTensorInfo(), 2, |
| 1546 | (n_cell * n_output), "RecurrentToCellWeights"); |
| 1547 | |
| 1548 | // Make sure the input-gate's parameters are either both present (regular |
| 1549 | // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly. |
| 1550 | bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights && |
| 1551 | !m_Parameters.m_CifgEnabled) || |
| 1552 | (!m_InputToInputWeights && !m_RecurrentToInputWeights && |
| 1553 | m_Parameters.m_CifgEnabled)); |
| 1554 | if (!cifg_weights_all_or_none) |
| 1555 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1556 | throw InvalidArgumentException(descriptorName + ": Input-Gate's parameters InputToInputWeights and " |
| 1557 | "RecurrentToInputWeights must either both be present (regular LSTM) " |
| 1558 | "or both not present (CIFG-LSTM). In addition CifgEnable must be set " |
| 1559 | "accordingly."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | if ( m_CellToInputWeights ) |
| 1563 | { |
| 1564 | ValidateTensorNumDimNumElem(m_CellToInputWeights->GetTensorInfo(), 1, |
| 1565 | n_cell, "CellToInputWeights"); |
| 1566 | } |
| 1567 | if ( m_CellToForgetWeights ) |
| 1568 | { |
| 1569 | ValidateTensorNumDimNumElem(m_CellToForgetWeights->GetTensorInfo(), 1, |
| 1570 | n_cell, "CellToForgetWeights"); |
| 1571 | } |
| 1572 | if ( m_CellToOutputWeights ) |
| 1573 | { |
| 1574 | ValidateTensorNumDimNumElem(m_CellToOutputWeights->GetTensorInfo(), 1, |
| 1575 | n_cell, "CellToOutputWeights"); |
| 1576 | } |
| 1577 | |
| 1578 | // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly. |
| 1579 | bool peephole_weights_all_or_none = |
| 1580 | (((m_CellToInputWeights || m_Parameters.m_CifgEnabled) && m_CellToForgetWeights |
| 1581 | && m_CellToOutputWeights && m_Parameters.m_PeepholeEnabled) |
| 1582 | || ( !m_CellToInputWeights && !m_CellToForgetWeights |
| 1583 | && !m_CellToOutputWeights && !m_Parameters.m_PeepholeEnabled)); |
| 1584 | if (!peephole_weights_all_or_none) |
| 1585 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1586 | throw InvalidArgumentException(descriptorName + ": Invalid combination of peephole parameters."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | // Make sure the input gate bias is present only when not a CIFG-LSTM. |
| 1590 | if (m_Parameters.m_CifgEnabled) |
| 1591 | { |
| 1592 | if (m_InputGateBias) |
| 1593 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1594 | throw InvalidArgumentException(descriptorName + ": InputGateBias is present and CIFG-LSTM is enabled."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | else |
| 1598 | { |
| 1599 | if (!m_InputGateBias) |
| 1600 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1601 | throw InvalidArgumentException(descriptorName + ": If CIFG-LSTM is disabled InputGateBias " |
| 1602 | "must be present."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1603 | } |
| 1604 | ValidateTensorNumDimNumElem(m_InputGateBias->GetTensorInfo(), 1, |
| 1605 | n_cell, "InputGateBias"); |
| 1606 | } |
| 1607 | |
| 1608 | ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias"); |
| 1609 | ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias"); |
| 1610 | |
| 1611 | ValidatePointer(m_CellBias, "Null pointer check", "CellBias"); |
| 1612 | ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias"); |
| 1613 | |
| 1614 | ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias"); |
| 1615 | ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias"); |
| 1616 | |
| 1617 | if (m_ProjectionWeights) |
| 1618 | { |
| 1619 | ValidateTensorNumDimNumElem(m_ProjectionWeights->GetTensorInfo(), 2, |
| 1620 | (n_cell * n_output), "ProjectionWeights"); |
| 1621 | } |
| 1622 | if (m_ProjectionBias) |
| 1623 | { |
| 1624 | ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias"); |
| 1625 | } |
| 1626 | |
| 1627 | // Making sure the projection tensors are consistent: |
| 1628 | // 1) If projection weight is not present, then projection bias should not be |
| 1629 | // present. |
| 1630 | // 2) If projection weight is present, then projection bias is optional. |
| 1631 | bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias && |
| 1632 | !m_Parameters.m_ProjectionEnabled) |
| 1633 | || (m_ProjectionWeights && !m_ProjectionBias && |
| 1634 | m_Parameters.m_ProjectionEnabled) |
| 1635 | || (m_ProjectionWeights && m_ProjectionBias && |
| 1636 | m_Parameters.m_ProjectionEnabled)); |
| 1637 | if (!projecton_tensors_consistent) |
| 1638 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1639 | throw InvalidArgumentException(descriptorName + ": Projection tensors are inconsistent."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | // The four layer normalization weights either all have values or none of them have values. Additionally, if |
| 1643 | // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights |
| 1644 | // either all have values or none of them have values. Layer normalization is used when the values of all the |
| 1645 | // layer normalization weights are present |
| 1646 | if (m_InputLayerNormWeights) |
| 1647 | { |
| 1648 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights"); |
| 1649 | } |
| 1650 | if (m_ForgetLayerNormWeights) |
| 1651 | { |
| 1652 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1653 | } |
| 1654 | if (m_CellLayerNormWeights) |
| 1655 | { |
| 1656 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1657 | } |
| 1658 | if (m_OutputLayerNormWeights) |
| 1659 | { |
| 1660 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1661 | } |
| 1662 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1663 | if (m_Parameters.m_LayerNormEnabled) |
| 1664 | { |
| 1665 | if (!m_Parameters.m_CifgEnabled) |
| 1666 | { |
| 1667 | if (!m_InputLayerNormWeights) |
| 1668 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1669 | throw InvalidArgumentException(descriptorName + ": Layer normalisation is enabled and CIFG-LSTM is " |
| 1670 | "disabled but InputLayerNormWeights are not present"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1671 | } |
| 1672 | ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), |
| 1673 | 1, n_cell, "InputLayerNormWeights"); |
| 1674 | } |
| 1675 | else if (m_InputLayerNormWeights) |
| 1676 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1677 | throw InvalidArgumentException(descriptorName + ":InputLayerNormWeights are present while CIFG is " |
| 1678 | "enabled"); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1682 | "ForgetLayerNormWeights"); |
| 1683 | ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights"); |
| 1684 | |
| 1685 | ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1686 | "OutputLayerNormWeights"); |
| 1687 | ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights"); |
| 1688 | |
| 1689 | ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled", |
| 1690 | "CellLayerNormWeights"); |
| 1691 | ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights"); |
| 1692 | } |
| 1693 | else if (m_InputLayerNormWeights || m_ForgetLayerNormWeights || m_OutputLayerNormWeights || m_CellLayerNormWeights) |
| 1694 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1695 | throw InvalidArgumentException(descriptorName + ": Layer normalisation is disabled but one or more layer " |
| 1696 | "normalisation weights are present."); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1697 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1701 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1702 | const std::string descriptorName{"ConvertFp32ToFp16QueueDescriptor"}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1703 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1704 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1705 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1706 | |
| 1707 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1708 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1709 | |
| 1710 | if (inputTensorInfo.GetDataType() != DataType::Float32) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1711 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1712 | throw InvalidArgumentException(descriptorName + ": Input tensor type must be Float32."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1715 | if (outputTensorInfo.GetDataType() != DataType::Float16) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1716 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1717 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Float16."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1718 | } |
| 1719 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1720 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1724 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1725 | const std::string descriptorName{"ConvertFp16ToFp32QueueDescriptor"}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1726 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1727 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1728 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1729 | |
| 1730 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1731 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1732 | |
| 1733 | if (inputTensorInfo.GetDataType() != DataType::Float16) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1734 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1735 | throw InvalidArgumentException(descriptorName + ": Input tensor type must be Float16."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1738 | if (outputTensorInfo.GetDataType() != DataType::Float32) |
| 1739 | { |
| 1740 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Float32."); |
| 1741 | } |
| 1742 | |
| 1743 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1744 | } |
| 1745 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1746 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1747 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1748 | const std::string descriptorName{"DivisionQueueDescriptor"}; |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1749 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1750 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 1751 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1752 | |
| 1753 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 1754 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 1755 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1756 | |
| 1757 | std::vector<DataType> supportedTypes = |
| 1758 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1759 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1760 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1761 | DataType::QuantisedSymm16, |
| 1762 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1763 | }; |
| 1764 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1765 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 1766 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 1767 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1768 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1769 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 1770 | inputTensorInfo1, |
| 1771 | outputTensorInfo, |
| 1772 | descriptorName, |
| 1773 | "input_0", |
| 1774 | "input_1"); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1775 | } |
| 1776 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1777 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1778 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1779 | const std::string descriptorName{"SubtractionQueueDescriptor"}; |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1780 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1781 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 1782 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1783 | |
| 1784 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 1785 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 1786 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1787 | |
| 1788 | std::vector<DataType> supportedTypes = |
| 1789 | { |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1790 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1791 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1792 | DataType::QuantisedSymm16, |
| 1793 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1794 | }; |
| 1795 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1796 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 1797 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 1798 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1799 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1800 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 1801 | inputTensorInfo1, |
| 1802 | outputTensorInfo, |
| 1803 | descriptorName, |
| 1804 | "input_0", |
| 1805 | "input_1"); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1806 | } |
| 1807 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1808 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1809 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1810 | const std::string descriptorName{"MaximumQueueDescriptor"}; |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1811 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1812 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 1813 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1814 | |
| 1815 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 1816 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 1817 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1818 | |
| 1819 | std::vector<DataType> supportedTypes = |
| 1820 | { |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 1821 | DataType::Float16, |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1822 | DataType::Float32, |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 1823 | DataType::Signed32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1824 | DataType::QuantisedAsymm8, |
| 1825 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1826 | }; |
| 1827 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1828 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 1829 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 1830 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1831 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1832 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 1833 | inputTensorInfo1, |
| 1834 | outputTensorInfo, |
| 1835 | descriptorName, |
| 1836 | "input_0", |
| 1837 | "input_1"); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1840 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1841 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1842 | const std::string descriptorName{"MeanQueueDescriptor"}; |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1843 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1844 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1845 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1846 | |
| 1847 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1848 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1849 | |
| 1850 | std::vector<DataType> supportedTypes = |
| 1851 | { |
| 1852 | DataType::Float32, |
| 1853 | DataType::Float16, |
| 1854 | DataType::QuantisedAsymm8, |
| 1855 | DataType::QuantisedSymm16 |
| 1856 | }; |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1857 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1858 | // First check if input tensor data type is supported, then |
| 1859 | // check if this data type matches the output tensor data type |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1860 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1861 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1862 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1863 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1864 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1865 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, inputTensorInfo.GetNumDimensions(), "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1866 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1867 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1868 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1869 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 1, "output"); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1870 | } |
| 1871 | else |
| 1872 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1873 | unsigned int outputDim = |
| 1874 | inputTensorInfo.GetNumDimensions() - boost::numeric_cast<unsigned int>(m_Parameters.m_Axis.size()); |
| 1875 | ValidateTensorNumDimensions(outputTensorInfo, |
| 1876 | descriptorName, |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1877 | outputDim > 0 ? outputDim : 1, |
| 1878 | "output"); |
| 1879 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1882 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1883 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1884 | const std::string descriptorName{"PadQueueDescriptor"}; |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1885 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1886 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1887 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1888 | |
| 1889 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1890 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1891 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1892 | // input and output should have the same number of dimensions |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1893 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, inputTensorInfo.GetNumDimensions(), "output"); |
| 1894 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1895 | // 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] | 1896 | if (m_Parameters.m_PadList.size() != inputTensorInfo.GetNumDimensions()) { |
| 1897 | throw InvalidArgumentException(descriptorName + ":Pad List should contain the same number of entries " |
| 1898 | "as there are dimensions in the input tensor that is " + |
| 1899 | std::to_string(inputTensorInfo.GetNumDimensions()) + " entries " + |
| 1900 | " not " + std::to_string(m_Parameters.m_PadList.size()) + " entries."); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1904 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1905 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1906 | const std::string descriptorName{"QuantizeQueueDescriptor"}; |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1907 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1908 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1909 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1910 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1911 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1912 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 1913 | |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 1914 | std::vector<DataType> supportedTypes = |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1915 | { |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 1916 | DataType::Float32, |
| 1917 | DataType::Float16 |
| 1918 | }; |
| 1919 | |
| 1920 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1921 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1922 | if (outputTensorInfo.GetDataType() != DataType::QuantisedAsymm8 && |
| 1923 | outputTensorInfo.GetDataType() != DataType::QuantisedSymm16) |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1924 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1925 | throw InvalidArgumentException(descriptorName + ": Output of quantized layer must be quantized type."); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1926 | } |
| 1927 | } |
| 1928 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1929 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1930 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1931 | const std::string descriptorName{"BatchToSpaceNdQueueDescriptor"}; |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 1932 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1933 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1934 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 1935 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1936 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1937 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 1938 | |
| 1939 | std::vector<DataType> supportedTypes = |
| 1940 | { |
| 1941 | DataType::Float32, |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 1942 | DataType::Float16, |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 1943 | DataType::QuantisedAsymm8, |
| 1944 | DataType::QuantisedSymm16 |
| 1945 | }; |
| 1946 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1947 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1948 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1951 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1952 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1953 | const std::string descriptorName{"StridedSliceQueueDescriptor"}; |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1954 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1955 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 1956 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 1957 | |
| 1958 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1959 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1960 | |
| 1961 | std::vector<DataType> supportedTypes = |
| 1962 | { |
| 1963 | DataType::Float16, |
| 1964 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 1965 | DataType::QuantisedAsymm8, |
| 1966 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1967 | }; |
| 1968 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1969 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 1970 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1971 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1972 | ValidateTensorQuantizationSpace(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1973 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1974 | const uint32_t rank = inputTensorInfo.GetNumDimensions(); |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1975 | if (rank > 4) |
| 1976 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1977 | 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] | 1978 | } |
| 1979 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1980 | // Begin, End & Stride length must be of rank(input0) |
| 1981 | if (m_Parameters.m_Begin.size() != rank) |
| 1982 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1983 | 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] | 1984 | } |
| 1985 | |
| 1986 | if (m_Parameters.m_End.size() != rank) |
| 1987 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1988 | 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] | 1989 | } |
| 1990 | |
| 1991 | if (m_Parameters.m_Stride.size() != rank) |
| 1992 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 1993 | 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] | 1994 | } |
| 1995 | |
| 1996 | // Stride entries must be non-zero |
| 1997 | for (auto& stride : m_Parameters.m_Stride) |
| 1998 | { |
| 1999 | if (stride == 0) |
| 2000 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2001 | throw InvalidArgumentException(descriptorName + ": Stride entries must be non-zero."); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2006 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2007 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2008 | const std::string descriptorName{"MinimumQueueDescriptor"}; |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2009 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2010 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2011 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2012 | |
| 2013 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2014 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2015 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2016 | |
| 2017 | std::vector<DataType> supportedTypes = |
| 2018 | { |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2019 | DataType::Float16, |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2020 | DataType::Float32, |
Mike Kelly | 1da0236 | 2019-08-01 08:43:57 +0100 | [diff] [blame] | 2021 | DataType::Signed32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2022 | DataType::QuantisedAsymm8, |
| 2023 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2024 | }; |
| 2025 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2026 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2027 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
| 2028 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 2029 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2030 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2031 | inputTensorInfo1, |
| 2032 | outputTensorInfo, |
| 2033 | descriptorName, |
| 2034 | "input_0", |
| 2035 | "input_1"); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 2038 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2039 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2040 | const std::string descriptorName{"DebugQueueDescriptor"}; |
| 2041 | |
| 2042 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2043 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2046 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2047 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2048 | const std::string descriptorName{"EqualQueueDescriptor"}; |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2049 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2050 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2051 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2052 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2053 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2054 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2055 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2056 | |
| 2057 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2058 | inputTensorInfo1, |
| 2059 | outputTensorInfo, |
| 2060 | descriptorName, |
| 2061 | "input_0", |
| 2062 | "input_1"); |
| 2063 | |
| 2064 | if (outputTensorInfo.GetDataType() != DataType::Boolean) |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2065 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2066 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Boolean."); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2067 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2070 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2071 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2072 | const std::string descriptorName{"GreaterQueueDescriptor"}; |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2073 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2074 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2075 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2076 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2077 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2078 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2079 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2080 | |
| 2081 | ValidateBroadcastTensorShapesMatch(inputTensorInfo0, |
| 2082 | inputTensorInfo1, |
| 2083 | outputTensorInfo, |
| 2084 | descriptorName, |
| 2085 | "input_0", |
| 2086 | "input_1"); |
| 2087 | |
| 2088 | if (outputTensorInfo.GetDataType() != DataType::Boolean) |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2089 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2090 | throw InvalidArgumentException(descriptorName + ": Output tensor type must be Boolean."); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 2091 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 2094 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2095 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2096 | const std::string descriptorName{"RsqrtQueueDescriptor"}; |
| 2097 | |
| 2098 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2099 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2100 | |
| 2101 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2102 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2103 | |
| 2104 | ValidateTensorShapesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 2105 | |
| 2106 | std::vector<DataType> supportedTypes = |
| 2107 | { |
| 2108 | DataType::Float16, |
| 2109 | DataType::Float32, |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 2110 | DataType::QuantisedAsymm8, |
| 2111 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 2112 | }; |
| 2113 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2114 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2115 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2118 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2119 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2120 | const std::string descriptorName{"GatherQueueDescriptor"}; |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2121 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2122 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2123 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2124 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2125 | const TensorInfo& indicesTensorInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2126 | if (indicesTensorInfo.GetDataType() != DataType::Signed32) |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2127 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2128 | throw InvalidArgumentException(descriptorName + ": Indices tensor type must be Int32."); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2131 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2132 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2133 | |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2134 | std::vector<DataType> supportedTypes = |
| 2135 | { |
| 2136 | DataType::Float16, |
| 2137 | DataType::Float32, |
| 2138 | DataType::QuantisedAsymm8, |
| 2139 | DataType::QuantisedSymm16 |
| 2140 | }; |
| 2141 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2142 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2143 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2144 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output"); |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 2145 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2146 | unsigned int outputDim = inputTensorInfo.GetNumDimensions() + indicesTensorInfo.GetNumDimensions() - 1; |
| 2147 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2150 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2151 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2152 | const std::string& descriptorName{"DetectionPostProcessQueueDescriptor"}; |
| 2153 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2154 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2155 | |
| 2156 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 2157 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2158 | throw InvalidArgumentException(descriptorName + ": Requires exactly four outputs. " + |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2159 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 2160 | } |
| 2161 | |
| 2162 | if (m_Anchors == nullptr) |
| 2163 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2164 | throw InvalidArgumentException(descriptorName + ": Anchors tensor descriptor is missing."); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2168 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2169 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 2170 | |
| 2171 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 2172 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2173 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
| 2174 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2175 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2176 | ValidateTensorNumDimensions(boxEncodingsInfo, descriptorName, 3, "box encodings"); |
| 2177 | ValidateTensorNumDimensions(scoresInfo, descriptorName, 3, "scores"); |
| 2178 | ValidateTensorNumDimensions(anchorsInfo, descriptorName, 2, "anchors"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2179 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2180 | const std::vector<DataType> supportedInputTypes = |
| 2181 | { |
| 2182 | DataType::Float32, |
| 2183 | DataType::QuantisedAsymm8, |
| 2184 | DataType::QuantisedSymm16 |
| 2185 | }; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2186 | |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2187 | ValidateDataTypes(boxEncodingsInfo, supportedInputTypes, descriptorName); |
| 2188 | ValidateDataTypes(scoresInfo, supportedInputTypes, descriptorName); |
| 2189 | ValidateDataTypes(anchorsInfo, supportedInputTypes, descriptorName); |
| 2190 | |
| 2191 | ValidateTensorNumDimensions(detectionBoxesInfo, descriptorName, 3, "detection boxes"); |
| 2192 | ValidateTensorNumDimensions(detectionScoresInfo, descriptorName, 2, "detection scores"); |
| 2193 | ValidateTensorNumDimensions(detectionClassesInfo, descriptorName, 2, "detection classes"); |
| 2194 | ValidateTensorNumDimensions(numDetectionsInfo, descriptorName, 1, "num detections"); |
| 2195 | |
| 2196 | // NOTE: Output is always Float32 regardless of input type |
| 2197 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, descriptorName, "detection boxes"); |
| 2198 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, descriptorName, "detection scores"); |
| 2199 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, descriptorName, "detection classes"); |
| 2200 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, descriptorName, "num detections"); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2201 | |
| 2202 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 2203 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2204 | throw InvalidArgumentException(descriptorName + ": Intersection over union threshold " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2205 | "must be positive and less than or equal to 1."); |
| 2206 | } |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2207 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2208 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 2209 | { |
Aron Virginas-Tar | 6331f91 | 2019-06-03 17:10:02 +0100 | [diff] [blame] | 2210 | throw InvalidArgumentException(descriptorName + ": Number of classes with background " |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 2211 | "should be equal to number of classes + 1."); |
| 2212 | } |
| 2213 | } |
| 2214 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2215 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2216 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2217 | const std::string& descriptorName{"DequantizeQueueDescriptor"}; |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2218 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2219 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2220 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2221 | |
| 2222 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2223 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2224 | |
| 2225 | if (inputTensorInfo.GetDataType() != DataType::QuantisedAsymm8 && |
| 2226 | inputTensorInfo.GetDataType() != DataType::QuantisedSymm16) |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2227 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2228 | throw InvalidArgumentException(descriptorName + ": Input to dequantize layer must be quantized type."); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2231 | std::vector<DataType> supportedTypes = |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2232 | { |
Sadik Armagan | 2208b60 | 2019-07-31 16:36:27 +0100 | [diff] [blame] | 2233 | DataType::Float32, |
| 2234 | DataType::Float16 |
| 2235 | }; |
| 2236 | |
| 2237 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2240 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2241 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2242 | const std::string& descriptorName{"MergeQueueDescriptor"}; |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2243 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2244 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2245 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2246 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2247 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2248 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2249 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2250 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2251 | ValidateTensorShapesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 2252 | ValidateTensorShapesMatch(inputTensorInfo0, outputTensorInfo, descriptorName, "input_0", "output"); |
| 2253 | |
| 2254 | ValidateTensorDataTypesMatch(inputTensorInfo0, inputTensorInfo1, descriptorName, "input_0", "input_1"); |
| 2255 | ValidateTensorDataTypesMatch(inputTensorInfo0, outputTensorInfo, descriptorName, "input_0", "output"); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2258 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2259 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2260 | const std::string& descriptorName{"SwitchQueueDescriptor"}; |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2261 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2262 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2263 | ValidateNumOutputs(workloadInfo, descriptorName, 2); |
| 2264 | |
| 2265 | const TensorInfo& inputTensorInfo0 = workloadInfo.m_InputTensorInfos[0]; |
| 2266 | const TensorInfo& inputTensorInfo1 = workloadInfo.m_InputTensorInfos[1]; |
| 2267 | |
| 2268 | const TensorInfo& outputTensorInfo0 = workloadInfo.m_OutputTensorInfos[0]; |
| 2269 | const TensorInfo& outputTensorInfo1 = workloadInfo.m_OutputTensorInfos[1]; |
| 2270 | |
| 2271 | std::vector<DataType> supportedTypes = |
| 2272 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2273 | DataType::Float32, |
| 2274 | DataType::QuantisedAsymm8, |
| 2275 | DataType::QuantisedSymm16 |
| 2276 | }; |
| 2277 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2278 | ValidateDataTypes(inputTensorInfo0, supportedTypes, descriptorName); |
| 2279 | ValidateDataTypes(inputTensorInfo1, supportedTypes, descriptorName); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2280 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2281 | ValidateDataTypes(outputTensorInfo0, supportedTypes, descriptorName); |
| 2282 | ValidateDataTypes(outputTensorInfo1, supportedTypes, descriptorName); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2283 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2284 | ValidateTensorShapesMatch(inputTensorInfo0, |
| 2285 | outputTensorInfo0, |
| 2286 | descriptorName, |
| 2287 | "input_0", |
| 2288 | "output_0"); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2289 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2290 | ValidateTensorShapesMatch(inputTensorInfo0, |
| 2291 | outputTensorInfo1, |
| 2292 | descriptorName, |
| 2293 | "input_0", |
| 2294 | "output_1"); |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 2297 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2298 | { |
| 2299 | // This is internally generated so it should not need validation. |
| 2300 | } |
| 2301 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2302 | void PreluQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2303 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2304 | const std::string& descriptorName{"PreluQueueDescriptor"}; |
| 2305 | |
| 2306 | ValidateNumInputs(workloadInfo, descriptorName, 2); |
| 2307 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2308 | |
| 2309 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2310 | const TensorInfo& alphaTensorInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2311 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2312 | |
| 2313 | std::vector<DataType> supportedTypes |
| 2314 | { |
| 2315 | DataType::Float16, |
| 2316 | DataType::Float32, |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2317 | DataType::QuantisedAsymm8, |
| 2318 | DataType::QuantisedSymm16 |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2319 | }; |
| 2320 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2321 | ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName); |
| 2322 | ValidateDataTypes(alphaTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2323 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2324 | ValidateDataTypes(outputTensorInfo, supportedTypes, descriptorName); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2325 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2326 | ValidateTensorDataTypesMatch(inputTensorInfo, alphaTensorInfo, descriptorName, "input", "alpha"); |
| 2327 | ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "ouptut"); |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2328 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2329 | ValidateBroadcastTensorShapesMatch(inputTensorInfo, |
| 2330 | alphaTensorInfo, |
| 2331 | outputTensorInfo, |
| 2332 | descriptorName, |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 2333 | "input", |
| 2334 | "alpha"); |
| 2335 | } |
| 2336 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2337 | void TransposeConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2338 | { |
| 2339 | const std::string descriptorName{"TransposeConvolution2dQueueDescriptor"}; |
| 2340 | |
| 2341 | ValidateNumInputs(workloadInfo, descriptorName, 1); |
| 2342 | ValidateNumOutputs(workloadInfo, descriptorName, 1); |
| 2343 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2344 | const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2345 | const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2346 | |
| 2347 | ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input"); |
| 2348 | ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2349 | |
| 2350 | ValidatePointer(m_Weight, descriptorName, "weight"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2351 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2352 | const TensorInfo& weightTensorInfo = m_Weight->GetTensorInfo(); |
| 2353 | ValidateTensorNumDimensions(weightTensorInfo, descriptorName, 4, "weight"); |
| 2354 | ValidateTensorDataType(weightTensorInfo, inputTensorInfo.GetDataType(), descriptorName, "weight"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2355 | |
| 2356 | if (m_Parameters.m_BiasEnabled) |
| 2357 | { |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2358 | ValidatePointer(m_Bias, descriptorName, "bias"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2359 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2360 | const TensorInfo& biasTensorInfo = m_Bias->GetTensorInfo(); |
| 2361 | ValidateTensorNumDimensions(biasTensorInfo, descriptorName, 1, "bias"); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2362 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2363 | ValidateTensorDataType(biasTensorInfo, |
| 2364 | GetBiasDataType(inputTensorInfo.GetDataType()), |
| 2365 | descriptorName, |
| 2366 | "bias"); |
| 2367 | |
| 2368 | ValidateBiasTensorQuantization(biasTensorInfo, inputTensorInfo, weightTensorInfo, descriptorName); |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2369 | } |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 2370 | } |
| 2371 | |
James Conroy | 9c3cae8 | 2019-08-01 16:01:48 +0100 | [diff] [blame] | 2372 | void QuantizedLstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 2373 | { |
| 2374 | const std::string descriptorName{"QuantizedLstmQueueDescriptor"}; |
| 2375 | |
| 2376 | // Validate number of inputs/outputs |
| 2377 | ValidateNumInputs(workloadInfo, descriptorName, 3); |
| 2378 | ValidateNumOutputs(workloadInfo, descriptorName, 2); |
| 2379 | |
| 2380 | // Input/output tensor infos |
| 2381 | auto inputInfo = workloadInfo.m_InputTensorInfos[0]; |
| 2382 | auto cellStateInInfo = workloadInfo.m_InputTensorInfos[1]; |
| 2383 | auto outputStateInInfo = workloadInfo.m_InputTensorInfos[2]; |
| 2384 | |
| 2385 | auto cellStateOutInfo = workloadInfo.m_OutputTensorInfos[0]; |
| 2386 | auto outputStateOutInfo = workloadInfo.m_OutputTensorInfos[1]; |
| 2387 | |
| 2388 | std::vector<DataType> inputOutputSupportedTypes = |
| 2389 | { |
| 2390 | DataType::QuantisedAsymm8 |
| 2391 | }; |
| 2392 | |
| 2393 | std::vector<DataType> cellStateSupportedTypes = |
| 2394 | { |
| 2395 | DataType::QuantisedSymm16 |
| 2396 | }; |
| 2397 | |
| 2398 | std::vector<DataType> weightsSupportedTypes = |
| 2399 | { |
| 2400 | DataType::QuantisedAsymm8 |
| 2401 | }; |
| 2402 | |
| 2403 | std::vector<DataType> biasSupportedTypes = |
| 2404 | { |
| 2405 | DataType::Signed32 |
| 2406 | }; |
| 2407 | |
| 2408 | // Validate types of input/output tensors |
| 2409 | ValidateDataTypes(inputInfo, inputOutputSupportedTypes, descriptorName); |
| 2410 | ValidateDataTypes(cellStateInInfo, cellStateSupportedTypes, descriptorName); |
| 2411 | ValidateDataTypes(outputStateInInfo, inputOutputSupportedTypes, descriptorName); |
| 2412 | |
| 2413 | ValidateDataTypes(cellStateOutInfo, cellStateSupportedTypes, descriptorName); |
| 2414 | ValidateDataTypes(outputStateOutInfo, inputOutputSupportedTypes, descriptorName); |
| 2415 | |
| 2416 | // Validate matching types of input/output tensors |
| 2417 | ValidateTensorDataTypesMatch(inputInfo, outputStateInInfo, descriptorName, "input", "outputStateIn"); |
| 2418 | ValidateTensorDataTypesMatch(outputStateInInfo, outputStateOutInfo, descriptorName, |
| 2419 | "outputStateIn", "outputStateOut"); |
| 2420 | ValidateTensorDataTypesMatch(cellStateInInfo, cellStateOutInfo, descriptorName, "cellStateIn", "cellStateOut"); |
| 2421 | |
| 2422 | // Validate matching quantization info for input/output tensors |
| 2423 | ValidateTensorQuantizationSpace(inputInfo, outputStateInInfo, descriptorName, "input", "outputStateIn"); |
| 2424 | ValidateTensorQuantizationSpace(inputInfo, outputStateOutInfo, descriptorName, "input", "outputStateOut"); |
| 2425 | ValidateTensorQuantizationSpace(cellStateInInfo, cellStateOutInfo, descriptorName, "cellStateIn", "cellStateOut"); |
| 2426 | |
| 2427 | // Infer number of batches, input size and output size from tensor dimensions |
| 2428 | const uint32_t numBatches = inputInfo.GetShape()[0]; |
| 2429 | const uint32_t inputSize = inputInfo.GetShape()[1]; |
| 2430 | const uint32_t outputSize = cellStateInInfo.GetShape()[1]; |
| 2431 | |
| 2432 | // Validate number of dimensions and number of elements for input/output tensors |
| 2433 | ValidateTensorNumDimNumElem(inputInfo, 2, (numBatches * inputSize), descriptorName + " input"); |
| 2434 | ValidateTensorNumDimNumElem(cellStateInInfo, 2, (numBatches * outputSize), descriptorName + " cellStateIn"); |
| 2435 | ValidateTensorNumDimNumElem(outputStateInInfo, 2, (numBatches * outputSize), descriptorName + " outputStateIn"); |
| 2436 | ValidateTensorNumDimNumElem(cellStateOutInfo, 2, (numBatches * outputSize), descriptorName + " cellStateOut"); |
| 2437 | ValidateTensorNumDimNumElem(outputStateOutInfo, 2, (numBatches * outputSize), descriptorName + " outputStateOut"); |
| 2438 | |
| 2439 | // Validate number of dimensions and number of elements for weights tensors |
| 2440 | ValidatePointer(m_InputToInputWeights, descriptorName, "InputToInputWeights"); |
| 2441 | auto inputToInputWeightsInfo = m_InputToInputWeights->GetTensorInfo(); |
| 2442 | ValidateTensorNumDimNumElem(inputToInputWeightsInfo, 2, (outputSize * inputSize), " InputToInputWeights"); |
| 2443 | |
| 2444 | ValidatePointer(m_InputToForgetWeights, descriptorName, "InputToForgetWeights"); |
| 2445 | auto inputToForgetWeightsInfo = m_InputToForgetWeights->GetTensorInfo(); |
| 2446 | ValidateTensorNumDimNumElem(inputToForgetWeightsInfo, 2, (outputSize * inputSize), " InputToForgetWeights"); |
| 2447 | |
| 2448 | ValidatePointer(m_InputToCellWeights, descriptorName, "InputToCellWeights"); |
| 2449 | auto inputToCellWeightsInfo = m_InputToCellWeights->GetTensorInfo(); |
| 2450 | ValidateTensorNumDimNumElem(inputToCellWeightsInfo, 2, (outputSize * inputSize), " InputToCellWeights"); |
| 2451 | |
| 2452 | ValidatePointer(m_InputToOutputWeights, descriptorName, "InputToOutputWeights"); |
| 2453 | auto inputToOutputWeightsInfo = m_InputToOutputWeights->GetTensorInfo(); |
| 2454 | ValidateTensorNumDimNumElem(inputToOutputWeightsInfo, 2, (outputSize * inputSize), " InputToOutputWeights"); |
| 2455 | |
| 2456 | ValidatePointer(m_RecurrentToInputWeights, descriptorName, "RecurrentToInputWeights"); |
| 2457 | auto recurrentToInputWeightsInfo = m_RecurrentToInputWeights->GetTensorInfo(); |
| 2458 | ValidateTensorNumDimNumElem(recurrentToInputWeightsInfo, 2, (outputSize * outputSize), " RecurrentToInputWeights"); |
| 2459 | |
| 2460 | ValidatePointer(m_RecurrentToForgetWeights, descriptorName, "RecurrentToForgetWeights"); |
| 2461 | auto recurrentToForgetWeightsInfo = m_RecurrentToForgetWeights->GetTensorInfo(); |
| 2462 | ValidateTensorNumDimNumElem(recurrentToForgetWeightsInfo, 2, (outputSize * outputSize), |
| 2463 | " RecurrentToForgetWeights"); |
| 2464 | |
| 2465 | ValidatePointer(m_RecurrentToCellWeights, descriptorName, "RecurrentToCellWeights"); |
| 2466 | auto recurrentToCellWeightsInfo = m_RecurrentToCellWeights->GetTensorInfo(); |
| 2467 | ValidateTensorNumDimNumElem(recurrentToCellWeightsInfo, 2, (outputSize * outputSize), " RecurrentToCellWeights"); |
| 2468 | |
| 2469 | ValidatePointer(m_RecurrentToOutputWeights, descriptorName, "RecurrentToOutputWeights"); |
| 2470 | auto recurrentToOutputWeightsInfo = m_RecurrentToOutputWeights->GetTensorInfo(); |
| 2471 | ValidateTensorNumDimNumElem(recurrentToOutputWeightsInfo, 2, (outputSize * outputSize), " RecurrentToCellWeights"); |
| 2472 | |
| 2473 | // Validate data types for weights tensors (all should match each other) |
| 2474 | ValidateDataTypes(inputToInputWeightsInfo, weightsSupportedTypes, descriptorName); |
| 2475 | |
| 2476 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToForgetWeightsInfo, descriptorName, |
| 2477 | "inputToInputWeights", "inputToForgetWeights"); |
| 2478 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToCellWeightsInfo, descriptorName, |
| 2479 | "inputToInputWeights", "inputToCellWeights"); |
| 2480 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, inputToOutputWeightsInfo, descriptorName, |
| 2481 | "inputToInputWeights", "inputToOutputWeights"); |
| 2482 | |
| 2483 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToInputWeightsInfo, descriptorName, |
| 2484 | "inputToInputWeights", "recurrentToInputWeights"); |
| 2485 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToForgetWeightsInfo, descriptorName, |
| 2486 | "inputToInputWeights", "recurrentToForgeteights"); |
| 2487 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToCellWeightsInfo, descriptorName, |
| 2488 | "inputToInputWeights", "recurrentToCellWeights"); |
| 2489 | ValidateTensorDataTypesMatch(inputToInputWeightsInfo, recurrentToOutputWeightsInfo, descriptorName, |
| 2490 | "inputToInputWeights", "recurrentToOutputWeights"); |
| 2491 | |
| 2492 | // Validate matching quantization info for weight tensors (all should match each other) |
| 2493 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToForgetWeightsInfo, |
| 2494 | descriptorName, "inputToInputWeights", "inputToForgetWeights"); |
| 2495 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToCellWeightsInfo, |
| 2496 | descriptorName, "inputToInputWeights", "inputToCellWeights"); |
| 2497 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, inputToOutputWeightsInfo, |
| 2498 | descriptorName, "inputToInputWeights", "inputToOutputWeights"); |
| 2499 | |
| 2500 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToInputWeightsInfo, |
| 2501 | descriptorName, "inputToInputWeights", "recurrentToInputWeights"); |
| 2502 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToForgetWeightsInfo, |
| 2503 | descriptorName, "inputToInputWeights", "recurrentToForgetWeights"); |
| 2504 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToCellWeightsInfo, |
| 2505 | descriptorName, "inputToInputWeights", "recurrentToCellWeights"); |
| 2506 | ValidateTensorQuantizationSpace(inputToInputWeightsInfo, recurrentToOutputWeightsInfo, |
| 2507 | descriptorName, "inputToInputWeights", "recurrentToOutputWeights"); |
| 2508 | |
| 2509 | // Validate number of dimensions and number of elements in bias tensors |
| 2510 | ValidatePointer(m_InputGateBias, descriptorName, "InputGateBias"); |
| 2511 | auto inputGateBiasInfo = m_InputGateBias->GetTensorInfo(); |
| 2512 | ValidateTensorNumDimNumElem(inputGateBiasInfo, 1, outputSize, " InputGateBias"); |
| 2513 | |
| 2514 | ValidatePointer(m_ForgetGateBias, descriptorName, "ForgetGateBias"); |
| 2515 | auto forgetGateBiasInfo = m_ForgetGateBias->GetTensorInfo(); |
| 2516 | ValidateTensorNumDimNumElem(forgetGateBiasInfo, 1, outputSize, " ForgetGateBias"); |
| 2517 | |
| 2518 | ValidatePointer(m_CellBias, descriptorName, "CellBias"); |
| 2519 | auto cellBiasInfo = m_CellBias->GetTensorInfo(); |
| 2520 | ValidateTensorNumDimNumElem(cellBiasInfo, 1, outputSize, " CellBias"); |
| 2521 | |
| 2522 | ValidatePointer(m_OutputGateBias, descriptorName, "OutputGateBias"); |
| 2523 | auto outputGateBiasInfo = m_OutputGateBias->GetTensorInfo(); |
| 2524 | ValidateTensorNumDimNumElem(outputGateBiasInfo, 1, outputSize, " OutputGateBias"); |
| 2525 | |
| 2526 | // Validate data types for bias tensors (all should match each other) |
| 2527 | ValidateDataTypes(inputGateBiasInfo, biasSupportedTypes, descriptorName); |
| 2528 | |
| 2529 | ValidateTensorDataTypesMatch(inputGateBiasInfo, forgetGateBiasInfo, descriptorName, |
| 2530 | "inputGateBias", "forgetGateBias"); |
| 2531 | ValidateTensorDataTypesMatch(inputGateBiasInfo, cellBiasInfo, descriptorName, |
| 2532 | "inputGateBias", "cellBias"); |
| 2533 | ValidateTensorDataTypesMatch(inputGateBiasInfo, outputGateBiasInfo, descriptorName, |
| 2534 | "inputGateBias", "outputGateBias"); |
| 2535 | |
| 2536 | // Validate bias tensor quantization info |
| 2537 | ValidateBiasTensorQuantization(inputGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2538 | ValidateBiasTensorQuantization(forgetGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2539 | ValidateBiasTensorQuantization(cellBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2540 | ValidateBiasTensorQuantization(outputGateBiasInfo, inputInfo, inputToInputWeightsInfo, descriptorName); |
| 2541 | } |
| 2542 | |
Aron Virginas-Tar | 84062b7 | 2019-07-19 11:37:10 +0100 | [diff] [blame] | 2543 | } // namespace armnn |