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