blob: f49a2109886392482918d853984c248d91889517 [file] [log] [blame]
David Becke97c6e02018-10-03 13:09:28 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
David Beck9efb57d2018-11-05 13:40:33 +00007#include <armnn/Types.hpp>
David Beck1b61be52018-11-08 09:19:14 +00008#include <armnn/IRuntime.hpp>
Matteo Martincigh49124022019-01-11 13:25:59 +00009
Derek Lambertiff05cc52019-04-26 13:05:17 +010010#include <ISubgraphViewConverter.hpp>
11#include <SubgraphView.hpp>
Matteo Martincigh49124022019-01-11 13:25:59 +000012
Derek Lambertic2fe5fb2019-05-08 10:23:08 +010013#include "OptimizationViews.hpp"
14
David Beck263e3492018-11-09 14:46:40 +000015#include <vector>
David Becke97c6e02018-10-03 13:09:28 +010016
17namespace armnn
18{
David Beck29c75de2018-10-23 13:35:58 +010019class IWorkloadFactory;
David Beck1b61be52018-11-08 09:19:14 +000020class IBackendContext;
Aron Virginas-Tar56055192018-11-12 18:10:43 +000021class IMemoryManager;
David Beck263e3492018-11-09 14:46:40 +000022class Optimization;
David Beck111b5d92018-11-12 14:59:37 +000023class ILayerSupport;
David Becke97c6e02018-10-03 13:09:28 +010024
25class IBackendInternal : public IBackend
26{
27protected:
David Beck9efb57d2018-11-05 13:40:33 +000028 // Creation must be done through a specific
29 // backend interface.
David Beck6b779f02018-10-09 17:20:21 +010030 IBackendInternal() = default;
David Becke97c6e02018-10-03 13:09:28 +010031
32public:
David Beck29c75de2018-10-23 13:35:58 +010033 // Allow backends created by the factory function
34 // to be destroyed through IBackendInternal.
35 ~IBackendInternal() override = default;
36
37 using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>;
David Beck1b61be52018-11-08 09:19:14 +000038 using IBackendContextPtr = std::unique_ptr<IBackendContext>;
David Beck263e3492018-11-09 14:46:40 +000039 using OptimizationPtr = std::unique_ptr<Optimization>;
40 using Optimizations = std::vector<OptimizationPtr>;
David Beck111b5d92018-11-12 14:59:37 +000041 using ILayerSupportSharedPtr = std::shared_ptr<ILayerSupport>;
David Beck1b61be52018-11-08 09:19:14 +000042
Aron Virginas-Tar56055192018-11-12 18:10:43 +000043 using IMemoryManagerUniquePtr = std::unique_ptr<IMemoryManager>;
44 using IMemoryManagerSharedPtr = std::shared_ptr<IMemoryManager>;
45
Matteo Martincigh602af092019-05-01 10:31:27 +010046 using GraphUniquePtr = std::unique_ptr<Graph>;
Derek Lambertiff05cc52019-04-26 13:05:17 +010047 using SubgraphViewUniquePtr = std::unique_ptr<SubgraphView>;
Matteo Martincighadddddb2019-01-24 14:06:23 +000048
Aron Virginas-Tar56055192018-11-12 18:10:43 +000049 virtual IMemoryManagerUniquePtr CreateMemoryManager() const = 0;
50
51 virtual IWorkloadFactoryPtr CreateWorkloadFactory(
52 const IMemoryManagerSharedPtr& memoryManager = nullptr) const = 0;
53
David Beck1b61be52018-11-08 09:19:14 +000054 virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const = 0;
Aron Virginas-Tar56055192018-11-12 18:10:43 +000055
David Beck263e3492018-11-09 14:46:40 +000056 virtual Optimizations GetOptimizations() const = 0;
David Beck111b5d92018-11-12 14:59:37 +000057 virtual ILayerSupportSharedPtr GetLayerSupport() const = 0;
Matteo Martincighadddddb2019-01-24 14:06:23 +000058
Derek Lambertic2fe5fb2019-05-08 10:23:08 +010059 // @deprecated Use "OptimizationViews OptimizeSubgraphView(const SubgraphView&);" instead.
60 virtual SubgraphViewUniquePtr OptimizeSubgraphView(const SubgraphView& subgraph, bool& optimizationAttempted) const
61 {
62 optimizationAttempted=false;
63 return nullptr;
64 }
65
66 // Default implementation of OptimizeSubgraphView for backward compatibility with old API.
67 // Override this method with a custom optimization implementation.
68 virtual OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph)
69 {
70 bool attempted=false;
71 SubgraphViewUniquePtr optSubgraph = OptimizeSubgraphView(subgraph, attempted);
72
73 OptimizationViews result;
74 if (!attempted)
75 {
76 result.AddUntouchedSubgraph(SubgraphView(subgraph));
77 }
78 else
79 {
80 if (optSubgraph)
81 {
82 result.AddSubstituion({*optSubgraph.get(), subgraph});
83 }
84 else
85 {
86 result.AddFailedSubgraph(SubgraphView(subgraph));
87 }
88 }
89 return result;
90 }
David Becke97c6e02018-10-03 13:09:28 +010091};
92
David Beck29c75de2018-10-23 13:35:58 +010093using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
94
David Becke97c6e02018-10-03 13:09:28 +010095} // namespace armnn