ArmNN
 20.02
BackendRegistry.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnn/Types.hpp>
8 #include <armnn/BackendId.hpp>
9 
10 #include <memory>
11 #include <unordered_map>
12 #include <functional>
13 
14 namespace armnn
15 {
16 
17 class IBackendInternal;
18 using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
19 
21 {
22 public:
24  using FactoryFunction = std::function<PointerType()>;
25 
26  void Register(const BackendId& id, FactoryFunction factory);
27  bool IsBackendRegistered(const BackendId& id) const;
28  FactoryFunction GetFactory(const BackendId& id) const;
29  size_t Size() const;
31  std::string GetBackendIdsAsString() const;
32 
34  virtual ~BackendRegistry() {}
35 
37  {
39  const BackendId& id,
40  FactoryFunction factory)
41  {
42  instance.Register(id, factory);
43  }
44  };
45 
46  void Deregister(const BackendId& id);
47 
48 protected:
49  using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>;
50 
51  /// For testing only
52  static void Swap(BackendRegistry& instance, FactoryStorage& other);
53 
54 private:
55  BackendRegistry(const BackendRegistry&) = delete;
56  BackendRegistry& operator=(const BackendRegistry&) = delete;
57 
58  FactoryStorage m_Factories;
59 };
60 
62 
63 } // namespace armnn
FactoryFunction GetFactory(const BackendId &id) const
BackendIdSet GetBackendIds() const
StaticRegistryInitializer(BackendRegistry &instance, const BackendId &id, FactoryFunction factory)
bool IsBackendRegistered(const BackendId &id) const
IBackendInternalUniquePtr PointerType
std::function< PointerType()> FactoryFunction
void Register(const BackendId &id, FactoryFunction factory)
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:191
static void Swap(BackendRegistry &instance, FactoryStorage &other)
For testing only.
std::unordered_map< BackendId, FactoryFunction > FactoryStorage
BackendRegistry & BackendRegistryInstance()
Copyright (c) 2020 ARM Limited.
std::string GetBackendIdsAsString() const
void Deregister(const BackendId &id)
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr