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, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 319 | const ConcatDescriptor& descriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 320 | Optional<std::string&> reasonIfUnsupported) const |
| 321 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 322 | ignore_unused(descriptor); |
| 323 | |
| 324 | bool supported = true; |
| 325 | std::array<DataType,3> supportedTypes = |
| 326 | { |
| 327 | DataType::Float32, |
| 328 | DataType::QuantisedAsymm8, |
| 329 | DataType::QuantisedSymm16 |
| 330 | }; |
| 331 | |
| 332 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 333 | "Reference concatenation: output type not supported"); |
| 334 | for (const TensorInfo* input : inputs) |
| 335 | { |
| 336 | supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported, |
| 337 | "Reference concatenation: input type not supported"); |
| 338 | |
| 339 | supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported, |
| 340 | "Reference concatenation: input and output types mismatched."); |
| 341 | } |
| 342 | |
| 343 | return supported; |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 344 | } |
| 345 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 346 | bool RefLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 347 | Optional<std::string&> reasonIfUnsupported) const |
| 348 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 349 | std::array<DataType,4> supportedTypes = |
| 350 | { |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 351 | DataType::Float32, |
| 352 | DataType::Signed32, |
| 353 | DataType::QuantisedAsymm8, |
| 354 | DataType::QuantisedSymm16 |
| 355 | }; |
| 356 | |
| 357 | return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 358 | "Reference constant: output is not a supported type."); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | bool RefLayerSupport::IsConvertFp16ToFp32Supported(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 | &TrueFunc<>, |
| 368 | &FalseInputFuncF32<>, |
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 | &FalseOutputFuncF16<>, |
| 375 | &TrueFunc<>, |
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::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 382 | const TensorInfo& output, |
| 383 | Optional<std::string&> reasonIfUnsupported) const |
| 384 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 385 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 386 | input.GetDataType(), |
| 387 | &FalseInputFuncF16<>, |
| 388 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 389 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 390 | &FalseFuncI32<>, |
| 391 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 392 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 393 | output.GetDataType(), |
| 394 | &TrueFunc<>, |
| 395 | &FalseOutputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 396 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 397 | &FalseFuncI32<>, |
| 398 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 402 | const TensorInfo& output, |
| 403 | const Convolution2dDescriptor& descriptor, |
| 404 | const TensorInfo& weights, |
| 405 | const Optional<TensorInfo>& biases, |
| 406 | Optional<std::string&> reasonIfUnsupported) const |
| 407 | { |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 408 | bool supported = true; |
| 409 | |
| 410 | // Define supported types. |
| 411 | std::array<DataType,3> supportedTypes = { |
| 412 | DataType::Float32, |
| 413 | DataType::QuantisedAsymm8, |
| 414 | DataType::QuantisedSymm16 |
| 415 | }; |
| 416 | |
| 417 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 418 | "Reference convolution2d: input is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 419 | |
| 420 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 421 | "Reference convolution2d: output is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 422 | |
| 423 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 424 | "Reference convolution2d: weights is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 425 | |
| 426 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 427 | "Reference convolution2d: input and output types mismatched."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 428 | |
| 429 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 430 | "Reference convolution2d: input and weights types mismatched."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 431 | |
| 432 | if (biases.has_value()) |
| 433 | { |
| 434 | std::array<DataType,3> biasesSupportedTypes = { |
| 435 | DataType::Float32, |
| 436 | DataType::Signed32 |
| 437 | }; |
| 438 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
Les Bell | d7f2908 | 2019-05-30 09:08:51 +0100 | [diff] [blame] | 439 | "Reference convolution2d: biases is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 440 | } |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 441 | ignore_unused(descriptor); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 442 | |
| 443 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 446 | bool RefLayerSupport::IsDebugSupported(const TensorInfo& input, |
| 447 | const TensorInfo& output, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 448 | Optional<std::string&> reasonIfUnsupported) const |
| 449 | { |
| 450 | ignore_unused(output); |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 451 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 452 | input.GetDataType(), |
| 453 | &TrueFunc<>, |
| 454 | &TrueFunc<>); |
| 455 | } |
| 456 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 457 | bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 458 | const TensorInfo& output, |
| 459 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 460 | const TensorInfo& weights, |
| 461 | const Optional<TensorInfo>& biases, |
| 462 | Optional<std::string&> reasonIfUnsupported) const |
| 463 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 464 | ignore_unused(output); |
| 465 | ignore_unused(descriptor); |
| 466 | ignore_unused(weights); |
| 467 | ignore_unused(biases); |
| 468 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 469 | input.GetDataType(), |
| 470 | &TrueFunc<>, |
| 471 | &TrueFunc<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 474 | bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input, |
| 475 | const TensorInfo& output, |
| 476 | Optional<std::string&> reasonIfUnsupported) const |
| 477 | { |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 478 | bool supported = true; |
| 479 | |
| 480 | std::array<DataType,2> supportedInputTypes = { |
| 481 | DataType::QuantisedAsymm8, |
| 482 | DataType::QuantisedSymm16 |
| 483 | }; |
| 484 | |
| 485 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 486 | "Reference dequantize: input type not supported."); |
| 487 | |
| 488 | std::array<DataType,2> supportedOutputTypes = { |
| 489 | DataType::Float32, |
| 490 | }; |
| 491 | |
| 492 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 493 | "Reference dequantize: output type not supported."); |
| 494 | |
| 495 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 496 | "Reference dequantize: input and output shapes have different num total elements."); |
| 497 | |
| 498 | return supported; |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 501 | bool RefLayerSupport::IsDetectionPostProcessSupported(const armnn::TensorInfo& input0, |
| 502 | const armnn::TensorInfo& input1, |
| 503 | const armnn::DetectionPostProcessDescriptor& descriptor, |
| 504 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 505 | { |
| 506 | ignore_unused(input1); |
| 507 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 508 | input0.GetDataType(), |
| 509 | &TrueFunc<>, |
| 510 | &TrueFunc<>); |
| 511 | } |
| 512 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 513 | bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 514 | const TensorInfo& output, |
| 515 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 516 | const TensorInfo& weights, |
| 517 | const Optional<TensorInfo>& biases, |
| 518 | Optional<std::string&> reasonIfUnsupported) const |
| 519 | { |
| 520 | if (descriptor.m_DilationY == 1 && descriptor.m_DilationY == 1) |
| 521 | { |
| 522 | return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported); |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | if (reasonIfUnsupported) |
| 527 | { |
| 528 | reasonIfUnsupported.value() = "Reference Depthwise Convolution: Dilation parameters must be 1"; |
| 529 | } |
| 530 | return false; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | |
| 535 | bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 536 | const TensorInfo& input1, |
| 537 | const TensorInfo& output, |
| 538 | Optional<std::string&> reasonIfUnsupported) const |
| 539 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 540 | bool supported = true; |
| 541 | |
| 542 | std::array<DataType,3> supportedTypes = { |
| 543 | DataType::Float32, |
| 544 | DataType::QuantisedAsymm8, |
| 545 | DataType::QuantisedSymm16 |
| 546 | }; |
| 547 | |
| 548 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 549 | "Reference division: input 0 is not a supported type."); |
| 550 | |
| 551 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 552 | "Reference division: input 1 is not a supported type."); |
| 553 | |
| 554 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 555 | "Reference division: output is not a supported type."); |
| 556 | |
| 557 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 558 | "Reference division: input 0 and Input 1 types are mismatched"); |
| 559 | |
| 560 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 561 | "Reference division: input and output types are mismatched"); |
| 562 | |
| 563 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 564 | "Reference division: shapes are not suitable for implicit broadcast."); |
| 565 | |
| 566 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 567 | } |
| 568 | |
FrancisMurtagh | 30cdfca | 2018-12-18 12:57:35 +0000 | [diff] [blame] | 569 | bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0, |
| 570 | const TensorInfo& input1, |
| 571 | const TensorInfo& output, |
| 572 | Optional<std::string&> reasonIfUnsupported) const |
| 573 | { |
| 574 | ignore_unused(input0); |
| 575 | ignore_unused(input1); |
| 576 | ignore_unused(output); |
| 577 | ignore_unused(reasonIfUnsupported); |
| 578 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 579 | input0.GetDataType(), |
| 580 | &TrueFunc<>, |
| 581 | &TrueFunc<>); |
| 582 | } |
| 583 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 584 | bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input, |
| 585 | const FakeQuantizationDescriptor& descriptor, |
| 586 | Optional<std::string&> reasonIfUnsupported) const |
| 587 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 588 | ignore_unused(descriptor); |
| 589 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 590 | input.GetDataType(), |
| 591 | &TrueFunc<>, |
| 592 | &FalseFuncU8<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | bool RefLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 596 | const TensorInfo& output, |
| 597 | Optional<std::string&> reasonIfUnsupported) const |
| 598 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 599 | ignore_unused(output); |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 600 | bool supported = true; |
| 601 | |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 602 | std::array<DataType,2> supportedTypes = |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 603 | { |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 604 | DataType::Float32, |
| 605 | DataType::QuantisedSymm16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 606 | }; |
| 607 | |
| 608 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 609 | "Reference Floor: input type not supported."); |
| 610 | |
| 611 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 612 | "Reference Floor: output type not supported."); |
| 613 | |
| 614 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 618 | const TensorInfo& output, |
| 619 | const TensorInfo& weights, |
| 620 | const TensorInfo& biases, |
| 621 | const FullyConnectedDescriptor& descriptor, |
| 622 | Optional<std::string&> reasonIfUnsupported) const |
| 623 | { |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 624 | bool supported = true; |
| 625 | |
| 626 | // Define supported types. |
| 627 | std::array<DataType,3> supportedTypes = |
| 628 | { |
| 629 | DataType::Float32, |
| 630 | DataType::QuantisedAsymm8, |
| 631 | DataType::QuantisedSymm16 |
| 632 | }; |
| 633 | |
| 634 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 635 | "Reference Fully Connected: input type not supported."); |
| 636 | |
| 637 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 638 | "Reference Fully Connected: output type not supported."); |
| 639 | |
| 640 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 641 | "Reference Fully Connected: input and output types mismatched."); |
| 642 | |
| 643 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 644 | "Reference Fully Connected: weights type not supported."); |
| 645 | |
| 646 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 647 | "Reference Fully Connected: input and weight types mismatched."); |
| 648 | |
| 649 | if (descriptor.m_BiasEnabled) |
| 650 | { |
| 651 | // Defined supported types for bias |
| 652 | std::array<DataType, 2> |
| 653 | supportedBiasTypes = |
| 654 | { |
| 655 | DataType::Float32, |
| 656 | DataType::Signed32 |
| 657 | }; |
| 658 | |
| 659 | supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported, |
| 660 | "Reference Fully Connected: bias type not supported."); |
| 661 | |
| 662 | supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported, |
| 663 | "Reference Fully Connected: bias and weight types mismatch."); |
| 664 | |
| 665 | supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported, |
| 666 | "Reference Fully Connected: bias type inferred from weights is incompatible."); |
| 667 | |
| 668 | } |
| 669 | |
| 670 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 671 | } |
| 672 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 673 | bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0, |
| 674 | const armnn::TensorInfo& input1, |
| 675 | const armnn::TensorInfo& output, |
| 676 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 677 | { |
| 678 | ignore_unused(input1); |
| 679 | ignore_unused(output); |
| 680 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 681 | input0.GetDataType(), |
| 682 | &TrueFunc<>, |
| 683 | &TrueFunc<>); |
| 684 | } |
| 685 | |
FrancisMurtagh | 878f023 | 2018-12-19 10:56:15 +0000 | [diff] [blame] | 686 | bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 687 | const TensorInfo& input1, |
| 688 | const TensorInfo& output, |
| 689 | Optional<std::string&> reasonIfUnsupported) const |
| 690 | { |
| 691 | ignore_unused(input0); |
| 692 | ignore_unused(input1); |
| 693 | ignore_unused(output); |
| 694 | ignore_unused(reasonIfUnsupported); |
| 695 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 696 | input0.GetDataType(), |
| 697 | &TrueFunc<>, |
| 698 | &TrueFunc<>); |
| 699 | } |
| 700 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 701 | bool RefLayerSupport::IsInputSupported(const TensorInfo& input, |
| 702 | Optional<std::string&> reasonIfUnsupported) const |
| 703 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame^] | 704 | return true; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 708 | const TensorInfo& output, |
| 709 | const L2NormalizationDescriptor& descriptor, |
| 710 | Optional<std::string&> reasonIfUnsupported) const |
| 711 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 712 | ignore_unused(output); |
| 713 | ignore_unused(descriptor); |
| 714 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 715 | input.GetDataType(), |
| 716 | &TrueFunc<>, |
| 717 | &FalseFuncU8<>); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | bool RefLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 721 | const TensorInfo& outputStateIn, |
| 722 | const TensorInfo& cellStateIn, |
| 723 | const TensorInfo& scratchBuffer, |
| 724 | const TensorInfo& outputStateOut, |
| 725 | const TensorInfo& cellStateOut, |
| 726 | const TensorInfo& output, |
| 727 | const LstmDescriptor& descriptor, |
| 728 | const TensorInfo& inputToForgetWeights, |
| 729 | const TensorInfo& inputToCellWeights, |
| 730 | const TensorInfo& inputToOutputWeights, |
| 731 | const TensorInfo& recurrentToForgetWeights, |
| 732 | const TensorInfo& recurrentToCellWeights, |
| 733 | const TensorInfo& recurrentToOutputWeights, |
| 734 | const TensorInfo& forgetGateBias, |
| 735 | const TensorInfo& cellBias, |
| 736 | const TensorInfo& outputGateBias, |
| 737 | const TensorInfo* inputToInputWeights, |
| 738 | const TensorInfo* recurrentToInputWeights, |
| 739 | const TensorInfo* cellToInputWeights, |
| 740 | const TensorInfo* inputGateBias, |
| 741 | const TensorInfo* projectionWeights, |
| 742 | const TensorInfo* projectionBias, |
| 743 | const TensorInfo* cellToForgetWeights, |
| 744 | const TensorInfo* cellToOutputWeights, |
| 745 | Optional<std::string&> reasonIfUnsupported) const |
| 746 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 747 | ignore_unused(descriptor); |
| 748 | ignore_unused(inputToForgetWeights); |
| 749 | ignore_unused(inputToCellWeights); |
| 750 | ignore_unused(inputToOutputWeights); |
| 751 | ignore_unused(recurrentToForgetWeights); |
| 752 | ignore_unused(recurrentToCellWeights); |
| 753 | ignore_unused(recurrentToOutputWeights); |
| 754 | ignore_unused(forgetGateBias); |
| 755 | ignore_unused(cellBias); |
| 756 | ignore_unused(outputGateBias); |
| 757 | ignore_unused(inputToInputWeights); |
| 758 | ignore_unused(recurrentToInputWeights); |
| 759 | ignore_unused(cellToInputWeights); |
| 760 | ignore_unused(inputGateBias); |
| 761 | ignore_unused(projectionWeights); |
| 762 | ignore_unused(projectionBias); |
| 763 | ignore_unused(cellToForgetWeights); |
| 764 | ignore_unused(cellToOutputWeights); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 765 | |
| 766 | bool supported = true; |
| 767 | |
| 768 | std::array<DataType,2> supportedTypes = { |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 769 | DataType::Float32, |
| 770 | DataType::QuantisedSymm16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 771 | }; |
| 772 | |
| 773 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 774 | "Reference Lstm: input is not a supported type."); |
| 775 | |
| 776 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported, |
| 777 | "Reference Lstm: input and outputStateIn types are mismatched"); |
| 778 | |
| 779 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported, |
| 780 | "Reference Lstm: input and cellStateIn types are mismatched"); |
| 781 | |
| 782 | supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported, |
| 783 | "Reference Lstm: input and scratchBuffer types are mismatched"); |
| 784 | |
| 785 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported, |
| 786 | "Reference Lstm: input and outputStateOut types are mismatched"); |
| 787 | |
| 788 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported, |
| 789 | "Reference Lstm: input and cellStateOut types are mismatched"); |
| 790 | |
| 791 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 792 | "Reference Lstm: input and output types are mismatched"); |
| 793 | |
| 794 | return supported; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 795 | } |
| 796 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 797 | bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 798 | const TensorInfo& input1, |
| 799 | const TensorInfo& output, |
| 800 | Optional<std::string&> reasonIfUnsupported) const |
| 801 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 802 | bool supported = true; |
| 803 | |
| 804 | std::array<DataType,3> supportedTypes = { |
| 805 | DataType::Float32, |
| 806 | DataType::QuantisedAsymm8, |
| 807 | DataType::QuantisedSymm16 |
| 808 | }; |
| 809 | |
| 810 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 811 | "Reference maximum: input 0 is not a supported type."); |
| 812 | |
| 813 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 814 | "Reference maximum: input 1 is not a supported type."); |
| 815 | |
| 816 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 817 | "Reference maximum: output is not a supported type."); |
| 818 | |
| 819 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 820 | "Reference maximum: input 0 and Input 1 types are mismatched"); |
| 821 | |
| 822 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 823 | "Reference maximum: input and output types are mismatched"); |
| 824 | |
| 825 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 826 | "Reference maximum: shapes are not suitable for implicit broadcast."); |
| 827 | |
| 828 | return supported; |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 831 | bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 832 | const TensorInfo& output, |
| 833 | const MeanDescriptor& descriptor, |
| 834 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 835 | { |
narpra01 | 1e4c31d | 2018-09-28 11:07:51 +0100 | [diff] [blame] | 836 | ignore_unused(output); |
| 837 | ignore_unused(descriptor); |
| 838 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 839 | input.GetDataType(), |
| 840 | &TrueFunc<>, |
| 841 | &TrueFunc<>); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 842 | } |
| 843 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 844 | bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 845 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 846 | const MergerDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 847 | Optional<std::string&> reasonIfUnsupported) const |
| 848 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 849 | return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 850 | } |
| 851 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 852 | bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 853 | const TensorInfo &output, |
| 854 | Optional<std::string &> reasonIfUnsupported) const |
| 855 | { |
| 856 | ignore_unused(output); |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 857 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 858 | input.GetDataType(), |
| 859 | &TrueFunc<>, |
| 860 | &TrueFunc<>, |
| 861 | &TrueFunc<>, |
| 862 | &FalseFuncI32<>, |
| 863 | &TrueFunc<>); |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 866 | bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 867 | const TensorInfo& input1, |
| 868 | const TensorInfo& output, |
| 869 | Optional<std::string&> reasonIfUnsupported) const |
| 870 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 871 | bool supported = true; |
| 872 | |
| 873 | std::array<DataType,3> supportedTypes = { |
| 874 | DataType::Float32, |
| 875 | DataType::QuantisedAsymm8, |
| 876 | DataType::QuantisedSymm16 |
| 877 | }; |
| 878 | |
| 879 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 880 | "Reference minimum: input 0 is not a supported type."); |
| 881 | |
| 882 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 883 | "Reference minimum: input 1 is not a supported type."); |
| 884 | |
| 885 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 886 | "Reference minimum: output is not a supported type."); |
| 887 | |
| 888 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 889 | "Reference minimum: input 0 and Input 1 types are mismatched"); |
| 890 | |
| 891 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 892 | "Reference minimum: input and output types are mismatched"); |
| 893 | |
| 894 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 895 | "Reference minimum: shapes are not suitable for implicit broadcast."); |
| 896 | |
| 897 | return supported; |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 898 | } |
| 899 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 900 | bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 901 | const TensorInfo& input1, |
| 902 | const TensorInfo& output, |
| 903 | Optional<std::string&> reasonIfUnsupported) const |
| 904 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 905 | bool supported = true; |
| 906 | |
| 907 | std::array<DataType,3> supportedTypes = { |
| 908 | DataType::Float32, |
| 909 | DataType::QuantisedAsymm8, |
| 910 | DataType::QuantisedSymm16 |
| 911 | }; |
| 912 | |
| 913 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 914 | "Reference multiplication: input 0 is not a supported type."); |
| 915 | |
| 916 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 917 | "Reference multiplication: input 1 is not a supported type."); |
| 918 | |
| 919 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 920 | "Reference multiplication: output is not a supported type."); |
| 921 | |
| 922 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 923 | "Reference multiplication: input 0 and Input 1 types are mismatched"); |
| 924 | |
| 925 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 926 | "Reference multiplication: input and output types are mismatched"); |
| 927 | |
| 928 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 929 | "Reference multiplication: shapes are not suitable for implicit broadcast."); |
| 930 | |
| 931 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 935 | const TensorInfo& output, |
| 936 | const NormalizationDescriptor& descriptor, |
| 937 | Optional<std::string&> reasonIfUnsupported) const |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 938 | { |
| 939 | ignore_unused(output); |
| 940 | ignore_unused(descriptor); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 941 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 942 | input.GetDataType(), |
| 943 | &TrueFunc<>, |
| 944 | &FalseFuncU8<>); |
| 945 | } |
| 946 | |
| 947 | bool RefLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 948 | Optional<std::string&> reasonIfUnsupported) const |
| 949 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame^] | 950 | return true; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | bool RefLayerSupport::IsPadSupported(const TensorInfo& input, |
| 954 | const TensorInfo& output, |
| 955 | const PadDescriptor& descriptor, |
| 956 | Optional<std::string&> reasonIfUnsupported) const |
| 957 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 958 | ignore_unused(output); |
| 959 | ignore_unused(descriptor); |
jimfly01 | f6ba747 | 2018-12-04 10:09:52 +0000 | [diff] [blame] | 960 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 961 | input.GetDataType(), |
| 962 | &TrueFunc<>, |
| 963 | &TrueFunc<>); |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 964 | } |
| 965 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 966 | bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 967 | const TensorInfo& output, |
| 968 | const PermuteDescriptor& descriptor, |
| 969 | Optional<std::string&> reasonIfUnsupported) const |
| 970 | { |
| 971 | ignore_unused(output); |
| 972 | ignore_unused(descriptor); |
| 973 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 974 | input.GetDataType(), |
| 975 | &TrueFunc<>, |
| 976 | &TrueFunc<>); |
| 977 | } |
| 978 | |
| 979 | bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 980 | const TensorInfo& output, |
| 981 | const Pooling2dDescriptor& descriptor, |
| 982 | Optional<std::string&> reasonIfUnsupported) const |
| 983 | { |
| 984 | ignore_unused(output); |
| 985 | ignore_unused(descriptor); |
| 986 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 987 | input.GetDataType(), |
| 988 | &TrueFunc<>, |
| 989 | &TrueFunc<>); |
| 990 | } |
| 991 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 992 | bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input, |
| 993 | const TensorInfo& output, |
| 994 | Optional<std::string&> reasonIfUnsupported) const |
| 995 | { |
| 996 | bool supported = true; |
| 997 | |
| 998 | // Define supported output types. |
| 999 | std::array<DataType,2> supportedInputTypes = { |
| 1000 | DataType::Float32, |
| 1001 | }; |
| 1002 | |
| 1003 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 1004 | "Reference quantize: input type not supported."); |
| 1005 | |
| 1006 | // Define supported output types. |
| 1007 | std::array<DataType,2> supportedOutputTypes = { |
| 1008 | DataType::QuantisedAsymm8, |
| 1009 | DataType::QuantisedSymm16 |
| 1010 | }; |
| 1011 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 1012 | "Reference quantize: output type not supported."); |
| 1013 | |
| 1014 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1015 | "Reference quantize: input and output shapes have different num total elements."); |
| 1016 | |
| 1017 | return supported; |
| 1018 | } |
| 1019 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1020 | bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1021 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1022 | Optional<std::string&> reasonIfUnsupported) const |
| 1023 | { |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1024 | ignore_unused(descriptor); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1025 | // Define supported output types. |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1026 | std::array<DataType,4> supportedOutputTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1027 | { |
| 1028 | DataType::Float32, |
| 1029 | DataType::Float16, |
Nina Drozd | 8ed4b8c | 2019-05-29 10:41:04 +0100 | [diff] [blame] | 1030 | DataType::QuantisedAsymm8, |
| 1031 | DataType::QuantisedSymm16 |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 1032 | }; |
| 1033 | return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported, |
| 1034 | "Reference reshape: input type not supported."); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 1038 | const TensorInfo& output, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1039 | Optional<std::string&> reasonIfUnsupported) const |
| 1040 | { |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 1041 | ignore_unused(output); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1042 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1043 | input.GetDataType(), |
| 1044 | &TrueFunc<>, |
| 1045 | &TrueFunc<>); |
| 1046 | } |
| 1047 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 1048 | bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input, |
| 1049 | const TensorInfo& output, |
| 1050 | Optional<std::string&> reasonIfUnsupported) const |
| 1051 | { |
| 1052 | ignore_unused(output); |
| 1053 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1054 | input.GetDataType(), |
| 1055 | &TrueFunc<>, |
| 1056 | &FalseFuncU8<>); |
| 1057 | } |
| 1058 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1059 | bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 1060 | const TensorInfo& output, |
| 1061 | const SoftmaxDescriptor& descriptor, |
| 1062 | Optional<std::string&> reasonIfUnsupported) const |
| 1063 | { |
| 1064 | ignore_unused(output); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 1065 | bool supported = true; |
| 1066 | std::array<DataType,3> supportedTypes = |
| 1067 | { |
| 1068 | DataType::Float32, |
| 1069 | DataType::QuantisedAsymm8, |
| 1070 | DataType::QuantisedSymm16 |
| 1071 | }; |
| 1072 | |
| 1073 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1074 | "Reference concatenation: output type not supported"); |
| 1075 | |
| 1076 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1077 | "Reference concatenation: input type not supported"); |
| 1078 | |
| 1079 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1080 | "Reference concatenation: input type not supported"); |
| 1081 | |
| 1082 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1083 | } |
| 1084 | |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1085 | bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 1086 | const TensorInfo& output, |
| 1087 | const SpaceToBatchNdDescriptor& descriptor, |
| 1088 | Optional<std::string&> reasonIfUnsupported) const |
| 1089 | { |
| 1090 | ignore_unused(output); |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 1091 | bool supported = true; |
| 1092 | std::array<DataType,3> supportedTypes = |
| 1093 | { |
| 1094 | DataType::Float32, |
| 1095 | DataType::QuantisedAsymm8, |
| 1096 | DataType::QuantisedSymm16 |
| 1097 | }; |
| 1098 | |
| 1099 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1100 | "Reference SpaceToBatchNd: input type not supported"); |
| 1101 | |
| 1102 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1103 | "Reference SpaceToBatchNd: output type not supported"); |
| 1104 | |
| 1105 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1106 | "Reference SpaceToBatchNd: input and output types are mismatched"); |
| 1107 | |
| 1108 | return supported; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1111 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1112 | const ViewsDescriptor& descriptor, |
| 1113 | Optional<std::string&> reasonIfUnsupported) const |
| 1114 | { |
| 1115 | ignore_unused(descriptor); |
| 1116 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1117 | input.GetDataType(), |
| 1118 | &TrueFunc<>, |
| 1119 | &TrueFunc<>); |
| 1120 | } |
| 1121 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 1122 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 1123 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 1124 | const ViewsDescriptor& descriptor, |
| 1125 | Optional<std::string&> reasonIfUnsupported) const |
| 1126 | { |
| 1127 | ignore_unused(descriptor); |
| 1128 | ignore_unused(outputs); |
| 1129 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1130 | input.GetDataType(), |
| 1131 | &TrueFunc<>, |
| 1132 | &TrueFunc<>); |
| 1133 | } |
| 1134 | |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1135 | bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 1136 | const TensorInfo& output, |
| 1137 | const StridedSliceDescriptor& descriptor, |
| 1138 | Optional<std::string&> reasonIfUnsupported) const |
| 1139 | { |
| 1140 | ignore_unused(output); |
| 1141 | ignore_unused(descriptor); |
| 1142 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 1143 | input.GetDataType(), |
| 1144 | &TrueFunc<>, |
| 1145 | &TrueFunc<>); |
| 1146 | } |
| 1147 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1148 | bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 1149 | const TensorInfo& input1, |
| 1150 | const TensorInfo& output, |
| 1151 | Optional<std::string&> reasonIfUnsupported) const |
| 1152 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1153 | bool supported = true; |
| 1154 | |
| 1155 | std::array<DataType,3> supportedTypes = { |
| 1156 | DataType::Float32, |
| 1157 | DataType::QuantisedAsymm8, |
| 1158 | DataType::QuantisedSymm16 |
| 1159 | }; |
| 1160 | |
| 1161 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1162 | "Reference subtraction: input 0 is not a supported type."); |
| 1163 | |
| 1164 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1165 | "Reference subtraction: input 1 is not a supported type."); |
| 1166 | |
| 1167 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1168 | "Reference subtraction: output is not a supported type."); |
| 1169 | |
| 1170 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1171 | "Reference subtraction: input 0 and Input 1 types are mismatched"); |
| 1172 | |
| 1173 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1174 | "Reference subtraction: input and output types are mismatched"); |
| 1175 | |
| 1176 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1177 | "Reference subtraction: shapes are not suitable for implicit broadcast."); |
| 1178 | |
| 1179 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1180 | } |
| 1181 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1182 | } // namespace armnn |