ArmNN
 20.02
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
 
 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 20 of file BackendRegistry.hpp.

Member Typedef Documentation

◆ FactoryFunction

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

Definition at line 24 of file BackendRegistry.hpp.

◆ FactoryStorage

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

Definition at line 49 of file BackendRegistry.hpp.

◆ PointerType

Definition at line 23 of file BackendRegistry.hpp.

Constructor & Destructor Documentation

◆ BackendRegistry()

BackendRegistry ( )
inline

Definition at line 33 of file BackendRegistry.hpp.

33 {}

◆ ~BackendRegistry()

virtual ~BackendRegistry ( )
inlinevirtual

Definition at line 34 of file BackendRegistry.hpp.

34 {}

Member Function Documentation

◆ Deregister()

void Deregister ( const BackendId id)

◆ GetBackendIds()

BackendIdSet GetBackendIds ( ) const

Definition at line 66 of file BackendRegistry.cpp.

Referenced by BackendRegistry::GetBackendIdsAsString().

67 {
68  BackendIdSet result;
69  for (const auto& it : m_Factories)
70  {
71  result.insert(it.first);
72  }
73  return result;
74 }
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:191

◆ GetBackendIdsAsString()

std::string GetBackendIdsAsString ( ) const

Definition at line 76 of file BackendRegistry.cpp.

References BackendRegistry::GetBackendIds().

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

77 {
78  static const std::string delimitator = ", ";
79 
80  std::stringstream output;
81  for (auto& backendId : GetBackendIds())
82  {
83  if (output.tellp() != std::streampos(0))
84  {
85  output << delimitator;
86  }
87  output << backendId;
88  }
89 
90  return output.str();
91 }
BackendIdSet GetBackendIds() const

◆ GetFactory()

BackendRegistry::FactoryFunction GetFactory ( const BackendId id) const

Definition at line 48 of file BackendRegistry.cpp.

References CHECK_LOCATION.

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

49 {
50  auto it = m_Factories.find(id);
51  if (it == m_Factories.end())
52  {
53  throw InvalidArgumentException(
54  std::string(id) + " has no IBackend factory registered",
55  CHECK_LOCATION());
56  }
57 
58  return it->second;
59 }
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ IsBackendRegistered()

bool IsBackendRegistered ( const BackendId id) const

Definition at line 43 of file BackendRegistry.cpp.

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

44 {
45  return (m_Factories.find(id) != m_Factories.end());
46 }

◆ Register()

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

Definition at line 19 of file BackendRegistry.cpp.

References CHECK_LOCATION, ProfilingService::IncrementCounterValue(), and ProfilingService::Instance().

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  if (profiling::ProfilingService::Instance().IsProfilingEnabled())
28  {
29  profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::REGISTERED_BACKENDS);
30  }
31  m_Factories[id] = factory;
32 }
static ProfilingService & Instance()
uint32_t IncrementCounterValue(uint16_t counterUid) override
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192

◆ Size()

size_t Size ( ) const

Definition at line 61 of file BackendRegistry.cpp.

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

62 {
63  return m_Factories.size();
64 }

◆ Swap()

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

For testing only.

Definition at line 93 of file BackendRegistry.cpp.

References armnn::swap().

94 {
95  std::swap(instance.m_Factories, other);
96 }
void swap(OriginsDescriptor &first, OriginsDescriptor &second)

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