aboutsummaryrefslogtreecommitdiff
path: root/src/backends/BackendRegistry.hpp
blob: e2c526d293af0bb22dd5ffa040dd8ab6c4744235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once

#include <armnn/Types.hpp>
#include <functional>
#include <memory>
#include <unordered_map>

namespace armnn
{

class IBackend;

class BackendRegistry
{
public:
    using FactoryFunction = std::function<IBackendUniquePtr()>;

    static BackendRegistry& Instance();

    void Register(const BackendId& id, FactoryFunction factory);
    FactoryFunction GetFactory(const BackendId& id) const;

    struct Helper
    {
        Helper(const BackendId& id, FactoryFunction factory)
        {
            BackendRegistry::Instance().Register(id, factory);
        }
    };

    size_t Size() const { return m_BackendFactories.size(); }
    BackendIdSet GetBackendIds() const;

protected:
    using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>;

    // For testing only
    static void Swap(FactoryStorage& other);
    BackendRegistry() {}
    ~BackendRegistry() {}

private:
    BackendRegistry(const BackendRegistry&) = delete;
    BackendRegistry& operator=(const BackendRegistry&) = delete;

    FactoryStorage m_BackendFactories;
};

} // namespace armnn