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