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 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 6 | #include "RefLayerSupport.hpp" |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 7 | #include "RefBackendId.hpp" |
David Beck | 3cc9a62 | 2018-10-12 10:38:31 +0100 | [diff] [blame] | 8 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | #include <InternalTypes.hpp> |
| 10 | #include <LayerSupportCommon.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <armnn/Types.hpp> |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 12 | #include <armnn/Descriptors.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 14 | #include <backendsCommon/BackendRegistry.hpp> |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 15 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 16 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | #include <boost/core/ignore_unused.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 19 | #include <vector> |
| 20 | #include <algorithm> |
| 21 | #include <array> |
| 22 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 23 | using namespace boost; |
| 24 | |
| 25 | namespace armnn |
| 26 | { |
| 27 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 28 | namespace |
| 29 | { |
| 30 | |
| 31 | template<typename Float32Func, typename Uint8Func, typename ... Params> |
| 32 | bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported, |
| 33 | DataType dataType, |
| 34 | Float32Func floatFuncPtr, |
| 35 | Uint8Func uint8FuncPtr, |
| 36 | Params&&... params) |
| 37 | { |
| 38 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 39 | dataType, |
| 40 | &FalseFunc<Params...>, |
| 41 | floatFuncPtr, |
| 42 | uint8FuncPtr, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 43 | &FalseFunc<Params...>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 44 | &FalseFunc<Params...>, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 45 | std::forward<Params>(params)...); |
| 46 | } |
| 47 | |
| 48 | } // anonymous namespace |
| 49 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 50 | namespace |
| 51 | { |
| 52 | |
| 53 | std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected, |
| 54 | unsigned int actual, |
| 55 | std::string& layerStr, |
| 56 | std::string& tensorName) |
| 57 | { |
| 58 | std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" + |
| 59 | " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor."; |
| 60 | |
| 61 | return errorMsg; |
| 62 | } |
| 63 | |
| 64 | } // anonymous namespace |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 65 | |
| 66 | namespace |
| 67 | { |
| 68 | template<typename F> |
| 69 | bool CheckSupportRule(F rule, Optional<std::string&> reasonIfUnsupported, const char* reason) |
| 70 | { |
| 71 | bool supported = rule(); |
| 72 | if (!supported && reason) |
| 73 | { |
| 74 | reasonIfUnsupported.value() += std::string(reason) + "\n"; // Append the reason on a new line |
| 75 | } |
| 76 | return supported; |
| 77 | } |
| 78 | |
| 79 | struct Rule |
| 80 | { |
| 81 | bool operator()() const |
| 82 | { |
| 83 | return m_Res; |
| 84 | } |
| 85 | |
| 86 | bool m_Res = true; |
| 87 | }; |
| 88 | |
Derek Lamberti | 2a434a8 | 2019-03-20 13:07:57 +0000 | [diff] [blame] | 89 | template<typename T> |
| 90 | bool AllTypesAreEqualImpl(T t) |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 91 | { |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | template<typename T, typename... Rest> |
| 96 | bool AllTypesAreEqualImpl(T t1, T t2, Rest... rest) |
| 97 | { |
| 98 | static_assert(std::is_same<T, TensorInfo>::value, "Type T must be a TensorInfo"); |
| 99 | |
Derek Lamberti | 2a434a8 | 2019-03-20 13:07:57 +0000 | [diff] [blame] | 100 | return (t1.GetDataType() == t2.GetDataType()) && AllTypesAreEqualImpl(t2, rest...); |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | struct TypesAreEqual : public Rule |
| 104 | { |
| 105 | template<typename ... Ts> |
| 106 | TypesAreEqual(const Ts&... ts) |
| 107 | { |
| 108 | m_Res = AllTypesAreEqualImpl(ts...); |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | struct QuantizationParametersAreEqual : public Rule |
| 113 | { |
| 114 | QuantizationParametersAreEqual(const TensorInfo& info0, const TensorInfo& info1) |
| 115 | { |
| 116 | m_Res = info0.GetQuantizationScale() == info1.GetQuantizationScale() && |
| 117 | info0.GetQuantizationOffset() == info1.GetQuantizationOffset(); |
| 118 | } |
| 119 | }; |
| 120 | |
| 121 | struct TypeAnyOf : public Rule |
| 122 | { |
| 123 | template<typename Container> |
| 124 | TypeAnyOf(const TensorInfo& info, const Container& c) |
| 125 | { |
| 126 | m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 127 | { |
| 128 | return dt == info.GetDataType(); |
| 129 | }); |
| 130 | } |
| 131 | }; |
| 132 | |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 133 | struct TypeIs : public Rule |
| 134 | { |
| 135 | TypeIs(const TensorInfo& info, DataType dt) |
| 136 | { |
| 137 | m_Res = dt == info.GetDataType(); |
| 138 | } |
| 139 | }; |
| 140 | |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 141 | struct BiasAndWeightsTypesMatch : public Rule |
| 142 | { |
| 143 | BiasAndWeightsTypesMatch(const TensorInfo& biases, const TensorInfo& weights) |
| 144 | { |
| 145 | m_Res = biases.GetDataType() == GetBiasTypeFromWeightsType(weights.GetDataType()).value(); |
| 146 | } |
| 147 | }; |
| 148 | |
| 149 | struct BiasAndWeightsTypesCompatible : public Rule |
| 150 | { |
| 151 | template<typename Container> |
| 152 | BiasAndWeightsTypesCompatible(const TensorInfo& info, const Container& c) |
| 153 | { |
| 154 | m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) |
| 155 | { |
| 156 | return dt == GetBiasTypeFromWeightsType(info.GetDataType()).value(); |
| 157 | }); |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 158 | } |
| 159 | }; |
| 160 | |
| 161 | struct ShapesAreSameRank : public Rule |
| 162 | { |
| 163 | ShapesAreSameRank(const TensorInfo& info0, const TensorInfo& info1) |
| 164 | { |
| 165 | m_Res = info0.GetShape().GetNumDimensions() == info1.GetShape().GetNumDimensions(); |
| 166 | } |
| 167 | }; |
| 168 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 169 | struct ShapesAreSameTotalSize : public Rule |
| 170 | { |
| 171 | ShapesAreSameTotalSize(const TensorInfo& info0, const TensorInfo& info1) |
| 172 | { |
| 173 | m_Res = info0.GetNumElements() == info1.GetNumElements(); |
| 174 | } |
| 175 | }; |
| 176 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 177 | struct ShapesAreBroadcastCompatible : public Rule |
| 178 | { |
| 179 | unsigned int CalcInputSize(const TensorShape& in, const TensorShape& out, unsigned int idx) |
| 180 | { |
| 181 | unsigned int offset = out.GetNumDimensions() - in.GetNumDimensions(); |
| 182 | unsigned int sizeIn = (idx < offset) ? 1 : in[idx-offset]; |
| 183 | return sizeIn; |
| 184 | } |
| 185 | |
| 186 | ShapesAreBroadcastCompatible(const TensorInfo& in0, const TensorInfo& in1, const TensorInfo& out) |
| 187 | { |
| 188 | const TensorShape& shape0 = in0.GetShape(); |
| 189 | const TensorShape& shape1 = in1.GetShape(); |
| 190 | const TensorShape& outShape = out.GetShape(); |
| 191 | |
| 192 | for (unsigned int i=0; i < outShape.GetNumDimensions() && m_Res; i++) |
| 193 | { |
| 194 | unsigned int sizeOut = outShape[i]; |
| 195 | unsigned int sizeIn0 = CalcInputSize(shape0, outShape, i); |
| 196 | unsigned int sizeIn1 = CalcInputSize(shape1, outShape, i); |
| 197 | |
| 198 | m_Res &= ((sizeIn0 == sizeOut) || (sizeIn0 == 1)) && |
| 199 | ((sizeIn1 == sizeOut) || (sizeIn1 == 1)); |
| 200 | } |
| 201 | } |
| 202 | }; |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 203 | |
| 204 | struct TensorNumDimensionsAreCorrect : public Rule |
| 205 | { |
| 206 | TensorNumDimensionsAreCorrect(const TensorInfo& info, unsigned int expectedNumDimensions) |
| 207 | { |
| 208 | m_Res = info.GetNumDimensions() == expectedNumDimensions; |
| 209 | } |
| 210 | }; |
| 211 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 212 | } // namespace |
| 213 | |
| 214 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 215 | bool RefLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 216 | const TensorInfo& output, |
| 217 | const ActivationDescriptor& descriptor, |
| 218 | Optional<std::string&> reasonIfUnsupported) const |
| 219 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 220 | bool supported = true; |
| 221 | |
| 222 | // Define supported types. |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 223 | std::array<DataType,3> supportedTypes = { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 224 | DataType::Float32, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 225 | DataType::QuantisedAsymm8, |
| 226 | DataType::QuantisedSymm16 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 230 | "Reference activation: input type not supported."); |
| 231 | |
| 232 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 233 | "Reference activation: output type not supported."); |
| 234 | |
| 235 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 236 | "Reference activation: input and output types mismatched."); |
| 237 | |
| 238 | supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported, |
| 239 | "Reference activation: input and output shapes are of different rank."); |
| 240 | |
| 241 | |
| 242 | struct ActivationFunctionSupported : public Rule |
| 243 | { |
| 244 | ActivationFunctionSupported(const ActivationDescriptor& desc) |
| 245 | { |
| 246 | switch(desc.m_Function) |
| 247 | { |
| 248 | case ActivationFunction::Abs: |
| 249 | case ActivationFunction::BoundedReLu: |
| 250 | case ActivationFunction::LeakyReLu: |
| 251 | case ActivationFunction::Linear: |
| 252 | case ActivationFunction::ReLu: |
| 253 | case ActivationFunction::Sigmoid: |
| 254 | case ActivationFunction::SoftReLu: |
| 255 | case ActivationFunction::Sqrt: |
| 256 | case ActivationFunction::Square: |
| 257 | case ActivationFunction::TanH: |
| 258 | { |
| 259 | m_Res = true; |
| 260 | break; |
| 261 | } |
| 262 | default: |
| 263 | { |
| 264 | m_Res = false; |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | }; |
| 270 | |
| 271 | // Function is supported |
| 272 | supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported, |
| 273 | "Reference activation: function not supported."); |
| 274 | |
| 275 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 279 | const TensorInfo& input1, |
| 280 | const TensorInfo& output, |
| 281 | Optional<std::string&> reasonIfUnsupported) const |
| 282 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 283 | bool supported = true; |
| 284 | |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 285 | std::array<DataType,3> supportedTypes = { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 286 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 287 | DataType::QuantisedAsymm8, |
| 288 | DataType::QuantisedSymm16 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 292 | "Reference addition: input 0 is not a supported type."); |
| 293 | |
| 294 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 295 | "Reference addition: input 1 is not a supported type."); |
| 296 | |
| 297 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 298 | "Reference addition: output is not a supported type."); |
| 299 | |
| 300 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 301 | "Reference addition: input 0 and Input 1 types are mismatched"); |
| 302 | |
| 303 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 304 | "Reference addition: input and output types are mismatched"); |
| 305 | |
| 306 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 307 | "Reference addition: shapes are not suitable for implicit broadcast."); |
| 308 | |
| 309 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 313 | const TensorInfo& output, |
| 314 | const TensorInfo& mean, |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 315 | const TensorInfo& variance, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 316 | const TensorInfo& beta, |
| 317 | const TensorInfo& gamma, |
| 318 | const BatchNormalizationDescriptor& descriptor, |
| 319 | Optional<std::string&> reasonIfUnsupported) const |
| 320 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 321 | ignore_unused(descriptor); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 322 | |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 323 | std::array<DataType, 3> supportedTypes = |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 324 | { |
| 325 | DataType::Float32, |
Matteo Martincigh | f550713 | 2019-06-04 10:59:47 +0100 | [diff] [blame] | 326 | DataType::QuantisedAsymm8, |
| 327 | DataType::QuantisedSymm16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | bool supported = true; |
| 331 | |
| 332 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 333 | "Reference batch normalization: input is not a supported type."); |
| 334 | |
| 335 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 336 | "Reference batch normalization: output is not a supported type."); |
| 337 | |
| 338 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 339 | "Reference batch normalization: input and output types are mismatched"); |
| 340 | |
| 341 | supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported, |
| 342 | "Reference batch normalization: mean is not a supported type."); |
| 343 | |
| 344 | supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported, |
| 345 | "Reference batch normalization: variance is not a supported type."); |
| 346 | |
| 347 | supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported, |
| 348 | "Reference batch normalization: beta is not a supported type."); |
| 349 | |
| 350 | supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported, |
| 351 | "Reference batch normalization: gamma is not a supported type."); |
| 352 | |
| 353 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 356 | bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 357 | const TensorInfo& output, |
| 358 | const BatchToSpaceNdDescriptor& descriptor, |
| 359 | Optional<std::string&> reasonIfUnsupported) const |
| 360 | { |
| 361 | ignore_unused(descriptor); |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 362 | |
| 363 | bool supported = true; |
| 364 | |
| 365 | std::string batchToSpaceNdLayerStr = "batchToSpaceNd"; |
| 366 | std::string inputTensorStr = "input"; |
| 367 | std::string outputTensorStr = "output"; |
| 368 | |
| 369 | // Define supported types. |
| 370 | std::array<DataType,3> supportedTypes = |
| 371 | { |
| 372 | DataType::Float32, |
| 373 | DataType::QuantisedAsymm8, |
| 374 | DataType::QuantisedSymm16 |
| 375 | }; |
| 376 | |
| 377 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 378 | "Reference BatchToSpaceNd: input type not supported."); |
| 379 | |
| 380 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 381 | "Reference BatchToSpaceNd: output type not supported."); |
| 382 | |
| 383 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 384 | "Reference BatchToSpaceNd: input and output types mismatched."); |
| 385 | |
| 386 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4), |
| 387 | reasonIfUnsupported, |
| 388 | CreateIncorrectDimensionsErrorMsg(4, |
| 389 | output.GetNumDimensions(), |
| 390 | batchToSpaceNdLayerStr, |
| 391 | outputTensorStr).data()); |
| 392 | |
| 393 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4), |
| 394 | reasonIfUnsupported, |
| 395 | CreateIncorrectDimensionsErrorMsg(4, |
| 396 | input.GetNumDimensions(), |
| 397 | batchToSpaceNdLayerStr, |
| 398 | inputTensorStr).data()); |
| 399 | |
| 400 | return supported; |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 403 | bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 404 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 405 | const ConcatDescriptor& descriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 406 | Optional<std::string&> reasonIfUnsupported) const |
| 407 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 408 | ignore_unused(descriptor); |
| 409 | |
| 410 | bool supported = true; |
| 411 | std::array<DataType,3> supportedTypes = |
| 412 | { |
| 413 | DataType::Float32, |
| 414 | DataType::QuantisedAsymm8, |
| 415 | DataType::QuantisedSymm16 |
| 416 | }; |
| 417 | |
| 418 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 419 | "Reference concatenation: output type not supported"); |
| 420 | for (const TensorInfo* input : inputs) |
| 421 | { |
| 422 | supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported, |
| 423 | "Reference concatenation: input type not supported"); |
| 424 | |
| 425 | supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported, |
| 426 | "Reference concatenation: input and output types mismatched."); |
| 427 | } |
| 428 | |
| 429 | return supported; |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 430 | } |
| 431 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 432 | bool RefLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 433 | Optional<std::string&> reasonIfUnsupported) const |
| 434 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 435 | std::array<DataType,4> supportedTypes = |
| 436 | { |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 437 | DataType::Float32, |
| 438 | DataType::Signed32, |
| 439 | DataType::QuantisedAsymm8, |
| 440 | DataType::QuantisedSymm16 |
| 441 | }; |
| 442 | |
| 443 | return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 444 | "Reference constant: output is not a supported type."); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 448 | const TensorInfo& output, |
| 449 | Optional<std::string&> reasonIfUnsupported) const |
| 450 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 451 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 452 | input.GetDataType(), |
| 453 | &TrueFunc<>, |
| 454 | &FalseInputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 455 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 456 | &FalseFuncI32<>, |
| 457 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 458 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 459 | output.GetDataType(), |
| 460 | &FalseOutputFuncF16<>, |
| 461 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 462 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 463 | &FalseFuncI32<>, |
| 464 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 468 | const TensorInfo& output, |
| 469 | Optional<std::string&> reasonIfUnsupported) const |
| 470 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 471 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 472 | input.GetDataType(), |
| 473 | &FalseInputFuncF16<>, |
| 474 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 475 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 476 | &FalseFuncI32<>, |
| 477 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 478 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 479 | output.GetDataType(), |
| 480 | &TrueFunc<>, |
| 481 | &FalseOutputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 482 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 483 | &FalseFuncI32<>, |
| 484 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 488 | const TensorInfo& output, |
| 489 | const Convolution2dDescriptor& descriptor, |
| 490 | const TensorInfo& weights, |
| 491 | const Optional<TensorInfo>& biases, |
| 492 | Optional<std::string&> reasonIfUnsupported) const |
| 493 | { |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 494 | bool supported = true; |
| 495 | |
| 496 | // Define supported types. |
| 497 | std::array<DataType,3> supportedTypes = { |
| 498 | DataType::Float32, |
| 499 | DataType::QuantisedAsymm8, |
| 500 | DataType::QuantisedSymm16 |
| 501 | }; |
| 502 | |
| 503 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 504 | "Reference convolution2d: input is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 505 | |
| 506 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 507 | "Reference convolution2d: output is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 508 | |
| 509 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 510 | "Reference convolution2d: weights is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 511 | |
| 512 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 513 | "Reference convolution2d: input and output types mismatched."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 514 | |
| 515 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 516 | "Reference convolution2d: input and weights types mismatched."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 517 | |
| 518 | if (biases.has_value()) |
| 519 | { |
| 520 | std::array<DataType,3> biasesSupportedTypes = { |
| 521 | DataType::Float32, |
| 522 | DataType::Signed32 |
| 523 | }; |
| 524 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 525 | "Reference convolution2d: biases is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 526 | } |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 527 | ignore_unused(descriptor); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 528 | |
| 529 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 532 | bool RefLayerSupport::IsDebugSupported(const TensorInfo& input, |
| 533 | const TensorInfo& output, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 534 | Optional<std::string&> reasonIfUnsupported) const |
| 535 | { |
| 536 | ignore_unused(output); |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 537 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 538 | input.GetDataType(), |
| 539 | &TrueFunc<>, |
| 540 | &TrueFunc<>); |
| 541 | } |
| 542 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 543 | bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 544 | const TensorInfo& output, |
| 545 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 546 | const TensorInfo& weights, |
| 547 | const Optional<TensorInfo>& biases, |
| 548 | Optional<std::string&> reasonIfUnsupported) const |
| 549 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 550 | bool supported = true; |
| 551 | |
| 552 | // Define supported types. |
| 553 | std::array<DataType,3> supportedTypes = |
| 554 | { |
| 555 | DataType::Float32, |
| 556 | DataType::QuantisedAsymm8, |
| 557 | DataType::QuantisedSymm16 |
| 558 | }; |
| 559 | |
| 560 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 561 | "Reference DepthwiseConvolution2d: input is not a supported type."); |
| 562 | |
| 563 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 564 | "Reference DepthwiseConvolution2d: output is not a supported type."); |
| 565 | |
| 566 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 567 | "Reference DepthwiseConvolution2d: weights is not a supported type."); |
| 568 | |
| 569 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 570 | "Reference DepthwiseConvolution2d: input and output types mismatched."); |
| 571 | |
| 572 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 573 | "Reference DepthwiseConvolution2d: input and weights types mismatched."); |
| 574 | |
| 575 | if (biases.has_value()) |
| 576 | { |
| 577 | std::array<DataType,2> biasesSupportedTypes = |
| 578 | { |
| 579 | DataType::Float32, |
| 580 | DataType::Signed32 |
| 581 | }; |
| 582 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 583 | "Reference DepthwiseConvolution2d: biases is not a supported type."); |
| 584 | } |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 585 | ignore_unused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 586 | |
| 587 | return supported; |
| 588 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 589 | } |
| 590 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 591 | bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input, |
| 592 | const TensorInfo& output, |
| 593 | Optional<std::string&> reasonIfUnsupported) const |
| 594 | { |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 595 | bool supported = true; |
| 596 | |
| 597 | std::array<DataType,2> supportedInputTypes = { |
| 598 | DataType::QuantisedAsymm8, |
| 599 | DataType::QuantisedSymm16 |
| 600 | }; |
| 601 | |
| 602 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 603 | "Reference dequantize: input type not supported."); |
| 604 | |
| 605 | std::array<DataType,2> supportedOutputTypes = { |
| 606 | DataType::Float32, |
| 607 | }; |
| 608 | |
| 609 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 610 | "Reference dequantize: output type not supported."); |
| 611 | |
| 612 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 613 | "Reference dequantize: input and output shapes have different num total elements."); |
| 614 | |
| 615 | return supported; |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 618 | bool RefLayerSupport::IsDetectionPostProcessSupported(const armnn::TensorInfo& input0, |
| 619 | const armnn::TensorInfo& input1, |
| 620 | const armnn::DetectionPostProcessDescriptor& descriptor, |
| 621 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 622 | { |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 623 | bool supported = true; |
| 624 | |
| 625 | std::vector<DataType> supportedInputTypes = |
| 626 | { |
| 627 | DataType::Float32, |
| 628 | DataType::QuantisedAsymm8, |
| 629 | DataType::QuantisedSymm16 |
| 630 | }; |
| 631 | |
| 632 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported, |
| 633 | "Reference DetectionPostProcess: input 0 is not a supported type."); |
| 634 | |
| 635 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedInputTypes), reasonIfUnsupported, |
| 636 | "Reference DetectionPostProcess: input 1 is not a supported type."); |
| 637 | |
| 638 | return supported; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 641 | bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 642 | const TensorInfo& output, |
| 643 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 644 | const TensorInfo& weights, |
| 645 | const Optional<TensorInfo>& biases, |
| 646 | Optional<std::string&> reasonIfUnsupported) const |
| 647 | { |
Aron Virginas-Tar | aece4ed | 2019-06-14 17:00:09 +0100 | [diff] [blame] | 648 | return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported); |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Aron Virginas-Tar | aece4ed | 2019-06-14 17:00:09 +0100 | [diff] [blame] | 651 | bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 652 | const TensorInfo& input1, |
| 653 | const TensorInfo& output, |
| 654 | Optional<std::string&> reasonIfUnsupported) const |
| 655 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 656 | bool supported = true; |
| 657 | |
| 658 | std::array<DataType,3> supportedTypes = { |
| 659 | DataType::Float32, |
| 660 | DataType::QuantisedAsymm8, |
| 661 | DataType::QuantisedSymm16 |
| 662 | }; |
| 663 | |
| 664 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 665 | "Reference division: input 0 is not a supported type."); |
| 666 | |
| 667 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 668 | "Reference division: input 1 is not a supported type."); |
| 669 | |
| 670 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 671 | "Reference division: output is not a supported type."); |
| 672 | |
| 673 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 674 | "Reference division: input 0 and Input 1 types are mismatched"); |
| 675 | |
| 676 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 677 | "Reference division: input and output types are mismatched"); |
| 678 | |
| 679 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 680 | "Reference division: shapes are not suitable for implicit broadcast."); |
| 681 | |
| 682 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 683 | } |
| 684 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 685 | bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0, |
| 686 | const TensorInfo& input1, |
| 687 | const TensorInfo& output, |
| 688 | Optional<std::string&> reasonIfUnsupported) const |
| 689 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 690 | bool supported = true; |
| 691 | |
| 692 | std::array<DataType,3> supportedTypes = |
| 693 | { |
| 694 | DataType::Float32, |
| 695 | DataType::QuantisedAsymm8, |
| 696 | DataType::QuantisedSymm16 |
| 697 | }; |
| 698 | |
| 699 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 700 | "Reference equal: input 0 is not a supported type."); |
| 701 | |
| 702 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 703 | "Reference equal: input 1 is not a supported type."); |
| 704 | |
| 705 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 706 | "Reference equal: input 0 and Input 1 types are mismatched"); |
| 707 | |
| 708 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 709 | "Reference equal: shapes are not suitable for implicit broadcast."); |
| 710 | |
| 711 | return supported; |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 712 | } |
| 713 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 714 | bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input, |
| 715 | const FakeQuantizationDescriptor& descriptor, |
| 716 | Optional<std::string&> reasonIfUnsupported) const |
| 717 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 718 | ignore_unused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 719 | bool supported = true; |
| 720 | |
| 721 | std::array<DataType,1> supportedTypes = |
| 722 | { |
| 723 | DataType::Float32 |
| 724 | }; |
| 725 | |
| 726 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 727 | "Reference fake quantization: input type not supported."); |
| 728 | |
| 729 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | bool RefLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 733 | const TensorInfo& output, |
| 734 | Optional<std::string&> reasonIfUnsupported) const |
| 735 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 736 | ignore_unused(output); |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 737 | bool supported = true; |
| 738 | |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 739 | std::array<DataType,2> supportedTypes = |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 740 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 741 | DataType::Float32, |
| 742 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 743 | }; |
| 744 | |
| 745 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 746 | "Reference Floor: input type not supported."); |
| 747 | |
| 748 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 749 | "Reference Floor: output type not supported."); |
| 750 | |
| 751 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 755 | const TensorInfo& output, |
| 756 | const TensorInfo& weights, |
| 757 | const TensorInfo& biases, |
| 758 | const FullyConnectedDescriptor& descriptor, |
| 759 | Optional<std::string&> reasonIfUnsupported) const |
| 760 | { |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 761 | bool supported = true; |
| 762 | |
| 763 | // Define supported types. |
| 764 | std::array<DataType,3> supportedTypes = |
| 765 | { |
| 766 | DataType::Float32, |
| 767 | DataType::QuantisedAsymm8, |
| 768 | DataType::QuantisedSymm16 |
| 769 | }; |
| 770 | |
| 771 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 772 | "Reference Fully Connected: input type not supported."); |
| 773 | |
| 774 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 775 | "Reference Fully Connected: output type not supported."); |
| 776 | |
| 777 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 778 | "Reference Fully Connected: input and output types mismatched."); |
| 779 | |
| 780 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 781 | "Reference Fully Connected: weights type not supported."); |
| 782 | |
| 783 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 784 | "Reference Fully Connected: input and weight types mismatched."); |
| 785 | |
| 786 | if (descriptor.m_BiasEnabled) |
| 787 | { |
| 788 | // Defined supported types for bias |
| 789 | std::array<DataType, 2> |
| 790 | supportedBiasTypes = |
| 791 | { |
| 792 | DataType::Float32, |
| 793 | DataType::Signed32 |
| 794 | }; |
| 795 | |
| 796 | supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported, |
| 797 | "Reference Fully Connected: bias type not supported."); |
| 798 | |
| 799 | supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported, |
| 800 | "Reference Fully Connected: bias and weight types mismatch."); |
| 801 | |
| 802 | supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported, |
| 803 | "Reference Fully Connected: bias type inferred from weights is incompatible."); |
| 804 | |
| 805 | } |
| 806 | |
| 807 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 808 | } |
| 809 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 810 | bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0, |
| 811 | const armnn::TensorInfo& input1, |
| 812 | const armnn::TensorInfo& output, |
| 813 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 814 | { |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 815 | bool supported = true; |
| 816 | std::array<DataType,3> supportedTypes = |
| 817 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 818 | DataType::Float32, |
| 819 | DataType::QuantisedAsymm8, |
| 820 | DataType::QuantisedSymm16 |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 821 | }; |
| 822 | |
| 823 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 824 | "Reference Gather: input type not supported"); |
| 825 | |
| 826 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 827 | "Reference Gather: output type not supported"); |
| 828 | |
| 829 | supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported, |
| 830 | "Reference Gather: indices (input1) type not supported"); |
| 831 | |
| 832 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 833 | "Reference Gather: input and output types not matching"); |
| 834 | |
| 835 | return supported; |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 836 | } |
| 837 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 838 | bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 839 | const TensorInfo& input1, |
| 840 | const TensorInfo& output, |
| 841 | Optional<std::string&> reasonIfUnsupported) const |
| 842 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 843 | bool supported = true; |
| 844 | |
| 845 | std::array<DataType,3> supportedTypes = |
| 846 | { |
| 847 | DataType::Float32, |
| 848 | DataType::QuantisedAsymm8, |
| 849 | DataType::QuantisedSymm16 |
| 850 | }; |
| 851 | |
| 852 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 853 | "Reference greater: input 0 is not a supported type."); |
| 854 | |
| 855 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 856 | "Reference greater: input 1 is not a supported type."); |
| 857 | |
| 858 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 859 | "Reference greater: input 0 and Input 1 types are mismatched"); |
| 860 | |
| 861 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 862 | "Reference greater: shapes are not suitable for implicit broadcast."); |
| 863 | |
| 864 | return supported; |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 865 | } |
| 866 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 867 | bool RefLayerSupport::IsInputSupported(const TensorInfo& input, |
| 868 | Optional<std::string&> reasonIfUnsupported) const |
| 869 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 870 | return true; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 874 | const TensorInfo& output, |
| 875 | const L2NormalizationDescriptor& descriptor, |
| 876 | Optional<std::string&> reasonIfUnsupported) const |
| 877 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 878 | ignore_unused(descriptor); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 879 | // Define supported types |
Ferran Balaguer | c6138d8 | 2019-06-13 17:23:50 +0100 | [diff] [blame] | 880 | std::array<DataType, 3> supportedTypes = |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 881 | { |
| 882 | DataType::Float32, |
Ferran Balaguer | c6138d8 | 2019-06-13 17:23:50 +0100 | [diff] [blame] | 883 | DataType::QuantisedAsymm8, |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 884 | DataType::QuantisedSymm16 |
| 885 | }; |
| 886 | |
| 887 | bool supported = true; |
| 888 | |
| 889 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 890 | "Reference L2normalization: input type not supported."); |
| 891 | |
| 892 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 893 | "Reference L2normalization: output type not supported."); |
| 894 | |
| 895 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 896 | "Reference L2normalization: input and output types mismatched."); |
| 897 | |
| 898 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 899 | "Reference L2normalization: input and output shapes have different " |
| 900 | "num total elements."); |
| 901 | |
| 902 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | bool RefLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 906 | const TensorInfo& outputStateIn, |
| 907 | const TensorInfo& cellStateIn, |
| 908 | const TensorInfo& scratchBuffer, |
| 909 | const TensorInfo& outputStateOut, |
| 910 | const TensorInfo& cellStateOut, |
| 911 | const TensorInfo& output, |
| 912 | const LstmDescriptor& descriptor, |
| 913 | const TensorInfo& inputToForgetWeights, |
| 914 | const TensorInfo& inputToCellWeights, |
| 915 | const TensorInfo& inputToOutputWeights, |
| 916 | const TensorInfo& recurrentToForgetWeights, |
| 917 | const TensorInfo& recurrentToCellWeights, |
| 918 | const TensorInfo& recurrentToOutputWeights, |
| 919 | const TensorInfo& forgetGateBias, |
| 920 | const TensorInfo& cellBias, |
| 921 | const TensorInfo& outputGateBias, |
| 922 | const TensorInfo* inputToInputWeights, |
| 923 | const TensorInfo* recurrentToInputWeights, |
| 924 | const TensorInfo* cellToInputWeights, |
| 925 | const TensorInfo* inputGateBias, |
| 926 | const TensorInfo* projectionWeights, |
| 927 | const TensorInfo* projectionBias, |
| 928 | const TensorInfo* cellToForgetWeights, |
| 929 | const TensorInfo* cellToOutputWeights, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 930 | Optional<std::string&> reasonIfUnsupported, |
| 931 | const TensorInfo* inputLayerNormWeights, |
| 932 | const TensorInfo* forgetLayerNormWeights, |
| 933 | const TensorInfo* cellLayerNormWeights, |
| 934 | const TensorInfo* outputLayerNormWeights) const |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 935 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 936 | ignore_unused(descriptor); |
| 937 | ignore_unused(inputToForgetWeights); |
| 938 | ignore_unused(inputToCellWeights); |
| 939 | ignore_unused(inputToOutputWeights); |
| 940 | ignore_unused(recurrentToForgetWeights); |
| 941 | ignore_unused(recurrentToCellWeights); |
| 942 | ignore_unused(recurrentToOutputWeights); |
| 943 | ignore_unused(forgetGateBias); |
| 944 | ignore_unused(cellBias); |
| 945 | ignore_unused(outputGateBias); |
| 946 | ignore_unused(inputToInputWeights); |
| 947 | ignore_unused(recurrentToInputWeights); |
| 948 | ignore_unused(cellToInputWeights); |
| 949 | ignore_unused(inputGateBias); |
| 950 | ignore_unused(projectionWeights); |
| 951 | ignore_unused(projectionBias); |
| 952 | ignore_unused(cellToForgetWeights); |
| 953 | ignore_unused(cellToOutputWeights); |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 954 | ignore_unused(inputLayerNormWeights); |
| 955 | ignore_unused(forgetLayerNormWeights); |
| 956 | ignore_unused(cellLayerNormWeights); |
| 957 | ignore_unused(outputLayerNormWeights); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 958 | |
| 959 | bool supported = true; |
| 960 | |
| 961 | std::array<DataType,2> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 962 | DataType::Float32, |
| 963 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 964 | }; |
| 965 | |
| 966 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 967 | "Reference Lstm: input is not a supported type."); |
| 968 | |
| 969 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported, |
| 970 | "Reference Lstm: input and outputStateIn types are mismatched"); |
| 971 | |
| 972 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported, |
| 973 | "Reference Lstm: input and cellStateIn types are mismatched"); |
| 974 | |
| 975 | supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported, |
| 976 | "Reference Lstm: input and scratchBuffer types are mismatched"); |
| 977 | |
| 978 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported, |
| 979 | "Reference Lstm: input and outputStateOut types are mismatched"); |
| 980 | |
| 981 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported, |
| 982 | "Reference Lstm: input and cellStateOut types are mismatched"); |
| 983 | |
| 984 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 985 | "Reference Lstm: input and output types are mismatched"); |
| 986 | |
| 987 | return supported; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 988 | } |
| 989 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 990 | bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 991 | const TensorInfo& input1, |
| 992 | const TensorInfo& output, |
| 993 | Optional<std::string&> reasonIfUnsupported) const |
| 994 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 995 | bool supported = true; |
| 996 | |
| 997 | std::array<DataType,3> supportedTypes = { |
| 998 | DataType::Float32, |
| 999 | DataType::QuantisedAsymm8, |
| 1000 | DataType::QuantisedSymm16 |
| 1001 | }; |
| 1002 | |
| 1003 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1004 | "Reference maximum: input 0 is not a supported type."); |
| 1005 | |
| 1006 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1007 | "Reference maximum: input 1 is not a supported type."); |
| 1008 | |
| 1009 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1010 | "Reference maximum: output is not a supported type."); |
| 1011 | |
| 1012 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1013 | "Reference maximum: input 0 and Input 1 types are mismatched"); |
| 1014 | |
| 1015 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1016 | "Reference maximum: input and output types are mismatched"); |
| 1017 | |
| 1018 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1019 | "Reference maximum: shapes are not suitable for implicit broadcast."); |
| 1020 | |
| 1021 | return supported; |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1024 | bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 1025 | const TensorInfo& output, |
| 1026 | const MeanDescriptor& descriptor, |
| 1027 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1028 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1029 | bool supported = true; |
| 1030 | std::string meanLayerStr = "Mean"; |
| 1031 | std::string outputTensorStr = "output"; |
| 1032 | |
James Conroy | b80775f | 2019-06-11 11:25:30 +0100 | [diff] [blame] | 1033 | std::array<DataType,3> supportedTypes = |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1034 | { |
| 1035 | DataType::Float32, |
James Conroy | b80775f | 2019-06-11 11:25:30 +0100 | [diff] [blame] | 1036 | DataType::QuantisedAsymm8, |
| 1037 | DataType::QuantisedSymm16 |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1038 | }; |
| 1039 | |
| 1040 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1041 | "Reference Mean: input type not supported."); |
| 1042 | |
| 1043 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1044 | "Reference Mean: input and output types are mismatched"); |
| 1045 | |
| 1046 | if (descriptor.m_KeepDims) |
| 1047 | { |
| 1048 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()), |
| 1049 | reasonIfUnsupported, |
| 1050 | CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(), |
| 1051 | output.GetNumDimensions(), |
| 1052 | meanLayerStr, outputTensorStr).data()); |
| 1053 | } |
| 1054 | else if (descriptor.m_Axis.empty()) |
| 1055 | { |
| 1056 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1), |
| 1057 | reasonIfUnsupported, |
| 1058 | CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(), |
| 1059 | meanLayerStr, outputTensorStr).data()); |
| 1060 | } |
| 1061 | else |
| 1062 | { |
| 1063 | auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size()); |
| 1064 | |
| 1065 | if (outputDim > 0) |
| 1066 | { |
| 1067 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim), |
| 1068 | reasonIfUnsupported, |
| 1069 | CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(), |
| 1070 | meanLayerStr, outputTensorStr).data()); |
| 1071 | } |
| 1072 | else |
| 1073 | { |
| 1074 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1), |
| 1075 | reasonIfUnsupported, |
| 1076 | CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(), |
| 1077 | meanLayerStr, outputTensorStr).data()); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | return supported; |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1084 | bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 1085 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1086 | const MergerDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1087 | Optional<std::string&> reasonIfUnsupported) const |
| 1088 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 1089 | return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1092 | bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 1093 | const TensorInfo &output, |
| 1094 | Optional<std::string &> reasonIfUnsupported) const |
| 1095 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1096 | bool supported = true; |
| 1097 | |
| 1098 | std::array<DataType,5> supportedTypes = |
| 1099 | { |
| 1100 | DataType::Float32, |
| 1101 | DataType::Float16, |
| 1102 | DataType::QuantisedAsymm8, |
| 1103 | DataType::QuantisedSymm16, |
| 1104 | DataType::Boolean |
| 1105 | }; |
| 1106 | |
| 1107 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1108 | "Reference MemCopy: input type not supported"); |
| 1109 | |
| 1110 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1111 | "Reference MemCopy: output type not supported"); |
| 1112 | |
| 1113 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1114 | "Reference MemCopy: input and output types are mismatched"); |
| 1115 | |
| 1116 | return supported; |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 1119 | bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 1120 | const TensorInfo& input1, |
| 1121 | const TensorInfo& output, |
| 1122 | Optional<std::string&> reasonIfUnsupported) const |
| 1123 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1124 | bool supported = true; |
| 1125 | |
| 1126 | std::array<DataType,3> supportedTypes = { |
| 1127 | DataType::Float32, |
| 1128 | DataType::QuantisedAsymm8, |
| 1129 | DataType::QuantisedSymm16 |
| 1130 | }; |
| 1131 | |
| 1132 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1133 | "Reference minimum: input 0 is not a supported type."); |
| 1134 | |
| 1135 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1136 | "Reference minimum: input 1 is not a supported type."); |
| 1137 | |
| 1138 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1139 | "Reference minimum: output is not a supported type."); |
| 1140 | |
| 1141 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1142 | "Reference minimum: input 0 and Input 1 types are mismatched"); |
| 1143 | |
| 1144 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1145 | "Reference minimum: input and output types are mismatched"); |
| 1146 | |
| 1147 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1148 | "Reference minimum: shapes are not suitable for implicit broadcast."); |
| 1149 | |
| 1150 | return supported; |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1153 | bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 1154 | const TensorInfo& input1, |
| 1155 | const TensorInfo& output, |
| 1156 | Optional<std::string&> reasonIfUnsupported) const |
| 1157 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1158 | bool supported = true; |
| 1159 | |
| 1160 | std::array<DataType,3> supportedTypes = { |
| 1161 | DataType::Float32, |
| 1162 | DataType::QuantisedAsymm8, |
| 1163 | DataType::QuantisedSymm16 |
| 1164 | }; |
| 1165 | |
| 1166 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1167 | "Reference multiplication: input 0 is not a supported type."); |
| 1168 | |
| 1169 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1170 | "Reference multiplication: input 1 is not a supported type."); |
| 1171 | |
| 1172 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1173 | "Reference multiplication: output is not a supported type."); |
| 1174 | |
| 1175 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1176 | "Reference multiplication: input 0 and Input 1 types are mismatched"); |
| 1177 | |
| 1178 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1179 | "Reference multiplication: input and output types are mismatched"); |
| 1180 | |
| 1181 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1182 | "Reference multiplication: shapes are not suitable for implicit broadcast."); |
| 1183 | |
| 1184 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 1188 | const TensorInfo& output, |
| 1189 | const NormalizationDescriptor& descriptor, |
| 1190 | Optional<std::string&> reasonIfUnsupported) const |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1191 | { |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1192 | ignore_unused(descriptor); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1193 | |
| 1194 | // Define supported types |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 1195 | std::array<DataType, 4> supportedTypes = |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1196 | { |
| 1197 | DataType::Float16, |
| 1198 | DataType::Float32, |
Matteo Martincigh | 6aeb771 | 2019-06-05 17:23:29 +0100 | [diff] [blame] | 1199 | DataType::QuantisedAsymm8, |
| 1200 | DataType::QuantisedSymm16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 1201 | }; |
| 1202 | |
| 1203 | bool supported = true; |
| 1204 | |
| 1205 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1206 | "Reference normalization: input type not supported."); |
| 1207 | |
| 1208 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1209 | "Reference normalization: output type not supported."); |
| 1210 | |
| 1211 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1212 | "Reference normalization: input and output shapes have different " |
| 1213 | "num total elements."); |
| 1214 | |
| 1215 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | bool RefLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 1219 | Optional<std::string&> reasonIfUnsupported) const |
| 1220 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 1221 | return true; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | bool RefLayerSupport::IsPadSupported(const TensorInfo& input, |
| 1225 | const TensorInfo& output, |
| 1226 | const PadDescriptor& descriptor, |
| 1227 | Optional<std::string&> reasonIfUnsupported) const |
| 1228 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1229 | ignore_unused(output); |
| 1230 | ignore_unused(descriptor); |
jimfly01 | f6ba747 | 2018-12-04 10:09:52 +0000 | [diff] [blame] | 1231 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1232 | input.GetDataType(), |
| 1233 | &TrueFunc<>, |
| 1234 | &TrueFunc<>); |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1237 | bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 1238 | const TensorInfo& output, |
| 1239 | const PermuteDescriptor& descriptor, |
| 1240 | Optional<std::string&> reasonIfUnsupported) const |
| 1241 | { |
| 1242 | ignore_unused(output); |
| 1243 | ignore_unused(descriptor); |
| 1244 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1245 | input.GetDataType(), |
| 1246 | &TrueFunc<>, |
| 1247 | &TrueFunc<>); |
| 1248 | } |
| 1249 | |
| 1250 | bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 1251 | const TensorInfo& output, |
| 1252 | const Pooling2dDescriptor& descriptor, |
| 1253 | Optional<std::string&> reasonIfUnsupported) const |
| 1254 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1255 | ignore_unused(descriptor); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1256 | bool supported = true; |
| 1257 | |
| 1258 | // Define supported output and inputs types. |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 1259 | std::array<DataType,3> supportedTypes = |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1260 | { |
| 1261 | DataType::Float32, |
Teresa Charlin | 0434df6 | 2019-06-06 13:40:35 +0100 | [diff] [blame] | 1262 | DataType::QuantisedAsymm8, |
| 1263 | DataType::QuantisedSymm16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 1264 | }; |
| 1265 | |
| 1266 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1267 | "Reference poolind2d: input is not a supported type."); |
| 1268 | |
| 1269 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1270 | "Reference poolind2d: output is not a supported type."); |
| 1271 | |
| 1272 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1273 | "Reference poolind2d: input and output types are mismatched."); |
| 1274 | |
| 1275 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 1278 | bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input, |
| 1279 | const TensorInfo& output, |
| 1280 | Optional<std::string&> reasonIfUnsupported) const |
| 1281 | { |
| 1282 | bool supported = true; |
| 1283 | |
| 1284 | // Define supported output types. |
| 1285 | std::array<DataType,2> supportedInputTypes = { |
| 1286 | DataType::Float32, |
| 1287 | }; |
| 1288 | |
| 1289 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 1290 | "Reference quantize: input type not supported."); |
| 1291 | |
| 1292 | // Define supported output types. |
| 1293 | std::array<DataType,2> supportedOutputTypes = { |
| 1294 | DataType::QuantisedAsymm8, |
| 1295 | DataType::QuantisedSymm16 |
| 1296 | }; |
| 1297 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 1298 | "Reference quantize: output type not supported."); |
| 1299 | |
| 1300 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1301 | "Reference quantize: input and output shapes have different num total elements."); |
| 1302 | |
| 1303 | return supported; |
| 1304 | } |
| 1305 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1306 | bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1307 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1308 | Optional<std::string&> reasonIfUnsupported) const |
| 1309 | { |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1310 | ignore_unused(descriptor); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1311 | // Define supported output types. |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1312 | std::array<DataType,4> supportedOutputTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1313 | { |
| 1314 | DataType::Float32, |
| 1315 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1316 | DataType::QuantisedAsymm8, |
| 1317 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1318 | }; |
| 1319 | return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported, |
| 1320 | "Reference reshape: input type not supported."); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 1324 | const TensorInfo& output, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1325 | Optional<std::string&> reasonIfUnsupported) const |
| 1326 | { |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1327 | bool supported = true; |
| 1328 | std::array<DataType,3> supportedTypes = |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1329 | { |
| 1330 | DataType::Float32, |
| 1331 | DataType::QuantisedAsymm8, |
| 1332 | DataType::QuantisedSymm16 |
| 1333 | }; |
Ellen Norris-Thompson | 3cb85f3 | 2019-06-17 11:32:49 +0100 | [diff] [blame] | 1334 | |
| 1335 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1336 | "Reference ResizeBilinear: input type not supported"); |
| 1337 | |
| 1338 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1339 | "Reference ResizeBilinear: output type not supported"); |
| 1340 | |
| 1341 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1342 | "Reference ResizeBilinear: input and output types not matching"); |
| 1343 | |
| 1344 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 1347 | bool RefLayerSupport::IsResizeSupported(const TensorInfo& input, |
| 1348 | const TensorInfo& output, |
| 1349 | const ResizeDescriptor& descriptor, |
| 1350 | Optional<std::string&> reasonIfUnsupported) const |
| 1351 | { |
| 1352 | bool supported = true; |
| 1353 | std::array<DataType,3> supportedTypes = |
| 1354 | { |
| 1355 | DataType::Float32, |
| 1356 | DataType::QuantisedAsymm8, |
| 1357 | DataType::QuantisedSymm16 |
| 1358 | }; |
| 1359 | |
| 1360 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1361 | "Reference Resize: input type not supported"); |
| 1362 | |
| 1363 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1364 | "Reference Resize: output type not supported"); |
| 1365 | |
| 1366 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1367 | "Reference Resize: input and output types not matching"); |
| 1368 | |
| 1369 | return supported; |
| 1370 | } |
| 1371 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1372 | bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input, |
| 1373 | const TensorInfo& output, |
| 1374 | Optional<std::string&> reasonIfUnsupported) const |
| 1375 | { |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1376 | bool supported = true; |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 1377 | std::array<DataType,3> supportedTypes = |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1378 | { |
| 1379 | DataType::Float32, |
nikraj01 | 24d7321 | 2019-06-14 14:20:40 +0100 | [diff] [blame] | 1380 | DataType::QuantisedAsymm8, |
| 1381 | DataType::QuantisedSymm16 |
nikraj01 | 0421e7f | 2019-06-14 09:40:34 +0100 | [diff] [blame] | 1382 | }; |
| 1383 | |
| 1384 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1385 | "Reference rsqrt: input type not supported"); |
| 1386 | |
| 1387 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1388 | "Reference rsqrt: output type not supported"); |
| 1389 | |
| 1390 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1391 | "Reference rsqrt: input and output types not matching"); |
| 1392 | |
| 1393 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1394 | "Reference Rsqrt: input and output shapes have different number of total elements"); |
| 1395 | |
| 1396 | return supported; |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1399 | bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 1400 | const TensorInfo& output, |
| 1401 | const SoftmaxDescriptor& descriptor, |
| 1402 | Optional<std::string&> reasonIfUnsupported) const |
| 1403 | { |
| 1404 | ignore_unused(output); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 1405 | bool supported = true; |
| 1406 | std::array<DataType,3> supportedTypes = |
| 1407 | { |
| 1408 | DataType::Float32, |
| 1409 | DataType::QuantisedAsymm8, |
| 1410 | DataType::QuantisedSymm16 |
| 1411 | }; |
| 1412 | |
| 1413 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1414 | "Reference concatenation: output type not supported"); |
| 1415 | |
| 1416 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1417 | "Reference concatenation: input type not supported"); |
| 1418 | |
| 1419 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1420 | "Reference concatenation: input type not supported"); |
| 1421 | |
| 1422 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1425 | bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 1426 | const TensorInfo& output, |
| 1427 | const SpaceToBatchNdDescriptor& descriptor, |
| 1428 | Optional<std::string&> reasonIfUnsupported) const |
| 1429 | { |
| 1430 | ignore_unused(output); |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1431 | bool supported = true; |
| 1432 | std::array<DataType,3> supportedTypes = |
| 1433 | { |
| 1434 | DataType::Float32, |
| 1435 | DataType::QuantisedAsymm8, |
| 1436 | DataType::QuantisedSymm16 |
| 1437 | }; |
| 1438 | |
| 1439 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1440 | "Reference SpaceToBatchNd: input type not supported"); |
| 1441 | |
| 1442 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1443 | "Reference SpaceToBatchNd: output type not supported"); |
| 1444 | |
| 1445 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1446 | "Reference SpaceToBatchNd: input and output types are mismatched"); |
| 1447 | |
| 1448 | return supported; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1451 | bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input, |
Keith Davis | 5191033 | 2019-06-26 15:28:43 +0100 | [diff] [blame] | 1452 | const TensorInfo& output, |
| 1453 | const SpaceToDepthDescriptor& descriptor, |
| 1454 | Optional<std::string&> reasonIfUnsupported) const |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1455 | { |
| 1456 | |
| 1457 | ignore_unused(descriptor); |
| 1458 | bool supported = true; |
| 1459 | |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame^] | 1460 | std::array<DataType,3> supportedTypes = |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1461 | { |
| 1462 | DataType::Float32, |
| 1463 | DataType::QuantisedAsymm8, |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame^] | 1464 | DataType::QuantisedSymm16 |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 1465 | }; |
| 1466 | |
| 1467 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1468 | "Reference SpaceToDepth: input type not supported"); |
| 1469 | |
| 1470 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1471 | "Reference SpaceToDepth: output type not supported"); |
| 1472 | |
| 1473 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1474 | "Reference SpaceToDepth: input and output types are mismatched"); |
| 1475 | |
| 1476 | return supported; |
| 1477 | } |
| 1478 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1479 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1480 | const ViewsDescriptor& descriptor, |
| 1481 | Optional<std::string&> reasonIfUnsupported) const |
| 1482 | { |
| 1483 | ignore_unused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1484 | bool supported = true; |
| 1485 | std::array<DataType,3> supportedTypes = |
| 1486 | { |
| 1487 | DataType::Float32, |
| 1488 | DataType::QuantisedAsymm8, |
| 1489 | DataType::QuantisedSymm16 |
| 1490 | }; |
| 1491 | |
| 1492 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1493 | "Reference splitter: input type not supported"); |
| 1494 | |
| 1495 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1496 | } |
| 1497 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 1498 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1499 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 1500 | const ViewsDescriptor& descriptor, |
| 1501 | Optional<std::string&> reasonIfUnsupported) const |
| 1502 | { |
| 1503 | ignore_unused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1504 | bool supported = true; |
| 1505 | std::array<DataType,3> supportedTypes = |
| 1506 | { |
| 1507 | DataType::Float32, |
| 1508 | DataType::QuantisedAsymm8, |
| 1509 | DataType::QuantisedSymm16 |
| 1510 | }; |
| 1511 | |
| 1512 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1513 | "Reference splitter: output type not supported"); |
| 1514 | for (const TensorInfo output : outputs) |
| 1515 | { |
| 1516 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1517 | "Reference splitter: input type not supported"); |
| 1518 | |
| 1519 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1520 | "Reference splitter: input and output types mismatched."); |
| 1521 | } |
| 1522 | |
| 1523 | return supported; |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1526 | bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 1527 | const TensorInfo& output, |
| 1528 | const StridedSliceDescriptor& descriptor, |
| 1529 | Optional<std::string&> reasonIfUnsupported) const |
| 1530 | { |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1531 | ignore_unused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1532 | bool supported = true; |
| 1533 | |
| 1534 | std::array<DataType,3> supportedTypes = |
| 1535 | { |
| 1536 | DataType::Float32, |
| 1537 | DataType::QuantisedAsymm8, |
| 1538 | DataType::QuantisedSymm16 |
| 1539 | }; |
| 1540 | |
| 1541 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1542 | "Reference StridedSlice: input type not supported"); |
| 1543 | |
| 1544 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1545 | "Reference StridedSlice: output type not supported"); |
| 1546 | |
| 1547 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1548 | "Reference StridedSlice: input and output types are mismatched"); |
| 1549 | |
| 1550 | return supported; |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1553 | bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 1554 | const TensorInfo& input1, |
| 1555 | const TensorInfo& output, |
| 1556 | Optional<std::string&> reasonIfUnsupported) const |
| 1557 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1558 | bool supported = true; |
| 1559 | |
| 1560 | std::array<DataType,3> supportedTypes = { |
| 1561 | DataType::Float32, |
| 1562 | DataType::QuantisedAsymm8, |
| 1563 | DataType::QuantisedSymm16 |
| 1564 | }; |
| 1565 | |
| 1566 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1567 | "Reference subtraction: input 0 is not a supported type."); |
| 1568 | |
| 1569 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1570 | "Reference subtraction: input 1 is not a supported type."); |
| 1571 | |
| 1572 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1573 | "Reference subtraction: output is not a supported type."); |
| 1574 | |
| 1575 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1576 | "Reference subtraction: input 0 and Input 1 types are mismatched"); |
| 1577 | |
| 1578 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1579 | "Reference subtraction: input and output types are mismatched"); |
| 1580 | |
| 1581 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1582 | "Reference subtraction: shapes are not suitable for implicit broadcast."); |
| 1583 | |
| 1584 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1585 | } |
| 1586 | |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 1587 | bool RefLayerSupport::IsPreluSupported(const TensorInfo& input, |
| 1588 | const TensorInfo& alpha, |
| 1589 | const TensorInfo& output, |
| 1590 | Optional<std::string&> reasonIfUnsupported) const |
| 1591 | { |
| 1592 | bool supported = true; |
| 1593 | |
| 1594 | std::array<DataType, 3> supportedTypes |
| 1595 | { |
| 1596 | DataType::Float32, |
| 1597 | DataType::QuantisedAsymm8, |
| 1598 | DataType::QuantisedSymm16 |
| 1599 | }; |
| 1600 | |
| 1601 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1602 | "PReLU: input is not a supported type."); |
| 1603 | |
| 1604 | supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported, |
| 1605 | "PReLU: alpha is not a supported type."); |
| 1606 | |
| 1607 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1608 | "PReLU: output is not a supported type."); |
| 1609 | |
| 1610 | supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported, |
| 1611 | "PReLU: input, alpha and output types are mismatched"); |
| 1612 | |
| 1613 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported, |
| 1614 | "PReLU: shapes are not suitable for implicit broadcast"); |
| 1615 | |
| 1616 | return supported; |
| 1617 | } |
| 1618 | |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 1619 | bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input, |
| 1620 | const TensorInfo& output, |
| 1621 | const TransposeConvolution2dDescriptor& descriptor, |
| 1622 | const TensorInfo& weights, |
| 1623 | const Optional<TensorInfo>& biases, |
| 1624 | Optional<std::string&> reasonIfUnsupported) const |
| 1625 | { |
| 1626 | ignore_unused(descriptor); |
| 1627 | |
| 1628 | bool supported = true; |
| 1629 | |
| 1630 | std::array<DataType,3> supportedTypes = |
| 1631 | { |
| 1632 | DataType::Float32, |
| 1633 | DataType::QuantisedAsymm8, |
| 1634 | DataType::QuantisedSymm16 |
| 1635 | }; |
| 1636 | |
| 1637 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1638 | "Reference TransposeConvolution2d: input is not a supported type."); |
| 1639 | |
| 1640 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1641 | "Reference TransposeConvolution2d: output is not a supported type."); |
| 1642 | |
| 1643 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 1644 | "Reference TransposeConvolution2d: weights is not a supported type."); |
| 1645 | |
| 1646 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1647 | "Reference TransposeConvolution2d: input and output types mismatched."); |
| 1648 | |
| 1649 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 1650 | "Reference TransposeConvolution2d: input and weights types mismatched."); |
| 1651 | |
| 1652 | if (biases.has_value()) |
| 1653 | { |
| 1654 | std::array<DataType,3> biasesSupportedTypes = { |
| 1655 | DataType::Float32, |
| 1656 | DataType::Signed32 |
| 1657 | }; |
| 1658 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 1659 | "Reference TransposeConvolution2d: biases is not a supported type."); |
| 1660 | } |
| 1661 | |
| 1662 | return supported; |
| 1663 | } |
| 1664 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1665 | } // namespace armnn |