Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU]Move VCL API from compiler_adapter to utils (#34662)

Wenjing Kangdca3df78ec42
diff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
index 8f7205ee4a9..3aa5b01104f 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
@@ -2,13 +2,13 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_npu_driver_compiler_adapter")
+set(TARGET_NAME "openvino_npu_compiler_adapter")
file(GLOB_RECURSE SOURCES *.cpp *.hpp *.h)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
-add_library(${TARGET_NAME} STATIC ${SOURCES})
+add_library(${TARGET_NAME} STATIC ${SOURCES} $<TARGET_OBJECTS:openvino_npu_vcl_utils>)
ov_build_target_faster(${TARGET_NAME}
PCH_HEADER "src/precomp.hpp"
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
index ef43e128027..bf377bc382c 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp
@@ -7,8 +7,8 @@
#include <memory>
#include <optional>
-#include "compiler.h"
#include "intel_npu/common/filtered_config.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "openvino/core/except.hpp"
#include "openvino/core/model.hpp"
#include "openvino/runtime/common.hpp"
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
index 787f6f02136..c5c2caea423 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
@@ -11,6 +11,7 @@
#include "intel_npu/npu_private_properties.hpp"
#include "intel_npu/profiling.hpp"
#include "intel_npu/utils/utils.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "model_serializer.hpp"
#include "openvino/runtime/make_tensor.hpp"
#include "openvino/util/file_util.hpp"
@@ -111,74 +112,6 @@ ov::Tensor make_tensor_from_aligned_addr(uint8_t* allocated, size_t size) {
namespace intel_npu {
-// clang-format off
-#define vcl_symbols_list() \
- vcl_symbol_statement(vclGetVersion) \
- vcl_symbol_statement(vclCompilerCreate) \
- vcl_symbol_statement(vclCompilerDestroy) \
- vcl_symbol_statement(vclCompilerGetProperties) \
- vcl_symbol_statement(vclQueryNetworkCreate) \
- vcl_symbol_statement(vclQueryNetwork) \
- vcl_symbol_statement(vclQueryNetworkDestroy) \
- vcl_symbol_statement(vclExecutableCreate) \
- vcl_symbol_statement(vclAllocatedExecutableCreate) \
- vcl_symbol_statement(vclExecutableDestroy) \
- vcl_symbol_statement(vclExecutableGetSerializableBlob) \
- vcl_symbol_statement(vclProfilingCreate) \
- vcl_symbol_statement(vclGetDecodedProfilingBuffer) \
- vcl_symbol_statement(vclProfilingDestroy) \
- vcl_symbol_statement(vclProfilingGetProperties) \
- vcl_symbol_statement(vclLogHandleGetString) \
- vcl_symbol_statement(vclAllocatedExecutableCreate2) \
- vcl_symbol_statement(vclGetCompilerSupportedOptions) \
- vcl_symbol_statement(vclGetCompilerIsOptionSupported) \
-
-
-// symbols that may not be supported in older versions of vcl
-#define vcl_weak_symbols_list() \
- vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot)
-// clang-format on
-
-class VCLApi {
-public:
- VCLApi();
- VCLApi(const VCLApi& other) = delete;
- VCLApi(VCLApi&& other) = delete;
- void operator=(const VCLApi&) = delete;
- void operator=(VCLApi&&) = delete;
-
- static const std::shared_ptr<VCLApi> getInstance();
- std::shared_ptr<void> getLibrary() const {
- return lib;
- }
-
-#define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol;
- vcl_symbols_list();
- vcl_weak_symbols_list();
-#undef vcl_symbol_statement
-
-private:
- std::shared_ptr<void> lib;
- Logger _logger;
-};
-
-#define vcl_symbol_statement(vcl_symbol) \
- template <typename... Args> \
- inline typename std::invoke_result<decltype(&::vcl_symbol), Args...>::type wrapped_##vcl_symbol(Args... args) { \
- const auto& ptr = VCLApi::getInstance(); \
- if (ptr->vcl_symbol == nullptr) { \
- OPENVINO_THROW("Unsupported vcl_symbol " #vcl_symbol); \
- } \
- return ptr->vcl_symbol(std::forward<Args>(args)...); \
- }
-vcl_symbols_list();
-vcl_weak_symbols_list();
-#undef vcl_symbol_statement
-#define vcl_symbol_statement(vcl_symbol) inline decltype(&::vcl_symbol) vcl_symbol = wrapped_##vcl_symbol;
-vcl_symbols_list();
-vcl_weak_symbols_list();
-#undef vcl_symbol_statement
-
static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
Logger _logger("VCLAPI", Logger::global().level());
_logger.debug("getLatestVCLLog start");
@@ -229,60 +162,6 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
} \
}
-VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) {
- std::filesystem::path baseName = "openvino_intel_npu_compiler_loader";
- std::filesystem::path libpath{};
-
- try {
- libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
- _logger.debug("Try to load %s", baseName.string().c_str());
- this->lib = ov::util::load_shared_object(libpath);
- } catch (const std::runtime_error& error) {
- _logger.debug("Failed to load %s: %s", baseName.string().c_str(), error.what());
-
- // TODO: remove fallback loading logic after all components switch to "openvino_intel_npu_compiler_loader"
- baseName = "openvino_intel_npu_compiler";
- _logger.debug("Trying to load %s", baseName.string().c_str());
- try {
- libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
- this->lib = ov::util::load_shared_object(libpath);
- } catch (const std::runtime_error& error) {
- _logger.debug("Failed to load a fallback library: %s", baseName.string().c_str());
- OPENVINO_THROW(error.what());
- }
- }
-
- try {
-#define vcl_symbol_statement(vcl_symbol) \
- this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol));
- vcl_symbols_list();
-#undef vcl_symbol_statement
- } catch (const std::runtime_error& error) {
- _logger.debug("Failed to get formal symbols from %s", baseName.string().c_str());
- OPENVINO_THROW(error.what());
- }
-
-#define vcl_symbol_statement(vcl_symbol) \
- try { \
- this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); \
- } catch (const std::runtime_error&) { \
- _logger.debug("Failed to get %s from %s", #vcl_symbol, baseName.string().c_str()); \
- this->vcl_symbol = nullptr; \
- }
- vcl_weak_symbols_list();
-#undef vcl_symbol_statement
-
-#define vcl_symbol_statement(vcl_symbol) vcl_symbol = this->vcl_symbol;
- vcl_symbols_list();
- vcl_weak_symbols_list();
-#undef vcl_symbol_statement
-}
-
-const std::shared_ptr<VCLApi> VCLApi::getInstance() {
- static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>();
- return instance;
-}
-
const std::shared_ptr<VCLCompilerImpl> VCLCompilerImpl::getInstance() {
static std::mutex mutex;
static std::weak_ptr<VCLCompilerImpl> weak_compiler;
diff --git a/src/plugins/intel_npu/src/plugin/CMakeLists.txt b/src/plugins/intel_npu/src/plugin/CMakeLists.txt
index 25ef87220dd..1ad564c6dd1 100644
--- a/src/plugins/intel_npu/src/plugin/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/plugin/CMakeLists.txt
@@ -25,7 +25,7 @@ ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
target_link_libraries(${TARGET_NAME}
PRIVATE
openvino_npu_common
- openvino_npu_driver_compiler_adapter
+ openvino_npu_compiler_adapter
openvino_npu_level_zero_backend
)
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler.h b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl.h
similarity index 100%
rename from src/plugins/intel_npu/src/compiler_adapter/include/compiler.h
rename to src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl.h
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
new file mode 100644
index 00000000000..8e22dbab091
--- /dev/null
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp
@@ -0,0 +1,82 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+
+#include "vcl.h"
+#include "intel_npu/utils/logger/logger.hpp"
+#include "openvino/core/except.hpp"
+namespace intel_npu {
+
+// clang-format off
+#define vcl_symbols_list() \
+ vcl_symbol_statement(vclGetVersion) \
+ vcl_symbol_statement(vclCompilerCreate) \
+ vcl_symbol_statement(vclCompilerDestroy) \
+ vcl_symbol_statement(vclCompilerGetProperties) \
+ vcl_symbol_statement(vclQueryNetworkCreate) \
+ vcl_symbol_statement(vclQueryNetwork) \
+ vcl_symbol_statement(vclQueryNetworkDestroy) \
+ vcl_symbol_statement(vclExecutableCreate) \
+ vcl_symbol_statement(vclExecutableDestroy) \
+ vcl_symbol_statement(vclExecutableGetSerializableBlob) \
+ vcl_symbol_statement(vclProfilingCreate) \
+ vcl_symbol_statement(vclGetDecodedProfilingBuffer) \
+ vcl_symbol_statement(vclProfilingDestroy) \
+ vcl_symbol_statement(vclProfilingGetProperties) \
+ vcl_symbol_statement(vclLogHandleGetString) \
+ vcl_symbol_statement(vclAllocatedExecutableCreate2) \
+ vcl_symbol_statement(vclGetCompilerSupportedOptions) \
+ vcl_symbol_statement(vclGetCompilerIsOptionSupported) \
+
+
+// symbols that may not be supported in older versions of vcl
+#define vcl_weak_symbols_list() \
+ vcl_symbol_statement(vclAllocatedExecutableCreate) \
+ vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot)
+// clang-format on
+
+class VCLApi {
+public:
+ VCLApi();
+ VCLApi(const VCLApi& other) = delete;
+ VCLApi(VCLApi&& other) = delete;
+ void operator=(const VCLApi&) = delete;
+ void operator=(VCLApi&&) = delete;
+
+ static const std::shared_ptr<VCLApi> getInstance();
+ std::shared_ptr<void> getLibrary() const {
+ return lib;
+ }
+
+#define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol;
+ vcl_symbols_list();
+ vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+
+private:
+ std::shared_ptr<void> lib;
+ Logger _logger;
+};
+
+#define vcl_symbol_statement(vcl_symbol) \
+ template <typename... Args> \
+ inline typename std::invoke_result<decltype(&::vcl_symbol), Args...>::type wrapped_##vcl_symbol(Args... args) { \
+ const auto& ptr = VCLApi::getInstance(); \
+ if (ptr->vcl_symbol == nullptr) { \
+ OPENVINO_THROW("Unsupported vcl_symbol " #vcl_symbol); \
+ } \
+ return ptr->vcl_symbol(std::forward<Args>(args)...); \
+ }
+vcl_symbols_list();
+vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+#define vcl_symbol_statement(vcl_symbol) inline decltype(&::vcl_symbol) vcl_symbol = wrapped_##vcl_symbol;
+vcl_symbols_list();
+vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/utils/src/CMakeLists.txt b/src/plugins/intel_npu/src/utils/src/CMakeLists.txt
index 69ded78aefe..ec6493205c1 100644
--- a/src/plugins/intel_npu/src/utils/src/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/utils/src/CMakeLists.txt
@@ -5,5 +5,6 @@
add_subdirectory(logger)
if(ENABLE_NPU_PLUGIN_ENGINE)
+ add_subdirectory(vcl)
add_subdirectory(zero)
endif()
diff --git a/src/plugins/intel_npu/src/utils/src/vcl/CMakeLists.txt b/src/plugins/intel_npu/src/utils/src/vcl/CMakeLists.txt
new file mode 100644
index 00000000000..ee78f0c0597
--- /dev/null
+++ b/src/plugins/intel_npu/src/utils/src/vcl/CMakeLists.txt
@@ -0,0 +1,26 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+#
+
+set(TARGET_NAME openvino_npu_vcl_utils)
+
+file(GLOB_RECURSE SOURCES *.cpp)
+source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
+
+add_library(${TARGET_NAME} OBJECT ${SOURCES})
+set_target_properties(
+ ${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
+ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
+
+add_library(openvino::npu_vcl_utils ALIAS ${TARGET_NAME})
+
+target_include_directories(${TARGET_NAME}
+ PUBLIC
+ $<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include>
+ PRIVATE
+ $<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+if(NOT BUILD_SHARED_LIBS)
+ target_compile_definitions(${TARGET_NAME} PRIVATE OPENVINO_STATIC_LIBRARY)
+endif()
diff --git a/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp b/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
new file mode 100644
index 00000000000..86c8b2ba922
--- /dev/null
+++ b/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "intel_npu/utils/vcl/vcl_api.hpp"
+
+#include <mutex>
+
+#include "openvino/util/file_util.hpp"
+#include "openvino/util/shared_object.hpp"
+
+namespace intel_npu {
+VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) {
+ std::filesystem::path baseName = "openvino_intel_npu_compiler_loader";
+ std::filesystem::path libpath{};
+
+ try {
+ libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
+ _logger.debug("Try to load %s", baseName.string().c_str());
+ this->lib = ov::util::load_shared_object(libpath);
+ } catch (const std::runtime_error& error) {
+ _logger.debug("Failed to load %s: %s", baseName.string().c_str(), error.what());
+
+ // TODO: remove fallback loading logic after all components switch to "openvino_intel_npu_compiler_loader"
+ baseName = "openvino_intel_npu_compiler";
+ _logger.debug("Trying to load %s", baseName.string().c_str());
+ try {
+ libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName);
+ this->lib = ov::util::load_shared_object(libpath);
+ } catch (const std::runtime_error& error) {
+ _logger.debug("Failed to load a fallback library: %s", baseName.string().c_str());
+ OPENVINO_THROW(error.what());
+ }
+ }
+
+ try {
+#define vcl_symbol_statement(vcl_symbol) \
+ this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol));
+ vcl_symbols_list();
+#undef vcl_symbol_statement
+ } catch (const std::runtime_error& error) {
+ _logger.debug("Failed to get formal symbols from %s", baseName.string().c_str());
+ OPENVINO_THROW(error.what());
+ }
+
+#define vcl_symbol_statement(vcl_symbol) \
+ try { \
+ this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol)); \
+ } catch (const std::runtime_error&) { \
+ _logger.debug("Failed to get %s from %s", #vcl_symbol, baseName.string().c_str()); \
+ this->vcl_symbol = nullptr; \
+ }
+ vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+
+#define vcl_symbol_statement(vcl_symbol) vcl_symbol = this->vcl_symbol;
+ vcl_symbols_list();
+ vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+}
+
+const std::shared_ptr<VCLApi> VCLApi::getInstance() {
+ static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>();
+ return instance;
+}
+
+} // namespace intel_npu
diff --git a/src/plugins/intel_npu/tests/functional/CMakeLists.txt b/src/plugins/intel_npu/tests/functional/CMakeLists.txt
index 46bf0c03c95..3287750219b 100644
--- a/src/plugins/intel_npu/tests/functional/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/functional/CMakeLists.txt
@@ -22,7 +22,7 @@ list(APPEND OPTIONAL_FUNC_TESTS_INCLUDES
"${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/include"
)
-list(APPEND OPTIONAL_FUNC_TESTS_LIBS openvino_npu_common openvino_npu_driver_compiler_adapter
+list(APPEND OPTIONAL_FUNC_TESTS_LIBS openvino_npu_common openvino_npu_compiler_adapter
openvino_npu_level_zero_backend openvino_npu_zero_utils openvino_npu_logger_utils)
ov_add_test_target(