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