1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include <backendsCommon/TensorHandleFactoryRegistry.hpp> 7 #include <armnn/backends/IMemoryManager.hpp> 8 9 namespace armnn 10 { 11 RegisterFactory(std::unique_ptr<ITensorHandleFactory> newFactory)12void TensorHandleFactoryRegistry::RegisterFactory(std::unique_ptr <ITensorHandleFactory> newFactory) 13 { 14 if (!newFactory) 15 { 16 return; 17 } 18 19 ITensorHandleFactory::FactoryId id = newFactory->GetId(); 20 21 // Don't register duplicates 22 for (auto& registeredFactory : m_Factories) 23 { 24 if (id == registeredFactory->GetId()) 25 { 26 return; 27 } 28 } 29 30 // Take ownership of the new allocator 31 m_Factories.push_back(std::move(newFactory)); 32 } 33 RegisterMemoryManager(std::shared_ptr<armnn::IMemoryManager> memoryManger)34void TensorHandleFactoryRegistry::RegisterMemoryManager(std::shared_ptr<armnn::IMemoryManager> memoryManger) 35 { 36 m_MemoryManagers.push_back(memoryManger); 37 } 38 GetFactory(ITensorHandleFactory::FactoryId id) const39ITensorHandleFactory* TensorHandleFactoryRegistry::GetFactory(ITensorHandleFactory::FactoryId id) const 40 { 41 for (auto& factory : m_Factories) 42 { 43 if (factory->GetId() == id) 44 { 45 return factory.get(); 46 } 47 } 48 49 return nullptr; 50 } 51 AquireMemory()52void TensorHandleFactoryRegistry::AquireMemory() 53 { 54 for (auto& mgr : m_MemoryManagers) 55 { 56 mgr->Acquire(); 57 } 58 } 59 ReleaseMemory()60void TensorHandleFactoryRegistry::ReleaseMemory() 61 { 62 for (auto& mgr : m_MemoryManagers) 63 { 64 mgr->Release(); 65 } 66 } 67 68 } // namespace armnn 69