ArmNN
 24.08
TensorHandleFactoryRegistry.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Types.hpp>
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 namespace armnn
15 {
16 
17 //Forward
18 class IMemoryManager;
19 
20 using CopyAndImportFactoryPairs = std::map<ITensorHandleFactory::FactoryId, ITensorHandleFactory::FactoryId>;
21 
22 ///
24 {
25 public:
26  TensorHandleFactoryRegistry() = default;
27 
30 
31  /// Register a TensorHandleFactory and transfer ownership
32  void RegisterFactory(std::unique_ptr<ITensorHandleFactory> allocator);
33 
34  /// Register a memory manager with shared ownership
35  void RegisterMemoryManager(std::shared_ptr<IMemoryManager> memoryManger);
36 
37  /// Find a TensorHandleFactory by Id
38  /// Returns nullptr if not found
40 
41  /// Overload of above allowing specification of Memory Source
43  MemorySource memSource) const;
44 
45  /// Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Import
47  ITensorHandleFactory::FactoryId importFactoryId);
48 
49  /// Get a matching TensorHandleFatory Id for Memory Import given TensorHandleFactory Id for Memory Copy
51 
52  /// Aquire memory required for inference
53  void AquireMemory();
54 
55  /// Release memory required for inference
56  void ReleaseMemory();
57 
58  std::vector<std::shared_ptr<IMemoryManager>>& GetMemoryManagers()
59  {
60  return m_MemoryManagers;
61  }
62 
63 private:
64  std::vector<std::unique_ptr<ITensorHandleFactory>> m_Factories;
65  std::vector<std::shared_ptr<IMemoryManager>> m_MemoryManagers;
66  CopyAndImportFactoryPairs m_FactoryMappings;
67 };
68 
69 } // namespace armnn
armnn::TensorHandleFactoryRegistry::ReleaseMemory
void ReleaseMemory()
Release memory required for inference.
Definition: TensorHandleFactoryRegistry.cpp:86
armnn::TensorHandleFactoryRegistry
Definition: TensorHandleFactoryRegistry.hpp:23
armnn::TensorHandleFactoryRegistry::GetFactory
ITensorHandleFactory * GetFactory(ITensorHandleFactory::FactoryId id) const
Find a TensorHandleFactory by Id Returns nullptr if not found.
Definition: TensorHandleFactoryRegistry.cpp:39
ITensorHandleFactory.hpp
armnn::TensorHandleFactoryRegistry::GetMemoryManagers
std::vector< std::shared_ptr< IMemoryManager > > & GetMemoryManagers()
Definition: TensorHandleFactoryRegistry.hpp:58
armnn::TensorHandleFactoryRegistry::RegisterMemoryManager
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
Definition: TensorHandleFactoryRegistry.cpp:34
armnn::TensorHandleFactoryRegistry::GetMatchingImportFactoryId
ITensorHandleFactory::FactoryId GetMatchingImportFactoryId(ITensorHandleFactory::FactoryId copyFactoryId)
Get a matching TensorHandleFatory Id for Memory Import given TensorHandleFactory Id for Memory Copy.
Definition: TensorHandleFactoryRegistry.cpp:72
armnn::ITensorHandleFactory
Definition: ITensorHandleFactory.hpp:46
armnn::TensorHandleFactoryRegistry::AquireMemory
void AquireMemory()
Aquire memory required for inference.
Definition: TensorHandleFactoryRegistry.cpp:78
armnn::TensorHandleFactoryRegistry::TensorHandleFactoryRegistry
TensorHandleFactoryRegistry()=default
armnn::MemorySource
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:244
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::TensorHandleFactoryRegistry::RegisterFactory
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
Definition: TensorHandleFactoryRegistry.cpp:12
armnn::CopyAndImportFactoryPairs
std::map< ITensorHandleFactory::FactoryId, ITensorHandleFactory::FactoryId > CopyAndImportFactoryPairs
Definition: TensorHandleFactoryRegistry.hpp:20
armnn::ITensorHandleFactory::FactoryId
std::string FactoryId
Definition: ITensorHandleFactory.hpp:49
armnn::TensorHandleFactoryRegistry::RegisterCopyAndImportFactoryPair
void RegisterCopyAndImportFactoryPair(ITensorHandleFactory::FactoryId copyFactoryId, ITensorHandleFactory::FactoryId importFactoryId)
Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Impor...
Definition: TensorHandleFactoryRegistry.cpp:66