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 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 144 | OptimizationViews ClBackend::OptimizeSubgraphView(const SubgraphView& subgraph, |
| 145 | const ModelOptions& modelOptions) const |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 146 | { |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 147 | OptimizationViews optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 148 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 149 | auto it = subgraph.end(); |
| 150 | bool isFastMathEnabled = false; |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 151 | std::map<LayerGuid, Layer*> untouched; |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 152 | |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 153 | while (it != subgraph.begin()) |
| 154 | { |
| 155 | --it; |
| 156 | Layer& base = **it; |
| 157 | untouched.insert({base.GetGuid(), &base}); |
| 158 | } |
| 159 | |
| 160 | it = subgraph.end(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 161 | #if defined(ARMCOMPUTECL_ENABLED) |
| 162 | IBackendInternal::IBackendSpecificModelContextPtr modelContextPtr = CreateBackendSpecificModelContext(modelOptions); |
| 163 | |
| 164 | if (modelContextPtr) |
| 165 | { |
| 166 | auto clModelOptions = dynamic_cast<ClBackendModelContext*>(modelContextPtr.get()); |
| 167 | if (clModelOptions) |
| 168 | { |
| 169 | isFastMathEnabled = clModelOptions->IsFastMathEnabled(); |
| 170 | } |
| 171 | } |
| 172 | #endif |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 173 | while (it != subgraph.begin()) |
| 174 | { |
| 175 | --it; |
| 176 | Layer& base = **it; |
| 177 | |
| 178 | if ((base.GetType() == LayerType::DepthwiseConvolution2d || base.GetType() == LayerType::Convolution2d |
| 179 | || base.GetType() == LayerType::BatchNormalization || base.GetType() == LayerType::FullyConnected |
| 180 | || base.GetType() == LayerType::Addition || base.GetType() == LayerType::Multiplication |
| 181 | || base.GetType() == LayerType::Subtraction || base.GetType() == LayerType::Division) |
| 182 | && (base.GetAdditionalInformation<ActivationDescriptor>() == nullptr)) |
| 183 | { |
| 184 | for (auto output = base.BeginOutputSlots(); output != base.EndOutputSlots(); ++output) |
| 185 | { |
| 186 | if (output->GetNumConnections() == 1) |
| 187 | { |
| 188 | for (auto&& childInput : output->GetConnections()) |
| 189 | { |
Teresa Charlin | d672f5d | 2021-01-18 18:07:57 +0000 | [diff] [blame] | 190 | if ((childInput->GetOwningLayer().GetType() == LayerType::Activation) && |
| 191 | (checkDataTypeInputandOutput(childInput->GetOwningLayer()))) |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 192 | { |
| 193 | Layer& child = childInput->GetOwningLayer(); |
| 194 | |
| 195 | auto* activationLayer = PolymorphicDowncast<ActivationLayer*>(&child); |
| 196 | |
| 197 | const std::string name = std::string("fused-") + child.GetName() + std::string("-into-") + |
| 198 | base.GetName(); |
| 199 | |
| 200 | // Get params from activation layer |
| 201 | ActivationDescriptor activationDesc = activationLayer->GetParameters(); |
| 202 | |
| 203 | if (base.GetType() == LayerType::Convolution2d) |
| 204 | { |
| 205 | Convolution2dLayer* baseLayer = PolymorphicDowncast<Convolution2dLayer*>(&base); |
| 206 | |
| 207 | Optional<TensorInfo> biases; |
| 208 | |
| 209 | if (baseLayer->GetParameters().m_BiasEnabled) |
| 210 | { |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 211 | biases = baseLayer->m_Bias->GetTensorInfo(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | arm_compute::Status status = ClConvolution2dWorkloadValidate( |
| 215 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 216 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 217 | baseLayer->GetParameters(), |
| 218 | baseLayer->m_Weight->GetTensorInfo(), |
| 219 | biases, |
| 220 | isFastMathEnabled, |
| 221 | &activationDesc); |
| 222 | |
| 223 | if (status) |
| 224 | { |
| 225 | FuseLayerWithWeightsAndBiases<Convolution2dLayer>(optimizationViews, |
| 226 | baseLayer, |
| 227 | activationLayer, |
| 228 | activationDesc, |
| 229 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 230 | untouched.erase(baseLayer->GetGuid()); |
| 231 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | else if (base.GetType() == LayerType::DepthwiseConvolution2d) |
| 235 | { |
| 236 | DepthwiseConvolution2dLayer* baseLayer = |
| 237 | PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&base); |
| 238 | |
| 239 | Optional<TensorInfo> biases; |
| 240 | |
| 241 | if (baseLayer->GetParameters().m_BiasEnabled) |
| 242 | { |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 243 | biases = baseLayer->m_Bias->GetTensorInfo(); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | arm_compute::Status status = ClDepthwiseConvolutionWorkloadValidate( |
| 247 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 248 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 249 | baseLayer->GetParameters(), |
| 250 | baseLayer->m_Weight->GetTensorInfo(), |
| 251 | biases, |
| 252 | &activationDesc); |
| 253 | |
| 254 | if (status) |
| 255 | { |
| 256 | FuseLayerWithWeightsAndBiases<DepthwiseConvolution2dLayer>(optimizationViews, |
| 257 | baseLayer, |
| 258 | activationLayer, |
| 259 | activationDesc, |
| 260 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 261 | untouched.erase(baseLayer->GetGuid()); |
| 262 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | else if (base.GetType() == LayerType::FullyConnected) |
| 266 | { |
| 267 | FullyConnectedLayer* baseLayer = PolymorphicDowncast<FullyConnectedLayer*>(&base); |
| 268 | |
| 269 | arm_compute::Status status = ClFullyConnectedWorkloadValidate( |
| 270 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 271 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 272 | baseLayer->m_Weight->GetTensorInfo(), |
| 273 | baseLayer->m_Bias->GetTensorInfo(), |
| 274 | baseLayer->GetParameters(), |
| 275 | &activationDesc); |
| 276 | |
| 277 | if (status) |
| 278 | { |
| 279 | FuseLayerWithWeightsAndBiases<FullyConnectedLayer>(optimizationViews, |
| 280 | baseLayer, |
| 281 | activationLayer, |
| 282 | activationDesc, |
| 283 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 284 | untouched.erase(baseLayer->GetGuid()); |
| 285 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | else if (base.GetType() == LayerType::BatchNormalization) |
| 289 | { |
| 290 | BatchNormalizationLayer* baseLayer = |
| 291 | PolymorphicDowncast<BatchNormalizationLayer*>(&base); |
| 292 | |
| 293 | arm_compute::Status status = ClBatchNormalizationValidate( |
| 294 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 295 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 296 | baseLayer->m_Mean->GetTensorInfo(), |
| 297 | baseLayer->m_Variance->GetTensorInfo(), |
| 298 | baseLayer->m_Beta->GetTensorInfo(), |
| 299 | baseLayer->m_Gamma->GetTensorInfo(), |
| 300 | baseLayer->GetParameters(), |
| 301 | &activationDesc); |
| 302 | |
| 303 | if (status) |
| 304 | { |
| 305 | BatchNormalizationLayer* replacementLayer = |
| 306 | FuseLayerWithParameters<BatchNormalizationLayer>(optimizationViews, |
| 307 | baseLayer, |
| 308 | activationLayer, |
| 309 | activationDesc, |
| 310 | name); |
| 311 | |
| 312 | replacementLayer->m_Beta = std::move(baseLayer->m_Beta); |
| 313 | replacementLayer->m_Gamma = std::move(baseLayer->m_Gamma); |
| 314 | replacementLayer->m_Mean = std::move(baseLayer->m_Mean); |
| 315 | replacementLayer->m_Variance = std::move(baseLayer->m_Variance); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 316 | untouched.erase(baseLayer->GetGuid()); |
| 317 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | else if (base.GetType() == LayerType::Addition) |
| 321 | { |
| 322 | AdditionLayer* baseLayer = PolymorphicDowncast<AdditionLayer*>(&base); |
| 323 | |
| 324 | arm_compute::Status status = ClAdditionValidate( |
| 325 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 326 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 327 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 328 | &activationDesc); |
| 329 | |
| 330 | if (status) |
| 331 | { |
| 332 | FuseLayerWithoutParameters<AdditionLayer>(optimizationViews, |
| 333 | baseLayer, |
| 334 | activationLayer, |
| 335 | activationDesc, |
| 336 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 337 | untouched.erase(baseLayer->GetGuid()); |
| 338 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | else if (base.GetType() == LayerType::Division) |
| 342 | { |
| 343 | DivisionLayer* baseLayer = PolymorphicDowncast<DivisionLayer*>(&base); |
| 344 | |
| 345 | arm_compute::Status status = ClDivisionWorkloadValidate( |
| 346 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 347 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 348 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 349 | &activationDesc); |
| 350 | |
| 351 | if (status) |
| 352 | { |
| 353 | FuseLayerWithoutParameters<DivisionLayer>(optimizationViews, |
| 354 | baseLayer, |
| 355 | activationLayer, |
| 356 | activationDesc, |
| 357 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 358 | untouched.erase(baseLayer->GetGuid()); |
| 359 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | else if (base.GetType() == LayerType::Multiplication) |
| 363 | { |
| 364 | MultiplicationLayer* baseLayer = PolymorphicDowncast<MultiplicationLayer*>(&base); |
| 365 | |
| 366 | arm_compute::Status status = ClMultiplicationWorkloadValidate( |
| 367 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 368 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 369 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 370 | &activationDesc); |
| 371 | |
| 372 | if (status) |
| 373 | { |
| 374 | FuseLayerWithoutParameters<MultiplicationLayer>(optimizationViews, |
| 375 | baseLayer, |
| 376 | activationLayer, |
| 377 | activationDesc, |
| 378 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 379 | untouched.erase(baseLayer->GetGuid()); |
| 380 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | else if (base.GetType() == LayerType::Subtraction) |
| 384 | { |
| 385 | SubtractionLayer* baseLayer = PolymorphicDowncast<SubtractionLayer*>(&base); |
| 386 | |
| 387 | arm_compute::Status status = ClSubtractionValidate( |
| 388 | baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 389 | baseLayer->GetInputSlot(1).GetConnectedOutputSlot()->GetTensorInfo(), |
| 390 | activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(), |
| 391 | &activationDesc); |
| 392 | |
| 393 | if (status) |
| 394 | { |
| 395 | FuseLayerWithoutParameters<SubtractionLayer>(optimizationViews, |
| 396 | baseLayer, |
| 397 | activationLayer, |
| 398 | activationDesc, |
| 399 | name); |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 400 | untouched.erase(baseLayer->GetGuid()); |
| 401 | untouched.erase(activationLayer->GetGuid()); |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 410 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 411 | if (optimizationViews.GetSubstitutions().empty()) |
| 412 | { |
| 413 | optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph)); |
| 414 | } |
Mike Kelly | 1ac690a | 2020-11-17 11:41:38 +0000 | [diff] [blame] | 415 | else |
| 416 | { |
| 417 | ReportUntouchedLayers(optimizationViews, untouched); |
| 418 | } |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 419 | |
| 420 | return optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 421 | } |
| 422 | |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 423 | } // namespace armnn |