forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
so_extension.hpp
53 lines (41 loc) · 1.47 KB
/
so_extension.hpp
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 (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/extension.hpp"
#include "openvino/core/visibility.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
namespace ov {
namespace detail {
class OPENVINO_API SOExtension : public Extension {
public:
~SOExtension() {
m_ext = {};
}
SOExtension(const Extension::Ptr& ext, const std::shared_ptr<void>& so) : m_ext(ext), m_so(so) {}
const Extension::Ptr& extension() const;
const std::shared_ptr<void> shared_object() const;
private:
Extension::Ptr m_ext;
std::shared_ptr<void> m_so;
};
inline std::vector<Extension::Ptr> load_extensions(const std::string& path) {
auto so = ov::util::load_shared_object(path.c_str());
using CreateFunction = void(std::vector<Extension::Ptr>&);
std::vector<Extension::Ptr> extensions;
reinterpret_cast<CreateFunction*>(ov::util::get_symbol(so, "create_extensions"))(extensions);
std::vector<Extension::Ptr> so_extensions;
so_extensions.reserve(extensions.size());
for (auto&& ex : extensions) {
so_extensions.emplace_back(std::make_shared<SOExtension>(ex, so));
}
return so_extensions;
}
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
inline std::vector<Extension::Ptr> load_extensions(const std::wstring& path) {
return load_extensions(ov::util::wstring_to_string(path).c_str());
}
#endif
} // namespace detail
} // namespace ov