telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #include "WorkloadData.hpp" |
| 6 | |
| 7 | #include "CpuTensorHandle.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 9 | #include <DataLayoutIndexed.hpp> |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 10 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <algorithm> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 12 | #include <iomanip> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <sstream> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | #include <boost/format.hpp> |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 17 | #include <boost/numeric/conversion/cast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 19 | using namespace armnnUtils; |
| 20 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | namespace armnn |
| 22 | { |
| 23 | |
| 24 | //--------------------------------------------------------------- |
| 25 | DataType GetBiasDataType(DataType inputDataType) |
| 26 | { |
| 27 | switch (inputDataType) |
| 28 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | case DataType::Float16: |
| 30 | return DataType::Float16; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | case DataType::Float32: |
| 32 | return DataType::Float32; |
| 33 | case DataType::QuantisedAsymm8: |
| 34 | return DataType::Signed32; |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 35 | case DataType::QuantisedSymm16: |
| 36 | return DataType::Signed32; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | default: |
| 38 | BOOST_ASSERT_MSG(false, "Invalid input data type"); |
| 39 | return DataType::Float32; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | namespace |
| 44 | { |
| 45 | |
| 46 | //--------------------------------------------------------------- |
| 47 | //android ndk does not support std::to_string function. |
| 48 | template <typename T> |
| 49 | std::string to_string(T value) |
| 50 | { |
| 51 | std::ostringstream os; |
| 52 | os << value; |
| 53 | return os.str(); |
| 54 | } |
| 55 | |
| 56 | //--------------------------------------------------------------- |
| 57 | void ValidatePointer(const void* ptr, std::string const& descName, std::string const& paramName) |
| 58 | { |
| 59 | if (!ptr) |
| 60 | { |
| 61 | throw InvalidArgumentException(descName + ": Invalid null pointer. The " + |
| 62 | paramName + " parameter must be set."); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | //--------------------------------------------------------------- |
| 67 | void ValidateTensorShapesMatch(const TensorInfo& first, |
| 68 | const TensorInfo& second, |
| 69 | std::string const& descName, |
| 70 | std::string const& firstName, |
| 71 | std::string const& secondName) |
| 72 | { |
| 73 | if (first.GetShape() != second.GetShape()) |
| 74 | { |
| 75 | throw InvalidArgumentException(descName + ": " |
| 76 | + firstName + " & " + secondName + " must have identical shapes"); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 81 | void ValidateNumInputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 83 | if (workloadInfo.m_InputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 84 | { |
| 85 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 86 | ": Requires exactly " + to_string(expectedSize) + "input(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 87 | to_string(workloadInfo.m_InputTensorInfos.size()) + " have been provided."); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | //--------------------------------------------------------------- |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 92 | void ValidateNumOutputs(const WorkloadInfo& workloadInfo, std::string const& descName, const unsigned int expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 94 | if (workloadInfo.m_OutputTensorInfos.size() != expectedSize) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | { |
| 96 | throw InvalidArgumentException(descName + |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 97 | ": Requires exactly " + to_string(expectedSize) + " output(s). " + |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 98 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | //--------------------------------------------------------------- |
| 103 | void ValidateTensorNumDimensions(const TensorInfo& tensor, |
| 104 | std::string const& descName, |
| 105 | unsigned int numDimensions, |
| 106 | std::string const& tensorName) |
| 107 | { |
| 108 | if (tensor.GetNumDimensions() != numDimensions) |
| 109 | { |
| 110 | throw InvalidArgumentException(descName + ": Expected " + to_string(numDimensions) + " but got " + |
| 111 | to_string(tensor.GetNumDimensions()) + " dimensions for " + |
| 112 | tensorName + " tensor."); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | //--------------------------------------------------------------- |
| 117 | void ValidateTensorDataType(const TensorInfo& tensor, DataType dataType, |
| 118 | const std::string& descName, std::string const& tensorName) |
| 119 | { |
| 120 | if (tensor.GetDataType() != dataType) |
| 121 | { |
| 122 | throw InvalidArgumentException(descName + ": Expected data type " + GetDataTypeName(dataType) + " but got " + |
| 123 | GetDataTypeName(tensor.GetDataType()) + " for " + tensorName + " tensor."); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | //--------------------------------------------------------------- |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 128 | void ValidateTensorQuantizationSpace(const TensorInfo& first, |
| 129 | const TensorInfo& second, |
| 130 | const std::string& descName, |
| 131 | std::string const& firstName, |
| 132 | std::string const& secondName) |
| 133 | { |
| 134 | if (!first.IsQuantized() || |
| 135 | !second.IsQuantized()) |
| 136 | { |
| 137 | // Not a quantized type, ignore the validation |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | DataType firstDataType = first.GetDataType(); |
| 142 | DataType secondDataType = second.GetDataType(); |
| 143 | |
| 144 | if (firstDataType != secondDataType) |
| 145 | { |
| 146 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 147 | " must be of the same quantized type, " + |
| 148 | firstName + " is " + GetDataTypeName(firstDataType) + ", " + |
| 149 | secondName + " is " + GetDataTypeName(secondDataType)); |
| 150 | } |
| 151 | |
| 152 | if (!first.IsTypeSpaceMatch(second)) |
| 153 | { |
| 154 | throw InvalidArgumentException(descName + ": " + firstName + " and " + secondName + |
| 155 | " must have the same quantization space, " + |
| 156 | firstName + " has offset " + to_string(first.GetQuantizationOffset()) + |
| 157 | " and scale " + to_string(first.GetQuantizationScale()) + ", " + |
| 158 | secondName + " has offset " + to_string(second.GetQuantizationOffset()) + |
| 159 | " and scale " + to_string(second.GetQuantizationScale())); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | //--------------------------------------------------------------- |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 164 | void ValidateBiasTensorQuantization(const TensorInfo& biasTensor, const TensorInfo& inputTensorInfo, |
| 165 | const TensorInfo& weightsTensorInfo, const std::string& descName) |
| 166 | { |
| 167 | if (biasTensor.GetQuantizationOffset() != 0) |
| 168 | { |
| 169 | throw InvalidArgumentException(descName + ": Expected zero quantization offset for bias tensor but got " + |
| 170 | to_string(biasTensor.GetQuantizationOffset())); |
| 171 | } |
| 172 | const float expectedScale = inputTensorInfo.GetQuantizationScale() * weightsTensorInfo.GetQuantizationScale(); |
kevmay01 | 6c46dd3 | 2018-12-17 15:32:45 +0000 | [diff] [blame] | 173 | if (std::abs(biasTensor.GetQuantizationScale() - expectedScale) > 0.00000001f) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 174 | { |
| 175 | // Print the float values with extra precision to see very small differences |
| 176 | std::stringstream msg; |
| 177 | msg << std::setprecision(10) << descName << ": Expected " << expectedScale << |
| 178 | " quantization scale for bias tensor (the product of the input and weight scales), but got " << |
| 179 | biasTensor.GetQuantizationScale(); |
| 180 | throw InvalidArgumentException(msg.str()); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | //--------------------------------------------------------------- |
| 185 | void ValidateTensors(const std::vector<ITensorHandle*>& vec, |
| 186 | unsigned int numExpected, |
| 187 | const std::string& descName, |
| 188 | const std::string& varName) |
| 189 | { |
| 190 | if (vec.empty() && numExpected > 0) |
| 191 | { |
| 192 | throw InvalidArgumentException(descName + ": Invalid empty " + varName + " array."); |
| 193 | } |
| 194 | |
| 195 | for (unsigned int i = 0; i < numExpected; ++i) |
| 196 | { |
| 197 | if (!vec[i]) |
| 198 | { |
| 199 | throw InvalidArgumentException(descName + ": Invalid NULL for " + varName + to_string(i)); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | //--------------------------------------------------------------- |
| 205 | void ValidateBroadcastTensorShapesMatch(const TensorInfo& first, |
| 206 | const TensorInfo& second, |
| 207 | const TensorInfo& output, |
| 208 | std::string const& descName, |
| 209 | std::string const& firstName, |
| 210 | std::string const& secondName) |
| 211 | { |
| 212 | // Tensors must have the same number of dimensions in order to be explicit about which dimensions will get |
| 213 | // broadcasted. |
| 214 | if (first.GetNumDimensions() != second.GetNumDimensions()) |
| 215 | { |
| 216 | throw InvalidArgumentException(descName + ": Tensors " |
| 217 | + firstName + " & " + secondName |
| 218 | + " must have the same number of dimensions in order to be broadcasted"); |
| 219 | } |
| 220 | uint32_t numDims = first.GetNumDimensions(); |
| 221 | std::vector<uint32_t> outputDims(numDims, 0u); |
| 222 | for (uint32_t i = 0; i < numDims; i++) |
| 223 | { |
| 224 | const bool dimsNotEqual = first.GetShape()[i] != second.GetShape()[i]; |
| 225 | const bool dimsNotOne = (first.GetShape()[i] != 1) && (second.GetShape()[i] != 1); |
| 226 | if (dimsNotEqual && dimsNotOne) |
| 227 | { |
| 228 | throw InvalidArgumentException("Broadcasting is not possible for incompatible shapes"); |
| 229 | } |
| 230 | outputDims[i] = std::max(first.GetShape()[i], second.GetShape()[i]); |
| 231 | } |
| 232 | TensorShape broadcastShape = TensorShape(boost::numeric_cast<unsigned int>(outputDims.size()), outputDims.data()); |
| 233 | if (broadcastShape != output.GetShape()) |
| 234 | { |
| 235 | throw InvalidArgumentException(descName + ": The tensor shape resulting from adding " |
| 236 | + firstName + " & " + secondName |
| 237 | + " does not match the output shape"); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | //--------------------------------------------------------------- |
| 242 | /// Validates that the output tensor's quantization scale is greater than the product |
| 243 | /// of the two input tensors' quantization scales. This is a requirement of the implementation of |
| 244 | /// the quantized multiplication. |
| 245 | void ValidateTensorQuantizationMultiplier(const TensorInfo& inputTensor1, const TensorInfo& inputTensor2, |
| 246 | const TensorInfo& outputTensorInfo, std::string const& descName, |
| 247 | const std::string& inputTensor1Name, const std::string& inputTensor2Name, const std::string& outputTensorName) |
| 248 | { |
| 249 | if (outputTensorInfo.GetDataType() == DataType::QuantisedAsymm8) |
| 250 | { |
| 251 | if (outputTensorInfo.GetQuantizationScale() <= |
| 252 | inputTensor1.GetQuantizationScale() * inputTensor2.GetQuantizationScale()) |
| 253 | { |
| 254 | std::stringstream msg; |
| 255 | msg << descName << ": Quantization scale of " << outputTensorName << " is not greater than " << |
| 256 | "the product of the " << inputTensor1Name << " and " << inputTensor2Name << " tensors"; |
| 257 | throw InvalidArgumentException(msg.str()); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 262 | //--------------------------------------------------------------- |
| 263 | void ValidateDataTypes(const TensorInfo& info, |
| 264 | const std::vector<armnn::DataType>& supportedTypes, |
| 265 | std::string const& descName) |
| 266 | { |
| 267 | auto iterator = std::find(supportedTypes.begin(), supportedTypes.end(), info.GetDataType()); |
| 268 | if (iterator == supportedTypes.end()) |
| 269 | { |
| 270 | throw InvalidArgumentException(descName + ": " + " Tensor type is not supported."); |
| 271 | } |
| 272 | } |
| 273 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 274 | } //namespace |
| 275 | |
| 276 | void QueueDescriptor::ValidateInputsOutputs(const std::string& descName, |
| 277 | unsigned int numExpectedIn, unsigned int numExpectedOut) const |
| 278 | { |
| 279 | ValidateTensors(m_Inputs, numExpectedIn, descName, "input"); |
| 280 | ValidateTensors(m_Outputs, numExpectedOut, descName, "output"); |
| 281 | } |
| 282 | |
| 283 | //--------------------------------------------------------------- |
| 284 | void MemCopyQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 285 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 286 | ValidateNumInputs(workloadInfo, "MemCopyQueueDescriptor", 1); |
| 287 | ValidateNumOutputs(workloadInfo, "MemCopyQueueDescriptor" , 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 288 | |
| 289 | if (workloadInfo.m_InputTensorInfos.size() != workloadInfo.m_OutputTensorInfos.size()) |
| 290 | { |
| 291 | throw InvalidArgumentException(boost::str( |
| 292 | boost::format("Number of input infos (%1%) does not match the number of output infos (%2%)") |
| 293 | % workloadInfo.m_InputTensorInfos.size() % workloadInfo.m_OutputTensorInfos.size())); |
| 294 | } |
| 295 | |
| 296 | for (std::size_t i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 297 | { |
| 298 | if (workloadInfo.m_InputTensorInfos[i].GetNumElements() != |
| 299 | workloadInfo.m_OutputTensorInfos[i].GetNumElements()) |
| 300 | { |
| 301 | throw InvalidArgumentException(boost::str( |
| 302 | boost::format("Number of elements for tensor input and output %1% does not match") |
| 303 | % i )); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if (m_Inputs.size() != m_Outputs.size()) |
| 308 | { |
| 309 | throw InvalidArgumentException(boost::str( |
| 310 | boost::format("Number of inputs (%1%) does not match the number of outputs (%2%)") |
| 311 | % m_Inputs.size() % m_Outputs.size())); |
| 312 | } |
| 313 | |
| 314 | for (unsigned int i = 0; i < m_Inputs.size(); ++i) |
| 315 | { |
| 316 | if (!m_Inputs[i]) |
| 317 | { |
| 318 | throw InvalidArgumentException(boost::str(boost::format("Invalid null input %1%") % i)); |
| 319 | } |
| 320 | |
| 321 | if (!m_Outputs[i]) |
| 322 | { |
| 323 | throw InvalidArgumentException(boost::str(boost::format("Invalid null output %1%") % i)); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | //--------------------------------------------------------------- |
| 329 | void ActivationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 330 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 331 | ValidateNumInputs(workloadInfo, "ActivationQueueDescriptor", 1); |
| 332 | ValidateNumOutputs(workloadInfo, "ActivationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 333 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 334 | workloadInfo.m_OutputTensorInfos[0], |
| 335 | "ActivationQueueDescriptor", |
| 336 | "input", |
| 337 | "output"); |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 338 | |
| 339 | std::vector<DataType> supportedTypes = { |
| 340 | DataType::Float32, |
| 341 | DataType::Float16, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 342 | DataType::QuantisedAsymm8, |
| 343 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 347 | supportedTypes, |
| 348 | "ActivationQueueDescriptor"); |
| 349 | |
| 350 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 351 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 352 | "ActivationQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | //--------------------------------------------------------------- |
| 356 | void SoftmaxQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 357 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 358 | ValidateNumInputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
| 359 | ValidateNumOutputs(workloadInfo, "SoftmaxQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 360 | |
| 361 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 362 | workloadInfo.m_OutputTensorInfos[0], |
| 363 | "SoftmaxQueueDescriptor", |
| 364 | "input", |
| 365 | "output"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 366 | |
| 367 | std::vector<DataType> supportedTypes = |
| 368 | { |
| 369 | DataType::Float16, |
| 370 | DataType::Float32, |
| 371 | DataType::QuantisedAsymm8, |
| 372 | DataType::QuantisedSymm16 |
| 373 | }; |
| 374 | |
| 375 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 376 | supportedTypes, |
| 377 | "SoftmaxQueueDescriptor"); |
| 378 | |
| 379 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 380 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 381 | "SoftmaxQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | //--------------------------------------------------------------- |
| 385 | void SplitterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 386 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 387 | ValidateNumInputs(workloadInfo, "SplitterQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 388 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 389 | // Check the supported data types |
| 390 | std::vector<DataType> supportedTypes = |
| 391 | { |
| 392 | DataType::Float32, |
| 393 | DataType::Float16, |
| 394 | DataType::Boolean, |
| 395 | DataType::Signed32, |
| 396 | DataType::QuantisedAsymm8, |
| 397 | DataType::QuantisedSymm16 |
| 398 | }; |
| 399 | |
| 400 | for (unsigned long i = 0; i < workloadInfo.m_OutputTensorInfos.size(); ++i) |
| 401 | { |
| 402 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[i], |
| 403 | supportedTypes, |
| 404 | "SplitterQueueDescriptor"); |
| 405 | } |
| 406 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 407 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 408 | "SplitterQueueDescriptor"); |
| 409 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 410 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 411 | { |
| 412 | throw InvalidArgumentException("SplitterQueueDescriptor: At least one output needs to be provided."); |
| 413 | } |
| 414 | |
| 415 | if (workloadInfo.m_OutputTensorInfos.size() != m_ViewOrigins.size()) |
| 416 | { |
| 417 | throw InvalidArgumentException( |
| 418 | "SplitterQueueDescriptor: Number of split windows " |
| 419 | "has to match number of workloadInfo.m_OutputTensorInfos. " |
| 420 | "Number of windows: " + |
| 421 | to_string(m_ViewOrigins.size()) + |
| 422 | ". Number of workloadInfo.m_OutputTensorInfos: " + to_string(workloadInfo.m_OutputTensorInfos.size())); |
| 423 | } |
| 424 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 425 | //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] | 426 | std::size_t inputDims = workloadInfo.m_InputTensorInfos[0].GetNumDimensions(); |
| 427 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 428 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 429 | //Checks that the dimensionality of input is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 430 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 431 | if (e.m_Origin.size() != inputDims) |
| 432 | { |
| 433 | throw InvalidArgumentException("SplitterQueueDescriptor: Window origin have to " |
| 434 | "have the same dimensionality as the input tensor. " |
| 435 | "Window origin (index: " + |
| 436 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 437 | " dimensions, the input " |
| 438 | "tensor has " + |
| 439 | to_string(inputDims) + " dimensions."); |
| 440 | } |
| 441 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 442 | { |
| 443 | if (e.m_Origin[i] + workloadInfo.m_OutputTensorInfos[w].GetShape()[i] > |
| 444 | workloadInfo.m_InputTensorInfos[0].GetShape()[i]) |
| 445 | { |
| 446 | throw InvalidArgumentException("SplitterQueueDescriptor: Window extent coordinates have to " |
| 447 | "be smaller or equal than the size of the input in that coord."); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | //--------------------------------------------------------------- |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 454 | void ConcatQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 455 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 456 | ValidateNumOutputs(workloadInfo, "ConcatQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 457 | |
| 458 | if (m_Inputs.size() <= 0) |
| 459 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 460 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 461 | } |
| 462 | if (m_Outputs.size() <= 0) |
| 463 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 464 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | if (workloadInfo.m_InputTensorInfos.size() <= 0) |
| 468 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 469 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo input needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 470 | } |
| 471 | if (workloadInfo.m_OutputTensorInfos.size() <= 0) |
| 472 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 473 | throw InvalidArgumentException("ConcatQueueDescriptor: At least one TensorInfo output needs to be provided."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 476 | if(m_Parameters.GetConcatAxis() > workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions()) |
| 477 | { |
| 478 | throw InvalidArgumentException("Invalid Concatenation Axis provided"); |
| 479 | } |
| 480 | |
| 481 | if (workloadInfo.m_InputTensorInfos[0].GetShape().GetNumDimensions() - m_Parameters.GetConcatAxis() == 1) |
| 482 | { |
| 483 | return; |
| 484 | } |
| 485 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 486 | if (workloadInfo.m_InputTensorInfos.size() != m_ViewOrigins.size()) |
| 487 | { |
| 488 | throw InvalidArgumentException( |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 489 | "ConcatQueueDescriptor: Number of split windows " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 490 | "has to match number of workloadInfo.m_InputTensorInfos. " |
| 491 | "Number of windows: " + |
| 492 | to_string(m_ViewOrigins.size()) + |
| 493 | ". Number of workloadInfo.m_InputTensorInfos: " + to_string(workloadInfo.m_InputTensorInfos.size())); |
| 494 | } |
| 495 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 496 | //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] | 497 | std::size_t outputDims = workloadInfo.m_OutputTensorInfos[0].GetNumDimensions(); |
| 498 | for(unsigned int w = 0; w < m_ViewOrigins.size(); ++w ) |
| 499 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 500 | //Checks that the dimensionality of output is same as the split windows. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 501 | ViewOrigin const& e = m_ViewOrigins[w]; |
| 502 | if (e.m_Origin.size() != outputDims) |
| 503 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 504 | throw InvalidArgumentException("ConcatQueueDescriptor: Window origin have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 505 | "have the same dimensionality as the output tensor. " |
| 506 | "Window origin (index: " + |
| 507 | to_string(w) + ") has " + to_string(e.m_Origin.size()) + |
| 508 | " dimensions, the output " |
| 509 | "tensor has " + |
| 510 | to_string(outputDims) + " dimensions."); |
| 511 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 512 | //Checks that the merge windows are within the output tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 513 | for (unsigned int i = 0; i < e.m_Origin.size(); ++i) |
| 514 | { |
| 515 | if (e.m_Origin[i] + workloadInfo.m_InputTensorInfos[w].GetShape()[i] |
| 516 | > workloadInfo.m_OutputTensorInfos[0].GetShape()[i]) |
| 517 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 518 | throw InvalidArgumentException("ConcatQueueDescriptor: Window extent coordinates have to " |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 519 | "be smaller or equal than the size of the output in that coord."); |
| 520 | } |
| 521 | } |
| 522 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 523 | |
| 524 | // Check the supported data types |
| 525 | std::vector<DataType> supportedTypes = |
| 526 | { |
| 527 | DataType::Float32, |
| 528 | DataType::Float16, |
| 529 | DataType::Boolean, |
| 530 | DataType::Signed32, |
| 531 | DataType::QuantisedAsymm8, |
| 532 | DataType::QuantisedSymm16 |
| 533 | }; |
| 534 | |
| 535 | for (unsigned long i = 0; i < workloadInfo.m_InputTensorInfos.size(); ++i) |
| 536 | { |
| 537 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[i], |
| 538 | supportedTypes, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 539 | "ConcatQueueDescriptor"); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 540 | } |
| 541 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 542 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 543 | "ConcatQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | //--------------------------------------------------------------- |
| 547 | void FullyConnectedQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 548 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 549 | ValidateNumInputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
| 550 | ValidateNumOutputs(workloadInfo, "FullyConnectedQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 551 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", 2, "output"); |
| 552 | |
| 553 | if (!(workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 2 || |
| 554 | workloadInfo.m_InputTensorInfos[0].GetNumDimensions() == 4)) |
| 555 | { |
| 556 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Input tensor must have 2 or 4 dimensions."); |
| 557 | } |
| 558 | |
| 559 | if (m_Weight == nullptr) |
| 560 | { |
| 561 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Weight tensor descriptor is missing."); |
| 562 | } |
| 563 | |
| 564 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor", 2, "weight"); |
| 565 | |
| 566 | if (m_Parameters.m_BiasEnabled) |
| 567 | { |
| 568 | if (m_Bias == nullptr) |
| 569 | { |
| 570 | throw InvalidArgumentException("FullyConnectedQueueDescriptor: Bias is enabled but " |
| 571 | "bias value tensor descriptor is missing."); |
| 572 | } |
| 573 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 574 | // Validates type and quantization values. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 575 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 576 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "FullyConnectedQueueDescriptor"); |
| 577 | |
| 578 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 579 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 580 | "FullyConnectedQueueDescriptor", "bias"); |
| 581 | |
| 582 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "FullyConnectedQueueDescriptor", 1, "bias"); |
| 583 | } |
| 584 | |
| 585 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 586 | workloadInfo.m_OutputTensorInfos[0], "FullyConnectedQueueDescriptor", "input", "weights", "output"); |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 587 | |
| 588 | // Check the supported data types |
| 589 | std::vector<DataType> supportedTypes = |
| 590 | { |
| 591 | DataType::Float32, |
| 592 | DataType::Float16, |
| 593 | DataType::QuantisedAsymm8, |
| 594 | DataType::QuantisedSymm16 |
| 595 | }; |
| 596 | |
| 597 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 598 | supportedTypes, |
| 599 | "FullyConnectedQueueDescriptor"); |
| 600 | |
| 601 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 602 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 603 | "FullyConnectedQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | //--------------------------------------------------------------- |
| 607 | void NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 608 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 609 | ValidateNumInputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
| 610 | ValidateNumOutputs(workloadInfo, "NormalizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 611 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 612 | workloadInfo.m_OutputTensorInfos[0], |
| 613 | "NormalizationQueueDescriptor", |
| 614 | "input", |
| 615 | "output"); |
| 616 | } |
| 617 | |
| 618 | void AdditionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 619 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 620 | ValidateNumInputs(workloadInfo, "AdditionQueueDescriptor", 2); |
| 621 | ValidateNumOutputs(workloadInfo, "AdditionQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 622 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 623 | std::vector<DataType> supportedTypes = { |
| 624 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 625 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 626 | DataType::QuantisedSymm16, |
| 627 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 631 | supportedTypes, |
| 632 | "AdditionQueueDescriptor"); |
| 633 | |
| 634 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 635 | supportedTypes, |
| 636 | "AdditionQueueDescriptor"); |
| 637 | |
| 638 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 639 | supportedTypes, |
| 640 | "AdditionQueueDescriptor"); |
| 641 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 642 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 643 | workloadInfo.m_InputTensorInfos[1], |
| 644 | workloadInfo.m_OutputTensorInfos[0], |
| 645 | "AdditionQueueDescriptor", |
| 646 | "first input", |
| 647 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | //--------------------------------------------------------------- |
| 651 | void MultiplicationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 652 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 653 | ValidateNumInputs(workloadInfo, "MultiplicationQueueDescriptor", 2); |
| 654 | ValidateNumOutputs(workloadInfo, "MultiplicationQueueDescriptor", 1); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 655 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 656 | std::vector<DataType> supportedTypes = { |
| 657 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 658 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 659 | DataType::QuantisedSymm16, |
| 660 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 664 | supportedTypes, |
| 665 | "MultiplicationQueueDescriptor"); |
| 666 | |
| 667 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 668 | supportedTypes, |
| 669 | "MultiplicationQueueDescriptor"); |
| 670 | |
| 671 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 672 | supportedTypes, |
| 673 | "MultiplicationQueueDescriptor"); |
| 674 | |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 675 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 676 | workloadInfo.m_InputTensorInfos[1], |
| 677 | workloadInfo.m_OutputTensorInfos[0], |
| 678 | "MultiplicationQueueDescriptor", |
| 679 | "first input", |
| 680 | "second input"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void BatchNormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 684 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 685 | ValidateNumInputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
| 686 | ValidateNumOutputs(workloadInfo, "BatchNormalizationQueueDescriptor", 1); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 687 | |
| 688 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 689 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 690 | |
| 691 | std::vector<DataType> supportedTypes = |
| 692 | { |
| 693 | DataType::Float16, |
| 694 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 695 | DataType::QuantisedAsymm8, |
| 696 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 697 | }; |
| 698 | |
| 699 | ValidateDataTypes(input, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 700 | ValidateDataTypes(output, supportedTypes, "BatchNormalizationQueueDescriptor"); |
| 701 | |
| 702 | ValidateDataTypes(output, { input.GetDataType() }, "BatchNormalizationQueueDescriptor"); |
| 703 | |
| 704 | ValidateTensorQuantizationSpace(input, output, "BatchNormalizationQueueDescriptor", "input", "output"); |
| 705 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 706 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 707 | workloadInfo.m_OutputTensorInfos[0], |
| 708 | "BatchNormalizationQueueDescriptor", |
| 709 | "input", |
| 710 | "output"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 711 | |
| 712 | ValidatePointer(m_Mean, "BatchNormalizationQueueDescriptor", "mean"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 713 | ValidatePointer(m_Variance, "BatchNormalizationQueueDescriptor", "variance"); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 714 | ValidatePointer(m_Beta, "BatchNormalizationQueueDescriptor", "beta"); |
| 715 | ValidatePointer(m_Gamma, "BatchNormalizationQueueDescriptor", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 716 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 717 | const TensorInfo& mean = m_Mean->GetTensorInfo(); |
| 718 | const TensorInfo& variance = m_Variance->GetTensorInfo(); |
| 719 | const TensorInfo& beta = m_Beta->GetTensorInfo(); |
| 720 | const TensorInfo& gamma = m_Gamma->GetTensorInfo(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 721 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 722 | ValidateTensorNumDimensions(mean, "BatchNormalizationQueueDescriptor", 1, "mean"); |
| 723 | ValidateTensorNumDimensions(variance, "BatchNormalizationQueueDescriptor", 1, "variance"); |
| 724 | ValidateTensorNumDimensions(beta, "BatchNormalizationQueueDescriptor", 1, "beta"); |
| 725 | ValidateTensorNumDimensions(gamma, "BatchNormalizationQueueDescriptor", 1, "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 726 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 727 | ValidateTensorShapesMatch(mean, variance, "BatchNormalizationQueueDescriptor", "mean", "variance"); |
| 728 | ValidateTensorShapesMatch(mean, beta, "BatchNormalizationQueueDescriptor", "mean", "beta"); |
| 729 | ValidateTensorShapesMatch(mean, gamma, "BatchNormalizationQueueDescriptor", "mean", "gamma"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void Convolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 733 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 734 | ValidateNumInputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
| 735 | ValidateNumOutputs(workloadInfo, "Convolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 736 | |
| 737 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "input"); |
| 738 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", 4, "output"); |
| 739 | |
| 740 | ValidatePointer(m_Weight, "Convolution2dQueueDescriptor", "weight"); |
| 741 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor", 4, "weight"); |
| 742 | ValidateTensorDataType(m_Weight->GetTensorInfo(), workloadInfo.m_InputTensorInfos[0].GetDataType(), |
| 743 | "Convolution2dQueueDescriptor", "weight"); |
| 744 | if (m_Parameters.m_BiasEnabled) |
| 745 | { |
| 746 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "Convolution2dQueueDescriptor", 1, "bias"); |
| 747 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 748 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 749 | "Convolution2dQueueDescriptor", "bias"); |
| 750 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 751 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "Convolution2dQueueDescriptor"); |
| 752 | } |
| 753 | |
| 754 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 755 | workloadInfo.m_OutputTensorInfos[0], "Convolution2dQueueDescriptor", "input", "weights", "output"); |
| 756 | } |
| 757 | |
| 758 | void DepthwiseConvolution2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 759 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 760 | ValidateNumInputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
| 761 | ValidateNumOutputs(workloadInfo, "DepthwiseConvolution2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 762 | |
| 763 | ValidateTensorNumDimensions( |
| 764 | workloadInfo.m_InputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "input"); |
| 765 | ValidateTensorNumDimensions( |
| 766 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", 4, "output"); |
| 767 | |
| 768 | ValidatePointer(m_Weight, "DepthwiseConvolution2dQueueDescriptor", "weight"); |
| 769 | ValidateTensorNumDimensions(m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 4, "weight"); |
| 770 | |
Bruno Goncalves | 22972f0 | 2019-04-26 21:03:24 -0300 | [diff] [blame] | 771 | if (m_Parameters.m_DilationX < 1 || m_Parameters.m_DilationY < 1 ) |
| 772 | { |
| 773 | throw InvalidArgumentException( |
| 774 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: dilationX (provided %1%) " |
| 775 | "and dilationY (provided %2%) cannot be smaller than 1.") |
| 776 | % m_Parameters.m_DilationX % m_Parameters.m_DilationX)); |
| 777 | } |
| 778 | |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 779 | const unsigned int channelIndex = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : 3; |
| 780 | |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 781 | // Expected weight shape: [ M, I, H, W ] - This shape does NOT depend on the data layout |
| 782 | // inputChannels * channelMultiplier should be equal to outputChannels. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 783 | const unsigned int numWeightChannelMultiplier = m_Weight->GetTensorInfo().GetShape()[0]; |
Matteo Martincigh | 747ef82 | 2018-12-18 09:26:39 +0000 | [diff] [blame] | 784 | const unsigned int numWeightInputChannels = m_Weight->GetTensorInfo().GetShape()[1]; |
Nikhil Raj | cec6b65 | 2018-10-12 13:51:57 +0100 | [diff] [blame] | 785 | const unsigned int numWeightOutputChannels = workloadInfo.m_OutputTensorInfos[0].GetShape()[channelIndex]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 786 | if (numWeightChannelMultiplier * numWeightInputChannels != numWeightOutputChannels) |
| 787 | { |
| 788 | throw InvalidArgumentException( |
| 789 | boost::str(boost::format("DepthwiseConvolution2dQueueDescriptor: output_channels (provided %1%) should be " |
| 790 | "equal to input_channels (provided %2%) multiplied by channel_multiplier " |
| 791 | "(provided %3%).") |
| 792 | % numWeightOutputChannels % numWeightInputChannels % numWeightChannelMultiplier)); |
| 793 | } |
| 794 | |
| 795 | if (m_Parameters.m_BiasEnabled) |
| 796 | { |
| 797 | ValidatePointer(m_Bias, "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 798 | ValidateTensorNumDimensions(m_Bias->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor", 1, "bias"); |
| 799 | ValidateBiasTensorQuantization(m_Bias->GetTensorInfo(), |
| 800 | workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), "DepthwiseConvolution2dQueueDescriptor"); |
| 801 | |
| 802 | ValidateTensorDataType(m_Bias->GetTensorInfo(), |
| 803 | GetBiasDataType(workloadInfo.m_InputTensorInfos[0].GetDataType()), |
| 804 | "DepthwiseConvolution2dQueueDescriptor", "bias"); |
| 805 | } |
| 806 | |
| 807 | ValidateTensorQuantizationMultiplier(workloadInfo.m_InputTensorInfos[0], m_Weight->GetTensorInfo(), |
| 808 | workloadInfo.m_OutputTensorInfos[0], "DepthwiseConvolution2dQueueDescriptor", "input", "weights", "output"); |
Ruomei Yan | 88d44b8 | 2019-05-23 14:29:06 +0100 | [diff] [blame] | 809 | |
| 810 | // Check the supported data types |
| 811 | std::vector<DataType> supportedTypes = { |
| 812 | DataType::Float32, |
| 813 | DataType::QuantisedAsymm8, |
| 814 | DataType::QuantisedSymm16, |
| 815 | DataType::Float16 |
| 816 | }; |
| 817 | |
| 818 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 819 | supportedTypes, |
| 820 | "DepthwiseConvolution2dQueueDescriptor"); |
| 821 | |
| 822 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 823 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 824 | "DepthwiseConvolution2dQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | void PermuteQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 828 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 829 | ValidateNumInputs(workloadInfo, "PermuteQueueDescriptor", 1); |
| 830 | ValidateNumOutputs(workloadInfo, "PermuteQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 831 | |
| 832 | const PermutationVector& mapping = m_Parameters.m_DimMappings; |
| 833 | |
| 834 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 835 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 836 | |
| 837 | ValidateTensorNumDimensions(input, "PermuteQueueDescriptor", mapping.GetSize(), "input"); |
| 838 | ValidateTensorNumDimensions(output, "PermuteQueueDescriptor", mapping.GetSize(), "output"); |
| 839 | |
| 840 | for (unsigned int i = 0; i < mapping.GetSize(); ++i) |
| 841 | { |
| 842 | if (input.GetShape()[i] != output.GetShape()[mapping[i]]) |
| 843 | { |
| 844 | throw InvalidArgumentException("PermuteQueueDescriptor: src dimension " + to_string(i) + |
| 845 | " (=" + to_string(input.GetShape()[i]) + ") " + |
| 846 | "must match dst dimension " + to_string(mapping[i]) + |
| 847 | " (=" + to_string(output.GetShape()[mapping[i]]) + ")"); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | void Pooling2dQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 853 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 854 | ValidateNumInputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
| 855 | ValidateNumOutputs(workloadInfo, "Pooling2dQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 856 | |
| 857 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "input"); |
| 858 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "Pooling2dQueueDescriptor", 4, "output"); |
| 859 | } |
| 860 | |
| 861 | void ResizeBilinearQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 862 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 863 | ValidateNumInputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
| 864 | ValidateNumOutputs(workloadInfo, "ResizeBilinearQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 865 | |
| 866 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "input"); |
| 867 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "ResizeBilinearQueueDescriptor", 4, "output"); |
| 868 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 869 | // Resizes bilinear only changes width and height: batch and channel count must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 870 | { |
| 871 | const unsigned int inputBatchSize = workloadInfo.m_InputTensorInfos[0].GetShape()[0]; |
| 872 | const unsigned int outputBatchSize = workloadInfo.m_OutputTensorInfos[0].GetShape()[0]; |
| 873 | if (inputBatchSize != outputBatchSize) |
| 874 | { |
| 875 | throw InvalidArgumentException( |
| 876 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input batch size (%1%) " |
| 877 | "does not match output batch size (%2%)") % inputBatchSize % outputBatchSize)); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | { |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 882 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 883 | const unsigned int inputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 884 | workloadInfo.m_InputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 885 | const unsigned int outputChannelCount = |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 886 | workloadInfo.m_OutputTensorInfos[0].GetShape()[dimensionIndices.GetChannelsIndex()]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 887 | if (inputChannelCount != outputChannelCount) |
| 888 | { |
| 889 | throw InvalidArgumentException( |
| 890 | boost::str(boost::format("ResizeBilinearQueueDescriptor: Input channel count (%1%) " |
| 891 | "does not match output channel count (%2%)") % inputChannelCount % outputChannelCount)); |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | void FakeQuantizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 897 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 898 | ValidateNumInputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
| 899 | ValidateNumOutputs(workloadInfo, "FakeQuantizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 900 | |
| 901 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "input"); |
| 902 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "FakeQuantizationQueueDescriptor", 2, "output"); |
| 903 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 904 | workloadInfo.m_OutputTensorInfos[0], |
| 905 | "FakeQuantizationQueueDescriptor", |
| 906 | "input", |
| 907 | "output"); |
| 908 | if (m_Parameters.m_Min > m_Parameters.m_Max) |
| 909 | { |
| 910 | throw InvalidArgumentException("FakeQuantizationQueueDescriptor: min cannot be greater than max"); |
| 911 | } |
| 912 | |
| 913 | } |
| 914 | |
| 915 | void L2NormalizationQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 916 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 917 | ValidateNumInputs(workloadInfo, "L2NormalizationQueueDescriptor", 1); |
| 918 | ValidateNumOutputs(workloadInfo, "L2NormalizationQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 919 | |
| 920 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "L2NormalizationQueueDescriptor", 4, "input"); |
| 921 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "L2NormalizationQueueDescriptor", 4, "output"); |
| 922 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 923 | workloadInfo.m_OutputTensorInfos[0], |
| 924 | "L2NormalizationQueueDescriptor", |
| 925 | "input", |
| 926 | "output"); |
| 927 | } |
| 928 | |
| 929 | void ConstantQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 930 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 931 | ValidateNumInputs(workloadInfo, "ConstantQueueDescriptor", 0); |
| 932 | ValidateNumOutputs(workloadInfo, "ConstantQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 933 | |
| 934 | if (!m_LayerOutput) |
| 935 | { |
| 936 | throw InvalidArgumentException("ConstantQueueDescriptor: No const input specified"); |
| 937 | } |
| 938 | |
| 939 | ValidateTensorShapesMatch(m_LayerOutput->GetTensorInfo(), |
| 940 | workloadInfo.m_OutputTensorInfos[0], |
| 941 | "ConstantQueueDescriptor", |
| 942 | "constant", |
| 943 | "output"); |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 944 | |
| 945 | // Check the supported data types |
| 946 | std::vector<DataType> supportedTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 947 | { |
| 948 | DataType::Float32, |
| 949 | DataType::Float16, |
| 950 | DataType::Signed32, |
| 951 | DataType::QuantisedAsymm8, |
| 952 | DataType::QuantisedSymm16 |
| 953 | }; |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 954 | |
| 955 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ConstantQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | void ReshapeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 959 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 960 | ValidateNumInputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
| 961 | ValidateNumOutputs(workloadInfo, "ReshapeQueueDescriptor", 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 962 | |
| 963 | if (workloadInfo.m_InputTensorInfos[0].GetNumElements() != workloadInfo.m_OutputTensorInfos[0].GetNumElements()) |
| 964 | { |
| 965 | throw InvalidArgumentException("ReshapeQueueDescriptor: Input tensor has " + |
| 966 | to_string(workloadInfo.m_InputTensorInfos[0].GetNumElements()) + " but output tensor has " + |
| 967 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 968 | } |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 969 | |
| 970 | // Check the supported data types |
| 971 | std::vector<DataType> supportedTypes = |
| 972 | { |
| 973 | DataType::Float32, |
| 974 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 975 | DataType::QuantisedAsymm8, |
| 976 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 977 | }; |
| 978 | |
| 979 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
| 980 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, "ReshapeQueueDescriptor"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 983 | void SpaceToBatchNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 984 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 985 | ValidateNumInputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
| 986 | ValidateNumOutputs(workloadInfo, "SpaceToBatchNdQueueDescriptor", 1); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 987 | |
| 988 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "input"); |
| 989 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "SpaceToBatchNdQueueDescriptor", 4, "output"); |
| 990 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 991 | if (m_Parameters.m_BlockShape.size() != 2) |
| 992 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 993 | throw InvalidArgumentException("Block Shape must contain 2 spatial dimensions"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size()) |
| 997 | { |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 998 | throw InvalidArgumentException("Pad List must contain the same number of dimensions as Block Shape."); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | const TensorShape inputShape = workloadInfo.m_InputTensorInfos[0].GetShape(); |
| 1002 | |
| 1003 | std::pair<unsigned int, unsigned int> heightPad = m_Parameters.m_PadList[0]; |
| 1004 | std::pair<unsigned int, unsigned int> widthPad = m_Parameters.m_PadList[1]; |
| 1005 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1006 | DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout); |
| 1007 | unsigned int inputHeight = inputShape[dimensionIndices.GetHeightIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1008 | + heightPad.first + heightPad.second; |
| 1009 | |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1010 | unsigned int inputWidth = inputShape[dimensionIndices.GetWidthIndex()] |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1011 | + widthPad.first + widthPad.second; |
| 1012 | |
| 1013 | unsigned int numInputElements = inputShape[0] * inputHeight * inputWidth |
Matthew Bentham | 8800c00 | 2018-11-19 13:19:28 +0000 | [diff] [blame] | 1014 | * inputShape[dimensionIndices.GetChannelsIndex()]; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1015 | |
| 1016 | if (workloadInfo.m_OutputTensorInfos[0].GetNumElements() != numInputElements) |
| 1017 | { |
| 1018 | throw InvalidArgumentException("SpaceToBatchNdQueueDescriptor: Input tensor has " + |
| 1019 | to_string(numInputElements) + " after padding but output tensor has " + |
| 1020 | to_string(workloadInfo.m_OutputTensorInfos[0].GetNumElements()) + " elements."); |
| 1021 | } |
| 1022 | |
| 1023 | 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] | 1024 | { |
| 1025 | throw InvalidArgumentException( |
| 1026 | "Input shape after padding must be divisible by Block Shape in all spatial dimensions"); |
| 1027 | } |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1028 | |
| 1029 | std::vector<DataType> supportedTypes = |
| 1030 | { |
| 1031 | DataType::Float16, |
| 1032 | DataType::Float32, |
| 1033 | DataType::QuantisedAsymm8, |
| 1034 | DataType::QuantisedSymm16 |
| 1035 | }; |
| 1036 | |
| 1037 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1038 | supportedTypes, |
| 1039 | "SpaceToBatchNdQueueDescriptor"); |
| 1040 | |
| 1041 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1042 | {workloadInfo.m_InputTensorInfos[0].GetDataType()}, |
| 1043 | "SpaceToBatchNdQueueDescriptor"); |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1046 | void FloorQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1047 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1048 | const std::string floorQueueDescString = "FloorQueueDescriptor"; |
| 1049 | |
| 1050 | ValidateNumInputs(workloadInfo, floorQueueDescString, 1); |
| 1051 | ValidateNumOutputs(workloadInfo, floorQueueDescString, 1); |
| 1052 | |
| 1053 | std::vector<DataType> supportedTypes = |
| 1054 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 1055 | DataType::Float32, |
| 1056 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1057 | }; |
| 1058 | |
| 1059 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, floorQueueDescString); |
| 1060 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], supportedTypes, floorQueueDescString); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1061 | |
| 1062 | if (workloadInfo.m_InputTensorInfos[0] != workloadInfo.m_OutputTensorInfos[0]) |
| 1063 | { |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1064 | throw InvalidArgumentException(floorQueueDescString + ": Input and output tensor infos do not match."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1068 | void LstmQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1069 | { |
| 1070 | ValidateTensorNumDimensions(workloadInfo.m_InputTensorInfos[0], "LstmQueueDescriptor", 2, "input"); |
| 1071 | ValidateTensorNumDimensions(workloadInfo.m_OutputTensorInfos[0], "LstmQueueDescriptor", 2, "output"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1072 | |
| 1073 | std::vector<DataType> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1074 | DataType::Float16, |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1075 | DataType::Float32, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1076 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1080 | supportedTypes, |
| 1081 | "LstmQueueDescriptor"); |
| 1082 | |
| 1083 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1084 | supportedTypes, |
| 1085 | "LstmQueueDescriptor"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | void ConvertFp32ToFp16QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1089 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1090 | ValidateNumInputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
| 1091 | ValidateNumOutputs(workloadInfo, "ConvertFp32ToFp16QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1092 | |
| 1093 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1094 | { |
| 1095 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Input tensor type must be Float32."); |
| 1096 | } |
| 1097 | |
| 1098 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1099 | { |
| 1100 | throw InvalidArgumentException("ConvertFp32ToFp16QueueDescriptor: Output tensor type must be Float16."); |
| 1101 | } |
| 1102 | |
| 1103 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1104 | workloadInfo.m_OutputTensorInfos[0], |
| 1105 | "ConvertFp32ToFp16QueueDescriptor", |
| 1106 | "input", |
| 1107 | "output"); |
| 1108 | } |
| 1109 | |
| 1110 | void ConvertFp16ToFp32QueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1111 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1112 | ValidateNumInputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
| 1113 | ValidateNumOutputs(workloadInfo, "ConvertFp16ToFp32QueueDescriptor", 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1114 | |
| 1115 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float16) |
| 1116 | { |
| 1117 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Input tensor type must be Float16."); |
| 1118 | } |
| 1119 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1120 | { |
| 1121 | throw InvalidArgumentException("ConvertFp16ToFp32QueueDescriptor: Output tensor type must be Float32."); |
| 1122 | } |
| 1123 | |
| 1124 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1125 | workloadInfo.m_OutputTensorInfos[0], |
| 1126 | "ConvertFp16ToFp32QueueDescriptor", |
| 1127 | "input", |
| 1128 | "output"); |
| 1129 | } |
| 1130 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1131 | void DivisionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1132 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1133 | ValidateNumInputs(workloadInfo, "DivisionQueueDescriptor", 2); |
| 1134 | ValidateNumOutputs(workloadInfo, "DivisionQueueDescriptor", 1); |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1135 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1136 | std::vector<DataType> supportedTypes = { |
| 1137 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1138 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1139 | DataType::QuantisedSymm16, |
| 1140 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1141 | }; |
| 1142 | |
| 1143 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1144 | supportedTypes, |
| 1145 | "DivisionQueueDescriptor"); |
| 1146 | |
| 1147 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1148 | supportedTypes, |
| 1149 | "DivisionQueueDescriptor"); |
| 1150 | |
| 1151 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1152 | supportedTypes, |
| 1153 | "DivisionQueueDescriptor"); |
| 1154 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 1155 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1156 | workloadInfo.m_InputTensorInfos[1], |
| 1157 | workloadInfo.m_OutputTensorInfos[0], |
| 1158 | "DivisionQueueDescriptor", |
| 1159 | "first input", |
| 1160 | "second input"); |
| 1161 | } |
| 1162 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1163 | void SubtractionQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1164 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1165 | ValidateNumInputs(workloadInfo, "SubtractionQueueDescriptor", 2); |
| 1166 | ValidateNumOutputs(workloadInfo, "SubtractionQueueDescriptor", 1); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1167 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1168 | std::vector<DataType> supportedTypes = { |
| 1169 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1170 | DataType::QuantisedAsymm8, |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 1171 | DataType::QuantisedSymm16, |
| 1172 | DataType::Float16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1173 | }; |
| 1174 | |
| 1175 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1176 | supportedTypes, |
| 1177 | "SubtractionQueueDescriptor"); |
| 1178 | |
| 1179 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1180 | supportedTypes, |
| 1181 | "SubtractionQueueDescriptor"); |
| 1182 | |
| 1183 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1184 | supportedTypes, |
| 1185 | "SubtractionQueueDescriptor"); |
| 1186 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 1187 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1188 | workloadInfo.m_InputTensorInfos[1], |
| 1189 | workloadInfo.m_OutputTensorInfos[0], |
| 1190 | "SubtractionQueueDescriptor", |
| 1191 | "first input", |
| 1192 | "second input"); |
| 1193 | } |
| 1194 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1195 | void MaximumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1196 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1197 | ValidateNumInputs(workloadInfo, "MaximumQueueDescriptor", 2); |
| 1198 | ValidateNumOutputs(workloadInfo, "MaximumQueueDescriptor", 1); |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1199 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1200 | std::vector<DataType> supportedTypes = { |
| 1201 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1202 | DataType::QuantisedAsymm8, |
| 1203 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1204 | }; |
| 1205 | |
| 1206 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1207 | supportedTypes, |
| 1208 | "MaximumQueueDescriptor"); |
| 1209 | |
| 1210 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1211 | supportedTypes, |
| 1212 | "MaximumQueueDescriptor"); |
| 1213 | |
| 1214 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1215 | supportedTypes, |
| 1216 | "MaximumQueueDescriptor"); |
| 1217 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 1218 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1219 | workloadInfo.m_InputTensorInfos[1], |
| 1220 | workloadInfo.m_OutputTensorInfos[0], |
| 1221 | "MaximumQueueDescriptor", |
| 1222 | "first input", |
| 1223 | "second input"); |
| 1224 | } |
| 1225 | |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1226 | void MeanQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1227 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1228 | ValidateNumInputs(workloadInfo, "MeanQueueDescriptor", 1); |
| 1229 | ValidateNumOutputs(workloadInfo, "MeanQueueDescriptor", 1); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1230 | |
| 1231 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
| 1232 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1233 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1234 | if (m_Parameters.m_KeepDims) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1235 | { |
| 1236 | ValidateTensorNumDimensions(output, "MeanQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1237 | } |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1238 | else if (m_Parameters.m_Axis.empty()) |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1239 | { |
| 1240 | ValidateTensorNumDimensions(output, "MeanQueueDescriptor", 1, "output"); |
| 1241 | } |
| 1242 | else |
| 1243 | { |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1244 | auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(m_Parameters.m_Axis.size()); |
narpra01 | eb06191 | 2018-09-10 17:35:27 +0100 | [diff] [blame] | 1245 | ValidateTensorNumDimensions(output, |
| 1246 | "MeanQueueDescriptor", |
| 1247 | outputDim > 0 ? outputDim : 1, |
| 1248 | "output"); |
| 1249 | } |
narpra01 | a6bf912 | 2018-09-10 09:50:09 +0100 | [diff] [blame] | 1250 | } |
| 1251 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1252 | void PadQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1253 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1254 | ValidateNumInputs(workloadInfo, "PadQueueDescriptor", 1); |
| 1255 | ValidateNumOutputs(workloadInfo, "PadQueueDescriptor", 1); |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1256 | |
| 1257 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1258 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1259 | |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 1260 | // input and output should have the same number of dimensions |
| 1261 | ValidateTensorNumDimensions(output, "PadQueueDescriptor", input.GetNumDimensions(), "output"); |
| 1262 | // there should be entry in the pad list for each dimension in the input tensor |
| 1263 | if (m_Parameters.m_PadList.size() != input.GetNumDimensions()) { |
| 1264 | throw InvalidArgumentException("Pad List should contain the same number of entries as there" |
| 1265 | " are dimensions in the input tensor that is " + |
| 1266 | to_string(input.GetNumDimensions()) + " entries " + |
| 1267 | " not " + to_string(m_Parameters.m_PadList.size()) + " entries."); |
| 1268 | } |
| 1269 | } |
| 1270 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1271 | void QuantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1272 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1273 | ValidateNumInputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
| 1274 | ValidateNumOutputs(workloadInfo, "QuantizeQueueDescriptor", 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1275 | |
| 1276 | |
| 1277 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1278 | { |
| 1279 | throw InvalidArgumentException("Quantize only accepts Float32 inputs."); |
| 1280 | } |
| 1281 | |
| 1282 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1283 | workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1284 | { |
| 1285 | throw InvalidArgumentException("Output of quantized layer must be quantized type."); |
| 1286 | } |
| 1287 | } |
| 1288 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1289 | void BatchToSpaceNdQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1290 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1291 | ValidateNumInputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
| 1292 | ValidateNumOutputs(workloadInfo, "BatchToSpaceNdQueueDescriptor", 1); |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1295 | void StridedSliceQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1296 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1297 | ValidateNumInputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
| 1298 | ValidateNumOutputs(workloadInfo, "StridedSliceQueueDescriptor", 1); |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1299 | |
| 1300 | const TensorInfo& input = workloadInfo.m_InputTensorInfos[0]; |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1301 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1302 | |
| 1303 | std::vector<DataType> supportedTypes = |
| 1304 | { |
| 1305 | DataType::Float16, |
| 1306 | DataType::Float32, |
Matteo Martincigh | 42666a1 | 2019-05-29 08:53:41 +0100 | [diff] [blame] | 1307 | DataType::QuantisedAsymm8, |
| 1308 | DataType::QuantisedSymm16 |
Matteo Martincigh | e851b3d | 2019-05-28 14:31:20 +0100 | [diff] [blame] | 1309 | }; |
| 1310 | |
| 1311 | ValidateDataTypes(input, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1312 | ValidateDataTypes(output, supportedTypes, "StridedSliceQueueDescriptor"); |
| 1313 | |
| 1314 | ValidateDataTypes(output, { input.GetDataType() }, "StridedSliceQueueDescriptor"); |
| 1315 | |
| 1316 | ValidateTensorQuantizationSpace(input, output, "StridedSliceQueueDescriptor", "input", "output"); |
| 1317 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1318 | const uint32_t rank = input.GetNumDimensions(); |
| 1319 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1320 | if (rank > 4) |
| 1321 | { |
| 1322 | throw InvalidArgumentException( |
| 1323 | "StridedSliceLayer: Input tensors with rank greater than 4 are not supported"); |
| 1324 | } |
| 1325 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 1326 | // Begin, End & Stride length must be of rank(input0) |
| 1327 | if (m_Parameters.m_Begin.size() != rank) |
| 1328 | { |
| 1329 | throw InvalidArgumentException("StridedSliceLayer: Begin length must be of rank input0(" |
| 1330 | + to_string(rank) + ")"); |
| 1331 | } |
| 1332 | |
| 1333 | if (m_Parameters.m_End.size() != rank) |
| 1334 | { |
| 1335 | throw InvalidArgumentException("StridedSliceLayer: End length must be of rank input0(" |
| 1336 | + to_string(rank) + ")"); |
| 1337 | } |
| 1338 | |
| 1339 | if (m_Parameters.m_Stride.size() != rank) |
| 1340 | { |
| 1341 | throw InvalidArgumentException("StridedSliceLayer: Stride length must be of rank input0(" |
| 1342 | + to_string(rank) + ")"); |
| 1343 | } |
| 1344 | |
| 1345 | // Stride entries must be non-zero |
| 1346 | for (auto& stride : m_Parameters.m_Stride) |
| 1347 | { |
| 1348 | if (stride == 0) |
| 1349 | { |
| 1350 | throw InvalidArgumentException("StridedSliceLayer: Stride entries must be non-zero"); |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1355 | void MinimumQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1356 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1357 | ValidateNumInputs(workloadInfo, "MinimumQueueDescriptor", 2); |
| 1358 | ValidateNumOutputs(workloadInfo, "MinimumQueueDescriptor", 1); |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1359 | |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1360 | std::vector<DataType> supportedTypes = { |
| 1361 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1362 | DataType::QuantisedAsymm8, |
| 1363 | DataType::QuantisedSymm16 |
Sadik Armagan | 2e6dc3a | 2019-04-03 17:48:18 +0100 | [diff] [blame] | 1364 | }; |
| 1365 | |
| 1366 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1367 | supportedTypes, |
| 1368 | "MinimumQueueDescriptor"); |
| 1369 | |
| 1370 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1371 | supportedTypes, |
| 1372 | "MinimumQueueDescriptor"); |
| 1373 | |
| 1374 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1375 | supportedTypes, |
| 1376 | "MinimumQueueDescriptor"); |
| 1377 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 1378 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1379 | workloadInfo.m_InputTensorInfos[1], |
| 1380 | workloadInfo.m_OutputTensorInfos[0], |
| 1381 | "MinimumQueueDescriptor", |
| 1382 | "first input", |
| 1383 | "second input"); |
| 1384 | } |
| 1385 | |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1386 | void DebugQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1387 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1388 | ValidateNumInputs(workloadInfo, "DebugQueueDescriptor", 1); |
| 1389 | ValidateNumOutputs(workloadInfo, "DebugQueueDescriptor", 1); |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1392 | void EqualQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1393 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1394 | ValidateNumInputs(workloadInfo, "EqualQueueDescriptor", 2); |
| 1395 | ValidateNumOutputs(workloadInfo, "EqualQueueDescriptor", 1); |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1396 | |
| 1397 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1398 | workloadInfo.m_InputTensorInfos[1], |
| 1399 | workloadInfo.m_OutputTensorInfos[0], |
| 1400 | "EqualQueueDescriptor", |
| 1401 | "first input", |
| 1402 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1403 | |
| 1404 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1405 | { |
| 1406 | throw InvalidArgumentException("EqualQueueDescriptor: Output tensor type must be Boolean."); |
| 1407 | } |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1410 | void GreaterQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1411 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1412 | ValidateNumInputs(workloadInfo, "GreaterQueueDescriptor", 2); |
| 1413 | ValidateNumOutputs(workloadInfo, "GreaterQueueDescriptor", 1); |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1414 | |
| 1415 | ValidateBroadcastTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1416 | workloadInfo.m_InputTensorInfos[1], |
| 1417 | workloadInfo.m_OutputTensorInfos[0], |
| 1418 | "GreaterQueueDescriptor", |
| 1419 | "first input", |
| 1420 | "second input"); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 1421 | |
| 1422 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Boolean) |
| 1423 | { |
| 1424 | throw InvalidArgumentException("GreaterQueueDescriptor: Output tensor type must be Boolean."); |
| 1425 | } |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1428 | void RsqrtQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1429 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1430 | ValidateNumInputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
| 1431 | ValidateNumOutputs(workloadInfo, "RsqrtQueueDescriptor", 1); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1432 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1433 | workloadInfo.m_OutputTensorInfos[0], |
| 1434 | "RsqrtQueueDescriptor", |
| 1435 | "input", |
| 1436 | "output"); |
| 1437 | } |
| 1438 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1439 | void GatherQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1440 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1441 | ValidateNumInputs(workloadInfo, "GatherQueueDescriptor", 2); |
| 1442 | ValidateNumOutputs(workloadInfo, "GatherQueueDescriptor", 1); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1443 | |
| 1444 | const TensorInfo& indices = workloadInfo.m_InputTensorInfos[1]; |
| 1445 | |
| 1446 | if (indices.GetDataType() != DataType::Signed32) |
| 1447 | { |
| 1448 | throw InvalidArgumentException("GatherQueueDescriptor: Indices tensor type must be int32."); |
| 1449 | } |
| 1450 | |
| 1451 | const TensorInfo& params = workloadInfo.m_InputTensorInfos[0]; |
| 1452 | const TensorInfo& output = workloadInfo.m_OutputTensorInfos[0]; |
| 1453 | unsigned int paramsDim = params.GetNumDimensions(); |
| 1454 | unsigned int indicesDim = indices.GetNumDimensions(); |
| 1455 | unsigned int outputDim = paramsDim - 1 + indicesDim; |
| 1456 | |
| 1457 | ValidateTensorNumDimensions(output, "GatherQueueDescriptor", outputDim, "output"); |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1460 | void DetectionPostProcessQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1461 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1462 | ValidateNumInputs(workloadInfo, "DetectionPostProcessQueueDescriptor", 2); |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1463 | |
| 1464 | if (workloadInfo.m_OutputTensorInfos.size() != 4) |
| 1465 | { |
| 1466 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Requires exactly four outputs. " + |
| 1467 | to_string(workloadInfo.m_OutputTensorInfos.size()) + " has been provided."); |
| 1468 | } |
| 1469 | |
| 1470 | if (m_Anchors == nullptr) |
| 1471 | { |
| 1472 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Anchors tensor descriptor is missing."); |
| 1473 | } |
| 1474 | |
| 1475 | const TensorInfo& boxEncodingsInfo = workloadInfo.m_InputTensorInfos[0]; |
| 1476 | const TensorInfo& scoresInfo = workloadInfo.m_InputTensorInfos[1]; |
| 1477 | const TensorInfo& anchorsInfo = m_Anchors->GetTensorInfo(); |
| 1478 | const TensorInfo& detectionBoxesInfo = workloadInfo.m_OutputTensorInfos[0]; |
Narumol Prangnawarat | 6d302bf | 2019-02-04 11:46:26 +0000 | [diff] [blame] | 1479 | const TensorInfo& detectionClassesInfo = workloadInfo.m_OutputTensorInfos[1]; |
| 1480 | const TensorInfo& detectionScoresInfo = workloadInfo.m_OutputTensorInfos[2]; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1481 | const TensorInfo& numDetectionsInfo = workloadInfo.m_OutputTensorInfos[3]; |
| 1482 | |
| 1483 | ValidateTensorNumDimensions(boxEncodingsInfo, "DetectionPostProcessQueueDescriptor", 3, "box encodings"); |
| 1484 | ValidateTensorNumDimensions(scoresInfo, "DetectionPostProcessQueueDescriptor", 3, "scores"); |
| 1485 | ValidateTensorNumDimensions(anchorsInfo, "DetectionPostProcessQueueDescriptor", 2, "anchors"); |
| 1486 | |
| 1487 | ValidateTensorNumDimensions(detectionBoxesInfo, "DetectionPostProcessQueueDescriptor", 3, "detection boxes"); |
| 1488 | ValidateTensorNumDimensions(detectionScoresInfo, "DetectionPostProcessQueueDescriptor", 2, "detection scores"); |
| 1489 | ValidateTensorNumDimensions(detectionClassesInfo, "DetectionPostProcessQueueDescriptor", 2, "detection classes"); |
| 1490 | ValidateTensorNumDimensions(numDetectionsInfo, "DetectionPostProcessQueueDescriptor", 1, "num detections"); |
| 1491 | |
| 1492 | ValidateTensorDataType(detectionBoxesInfo, DataType::Float32, |
| 1493 | "DetectionPostProcessQueueDescriptor", "detection boxes"); |
| 1494 | ValidateTensorDataType(detectionScoresInfo, DataType::Float32, |
| 1495 | "DetectionPostProcessQueueDescriptor", "detection scores"); |
| 1496 | ValidateTensorDataType(detectionClassesInfo, DataType::Float32, |
| 1497 | "DetectionPostProcessQueueDescriptor", "detection classes"); |
| 1498 | ValidateTensorDataType(numDetectionsInfo, DataType::Float32, |
| 1499 | "DetectionPostProcessQueueDescriptor", "num detections"); |
| 1500 | |
| 1501 | if (m_Parameters.m_NmsIouThreshold <= 0.0f || m_Parameters.m_NmsIouThreshold > 1.0f) |
| 1502 | { |
| 1503 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Intersection over union threshold " |
| 1504 | "must be positive and less than or equal to 1."); |
| 1505 | } |
| 1506 | if (scoresInfo.GetShape()[2] != m_Parameters.m_NumClasses + 1) |
| 1507 | { |
| 1508 | throw InvalidArgumentException("DetectionPostProcessQueueDescriptor: Number of classes with background " |
| 1509 | "should be equal to number of classes + 1."); |
| 1510 | } |
| 1511 | } |
| 1512 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1513 | void DequantizeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1514 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1515 | ValidateNumInputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
| 1516 | ValidateNumOutputs(workloadInfo, "DequantizeQueueDescriptor", 1); |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 1517 | |
| 1518 | if (workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedAsymm8 && |
| 1519 | workloadInfo.m_InputTensorInfos[0].GetDataType() != DataType::QuantisedSymm16) |
| 1520 | { |
| 1521 | throw InvalidArgumentException("Input to dequantize layer must be quantized type."); |
| 1522 | } |
| 1523 | |
| 1524 | if (workloadInfo.m_OutputTensorInfos[0].GetDataType() != DataType::Float32) |
| 1525 | { |
| 1526 | throw InvalidArgumentException("Output of dequantize layer must be Float32 type."); |
| 1527 | } |
| 1528 | } |
| 1529 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1530 | void MergeQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1531 | { |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1532 | ValidateNumInputs(workloadInfo, "MergeQueueDescriptor", 2); |
| 1533 | ValidateNumOutputs(workloadInfo, "MergeQueueDescriptor", 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 1534 | |
| 1535 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1536 | workloadInfo.m_InputTensorInfos[1], |
| 1537 | "MergeQueueDescriptor", |
| 1538 | "input0", |
| 1539 | "input1"); |
| 1540 | |
| 1541 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1542 | workloadInfo.m_OutputTensorInfos[0], |
| 1543 | "MergeQueueDescriptor", |
| 1544 | "input0", |
| 1545 | "output"); |
| 1546 | |
| 1547 | const DataType dataType = workloadInfo.m_InputTensorInfos[0].GetDataType(); |
| 1548 | ValidateTensorDataType(workloadInfo.m_InputTensorInfos[1], dataType, "MergeQueueDescriptor", "input1"); |
| 1549 | ValidateTensorDataType(workloadInfo.m_OutputTensorInfos[0], dataType, "MergeQueueDescriptor", "output"); |
| 1550 | } |
| 1551 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 1552 | void SwitchQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1553 | { |
| 1554 | ValidateNumInputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1555 | ValidateNumOutputs(workloadInfo, "SwitchQueueDescriptor", 2); |
| 1556 | |
| 1557 | std::vector<DataType> supportedTypes = { |
| 1558 | DataType::Float32, |
| 1559 | DataType::QuantisedAsymm8, |
| 1560 | DataType::QuantisedSymm16 |
| 1561 | }; |
| 1562 | |
| 1563 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], |
| 1564 | supportedTypes, |
| 1565 | "SwitchQueueDescriptor"); |
| 1566 | |
| 1567 | ValidateDataTypes(workloadInfo.m_InputTensorInfos[1], |
| 1568 | supportedTypes, |
| 1569 | "SwitchQueueDescriptor"); |
| 1570 | |
| 1571 | ValidateDataTypes(workloadInfo.m_OutputTensorInfos[0], |
| 1572 | supportedTypes, |
| 1573 | "SwitchQueueDescriptor"); |
| 1574 | |
| 1575 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1576 | workloadInfo.m_OutputTensorInfos[0], |
| 1577 | "SwitchQueueDescriptor", |
| 1578 | "input0", |
| 1579 | "output0"); |
| 1580 | |
| 1581 | ValidateTensorShapesMatch(workloadInfo.m_InputTensorInfos[0], |
| 1582 | workloadInfo.m_OutputTensorInfos[1], |
| 1583 | "SwitchQueueDescriptor", |
| 1584 | "input0", |
| 1585 | "output1"); |
| 1586 | } |
| 1587 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 1588 | void PreCompiledQueueDescriptor::Validate(const WorkloadInfo& workloadInfo) const |
| 1589 | { |
| 1590 | // This is internally generated so it should not need validation. |
| 1591 | } |
| 1592 | |
Nattapat Chaimanowong | a0d2844 | 2018-11-21 16:48:17 +0000 | [diff] [blame] | 1593 | } //namespace armnn |