aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/DynamicBackend.hpp
blob: b202309c314cac46eda0c8b61e5418a969886145 (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
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include "IBackendInternal.hpp"

#include <functional>
#include <memory>

namespace armnn
{

class DynamicBackend
{
public:
    using HandleCloser = std::function<void(const void*)>;
    using HandlePtr = std::unique_ptr<void, HandleCloser>;

    explicit DynamicBackend(const void* sharedObjectHandle);

    /// Public dynamic backend functions
    BackendId GetBackendId();
    BackendVersion GetBackendVersion();
    IBackendInternalUniquePtr GetBackend();

private:
    template<typename BackendFunctionType>
    BackendFunctionType SetFunctionPointer(const std::string& backendFunctionName);

    /// Backend function pointer types
    using IdFunctionType      = const char*(*)();
    using VersionFunctionType = void(*)(uint32_t*, uint32_t*);
    using FactoryFunctionType = void*(*)();

    /// Backend function pointers
    IdFunctionType      m_BackendIdFunction;
    VersionFunctionType m_BackendVersionFunction;
    FactoryFunctionType m_BackendFactoryFunction;

    /// Shared object handle
    HandlePtr m_Handle;
};

using DynamicBackendPtr = std::unique_ptr<DynamicBackend>;

} // namespace armnn