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