telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. 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 | 3cc9a62 | 2018-10-12 10:38:31 +0100 | [diff] [blame] | 7 | |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 8 | #include <armnn/TypesUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 9 | #include <armnn/Types.hpp> |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 10 | #include <armnn/utility/IgnoreUnused.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 11 | #include <armnn/utility/NumericCast.hpp> |
Cathal Corbett | 34b429c | 2021-12-24 12:24:40 +0000 | [diff] [blame] | 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 14 | #include <LayerSupportCommon.hpp> |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 15 | #include <backendsCommon/LayerSupportRules.hpp> |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 16 | |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 17 | #include <vector> |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 18 | #include <array> |
| 19 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | namespace armnn |
| 21 | { |
| 22 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 23 | namespace |
| 24 | { |
| 25 | |
| 26 | template<typename Float32Func, typename Uint8Func, typename ... Params> |
| 27 | bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported, |
| 28 | DataType dataType, |
| 29 | Float32Func floatFuncPtr, |
| 30 | Uint8Func uint8FuncPtr, |
| 31 | Params&&... params) |
| 32 | { |
| 33 | return IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 34 | dataType, |
| 35 | &FalseFunc<Params...>, |
| 36 | floatFuncPtr, |
| 37 | uint8FuncPtr, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 38 | &FalseFunc<Params...>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 39 | &FalseFunc<Params...>, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 40 | std::forward<Params>(params)...); |
| 41 | } |
| 42 | |
| 43 | } // anonymous namespace |
| 44 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 45 | namespace |
| 46 | { |
| 47 | |
| 48 | std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected, |
| 49 | unsigned int actual, |
| 50 | std::string& layerStr, |
| 51 | std::string& tensorName) |
| 52 | { |
| 53 | std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" + |
| 54 | " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor."; |
| 55 | |
| 56 | return errorMsg; |
| 57 | } |
| 58 | |
| 59 | } // anonymous namespace |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 60 | |
Cathal Corbett | 34b429c | 2021-12-24 12:24:40 +0000 | [diff] [blame] | 61 | bool RefLayerSupport::IsLayerSupported(const LayerType& type, |
| 62 | const std::vector<TensorInfo>& infos, |
| 63 | const BaseDescriptor& descriptor, |
| 64 | const Optional<LstmInputParamsInfo>& lstmParamsInfo, |
| 65 | const Optional<QuantizedLstmInputParamsInfo>& quantizedLstmInputParamsInfo, |
| 66 | Optional<std::string&> reasonIfUnsupported) const |
| 67 | { |
| 68 | switch (type) |
| 69 | { |
| 70 | case LayerType::Activation: |
| 71 | return IsActivationSupported(infos[0], |
| 72 | infos[1], |
| 73 | *(PolymorphicDowncast<const ActivationDescriptor*>(&descriptor)), |
| 74 | reasonIfUnsupported); |
| 75 | case LayerType::Addition: |
| 76 | return IsAdditionSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 77 | case LayerType::ArgMinMax: |
| 78 | return IsArgMinMaxSupported(infos[0], |
| 79 | infos[1], |
| 80 | *(PolymorphicDowncast<const ArgMinMaxDescriptor*>(&descriptor)), |
| 81 | reasonIfUnsupported); |
| 82 | case LayerType::BatchNormalization: |
| 83 | return IsBatchNormalizationSupported(infos[0], |
| 84 | infos[1], |
| 85 | infos[2], |
| 86 | infos[3], |
| 87 | infos[4], |
| 88 | infos[5], |
| 89 | *(PolymorphicDowncast<const BatchNormalizationDescriptor*> |
| 90 | (&descriptor)), |
| 91 | reasonIfUnsupported); |
| 92 | case LayerType::BatchToSpaceNd: |
| 93 | return IsBatchToSpaceNdSupported(infos[0], |
| 94 | infos[1], |
| 95 | *(PolymorphicDowncast<const BatchToSpaceNdDescriptor*>(&descriptor)), |
| 96 | reasonIfUnsupported); |
| 97 | case LayerType::Comparison: |
| 98 | return IsComparisonSupported(infos[0], |
| 99 | infos[1], |
| 100 | infos[2], |
| 101 | *(PolymorphicDowncast<const ComparisonDescriptor*>(&descriptor)), |
| 102 | reasonIfUnsupported); |
| 103 | case LayerType::Concat: |
| 104 | { |
| 105 | std::vector<const TensorInfo*> inputInfos; |
| 106 | for (uint32_t i = 0; i < (infos.size() - 1); i++) |
| 107 | { |
| 108 | inputInfos.push_back(&infos[i]); |
| 109 | } |
| 110 | return IsConcatSupported(inputInfos, |
| 111 | infos[infos.size() - 1], |
| 112 | *(PolymorphicDowncast<const OriginsDescriptor*>(&descriptor)), |
| 113 | reasonIfUnsupported); |
| 114 | } |
| 115 | case LayerType::Constant: |
| 116 | return IsConstantSupported(infos[0], reasonIfUnsupported); |
| 117 | case LayerType::ConvertBf16ToFp32: |
| 118 | return IsConvertBf16ToFp32Supported(infos[0], infos[1], reasonIfUnsupported); |
| 119 | case LayerType::ConvertFp16ToFp32: |
| 120 | return IsConvertFp16ToFp32Supported(infos[0], infos[1], reasonIfUnsupported); |
| 121 | case LayerType::ConvertFp32ToBf16: |
| 122 | return IsConvertFp32ToBf16Supported(infos[0], infos[1], reasonIfUnsupported); |
| 123 | case LayerType::ConvertFp32ToFp16: |
| 124 | return IsConvertFp32ToFp16Supported(infos[0], infos[1], reasonIfUnsupported); |
| 125 | case LayerType::Convolution2d: |
| 126 | { |
| 127 | if (infos.size() != 4) |
| 128 | { |
| 129 | throw InvalidArgumentException("Invalid number of Convolution2d TensorInfos. " |
| 130 | "TensorInfos should be of format: {input, output, weights, biases}."); |
| 131 | } |
| 132 | |
| 133 | auto desc = *(PolymorphicDowncast<const Convolution2dDescriptor*>(&descriptor)); |
| 134 | if (infos[3] == TensorInfo()) |
| 135 | { |
| 136 | return IsConvolution2dSupported(infos[0], |
| 137 | infos[1], |
| 138 | desc, |
| 139 | infos[2], |
| 140 | EmptyOptional(), |
| 141 | reasonIfUnsupported); |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | return IsConvolution2dSupported(infos[0], |
| 146 | infos[1], |
| 147 | desc, |
| 148 | infos[2], |
| 149 | infos[3], |
| 150 | reasonIfUnsupported); |
| 151 | } |
| 152 | } |
| 153 | case LayerType::DepthToSpace: |
| 154 | return IsDepthToSpaceSupported(infos[0], |
| 155 | infos[1], |
| 156 | *(PolymorphicDowncast<const DepthToSpaceDescriptor*>(&descriptor)), |
| 157 | reasonIfUnsupported); |
| 158 | case LayerType::DepthwiseConvolution2d: |
| 159 | { |
| 160 | if (infos.size() != 4) |
| 161 | { |
| 162 | throw InvalidArgumentException("Invalid number of DepthwiseConvolution2d TensorInfos. " |
| 163 | "TensorInfos should be of format: {input, output, weights, biases}."); |
| 164 | } |
| 165 | |
| 166 | auto desc = *(PolymorphicDowncast<const DepthwiseConvolution2dDescriptor*>(&descriptor)); |
| 167 | if (infos[3] == TensorInfo()) |
| 168 | { |
| 169 | return IsDepthwiseConvolutionSupported(infos[0], |
| 170 | infos[1], |
| 171 | desc, |
| 172 | infos[2], |
| 173 | EmptyOptional(), |
| 174 | reasonIfUnsupported); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | return IsDepthwiseConvolutionSupported(infos[0], |
| 179 | infos[1], |
| 180 | desc, |
| 181 | infos[2], |
| 182 | infos[3], |
| 183 | reasonIfUnsupported); |
| 184 | } |
| 185 | } |
| 186 | case LayerType::Dequantize: |
| 187 | return IsDequantizeSupported(infos[0], infos[1], reasonIfUnsupported); |
| 188 | case LayerType::Division: |
| 189 | return IsDivisionSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 190 | case LayerType::ElementwiseUnary: |
| 191 | return IsElementwiseUnarySupported(infos[0], |
| 192 | infos[1], |
| 193 | *(PolymorphicDowncast<const ElementwiseUnaryDescriptor*>(&descriptor)), |
| 194 | reasonIfUnsupported); |
| 195 | case LayerType::Fill: |
| 196 | return IsFillSupported(infos[0], |
| 197 | infos[1], |
| 198 | *(PolymorphicDowncast<const FillDescriptor*>(&descriptor)), |
| 199 | reasonIfUnsupported); |
| 200 | case LayerType::Floor: |
| 201 | return IsFloorSupported(infos[0], infos[1], reasonIfUnsupported); |
| 202 | case LayerType::FullyConnected: |
| 203 | return IsFullyConnectedSupported(infos[0], |
| 204 | infos[1], |
| 205 | infos[2], |
| 206 | infos[3], |
| 207 | *(PolymorphicDowncast<const FullyConnectedDescriptor*>(&descriptor)), |
| 208 | reasonIfUnsupported); |
| 209 | case LayerType::Gather: |
| 210 | return IsGatherSupported(infos[0], |
| 211 | infos[1], |
| 212 | infos[2], |
| 213 | *(PolymorphicDowncast<const GatherDescriptor*>(&descriptor)), |
| 214 | reasonIfUnsupported); |
| 215 | case LayerType::Input: |
| 216 | return IsInputSupported(infos[0], reasonIfUnsupported); |
| 217 | case LayerType::InstanceNormalization: |
| 218 | return IsInstanceNormalizationSupported(infos[0], |
| 219 | infos[1], |
| 220 | *(PolymorphicDowncast<const InstanceNormalizationDescriptor*> |
| 221 | (&descriptor)), |
| 222 | reasonIfUnsupported); |
| 223 | case LayerType::L2Normalization: |
| 224 | return IsL2NormalizationSupported(infos[0], |
| 225 | infos[1], |
| 226 | *(PolymorphicDowncast<const L2NormalizationDescriptor*>(&descriptor)), |
| 227 | reasonIfUnsupported); |
| 228 | case LayerType::LogicalBinary: |
| 229 | return IsLogicalBinarySupported(infos[0], |
| 230 | infos[1], |
| 231 | infos[2], |
| 232 | *(PolymorphicDowncast<const LogicalBinaryDescriptor*>(&descriptor)), |
| 233 | reasonIfUnsupported); |
| 234 | case LayerType::LogSoftmax: |
| 235 | return IsLogSoftmaxSupported(infos[0], |
| 236 | infos[1], |
| 237 | *(PolymorphicDowncast<const LogSoftmaxDescriptor*>(&descriptor)), |
| 238 | reasonIfUnsupported); |
| 239 | case LayerType::Lstm: |
| 240 | return IsLstmSupported(infos[0], |
| 241 | infos[1], |
| 242 | infos[2], |
| 243 | infos[3], |
| 244 | infos[4], |
| 245 | infos[5], |
| 246 | infos[6], |
| 247 | *(PolymorphicDowncast<const LstmDescriptor*>(&descriptor)), |
| 248 | lstmParamsInfo.value(), |
| 249 | reasonIfUnsupported); |
| 250 | case LayerType::QLstm: |
| 251 | return IsQLstmSupported(infos[0], |
| 252 | infos[1], |
| 253 | infos[2], |
| 254 | infos[3], |
| 255 | infos[4], |
| 256 | infos[5], |
| 257 | *(PolymorphicDowncast<const QLstmDescriptor*>(&descriptor)), |
| 258 | lstmParamsInfo.value(), |
| 259 | reasonIfUnsupported); |
| 260 | case LayerType::Maximum: |
| 261 | return IsMaximumSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 262 | case LayerType::Mean: |
| 263 | return IsMeanSupported(infos[0], |
| 264 | infos[1], |
| 265 | *(PolymorphicDowncast<const MeanDescriptor*>(&descriptor)), |
| 266 | reasonIfUnsupported); |
| 267 | case LayerType::Minimum: |
| 268 | return IsMinimumSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 269 | case LayerType::Multiplication: |
| 270 | return IsMultiplicationSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 271 | case LayerType::Normalization: |
| 272 | return IsNormalizationSupported(infos[0], |
| 273 | infos[1], |
| 274 | *(PolymorphicDowncast<const NormalizationDescriptor*>(&descriptor)), |
| 275 | reasonIfUnsupported); |
| 276 | case LayerType::Output: |
| 277 | return IsOutputSupported(infos[0], reasonIfUnsupported); |
| 278 | case LayerType::Pad: |
| 279 | return IsPadSupported(infos[0], |
| 280 | infos[1], |
| 281 | *(PolymorphicDowncast<const PadDescriptor*>(&descriptor)), |
| 282 | reasonIfUnsupported); |
| 283 | case LayerType::Permute: |
| 284 | return IsPermuteSupported(infos[0], |
| 285 | infos[1], |
| 286 | *(PolymorphicDowncast<const PermuteDescriptor*>(&descriptor)), |
| 287 | reasonIfUnsupported); |
| 288 | case LayerType::Pooling2d: |
| 289 | return IsPooling2dSupported(infos[0], |
| 290 | infos[1], |
| 291 | *(PolymorphicDowncast<const Pooling2dDescriptor*>(&descriptor)), |
| 292 | reasonIfUnsupported); |
| 293 | case LayerType::Prelu: |
| 294 | return IsPreluSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 295 | case LayerType::Quantize: |
| 296 | return IsQuantizeSupported(infos[0], infos[1], reasonIfUnsupported); |
| 297 | case LayerType::Reshape: |
| 298 | return IsReshapeSupported(infos[0], |
| 299 | infos[1], |
| 300 | *(PolymorphicDowncast<const ReshapeDescriptor*>(&descriptor)), |
| 301 | reasonIfUnsupported); |
| 302 | case LayerType::Resize: |
| 303 | return IsResizeSupported(infos[0], |
| 304 | infos[1], |
| 305 | *(PolymorphicDowncast<const ResizeDescriptor*>(&descriptor)), |
| 306 | reasonIfUnsupported); |
| 307 | case LayerType::Reduce: |
| 308 | return IsReduceSupported(infos[0], |
| 309 | infos[1], |
| 310 | *(PolymorphicDowncast<const ReduceDescriptor*>(&descriptor)), |
| 311 | reasonIfUnsupported); |
| 312 | case LayerType::Slice: |
| 313 | return IsSliceSupported(infos[0], |
| 314 | infos[1], |
| 315 | *(PolymorphicDowncast<const SliceDescriptor*>(&descriptor)), |
| 316 | reasonIfUnsupported); |
| 317 | case LayerType::Softmax: |
| 318 | return IsSoftmaxSupported(infos[0], |
| 319 | infos[1], |
| 320 | *(PolymorphicDowncast<const SoftmaxDescriptor*>(&descriptor)), |
| 321 | reasonIfUnsupported); |
| 322 | case LayerType::SpaceToBatchNd: |
| 323 | return IsSpaceToBatchNdSupported(infos[0], |
| 324 | infos[1], |
| 325 | *(PolymorphicDowncast<const SpaceToBatchNdDescriptor*>(&descriptor)), |
| 326 | reasonIfUnsupported); |
| 327 | case LayerType::SpaceToDepth: |
| 328 | return IsSpaceToDepthSupported(infos[0], |
| 329 | infos[1], |
| 330 | *(PolymorphicDowncast<const SpaceToDepthDescriptor*>(&descriptor)), |
| 331 | reasonIfUnsupported); |
| 332 | case LayerType::Splitter: |
| 333 | { |
| 334 | std::vector<TensorInfo> outputInfos; |
| 335 | for (uint32_t i = 1; i < infos.size(); i++) |
| 336 | { |
| 337 | outputInfos.push_back(infos[i]); |
| 338 | } |
| 339 | return IsSplitterSupported(infos[0], |
| 340 | {outputInfos.begin(), outputInfos.end()}, |
| 341 | *(PolymorphicDowncast<const ViewsDescriptor*>(&descriptor)), |
| 342 | reasonIfUnsupported); |
| 343 | } |
| 344 | case LayerType::Stack: |
| 345 | { |
| 346 | std::vector<const TensorInfo*> inputInfos; |
| 347 | for (uint32_t i = 0; i < infos.size() - 1; i++) |
| 348 | { |
| 349 | inputInfos.push_back(&infos[i]); |
| 350 | } |
| 351 | return IsStackSupported(inputInfos, |
| 352 | infos[infos.size() - 1], |
| 353 | *(PolymorphicDowncast<const StackDescriptor*>(&descriptor)), |
| 354 | reasonIfUnsupported); |
| 355 | } |
| 356 | case LayerType::StridedSlice: |
| 357 | return IsStridedSliceSupported(infos[0], |
| 358 | infos[1], |
| 359 | *(PolymorphicDowncast<const StridedSliceDescriptor*>(&descriptor)), |
| 360 | reasonIfUnsupported); |
| 361 | case LayerType::Subtraction: |
| 362 | return IsSubtractionSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 363 | case LayerType::Transpose: |
| 364 | return IsTransposeSupported(infos[0], |
| 365 | infos[1], |
| 366 | *(PolymorphicDowncast<const TransposeDescriptor*>(&descriptor)), |
| 367 | reasonIfUnsupported); |
| 368 | case LayerType::TransposeConvolution2d: |
| 369 | { |
| 370 | if (infos.size() != 4) |
| 371 | { |
| 372 | throw InvalidArgumentException("Invalid number of TransposeConvolution2d TensorInfos. " |
| 373 | "TensorInfos should be of format: {input, output, weights, biases}."); |
| 374 | } |
| 375 | |
| 376 | auto desc = *(PolymorphicDowncast<const TransposeConvolution2dDescriptor*>(&descriptor)); |
| 377 | if (infos[3] == TensorInfo()) |
| 378 | { |
| 379 | return IsTransposeConvolution2dSupported(infos[0], |
| 380 | infos[1], |
| 381 | desc, |
| 382 | infos[2], |
| 383 | EmptyOptional(), |
| 384 | reasonIfUnsupported); |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | return IsTransposeConvolution2dSupported(infos[0], |
| 389 | infos[1], |
| 390 | desc, |
| 391 | infos[2], |
| 392 | infos[3], |
| 393 | reasonIfUnsupported); |
| 394 | } |
| 395 | } |
| 396 | case LayerType::Cast: |
| 397 | return IsCastSupported(infos[0], infos[1], reasonIfUnsupported); |
| 398 | case LayerType::ChannelShuffle: |
| 399 | return IsChannelShuffleSupported(infos[0], |
| 400 | infos[1], |
| 401 | *(PolymorphicDowncast<const ChannelShuffleDescriptor*>(&descriptor)), |
| 402 | reasonIfUnsupported); |
| 403 | case LayerType::Convolution3d: |
| 404 | { |
| 405 | if (infos.size() != 4) |
| 406 | { |
| 407 | throw InvalidArgumentException("Invalid number of Convolution3d TensorInfos. " |
| 408 | "TensorInfos should be of format: {input, output, weights, biases}."); |
| 409 | } |
| 410 | |
| 411 | auto desc = *(PolymorphicDowncast<const Convolution3dDescriptor*>(&descriptor)); |
| 412 | if (infos[3] == TensorInfo()) |
| 413 | { |
| 414 | return IsConvolution3dSupported(infos[0], |
| 415 | infos[1], |
| 416 | desc, |
| 417 | infos[2], |
| 418 | EmptyOptional(), |
| 419 | reasonIfUnsupported); |
| 420 | } |
| 421 | else |
| 422 | { |
| 423 | return IsConvolution3dSupported(infos[0], |
| 424 | infos[1], |
| 425 | desc, |
| 426 | infos[2], |
| 427 | infos[3], |
| 428 | reasonIfUnsupported); |
| 429 | } |
| 430 | } |
| 431 | case LayerType::Debug: |
| 432 | return IsDebugSupported(infos[0], infos[1], reasonIfUnsupported); |
| 433 | case LayerType::DetectionPostProcess: |
| 434 | return IsDetectionPostProcessSupported(infos[0], |
| 435 | infos[1], |
| 436 | infos[2], |
| 437 | infos[3], |
| 438 | infos[4], |
| 439 | infos[5], |
| 440 | infos[6], |
| 441 | *(PolymorphicDowncast<const DetectionPostProcessDescriptor*> |
| 442 | (&descriptor)), |
| 443 | reasonIfUnsupported); |
| 444 | case LayerType::FakeQuantization: |
| 445 | return IsFakeQuantizationSupported(infos[0], |
| 446 | *(PolymorphicDowncast<const FakeQuantizationDescriptor*>(&descriptor)), |
| 447 | reasonIfUnsupported); |
| 448 | case LayerType::MemCopy: |
| 449 | return IsMemCopySupported(infos[0], infos[1], reasonIfUnsupported); |
| 450 | case LayerType::Rank: |
| 451 | return IsRankSupported(infos[0], infos[1], reasonIfUnsupported); |
| 452 | case LayerType::Shape: |
| 453 | return IsShapeSupported(infos[0], infos[1], reasonIfUnsupported); |
| 454 | case LayerType::UnidirectionalSequenceLstm: |
| 455 | { |
| 456 | if (infos.size() != 6) |
| 457 | { |
| 458 | throw InvalidArgumentException("Invalid number of UnidirectionalSequenceLstm TensorInfos. TensorInfos " |
| 459 | "should be of format: {input, outputStateIn, cellStateIn, " |
| 460 | "hiddenStateOutputVal, cellStateOutputVal, output}"); |
| 461 | } |
| 462 | auto desc = *(PolymorphicDowncast<const UnidirectionalSequenceLstmDescriptor*>(&descriptor)); |
| 463 | |
| 464 | bool isHiddenStateOutputOptional = (infos[4] == TensorInfo()); |
| 465 | bool isCellStateOutput = (infos[5] == TensorInfo()); |
| 466 | if (isHiddenStateOutputOptional && isCellStateOutput) |
| 467 | { |
| 468 | return IsUnidirectionalSequenceLstmSupported(infos[0], |
| 469 | infos[1], |
| 470 | infos[2], |
| 471 | infos[3], |
| 472 | EmptyOptional(), |
| 473 | EmptyOptional(), |
| 474 | desc, |
| 475 | lstmParamsInfo.value(), |
| 476 | reasonIfUnsupported); |
| 477 | } |
| 478 | else if (isHiddenStateOutputOptional) |
| 479 | { |
| 480 | return IsUnidirectionalSequenceLstmSupported(infos[0], |
| 481 | infos[1], |
| 482 | infos[2], |
| 483 | infos[3], |
| 484 | EmptyOptional(), |
| 485 | infos[5], |
| 486 | desc, |
| 487 | lstmParamsInfo.value(), |
| 488 | reasonIfUnsupported); |
| 489 | } |
| 490 | else if (isCellStateOutput) |
| 491 | { |
| 492 | return IsUnidirectionalSequenceLstmSupported(infos[0], |
| 493 | infos[1], |
| 494 | infos[2], |
| 495 | infos[3], |
| 496 | infos[4], |
| 497 | EmptyOptional(), |
| 498 | desc, |
| 499 | lstmParamsInfo.value(), |
| 500 | reasonIfUnsupported); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | return IsUnidirectionalSequenceLstmSupported(infos[0], |
| 505 | infos[1], |
| 506 | infos[2], |
| 507 | infos[3], |
| 508 | infos[4], |
| 509 | infos[5], |
| 510 | desc, |
| 511 | lstmParamsInfo.value(), |
| 512 | reasonIfUnsupported); |
| 513 | } |
| 514 | } |
| 515 | case LayerType::Pooling3d: |
| 516 | return IsPooling3dSupported(infos[0], |
| 517 | infos[1], |
| 518 | *(PolymorphicDowncast<const Pooling3dDescriptor*>(&descriptor)), |
| 519 | reasonIfUnsupported); |
| 520 | case LayerType::Map: |
| 521 | return true; |
| 522 | case LayerType::Unmap: |
| 523 | return true; |
| 524 | case LayerType::MemImport: |
| 525 | return LayerSupportBase::IsMemImportSupported(infos[0], infos[1], reasonIfUnsupported); |
| 526 | case LayerType::Merge: |
| 527 | return LayerSupportBase::IsMergeSupported(infos[0], infos[1], infos[2], reasonIfUnsupported); |
| 528 | case LayerType::QuantizedLstm: |
| 529 | return LayerSupportBase::IsQuantizedLstmSupported(infos[0], |
| 530 | infos[1], |
| 531 | infos[2], |
| 532 | infos[3], |
| 533 | infos[4], |
| 534 | quantizedLstmInputParamsInfo.value(), |
| 535 | reasonIfUnsupported); |
| 536 | default: |
| 537 | // layers not supported in neon by default: |
| 538 | // precompiled, standin, switch |
| 539 | return false; |
| 540 | } |
| 541 | } |
| 542 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 543 | bool RefLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 544 | const TensorInfo& output, |
| 545 | const ActivationDescriptor& descriptor, |
| 546 | Optional<std::string&> reasonIfUnsupported) const |
| 547 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 548 | bool supported = true; |
| 549 | |
| 550 | // Define supported types. |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 551 | std::array<DataType,6> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 552 | DataType::BFloat16, |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 553 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 554 | DataType::Float16, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 555 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 556 | DataType::QAsymmU8, |
| 557 | DataType::QSymmS16 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 561 | "Reference activation: input type not supported."); |
| 562 | |
| 563 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 564 | "Reference activation: output type not supported."); |
| 565 | |
| 566 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 567 | "Reference activation: input and output types mismatched."); |
| 568 | |
| 569 | supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported, |
| 570 | "Reference activation: input and output shapes are of different rank."); |
| 571 | |
| 572 | |
| 573 | struct ActivationFunctionSupported : public Rule |
| 574 | { |
| 575 | ActivationFunctionSupported(const ActivationDescriptor& desc) |
| 576 | { |
| 577 | switch(desc.m_Function) |
| 578 | { |
| 579 | case ActivationFunction::Abs: |
| 580 | case ActivationFunction::BoundedReLu: |
David Monahan | 3b3c381 | 2020-02-25 09:03:29 +0000 | [diff] [blame] | 581 | case ActivationFunction::Elu: |
Colm Donelan | 03fbeaf | 2020-02-26 15:39:23 +0000 | [diff] [blame] | 582 | case ActivationFunction::HardSwish: |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 583 | case ActivationFunction::LeakyReLu: |
| 584 | case ActivationFunction::Linear: |
| 585 | case ActivationFunction::ReLu: |
| 586 | case ActivationFunction::Sigmoid: |
| 587 | case ActivationFunction::SoftReLu: |
| 588 | case ActivationFunction::Sqrt: |
| 589 | case ActivationFunction::Square: |
| 590 | case ActivationFunction::TanH: |
| 591 | { |
| 592 | m_Res = true; |
| 593 | break; |
| 594 | } |
| 595 | default: |
| 596 | { |
| 597 | m_Res = false; |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | }; |
| 603 | |
| 604 | // Function is supported |
| 605 | supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported, |
| 606 | "Reference activation: function not supported."); |
| 607 | |
| 608 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 612 | const TensorInfo& input1, |
| 613 | const TensorInfo& output, |
| 614 | Optional<std::string&> reasonIfUnsupported) const |
| 615 | { |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 616 | bool supported = true; |
| 617 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 618 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 619 | DataType::BFloat16, |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 620 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 621 | DataType::Float16, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 622 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 623 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 624 | DataType::QSymmS16, |
| 625 | DataType::Signed32 |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 626 | }; |
| 627 | |
| 628 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 629 | "Reference addition: input 0 is not a supported type."); |
| 630 | |
| 631 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 632 | "Reference addition: input 1 is not a supported type."); |
| 633 | |
| 634 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 635 | "Reference addition: output is not a supported type."); |
| 636 | |
| 637 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 638 | "Reference addition: input 0 and Input 1 types are mismatched"); |
| 639 | |
| 640 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 641 | "Reference addition: input and output types are mismatched"); |
| 642 | |
| 643 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 644 | "Reference addition: shapes are not suitable for implicit broadcast."); |
| 645 | |
| 646 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 647 | } |
| 648 | |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 649 | bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output, |
| 650 | const armnn::ArgMinMaxDescriptor &descriptor, |
| 651 | armnn::Optional<std::string &> reasonIfUnsupported) const |
| 652 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 653 | IgnoreUnused(descriptor); |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 654 | |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 655 | std::array<DataType, 8> supportedInputTypes = |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 656 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 657 | DataType::BFloat16, |
Teresa Charlin | e300b36 | 2020-05-25 10:01:03 +0100 | [diff] [blame] | 658 | DataType::Float16, |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 659 | DataType::Float32, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 660 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 661 | DataType::QAsymmU8, |
| 662 | DataType::QSymmS16, |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 663 | DataType::Signed32, |
| 664 | DataType::Signed64 |
| 665 | }; |
| 666 | |
| 667 | std::array<DataType,2> supportedOutputTypes = { |
| 668 | DataType::Signed32, |
| 669 | DataType::Signed64 |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 670 | }; |
| 671 | |
| 672 | bool supported = true; |
| 673 | |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 674 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 675 | "Reference ArgMinMax: input is not a supported type."); |
Mike Kelly | 1f140f7 | 2021-04-06 12:25:55 +0100 | [diff] [blame] | 676 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
Nikhil Raj | 68c2c90 | 2019-09-19 11:21:11 +0100 | [diff] [blame] | 677 | "Reference ArgMinMax: output type not supported"); |
| 678 | |
| 679 | return supported; |
| 680 | } |
| 681 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 682 | bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 683 | const TensorInfo& output, |
| 684 | const TensorInfo& mean, |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 685 | const TensorInfo& variance, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 686 | const TensorInfo& beta, |
| 687 | const TensorInfo& gamma, |
| 688 | const BatchNormalizationDescriptor& descriptor, |
| 689 | Optional<std::string&> reasonIfUnsupported) const |
| 690 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 691 | IgnoreUnused(descriptor); |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 692 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 693 | std::array<DataType, 6> supportedTypes = |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 694 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 695 | DataType::BFloat16, |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 696 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 697 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 698 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 699 | DataType::QAsymmU8, |
| 700 | DataType::QSymmS16 |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | bool supported = true; |
| 704 | |
| 705 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 706 | "Reference batch normalization: input is not a supported type."); |
| 707 | |
| 708 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 709 | "Reference batch normalization: output is not a supported type."); |
| 710 | |
| 711 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 712 | "Reference batch normalization: input and output types are mismatched"); |
| 713 | |
| 714 | supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported, |
| 715 | "Reference batch normalization: mean is not a supported type."); |
| 716 | |
| 717 | supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported, |
| 718 | "Reference batch normalization: variance is not a supported type."); |
| 719 | |
| 720 | supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported, |
| 721 | "Reference batch normalization: beta is not a supported type."); |
| 722 | |
| 723 | supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported, |
| 724 | "Reference batch normalization: gamma is not a supported type."); |
| 725 | |
| 726 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 727 | } |
| 728 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 729 | bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 730 | const TensorInfo& output, |
| 731 | const BatchToSpaceNdDescriptor& descriptor, |
| 732 | Optional<std::string&> reasonIfUnsupported) const |
| 733 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 734 | IgnoreUnused(descriptor); |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 735 | |
| 736 | bool supported = true; |
| 737 | |
| 738 | std::string batchToSpaceNdLayerStr = "batchToSpaceNd"; |
| 739 | std::string inputTensorStr = "input"; |
| 740 | std::string outputTensorStr = "output"; |
| 741 | |
| 742 | // Define supported types. |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 743 | std::array<DataType,6> supportedTypes = |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 744 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 745 | DataType::BFloat16, |
| 746 | DataType::Float32, |
| 747 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 748 | DataType::QAsymmS8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 749 | DataType::QAsymmU8, |
| 750 | DataType::QSymmS16 |
Francis Murtagh | d0dfe17 | 2019-06-25 10:57:10 +0100 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 754 | "Reference BatchToSpaceNd: input type not supported."); |
| 755 | |
| 756 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 757 | "Reference BatchToSpaceNd: output type not supported."); |
| 758 | |
| 759 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 760 | "Reference BatchToSpaceNd: input and output types mismatched."); |
| 761 | |
| 762 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4), |
| 763 | reasonIfUnsupported, |
| 764 | CreateIncorrectDimensionsErrorMsg(4, |
| 765 | output.GetNumDimensions(), |
| 766 | batchToSpaceNdLayerStr, |
| 767 | outputTensorStr).data()); |
| 768 | |
| 769 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4), |
| 770 | reasonIfUnsupported, |
| 771 | CreateIncorrectDimensionsErrorMsg(4, |
| 772 | input.GetNumDimensions(), |
| 773 | batchToSpaceNdLayerStr, |
| 774 | inputTensorStr).data()); |
| 775 | |
| 776 | return supported; |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 777 | } |
| 778 | |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 779 | bool RefLayerSupport::IsCastSupported(const TensorInfo& input, |
| 780 | const TensorInfo& output, |
| 781 | Optional<std::string&> reasonIfUnsupported) const |
| 782 | { |
| 783 | std::array<DataType, 9> supportedInputTypes = |
| 784 | { |
| 785 | DataType::BFloat16, |
| 786 | DataType::Float32, |
| 787 | DataType::Float16, |
| 788 | DataType::QSymmS8, |
| 789 | DataType::QAsymmS8, |
| 790 | DataType::QAsymmU8, |
| 791 | DataType::QSymmS16, |
| 792 | DataType::Signed32 |
| 793 | }; |
| 794 | |
| 795 | bool supported = true; |
| 796 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 797 | "Reference cast: input is not a supported type"); |
| 798 | |
| 799 | |
| 800 | supported &= CheckSupportRule(TypeAnyOf(output, supportedInputTypes), reasonIfUnsupported, |
| 801 | "Reference cast: output is not a supported type"); |
| 802 | |
| 803 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 804 | "Reference cast: input and output shapes have different number of total elements"); |
| 805 | |
| 806 | return supported; |
| 807 | } |
| 808 | |
Simon Obute | 51f6777 | 2021-09-03 15:50:13 +0100 | [diff] [blame] | 809 | bool RefLayerSupport::IsChannelShuffleSupported(const TensorInfo& input, |
| 810 | const TensorInfo& output, |
| 811 | const ChannelShuffleDescriptor& descriptor, |
| 812 | Optional<std::string&> reasonIfUnsupported) const |
| 813 | { |
| 814 | IgnoreUnused(descriptor); |
| 815 | bool supported = true; |
| 816 | |
| 817 | // Define supported output and inputs types. |
| 818 | std::array<DataType, 7> supportedTypes = |
| 819 | { |
| 820 | DataType::BFloat16, |
| 821 | DataType::Float32, |
| 822 | DataType::Float16, |
| 823 | DataType::QAsymmS8, |
| 824 | DataType::QAsymmU8, |
| 825 | DataType::QSymmS8, |
| 826 | DataType::QSymmS16 |
| 827 | }; |
| 828 | |
| 829 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 830 | "Reference ChannelShuffle: input is not a supported type."); |
| 831 | |
| 832 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 833 | "Reference ChannelShuffle: output is not a supported type."); |
| 834 | |
| 835 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 836 | "Reference ChannelShuffle: input and output types are mismatched."); |
| 837 | |
| 838 | return supported; |
| 839 | } |
| 840 | |
| 841 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 842 | bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0, |
| 843 | const TensorInfo& input1, |
| 844 | const TensorInfo& output, |
| 845 | const ComparisonDescriptor& descriptor, |
| 846 | Optional<std::string&> reasonIfUnsupported) const |
| 847 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 848 | IgnoreUnused(descriptor); |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 849 | std::array<DataType, 8> supportedInputTypes = |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 850 | { |
Sadik Armagan | b60dd24 | 2020-03-19 13:53:16 +0000 | [diff] [blame] | 851 | DataType::Boolean, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 852 | DataType::BFloat16, |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 853 | DataType::Float32, |
| 854 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 855 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 856 | DataType::QAsymmU8, |
Sadik Armagan | b60dd24 | 2020-03-19 13:53:16 +0000 | [diff] [blame] | 857 | DataType::QSymmS16, |
| 858 | DataType::Signed32 |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | bool supported = true; |
| 862 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported, |
| 863 | "Reference comparison: input 0 is not a supported type"); |
| 864 | |
| 865 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 866 | "Reference comparison: input 0 and Input 1 types are mismatched"); |
| 867 | |
| 868 | supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported, |
| 869 | "Reference comparison: output is not of type Boolean"); |
| 870 | |
| 871 | return supported; |
| 872 | } |
| 873 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 874 | bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 875 | const TensorInfo& output, |
Cathal Corbett | 34b429c | 2021-12-24 12:24:40 +0000 | [diff] [blame] | 876 | const OriginsDescriptor& descriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 877 | Optional<std::string&> reasonIfUnsupported) const |
| 878 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 879 | IgnoreUnused(descriptor); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 880 | |
| 881 | bool supported = true; |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 882 | std::array<DataType,6> supportedTypes = |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 883 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 884 | DataType::BFloat16, |
| 885 | DataType::Float32, |
| 886 | DataType::Float16, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 887 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 888 | DataType::QAsymmU8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 889 | DataType::QSymmS16 |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 890 | }; |
| 891 | |
| 892 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 893 | "Reference concatenation: output type not supported"); |
| 894 | for (const TensorInfo* input : inputs) |
| 895 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 896 | ARMNN_ASSERT(input != nullptr); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 897 | supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported, |
| 898 | "Reference concatenation: input type not supported"); |
| 899 | |
| 900 | supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported, |
| 901 | "Reference concatenation: input and output types mismatched."); |
| 902 | } |
| 903 | |
| 904 | return supported; |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 905 | } |
| 906 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 907 | bool RefLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 908 | Optional<std::string&> reasonIfUnsupported) const |
| 909 | { |
Teresa Charlin | 6fa8ce6 | 2020-05-25 16:16:44 +0100 | [diff] [blame] | 910 | std::array<DataType,8> supportedTypes = |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 911 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 912 | DataType::BFloat16, |
Teresa Charlin | 6fa8ce6 | 2020-05-25 16:16:44 +0100 | [diff] [blame] | 913 | DataType::Float16, |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 914 | DataType::Float32, |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 915 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 916 | DataType::QAsymmU8, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 917 | DataType::QSymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 918 | DataType::QSymmS16, |
| 919 | DataType::Signed32 |
Nina Drozd | 58ef2c6 | 2019-05-16 12:09:18 +0100 | [diff] [blame] | 920 | }; |
| 921 | |
| 922 | return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 923 | "Reference constant: output is not a supported type."); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Narumol Prangnawarat | 7ddbbae | 2020-03-13 10:26:05 +0000 | [diff] [blame] | 926 | bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input, |
| 927 | const TensorInfo& output, |
| 928 | Optional<std::string&> reasonIfUnsupported) const |
| 929 | { |
| 930 | bool supported = true; |
| 931 | |
| 932 | supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported, |
| 933 | "Reference for ConvertBf16ToFp32 layer: input type not supported"); |
| 934 | |
| 935 | supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported, |
| 936 | "Reference for ConvertBf16ToFp32 layer: output type not supported"); |
| 937 | |
| 938 | return supported; |
| 939 | } |
| 940 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 941 | bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 942 | const TensorInfo& output, |
| 943 | Optional<std::string&> reasonIfUnsupported) const |
| 944 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 945 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 946 | input.GetDataType(), |
| 947 | &TrueFunc<>, |
| 948 | &FalseInputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 949 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 950 | &FalseFuncI32<>, |
| 951 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 952 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 953 | output.GetDataType(), |
| 954 | &FalseOutputFuncF16<>, |
| 955 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 956 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 957 | &FalseFuncI32<>, |
| 958 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 961 | bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input, |
| 962 | const TensorInfo& output, |
| 963 | Optional<std::string&> reasonIfUnsupported) const |
| 964 | { |
| 965 | bool supported = true; |
| 966 | |
| 967 | supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported, |
| 968 | "Reference for ConvertFp32ToBf16 layer: input type not supported"); |
| 969 | |
| 970 | supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported, |
| 971 | "Reference for ConvertFp32ToBf16 layer: output type not supported"); |
| 972 | |
| 973 | return supported; |
| 974 | } |
| 975 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 976 | bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 977 | const TensorInfo& output, |
| 978 | Optional<std::string&> reasonIfUnsupported) const |
| 979 | { |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 980 | return (IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 981 | input.GetDataType(), |
| 982 | &FalseInputFuncF16<>, |
| 983 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 984 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 985 | &FalseFuncI32<>, |
| 986 | &FalseFuncU8<>) && |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 987 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 988 | output.GetDataType(), |
| 989 | &TrueFunc<>, |
| 990 | &FalseOutputFuncF32<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 991 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 992 | &FalseFuncI32<>, |
| 993 | &FalseFuncU8<>)); |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 997 | const TensorInfo& output, |
| 998 | const Convolution2dDescriptor& descriptor, |
| 999 | const TensorInfo& weights, |
| 1000 | const Optional<TensorInfo>& biases, |
| 1001 | Optional<std::string&> reasonIfUnsupported) const |
| 1002 | { |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1003 | bool supported = true; |
| 1004 | |
| 1005 | // Define supported types. |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1006 | std::array<DataType,7> supportedTypes = |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1007 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1008 | DataType::BFloat16, |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1009 | DataType::Float32, |
| 1010 | DataType::Float16, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 1011 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1012 | DataType::QAsymmU8, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1013 | DataType::QSymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1014 | DataType::QSymmS16 |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1015 | }; |
| 1016 | |
| 1017 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1018 | "Reference Convolution2d: input is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1019 | |
| 1020 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1021 | "Reference Convolution2d: output is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1022 | |
Narumol Prangnawarat | 57ef008 | 2020-03-26 09:20:43 +0000 | [diff] [blame] | 1023 | // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization. |
| 1024 | if (input.GetDataType() == DataType::BFloat16) |
| 1025 | { |
| 1026 | if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32) |
| 1027 | { |
| 1028 | reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n"; |
| 1029 | supported = false; |
| 1030 | } |
| 1031 | } |
| 1032 | else |
| 1033 | { |
| 1034 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1035 | "Reference Convolution2d: input and output types mismatched."); |
Narumol Prangnawarat | 57ef008 | 2020-03-26 09:20:43 +0000 | [diff] [blame] | 1036 | } |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1037 | |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1038 | const DataType inputType = input.GetDataType(); |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 1039 | if (IsQuantized8BitType(inputType)) |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1040 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 1041 | std::array<DataType, 3> supportedWeightTypes = |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1042 | { |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1043 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1044 | DataType::QAsymmU8, |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 1045 | DataType::QSymmS8 |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1046 | }; |
| 1047 | |
| 1048 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1049 | "Reference Convolution2d: weights type not supported for quantized input."); |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1050 | } |
| 1051 | else |
| 1052 | { |
| 1053 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1054 | "Reference Convolution2d: weights is not a supported type."); |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1055 | |
| 1056 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1057 | "Reference Convolution2d: input and weights types mismatched."); |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1058 | } |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1059 | |
| 1060 | if (biases.has_value()) |
| 1061 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1062 | std::array<DataType,4> biasesSupportedTypes = |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1063 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1064 | DataType::BFloat16, |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1065 | DataType::Float32, |
| 1066 | DataType::Float16, |
| 1067 | DataType::Signed32 |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1068 | }; |
Aron Virginas-Tar | 5edc881 | 2019-11-05 18:00:21 +0000 | [diff] [blame] | 1069 | |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1070 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1071 | "Reference Convolution2d: biases is not a supported type."); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1072 | } |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1073 | IgnoreUnused(descriptor); |
Mike Kelly | 2f80f6e | 2019-05-16 12:41:34 +0100 | [diff] [blame] | 1074 | |
| 1075 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
Matthew Sloyan | b63a311 | 2021-09-08 13:05:51 +0100 | [diff] [blame] | 1078 | bool RefLayerSupport::IsConvolution3dSupported(const TensorInfo& input, |
| 1079 | const TensorInfo& output, |
| 1080 | const Convolution3dDescriptor& descriptor, |
| 1081 | const TensorInfo& weights, |
| 1082 | const Optional<TensorInfo>& biases, |
| 1083 | Optional<std::string&> reasonIfUnsupported) const |
| 1084 | { |
| 1085 | bool supported = true; |
| 1086 | |
| 1087 | // Define supported types. |
| 1088 | std::array<DataType,7> supportedTypes = |
| 1089 | { |
| 1090 | DataType::BFloat16, |
| 1091 | DataType::Float32, |
| 1092 | DataType::Float16, |
| 1093 | DataType::QAsymmS8, |
| 1094 | DataType::QAsymmU8, |
| 1095 | DataType::QSymmS8, |
| 1096 | DataType::QSymmS16 |
| 1097 | }; |
| 1098 | |
| 1099 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1100 | "Reference Convolution3d: input is not a supported type."); |
| 1101 | |
| 1102 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1103 | "Reference Convolution3d: output is not a supported type."); |
| 1104 | |
| 1105 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1106 | "Reference Convolution3d: input and output types mismatched."); |
| 1107 | |
| 1108 | const DataType inputType = input.GetDataType(); |
| 1109 | if (IsQuantized8BitType(inputType)) |
| 1110 | { |
| 1111 | std::array<DataType, 3> supportedWeightTypes = |
| 1112 | { |
| 1113 | DataType::QAsymmS8, |
| 1114 | DataType::QAsymmU8, |
| 1115 | DataType::QSymmS8 |
| 1116 | }; |
| 1117 | |
| 1118 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported, |
| 1119 | "Reference Convolution3d: weights type not supported for quantized input."); |
| 1120 | } |
| 1121 | else |
| 1122 | { |
| 1123 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 1124 | "Reference Convolution3d: weights is not a supported type."); |
| 1125 | |
| 1126 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 1127 | "Reference Convolution3d: input and weights types mismatched."); |
| 1128 | } |
| 1129 | |
| 1130 | if (biases.has_value()) |
| 1131 | { |
| 1132 | std::array<DataType,4> biasesSupportedTypes = |
| 1133 | { |
| 1134 | DataType::BFloat16, |
| 1135 | DataType::Float32, |
| 1136 | DataType::Float16, |
| 1137 | DataType::Signed32 |
| 1138 | }; |
| 1139 | |
| 1140 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 1141 | "Reference Convolution3d: biases is not a supported type."); |
| 1142 | } |
| 1143 | IgnoreUnused(descriptor); |
| 1144 | |
| 1145 | return supported; |
| 1146 | } |
| 1147 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 1148 | bool RefLayerSupport::IsDebugSupported(const TensorInfo& input, |
| 1149 | const TensorInfo& output, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 1150 | Optional<std::string&> reasonIfUnsupported) const |
| 1151 | { |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1152 | bool supported = true; |
| 1153 | |
Narumol Prangnawarat | 403a185 | 2020-03-12 14:24:13 +0000 | [diff] [blame] | 1154 | std::array<DataType, 8> supportedTypes = |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1155 | { |
Narumol Prangnawarat | 403a185 | 2020-03-12 14:24:13 +0000 | [diff] [blame] | 1156 | DataType::BFloat16, |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 1157 | DataType::Float16, |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1158 | DataType::Float32, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 1159 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1160 | DataType::QAsymmU8, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1161 | DataType::QSymmS8, |
Narumol Prangnawarat | d2d917d | 2020-01-09 10:16:39 +0000 | [diff] [blame] | 1162 | DataType::QSymmS16, |
| 1163 | DataType::Signed32 |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1167 | "Reference for Debug layer: input type not supported"); |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1168 | |
| 1169 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1170 | "Reference for Debug layer: output type not supported"); |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1171 | |
| 1172 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1173 | "Reference for Debug layer: input and output types are mismatched"); |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 1174 | |
| 1175 | return supported; |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 1178 | bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input, |
| 1179 | const TensorInfo& output, |
| 1180 | const DepthToSpaceDescriptor& descriptor, |
| 1181 | Optional<std::string&> reasonIfUnsupported) const |
| 1182 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1183 | IgnoreUnused(descriptor); |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 1184 | bool supported = true; |
| 1185 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1186 | std::array<DataType,6> supportedTypes = |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 1187 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1188 | DataType::BFloat16, |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 1189 | DataType::Float32, |
| 1190 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1191 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1192 | DataType::QAsymmU8, |
| 1193 | DataType::QSymmS16 |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 1194 | }; |
| 1195 | |
| 1196 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1197 | "Reference DepthToSpace: input type not supported"); |
| 1198 | |
| 1199 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1200 | "Reference DepthToSpace: output type not supported"); |
| 1201 | |
| 1202 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1203 | "Reference DepthToSpace: input and output types are mismatched"); |
| 1204 | |
| 1205 | return supported; |
| 1206 | } |
| 1207 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1208 | bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 1209 | const TensorInfo& output, |
| 1210 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 1211 | const TensorInfo& weights, |
| 1212 | const Optional<TensorInfo>& biases, |
| 1213 | Optional<std::string&> reasonIfUnsupported) const |
| 1214 | { |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1215 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1216 | bool supported = true; |
| 1217 | |
| 1218 | // Define supported types. |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1219 | std::array<DataType,7> supportedTypes = |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1220 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1221 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1222 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 1223 | DataType::Float16, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 1224 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1225 | DataType::QAsymmU8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1226 | DataType::QSymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1227 | DataType::QSymmS16 |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1228 | }; |
| 1229 | |
| 1230 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1231 | "Reference DepthwiseConvolution2d: input is not a supported type."); |
| 1232 | |
| 1233 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1234 | "Reference DepthwiseConvolution2d: output is not a supported type."); |
| 1235 | |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1236 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1237 | "Reference DepthwiseConvolution2d: input and output types mismatched."); |
| 1238 | |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1239 | const DataType inputType = input.GetDataType(); |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 1240 | if (IsQuantized8BitType(inputType)) |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1241 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 1242 | std::array<DataType, 3> supportedWeightTypes = |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1243 | { |
| 1244 | DataType::QAsymmS8, |
| 1245 | DataType::QAsymmU8, |
| 1246 | DataType::QSymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1247 | }; |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1248 | |
| 1249 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1250 | "Reference DepthwiseConvolution2d: weights type not supported for " |
| 1251 | "quantized input."); |
Teresa Charlin | d8df026 | 2019-11-11 12:28:15 +0000 | [diff] [blame] | 1252 | } |
| 1253 | else |
| 1254 | { |
| 1255 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 1256 | "Reference DepthwiseConvolution2d: weights is not a supported type."); |
| 1257 | |
| 1258 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 1259 | "Reference DepthwiseConvolution2d: input and weights types mismatched."); |
| 1260 | } |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1261 | |
| 1262 | if (biases.has_value()) |
| 1263 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1264 | std::array<DataType,4> biasesSupportedTypes = |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1265 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1266 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1267 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 1268 | DataType::Float16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1269 | DataType::Signed32 |
| 1270 | }; |
| 1271 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 1272 | "Reference DepthwiseConvolution2d: biases is not a supported type."); |
| 1273 | } |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1274 | |
| 1275 | return supported; |
| 1276 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1277 | } |
| 1278 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 1279 | bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input, |
| 1280 | const TensorInfo& output, |
| 1281 | Optional<std::string&> reasonIfUnsupported) const |
| 1282 | { |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 1283 | bool supported = true; |
| 1284 | |
Ryan OShea | 9add120 | 2020-02-07 10:06:33 +0000 | [diff] [blame] | 1285 | std::array<DataType,4> supportedInputTypes = { |
| 1286 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1287 | DataType::QAsymmU8, |
Finn Williams | fd27106 | 2019-12-04 14:27:27 +0000 | [diff] [blame] | 1288 | DataType::QSymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1289 | DataType::QSymmS16 |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 1290 | }; |
| 1291 | |
| 1292 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1293 | "Reference for Dequantize layer: input type not supported."); |
| 1294 | |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 1295 | supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported, |
Teresa Charlin | 1b1950d | 2021-06-02 20:23:21 +0100 | [diff] [blame] | 1296 | "Reference for Dequantize layer: per-axis quantized input not supported."); |
Derek Lamberti | d466a54 | 2020-01-22 15:37:29 +0000 | [diff] [blame] | 1297 | |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1298 | std::array<DataType,3> supportedOutputTypes = { |
| 1299 | DataType::BFloat16, |
Jan Eilers | f710793 | 2019-11-01 11:09:36 +0000 | [diff] [blame] | 1300 | DataType::Float32, |
| 1301 | DataType::Float16 |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 1302 | }; |
| 1303 | |
| 1304 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1305 | "Reference for Dequantize layer: output type not supported."); |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 1306 | |
| 1307 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 1308 | "Reference for Dequantize layer: input/output shapes have different num total " |
| 1309 | "elements."); |
Nattapat Chaimanowong | afa4e3a | 2019-04-02 11:41:45 +0100 | [diff] [blame] | 1310 | |
| 1311 | return supported; |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 1314 | bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings, |
| 1315 | const TensorInfo& scores, |
| 1316 | const TensorInfo& anchors, |
| 1317 | const TensorInfo& detectionBoxes, |
| 1318 | const TensorInfo& detectionClasses, |
| 1319 | const TensorInfo& detectionScores, |
| 1320 | const TensorInfo& numDetections, |
| 1321 | const DetectionPostProcessDescriptor& descriptor, |
| 1322 | Optional<std::string&> reasonIfUnsupported) const |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1323 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1324 | IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor); |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 1325 | |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1326 | bool supported = true; |
| 1327 | |
Sadik Armagan | aa41d5d | 2020-11-16 14:27:52 +0000 | [diff] [blame] | 1328 | std::array<DataType,6> supportedInputTypes = |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1329 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1330 | DataType::BFloat16, |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1331 | DataType::Float32, |
Sadik Armagan | aa41d5d | 2020-11-16 14:27:52 +0000 | [diff] [blame] | 1332 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1333 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1334 | DataType::QAsymmU8, |
| 1335 | DataType::QSymmS16 |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1336 | }; |
| 1337 | |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 1338 | supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported, |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1339 | "Reference DetectionPostProcess: input 0 is not a supported type."); |
| 1340 | |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 1341 | supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported, |
Aron Virginas-Tar | a37e1bd | 2019-06-06 16:08:30 +0100 | [diff] [blame] | 1342 | "Reference DetectionPostProcess: input 1 is not a supported type."); |
| 1343 | |
| 1344 | return supported; |
Narumol Prangnawarat | bc67cef | 2019-01-31 15:31:54 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 1347 | bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 1348 | const TensorInfo& output, |
| 1349 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 1350 | const TensorInfo& weights, |
| 1351 | const Optional<TensorInfo>& biases, |
| 1352 | Optional<std::string&> reasonIfUnsupported) const |
| 1353 | { |
Aron Virginas-Tar | aece4ed | 2019-06-14 17:00:09 +0100 | [diff] [blame] | 1354 | return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported); |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 1355 | } |
| 1356 | |
Aron Virginas-Tar | aece4ed | 2019-06-14 17:00:09 +0100 | [diff] [blame] | 1357 | bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1358 | const TensorInfo& input1, |
| 1359 | const TensorInfo& output, |
| 1360 | Optional<std::string&> reasonIfUnsupported) const |
| 1361 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1362 | bool supported = true; |
| 1363 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 1364 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1365 | DataType::BFloat16, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1366 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 1367 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1368 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1369 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 1370 | DataType::QSymmS16, |
| 1371 | DataType::Signed32 |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1372 | }; |
| 1373 | |
| 1374 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1375 | "Reference division: input 0 is not a supported type."); |
| 1376 | |
| 1377 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1378 | "Reference division: input 1 is not a supported type."); |
| 1379 | |
| 1380 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1381 | "Reference division: output is not a supported type."); |
| 1382 | |
| 1383 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1384 | "Reference division: input 0 and Input 1 types are mismatched"); |
| 1385 | |
| 1386 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1387 | "Reference division: input and output types are mismatched"); |
| 1388 | |
| 1389 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1390 | "Reference division: shapes are not suitable for implicit broadcast."); |
| 1391 | |
| 1392 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1395 | bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input, |
| 1396 | const TensorInfo& output, |
| 1397 | const ElementwiseUnaryDescriptor& descriptor, |
| 1398 | Optional<std::string&> reasonIfUnsupported) const |
| 1399 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1400 | IgnoreUnused(descriptor); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1401 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1402 | std::array<DataType, 7> supportedTypes = |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1403 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1404 | DataType::BFloat16, |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1405 | DataType::Float32, |
| 1406 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1407 | DataType::QAsymmS8, |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1408 | DataType::QAsymmU8, |
Sadik Armagan | ac47210 | 2020-03-24 09:54:36 +0000 | [diff] [blame] | 1409 | DataType::QSymmS16, |
| 1410 | DataType::Signed32 |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1411 | }; |
| 1412 | |
Narumol Prangnawarat | 0c95f4c | 2020-11-18 16:52:07 +0000 | [diff] [blame] | 1413 | std::array<DataType, 1> logicalSupportedTypes = |
| 1414 | { |
| 1415 | DataType::Boolean |
| 1416 | }; |
| 1417 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1418 | bool supported = true; |
| 1419 | |
Narumol Prangnawarat | 0c95f4c | 2020-11-18 16:52:07 +0000 | [diff] [blame] | 1420 | if (descriptor.m_Operation == UnaryOperation::LogicalNot) |
| 1421 | { |
| 1422 | supported &= CheckSupportRule(TypeAnyOf(input, logicalSupportedTypes), reasonIfUnsupported, |
| 1423 | "Reference elementwise unary: input type not supported"); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1424 | |
Narumol Prangnawarat | 0c95f4c | 2020-11-18 16:52:07 +0000 | [diff] [blame] | 1425 | supported &= CheckSupportRule(TypeAnyOf(output, logicalSupportedTypes), reasonIfUnsupported, |
| 1426 | "Reference elementwise unary: output type not supported"); |
| 1427 | } |
| 1428 | else |
| 1429 | { |
| 1430 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1431 | "Reference elementwise unary: input type not supported"); |
| 1432 | |
| 1433 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1434 | "Reference elementwise unary: output type not supported"); |
| 1435 | } |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1436 | |
| 1437 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1438 | "Reference elementwise unary: input and output types not matching"); |
| 1439 | |
| 1440 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1441 | "Reference elementwise unary: input and output shapes" |
| 1442 | "have different number of total elements"); |
| 1443 | |
| 1444 | return supported; |
| 1445 | } |
| 1446 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1447 | bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input, |
| 1448 | const FakeQuantizationDescriptor& descriptor, |
| 1449 | Optional<std::string&> reasonIfUnsupported) const |
| 1450 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1451 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1452 | bool supported = true; |
| 1453 | |
| 1454 | std::array<DataType,1> supportedTypes = |
| 1455 | { |
| 1456 | DataType::Float32 |
| 1457 | }; |
| 1458 | |
| 1459 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1460 | "Reference fake quantization: input type not supported."); |
| 1461 | |
| 1462 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1463 | } |
| 1464 | |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1465 | bool RefLayerSupport::IsFillSupported(const TensorInfo& input, |
| 1466 | const TensorInfo& output, |
| 1467 | const FillDescriptor& descriptor, |
| 1468 | Optional<std::string&> reasonIfUnsupported) const |
| 1469 | { |
| 1470 | IgnoreUnused(descriptor); |
| 1471 | IgnoreUnused(output); |
| 1472 | |
| 1473 | bool supported = true; |
| 1474 | |
Sadik Armagan | a792a05 | 2020-06-23 16:22:23 +0100 | [diff] [blame] | 1475 | std::array<DataType,3> supportedTypes = |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1476 | { |
| 1477 | DataType::Float32, |
Sadik Armagan | a792a05 | 2020-06-23 16:22:23 +0100 | [diff] [blame] | 1478 | DataType::Float16, |
| 1479 | DataType::Signed32 |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1480 | }; |
| 1481 | |
Teresa Charlin | 4b10fef | 2020-07-29 09:36:41 +0100 | [diff] [blame] | 1482 | supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported, |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1483 | "Reference Fill: input type not supported."); |
| 1484 | |
Teresa Charlin | 4408850 | 2020-07-27 11:27:19 +0100 | [diff] [blame] | 1485 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1486 | "Reference Fill: output type not supported."); |
Ryan OShea | f4bfa6a | 2020-06-10 11:33:37 +0100 | [diff] [blame] | 1487 | return supported; |
| 1488 | } |
| 1489 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1490 | bool RefLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 1491 | const TensorInfo& output, |
| 1492 | Optional<std::string&> reasonIfUnsupported) const |
| 1493 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1494 | IgnoreUnused(output); |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1495 | bool supported = true; |
| 1496 | |
Francis Murtagh | e8ac133 | 2020-07-30 18:03:40 +0100 | [diff] [blame] | 1497 | std::array<DataType,3> supportedTypes = |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1498 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1499 | DataType::BFloat16, |
James Conroy | b40d710 | 2019-06-04 12:32:09 +0100 | [diff] [blame] | 1500 | DataType::Float32, |
Francis Murtagh | e8ac133 | 2020-07-30 18:03:40 +0100 | [diff] [blame] | 1501 | DataType::Float16 |
James Conroy | 83735b1 | 2019-05-30 16:36:59 +0100 | [diff] [blame] | 1502 | }; |
| 1503 | |
| 1504 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1505 | "Reference Floor: input type not supported."); |
| 1506 | |
| 1507 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1508 | "Reference Floor: output type not supported."); |
| 1509 | |
| 1510 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 1514 | const TensorInfo& output, |
| 1515 | const TensorInfo& weights, |
| 1516 | const TensorInfo& biases, |
| 1517 | const FullyConnectedDescriptor& descriptor, |
| 1518 | Optional<std::string&> reasonIfUnsupported) const |
| 1519 | { |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1520 | bool supported = true; |
| 1521 | |
| 1522 | // Define supported types. |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1523 | std::array<DataType,6> supportedTypes = |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1524 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1525 | DataType::BFloat16, |
| 1526 | DataType::Float32, |
| 1527 | DataType::Float16, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1528 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1529 | DataType::QAsymmU8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1530 | DataType::QSymmS16 |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1531 | }; |
| 1532 | |
| 1533 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1534 | "Reference Fully Connected: input type not supported."); |
| 1535 | |
| 1536 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1537 | "Reference Fully Connected: output type not supported."); |
| 1538 | |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1539 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 1540 | "Reference Fully Connected: weights type not supported."); |
| 1541 | |
Narumol Prangnawarat | 57ef008 | 2020-03-26 09:20:43 +0000 | [diff] [blame] | 1542 | // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization. |
| 1543 | if (input.GetDataType() == DataType::BFloat16) |
| 1544 | { |
| 1545 | if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32) |
| 1546 | { |
| 1547 | reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n"; |
| 1548 | supported = false; |
| 1549 | } |
| 1550 | } |
| 1551 | else |
| 1552 | { |
| 1553 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1554 | "Reference Fully Connected: input and output types mismatched."); |
| 1555 | } |
| 1556 | |
Jan Eilers | 1f45dc3 | 2020-06-15 11:43:03 +0100 | [diff] [blame] | 1557 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 1558 | "Reference Fully Connected: weights is not a supported type."); |
Francis Murtagh | ddb1d06 | 2020-03-10 13:51:45 +0000 | [diff] [blame] | 1559 | |
Jan Eilers | 1f45dc3 | 2020-06-15 11:43:03 +0100 | [diff] [blame] | 1560 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 1561 | "Reference Fully Connected: input and weights types mismatched."); |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1562 | |
| 1563 | if (descriptor.m_BiasEnabled) |
| 1564 | { |
| 1565 | // Defined supported types for bias |
Sadik Armagan | db73c98 | 2020-04-01 17:35:30 +0100 | [diff] [blame] | 1566 | std::array<DataType, 5> |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1567 | supportedBiasTypes = |
| 1568 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1569 | DataType::BFloat16, |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1570 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 1571 | DataType::Float16, |
Sadik Armagan | db73c98 | 2020-04-01 17:35:30 +0100 | [diff] [blame] | 1572 | DataType::Signed32, |
| 1573 | DataType::QAsymmS8 |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1574 | }; |
| 1575 | |
| 1576 | supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported, |
| 1577 | "Reference Fully Connected: bias type not supported."); |
| 1578 | |
| 1579 | supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported, |
| 1580 | "Reference Fully Connected: bias and weight types mismatch."); |
| 1581 | |
| 1582 | supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported, |
| 1583 | "Reference Fully Connected: bias type inferred from weights is incompatible."); |
| 1584 | |
Narumol Prangnawarat | 366d723 | 2020-04-29 12:58:17 +0100 | [diff] [blame] | 1585 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported, |
| 1586 | "Reference Fully Connected: bias must have 1 dimension."); |
| 1587 | |
Francis Murtagh | 46c09d0 | 2019-05-28 08:15:28 +0100 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1593 | bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0, |
| 1594 | const armnn::TensorInfo& input1, |
| 1595 | const armnn::TensorInfo& output, |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1596 | const GatherDescriptor& descriptor, |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1597 | armnn::Optional<std::string&> reasonIfUnsupported) const |
| 1598 | { |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 1599 | bool supported = true; |
Teresa Charlin | 3940d8b | 2020-05-29 16:47:23 +0100 | [diff] [blame] | 1600 | std::array<DataType,7> supportedTypes = |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 1601 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1602 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1603 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 1604 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1605 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1606 | DataType::QAsymmU8, |
Teresa Charlin | 3940d8b | 2020-05-29 16:47:23 +0100 | [diff] [blame] | 1607 | DataType::QSymmS16, |
| 1608 | DataType::Signed32 |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 1609 | }; |
| 1610 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 1611 | if (descriptor.m_Axis != 0) |
| 1612 | { |
| 1613 | reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n"); |
| 1614 | supported &= false; |
| 1615 | } |
Ellen Norris-Thompson | e0dbedf | 2019-06-24 09:23:38 +0100 | [diff] [blame] | 1616 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1617 | "Reference Gather: input type not supported"); |
| 1618 | |
| 1619 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1620 | "Reference Gather: output type not supported"); |
| 1621 | |
| 1622 | supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported, |
| 1623 | "Reference Gather: indices (input1) type not supported"); |
| 1624 | |
| 1625 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1626 | "Reference Gather: input and output types not matching"); |
| 1627 | |
| 1628 | return supported; |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 1631 | bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/, |
| 1632 | Optional<std::string&> /*reasonIfUnsupported*/) const |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1633 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 1634 | return true; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 1637 | bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input, |
| 1638 | const TensorInfo& output, |
| 1639 | const InstanceNormalizationDescriptor& descriptor, |
| 1640 | Optional<std::string&> reasonIfUnsupported) const |
| 1641 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1642 | IgnoreUnused(descriptor); |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 1643 | // Define supported types |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1644 | std::array<DataType, 3> supportedTypes = |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 1645 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1646 | DataType::BFloat16, |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 1647 | DataType::Float32, |
| 1648 | DataType::Float16 |
| 1649 | }; |
| 1650 | |
| 1651 | bool supported = true; |
| 1652 | |
| 1653 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1654 | "Reference Instance Normalization: input type not supported."); |
| 1655 | |
| 1656 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1657 | "Reference Instance Normalization: output type not supported."); |
| 1658 | |
| 1659 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1660 | "Reference Instance Normalization: input and output types mismatched."); |
| 1661 | |
| 1662 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1663 | "Reference Instance Normalization: input and output shapes have different " |
| 1664 | "num total elements."); |
| 1665 | |
| 1666 | return supported; |
| 1667 | } |
| 1668 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1669 | bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 1670 | const TensorInfo& output, |
| 1671 | const L2NormalizationDescriptor& descriptor, |
| 1672 | Optional<std::string&> reasonIfUnsupported) const |
| 1673 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1674 | IgnoreUnused(descriptor); |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1675 | // Define supported types |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1676 | std::array<DataType, 6> supportedTypes = |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1677 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1678 | DataType::BFloat16, |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1679 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 1680 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1681 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1682 | DataType::QAsymmU8, |
| 1683 | DataType::QSymmS16 |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 1684 | }; |
| 1685 | |
| 1686 | bool supported = true; |
| 1687 | |
| 1688 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1689 | "Reference L2normalization: input type not supported."); |
| 1690 | |
| 1691 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1692 | "Reference L2normalization: output type not supported."); |
| 1693 | |
| 1694 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1695 | "Reference L2normalization: input and output types mismatched."); |
| 1696 | |
| 1697 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 1698 | "Reference L2normalization: input and output shapes have different " |
| 1699 | "num total elements."); |
| 1700 | |
| 1701 | return supported; |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 1704 | bool RefLayerSupport::IsLogicalBinarySupported(const TensorInfo& input0, |
| 1705 | const TensorInfo& input1, |
| 1706 | const TensorInfo& output, |
| 1707 | const LogicalBinaryDescriptor& descriptor, |
| 1708 | Optional<std::string&> reasonIfUnsupported) const |
| 1709 | { |
| 1710 | IgnoreUnused(descriptor); |
| 1711 | |
| 1712 | std::array<DataType, 1> supportedTypes = |
| 1713 | { |
| 1714 | DataType::Boolean |
| 1715 | }; |
| 1716 | |
| 1717 | bool supported = true; |
| 1718 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1719 | "Reference LogicalBinary: input 0 type not supported"); |
| 1720 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1721 | "Reference LogicalBinary: input 1 type not supported"); |
| 1722 | |
| 1723 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1724 | "Reference LogicalBinary: input and output types do not match"); |
| 1725 | |
| 1726 | return supported; |
| 1727 | } |
| 1728 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 1729 | bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input, |
| 1730 | const TensorInfo& output, |
| 1731 | const LogSoftmaxDescriptor& descriptor, |
| 1732 | Optional<std::string&> reasonIfUnsupported) const |
| 1733 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1734 | IgnoreUnused(descriptor); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 1735 | |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1736 | std::array<DataType, 3> supportedTypes = |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 1737 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1738 | DataType::BFloat16, |
| 1739 | DataType::Float32, |
| 1740 | DataType::Float16 |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 1741 | }; |
| 1742 | |
| 1743 | bool supported = true; |
| 1744 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1745 | "Reference LogSoftmax: input type not supported"); |
| 1746 | |
| 1747 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1748 | "Reference LogSoftmax: output type not supported"); |
| 1749 | |
| 1750 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1751 | "Reference LogSoftmax: input and output types do not match"); |
| 1752 | |
| 1753 | return supported; |
| 1754 | } |
| 1755 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1756 | bool RefLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 1757 | const TensorInfo& outputStateIn, |
| 1758 | const TensorInfo& cellStateIn, |
| 1759 | const TensorInfo& scratchBuffer, |
| 1760 | const TensorInfo& outputStateOut, |
| 1761 | const TensorInfo& cellStateOut, |
| 1762 | const TensorInfo& output, |
| 1763 | const LstmDescriptor& descriptor, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1764 | const LstmInputParamsInfo& paramsInfo, |
| 1765 | Optional<std::string&> reasonIfUnsupported) const |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 1766 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 1767 | IgnoreUnused(descriptor); |
| 1768 | IgnoreUnused(paramsInfo); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1769 | |
| 1770 | bool supported = true; |
| 1771 | |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1772 | std::array<DataType,3> supportedTypes = { |
| 1773 | DataType::BFloat16, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1774 | DataType::Float32, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1775 | DataType::QSymmS16 |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1776 | }; |
| 1777 | |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1778 | // check inputs and outputs |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1779 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1780 | "Reference Lstm: input is not a supported type."); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1781 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported, |
| 1782 | "Reference Lstm: input and outputStateIn types are mismatched"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1783 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported, |
| 1784 | "Reference Lstm: input and cellStateIn types are mismatched"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1785 | supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported, |
| 1786 | "Reference Lstm: input and scratchBuffer types are mismatched"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1787 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported, |
| 1788 | "Reference Lstm: input and outputStateOut types are mismatched"); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1789 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported, |
| 1790 | "Reference Lstm: input and cellStateOut types are mismatched"); |
Narumol Prangnawarat | e5339e7 | 2021-07-28 17:33:28 +0100 | [diff] [blame] | 1791 | |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1792 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1793 | "Reference Lstm: input and output types are mismatched"); |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1794 | // check layer parameters |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1795 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1796 | "Reference Lstm: input and InputToForgetWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1797 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1798 | "Reference Lstm: input and InputToCellWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1799 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1800 | "Reference Lstm: input and InputToOutputWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1801 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1802 | "Reference Lstm: input and RecurrentToForgetWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1803 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1804 | "Reference Lstm: input and RecurrentToCellWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1805 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1806 | "Reference Lstm: input and RecurrentToOutputWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1807 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1808 | "Reference Lstm: input and ForgetGateBias types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1809 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1810 | "Reference Lstm: input and CellBias types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1811 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1812 | "Reference Lstm: input and OutputGateBias types are mismatched"); |
| 1813 | if (!descriptor.m_CifgEnabled) |
| 1814 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1815 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1816 | "Reference Lstm: input and InputToInputWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1817 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1818 | reasonIfUnsupported, |
| 1819 | "Reference Lstm: input and RecurrentToInputWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1820 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1821 | "Reference Lstm: input and InputGateBias types are mismatched"); |
| 1822 | if (descriptor.m_PeepholeEnabled) |
| 1823 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1824 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1825 | reasonIfUnsupported, |
| 1826 | "Reference Lstm: input and CellToInputWeights types are mismatched"); |
| 1827 | } |
| 1828 | } |
| 1829 | if (descriptor.m_PeepholeEnabled) |
| 1830 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1831 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1832 | "Reference Lstm: input and CellToForgetWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1833 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1834 | "Reference Lstm: input and CellToOutputWeights types are mismatched"); |
| 1835 | } |
| 1836 | if (descriptor.m_ProjectionEnabled) |
| 1837 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1838 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1839 | "Reference Lstm: input and mProjectionWeights types are mismatched"); |
| 1840 | if (paramsInfo.m_ProjectionBias != nullptr) |
| 1841 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1842 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1843 | "Reference Lstm: input and ProjectionBias types are mismatched"); |
| 1844 | } |
| 1845 | } |
| 1846 | if (descriptor.m_LayerNormEnabled) |
| 1847 | { |
| 1848 | if (!descriptor.m_CifgEnabled) |
| 1849 | { |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1850 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1851 | reasonIfUnsupported, |
| 1852 | "Reference Lstm: input and InputLayerNormWeights types are mismatched"); |
| 1853 | } |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1854 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1855 | reasonIfUnsupported, |
| 1856 | "Reference Lstm: input and ForgetLayerNormWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1857 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1858 | reasonIfUnsupported, |
| 1859 | "Reference Lstm: input and CellLayerNormWeights types are mismatched"); |
Francis Murtagh | bb590b4 | 2019-08-14 09:51:36 +0100 | [diff] [blame] | 1860 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()), |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 1861 | reasonIfUnsupported, |
| 1862 | "Reference Lstm: input and OutputLayerNormWeights types are mismatched"); |
| 1863 | } |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1864 | |
| 1865 | return supported; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1866 | } |
| 1867 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 1868 | bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 1869 | const TensorInfo& input1, |
| 1870 | const TensorInfo& output, |
| 1871 | Optional<std::string&> reasonIfUnsupported) const |
| 1872 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1873 | bool supported = true; |
| 1874 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 1875 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1876 | DataType::BFloat16, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1877 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 1878 | DataType::Float16, |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 1879 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1880 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 1881 | DataType::QSymmS16, |
| 1882 | DataType::Signed32 |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 1883 | }; |
| 1884 | |
| 1885 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 1886 | "Reference maximum: input 0 is not a supported type."); |
| 1887 | |
| 1888 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 1889 | "Reference maximum: input 1 is not a supported type."); |
| 1890 | |
| 1891 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1892 | "Reference maximum: output is not a supported type."); |
| 1893 | |
| 1894 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 1895 | "Reference maximum: input 0 and Input 1 types are mismatched"); |
| 1896 | |
| 1897 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 1898 | "Reference maximum: input and output types are mismatched"); |
| 1899 | |
| 1900 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 1901 | "Reference maximum: shapes are not suitable for implicit broadcast."); |
| 1902 | |
| 1903 | return supported; |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 1906 | bool RefLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 1907 | const TensorInfo& output, |
| 1908 | const MeanDescriptor& descriptor, |
| 1909 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1910 | { |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1911 | bool supported = true; |
| 1912 | std::string meanLayerStr = "Mean"; |
| 1913 | std::string outputTensorStr = "output"; |
| 1914 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1915 | std::array<DataType,6> supportedTypes = |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1916 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1917 | DataType::BFloat16, |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1918 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 1919 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1920 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1921 | DataType::QAsymmU8, |
| 1922 | DataType::QSymmS16 |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1923 | }; |
| 1924 | |
| 1925 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1926 | "Reference Mean: input type not supported."); |
| 1927 | |
| 1928 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1929 | "Reference Mean: input and output types are mismatched"); |
| 1930 | |
| 1931 | if (descriptor.m_KeepDims) |
| 1932 | { |
| 1933 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()), |
| 1934 | reasonIfUnsupported, |
| 1935 | CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(), |
| 1936 | output.GetNumDimensions(), |
| 1937 | meanLayerStr, outputTensorStr).data()); |
| 1938 | } |
| 1939 | else if (descriptor.m_Axis.empty()) |
| 1940 | { |
| 1941 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1), |
| 1942 | reasonIfUnsupported, |
| 1943 | CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(), |
| 1944 | meanLayerStr, outputTensorStr).data()); |
| 1945 | } |
| 1946 | else |
| 1947 | { |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 1948 | auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size()); |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1949 | |
| 1950 | if (outputDim > 0) |
| 1951 | { |
| 1952 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim), |
| 1953 | reasonIfUnsupported, |
| 1954 | CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(), |
| 1955 | meanLayerStr, outputTensorStr).data()); |
| 1956 | } |
| 1957 | else |
| 1958 | { |
| 1959 | supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1), |
| 1960 | reasonIfUnsupported, |
| 1961 | CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(), |
| 1962 | meanLayerStr, outputTensorStr).data()); |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | return supported; |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1969 | bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 1970 | const TensorInfo &output, |
| 1971 | Optional<std::string &> reasonIfUnsupported) const |
| 1972 | { |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1973 | bool supported = true; |
| 1974 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1975 | std::array<DataType,7> supportedTypes = |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1976 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 1977 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1978 | DataType::Float32, |
| 1979 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 1980 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 1981 | DataType::QAsymmU8, |
| 1982 | DataType::QSymmS16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 1983 | DataType::Boolean |
| 1984 | }; |
| 1985 | |
| 1986 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 1987 | "Reference MemCopy: input type not supported"); |
| 1988 | |
| 1989 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 1990 | "Reference MemCopy: output type not supported"); |
| 1991 | |
| 1992 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 1993 | "Reference MemCopy: input and output types are mismatched"); |
| 1994 | |
| 1995 | return supported; |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 1998 | bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 1999 | const TensorInfo& input1, |
| 2000 | const TensorInfo& output, |
| 2001 | Optional<std::string&> reasonIfUnsupported) const |
| 2002 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2003 | bool supported = true; |
| 2004 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2005 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2006 | DataType::BFloat16, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2007 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2008 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2009 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2010 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2011 | DataType::QSymmS16, |
| 2012 | DataType::Signed32 |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2013 | }; |
| 2014 | |
| 2015 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 2016 | "Reference minimum: input 0 is not a supported type."); |
| 2017 | |
| 2018 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 2019 | "Reference minimum: input 1 is not a supported type."); |
| 2020 | |
| 2021 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2022 | "Reference minimum: output is not a supported type."); |
| 2023 | |
| 2024 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 2025 | "Reference minimum: input 0 and Input 1 types are mismatched"); |
| 2026 | |
| 2027 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 2028 | "Reference minimum: input and output types are mismatched"); |
| 2029 | |
| 2030 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 2031 | "Reference minimum: shapes are not suitable for implicit broadcast."); |
| 2032 | |
| 2033 | return supported; |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2036 | bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 2037 | const TensorInfo& input1, |
| 2038 | const TensorInfo& output, |
| 2039 | Optional<std::string&> reasonIfUnsupported) const |
| 2040 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2041 | bool supported = true; |
| 2042 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2043 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2044 | DataType::BFloat16, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2045 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 2046 | DataType::Float16, |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 2047 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2048 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2049 | DataType::QSymmS16, |
| 2050 | DataType::Signed32 |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2051 | }; |
| 2052 | |
| 2053 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 2054 | "Reference multiplication: input 0 is not a supported type."); |
| 2055 | |
| 2056 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 2057 | "Reference multiplication: input 1 is not a supported type."); |
| 2058 | |
| 2059 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2060 | "Reference multiplication: output is not a supported type."); |
| 2061 | |
| 2062 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 2063 | "Reference multiplication: input 0 and Input 1 types are mismatched"); |
| 2064 | |
| 2065 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 2066 | "Reference multiplication: input and output types are mismatched"); |
| 2067 | |
| 2068 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 2069 | "Reference multiplication: shapes are not suitable for implicit broadcast."); |
| 2070 | |
| 2071 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 2075 | const TensorInfo& output, |
| 2076 | const NormalizationDescriptor& descriptor, |
| 2077 | Optional<std::string&> reasonIfUnsupported) const |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 2078 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2079 | IgnoreUnused(descriptor); |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 2080 | |
| 2081 | // Define supported types |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2082 | std::array<DataType, 6> supportedTypes = |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 2083 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2084 | DataType::BFloat16, |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 2085 | DataType::Float16, |
| 2086 | DataType::Float32, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2087 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2088 | DataType::QAsymmU8, |
| 2089 | DataType::QSymmS16 |
Matteo Martincigh | 2fc70c5 | 2019-06-05 14:12:48 +0100 | [diff] [blame] | 2090 | }; |
| 2091 | |
| 2092 | bool supported = true; |
| 2093 | |
| 2094 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2095 | "Reference normalization: input type not supported."); |
| 2096 | |
| 2097 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2098 | "Reference normalization: output type not supported."); |
| 2099 | |
| 2100 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 2101 | "Reference normalization: input and output shapes have different " |
| 2102 | "num total elements."); |
| 2103 | |
| 2104 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 2107 | bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/, |
| 2108 | Optional<std::string&> /*reasonIfUnsupported*/) const |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2109 | { |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 2110 | return true; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | bool RefLayerSupport::IsPadSupported(const TensorInfo& input, |
| 2114 | const TensorInfo& output, |
| 2115 | const PadDescriptor& descriptor, |
| 2116 | Optional<std::string&> reasonIfUnsupported) const |
| 2117 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2118 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | e6eaf66 | 2019-07-08 08:57:17 +0100 | [diff] [blame] | 2119 | bool supported = true; |
| 2120 | |
| 2121 | // Define supported output and inputs types. |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2122 | std::array<DataType,6> supportedTypes = |
Narumol Prangnawarat | e6eaf66 | 2019-07-08 08:57:17 +0100 | [diff] [blame] | 2123 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2124 | DataType::BFloat16, |
Narumol Prangnawarat | e6eaf66 | 2019-07-08 08:57:17 +0100 | [diff] [blame] | 2125 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 2126 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2127 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2128 | DataType::QAsymmU8, |
| 2129 | DataType::QSymmS16 |
Narumol Prangnawarat | e6eaf66 | 2019-07-08 08:57:17 +0100 | [diff] [blame] | 2130 | }; |
| 2131 | |
| 2132 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2133 | "Reference pad: input is not a supported type."); |
| 2134 | |
| 2135 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2136 | "Reference pad: output is not a supported type."); |
| 2137 | |
| 2138 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2139 | "Reference pad: input and output types are mismatched."); |
| 2140 | |
| 2141 | return supported; |
Nina Drozd | 661dfa7 | 2018-10-02 11:14:17 +0100 | [diff] [blame] | 2142 | } |
| 2143 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2144 | bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 2145 | const TensorInfo& output, |
| 2146 | const PermuteDescriptor& descriptor, |
| 2147 | Optional<std::string&> reasonIfUnsupported) const |
| 2148 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2149 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 2150 | bool supported = true; |
| 2151 | |
| 2152 | // Define supported output and inputs types. |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2153 | std::array<DataType, 6> supportedTypes = |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 2154 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2155 | DataType::BFloat16, |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 2156 | DataType::Float32, |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2157 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2158 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2159 | DataType::QAsymmU8, |
| 2160 | DataType::QSymmS16 |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 2161 | }; |
| 2162 | |
| 2163 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2164 | "Reference permute: input is not a supported type."); |
| 2165 | |
| 2166 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2167 | "Reference permute: output is not a supported type."); |
| 2168 | |
| 2169 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2170 | "Reference permute: input and output types are mismatched."); |
| 2171 | |
| 2172 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 2176 | const TensorInfo& output, |
| 2177 | const Pooling2dDescriptor& descriptor, |
| 2178 | Optional<std::string&> reasonIfUnsupported) const |
| 2179 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2180 | IgnoreUnused(descriptor); |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 2181 | bool supported = true; |
| 2182 | |
| 2183 | // Define supported output and inputs types. |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2184 | std::array<DataType,6> supportedTypes = |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 2185 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2186 | DataType::BFloat16, |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 2187 | DataType::Float32, |
Matthew Jackson | 252df3a | 2019-09-11 09:19:18 +0100 | [diff] [blame] | 2188 | DataType::Float16, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 2189 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2190 | DataType::QAsymmU8, |
| 2191 | DataType::QSymmS16 |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 2192 | }; |
| 2193 | |
| 2194 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2195 | "Reference poolind2d: input is not a supported type."); |
| 2196 | |
| 2197 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2198 | "Reference poolind2d: output is not a supported type."); |
| 2199 | |
| 2200 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2201 | "Reference poolind2d: input and output types are mismatched."); |
| 2202 | |
| 2203 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2204 | } |
| 2205 | |
Tamás Nyíri | 7b885b3 | 2021-10-26 14:47:57 +0100 | [diff] [blame] | 2206 | bool RefLayerSupport::IsPooling3dSupported(const TensorInfo& input, |
| 2207 | const TensorInfo& output, |
| 2208 | const Pooling3dDescriptor& descriptor, |
| 2209 | Optional<std::string&> reasonIfUnsupported) const |
| 2210 | { |
| 2211 | IgnoreUnused(descriptor); |
| 2212 | bool supported = true; |
| 2213 | |
| 2214 | // Define supported output and inputs types. |
| 2215 | std::array<DataType,6> supportedTypes = |
| 2216 | { |
| 2217 | DataType::BFloat16, |
| 2218 | DataType::Float32, |
| 2219 | DataType::Float16, |
| 2220 | DataType::QAsymmS8, |
| 2221 | DataType::QAsymmU8, |
| 2222 | DataType::QSymmS16 |
| 2223 | }; |
| 2224 | |
| 2225 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2226 | "Reference poolind3d: input is not a supported type."); |
| 2227 | |
| 2228 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2229 | "Reference poolind3d: output is not a supported type."); |
| 2230 | |
| 2231 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2232 | "Reference poolind3d: input and output types are mismatched."); |
| 2233 | |
| 2234 | return supported; |
| 2235 | } |
| 2236 | |
| 2237 | |
James Conroy | 4f1f899 | 2020-04-29 20:01:10 +0100 | [diff] [blame] | 2238 | bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input, |
| 2239 | const TensorInfo& previousOutputIn, |
| 2240 | const TensorInfo& previousCellStateIn, |
| 2241 | const TensorInfo& outputStateOut, |
| 2242 | const TensorInfo& cellStateOut, |
| 2243 | const TensorInfo& output, |
| 2244 | const QLstmDescriptor& descriptor, |
| 2245 | const LstmInputParamsInfo& paramsInfo, |
| 2246 | Optional<std::string&> reasonIfUnsupported) const |
| 2247 | { |
| 2248 | IgnoreUnused(input); |
| 2249 | IgnoreUnused(previousOutputIn); |
| 2250 | IgnoreUnused(previousCellStateIn); |
| 2251 | IgnoreUnused(outputStateOut); |
| 2252 | IgnoreUnused(cellStateOut); |
| 2253 | IgnoreUnused(output); |
| 2254 | IgnoreUnused(descriptor); |
| 2255 | IgnoreUnused(paramsInfo); |
| 2256 | |
| 2257 | IgnoreUnused(reasonIfUnsupported); |
| 2258 | |
| 2259 | return true; |
| 2260 | } |
| 2261 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2262 | bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input, |
| 2263 | const TensorInfo& output, |
| 2264 | Optional<std::string&> reasonIfUnsupported) const |
| 2265 | { |
| 2266 | bool supported = true; |
| 2267 | |
Finn Williams | fd27106 | 2019-12-04 14:27:27 +0000 | [diff] [blame] | 2268 | // Define supported input types. |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2269 | std::array<DataType,7> supportedInputTypes = { |
| 2270 | DataType::BFloat16, |
Keith Davis | 5e51cd8 | 2020-01-29 16:52:59 +0000 | [diff] [blame] | 2271 | DataType::Float32, |
Keith Davis | 3d8bc97 | 2020-02-04 09:31:47 +0000 | [diff] [blame] | 2272 | DataType::Float16, |
Ryan OShea | 9add120 | 2020-02-07 10:06:33 +0000 | [diff] [blame] | 2273 | DataType::QAsymmS8, |
Keith Davis | 5e51cd8 | 2020-01-29 16:52:59 +0000 | [diff] [blame] | 2274 | DataType::QAsymmU8, |
| 2275 | DataType::QSymmS8, |
| 2276 | DataType::QSymmS16 |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2277 | }; |
| 2278 | |
| 2279 | supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported, |
| 2280 | "Reference quantize: input type not supported."); |
| 2281 | |
| 2282 | // Define supported output types. |
Ryan OShea | 9add120 | 2020-02-07 10:06:33 +0000 | [diff] [blame] | 2283 | std::array<DataType,4> supportedOutputTypes = { |
Ryan OShea | 9add120 | 2020-02-07 10:06:33 +0000 | [diff] [blame] | 2284 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2285 | DataType::QAsymmU8, |
Finn Williams | fd27106 | 2019-12-04 14:27:27 +0000 | [diff] [blame] | 2286 | DataType::QSymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2287 | DataType::QSymmS16 |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 2288 | }; |
| 2289 | supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 2290 | "Reference quantize: output type not supported."); |
| 2291 | |
| 2292 | supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported, |
| 2293 | "Reference quantize: input and output shapes have different num total elements."); |
| 2294 | |
| 2295 | return supported; |
| 2296 | } |
| 2297 | |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 2298 | bool RefLayerSupport::IsRankSupported(const TensorInfo& input, |
| 2299 | const TensorInfo& output, |
| 2300 | Optional<std::string&> reasonIfUnsupported) const |
| 2301 | { |
| 2302 | IgnoreUnused(input); |
| 2303 | // Define supported output types. |
| 2304 | std::array<DataType,1> supportedOutputTypes = |
| 2305 | { |
| 2306 | DataType::Signed32, |
| 2307 | }; |
| 2308 | |
| 2309 | return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported, |
| 2310 | "Reference rank: input type not supported."); |
| 2311 | } |
| 2312 | |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 2313 | bool RefLayerSupport::IsReduceSupported(const TensorInfo& input, |
| 2314 | const TensorInfo& output, |
| 2315 | const ReduceDescriptor& descriptor, |
| 2316 | Optional<std::string&> reasonIfUnsupported) const |
| 2317 | { |
| 2318 | IgnoreUnused(descriptor); |
| 2319 | bool supported = true; |
| 2320 | std::array<DataType,7> supportedTypes = |
| 2321 | { |
| 2322 | DataType::BFloat16, |
| 2323 | DataType::Float32, |
| 2324 | DataType::Float16, |
| 2325 | DataType::QAsymmS8, |
| 2326 | DataType::QAsymmU8, |
| 2327 | DataType::QSymmS16, |
| 2328 | DataType::Signed32 |
| 2329 | }; |
| 2330 | |
| 2331 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2332 | "Reference Reduce: input type not supported"); |
| 2333 | |
| 2334 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2335 | "Reference Reduce: output type not supported"); |
| 2336 | |
| 2337 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2338 | "Reference Reduce: input and output types not matching"); |
| 2339 | |
| 2340 | return supported; |
| 2341 | } |
| 2342 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2343 | bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Kevin May | a023c40 | 2019-12-12 17:28:05 +0000 | [diff] [blame] | 2344 | const TensorInfo& output, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 2345 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2346 | Optional<std::string&> reasonIfUnsupported) const |
| 2347 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2348 | IgnoreUnused(output); |
| 2349 | IgnoreUnused(descriptor); |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 2350 | // Define supported output types. |
Narumol Prangnawarat | 0c95f4c | 2020-11-18 16:52:07 +0000 | [diff] [blame] | 2351 | std::array<DataType,8> supportedOutputTypes = |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 2352 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2353 | DataType::BFloat16, |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 2354 | DataType::Float32, |
| 2355 | DataType::Float16, |
Narumol Prangnawarat | 0718ee9 | 2019-09-13 16:53:38 +0100 | [diff] [blame] | 2356 | DataType::Signed32, |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 2357 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2358 | DataType::QAsymmU8, |
Narumol Prangnawarat | 0c95f4c | 2020-11-18 16:52:07 +0000 | [diff] [blame] | 2359 | DataType::QSymmS16, |
| 2360 | DataType::Boolean |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 2361 | }; |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 2362 | |
Nina Drozd | 2f2778f | 2019-05-27 10:37:05 +0100 | [diff] [blame] | 2363 | return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported, |
| 2364 | "Reference reshape: input type not supported."); |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2365 | } |
| 2366 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 2367 | bool RefLayerSupport::IsResizeSupported(const TensorInfo& input, |
| 2368 | const TensorInfo& output, |
| 2369 | const ResizeDescriptor& descriptor, |
| 2370 | Optional<std::string&> reasonIfUnsupported) const |
| 2371 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2372 | IgnoreUnused(descriptor); |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 2373 | bool supported = true; |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2374 | std::array<DataType,6> supportedTypes = |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 2375 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2376 | DataType::BFloat16, |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 2377 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2378 | DataType::Float16, |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 2379 | DataType::QAsymmS8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2380 | DataType::QAsymmU8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2381 | DataType::QSymmS16 |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 2382 | }; |
| 2383 | |
| 2384 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2385 | "Reference Resize: input type not supported"); |
| 2386 | |
| 2387 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2388 | "Reference Resize: output type not supported"); |
| 2389 | |
| 2390 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2391 | "Reference Resize: input and output types not matching"); |
| 2392 | |
| 2393 | return supported; |
| 2394 | } |
| 2395 | |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 2396 | bool RefLayerSupport::IsShapeSupported(const TensorInfo& input, |
| 2397 | const TensorInfo& output, |
| 2398 | Optional<std::string&> reasonIfUnsupported) const |
| 2399 | { |
| 2400 | IgnoreUnused(input); |
| 2401 | bool supported = true; |
| 2402 | |
| 2403 | std::array<DataType, 1> supportedTypes = |
| 2404 | { |
| 2405 | DataType::Signed32 |
| 2406 | }; |
| 2407 | |
| 2408 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2409 | "Reference Shape: output type not supported"); |
| 2410 | |
| 2411 | return supported; |
| 2412 | } |
| 2413 | |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2414 | bool RefLayerSupport::IsSliceSupported(const TensorInfo& input, |
| 2415 | const TensorInfo& output, |
| 2416 | const SliceDescriptor& descriptor, |
| 2417 | Optional<std::string&> reasonIfUnsupported) const |
| 2418 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2419 | IgnoreUnused(descriptor); |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2420 | bool supported = true; |
| 2421 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2422 | std::array<DataType, 5> supportedTypes = |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2423 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2424 | DataType::BFloat16, |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2425 | DataType::Float32, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2426 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2427 | DataType::QAsymmU8, |
| 2428 | DataType::QSymmS16 |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 2429 | }; |
| 2430 | |
| 2431 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2432 | "Reference Slice: input type not supported"); |
| 2433 | |
| 2434 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2435 | "Reference Slice: output type not supported"); |
| 2436 | |
| 2437 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2438 | "Reference Slice: input and output types are mismatched"); |
| 2439 | |
| 2440 | return supported; |
| 2441 | } |
| 2442 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2443 | bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 2444 | const TensorInfo& output, |
| 2445 | const SoftmaxDescriptor& descriptor, |
| 2446 | Optional<std::string&> reasonIfUnsupported) const |
| 2447 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2448 | IgnoreUnused(descriptor); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2449 | bool supported = true; |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2450 | std::array<DataType,7> supportedTypes = |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2451 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2452 | DataType::BFloat16, |
| 2453 | DataType::Float32, |
| 2454 | DataType::Float16, |
| 2455 | DataType::QSymmS8, |
| 2456 | DataType::QAsymmS8, |
| 2457 | DataType::QAsymmU8, |
| 2458 | DataType::QSymmS16 |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2459 | }; |
| 2460 | |
| 2461 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 2462 | "Reference Softmax: output type not supported"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2463 | |
| 2464 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 2465 | "Reference Softmax: input type not supported"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2466 | |
| 2467 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 2468 | "Reference Softmax: input type not supported"); |
nikraj01 | 248683f | 2019-05-29 16:46:50 +0100 | [diff] [blame] | 2469 | |
| 2470 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2471 | } |
| 2472 | |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 2473 | bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 2474 | const TensorInfo& output, |
| 2475 | const SpaceToBatchNdDescriptor& descriptor, |
| 2476 | Optional<std::string&> reasonIfUnsupported) const |
| 2477 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2478 | IgnoreUnused(descriptor); |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 2479 | bool supported = true; |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2480 | std::array<DataType,6> supportedTypes = |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 2481 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2482 | DataType::BFloat16, |
| 2483 | DataType::Float32, |
| 2484 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2485 | DataType::QAsymmS8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2486 | DataType::QAsymmU8, |
| 2487 | DataType::QSymmS16 |
nikraj01 | 120522a | 2019-05-31 11:33:07 +0100 | [diff] [blame] | 2488 | }; |
| 2489 | |
| 2490 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2491 | "Reference SpaceToBatchNd: input type not supported"); |
| 2492 | |
| 2493 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2494 | "Reference SpaceToBatchNd: output type not supported"); |
| 2495 | |
| 2496 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2497 | "Reference SpaceToBatchNd: input and output types are mismatched"); |
| 2498 | |
| 2499 | return supported; |
Nattapat Chaimanowong | 3ea76d5 | 2018-11-09 14:10:38 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2502 | bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input, |
Keith Davis | 5191033 | 2019-06-26 15:28:43 +0100 | [diff] [blame] | 2503 | const TensorInfo& output, |
| 2504 | const SpaceToDepthDescriptor& descriptor, |
| 2505 | Optional<std::string&> reasonIfUnsupported) const |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2506 | { |
| 2507 | |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2508 | IgnoreUnused(descriptor); |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2509 | bool supported = true; |
| 2510 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2511 | std::array<DataType,6> supportedTypes = |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2512 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2513 | DataType::BFloat16, |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2514 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2515 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2516 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2517 | DataType::QAsymmU8, |
| 2518 | DataType::QSymmS16 |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 2519 | }; |
| 2520 | |
| 2521 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2522 | "Reference SpaceToDepth: input type not supported"); |
| 2523 | |
| 2524 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2525 | "Reference SpaceToDepth: output type not supported"); |
| 2526 | |
| 2527 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2528 | "Reference SpaceToDepth: input and output types are mismatched"); |
| 2529 | |
| 2530 | return supported; |
| 2531 | } |
| 2532 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2533 | bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input, |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 2534 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 2535 | const ViewsDescriptor& descriptor, |
| 2536 | Optional<std::string&> reasonIfUnsupported) const |
| 2537 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2538 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2539 | bool supported = true; |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2540 | std::array<DataType,6> supportedTypes = |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2541 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2542 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2543 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2544 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2545 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2546 | DataType::QAsymmU8, |
| 2547 | DataType::QSymmS16 |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2548 | }; |
| 2549 | |
| 2550 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2551 | "Reference splitter: output type not supported"); |
Derek Lamberti | eac4adb | 2020-08-25 13:05:59 +0100 | [diff] [blame] | 2552 | for (const TensorInfo& output : outputs) |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2553 | { |
| 2554 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2555 | "Reference splitter: input type not supported"); |
| 2556 | |
| 2557 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2558 | "Reference splitter: input and output types mismatched."); |
| 2559 | } |
| 2560 | |
| 2561 | return supported; |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 2562 | } |
| 2563 | |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2564 | bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs, |
| 2565 | const TensorInfo& output, |
| 2566 | const StackDescriptor& descriptor, |
| 2567 | Optional<std::string&> reasonIfUnsupported) const |
| 2568 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2569 | IgnoreUnused(descriptor); |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2570 | |
| 2571 | bool supported = true; |
Sadik Armagan | 529195f | 2022-01-14 12:56:35 +0000 | [diff] [blame] | 2572 | std::array<DataType,7> supportedTypes = |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2573 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2574 | DataType::BFloat16, |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2575 | DataType::Float32, |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 2576 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2577 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2578 | DataType::QAsymmU8, |
Sadik Armagan | 529195f | 2022-01-14 12:56:35 +0000 | [diff] [blame] | 2579 | DataType::QSymmS16, |
| 2580 | DataType::Signed32 |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2581 | }; |
| 2582 | |
| 2583 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2584 | "Reference stack: output type not supported"); |
| 2585 | for (const TensorInfo* input : inputs) |
| 2586 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 2587 | ARMNN_ASSERT(input != nullptr); |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 2588 | supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported, |
| 2589 | "Reference stack: input type not supported"); |
| 2590 | |
| 2591 | supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported, |
| 2592 | "Reference stack: input and output types mismatched."); |
| 2593 | } |
| 2594 | |
| 2595 | return supported; |
| 2596 | } |
| 2597 | |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 2598 | bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 2599 | const TensorInfo& output, |
| 2600 | const StridedSliceDescriptor& descriptor, |
| 2601 | Optional<std::string&> reasonIfUnsupported) const |
| 2602 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2603 | IgnoreUnused(descriptor); |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2604 | bool supported = true; |
| 2605 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2606 | std::array<DataType,5> supportedTypes = |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2607 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2608 | DataType::BFloat16, |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2609 | DataType::Float32, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2610 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2611 | DataType::QAsymmU8, |
| 2612 | DataType::QSymmS16 |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 2613 | }; |
| 2614 | |
| 2615 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2616 | "Reference StridedSlice: input type not supported"); |
| 2617 | |
| 2618 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2619 | "Reference StridedSlice: output type not supported"); |
| 2620 | |
| 2621 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2622 | "Reference StridedSlice: input and output types are mismatched"); |
| 2623 | |
| 2624 | return supported; |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2627 | bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 2628 | const TensorInfo& input1, |
| 2629 | const TensorInfo& output, |
| 2630 | Optional<std::string&> reasonIfUnsupported) const |
| 2631 | { |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2632 | bool supported = true; |
| 2633 | |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2634 | std::array<DataType,7> supportedTypes = { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2635 | DataType::BFloat16, |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2636 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2637 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2638 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2639 | DataType::QAsymmU8, |
Teresa Charlin | ecb6b8e | 2020-05-22 18:08:23 +0100 | [diff] [blame] | 2640 | DataType::QSymmS16, |
| 2641 | DataType::Signed32 |
Sadik Armagan | 2999a02 | 2019-04-09 14:20:12 +0100 | [diff] [blame] | 2642 | }; |
| 2643 | |
| 2644 | supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported, |
| 2645 | "Reference subtraction: input 0 is not a supported type."); |
| 2646 | |
| 2647 | supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported, |
| 2648 | "Reference subtraction: input 1 is not a supported type."); |
| 2649 | |
| 2650 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2651 | "Reference subtraction: output is not a supported type."); |
| 2652 | |
| 2653 | supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported, |
| 2654 | "Reference subtraction: input 0 and Input 1 types are mismatched"); |
| 2655 | |
| 2656 | supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported, |
| 2657 | "Reference subtraction: input and output types are mismatched"); |
| 2658 | |
| 2659 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported, |
| 2660 | "Reference subtraction: shapes are not suitable for implicit broadcast."); |
| 2661 | |
| 2662 | return supported; |
Aron Virginas-Tar | b5acbb7 | 2018-10-15 11:11:51 +0100 | [diff] [blame] | 2663 | } |
| 2664 | |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2665 | bool RefLayerSupport::IsPreluSupported(const TensorInfo& input, |
| 2666 | const TensorInfo& alpha, |
| 2667 | const TensorInfo& output, |
| 2668 | Optional<std::string&> reasonIfUnsupported) const |
| 2669 | { |
| 2670 | bool supported = true; |
| 2671 | |
Teresa Charlin | 3940d8b | 2020-05-29 16:47:23 +0100 | [diff] [blame] | 2672 | std::array<DataType, 6> supportedTypes |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2673 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2674 | DataType::BFloat16, |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2675 | DataType::Float32, |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 2676 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2677 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2678 | DataType::QAsymmU8, |
Teresa Charlin | 3940d8b | 2020-05-29 16:47:23 +0100 | [diff] [blame] | 2679 | DataType::QSymmS16 |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 2680 | }; |
| 2681 | |
| 2682 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2683 | "PReLU: input is not a supported type."); |
| 2684 | |
| 2685 | supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported, |
| 2686 | "PReLU: alpha is not a supported type."); |
| 2687 | |
| 2688 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2689 | "PReLU: output is not a supported type."); |
| 2690 | |
| 2691 | supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported, |
| 2692 | "PReLU: input, alpha and output types are mismatched"); |
| 2693 | |
| 2694 | supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported, |
| 2695 | "PReLU: shapes are not suitable for implicit broadcast"); |
| 2696 | |
| 2697 | return supported; |
| 2698 | } |
| 2699 | |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2700 | bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input, |
| 2701 | const TensorInfo& output, |
| 2702 | const TransposeConvolution2dDescriptor& descriptor, |
| 2703 | const TensorInfo& weights, |
| 2704 | const Optional<TensorInfo>& biases, |
| 2705 | Optional<std::string&> reasonIfUnsupported) const |
| 2706 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2707 | IgnoreUnused(descriptor); |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2708 | bool supported = true; |
| 2709 | |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2710 | std::array<DataType,7> supportedTypes = |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2711 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2712 | DataType::BFloat16, |
| 2713 | DataType::Float32, |
| 2714 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2715 | DataType::QAsymmS8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2716 | DataType::QAsymmU8, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2717 | DataType::QSymmS8, |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2718 | DataType::QSymmS16 |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2719 | }; |
| 2720 | |
| 2721 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2722 | "Reference TransposeConvolution2d: input is not a supported type."); |
| 2723 | |
| 2724 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2725 | "Reference TransposeConvolution2d: output is not a supported type."); |
| 2726 | |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2727 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2728 | "Reference TransposeConvolution2d: input and output types mismatched."); |
| 2729 | |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2730 | |
| 2731 | const DataType inputType = input.GetDataType(); |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2732 | if (IsQuantized8BitType(inputType)) |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2733 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2734 | std::array<DataType, 3> supportedWeightTypes = |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2735 | { |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2736 | DataType::QAsymmS8, |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 2737 | DataType::QAsymmU8, |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 2738 | DataType::QSymmS8 |
Aron Virginas-Tar | 94d3b93 | 2019-11-11 12:54:47 +0000 | [diff] [blame] | 2739 | }; |
| 2740 | |
| 2741 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported, |
| 2742 | "Reference TransposeConvolution2d: weights type not supported for " |
| 2743 | "quantized input."); |
| 2744 | } |
| 2745 | else |
| 2746 | { |
| 2747 | supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, |
| 2748 | "Reference TransposeConvolution2d: weights is not a supported type."); |
| 2749 | |
| 2750 | supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, |
| 2751 | "Reference TransposeConvolution2d: input and weights types mismatched."); |
| 2752 | } |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2753 | |
| 2754 | if (biases.has_value()) |
| 2755 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2756 | std::array<DataType,4> biasesSupportedTypes = |
Aron Virginas-Tar | 651aafe | 2019-08-05 11:52:05 +0100 | [diff] [blame] | 2757 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2758 | DataType::BFloat16, |
| 2759 | DataType::Float32, |
| 2760 | DataType::Float16, |
| 2761 | DataType::Signed32 |
Aron Virginas-Tar | 98180ef | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 2762 | }; |
| 2763 | supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported, |
| 2764 | "Reference TransposeConvolution2d: biases is not a supported type."); |
| 2765 | } |
| 2766 | |
| 2767 | return supported; |
| 2768 | } |
| 2769 | |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2770 | bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input, |
| 2771 | const TensorInfo& output, |
| 2772 | const TransposeDescriptor& descriptor, |
| 2773 | Optional<std::string&> reasonIfUnsupported) const |
| 2774 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 2775 | IgnoreUnused(descriptor); |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2776 | bool supported = true; |
| 2777 | |
| 2778 | // Define supported output and inputs types. |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2779 | std::array<DataType, 6> supportedTypes = |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2780 | { |
Narumol Prangnawarat | 44179c3 | 2020-03-11 14:51:27 +0000 | [diff] [blame] | 2781 | DataType::BFloat16, |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2782 | DataType::Float32, |
| 2783 | DataType::Float16, |
Sadik Armagan | 303980c | 2020-04-17 12:45:14 +0100 | [diff] [blame] | 2784 | DataType::QAsymmS8, |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 2785 | DataType::QAsymmU8, |
| 2786 | DataType::QSymmS16 |
| 2787 | }; |
| 2788 | |
| 2789 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2790 | "Reference transpose: input is not a supported type."); |
| 2791 | |
| 2792 | supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, |
| 2793 | "Reference transpose: output is not a supported type."); |
| 2794 | |
| 2795 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2796 | "Reference transpose: input and output types are mismatched."); |
| 2797 | |
| 2798 | return supported; |
| 2799 | } |
| 2800 | |
Narumol Prangnawarat | e5339e7 | 2021-07-28 17:33:28 +0100 | [diff] [blame] | 2801 | bool RefLayerSupport::IsUnidirectionalSequenceLstmSupported( |
| 2802 | const TensorInfo& input, |
| 2803 | const TensorInfo& outputStateIn, |
| 2804 | const TensorInfo& cellStateIn, |
| 2805 | const TensorInfo& output, |
| 2806 | const Optional<TensorInfo>& hiddenStateOutput, |
| 2807 | const Optional<TensorInfo>& cellStateOutput, |
| 2808 | const UnidirectionalSequenceLstmDescriptor& descriptor, |
| 2809 | const LstmInputParamsInfo& paramsInfo, |
| 2810 | Optional<std::string&> reasonIfUnsupported) const |
| 2811 | { |
| 2812 | IgnoreUnused(descriptor); |
| 2813 | IgnoreUnused(paramsInfo); |
| 2814 | IgnoreUnused(outputStateIn); |
| 2815 | IgnoreUnused(cellStateIn); |
| 2816 | bool supported = true; |
| 2817 | |
| 2818 | if (hiddenStateOutput.has_value() || cellStateOutput.has_value()) |
| 2819 | { |
| 2820 | reasonIfUnsupported.value() += "Reference UnidirectionalSequenceLstm: hidden state output " |
| 2821 | "and cell state output are not supported at the moment."; |
| 2822 | } |
| 2823 | |
| 2824 | std::array<DataType, 1> supportedTypes = |
| 2825 | { |
| 2826 | DataType::Float32 |
| 2827 | }; |
| 2828 | |
Narumol Prangnawarat | bd575b2 | 2021-08-31 16:53:54 +0100 | [diff] [blame] | 2829 | std::array<DataType, 2> supportedWeightTypes = |
Narumol Prangnawarat | e5339e7 | 2021-07-28 17:33:28 +0100 | [diff] [blame] | 2830 | { |
Narumol Prangnawarat | bd575b2 | 2021-08-31 16:53:54 +0100 | [diff] [blame] | 2831 | DataType::Float32, |
| 2832 | DataType::QAsymmS8 |
Narumol Prangnawarat | e5339e7 | 2021-07-28 17:33:28 +0100 | [diff] [blame] | 2833 | }; |
| 2834 | |
| 2835 | // check inputs and outputs |
| 2836 | supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, |
| 2837 | "Reference UnidirectionalSequenceLstm: input is not a supported type."); |
| 2838 | supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported, |
| 2839 | "Reference UnidirectionalSequenceLstm: input and outputStateIn types are mismatched"); |
| 2840 | supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported, |
| 2841 | "Reference UnidirectionalSequenceLstm: input and cellStateIn types are mismatched"); |
| 2842 | |
| 2843 | supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, |
| 2844 | "Reference UnidirectionalSequenceLstm: input and output types are mismatched"); |
| 2845 | // check layer parameters |
| 2846 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetInputToForgetWeights(), supportedWeightTypes), |
| 2847 | reasonIfUnsupported, |
| 2848 | "Reference UnidirectionalSequenceLstm: InputToForgetWeights " |
| 2849 | "is not a supported type."); |
| 2850 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetInputToCellWeights(), supportedWeightTypes), |
| 2851 | reasonIfUnsupported, |
| 2852 | "Reference UnidirectionalSequenceLstm: InputToCellWeights is not a supported type."); |
| 2853 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetInputToOutputWeights(), supportedWeightTypes), |
| 2854 | reasonIfUnsupported, |
| 2855 | "Reference UnidirectionalSequenceLstm: InputToOutputWeights " |
| 2856 | "is not a supported type."); |
| 2857 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetRecurrentToForgetWeights(), supportedWeightTypes), |
| 2858 | reasonIfUnsupported, |
| 2859 | "Reference UnidirectionalSequenceLstm: RecurrentToForgetWeights " |
| 2860 | "is not a supported type."); |
| 2861 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetRecurrentToCellWeights(), supportedWeightTypes), |
| 2862 | reasonIfUnsupported, |
| 2863 | "Reference UnidirectionalSequenceLstm: RecurrentToCellWeights " |
| 2864 | "is not a supported type."); |
| 2865 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetRecurrentToOutputWeights(), supportedWeightTypes), |
| 2866 | reasonIfUnsupported, |
| 2867 | "Reference UnidirectionalSequenceLstm: RecurrentToOutputWeights " |
| 2868 | "is not a supported type."); |
| 2869 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported, |
| 2870 | "Reference UnidirectionalSequenceLstm: input and ForgetGateBias types " |
| 2871 | "are mismatched"); |
| 2872 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported, |
| 2873 | "Reference UnidirectionalSequenceLstm: input and CellBias types are mismatched"); |
| 2874 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported, |
| 2875 | "Reference UnidirectionalSequenceLstm: input and OutputGateBias types " |
| 2876 | "are mismatched"); |
| 2877 | if (!descriptor.m_CifgEnabled) |
| 2878 | { |
| 2879 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetInputToInputWeights(), supportedWeightTypes), |
| 2880 | reasonIfUnsupported, |
| 2881 | "Reference UnidirectionalSequenceLstm: InputToInputWeights " |
| 2882 | "is not a supported type."); |
| 2883 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetRecurrentToInputWeights(), supportedWeightTypes), |
| 2884 | reasonIfUnsupported, |
| 2885 | "Reference UnidirectionalSequenceLstm: RecurrentToInputWeights " |
| 2886 | "is not a supported type."); |
| 2887 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported, |
| 2888 | "Reference UnidirectionalSequenceLstm: input and InputGateBias types " |
| 2889 | "are mismatched"); |
| 2890 | if (descriptor.m_PeepholeEnabled) |
| 2891 | { |
| 2892 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetCellToInputWeights(), supportedWeightTypes), |
| 2893 | reasonIfUnsupported, |
| 2894 | "Reference UnidirectionalSequenceLstm: CellToInputWeights " |
| 2895 | "is not a supported type."); |
| 2896 | } |
| 2897 | } |
| 2898 | if (descriptor.m_PeepholeEnabled) |
| 2899 | { |
| 2900 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetCellToForgetWeights(), supportedWeightTypes), |
| 2901 | reasonIfUnsupported, |
| 2902 | "Reference UnidirectionalSequenceLstm: CellToForgetWeights " |
| 2903 | "is not a supported type."); |
| 2904 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetCellToOutputWeights(), supportedWeightTypes), |
| 2905 | reasonIfUnsupported, |
| 2906 | "Reference UnidirectionalSequenceLstm: CellToOutputWeights " |
| 2907 | "is not a supported type."); |
| 2908 | } |
| 2909 | if (descriptor.m_ProjectionEnabled) |
| 2910 | { |
| 2911 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetProjectionWeights(), supportedWeightTypes), |
| 2912 | reasonIfUnsupported, |
| 2913 | "Reference UnidirectionalSequenceLstm: ProjectionWeights " |
| 2914 | "is not a supported type."); |
| 2915 | if (paramsInfo.m_ProjectionBias != nullptr) |
| 2916 | { |
| 2917 | supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported, |
| 2918 | "Reference UnidirectionalSequenceLstm: input and ProjectionBias types " |
| 2919 | "are mismatched"); |
| 2920 | } |
| 2921 | } |
| 2922 | if (descriptor.m_LayerNormEnabled) |
| 2923 | { |
| 2924 | if (!descriptor.m_CifgEnabled) |
| 2925 | { |
| 2926 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetInputLayerNormWeights(), supportedWeightTypes), |
| 2927 | reasonIfUnsupported, |
| 2928 | "Reference UnidirectionalSequenceLstm: InputLayerNormWeights " |
| 2929 | "is not a supported type."); |
| 2930 | } |
| 2931 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetForgetLayerNormWeights(), supportedWeightTypes), |
| 2932 | reasonIfUnsupported, |
| 2933 | "Reference UnidirectionalSequenceLstm: ForgetLayerNormWeights " |
| 2934 | "is not a supported type."); |
| 2935 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetCellLayerNormWeights(), supportedWeightTypes), |
| 2936 | reasonIfUnsupported, |
| 2937 | "Reference UnidirectionalSequenceLstm: CellLayerNormWeights " |
| 2938 | "is not a supported type."); |
| 2939 | supported &= CheckSupportRule(TypeAnyOf(paramsInfo.GetOutputLayerNormWeights(), supportedWeightTypes), |
| 2940 | reasonIfUnsupported, |
| 2941 | "Reference UnidirectionalSequenceLstm: OutputLayerNormWeights " |
| 2942 | "is not a supported type."); |
| 2943 | } |
| 2944 | |
| 2945 | return supported; |
| 2946 | } |
| 2947 | |
arovir01 | 1c7c81b | 2018-10-08 11:34:28 +0100 | [diff] [blame] | 2948 | } // namespace armnn |