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 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 50 | |
| 51 | namespace |
| 52 | { |
| 53 | template<typename F> |
| 54 | bool CheckSupportRule(F rule, Optional<std::string&> reasonIfUnsupported, const char* reason) |
| 55 | { |
| 56 | bool supported = rule(); |
| 57 | if (!supported && reason) |
| 58 | { |
| 59 | reasonIfUnsupported.value() += std::string(reason) + "\n"; // Append the reason on a new line |
| 60 | } |
| 61 | return supported; |
| 62 | } |
| 63 | |
| 64 | struct Rule |
| 65 | { |
| 66 | bool operator()() const |
| 67 | { |
| 68 | return m_Res; |
| 69 | } |
| 70 | |
| 71 | bool m_Res = true; |
| 72 | }; |
| 73 | |
Derek Lamberti | 2a434a8 | 2019-03-20 13:07:57 +0000 | [diff] [blame] | 74 | template<typename T> |
| 75 | bool AllTypesAreEqualImpl(T t) |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 76 | { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | template<typename T, typename... Rest> |
| 81 | bool AllTypesAreEqualImpl(T t1, T t2, Rest... rest) |
| 82 | { |
| 83 | static_assert(std::is_same<T, TensorInfo>::value, "Type T must be a TensorInfo"); |
| 84 | |
Derek Lamberti | 2a434a8 | 2019-03-20 13:07:57 +0000 | [diff] [blame] | 85 | return (t1.GetDataType() == t2.GetDataType()) && AllTypesAreEqualImpl(t2, rest...); |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | struct TypesAreEqual : public Rule |
| 89 | { |
| 90 | template<typename ... Ts> |
| 91 | TypesAreEqual(const Ts&... ts) |
| 92 | { |
| 93 | m_Res = AllTypesAreEqualImpl(ts...); |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | struct QuantizationParametersAreEqual : public Rule |
| 98 | { |
| 99 | QuantizationParametersAreEqual(const TensorInfo& info0, const TensorInfo& info1) |
| 100 | { |
| 101 | m_Res = info0.GetQuantizationScale() == info1.GetQuantizationScale() && |
| 102 | info0.GetQuantizationOffset() == info1.GetQuantizationOffset(); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | struct TypeAnyOf : public Rule |
| 107 | { |
| 108 | template<typename Container> |
| 109 | TypeAnyOf(const TensorInfo& info, const Container& c) |
| 110 | { |
| 111 | m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 112 | { |
| 113 | return dt == info.GetDataType(); |
| 114 | }); |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | struct BiasAndWeightsTypesMatch : public Rule |
| 119 | { |
| 120 | BiasAndWeightsTypesMatch(const TensorInfo& biases, const TensorInfo& weights) |
| 121 | { |
| 122 | m_Res = biases.GetDataType() == GetBiasTypeFromWeightsType(weights.GetDataType()).value(); |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | struct BiasAndWeightsTypesCompatible : public Rule |
| 127 | { |
| 128 | template<typename Container> |
| 129 | BiasAndWeightsTypesCompatible(const TensorInfo& info, const Container& c) |
| 130 | { |
| 131 | m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) |
| 132 | { |
| 133 | return dt == GetBiasTypeFromWeightsType(info.GetDataType()).value(); |
| 134 | }); |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 135 | } |
| 136 | }; |
| 137 | |
| 138 | struct ShapesAreSameRank : public Rule |
| 139 | { |
| 140 | ShapesAreSameRank(const TensorInfo& info0, const TensorInfo& info1) |
| 141 | { |
| 142 | m_Res = info0.GetShape().GetNumDimensions() == info1.GetShape().GetNumDimensions(); |
| 143 | } |
| 144 | }; |
| 145 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 146 | struct ShapesAreSameTotalSize : public Rule |
| 147 | { |
| 148 | ShapesAreSameTotalSize(const TensorInfo& info0, const TensorInfo& info1) |
| 149 | { |
| 150 | m_Res = info0.GetNumElements() == info1.GetNumElements(); |
| 151 | } |
| 152 | }; |
| 153 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 154 | struct ShapesAreBroadcastCompatible : public Rule |
| 155 | { |
| 156 | unsigned int CalcInputSize(const TensorShape& in, const TensorShape& out, unsigned int idx) |
| 157 | { |
| 158 | unsigned int offset = out.GetNumDimensions() - in.GetNumDimensions(); |
| 159 | unsigned int sizeIn = (idx < offset) ? 1 : in[idx-offset]; |
| 160 | return sizeIn; |
| 161 | } |
| 162 | |
| 163 | ShapesAreBroadcastCompatible(const TensorInfo& in0, const TensorInfo& in1, const TensorInfo& out) |
| 164 | { |
| 165 | const TensorShape& shape0 = in0.GetShape(); |
| 166 | const TensorShape& shape1 = in1.GetShape(); |
| 167 | const TensorShape& outShape = out.GetShape(); |
| 168 | |
| 169 | for (unsigned int i=0; i < outShape.GetNumDimensions() && m_Res; i++) |
| 170 | { |
| 171 | unsigned int sizeOut = outShape[i]; |
| 172 | unsigned int sizeIn0 = CalcInputSize(shape0, outShape, i); |
| 173 | unsigned int sizeIn1 = CalcInputSize(shape1, outShape, i); |
| 174 | |
| 175 | m_Res &= ((sizeIn0 == sizeOut) || (sizeIn0 == 1)) && |
| 176 | ((sizeIn1 == sizeOut) || (sizeIn1 == 1)); |
| 177 | } |
| 178 | } |
| 179 | }; |
| 180 | } // namespace |
| 181 | |
| 182 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 183 | bool RefLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 184 | const TensorInfo& output, |
| 185 | const ActivationDescriptor& descriptor, |
| 186 | Optional<std::string&> reasonIfUnsupported) const |
| 187 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 188 | bool supported = true; |
| 189 | |
| 190 | // Define supported types. |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 191 | std::array<DataType,3> supportedTypes = { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 192 | DataType::Float32, |
Teresa Charlin | 18515e2 | 2019-04-24 10:17:46 +0100 | [diff] [blame] | 193 | DataType::QuantisedAsymm8, |
| 194 | DataType::QuantisedSymm16 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 198 | "Reference activation: input type not supported."); |
| 199 | |
| 200 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 201 | "Reference activation: output type not supported."); |
| 202 | |
| 203 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 204 | "Reference activation: input and output types mismatched."); |
| 205 | |
| 206 | supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported, |
| 207 | "Reference activation: input and output shapes are of different rank."); |
| 208 | |
| 209 | |
| 210 | struct ActivationFunctionSupported : public Rule |
| 211 | { |
| 212 | ActivationFunctionSupported(const ActivationDescriptor& desc) |
| 213 | { |
| 214 | switch(desc.m_Function) |
| 215 | { |
| 216 | case ActivationFunction::Abs: |
| 217 | case ActivationFunction::BoundedReLu: |
| 218 | case ActivationFunction::LeakyReLu: |
| 219 | case ActivationFunction::Linear: |
| 220 | case ActivationFunction::ReLu: |
| 221 | case ActivationFunction::Sigmoid: |
| 222 | case ActivationFunction::SoftReLu: |
| 223 | case ActivationFunction::Sqrt: |
| 224 | case ActivationFunction::Square: |
| 225 | case ActivationFunction::TanH: |
| 226 | { |
| 227 | m_Res = true; |
| 228 | break; |
| 229 | } |
| 230 | default: |
| 231 | { |
| 232 | m_Res = false; |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | }; |
| 238 | |
| 239 | // Function is supported |
| 240 | supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported, |
| 241 | "Reference activation: function not supported."); |
| 242 | |
| 243 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 247 | const TensorInfo& input1, |
| 248 | const TensorInfo& output, |
| 249 | Optional<std::string&> reasonIfUnsupported) const |
| 250 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 251 | bool supported = true; |
| 252 | |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 253 | std::array<DataType,3> supportedTypes = { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 254 | DataType::Float32, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 255 | DataType::QuantisedAsymm8, |
| 256 | DataType::QuantisedSymm16 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 260 | "Reference addition: input 0 is not a supported type."); |
| 261 | |
| 262 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 263 | "Reference addition: input 1 is not a supported type."); |
| 264 | |
| 265 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 266 | "Reference addition: output is not a supported type."); |
| 267 | |
| 268 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 269 | "Reference addition: input 0 and Input 1 types are mismatched"); |
| 270 | |
| 271 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 272 | "Reference addition: input and output types are mismatched"); |
| 273 | |
| 274 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 275 | "Reference addition: shapes are not suitable for implicit broadcast."); |
| 276 | |
| 277 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 281 | const TensorInfo& output, |
| 282 | const TensorInfo& mean, |
| 283 | const TensorInfo& var, |
| 284 | const TensorInfo& beta, |
| 285 | const TensorInfo& gamma, |
| 286 | const BatchNormalizationDescriptor& descriptor, |
| 287 | Optional<std::string&> reasonIfUnsupported) const |
| 288 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 289 | ignore_unused(output); |
| 290 | ignore_unused(mean); |
| 291 | ignore_unused(var); |
| 292 | ignore_unused(beta); |
| 293 | ignore_unused(gamma); |
| 294 | ignore_unused(descriptor); |
| 295 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 296 | input.GetDataType(), |
| 297 | &TrueFunc<>, |
| 298 | &TrueFunc<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 301 | bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 302 | const TensorInfo& output, |
| 303 | const BatchToSpaceNdDescriptor& descriptor, |
| 304 | Optional<std::string&> reasonIfUnsupported) const |
| 305 | { |
| 306 | ignore_unused(descriptor); |
| 307 | return (IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 308 | input.GetDataType(), |
| 309 | &TrueFunc<>, |
| 310 | &TrueFunc<>) && |
| 311 | IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 312 | output.GetDataType(), |
| 313 | &TrueFunc<>, |
| 314 | &TrueFunc<>)); |
| 315 | } |
| 316 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 317 | bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 318 | const TensorInfo& output, |
| 319 | const OriginsDescriptor& descriptor, |
| 320 | Optional<std::string&> reasonIfUnsupported) const |
| 321 | { |
| 322 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
| 323 | return IsMergerSupported(inputs, output, descriptor, reasonIfUnsupported); |
| 324 | ARMNN_NO_DEPRECATE_WARN_END |
| 325 | } |
| 326 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 327 | bool RefLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 328 | Optional<std::string&> reasonIfUnsupported) const |
| 329 | { |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 330 | std::array<DataType,4> supportedTypes = { |
| 331 | DataType::Float32, |
| 332 | DataType::Signed32, |
| 333 | DataType::QuantisedAsymm8, |
| 334 | DataType::QuantisedSymm16 |
| 335 | }; |
| 336 | |
| 337 | return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 338 | "Reference constant: output is not a supported type."); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 342 | const TensorInfo& output, |
| 343 | Optional<std::string&> reasonIfUnsupported) const |
| 344 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 345 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 346 | input.GetDataType(), |
| 347 | &TrueFunc<>, |
| 348 | &FalseInputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 349 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 350 | &FalseFuncI32<>, |
| 351 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 352 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 353 | output.GetDataType(), |
| 354 | &FalseOutputFuncF16<>, |
| 355 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 356 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 357 | &FalseFuncI32<>, |
| 358 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 362 | const TensorInfo& output, |
| 363 | Optional<std::string&> reasonIfUnsupported) const |
| 364 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 365 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 366 | input.GetDataType(), |
| 367 | &FalseInputFuncF16<>, |
| 368 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 369 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 370 | &FalseFuncI32<>, |
| 371 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 372 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 373 | output.GetDataType(), |
| 374 | &TrueFunc<>, |
| 375 | &FalseOutputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 376 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 377 | &FalseFuncI32<>, |
| 378 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 382 | const TensorInfo& output, |
| 383 | const Convolution2dDescriptor& descriptor, |
| 384 | const TensorInfo& weights, |
| 385 | const Optional<TensorInfo>& biases, |
| 386 | Optional<std::string&> reasonIfUnsupported) const |
| 387 | { |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 388 | bool supported = true; |
| 389 | |
| 390 | // Define supported types. |
| 391 | std::array<DataType,3> supportedTypes = { |
| 392 | DataType::Float32, |
| 393 | DataType::QuantisedAsymm8, |
| 394 | DataType::QuantisedSymm16 |
| 395 | }; |
| 396 | |
| 397 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 398 | "Reference addition: input is not a supported type."); |
| 399 | |
| 400 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 401 | "Reference addition: output is not a supported type."); |
| 402 | |
| 403 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 404 | "Reference addition: weights is not a supported type."); |
| 405 | |
| 406 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 407 | "Reference activation: input and output types mismatched."); |
| 408 | |
| 409 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 410 | "Reference activation: input and weights types mismatched."); |
| 411 | |
| 412 | if (biases.has_value()) |
| 413 | { |
| 414 | std::array<DataType,3> biasesSupportedTypes = { |
| 415 | DataType::Float32, |
| 416 | DataType::Signed32 |
| 417 | }; |
| 418 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 419 | "Reference addition: biases is not a supported type."); |
| 420 | } |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 421 | ignore_unused(descriptor); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 422 | |
| 423 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 426 | bool RefLayerSupport::IsDebugSupported(const TensorInfo& input, |
| 427 | const TensorInfo& output, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 428 | Optional<std::string&> reasonIfUnsupported) const |
| 429 | { |
| 430 | ignore_unused(output); |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 431 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 432 | input.GetDataType(), |
| 433 | &TrueFunc<>, |
| 434 | &TrueFunc<>); |
| 435 | } |
| 436 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 437 | bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 438 | const TensorInfo& output, |
| 439 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 440 | const TensorInfo& weights, |
| 441 | const Optional<TensorInfo>& biases, |
| 442 | Optional<std::string&> reasonIfUnsupported) const |
| 443 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 444 | ignore_unused(output); |
| 445 | ignore_unused(descriptor); |
| 446 | ignore_unused(weights); |
| 447 | ignore_unused(biases); |
| 448 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 449 | input.GetDataType(), |
| 450 | &TrueFunc<>, |
| 451 | &TrueFunc<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 454 | bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input, |
| 455 | const TensorInfo& output, |
| 456 | Optional<std::string&> reasonIfUnsupported) const |
| 457 | { |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 458 | bool supported = true; |
| 459 | |
| 460 | std::array<DataType,2> supportedInputTypes = { |
| 461 | DataType::QuantisedAsymm8, |
| 462 | DataType::QuantisedSymm16 |
| 463 | }; |
| 464 | |
| 465 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 466 | "Reference dequantize: input type not supported."); |
| 467 | |
| 468 | std::array<DataType,2> supportedOutputTypes = { |
| 469 | DataType::Float32, |
| 470 | }; |
| 471 | |
| 472 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 473 | "Reference dequantize: output type not supported."); |
| 474 | |
| 475 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 476 | "Reference dequantize: input and output shapes have different num total elements."); |
| 477 | |
| 478 | return supported; |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 481 | bool RefLayerSupport::IsDetectionPostProcessSupported(const armnn::TensorInfo& input0, |
| 482 | const armnn::TensorInfo& input1, |
| 483 | const armnn::DetectionPostProcessDescriptor& descriptor, |
| 484 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 485 | { |
| 486 | ignore_unused(input1); |
| 487 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 488 | input0.GetDataType(), |
| 489 | &TrueFunc<>, |
| 490 | &TrueFunc<>); |
| 491 | } |
| 492 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 493 | bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 494 | const TensorInfo& output, |
| 495 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 496 | const TensorInfo& weights, |
| 497 | const Optional<TensorInfo>& biases, |
| 498 | Optional<std::string&> reasonIfUnsupported) const |
| 499 | { |
| 500 | if (descriptor.m_DilationY == 1 && descriptor.m_DilationY == 1) |
| 501 | { |
| 502 | return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported); |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | if (reasonIfUnsupported) |
| 507 | { |
| 508 | reasonIfUnsupported.value() = "Reference Depthwise Convolution: Dilation parameters must be 1"; |
| 509 | } |
| 510 | return false; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | |
| 515 | bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 516 | const TensorInfo& input1, |
| 517 | const TensorInfo& output, |
| 518 | Optional<std::string&> reasonIfUnsupported) const |
| 519 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 520 | bool supported = true; |
| 521 | |
| 522 | std::array<DataType,3> supportedTypes = { |
| 523 | DataType::Float32, |
| 524 | DataType::QuantisedAsymm8, |
| 525 | DataType::QuantisedSymm16 |
| 526 | }; |
| 527 | |
| 528 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 529 | "Reference division: input 0 is not a supported type."); |
| 530 | |
| 531 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 532 | "Reference division: input 1 is not a supported type."); |
| 533 | |
| 534 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 535 | "Reference division: output is not a supported type."); |
| 536 | |
| 537 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 538 | "Reference division: input 0 and Input 1 types are mismatched"); |
| 539 | |
| 540 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 541 | "Reference division: input and output types are mismatched"); |
| 542 | |
| 543 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 544 | "Reference division: shapes are not suitable for implicit broadcast."); |
| 545 | |
| 546 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 547 | } |
| 548 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 549 | bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0, |
| 550 | const TensorInfo& input1, |
| 551 | const TensorInfo& output, |
| 552 | Optional<std::string&> reasonIfUnsupported) const |
| 553 | { |
| 554 | ignore_unused(input0); |
| 555 | ignore_unused(input1); |
| 556 | ignore_unused(output); |
| 557 | ignore_unused(reasonIfUnsupported); |
| 558 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 559 | input0.GetDataType(), |
| 560 | &TrueFunc<>, |
| 561 | &TrueFunc<>); |
| 562 | } |
| 563 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 564 | bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input, |
| 565 | const FakeQuantizationDescriptor& descriptor, |
| 566 | Optional<std::string&> reasonIfUnsupported) const |
| 567 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 568 | ignore_unused(descriptor); |
| 569 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 570 | input.GetDataType(), |
| 571 | &TrueFunc<>, |
| 572 | &FalseFuncU8<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | bool RefLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 576 | const TensorInfo& output, |
| 577 | Optional<std::string&> reasonIfUnsupported) const |
| 578 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 579 | ignore_unused(output); |
| 580 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 581 | input.GetDataType(), |
| 582 | &TrueFunc<>, |
| 583 | &FalseFuncU8<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 587 | const TensorInfo& output, |
| 588 | const TensorInfo& weights, |
| 589 | const TensorInfo& biases, |
| 590 | const FullyConnectedDescriptor& descriptor, |
| 591 | Optional<std::string&> reasonIfUnsupported) const |
| 592 | { |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 593 | bool supported = true; |
| 594 | |
| 595 | // Define supported types. |
| 596 | std::array<DataType,3> supportedTypes = |
| 597 | { |
| 598 | DataType::Float32, |
| 599 | DataType::QuantisedAsymm8, |
| 600 | DataType::QuantisedSymm16 |
| 601 | }; |
| 602 | |
| 603 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 604 | "Reference Fully Connected: input type not supported."); |
| 605 | |
| 606 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 607 | "Reference Fully Connected: output type not supported."); |
| 608 | |
| 609 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 610 | "Reference Fully Connected: input and output types mismatched."); |
| 611 | |
| 612 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 613 | "Reference Fully Connected: weights type not supported."); |
| 614 | |
| 615 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 616 | "Reference Fully Connected: input and weight types mismatched."); |
| 617 | |
| 618 | if (descriptor.m_BiasEnabled) |
| 619 | { |
| 620 | // Defined supported types for bias |
| 621 | std::array<DataType, 2> |
| 622 | supportedBiasTypes = |
| 623 | { |
| 624 | DataType::Float32, |
| 625 | DataType::Signed32 |
| 626 | }; |
| 627 | |
| 628 | supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported, |
| 629 | "Reference Fully Connected: bias type not supported."); |
| 630 | |
| 631 | supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported, |
| 632 | "Reference Fully Connected: bias and weight types mismatch."); |
| 633 | |
| 634 | supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported, |
| 635 | "Reference Fully Connected: bias type inferred from weights is incompatible."); |
| 636 | |
| 637 | } |
| 638 | |
| 639 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 640 | } |
| 641 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 642 | bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0, |
| 643 | const armnn::TensorInfo& input1, |
| 644 | const armnn::TensorInfo& output, |
| 645 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 646 | { |
| 647 | ignore_unused(input1); |
| 648 | ignore_unused(output); |
| 649 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 650 | input0.GetDataType(), |
| 651 | &TrueFunc<>, |
| 652 | &TrueFunc<>); |
| 653 | } |
| 654 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 655 | bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 656 | const TensorInfo& input1, |
| 657 | const TensorInfo& output, |
| 658 | Optional<std::string&> reasonIfUnsupported) const |
| 659 | { |
| 660 | ignore_unused(input0); |
| 661 | ignore_unused(input1); |
| 662 | ignore_unused(output); |
| 663 | ignore_unused(reasonIfUnsupported); |
| 664 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 665 | input0.GetDataType(), |
| 666 | &TrueFunc<>, |
| 667 | &TrueFunc<>); |
| 668 | } |
| 669 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 670 | bool RefLayerSupport::IsInputSupported(const TensorInfo& input, |
| 671 | Optional<std::string&> reasonIfUnsupported) const |
| 672 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 673 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 674 | input.GetDataType(), |
| 675 | &TrueFunc<>, |
| 676 | &TrueFunc<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 680 | const TensorInfo& output, |
| 681 | const L2NormalizationDescriptor& descriptor, |
| 682 | Optional<std::string&> reasonIfUnsupported) const |
| 683 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 684 | ignore_unused(output); |
| 685 | ignore_unused(descriptor); |
| 686 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 687 | input.GetDataType(), |
| 688 | &TrueFunc<>, |
| 689 | &FalseFuncU8<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | bool RefLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 693 | const TensorInfo& outputStateIn, |
| 694 | const TensorInfo& cellStateIn, |
| 695 | const TensorInfo& scratchBuffer, |
| 696 | const TensorInfo& outputStateOut, |
| 697 | const TensorInfo& cellStateOut, |
| 698 | const TensorInfo& output, |
| 699 | const LstmDescriptor& descriptor, |
| 700 | const TensorInfo& inputToForgetWeights, |
| 701 | const TensorInfo& inputToCellWeights, |
| 702 | const TensorInfo& inputToOutputWeights, |
| 703 | const TensorInfo& recurrentToForgetWeights, |
| 704 | const TensorInfo& recurrentToCellWeights, |
| 705 | const TensorInfo& recurrentToOutputWeights, |
| 706 | const TensorInfo& forgetGateBias, |
| 707 | const TensorInfo& cellBias, |
| 708 | const TensorInfo& outputGateBias, |
| 709 | const TensorInfo* inputToInputWeights, |
| 710 | const TensorInfo* recurrentToInputWeights, |
| 711 | const TensorInfo* cellToInputWeights, |
| 712 | const TensorInfo* inputGateBias, |
| 713 | const TensorInfo* projectionWeights, |
| 714 | const TensorInfo* projectionBias, |
| 715 | const TensorInfo* cellToForgetWeights, |
| 716 | const TensorInfo* cellToOutputWeights, |
| 717 | Optional<std::string&> reasonIfUnsupported) const |
| 718 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 719 | ignore_unused(descriptor); |
| 720 | ignore_unused(inputToForgetWeights); |
| 721 | ignore_unused(inputToCellWeights); |
| 722 | ignore_unused(inputToOutputWeights); |
| 723 | ignore_unused(recurrentToForgetWeights); |
| 724 | ignore_unused(recurrentToCellWeights); |
| 725 | ignore_unused(recurrentToOutputWeights); |
| 726 | ignore_unused(forgetGateBias); |
| 727 | ignore_unused(cellBias); |
| 728 | ignore_unused(outputGateBias); |
| 729 | ignore_unused(inputToInputWeights); |
| 730 | ignore_unused(recurrentToInputWeights); |
| 731 | ignore_unused(cellToInputWeights); |
| 732 | ignore_unused(inputGateBias); |
| 733 | ignore_unused(projectionWeights); |
| 734 | ignore_unused(projectionBias); |
| 735 | ignore_unused(cellToForgetWeights); |
| 736 | ignore_unused(cellToOutputWeights); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 737 | |
| 738 | bool supported = true; |
| 739 | |
| 740 | std::array<DataType,2> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 741 | DataType::Float32, |
| 742 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 743 | }; |
| 744 | |
| 745 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 746 | "Reference Lstm: input is not a supported type."); |
| 747 | |
| 748 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported, |
| 749 | "Reference Lstm: input and outputStateIn types are mismatched"); |
| 750 | |
| 751 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported, |
| 752 | "Reference Lstm: input and cellStateIn types are mismatched"); |
| 753 | |
| 754 | supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported, |
| 755 | "Reference Lstm: input and scratchBuffer types are mismatched"); |
| 756 | |
| 757 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported, |
| 758 | "Reference Lstm: input and outputStateOut types are mismatched"); |
| 759 | |
| 760 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported, |
| 761 | "Reference Lstm: input and cellStateOut types are mismatched"); |
| 762 | |
| 763 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 764 | "Reference Lstm: input and output types are mismatched"); |
| 765 | |
| 766 | return supported; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 767 | } |
| 768 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 769 | bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 770 | const TensorInfo& input1, |
| 771 | const TensorInfo& output, |
| 772 | Optional<std::string&> reasonIfUnsupported) const |
| 773 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 774 | bool supported = true; |
| 775 | |
| 776 | std::array<DataType,3> supportedTypes = { |
| 777 | DataType::Float32, |
| 778 | DataType::QuantisedAsymm8, |
| 779 | DataType::QuantisedSymm16 |
| 780 | }; |
| 781 | |
| 782 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 783 | "Reference maximum: input 0 is not a supported type."); |
| 784 | |
| 785 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 786 | "Reference maximum: input 1 is not a supported type."); |
| 787 | |
| 788 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 789 | "Reference maximum: output is not a supported type."); |
| 790 | |
| 791 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 792 | "Reference maximum: input 0 and Input 1 types are mismatched"); |
| 793 | |
| 794 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 795 | "Reference maximum: input and output types are mismatched"); |
| 796 | |
| 797 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 798 | "Reference maximum: shapes are not suitable for implicit broadcast."); |
| 799 | |
| 800 | return supported; |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 803 | bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 804 | const TensorInfo& output, |
| 805 | const MeanDescriptor& descriptor, |
| 806 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 807 | { |
narpra01 | 1e4c31d | 2018-09-28 11:07:51 +0100 | [diff] [blame] | 808 | ignore_unused(output); |
| 809 | ignore_unused(descriptor); |
| 810 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 811 | input.GetDataType(), |
| 812 | &TrueFunc<>, |
| 813 | &TrueFunc<>); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 814 | } |
| 815 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 816 | bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 817 | const TensorInfo& output, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 818 | const OriginsDescriptor& descriptor, |
| 819 | Optional<std::string&> reasonIfUnsupported) const |
| 820 | { |
| 821 | ignore_unused(descriptor); |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 822 | |
| 823 | bool supported = true; |
| 824 | std::array<DataType,3> supportedTypes = |
| 825 | { |
| 826 | DataType::Float32, |
| 827 | DataType::QuantisedAsymm8, |
| 828 | DataType::QuantisedSymm16 |
| 829 | }; |
| 830 | |
| 831 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 832 | "Reference concatenation: output type not supported"); |
| 833 | for (const TensorInfo* input : inputs) |
| 834 | { |
| 835 | supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported, |
| 836 | "Reference concatenation: input type not supported"); |
| 837 | |
| 838 | supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported, |
| 839 | "Reference concatenation: input and output types mismatched."); |
| 840 | } |
| 841 | |
| 842 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 845 | bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 846 | const TensorInfo &output, |
| 847 | Optional<std::string &> reasonIfUnsupported) const |
| 848 | { |
| 849 | ignore_unused(output); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 850 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 851 | input.GetDataType(), |
| 852 | &TrueFunc<>, |
| 853 | &TrueFunc<>, |
| 854 | &TrueFunc<>, |
| 855 | &FalseFuncI32<>, |
| 856 | &TrueFunc<>); |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 859 | bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 860 | const TensorInfo& input1, |
| 861 | const TensorInfo& output, |
| 862 | Optional<std::string&> reasonIfUnsupported) const |
| 863 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 864 | bool supported = true; |
| 865 | |
| 866 | std::array<DataType,3> supportedTypes = { |
| 867 | DataType::Float32, |
| 868 | DataType::QuantisedAsymm8, |
| 869 | DataType::QuantisedSymm16 |
| 870 | }; |
| 871 | |
| 872 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 873 | "Reference minimum: input 0 is not a supported type."); |
| 874 | |
| 875 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 876 | "Reference minimum: input 1 is not a supported type."); |
| 877 | |
| 878 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 879 | "Reference minimum: output is not a supported type."); |
| 880 | |
| 881 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 882 | "Reference minimum: input 0 and Input 1 types are mismatched"); |
| 883 | |
| 884 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 885 | "Reference minimum: input and output types are mismatched"); |
| 886 | |
| 887 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 888 | "Reference minimum: shapes are not suitable for implicit broadcast."); |
| 889 | |
| 890 | return supported; |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 893 | bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 894 | const TensorInfo& input1, |
| 895 | const TensorInfo& output, |
| 896 | Optional<std::string&> reasonIfUnsupported) const |
| 897 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 898 | bool supported = true; |
| 899 | |
| 900 | std::array<DataType,3> supportedTypes = { |
| 901 | DataType::Float32, |
| 902 | DataType::QuantisedAsymm8, |
| 903 | DataType::QuantisedSymm16 |
| 904 | }; |
| 905 | |
| 906 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 907 | "Reference multiplication: input 0 is not a supported type."); |
| 908 | |
| 909 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 910 | "Reference multiplication: input 1 is not a supported type."); |
| 911 | |
| 912 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 913 | "Reference multiplication: output is not a supported type."); |
| 914 | |
| 915 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 916 | "Reference multiplication: input 0 and Input 1 types are mismatched"); |
| 917 | |
| 918 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 919 | "Reference multiplication: input and output types are mismatched"); |
| 920 | |
| 921 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 922 | "Reference multiplication: shapes are not suitable for implicit broadcast."); |
| 923 | |
| 924 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 928 | const TensorInfo& output, |
| 929 | const NormalizationDescriptor& descriptor, |
| 930 | Optional<std::string&> reasonIfUnsupported) const |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 931 | { |
| 932 | ignore_unused(output); |
| 933 | ignore_unused(descriptor); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 934 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 935 | input.GetDataType(), |
| 936 | &TrueFunc<>, |
| 937 | &FalseFuncU8<>); |
| 938 | } |
| 939 | |
| 940 | bool RefLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 941 | Optional<std::string&> reasonIfUnsupported) const |
| 942 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 943 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 944 | output.GetDataType(), |
| 945 | &TrueFunc<>, |
| 946 | &TrueFunc<>, |
| 947 | &TrueFunc<>, |
| 948 | &FalseFuncI32<>, |
| 949 | &TrueFunc<>); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | bool RefLayerSupport::IsPadSupported(const TensorInfo& input, |
| 953 | const TensorInfo& output, |
| 954 | const PadDescriptor& descriptor, |
| 955 | Optional<std::string&> reasonIfUnsupported) const |
| 956 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 957 | ignore_unused(output); |
| 958 | ignore_unused(descriptor); |
jimfly01 | f6ba747 | 2018-12-04 10:09:52 +0000 | [diff] [blame] | 959 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 960 | input.GetDataType(), |
| 961 | &TrueFunc<>, |
| 962 | &TrueFunc<>); |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 963 | } |
| 964 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 965 | bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 966 | const TensorInfo& output, |
| 967 | const PermuteDescriptor& descriptor, |
| 968 | Optional<std::string&> reasonIfUnsupported) const |
| 969 | { |
| 970 | ignore_unused(output); |
| 971 | ignore_unused(descriptor); |
| 972 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 973 | input.GetDataType(), |
| 974 | &TrueFunc<>, |
| 975 | &TrueFunc<>); |
| 976 | } |
| 977 | |
| 978 | bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 979 | const TensorInfo& output, |
| 980 | const Pooling2dDescriptor& descriptor, |
| 981 | Optional<std::string&> reasonIfUnsupported) const |
| 982 | { |
| 983 | ignore_unused(output); |
| 984 | ignore_unused(descriptor); |
| 985 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 986 | input.GetDataType(), |
| 987 | &TrueFunc<>, |
| 988 | &TrueFunc<>); |
| 989 | } |
| 990 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 991 | bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input, |
| 992 | const TensorInfo& output, |
| 993 | Optional<std::string&> reasonIfUnsupported) const |
| 994 | { |
| 995 | bool supported = true; |
| 996 | |
| 997 | // Define supported output types. |
| 998 | std::array<DataType,2> supportedInputTypes = { |
| 999 | DataType::Float32, |
| 1000 | }; |
| 1001 | |
| 1002 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 1003 | "Reference quantize: input type not supported."); |
| 1004 | |
| 1005 | // Define supported output types. |
| 1006 | std::array<DataType,2> supportedOutputTypes = { |
| 1007 | DataType::QuantisedAsymm8, |
| 1008 | DataType::QuantisedSymm16 |
| 1009 | }; |
| 1010 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 1011 | "Reference quantize: output type not supported."); |
| 1012 | |
| 1013 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1014 | "Reference quantize: input and output shapes have different num total elements."); |
| 1015 | |
| 1016 | return supported; |
| 1017 | } |
| 1018 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1019 | bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1020 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1021 | Optional<std::string&> reasonIfUnsupported) const |
| 1022 | { |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1023 | ignore_unused(descriptor); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame^] | 1024 | // Define supported output types. |
| 1025 | std::array<DataType,3> supportedOutputTypes = |
| 1026 | { |
| 1027 | DataType::Float32, |
| 1028 | DataType::Float16, |
| 1029 | DataType::QuantisedAsymm8 |
| 1030 | }; |
| 1031 | return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported, |
| 1032 | "Reference reshape: input type not supported."); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 1036 | const TensorInfo& output, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1037 | Optional<std::string&> reasonIfUnsupported) const |
| 1038 | { |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 1039 | ignore_unused(output); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1040 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1041 | input.GetDataType(), |
| 1042 | &TrueFunc<>, |
| 1043 | &TrueFunc<>); |
| 1044 | } |
| 1045 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1046 | bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input, |
| 1047 | const TensorInfo& output, |
| 1048 | Optional<std::string&> reasonIfUnsupported) const |
| 1049 | { |
| 1050 | ignore_unused(output); |
| 1051 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1052 | input.GetDataType(), |
| 1053 | &TrueFunc<>, |
| 1054 | &FalseFuncU8<>); |
| 1055 | } |
| 1056 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1057 | bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 1058 | const TensorInfo& output, |
| 1059 | const SoftmaxDescriptor& descriptor, |
| 1060 | Optional<std::string&> reasonIfUnsupported) const |
| 1061 | { |
| 1062 | ignore_unused(output); |
| 1063 | ignore_unused(descriptor); |
| 1064 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1065 | input.GetDataType(), |
| 1066 | &TrueFunc<>, |
| 1067 | &TrueFunc<>); |
| 1068 | } |
| 1069 | |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1070 | bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 1071 | const TensorInfo& output, |
| 1072 | const SpaceToBatchNdDescriptor& descriptor, |
| 1073 | Optional<std::string&> reasonIfUnsupported) const |
| 1074 | { |
| 1075 | ignore_unused(output); |
| 1076 | ignore_unused(descriptor); |
| 1077 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1078 | input.GetDataType(), |
| 1079 | &TrueFunc<>, |
| 1080 | &TrueFunc<>); |
| 1081 | } |
| 1082 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1083 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1084 | const ViewsDescriptor& descriptor, |
| 1085 | Optional<std::string&> reasonIfUnsupported) const |
| 1086 | { |
| 1087 | ignore_unused(descriptor); |
| 1088 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1089 | input.GetDataType(), |
| 1090 | &TrueFunc<>, |
| 1091 | &TrueFunc<>); |
| 1092 | } |
| 1093 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 1094 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1095 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 1096 | const ViewsDescriptor& descriptor, |
| 1097 | Optional<std::string&> reasonIfUnsupported) const |
| 1098 | { |
| 1099 | ignore_unused(descriptor); |
| 1100 | ignore_unused(outputs); |
| 1101 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1102 | input.GetDataType(), |
| 1103 | &TrueFunc<>, |
| 1104 | &TrueFunc<>); |
| 1105 | } |
| 1106 | |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1107 | bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 1108 | const TensorInfo& output, |
| 1109 | const StridedSliceDescriptor& descriptor, |
| 1110 | Optional<std::string&> reasonIfUnsupported) const |
| 1111 | { |
| 1112 | ignore_unused(output); |
| 1113 | ignore_unused(descriptor); |
| 1114 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1115 | input.GetDataType(), |
| 1116 | &TrueFunc<>, |
| 1117 | &TrueFunc<>); |
| 1118 | } |
| 1119 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1120 | bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 1121 | const TensorInfo& input1, |
| 1122 | const TensorInfo& output, |
| 1123 | Optional<std::string&> reasonIfUnsupported) const |
| 1124 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1125 | bool supported = true; |
| 1126 | |
| 1127 | std::array<DataType,3> supportedTypes = { |
| 1128 | DataType::Float32, |
| 1129 | DataType::QuantisedAsymm8, |
| 1130 | DataType::QuantisedSymm16 |
| 1131 | }; |
| 1132 | |
| 1133 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1134 | "Reference subtraction: input 0 is not a supported type."); |
| 1135 | |
| 1136 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1137 | "Reference subtraction: input 1 is not a supported type."); |
| 1138 | |
| 1139 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1140 | "Reference subtraction: output is not a supported type."); |
| 1141 | |
| 1142 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1143 | "Reference subtraction: input 0 and Input 1 types are mismatched"); |
| 1144 | |
| 1145 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1146 | "Reference subtraction: input and output types are mismatched"); |
| 1147 | |
| 1148 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1149 | "Reference subtraction: shapes are not suitable for implicit broadcast."); |
| 1150 | |
| 1151 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1154 | } // namespace armnn |