diff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt index 8f7205ee4a917d..f208703fd07035 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt +++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries(${TARGET_NAME} openvino::npu_al openvino::xml_util openvino::npu_vm_runtime_api + openvino::npu_vcl_utils ) # 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 e4242dc01770ff..3c2dbc48d5531a 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,9 +7,9 @@ #include #include -#include "compiler.h" #include "intel_npu/common/filtered_config.hpp" #include "intel_npu/network_metadata.hpp" +#include "intel_npu/utils/vcl/vcl_api.hpp" #include "openvino/core/except.hpp" namespace intel_npu { 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 cc843bc30c528b..b544a064c17cff 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 getInstance(); - std::shared_ptr 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 lib; - Logger _logger; -}; - -#define vcl_symbol_statement(vcl_symbol) \ - template \ - inline typename std::invoke_result::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)...); \ - } -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,48 +162,6 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) { } \ } -VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) { - const std::filesystem::path baseName = "openvino_intel_npu_compiler"; - try { - auto libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName); - _logger.debug("Try to load openvino_intel_npu_compiler"); - this->lib = ov::util::load_shared_object(libpath); - } catch (const std::runtime_error& error) { - _logger.debug("Failed to load openvino_intel_npu_compiler"); - OPENVINO_THROW(error.what()); - } - - try { -#define vcl_symbol_statement(vcl_symbol) \ - this->vcl_symbol = reinterpret_cast(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 openvino_intel_npu_compiler"); - OPENVINO_THROW(error.what()); - } - -#define vcl_symbol_statement(vcl_symbol) \ - try { \ - this->vcl_symbol = reinterpret_cast(ov::util::get_symbol(lib, #vcl_symbol)); \ - } catch (const std::runtime_error&) { \ - _logger.debug("Failed to get %s from openvino_intel_npu_compiler", #vcl_symbol); \ - 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::getInstance() { - static std::shared_ptr instance = std::make_shared(); - return instance; -} - const std::shared_ptr VCLCompilerImpl::getInstance() { static std::mutex mutex; static std::weak_ptr weak_compiler; 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 96% 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 index a7f58240d0e43a..bbb96f7ed5e081 100644 --- 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 @@ -249,22 +249,11 @@ VCL_APIEXPORT vcl_result_t VCL_APICALL vclExecutableCreate(vcl_compiler_handle_t vcl_executable_desc_t desc, vcl_executable_handle_t* executable); -DEPRECATED typedef struct __vcl_allocator_t { - uint8_t* (*allocate)(uint64_t); - void (*deallocate)(uint8_t*); -} vcl_allocator_t; - typedef struct __vcl_allocator2_t { uint8_t* (*allocate)(struct __vcl_allocator2_t*, uint64_t); void (*deallocate)(struct __vcl_allocator2_t*, uint8_t*); } vcl_allocator2_t; -DEPRECATED VCL_APIEXPORT vcl_result_t VCL_APICALL vclAllocatedExecutableCreate(vcl_compiler_handle_t compiler, - vcl_executable_desc_t desc, - const vcl_allocator_t* allocator, - uint8_t** blobBuffer, - uint64_t* blobSize); - VCL_APIEXPORT vcl_result_t VCL_APICALL vclAllocatedExecutableCreate2(vcl_compiler_handle_t compiler, vcl_executable_desc_t desc, vcl_allocator2_t* allocator, 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 00000000000000..27173568aaacfb --- /dev/null +++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vcl/vcl_api.hpp @@ -0,0 +1,81 @@ +// Copyright (C) 2018-2026 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#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(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 getInstance(); + std::shared_ptr 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 lib; + Logger _logger; +}; + +#define vcl_symbol_statement(vcl_symbol) \ + template \ + inline typename std::invoke_result::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)...); \ + } +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 69ded78aefebe5..373404dc39c3d5 100644 --- a/src/plugins/intel_npu/src/utils/src/CMakeLists.txt +++ b/src/plugins/intel_npu/src/utils/src/CMakeLists.txt @@ -3,6 +3,7 @@ # add_subdirectory(logger) +add_subdirectory(vcl) if(ENABLE_NPU_PLUGIN_ENGINE) add_subdirectory(zero) 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 00000000000000..d3799d406e9e63 --- /dev/null +++ b/src/plugins/intel_npu/src/utils/src/vcl/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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} STATIC ${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 + $ +) +target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime::dev openvino_npu_logger_utils) + +# +# targets install +# + +ov_install_static_lib(${TARGET_NAME} ${NPU_PLUGIN_COMPONENT}) + \ No newline at end of file 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 00000000000000..21c06e150f8f2a --- /dev/null +++ b/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2018-2026 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "intel_npu/utils/vcl/vcl_api.hpp" + +#include + +#include "openvino/util/file_util.hpp" +#include "openvino/util/shared_object.hpp" + +namespace intel_npu { +VCLApi::VCLApi() : _logger("VCLApi", Logger::global().level()) { + const std::filesystem::path baseName = "openvino_intel_npu_compiler"; + try { + auto libpath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName); + _logger.debug("Try to load openvino_intel_npu_compiler"); + this->lib = ov::util::load_shared_object(libpath); + } catch (const std::runtime_error& error) { + _logger.debug("Failed to load openvino_intel_npu_compiler"); + OPENVINO_THROW(error.what()); + } + + try { +#define vcl_symbol_statement(vcl_symbol) \ + this->vcl_symbol = reinterpret_cast(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 openvino_intel_npu_compiler"); + OPENVINO_THROW(error.what()); + } + +#define vcl_symbol_statement(vcl_symbol) \ + try { \ + this->vcl_symbol = reinterpret_cast(ov::util::get_symbol(lib, #vcl_symbol)); \ + } catch (const std::runtime_error&) { \ + _logger.debug("Failed to get %s from openvino_intel_npu_compiler", #vcl_symbol); \ + 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::getInstance() { + static std::shared_ptr instance = std::make_shared(); + return instance; +} + +} // namespace intel_npu