ArmNN
 21.11
BackendRegistry Class Reference

#include <BackendRegistry.hpp>

Inheritance diagram for BackendRegistry:
TestBackendRegistry

Classes

struct  StaticRegistryInitializer
 

Public Types

using PointerType = IBackendInternalUniquePtr
 
using FactoryFunction = std::function< PointerType()>
 

Public Member Functions

void Register (const BackendId &id, FactoryFunction factory)
 
bool IsBackendRegistered (const BackendId &id) const
 
FactoryFunction GetFactory (const BackendId &id) const
 
size_t Size () const
 
BackendIdSet GetBackendIds () const
 
std::string GetBackendIdsAsString () const
 
void SetProfilingService (armnn::Optional< profiling::ProfilingService &> profilingService)
 
void RegisterAllocator (const BackendId &id, std::shared_ptr< ICustomAllocator > alloc)
 
std::unordered_map< BackendId, std::shared_ptr< ICustomAllocator > > GetAllocators ()
 
void RegisterMemoryOptimizerStrategy (const BackendId &id, std::shared_ptr< IMemoryOptimizerStrategy > strategy)
 
MemoryOptimizerStrategiesMapRef GetMemoryOptimizerStrategies ()
 
 BackendRegistry ()
 
virtual ~BackendRegistry ()
 
void Deregister (const BackendId &id)
 
void DeregisterAllocator (const BackendId &id)
 
void DeregisterMemoryOptimizerStrategy (const BackendId &id)
 

Protected Types

using FactoryStorage = std::unordered_map< BackendId, FactoryFunction >
 

Static Protected Member Functions

static void Swap (BackendRegistry &instance, FactoryStorage &other)
 For testing only. More...
 

Detailed Description

Definition at line 29 of file BackendRegistry.hpp.

Member Typedef Documentation

◆ FactoryFunction

using FactoryFunction = std::function<PointerType()>

Definition at line 33 of file BackendRegistry.hpp.

◆ FactoryStorage

using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>
protected

Definition at line 65 of file BackendRegistry.hpp.

◆ PointerType

Definition at line 32 of file BackendRegistry.hpp.

Constructor & Destructor Documentation

◆ BackendRegistry()

BackendRegistry ( )
inline

Definition at line 47 of file BackendRegistry.hpp.

47 {}

◆ ~BackendRegistry()

virtual ~BackendRegistry ( )
inlinevirtual

Definition at line 48 of file BackendRegistry.hpp.

48 {}

Member Function Documentation

◆ Deregister()

void Deregister ( const BackendId id)

Definition at line 39 of file BackendRegistry.cpp.

References BackendRegistry::DeregisterAllocator().

Referenced by DynamicBackendUtils::DeregisterDynamicBackends(), TEST_SUITE(), MockBackendInitialiser::~MockBackendInitialiser(), and MockImportBackendInitialiser::~MockImportBackendInitialiser().

40 {
41  m_Factories.erase(id);
43 
44  if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
45  {
46  m_ProfilingService.value().IncrementCounterValue(armnn::profiling::UNREGISTERED_BACKENDS);
47  }
48 }
void DeregisterAllocator(const BackendId &id)

◆ DeregisterAllocator()

void DeregisterAllocator ( const BackendId id)

Definition at line 121 of file BackendRegistry.cpp.

Referenced by BackendRegistry::Deregister().

122 {
123  m_CustomMemoryAllocatorMap.erase(id);
124 }

◆ DeregisterMemoryOptimizerStrategy()

void DeregisterMemoryOptimizerStrategy ( const BackendId id)

Definition at line 143 of file BackendRegistry.cpp.

Referenced by TEST_SUITE().

144 {
145  m_MemoryOptimizerStrategyMap.erase(id);
146 }

◆ GetAllocators()

std::unordered_map< BackendId, std::shared_ptr< ICustomAllocator > > GetAllocators ( )

Definition at line 126 of file BackendRegistry.cpp.

Referenced by LoadedNetwork::RegisterDebugCallback().

127 {
128  return m_CustomMemoryAllocatorMap;
129 }

◆ GetBackendIds()

BackendIdSet GetBackendIds ( ) const

Definition at line 73 of file BackendRegistry.cpp.

Referenced by BackendRegistry::GetBackendIdsAsString(), and TEST_SUITE().

74 {
75  BackendIdSet result;
76  for (const auto& it : m_Factories)
77  {
78  result.insert(it.first);
79  }
80  return result;
81 }
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:193

◆ GetBackendIdsAsString()

std::string GetBackendIdsAsString ( ) const

Definition at line 83 of file BackendRegistry.cpp.

References BackendRegistry::GetBackendIds().

Referenced by InferenceModel< IParser, TDataType >::AddCommandLineOptions(), main(), and ProgramOptions::ProgramOptions().

84 {
85  static const std::string delimitator = ", ";
86 
87  std::stringstream output;
88  for (auto& backendId : GetBackendIds())
89  {
90  if (output.tellp() != std::streampos(0))
91  {
92  output << delimitator;
93  }
94  output << backendId;
95  }
96 
97  return output.str();
98 }
BackendIdSet GetBackendIds() const

◆ GetFactory()

BackendRegistry::FactoryFunction GetFactory ( const BackendId id) const

Definition at line 55 of file BackendRegistry.cpp.

References CHECK_LOCATION.

Referenced by armnn::GetILayerSupportByBackendId(), LoadedNetwork::MakeLoadedNetwork(), RuntimeImpl::RuntimeImpl(), and TEST_SUITE().

56 {
57  auto it = m_Factories.find(id);
58  if (it == m_Factories.end())
59  {
60  throw InvalidArgumentException(
61  std::string(id) + " has no IBackend factory registered",
62  CHECK_LOCATION());
63  }
64 
65  return it->second;
66 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:209

◆ GetMemoryOptimizerStrategies()

MemoryOptimizerStrategiesMapRef GetMemoryOptimizerStrategies ( )

Definition at line 148 of file BackendRegistry.cpp.

Referenced by LoadedNetwork::MakeLoadedNetwork().

149 {
150  return m_MemoryOptimizerStrategyMap;
151 }

◆ IsBackendRegistered()

bool IsBackendRegistered ( const BackendId id) const

Definition at line 50 of file BackendRegistry.cpp.

Referenced by armnn::GetILayerSupportByBackendId(), and DynamicBackendUtils::RegisterDynamicBackendsImpl().

51 {
52  return (m_Factories.find(id) != m_Factories.end());
53 }

◆ Register()

void Register ( const BackendId id,
BackendRegistry::FactoryFunction  factory 
)

Definition at line 19 of file BackendRegistry.cpp.

References CHECK_LOCATION.

Referenced by MockBackendInitialiser::MockBackendInitialiser(), MockImportBackendInitialiser::MockImportBackendInitialiser(), DynamicBackendUtils::RegisterDynamicBackendsImpl(), BackendRegistry::StaticRegistryInitializer::StaticRegistryInitializer(), and TEST_SUITE().

20 {
21  if (m_Factories.find(id) != m_Factories.end())
22  {
23  throw InvalidArgumentException(
24  std::string(id) + " already registered as IBackend factory",
25  CHECK_LOCATION());
26  }
27  m_Factories[id] = factory;
28 
29  if (m_ProfilingService.has_value())
30  {
31  if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
32  {
33  m_ProfilingService.value().IncrementCounterValue(armnn::profiling::REGISTERED_BACKENDS);
34  }
35  }
36 
37 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:209

◆ RegisterAllocator()

void RegisterAllocator ( const BackendId id,
std::shared_ptr< ICustomAllocator alloc 
)

Definition at line 110 of file BackendRegistry.cpp.

References CHECK_LOCATION.

Referenced by RuntimeImpl::RuntimeImpl().

111 {
112  if (m_CustomMemoryAllocatorMap.find(id) != m_CustomMemoryAllocatorMap.end())
113  {
114  throw InvalidArgumentException(
115  std::string(id) + " already has an allocator associated with it",
116  CHECK_LOCATION());
117  }
118  m_CustomMemoryAllocatorMap[id] = alloc;
119 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:209

◆ RegisterMemoryOptimizerStrategy()

void RegisterMemoryOptimizerStrategy ( const BackendId id,
std::shared_ptr< IMemoryOptimizerStrategy strategy 
)

Definition at line 131 of file BackendRegistry.cpp.

References CHECK_LOCATION.

Referenced by RuntimeImpl::RuntimeImpl(), and TEST_SUITE().

133 {
134  if (m_MemoryOptimizerStrategyMap.find(id) != m_MemoryOptimizerStrategyMap.end())
135  {
136  throw InvalidArgumentException(
137  std::string(id) + " already has an memory optimizer strategy associated with it",
138  CHECK_LOCATION());
139  }
140  m_MemoryOptimizerStrategyMap[id] = strategy;
141 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:209

◆ SetProfilingService()

void SetProfilingService ( armnn::Optional< profiling::ProfilingService &>  profilingService)

Definition at line 105 of file BackendRegistry.cpp.

Referenced by RuntimeImpl::RuntimeImpl(), and RuntimeImpl::~RuntimeImpl().

106 {
107  m_ProfilingService = profilingService;
108 }

◆ Size()

size_t Size ( ) const

Definition at line 68 of file BackendRegistry.cpp.

Referenced by RuntimeEmptyTestImpl(), RuntimeInvalidOverridePathTestImpl(), and TEST_SUITE().

69 {
70  return m_Factories.size();
71 }

◆ Swap()

void Swap ( BackendRegistry instance,
BackendRegistry::FactoryStorage other 
)
staticprotected

For testing only.

Definition at line 100 of file BackendRegistry.cpp.

References armnn::swap().

101 {
102  std::swap(instance.m_Factories, other);
103 }
void swap(OriginsDescriptor &first, OriginsDescriptor &second)

The documentation for this class was generated from the following files: