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 | |
| 6 | #include "LayerSupportCommon.hpp" |
| 7 | #include "RefLayerSupport.hpp" |
| 8 | #include <armnn/Descriptors.hpp> |
| 9 | #include <armnn/Types.hpp> |
| 10 | #include <armnn/Tensor.hpp> |
| 11 | |
| 12 | #include <boost/core/ignore_unused.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include "InternalTypes.hpp" |
| 14 | |
| 15 | using namespace boost; |
| 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | template<typename Float32Func, typename Uint8Func, typename ... Params> |
| 21 | bool IsSupportedForDataTypeRef(std::string* reasonIfUnsupported, |
| 22 | DataType dataType, |
| 23 | Float32Func floatFuncPtr, |
| 24 | Uint8Func uint8FuncPtr, |
| 25 | Params&&... params) |
| 26 | { |
| 27 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 28 | dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | &FalseFunc<Params...>, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 30 | floatFuncPtr, |
| 31 | uint8FuncPtr, |
| 32 | std::forward<Params>(params)...); |
| 33 | } |
| 34 | |
| 35 | bool IsActivationSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 36 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | const ActivationDescriptor& descriptor, |
| 38 | std::string* reasonIfUnsupported) |
| 39 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | ignore_unused(descriptor); |
| 42 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 43 | input.GetDataType(), |
| 44 | &TrueFunc<>, |
| 45 | &TrueFunc<>); |
| 46 | } |
| 47 | |
| 48 | bool IsAdditionSupportedRef(const TensorInfo& input0, |
| 49 | const TensorInfo& input1, |
| 50 | const TensorInfo& output, |
| 51 | std::string* reasonIfUnsupported) |
| 52 | { |
| 53 | ignore_unused(input1); |
| 54 | ignore_unused(output); |
| 55 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 56 | input0.GetDataType(), |
| 57 | &TrueFunc<>, |
| 58 | &TrueFunc<>); |
| 59 | } |
| 60 | |
| 61 | bool IsBatchNormalizationSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | const TensorInfo& output, |
| 63 | const TensorInfo& mean, |
| 64 | const TensorInfo& var, |
| 65 | const TensorInfo& beta, |
| 66 | const TensorInfo& gamma, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | const BatchNormalizationDescriptor& descriptor, |
| 68 | std::string* reasonIfUnsupported) |
| 69 | { |
| 70 | ignore_unused(descriptor); |
| 71 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 72 | input.GetDataType(), |
| 73 | &TrueFunc<>, |
| 74 | &TrueFunc<>); |
| 75 | } |
| 76 | |
| 77 | bool IsConstantSupportedRef(const TensorInfo& output, |
| 78 | std::string* reasonIfUnsupported) |
| 79 | { |
| 80 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 81 | output.GetDataType(), |
| 82 | &TrueFunc<>, |
| 83 | &TrueFunc<>); |
| 84 | } |
| 85 | |
| 86 | bool IsConvolution2dSupportedRef(const TensorInfo& input, |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 87 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 88 | const Convolution2dDescriptor& descriptor, |
| 89 | const TensorInfo& weights, |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 90 | const boost::optional<TensorInfo>& biases, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | std::string* reasonIfUnsupported) |
| 92 | { |
| 93 | ignore_unused(descriptor); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 94 | ignore_unused(output); |
| 95 | ignore_unused(weights); |
| 96 | ignore_unused(biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 97 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 98 | input.GetDataType(), |
| 99 | &TrueFunc<>, |
| 100 | &TrueFunc<>); |
| 101 | } |
| 102 | |
| 103 | bool IsDepthwiseConvolutionSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 104 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 105 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 106 | const TensorInfo& weights, |
arovir01 | a682410 | 2018-08-28 17:40:45 +0100 | [diff] [blame] | 107 | const boost::optional<TensorInfo>& biases, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 108 | std::string* reasonIfUnsupported) |
| 109 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 110 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 111 | ignore_unused(descriptor); |
| 112 | ignore_unused(weights); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 113 | ignore_unused(biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 114 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 115 | input.GetDataType(), |
| 116 | &TrueFunc<>, |
| 117 | &TrueFunc<>); |
| 118 | } |
| 119 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 120 | bool IsDivisionSupportedRef(const TensorInfo& input0, |
| 121 | const TensorInfo& input1, |
| 122 | const TensorInfo& output, |
| 123 | std::string* reasonIfUnsupported) |
| 124 | { |
| 125 | ignore_unused(input1); |
| 126 | ignore_unused(output); |
| 127 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 128 | input0.GetDataType(), |
| 129 | &TrueFunc<>, |
| 130 | &TrueFunc<>); |
| 131 | } |
| 132 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 133 | bool IsSubtractionSupportedRef(const TensorInfo& input0, |
| 134 | const TensorInfo& input1, |
| 135 | const TensorInfo& output, |
| 136 | std::string* reasonIfUnsupported) |
| 137 | { |
David Beck | f195f03 | 2018-09-06 16:46:34 +0100 | [diff] [blame] | 138 | ignore_unused(input1); |
| 139 | ignore_unused(output); |
| 140 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 141 | input0.GetDataType(), |
| 142 | &TrueFunc<>, |
| 143 | &TrueFunc<>); |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 144 | } |
| 145 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 146 | bool IsFullyConnectedSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 147 | const TensorInfo& output, |
| 148 | const TensorInfo& weights, |
| 149 | const TensorInfo& biases, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 150 | const FullyConnectedDescriptor& descriptor, |
| 151 | std::string* reasonIfUnsupported) |
| 152 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 153 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 154 | ignore_unused(descriptor); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 155 | ignore_unused(weights); |
| 156 | ignore_unused(biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 157 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 158 | input.GetDataType(), |
| 159 | &TrueFunc<>, |
| 160 | &TrueFunc<>); |
| 161 | } |
| 162 | |
| 163 | bool IsInputSupportedRef(const TensorInfo& input, |
| 164 | std::string* reasonIfUnsupported) |
| 165 | { |
| 166 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 167 | input.GetDataType(), |
| 168 | &TrueFunc<>, |
| 169 | &TrueFunc<>); |
| 170 | } |
| 171 | |
| 172 | bool IsL2NormalizationSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 173 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 174 | std::string* reasonIfUnsupported) |
| 175 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 176 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 177 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 178 | input.GetDataType(), |
| 179 | &TrueFunc<>, |
| 180 | &FalseFuncU8<>); |
| 181 | } |
| 182 | |
| 183 | bool IsMergerSupportedRef(const std::vector<const TensorInfo*> inputs, |
| 184 | const OriginsDescriptor& descriptor, |
| 185 | std::string* reasonIfUnsupported) |
| 186 | { |
| 187 | ignore_unused(descriptor); |
| 188 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 189 | inputs[0]->GetDataType(), |
| 190 | &TrueFunc<>, |
| 191 | &TrueFunc<>); |
| 192 | } |
| 193 | |
| 194 | bool IsMultiplicationSupportedRef(const TensorInfo& input0, |
| 195 | const TensorInfo& input1, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 196 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 197 | std::string* reasonIfUnsupported) |
| 198 | { |
| 199 | ignore_unused(input1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 200 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 201 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 202 | input0.GetDataType(), |
| 203 | &TrueFunc<>, |
| 204 | &TrueFunc<>); |
| 205 | } |
| 206 | |
| 207 | bool IsNormalizationSupportedRef(const TensorInfo& input, |
| 208 | const TensorInfo& output, |
| 209 | const NormalizationDescriptor& descriptor, |
| 210 | std::string* reasonIfUnsupported) |
| 211 | { |
| 212 | ignore_unused(descriptor); |
| 213 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 214 | input.GetDataType(), |
| 215 | &TrueFunc<>, |
| 216 | &FalseFuncU8<>); |
| 217 | } |
| 218 | |
| 219 | bool IsOutputSupportedRef(const TensorInfo& output, |
| 220 | std::string* reasonIfUnsupported) |
| 221 | { |
| 222 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 223 | output.GetDataType(), |
| 224 | &TrueFunc<>, |
| 225 | &TrueFunc<>); |
| 226 | } |
| 227 | |
| 228 | bool IsPermuteSupportedRef(const TensorInfo& input, |
| 229 | const TensorInfo& output, |
| 230 | const PermuteDescriptor& descriptor, |
| 231 | std::string* reasonIfUnsupported) |
| 232 | { |
| 233 | ignore_unused(descriptor); |
| 234 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 235 | input.GetDataType(), |
| 236 | &TrueFunc<>, |
| 237 | &TrueFunc<>); |
| 238 | } |
| 239 | |
| 240 | bool IsPooling2dSupportedRef(const TensorInfo& input, |
| 241 | const TensorInfo& output, |
| 242 | const Pooling2dDescriptor& descriptor, |
| 243 | std::string* reasonIfUnsupported) |
| 244 | { |
| 245 | ignore_unused(descriptor); |
| 246 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 247 | input.GetDataType(), |
| 248 | &TrueFunc<>, |
| 249 | &TrueFunc<>); |
| 250 | } |
| 251 | |
| 252 | bool IsResizeBilinearSupportedRef(const TensorInfo& input, |
| 253 | std::string* reasonIfUnsupported) |
| 254 | { |
| 255 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 256 | input.GetDataType(), |
| 257 | &TrueFunc<>, |
| 258 | &TrueFunc<>); |
| 259 | } |
| 260 | |
| 261 | bool IsSoftmaxSupportedRef(const TensorInfo& input, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 262 | const TensorInfo& output, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 263 | const SoftmaxDescriptor& descriptor, |
| 264 | std::string* reasonIfUnsupported) |
| 265 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 266 | ignore_unused(output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 267 | ignore_unused(descriptor); |
| 268 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 269 | input.GetDataType(), |
| 270 | &TrueFunc<>, |
| 271 | &TrueFunc<>); |
| 272 | } |
| 273 | |
| 274 | bool IsSplitterSupportedRef(const TensorInfo& input, |
| 275 | const ViewsDescriptor& descriptor, |
| 276 | std::string* reasonIfUnsupported) |
| 277 | { |
| 278 | ignore_unused(descriptor); |
| 279 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 280 | input.GetDataType(), |
| 281 | &TrueFunc<>, |
| 282 | &TrueFunc<>); |
| 283 | } |
| 284 | |
| 285 | bool IsFakeQuantizationSupportedRef(const TensorInfo& input, |
| 286 | const FakeQuantizationDescriptor& descriptor, |
| 287 | std::string* reasonIfUnsupported) |
| 288 | { |
| 289 | ignore_unused(descriptor); |
| 290 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 291 | input.GetDataType(), |
| 292 | &TrueFunc<>, |
| 293 | &FalseFuncU8<>); |
| 294 | } |
| 295 | |
| 296 | bool IsReshapeSupportedRef(const TensorInfo& input, |
| 297 | std::string* reasonIfUnsupported) |
| 298 | { |
| 299 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 300 | input.GetDataType(), |
| 301 | &TrueFunc<>, |
| 302 | &TrueFunc<>); |
| 303 | } |
| 304 | |
| 305 | bool IsFloorSupportedRef(const TensorInfo& input, |
| 306 | const TensorInfo& output, |
| 307 | std::string* reasonIfUnsupported) |
| 308 | { |
| 309 | ignore_unused(output); |
| 310 | return IsSupportedForDataTypeRef(reasonIfUnsupported, |
| 311 | input.GetDataType(), |
| 312 | &TrueFunc<>, |
| 313 | &FalseFuncU8<>); |
| 314 | } |
| 315 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 316 | bool IsLstmSupportedRef(const TensorInfo& input, const TensorInfo& outputStateIn, |
| 317 | const TensorInfo& cellStateIn, const TensorInfo& scratchBuffer, |
| 318 | const TensorInfo& outputStateOut, const TensorInfo& cellStateOut, |
| 319 | const TensorInfo& output, const LstmDescriptor& descriptor, |
| 320 | const TensorInfo& inputToForgetWeights, const TensorInfo& inputToCellWeights, |
| 321 | const TensorInfo& inputToOutputWeights, const TensorInfo& recurrentToForgetWeights, |
| 322 | const TensorInfo& recurrentToCellWeights, const TensorInfo& recurrentToOutputWeights, |
| 323 | const TensorInfo& forgetGateBias, const TensorInfo& cellBias, |
| 324 | const TensorInfo& outputGateBias, const TensorInfo* inputToInputWeights, |
| 325 | const TensorInfo* recurrentToInputWeights, const TensorInfo* cellToInputWeights, |
| 326 | const TensorInfo* inputGateBias, const TensorInfo* projectionWeights, |
| 327 | const TensorInfo* projectionBias, const TensorInfo* cellToForgetWeights, |
| 328 | const TensorInfo* cellToOutputWeights, std::string* reasonIfUnsupported) |
| 329 | { |
| 330 | ignore_unused(input); |
| 331 | ignore_unused(outputStateIn); |
| 332 | ignore_unused(cellStateIn); |
| 333 | ignore_unused(scratchBuffer); |
| 334 | ignore_unused(outputStateOut); |
| 335 | ignore_unused(cellStateOut); |
| 336 | ignore_unused(output); |
| 337 | ignore_unused(descriptor); |
| 338 | ignore_unused(inputToForgetWeights); |
| 339 | ignore_unused(inputToCellWeights); |
| 340 | ignore_unused(inputToOutputWeights); |
| 341 | ignore_unused(recurrentToForgetWeights); |
| 342 | ignore_unused(recurrentToCellWeights); |
| 343 | ignore_unused(recurrentToOutputWeights); |
| 344 | ignore_unused(forgetGateBias); |
| 345 | ignore_unused(cellBias); |
| 346 | ignore_unused(outputGateBias); |
| 347 | ignore_unused(inputToInputWeights); |
| 348 | ignore_unused(recurrentToInputWeights); |
| 349 | ignore_unused(cellToInputWeights); |
| 350 | ignore_unused(inputGateBias); |
| 351 | ignore_unused(projectionWeights); |
| 352 | ignore_unused(projectionBias); |
| 353 | ignore_unused(cellToForgetWeights); |
| 354 | ignore_unused(cellToOutputWeights); |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | bool IsConvertFp16ToFp32SupportedRef(const TensorInfo& input, |
| 359 | const TensorInfo& output, |
| 360 | std::string* reasonIfUnsupported) |
| 361 | { |
| 362 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 363 | input.GetDataType(), |
| 364 | &TrueFunc<>, |
| 365 | &FalseInputFuncF32<>, |
| 366 | &FalseFuncU8<>) && |
| 367 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 368 | output.GetDataType(), |
| 369 | &FalseOutputFuncF16<>, |
| 370 | &TrueFunc<>, |
| 371 | &FalseFuncU8<>)); |
| 372 | } |
| 373 | |
| 374 | bool IsConvertFp32ToFp16SupportedRef(const TensorInfo& input, |
| 375 | const TensorInfo& output, |
| 376 | std::string* reasonIfUnsupported) |
| 377 | { |
| 378 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 379 | input.GetDataType(), |
| 380 | &FalseInputFuncF16<>, |
| 381 | &TrueFunc<>, |
| 382 | &FalseFuncU8<>) && |
| 383 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 384 | output.GetDataType(), |
| 385 | &TrueFunc<>, |
| 386 | &FalseOutputFuncF32<>, |
| 387 | &FalseFuncU8<>)); |
| 388 | } |
| 389 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame^] | 390 | bool IsMeanSupportedRef(const TensorInfo& input, |
| 391 | const TensorInfo& output, |
| 392 | const MeanDescriptor& descriptor, |
| 393 | std::string* reasonIfUnsupported) |
| 394 | { |
| 395 | return false; |
| 396 | } |
| 397 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 398 | } |