ArmNN
 20.05
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)
 
 BackendRegistry ()
 
virtual ~BackendRegistry ()
 
void Deregister (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 25 of file BackendRegistry.hpp.

Member Typedef Documentation

◆ FactoryFunction

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

Definition at line 29 of file BackendRegistry.hpp.

◆ FactoryStorage

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

Definition at line 55 of file BackendRegistry.hpp.

◆ PointerType

Definition at line 28 of file BackendRegistry.hpp.

Constructor & Destructor Documentation

◆ BackendRegistry()

BackendRegistry ( )
inline

Definition at line 39 of file BackendRegistry.hpp.

39 {}

◆ ~BackendRegistry()

virtual ~BackendRegistry ( )
inlinevirtual

Definition at line 40 of file BackendRegistry.hpp.

40 {}

Member Function Documentation

◆ Deregister()

void Deregister ( const BackendId id)

Definition at line 39 of file BackendRegistry.cpp.

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

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

◆ GetBackendIds()

BackendIdSet GetBackendIds ( ) const

Definition at line 72 of file BackendRegistry.cpp.

Referenced by BackendRegistry::GetBackendIdsAsString().

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

◆ GetBackendIdsAsString()

std::string GetBackendIdsAsString ( ) const

Definition at line 82 of file BackendRegistry.cpp.

References BackendRegistry::GetBackendIds().

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

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

◆ GetFactory()

BackendRegistry::FactoryFunction GetFactory ( const BackendId id) const

Definition at line 54 of file BackendRegistry.cpp.

References CHECK_LOCATION.

Referenced by BOOST_AUTO_TEST_CASE(), armnn::GetILayerSupportByBackendId(), LoadedNetwork::MakeLoadedNetwork(), armnn::Optimize(), and Runtime::Runtime().

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

◆ IsBackendRegistered()

bool IsBackendRegistered ( const BackendId id) const

Definition at line 49 of file BackendRegistry.cpp.

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

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

◆ Register()

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

Definition at line 19 of file BackendRegistry.cpp.

References CHECK_LOCATION.

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

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:192

◆ SetProfilingService()

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

Definition at line 104 of file BackendRegistry.cpp.

References profilingService.

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

105 {
106  m_ProfilingService = profilingService;
107 }
armnn::profiling::ProfilingService profilingService

◆ Size()

size_t Size ( ) const

Definition at line 67 of file BackendRegistry.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), RegisterSingleDynamicBackendTestImpl(), RuntimeEmptyTestImpl(), and RuntimeInvalidOverridePathTestImpl().

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

◆ Swap()

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

For testing only.

Definition at line 99 of file BackendRegistry.cpp.

References armnn::swap().

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

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