diff options
author | David Beck <david.beck@arm.com> | 2018-11-12 14:59:37 +0000 |
---|---|---|
committer | Aron Virginas-Tar <aron.virginas-tar@arm.com> | 2018-11-12 16:02:51 +0000 |
commit | 111b5d94d7e854c21377f8d2c0b4234317a903f6 (patch) | |
tree | 68111e5d89b605c898b2327cb59b915e3ff64ce9 /src/backends/backendsCommon/BackendRegistry.cpp | |
parent | 4e1e136cce3fca73ba49b570cfcb620f4ec574da (diff) | |
download | armnn-111b5d94d7e854c21377f8d2c0b4234317a903f6.tar.gz |
IVGCVSW-2125 : Consolidate backend registries into one
Change-Id: I56da4780f8f5fcef7ff01d232d5d61bf299364bf
Diffstat (limited to 'src/backends/backendsCommon/BackendRegistry.cpp')
-rw-r--r-- | src/backends/backendsCommon/BackendRegistry.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/BackendRegistry.cpp b/src/backends/backendsCommon/BackendRegistry.cpp index e9361210f2..80ab01ce1b 100644 --- a/src/backends/backendsCommon/BackendRegistry.cpp +++ b/src/backends/backendsCommon/BackendRegistry.cpp @@ -4,6 +4,7 @@ // #include "BackendRegistry.hpp" +#include <armnn/Exceptions.hpp> namespace armnn { @@ -14,4 +15,72 @@ BackendRegistry& BackendRegistryInstance() return instance; } +void BackendRegistry::Register(const BackendId& id, BackendRegistry::FactoryFunction factory) +{ + if (m_Factories.count(id) > 0) + { + throw InvalidArgumentException( + std::string(id) + " already registered as IBackend factory", + CHECK_LOCATION()); + } + + m_Factories[id] = factory; +} + +bool BackendRegistry::IsBackendRegistered(const BackendId& id) const +{ + return (m_Factories.find(id) != m_Factories.end()); +} + +BackendRegistry::FactoryFunction BackendRegistry::GetFactory(const BackendId& id) const +{ + auto it = m_Factories.find(id); + if (it == m_Factories.end()) + { + throw InvalidArgumentException( + std::string(id) + " has no IBackend factory registered", + CHECK_LOCATION()); + } + + return it->second; +} + +size_t BackendRegistry::Size() const +{ + return m_Factories.size(); +} + +BackendIdSet BackendRegistry::GetBackendIds() const +{ + BackendIdSet result; + for (const auto& it : m_Factories) + { + result.insert(it.first); + } + return result; +} + +std::string BackendRegistry::GetBackendIdsAsString() const +{ + static const std::string delimitator = ", "; + + std::stringstream output; + for (auto& backendId : GetBackendIds()) + { + if (output.tellp() != std::streampos(0)) + { + output << delimitator; + } + output << backendId; + } + + return output.str(); +} + +void BackendRegistry::Swap(BackendRegistry& instance, BackendRegistry::FactoryStorage& other) +{ + std::swap(instance.m_Factories, other); +} + + } // namespace armnn |