ArmNN
 24.08
BackendRegistry Class Reference

#include <BackendRegistry.hpp>

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< arm::pipe::IProfilingService & > 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 35 of file BackendRegistry.hpp.

Member Typedef Documentation

◆ FactoryFunction

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

Definition at line 39 of file BackendRegistry.hpp.

◆ FactoryStorage

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

Definition at line 71 of file BackendRegistry.hpp.

◆ PointerType

Definition at line 38 of file BackendRegistry.hpp.

Constructor & Destructor Documentation

◆ BackendRegistry()

BackendRegistry ( )
inline

Definition at line 53 of file BackendRegistry.hpp.

53 {}

◆ ~BackendRegistry()

virtual ~BackendRegistry ( )
inlinevirtual

Definition at line 54 of file BackendRegistry.hpp.

54 {}

Member Function Documentation

◆ Deregister()

void Deregister ( const BackendId id)

Definition at line 41 of file BackendRegistry.cpp.

42 {
43  m_Factories.erase(id);
45 
46  if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
47  {
48  m_ProfilingService.value().IncrementCounterValue(arm::pipe::UNREGISTERED_BACKENDS);
49  }
50 }

References BackendRegistry::DeregisterAllocator(), OptionalBase::has_value(), and OptionalReferenceSwitch< IsReference, T >::value().

Referenced by DynamicBackendUtils::DeregisterDynamicBackends().

◆ DeregisterAllocator()

void DeregisterAllocator ( const BackendId id)

Definition at line 123 of file BackendRegistry.cpp.

124 {
125  m_CustomMemoryAllocatorMap.erase(id);
126 }

Referenced by BackendRegistry::Deregister().

◆ DeregisterMemoryOptimizerStrategy()

void DeregisterMemoryOptimizerStrategy ( const BackendId id)

Definition at line 145 of file BackendRegistry.cpp.

146 {
147  m_MemoryOptimizerStrategyMap.erase(id);
148 }

◆ GetAllocators()

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

Definition at line 128 of file BackendRegistry.cpp.

129 {
130  return m_CustomMemoryAllocatorMap;
131 }

◆ GetBackendIds()

BackendIdSet GetBackendIds ( ) const

Definition at line 75 of file BackendRegistry.cpp.

76 {
77  BackendIdSet result;
78  for (const auto& it : m_Factories)
79  {
80  result.insert(it.first);
81  }
82  return result;
83 }

Referenced by BackendRegistry::GetBackendIdsAsString().

◆ GetBackendIdsAsString()

std::string GetBackendIdsAsString ( ) const

Definition at line 85 of file BackendRegistry.cpp.

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

References BackendRegistry::GetBackendIds().

◆ GetFactory()

BackendRegistry::FactoryFunction GetFactory ( const BackendId id) const

Definition at line 57 of file BackendRegistry.cpp.

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

References CHECK_LOCATION.

Referenced by armnn::GetILayerSupportByBackendId(), and RuntimeImpl::RuntimeImpl().

◆ GetMemoryOptimizerStrategies()

MemoryOptimizerStrategiesMapRef GetMemoryOptimizerStrategies ( )

Definition at line 150 of file BackendRegistry.cpp.

151 {
152  return m_MemoryOptimizerStrategyMap;
153 }

◆ IsBackendRegistered()

bool IsBackendRegistered ( const BackendId id) const

Definition at line 52 of file BackendRegistry.cpp.

53 {
54  return (m_Factories.find(id) != m_Factories.end());
55 }

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

◆ Register()

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

Definition at line 21 of file BackendRegistry.cpp.

22 {
23  if (m_Factories.find(id) != m_Factories.end())
24  {
25  throw InvalidArgumentException(
26  std::string(id) + " already registered as IBackend factory",
27  CHECK_LOCATION());
28  }
29  m_Factories[id] = factory;
30 
31  if (m_ProfilingService.has_value())
32  {
33  if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
34  {
35  m_ProfilingService.value().IncrementCounterValue(arm::pipe::REGISTERED_BACKENDS);
36  }
37  }
38 
39 }

References CHECK_LOCATION, OptionalBase::has_value(), and OptionalReferenceSwitch< IsReference, T >::value().

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

◆ RegisterAllocator()

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

Definition at line 112 of file BackendRegistry.cpp.

113 {
114  if (m_CustomMemoryAllocatorMap.find(id) != m_CustomMemoryAllocatorMap.end())
115  {
116  throw InvalidArgumentException(
117  std::string(id) + " already has an allocator associated with it",
118  CHECK_LOCATION());
119  }
120  m_CustomMemoryAllocatorMap[id] = alloc;
121 }

References CHECK_LOCATION.

Referenced by RuntimeImpl::RuntimeImpl().

◆ RegisterMemoryOptimizerStrategy()

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

Definition at line 133 of file BackendRegistry.cpp.

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

References CHECK_LOCATION.

Referenced by RuntimeImpl::RuntimeImpl().

◆ SetProfilingService()

void SetProfilingService ( armnn::Optional< arm::pipe::IProfilingService & >  profilingService)

Definition at line 107 of file BackendRegistry.cpp.

108 {
109  m_ProfilingService = profilingService;
110 }

Referenced by RuntimeImpl::~RuntimeImpl().

◆ Size()

size_t Size ( ) const

Definition at line 70 of file BackendRegistry.cpp.

71 {
72  return m_Factories.size();
73 }

◆ Swap()

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

For testing only.

Definition at line 102 of file BackendRegistry.cpp.

103 {
104  std::swap(instance.m_Factories, other);
105 }

References armnn::swap().


The documentation for this class was generated from the following files:
armnn::BackendIdSet
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:193
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::swap
void swap(OriginsDescriptor &first, OriginsDescriptor &second)
Definition: Descriptors.cpp:357
armnn::BackendRegistry::GetBackendIds
BackendIdSet GetBackendIds() const
Definition: BackendRegistry.cpp:75
armnn::BackendRegistry::DeregisterAllocator
void DeregisterAllocator(const BackendId &id)
Definition: BackendRegistry.cpp:123
armnn::OptionalReferenceSwitch::value
const T & value() const
Definition: Optional.hpp:146
armnn::OptionalBase::has_value
bool has_value() const noexcept
Definition: Optional.hpp:53