ArmNN
 20.11
MockImportBackend.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "MockImportBackend.hpp"
8 
13 
16 
17 #include <Optimizer.hpp>
18 
19 namespace armnn
20 {
21 
23 {
25  []()
26  {
28  });
29 }
30 
32 {
33  try
34  {
36  }
37  catch (...)
38  {
39  std::cerr << "could not deregister mock import backend" << std::endl;
40  }
41 }
42 
44 {
45  static const BackendId s_Id{ MockImportBackendId() };
46  return s_Id;
47 }
48 
50  const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const
51 {
52  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
53 }
54 
56  class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const
57 {
58  auto memoryManager = std::make_shared<RefMemoryManager>();
59 
60  tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
61  tensorHandleFactoryRegistry.RegisterFactory(std::make_unique<RefTensorHandleFactory>(memoryManager));
62 
63  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
64 }
65 
67 {
68  return IBackendContextPtr{};
69 }
70 
73 {
75 }
76 
78 {
79  return std::make_unique<RefMemoryManager>();
80 }
81 
83 {
84  return Optimizations{};
85 }
86 
88 {
89  static ILayerSupportSharedPtr layerSupport{new MockImportLayerSupport};
90  return layerSupport;
91 }
92 
94 {
95  OptimizationViews optimizationViews;
96 
97  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
98 
99  return optimizationViews;
100 }
101 
102 std::vector<ITensorHandleFactory::FactoryId> MockImportBackend::GetHandleFactoryPreferences() const
103 {
104  return std::vector<ITensorHandleFactory::FactoryId> { RefTensorHandleFactory::GetIdStatic() };
105 }
106 
108 {
109  auto memoryManager = std::make_shared<RefMemoryManager>();
110 
111  registry.RegisterMemoryManager(memoryManager);
112  registry.RegisterFactory(std::make_unique<RefTensorHandleFactory>(memoryManager));
113 }
114 
115 } // namespace armnn
void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &registry) override
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
static const FactoryId & GetIdStatic()
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::vector< OptimizationPtr > Optimizations
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
void Register(const BackendId &id, FactoryFunction factory)
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
BackendRegistry & BackendRegistryInstance()
Copyright (c) 2020 ARM Limited.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
constexpr const char * MockImportBackendId()
The SubgraphView class represents a subgraph of a Graph.
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
static const BackendId & GetIdStatic()
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Create the runtime context of the backend.
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
void AddUntouchedSubgraph(SubgraphView &&subgraph)
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
void Deregister(const BackendId &id)
IBackendInternal::Optimizations GetOptimizations() const override
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr
std::shared_ptr< armnn::profiling::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we&#39;ll keep it in the backend namespace...
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
std::unique_ptr< IBackendContext > IBackendContextPtr