ArmNN
 21.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 #include <armnn/Optional.hpp>
10 
11 #include <memory>
12 #include <unordered_map>
13 #include <functional>
14 
15 namespace armnn
16 {
17 
18 namespace profiling
19 {
20  class ProfilingService;
21 }
22 class IBackendInternal;
23 using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
24 
26 {
27 public:
29  using FactoryFunction = std::function<PointerType()>;
30 
31  void Register(const BackendId& id, FactoryFunction factory);
32  bool IsBackendRegistered(const BackendId& id) const;
33  FactoryFunction GetFactory(const BackendId& id) const;
34  size_t Size() const;
35  BackendIdSet GetBackendIds() const;
36  std::string GetBackendIdsAsString() const;
37  void SetProfilingService(armnn::Optional<profiling::ProfilingService&> profilingService);
38 
40  virtual ~BackendRegistry() {}
41 
43  {
45  const BackendId& id,
46  FactoryFunction factory)
47  {
48  instance.Register(id, factory);
49  }
50  };
51 
52  void Deregister(const BackendId& id);
53 
54 protected:
55  using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>;
56 
57  /// For testing only
58  static void Swap(BackendRegistry& instance, FactoryStorage& other);
59 
60 private:
61  BackendRegistry(const BackendRegistry&) = delete;
62  BackendRegistry& operator=(const BackendRegistry&) = delete;
63 
64  FactoryStorage m_Factories;
66 };
67 
69 
70 } // namespace armnn
StaticRegistryInitializer(BackendRegistry &instance, const BackendId &id, FactoryFunction factory)
IBackendInternalUniquePtr PointerType
std::function< PointerType()> FactoryFunction
void Register(const BackendId &id, FactoryFunction factory)
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:191
std::unordered_map< BackendId, FactoryFunction > FactoryStorage
BackendRegistry & BackendRegistryInstance()
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr