Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target_link_libraries(${TARGET_NAME}
openvino::npu_al
openvino::xml_util
openvino::npu_vm_runtime_api
openvino::npu_vcl_utils
)

#
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/intel_npu/src/compiler_adapter/include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
111 changes: 1 addition & 110 deletions src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -134,74 +135,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");
Expand Down Expand Up @@ -252,48 +185,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<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 openvino_intel_npu_compiler");
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 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> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <memory>

#include "compiler.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<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
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/utils/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

add_subdirectory(logger)
add_subdirectory(vcl)

if(ENABLE_NPU_PLUGIN_ENGINE)
add_subdirectory(zero)
Expand Down
36 changes: 36 additions & 0 deletions src/plugins/intel_npu/src/utils/src/vcl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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})
set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME npu_vcl_utils)

message(STATUS "NPU_UTILS_SOURCE_DIR IS ${NPU_UTILS_SOURCE_DIR}")
message(STATUS "NPU_COMPILER_ADAPTER_SRC_DIR IS ${NPU_COMPILER_ADAPTER_SRC_DIR}")
target_include_directories(${TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/../compiler_adapter/include>
)
target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime::dev openvino_npu_logger_utils)

#
# targets install
#

ov_install_static_lib(${TARGET_NAME} ${NPU_PLUGIN_COMPONENT})

ov_developer_package_export_targets(TARGET openvino::npu_vcl_utils
INSTALL_INCLUDE_DIRECTORIES
$<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include>/)

55 changes: 55 additions & 0 deletions src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
Original file line number Diff line number Diff line change
@@ -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 <mutex>

#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<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 openvino_intel_npu_compiler");
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 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> VCLApi::getInstance() {
static std::shared_ptr<VCLApi> instance = std::make_shared<VCLApi>();
return instance;
}

} // namespace intel_npu
Loading