Skip to content

Commit 99e7fb8

Browse files
Move VCL API to utils
Signed-off-by: Kang, Wenjing <wenjing.kang@intel.com>
1 parent 4188f16 commit 99e7fb8

File tree

8 files changed

+168
-122
lines changed

8 files changed

+168
-122
lines changed

src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ target_link_libraries(${TARGET_NAME}
2828
openvino::npu_al
2929
openvino::xml_util
3030
openvino::npu_vm_runtime_api
31+
openvino::npu_vcl_utils
3132
)
3233

3334
#

src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <memory>
88
#include <optional>
99

10-
#include "compiler.h"
10+
#include "intel_npu/utils/vcl/vcl_api.hpp"
1111
#include "intel_npu/common/filtered_config.hpp"
1212
#include "intel_npu/network_metadata.hpp"
1313
#include "openvino/core/except.hpp"

src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "intel_npu/npu_private_properties.hpp"
1212
#include "intel_npu/profiling.hpp"
1313
#include "intel_npu/utils/utils.hpp"
14+
#include "intel_npu/utils/vcl/vcl_api.hpp"
1415
#include "model_serializer.hpp"
1516
#include "openvino/runtime/make_tensor.hpp"
1617
#include "openvino/util/file_util.hpp"
@@ -111,74 +112,6 @@ ov::Tensor make_tensor_from_aligned_addr(uint8_t* allocated, size_t size) {
111112

112113
namespace intel_npu {
113114

114-
// clang-format off
115-
#define vcl_symbols_list() \
116-
vcl_symbol_statement(vclGetVersion) \
117-
vcl_symbol_statement(vclCompilerCreate) \
118-
vcl_symbol_statement(vclCompilerDestroy) \
119-
vcl_symbol_statement(vclCompilerGetProperties) \
120-
vcl_symbol_statement(vclQueryNetworkCreate) \
121-
vcl_symbol_statement(vclQueryNetwork) \
122-
vcl_symbol_statement(vclQueryNetworkDestroy) \
123-
vcl_symbol_statement(vclExecutableCreate) \
124-
vcl_symbol_statement(vclAllocatedExecutableCreate) \
125-
vcl_symbol_statement(vclExecutableDestroy) \
126-
vcl_symbol_statement(vclExecutableGetSerializableBlob) \
127-
vcl_symbol_statement(vclProfilingCreate) \
128-
vcl_symbol_statement(vclGetDecodedProfilingBuffer) \
129-
vcl_symbol_statement(vclProfilingDestroy) \
130-
vcl_symbol_statement(vclProfilingGetProperties) \
131-
vcl_symbol_statement(vclLogHandleGetString) \
132-
vcl_symbol_statement(vclAllocatedExecutableCreate2) \
133-
vcl_symbol_statement(vclGetCompilerSupportedOptions) \
134-
vcl_symbol_statement(vclGetCompilerIsOptionSupported) \
135-
136-
137-
// symbols that may not be supported in older versions of vcl
138-
#define vcl_weak_symbols_list() \
139-
vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot)
140-
// clang-format on
141-
142-
class VCLApi {
143-
public:
144-
VCLApi();
145-
VCLApi(const VCLApi& other) = delete;
146-
VCLApi(VCLApi&& other) = delete;
147-
void operator=(const VCLApi&) = delete;
148-
void operator=(VCLApi&&) = delete;
149-
150-
static const std::shared_ptr<VCLApi> getInstance();
151-
std::shared_ptr<void> getLibrary() const {
152-
return lib;
153-
}
154-
155-
#define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol;
156-
vcl_symbols_list();
157-
vcl_weak_symbols_list();
158-
#undef vcl_symbol_statement
159-
160-
private:
161-
std::shared_ptr<void> lib;
162-
Logger _logger;
163-
};
164-
165-
#define vcl_symbol_statement(vcl_symbol) \
166-
template <typename... Args> \
167-
inline typename std::invoke_result<decltype(&::vcl_symbol), Args...>::type wrapped_##vcl_symbol(Args... args) { \
168-
const auto& ptr = VCLApi::getInstance(); \
169-
if (ptr->vcl_symbol == nullptr) { \
170-
OPENVINO_THROW("Unsupported vcl_symbol " #vcl_symbol); \
171-
} \
172-
return ptr->vcl_symbol(std::forward<Args>(args)...); \
173-
}
174-
vcl_symbols_list();
175-
vcl_weak_symbols_list();
176-
#undef vcl_symbol_statement
177-
#define vcl_symbol_statement(vcl_symbol) inline decltype(&::vcl_symbol) vcl_symbol = wrapped_##vcl_symbol;
178-
vcl_symbols_list();
179-
vcl_weak_symbols_list();
180-
#undef vcl_symbol_statement
181-
182115
static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
183116
Logger _logger("VCLAPI", Logger::global().level());
184117
_logger.debug("getLatestVCLLog start");
@@ -229,48 +162,6 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
229162
} \
230163
}
231164

232-
VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) {
233-
const std::filesystem::path baseName = "openvino_intel_npu_compiler";
234-
try {
235-
auto libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
236-
_logger.debug("Try to load openvino_intel_npu_compiler");
237-
this->lib = ov::util::load_shared_object(libpath);
238-
} catch (const std::runtime_error& error) {
239-
_logger.debug("Failed to load openvino_intel_npu_compiler");
240-
OPENVINO_THROW(error.what());
241-
}
242-
243-
try {
244-
#define vcl_symbol_statement(vcl_symbol) \
245-
this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol));
246-
vcl_symbols_list();
247-
#undef vcl_symbol_statement
248-
} catch (const std::runtime_error& error) {
249-
_logger.debug("Failed to get formal symbols from openvino_intel_npu_compiler");
250-
OPENVINO_THROW(error.what());
251-
}
252-
253-
#define vcl_symbol_statement(vcl_symbol) \
254-
try { \
255-
this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); \
256-
} catch (const std::runtime_error&) { \
257-
_logger.debug("Failed to get %s from openvino_intel_npu_compiler", #vcl_symbol); \
258-
this->vcl_symbol = nullptr; \
259-
}
260-
vcl_weak_symbols_list();
261-
#undef vcl_symbol_statement
262-
263-
#define vcl_symbol_statement(vcl_symbol) vcl_symbol = this->vcl_symbol;
264-
vcl_symbols_list();
265-
vcl_weak_symbols_list();
266-
#undef vcl_symbol_statement
267-
}
268-
269-
const std::shared_ptr<VCLApi> VCLApi::getInstance() {
270-
static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>();
271-
return instance;
272-
}
273-
274165
const std::shared_ptr<VCLCompilerImpl> VCLCompilerImpl::getInstance() {
275166
static std::mutex mutex;
276167
static std::weak_ptr<VCLCompilerImpl> weak_compiler;

src/plugins/intel_npu/src/compiler_adapter/include/compiler.h renamed to src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,11 @@ VCL_APIEXPORT vcl_result_t VCL_APICALL vclExecutableCreate(vcl_compiler_handle_t
249249
vcl_executable_desc_t desc,
250250
vcl_executable_handle_t* executable);
251251

252-
DEPRECATED typedef struct __vcl_allocator_t {
253-
uint8_t* (*allocate)(uint64_t);
254-
void (*deallocate)(uint8_t*);
255-
} vcl_allocator_t;
256-
257252
typedef struct __vcl_allocator2_t {
258253
uint8_t* (*allocate)(struct __vcl_allocator2_t*, uint64_t);
259254
void (*deallocate)(struct __vcl_allocator2_t*, uint8_t*);
260255
} vcl_allocator2_t;
261256

262-
DEPRECATED VCL_APIEXPORT vcl_result_t VCL_APICALL vclAllocatedExecutableCreate(vcl_compiler_handle_t compiler,
263-
vcl_executable_desc_t desc,
264-
const vcl_allocator_t* allocator,
265-
uint8_t** blobBuffer,
266-
uint64_t* blobSize);
267-
268257
VCL_APIEXPORT vcl_result_t VCL_APICALL vclAllocatedExecutableCreate2(vcl_compiler_handle_t compiler,
269258
vcl_executable_desc_t desc,
270259
vcl_allocator2_t* allocator,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (C) 2018-2026 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include <memory>
8+
9+
#include "vcl.h"
10+
#include "intel_npu/utils/logger/logger.hpp"
11+
#include "openvino/core/except.hpp"
12+
namespace intel_npu {
13+
14+
// clang-format off
15+
#define vcl_symbols_list() \
16+
vcl_symbol_statement(vclGetVersion) \
17+
vcl_symbol_statement(vclCompilerCreate) \
18+
vcl_symbol_statement(vclCompilerDestroy) \
19+
vcl_symbol_statement(vclCompilerGetProperties) \
20+
vcl_symbol_statement(vclQueryNetworkCreate) \
21+
vcl_symbol_statement(vclQueryNetwork) \
22+
vcl_symbol_statement(vclQueryNetworkDestroy) \
23+
vcl_symbol_statement(vclExecutableCreate) \
24+
vcl_symbol_statement(vclExecutableDestroy) \
25+
vcl_symbol_statement(vclExecutableGetSerializableBlob) \
26+
vcl_symbol_statement(vclProfilingCreate) \
27+
vcl_symbol_statement(vclGetDecodedProfilingBuffer) \
28+
vcl_symbol_statement(vclProfilingDestroy) \
29+
vcl_symbol_statement(vclProfilingGetProperties) \
30+
vcl_symbol_statement(vclLogHandleGetString) \
31+
vcl_symbol_statement(vclAllocatedExecutableCreate2) \
32+
vcl_symbol_statement(vclGetCompilerSupportedOptions) \
33+
vcl_symbol_statement(vclGetCompilerIsOptionSupported) \
34+
35+
36+
// symbols that may not be supported in older versions of vcl
37+
#define vcl_weak_symbols_list() \
38+
vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot)
39+
// clang-format on
40+
41+
class VCLApi {
42+
public:
43+
VCLApi();
44+
VCLApi(const VCLApi& other) = delete;
45+
VCLApi(VCLApi&& other) = delete;
46+
void operator=(const VCLApi&) = delete;
47+
void operator=(VCLApi&&) = delete;
48+
49+
static const std::shared_ptr<VCLApi> getInstance();
50+
std::shared_ptr<void> getLibrary() const {
51+
return lib;
52+
}
53+
54+
#define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol;
55+
vcl_symbols_list();
56+
vcl_weak_symbols_list();
57+
#undef vcl_symbol_statement
58+
59+
private:
60+
std::shared_ptr<void> lib;
61+
Logger _logger;
62+
};
63+
64+
#define vcl_symbol_statement(vcl_symbol) \
65+
template <typename... Args> \
66+
inline typename std::invoke_result<decltype(&::vcl_symbol), Args...>::type wrapped_##vcl_symbol(Args... args) { \
67+
const auto& ptr = VCLApi::getInstance(); \
68+
if (ptr->vcl_symbol == nullptr) { \
69+
OPENVINO_THROW("Unsupported vcl_symbol " #vcl_symbol); \
70+
} \
71+
return ptr->vcl_symbol(std::forward<Args>(args)...); \
72+
}
73+
vcl_symbols_list();
74+
vcl_weak_symbols_list();
75+
#undef vcl_symbol_statement
76+
#define vcl_symbol_statement(vcl_symbol) inline decltype(&::vcl_symbol) vcl_symbol = wrapped_##vcl_symbol;
77+
vcl_symbols_list();
78+
vcl_weak_symbols_list();
79+
#undef vcl_symbol_statement
80+
81+
} // namespace intel_npu

src/plugins/intel_npu/src/utils/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
add_subdirectory(logger)
6+
add_subdirectory(vcl)
67

78
if(ENABLE_NPU_PLUGIN_ENGINE)
89
add_subdirectory(zero)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (C) 2018-2026 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
5+
set(TARGET_NAME openvino_npu_vcl_utils)
6+
7+
file(GLOB_RECURSE SOURCES *.cpp)
8+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
9+
10+
add_library(${TARGET_NAME} STATIC ${SOURCES})
11+
set_target_properties(
12+
${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
13+
ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
14+
15+
add_library(openvino::npu_vcl_utils ALIAS ${TARGET_NAME})
16+
17+
target_include_directories(${TARGET_NAME}
18+
PUBLIC
19+
$<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include>
20+
)
21+
target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime::dev openvino_npu_logger_utils)
22+
23+
#
24+
# targets install
25+
#
26+
27+
ov_install_static_lib(${TARGET_NAME} ${NPU_PLUGIN_COMPONENT})
28+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (C) 2018-2026 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "intel_npu/utils/vcl/vcl_api.hpp"
6+
7+
#include <mutex>
8+
9+
#include "openvino/util/file_util.hpp"
10+
#include "openvino/util/shared_object.hpp"
11+
12+
namespace intel_npu {
13+
VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) {
14+
const std::filesystem::path baseName = "openvino_intel_npu_compiler";
15+
try {
16+
auto libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
17+
_logger.debug("Try to load openvino_intel_npu_compiler");
18+
this->lib = ov::util::load_shared_object(libpath);
19+
} catch (const std::runtime_error& error) {
20+
_logger.debug("Failed to load openvino_intel_npu_compiler");
21+
OPENVINO_THROW(error.what());
22+
}
23+
24+
try {
25+
#define vcl_symbol_statement(vcl_symbol) \
26+
this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol));
27+
vcl_symbols_list();
28+
#undef vcl_symbol_statement
29+
} catch (const std::runtime_error& error) {
30+
_logger.debug("Failed to get formal symbols from openvino_intel_npu_compiler");
31+
OPENVINO_THROW(error.what());
32+
}
33+
34+
#define vcl_symbol_statement(vcl_symbol) \
35+
try { \
36+
this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); \
37+
} catch (const std::runtime_error&) { \
38+
_logger.debug("Failed to get %s from openvino_intel_npu_compiler", #vcl_symbol); \
39+
this->vcl_symbol = nullptr; \
40+
}
41+
vcl_weak_symbols_list();
42+
#undef vcl_symbol_statement
43+
44+
#define vcl_symbol_statement(vcl_symbol) vcl_symbol = this->vcl_symbol;
45+
vcl_symbols_list();
46+
vcl_weak_symbols_list();
47+
#undef vcl_symbol_statement
48+
}
49+
50+
const std::shared_ptr<VCLApi> VCLApi::getInstance() {
51+
static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>();
52+
return instance;
53+
}
54+
55+
} // namespace intel_npu

0 commit comments

Comments
 (0)