arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ClBackend.hpp" |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 7 | #include "ClBackendId.hpp" |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 8 | #include "ClBackendModelContext.hpp" |
arovir01 | a094479 | 2018-10-11 15:00:58 +0100 | [diff] [blame] | 9 | #include "ClWorkloadFactory.hpp" |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 10 | #include "ClBackendContext.hpp" |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 11 | #include "ClLayerSupport.hpp" |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 12 | #include "ClTensorHandleFactory.hpp" |
arovir01 | a094479 | 2018-10-11 15:00:58 +0100 | [diff] [blame] | 13 | |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 14 | #include <armnn/BackendRegistry.hpp> |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 15 | #include <armnn/Descriptors.hpp> |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 16 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 17 | #include <aclCommon/ArmComputeSubgraphUtils.hpp> |
| 18 | #include <aclCommon/ArmComputeUtils.hpp> |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 19 | #include <aclCommon/BaseMemoryManager.hpp> |
| 20 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 21 | #include <armnn/backends/IBackendContext.hpp> |
| 22 | #include <armnn/backends/IMemoryManager.hpp> |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 23 | #include <armnn/utility/PolymorphicDowncast.hpp> |
| 24 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 25 | #include "workloads/ClAdditionWorkload.hpp" |
| 26 | #include "workloads/ClBatchNormalizationFloatWorkload.hpp" |
| 27 | #include "workloads/ClConvolution2dWorkload.hpp" |
| 28 | #include "workloads/ClDepthwiseConvolutionWorkload.hpp" |
| 29 | #include "workloads/ClDivisionFloatWorkload.hpp" |
| 30 | #include "workloads/ClFullyConnectedWorkload.hpp" |
| 31 | #include "workloads/ClMultiplicationWorkload.hpp" |
| 32 | #include "workloads/ClSubtractionWorkload.hpp" |
| 33 | |
David Beck | 263e349 | 2018-11-09 14:46:40 +0000 | [diff] [blame] | 34 | #include <Optimizer.hpp> |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 35 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 36 | #include <arm_compute/core/Types.h> |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 37 | #include <arm_compute/runtime/CL/CLBufferAllocator.h> |
| 38 | |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 39 | namespace armnn |
| 40 | { |
| 41 | |
David Beck | 3cc9a62 | 2018-10-12 10:38:31 +0100 | [diff] [blame] | 42 | const BackendId& ClBackend::GetIdStatic() |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 43 | { |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 44 | static const BackendId s_Id{ClBackendId()}; |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 45 | return s_Id; |
| 46 | } |
| 47 | |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 48 | IBackendInternal::IMemoryManagerUniquePtr ClBackend::CreateMemoryManager() const |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 49 | { |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 50 | return std::make_unique<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>()); |
| 51 | } |
| 52 | |
| 53 | IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory( |
| 54 | const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const |
| 55 | { |
| 56 | return std::make_unique<ClWorkloadFactory>( |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 57 | PolymorphicPointerDowncast<ClMemoryManager>(memoryManager)); |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 60 | IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory( |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 61 | const IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const ModelOptions& modelOptions) const |
| 62 | { |
| 63 | return std::make_unique<ClWorkloadFactory>( |
| 64 | PolymorphicPointerDowncast<ClMemoryManager>(memoryManager), CreateBackendSpecificModelContext(modelOptions)); |
| 65 | } |
| 66 | |
| 67 | IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory( |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 68 | TensorHandleFactoryRegistry& registry) const |
| 69 | { |
| 70 | auto memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>()); |
| 71 | |
| 72 | registry.RegisterMemoryManager(memoryManager); |
Narumol Prangnawarat | 549cb7a | 2020-07-10 17:50:53 +0100 | [diff] [blame] | 73 | registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager)); |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 74 | |
| 75 | return std::make_unique<ClWorkloadFactory>( |
Jan Eilers | 3c9e045 | 2020-04-10 13:00:44 +0100 | [diff] [blame] | 76 | PolymorphicPointerDowncast<ClMemoryManager>(memoryManager)); |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Sadik Armagan | 04a7297 | 2020-09-14 15:44:18 +0100 | [diff] [blame] | 79 | IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory( |
| 80 | TensorHandleFactoryRegistry& registry, const ModelOptions& modelOptions) const |
| 81 | { |
| 82 | auto memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>()); |
| 83 | |
| 84 | registry.RegisterMemoryManager(memoryManager); |
| 85 | registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager)); |
| 86 | |
| 87 | return std::make_unique<ClWorkloadFactory>( |
| 88 | PolymorphicPointerDowncast<ClMemoryManager>(memoryManager), CreateBackendSpecificModelContext(modelOptions)); |
| 89 | } |
| 90 | |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 91 | std::vector<ITensorHandleFactory::FactoryId> ClBackend::GetHandleFactoryPreferences() const |
| 92 | { |
| 93 | return std::vector<ITensorHandleFactory::FactoryId> {ClTensorHandleFactory::GetIdStatic()}; |
| 94 | } |
| 95 | |
| 96 | void ClBackend::RegisterTensorHandleFactories(TensorHandleFactoryRegistry& registry) |
| 97 | { |
| 98 | auto mgr = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>()); |
| 99 | |
| 100 | registry.RegisterMemoryManager(mgr); |
| 101 | registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(mgr)); |
| 102 | } |
| 103 | |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 104 | IBackendInternal::IBackendContextPtr ClBackend::CreateBackendContext(const IRuntime::CreationOptions& options) const |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 105 | { |
| 106 | return IBackendContextPtr{new ClBackendContext{options}}; |
| 107 | } |
| 108 | |
Colm Donelan | e49755b | 2020-01-29 15:22:43 +0000 | [diff] [blame] | 109 | IBackendInternal::IBackendProfilingContextPtr ClBackend::CreateBackendProfilingContext( |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 110 | const IRuntime::CreationOptions&, IBackendProfilingPtr&) |
Colm Donelan | e49755b | 2020-01-29 15:22:43 +0000 | [diff] [blame] | 111 | { |
| 112 | return IBackendProfilingContextPtr{}; |
| 113 | } |
| 114 | |
David Beck | 263e349 | 2018-11-09 14:46:40 +0000 | [diff] [blame] | 115 | IBackendInternal::Optimizations ClBackend::GetOptimizations() const |
| 116 | { |
| 117 | return Optimizations{}; |
| 118 | } |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 119 | |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 120 | IBackendInternal::IBackendSpecificModelContextPtr ClBackend::CreateBackendSpecificModelContext( |
| 121 | const ModelOptions& modelOptions) const |
| 122 | { |
| 123 | return IBackendSpecificModelContextPtr{new ClBackendModelContext{modelOptions}}; |
| 124 | } |
| 125 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 126 | IBackendInternal::ILayerSupportSharedPtr ClBackend::GetLayerSupport() const |
| 127 | { |
Sadik Armagan | 045f6be | 2020-09-10 13:37:32 +0100 | [diff] [blame] | 128 | static ILayerSupportSharedPtr layerSupport |
| 129 | { |
| 130 | new ClLayerSupport(IBackendInternal::IBackendSpecificModelContextPtr{}) |
| 131 | }; |
| 132 | return layerSupport; |
| 133 | } |
| 134 | |
| 135 | IBackendInternal::ILayerSupportSharedPtr ClBackend::GetLayerSupport(const ModelOptions& modelOptions) const |
| 136 | { |
| 137 | static ILayerSupportSharedPtr layerSupport |
| 138 | { |
| 139 | new ClLayerSupport(CreateBackendSpecificModelContext(modelOptions)) |
| 140 | }; |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 141 | return layerSupport; |
| 142 | } |
| 143 | |
Sadik Armagan | aede8ca | 2021-03-31 16:12:13 +0100 | [diff] [blame^] | 144 | bool ClBackend::HasCapability(BackendCapability capabilityClass) const |
| 145 | { |
| 146 | auto search = gpuAccCapabilities.find(capabilityClass); |
| 147 | if (search != gpuAccCapabilities.end()) |
| 148 | { |
| 149 | return true; |
| 150 | } |
| 151 | return false; |
| 152 | } |
| 153 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 154 | OptimizationViews ClBackend::OptimizeSubgraphView(const SubgraphView& subgraph, |
| 155 | const ModelOptions& modelOptions) const |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 156 | { |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 157 | OptimizationViews optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 158 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 159 | auto it = subgraph.end(); |
| 160 | bool isFastMathEnabled = false; |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 161 | std::map<LayerGuid, Layer*> untouched; |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 162 | |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 163 | while (it != subgraph.begin()) |
| 164 | { |
| 165 | --it; |
| 166 | Layer& base = **it; |
| 167 | untouched.insert({base.GetGuid(), &base}); |
| 168 | } |
| 169 | |
| 170 | it = subgraph.end(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 171 | #if defined(ARMCOMPUTECL_ENABLED) |
| 172 | IBackendInternal::IBackendSpecificModelContextPtr modelContextPtr = CreateBackendSpecificModelContext(modelOptions); |
| 173 | |
| 174 | if (modelContextPtr) |
| 175 | { |
| 176 | auto clModelOptions = dynamic_cast<ClBackendModelContext*>(modelContextPtr.get()); |
| 177 | if (clModelOptions) |
| 178 | { |
| 179 | isFastMathEnabled = clModelOptions->IsFastMathEnabled(); |
| 180 | } |
| 181 | } |
| 182 | #endif |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 183 | while (it != subgraph.begin()) |
| 184 | { |
| 185 | --it; |
| 186 | Layer& base = **it; |
| 187 | |
| 188 | if ((base.GetType() == LayerType::DepthwiseConvolution2d || base.GetType() == LayerType::Convolution2d |
| 189 | || base.GetType() == LayerType::BatchNormalization || base.GetType() == LayerType::FullyConnected |
| 190 | || base.GetType() == LayerType::Addition || base.GetType() == LayerType::Multiplication |
| 191 | || base.GetType() == LayerType::Subtraction || base.GetType() == LayerType::Division) |
| 192 | && (base.GetAdditionalInformation<ActivationDescriptor>() == nullptr)) |
| 193 | { |
| 194 | for (auto output = base.BeginOutputSlots(); output != base.EndOutputSlots(); ++output) |
| 195 | { |
| 196 | if (output->GetNumConnections() == 1) |
| 197 | { |
| 198 | for (auto&& childInput : output->GetConnections()) |
| 199 | { |
Teresa Charlin | d672f5d | 2021-01-18 18:07:57 +0000 | [diff] [blame] | 200 | if ((childInput->GetOwningLayer().GetType() == LayerType::Activation) && |
| 201 | (checkDataTypeInputandOutput(childInput->GetOwningLayer()))) |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 202 | { |
| 203 | Layer& child = childInput->GetOwningLayer(); |
| 204 | |
| 205 | auto* activationLayer = PolymorphicDowncast<ActivationLayer*>(&child); |
| 206 | |
| 207 | const std::string name = std::string("fused-") + child.GetName() + std::string("-into-") + |
| 208 | base.GetName(); |
| 209 | |
| 210 | // Get params from activation layer |
| 211 | ActivationDescriptor activationDesc = activationLayer->GetParameters(); |
| 212 | |
| 213 | if (base.GetType() == LayerType::Convolution2d) |
| 214 | { |
| 215 | Convolution2dLayer* baseLayer = PolymorphicDowncast<Convolution2dLayer*>(&base); |
| 216 | |
| 217 | Optional<TensorInfo> biases; |
| 218 | |
| 219 | if (baseLayer->GetParameters().m_BiasEnabled) |
| 220 | { |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 221 | biases = baseLayer->m_Bias->GetTensorInfo(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | arm_compute::Status status = ClConvolution2dWorkloadValidate( |
| 225 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 226 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 227 | baseLayer->GetParameters(), |
| 228 | baseLayer->m_Weight->GetTensorInfo(), |
| 229 | biases, |
| 230 | isFastMathEnabled, |
| 231 | &activationDesc); |
| 232 | |
| 233 | if (status) |
| 234 | { |
| 235 | FuseLayerWithWeightsAndBiases<Convolution2dLayer>(optimizationViews, |
| 236 | baseLayer, |
| 237 | activationLayer, |
| 238 | activationDesc, |
| 239 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 240 | untouched.erase(baseLayer->GetGuid()); |
| 241 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | else if (base.GetType() == LayerType::DepthwiseConvolution2d) |
| 245 | { |
| 246 | DepthwiseConvolution2dLayer* baseLayer = |
| 247 | PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&base); |
| 248 | |
| 249 | Optional<TensorInfo> biases; |
| 250 | |
| 251 | if (baseLayer->GetParameters().m_BiasEnabled) |
| 252 | { |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 253 | biases = baseLayer->m_Bias->GetTensorInfo(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | arm_compute::Status status = ClDepthwiseConvolutionWorkloadValidate( |
| 257 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 258 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 259 | baseLayer->GetParameters(), |
| 260 | baseLayer->m_Weight->GetTensorInfo(), |
| 261 | biases, |
| 262 | &activationDesc); |
| 263 | |
| 264 | if (status) |
| 265 | { |
| 266 | FuseLayerWithWeightsAndBiases<DepthwiseConvolution2dLayer>(optimizationViews, |
| 267 | baseLayer, |
| 268 | activationLayer, |
| 269 | activationDesc, |
| 270 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 271 | untouched.erase(baseLayer->GetGuid()); |
| 272 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | else if (base.GetType() == LayerType::FullyConnected) |
| 276 | { |
| 277 | FullyConnectedLayer* baseLayer = PolymorphicDowncast<FullyConnectedLayer*>(&base); |
| 278 | |
| 279 | arm_compute::Status status = ClFullyConnectedWorkloadValidate( |
| 280 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 281 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 282 | baseLayer->m_Weight->GetTensorInfo(), |
| 283 | baseLayer->m_Bias->GetTensorInfo(), |
| 284 | baseLayer->GetParameters(), |
| 285 | &activationDesc); |
| 286 | |
| 287 | if (status) |
| 288 | { |
| 289 | FuseLayerWithWeightsAndBiases<FullyConnectedLayer>(optimizationViews, |
| 290 | baseLayer, |
| 291 | activationLayer, |
| 292 | activationDesc, |
| 293 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 294 | untouched.erase(baseLayer->GetGuid()); |
| 295 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | else if (base.GetType() == LayerType::BatchNormalization) |
| 299 | { |
| 300 | BatchNormalizationLayer* baseLayer = |
| 301 | PolymorphicDowncast<BatchNormalizationLayer*>(&base); |
| 302 | |
| 303 | arm_compute::Status status = ClBatchNormalizationValidate( |
| 304 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 305 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 306 | baseLayer->m_Mean->GetTensorInfo(), |
| 307 | baseLayer->m_Variance->GetTensorInfo(), |
| 308 | baseLayer->m_Beta->GetTensorInfo(), |
| 309 | baseLayer->m_Gamma->GetTensorInfo(), |
| 310 | baseLayer->GetParameters(), |
| 311 | &activationDesc); |
| 312 | |
| 313 | if (status) |
| 314 | { |
| 315 | BatchNormalizationLayer* replacementLayer = |
| 316 | FuseLayerWithParameters<BatchNormalizationLayer>(optimizationViews, |
| 317 | baseLayer, |
| 318 | activationLayer, |
| 319 | activationDesc, |
| 320 | name); |
| 321 | |
| 322 | replacementLayer->m_Beta = std::move(baseLayer->m_Beta); |
| 323 | replacementLayer->m_Gamma = std::move(baseLayer->m_Gamma); |
| 324 | replacementLayer->m_Mean = std::move(baseLayer->m_Mean); |
| 325 | replacementLayer->m_Variance = std::move(baseLayer->m_Variance); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 326 | untouched.erase(baseLayer->GetGuid()); |
| 327 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | else if (base.GetType() == LayerType::Addition) |
| 331 | { |
| 332 | AdditionLayer* baseLayer = PolymorphicDowncast<AdditionLayer*>(&base); |
| 333 | |
| 334 | arm_compute::Status status = ClAdditionValidate( |
| 335 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 336 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 337 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 338 | &activationDesc); |
| 339 | |
| 340 | if (status) |
| 341 | { |
| 342 | FuseLayerWithoutParameters<AdditionLayer>(optimizationViews, |
| 343 | baseLayer, |
| 344 | activationLayer, |
| 345 | activationDesc, |
| 346 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 347 | untouched.erase(baseLayer->GetGuid()); |
| 348 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | else if (base.GetType() == LayerType::Division) |
| 352 | { |
| 353 | DivisionLayer* baseLayer = PolymorphicDowncast<DivisionLayer*>(&base); |
| 354 | |
| 355 | arm_compute::Status status = ClDivisionWorkloadValidate( |
| 356 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 357 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 358 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 359 | &activationDesc); |
| 360 | |
| 361 | if (status) |
| 362 | { |
| 363 | FuseLayerWithoutParameters<DivisionLayer>(optimizationViews, |
| 364 | baseLayer, |
| 365 | activationLayer, |
| 366 | activationDesc, |
| 367 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 368 | untouched.erase(baseLayer->GetGuid()); |
| 369 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | else if (base.GetType() == LayerType::Multiplication) |
| 373 | { |
| 374 | MultiplicationLayer* baseLayer = PolymorphicDowncast<MultiplicationLayer*>(&base); |
| 375 | |
| 376 | arm_compute::Status status = ClMultiplicationWorkloadValidate( |
| 377 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 378 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 379 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 380 | &activationDesc); |
| 381 | |
| 382 | if (status) |
| 383 | { |
| 384 | FuseLayerWithoutParameters<MultiplicationLayer>(optimizationViews, |
| 385 | baseLayer, |
| 386 | activationLayer, |
| 387 | activationDesc, |
| 388 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 389 | untouched.erase(baseLayer->GetGuid()); |
| 390 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | else if (base.GetType() == LayerType::Subtraction) |
| 394 | { |
| 395 | SubtractionLayer* baseLayer = PolymorphicDowncast<SubtractionLayer*>(&base); |
| 396 | |
| 397 | arm_compute::Status status = ClSubtractionValidate( |
| 398 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 399 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 400 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 401 | &activationDesc); |
| 402 | |
| 403 | if (status) |
| 404 | { |
| 405 | FuseLayerWithoutParameters<SubtractionLayer>(optimizationViews, |
| 406 | baseLayer, |
| 407 | activationLayer, |
| 408 | activationDesc, |
| 409 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 410 | untouched.erase(baseLayer->GetGuid()); |
| 411 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 420 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 421 | if (optimizationViews.GetSubstitutions().empty()) |
| 422 | { |
| 423 | optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph)); |
| 424 | } |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 425 | else |
| 426 | { |
| 427 | ReportUntouchedLayers(optimizationViews, untouched); |
| 428 | } |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 429 | |
| 430 | return optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 431 | } |
| 432 | |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 433 | } // namespace armnn |