blob: 6bedec4580c8bc3f43fbdb7cd6833be44d780362 (
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
54
55
56
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include <armnn/Exceptions.hpp>
#include <string>
#include <dlfcn.h>
#include <boost/format.hpp>
namespace armnn
{
class DynamicBackendUtils
{
public:
static void* OpenHandle(const std::string& sharedObjectPath);
static void CloseHandle(const void* sharedObjectHandle);
template<typename EntryPointType>
static EntryPointType GetEntryPoint(const void* sharedObjectHandle, const char* symbolName);
private:
static std::string GetDlError();
/// This class is to hold utility functions only
DynamicBackendUtils() = delete;
};
template<typename EntryPointType>
EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle, const char* symbolName)
{
if (sharedObjectHandle == nullptr)
{
throw RuntimeException("GetEntryPoint error: invalid handle");
}
if (symbolName == nullptr)
{
throw RuntimeException("GetEntryPoint error: invalid symbol");
}
auto entryPoint = reinterpret_cast<EntryPointType>(dlsym(const_cast<void*>(sharedObjectHandle), symbolName));
if (!entryPoint)
{
throw RuntimeException(boost::str(boost::format("GetEntryPoint error: %1") % GetDlError()));
}
return entryPoint;
}
} // namespace armnn
|