Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +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. |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 6 | #include <armnn/Deprecated.hpp> |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 7 | #include <armnn/Exceptions.hpp> |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 8 | #include <armnn/Types.hpp> |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 9 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 10 | #include <backendsCommon/LayerSupportBase.hpp> |
| 11 | |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 12 | #include <armnn/utility/IgnoreUnused.hpp> |
Cathal Corbett | 34b429c | 2021-12-24 12:24:40 +0000 | [diff] [blame] | 13 | #include <armnn/utility/PolymorphicDowncast.hpp> |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 14 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 15 | namespace |
| 16 | { |
| 17 | |
| 18 | bool DefaultLayerSupport(const char* func, |
| 19 | const char* file, |
| 20 | unsigned int line, |
| 21 | armnn::Optional<std::string&> reasonIfUnsupported) |
| 22 | { |
| 23 | // NOTE: We only need to return the reason if the optional parameter is not empty |
| 24 | if (reasonIfUnsupported) |
| 25 | { |
| 26 | std::stringstream message; |
| 27 | message << func << " is not implemented [" << file << ":" << line << "]"; |
| 28 | |
| 29 | reasonIfUnsupported.value() = message.str(); |
| 30 | } |
| 31 | |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | } // anonymous namespace |
| 36 | |
| 37 | namespace armnn |
| 38 | { |
| 39 | |
Cathal Corbett | 34b429c | 2021-12-24 12:24:40 +0000 | [diff] [blame] | 40 | bool LayerSupportBase::IsLayerSupported(const LayerType& type, |
| 41 | const std::vector<TensorInfo>& infos, |
| 42 | const BaseDescriptor& descriptor, |
| 43 | const Optional<LstmInputParamsInfo>&, |
| 44 | const Optional<QuantizedLstmInputParamsInfo>&, |
| 45 | Optional<std::string&> reasonIfUnsupported) const |
| 46 | { |
| 47 | switch(type) |
| 48 | { |
| 49 | case LayerType::MemCopy: |
| 50 | return IsMemCopySupported(infos[0], infos[1], reasonIfUnsupported); |
| 51 | case LayerType::MemImport: |
| 52 | return IsMemImportSupported(infos[0], infos[1], reasonIfUnsupported); |
| 53 | case LayerType::StandIn: |
| 54 | { |
| 55 | auto desc = *(PolymorphicDowncast<const StandInDescriptor*>(&descriptor)); |
| 56 | |
| 57 | if (infos.size() != (desc.m_NumInputs + desc.m_NumOutputs)) |
| 58 | { |
| 59 | throw InvalidArgumentException("Number of StandIn layer TensorInfos does not equal " |
| 60 | "the combined number of input and output slots assigned " |
| 61 | "to the StandIn descriptor"); |
| 62 | } |
| 63 | |
| 64 | std::vector<const TensorInfo*> inputInfos; |
| 65 | for (uint32_t i = 0; i < desc.m_NumInputs; i++) |
| 66 | { |
| 67 | inputInfos.push_back(&infos[i]); |
| 68 | } |
| 69 | std::vector<const TensorInfo*> outputInfos; |
| 70 | for (uint32_t i = desc.m_NumInputs; i < infos.size(); i++) |
| 71 | { |
| 72 | outputInfos.push_back(&infos[i]); |
| 73 | } |
| 74 | |
| 75 | return IsStandInSupported(inputInfos, |
| 76 | outputInfos, |
| 77 | desc, |
| 78 | reasonIfUnsupported); |
| 79 | } |
| 80 | default: |
| 81 | return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported); |
| 82 | } |
| 83 | } |
| 84 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 85 | bool LayerSupportBase::IsDetectionPostProcessSupported(const TensorInfo&, // boxEncodings |
| 86 | const TensorInfo&, // scores |
| 87 | const TensorInfo&, // anchors |
| 88 | const TensorInfo&, // detectionBoxes |
| 89 | const TensorInfo&, // detectionClasses |
| 90 | const TensorInfo&, // detectionScores |
| 91 | const TensorInfo&, // numDetections |
| 92 | const DetectionPostProcessDescriptor&, //descriptor |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 93 | Optional<std::string&> reasonIfUnsupported) const |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 94 | { |
| 95 | return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported); |
| 96 | } |
| 97 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 98 | bool LayerSupportBase::IsMemCopySupported(const armnn::TensorInfo&, // input |
| 99 | const armnn::TensorInfo&, // output |
| 100 | armnn::Optional<std::string &> ) const // reasonIfUnsupported |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 101 | { |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 102 | return true; |
| 103 | } |
| 104 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 105 | bool LayerSupportBase::IsMemImportSupported(const armnn::TensorInfo&, // input |
| 106 | const armnn::TensorInfo&, // output |
| 107 | armnn::Optional<std::string &> ) const // reasonIfUnsupported |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 108 | { |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 109 | return true; |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 112 | bool LayerSupportBase::IsMergeSupported(const TensorInfo&, // input0 |
| 113 | const TensorInfo&, // input1 |
| 114 | const TensorInfo&, // output |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 115 | Optional<std::string&> reasonIfUnsupported) const |
| 116 | { |
| 117 | return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported); |
| 118 | } |
| 119 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 120 | bool LayerSupportBase::IsQuantizedLstmSupported(const TensorInfo&, // input |
| 121 | const TensorInfo&, // previousCellStateIn |
| 122 | const TensorInfo&, // previousOutputIn |
| 123 | const TensorInfo&, // cellStateOut |
| 124 | const TensorInfo&, // output |
| 125 | const QuantizedLstmInputParamsInfo&, // paramsInfo |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 126 | Optional<std::string&> reasonIfUnsupported) const |
| 127 | { |
| 128 | return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported); |
| 129 | } |
| 130 | |
Keith Davis | 3ae3f97 | 2021-05-21 16:33:48 +0100 | [diff] [blame] | 131 | bool LayerSupportBase::IsShapeSupported(const TensorInfo&, // input |
| 132 | const TensorInfo&, // output |
| 133 | Optional<std::string&> reasonIfUnsupported) const |
| 134 | { |
| 135 | return DefaultLayerSupport(__func__, __FILE__, __LINE__, reasonIfUnsupported); |
| 136 | } |
| 137 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 138 | bool LayerSupportBase::IsStandInSupported(const std::vector<const TensorInfo*>&, // inputs |
| 139 | const std::vector<const TensorInfo*>&, // outputs |
| 140 | const StandInDescriptor&, // descriptor |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 141 | Optional<std::string&> reasonIfUnsupported) const |
| 142 | { |
| 143 | if (reasonIfUnsupported) |
| 144 | { |
| 145 | std::stringstream message; |
| 146 | message << "StandIn layer is not executable via backends"; |
| 147 | |
| 148 | reasonIfUnsupported.value() = message.str(); |
| 149 | } |
| 150 | |
| 151 | return false; |
| 152 | } |
| 153 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 154 | } // namespace armnn |