Skip to content

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

[NPU] Extract the VCL dependency from VCLCompilerImpl (#37778)

Patrik Stepana3e9792a73b6
diff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
index 6ad1cff7d3e..edd84e80c69 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt
@@ -14,6 +14,7 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/include/model_serializer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/parser.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/plugin_compiler_adapter.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/vcl_version_utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/weightless_graph.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/weightless_utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/xml_serializer.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 7d2865db129..2b8528fd623 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
@@ -4,8 +4,12 @@
#pragma once
+#include <cstdint>
#include <memory>
#include <optional>
+#include <string>
+#include <utility>
+#include <vector>
#include "intel_npu/common/filtered_config.hpp"
#include "intel_npu/common/npu.hpp"
@@ -20,7 +24,7 @@ namespace intel_npu {
class VCLCompilerImpl final : public std::enable_shared_from_this<VCLCompilerImpl> {
public:
- VCLCompilerImpl(const std::string& libraryDir,
+ VCLCompilerImpl(std::shared_ptr<const VCLFunctionTable> functions,
const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt);
~VCLCompilerImpl();
@@ -85,7 +89,7 @@ public:
/**
* @brief Returns the compiler supported options list
*/
- void get_supported_options(std::vector<char>& options) const;
+ std::vector<std::string> get_supported_options() const;
/**
* @brief Checks whether the given option and value are supported by the compiler
@@ -96,8 +100,6 @@ public:
bool is_option_supported(const std::string& option,
const std::optional<std::string>& optValue = std::nullopt) const;
- std::shared_ptr<void> getLinkedLibrary() const;
-
private:
/**
* @brief Compiles the given model according to the given configuration. During the model serialization step,
@@ -108,6 +110,7 @@ private:
const FilteredConfig& config,
const bool storeWeightlessCacheAttributeFlag) const;
+ std::shared_ptr<const VCLFunctionTable> _functions;
vcl_log_handle_t _logHandle = nullptr;
vcl_compiler_handle_t _compilerHandle = nullptr;
vcl_compiler_properties_t _compilerProperties;
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/vcl_version_utils.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_version_utils.hpp
new file mode 100644
index 00000000000..e775ce2cb94
--- /dev/null
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/vcl_version_utils.hpp
@@ -0,0 +1,71 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <cstdint>
+
+#include "openvino/core/except.hpp"
+
+namespace intel_npu::vcl_version_utils {
+
+/**
+ * @brief The VCL API version the plugin will actually speak: the lower of what the plugin was built
+ * against and what the loaded compiler library reports.
+ */
+struct UsedVersion {
+ uint16_t Major;
+ uint16_t Minor;
+};
+
+/**
+ * @brief Negotiates the VCL version to use.
+ *
+ * Expressed in plain integers rather than `vcl_version_info_t`, since the negotiation itself has no
+ * dependency on VCL types.
+ *
+ * - Same major: take the lower minor.
+ * - Plugin major newer than the library: downgrade to the library's version.
+ * - Plugin major older than the library: keep the plugin's version.
+ */
+inline UsedVersion getUsedVclVersion(uint16_t pluginMajor,
+ uint16_t pluginMinor,
+ uint16_t loadedMajor,
+ uint16_t loadedMinor) {
+ uint16_t usedMajor = pluginMajor, usedMinor = pluginMinor;
+ if (pluginMajor == loadedMajor) {
+ usedMinor = std::min(pluginMinor, loadedMinor);
+ } else if (pluginMajor > loadedMajor) {
+ usedMajor = loadedMajor;
+ usedMinor = loadedMinor;
+ }
+ return {usedMajor, usedMinor};
+}
+
+/**
+ * @brief Throws if the negotiated version is below the floor the plugin requires.
+ * @param usedVersion Result of `getUsedVclVersion`.
+ * @param loadedMajor,loadedMinor Version reported by the compiler library, used for the message.
+ * @param floorMajor,floorMinor Minimum version the plugin supports (`VCL_COMPILER_VERSION_*`).
+ */
+inline void checkVclVersion(const UsedVersion& usedVersion,
+ uint16_t loadedMajor,
+ uint16_t loadedMinor,
+ uint16_t floorMajor,
+ uint16_t floorMinor) {
+ if (usedVersion.Major < floorMajor || (usedVersion.Major == floorMajor && usedVersion.Minor < floorMinor)) {
+ OPENVINO_THROW("Unsupported VCL version: ",
+ loadedMajor,
+ ".",
+ loadedMinor,
+ ", please use VCL ",
+ floorMajor,
+ ".",
+ floorMinor,
+ " or later");
+ }
+}
+
+} // namespace intel_npu::vcl_version_utils
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 a784b507b9b..ac967a34c18 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
@@ -5,8 +5,11 @@
#include "compiler_impl.hpp"
#include <algorithm>
+#include <cstring>
#include <limits>
#include <mutex>
+#include <sstream>
+#include <utility>
#include "intel_npu/config/options.hpp"
#include "intel_npu/npu_private_properties.hpp"
@@ -18,54 +21,23 @@
#include "openvino/runtime/make_tensor.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
+#include "vcl_version_utils.hpp"
#include "weightless_utils.hpp"
#include "ze_graph_ext_wrappers.hpp"
-namespace {
-
-struct UsedVersion {
- int Major;
- int Minor;
- UsedVersion(int major, int minor) : Major(major), Minor(minor) {}
-};
-
-UsedVersion getUsedVclVersion(uint16_t pluginMajor, uint16_t pluginMinor, const vcl_version_info_t& loadedVersion) {
- uint16_t usedMajor = pluginMajor, usedMinor = pluginMinor;
- if (pluginMajor == loadedVersion.major) {
- usedMinor = std::min(pluginMinor, loadedVersion.minor);
- } else if (pluginMajor > loadedVersion.major) {
- usedMajor = loadedVersion.major;
- usedMinor = loadedVersion.minor;
- }
- return {usedMajor, usedMinor};
-}
-
-void checkVclVersion(const UsedVersion& usedVersion, const vcl_version_info_t& loadedVersion) {
- if (usedVersion.Major < VCL_COMPILER_VERSION_MAJOR ||
- (usedVersion.Major == VCL_COMPILER_VERSION_MAJOR && usedVersion.Minor < VCL_COMPILER_VERSION_MINOR)) {
- OPENVINO_THROW("Unsupported VCL version: ",
- loadedVersion.major,
- ".",
- loadedVersion.minor,
- ", please use VCL ",
- VCL_COMPILER_VERSION_MAJOR,
- ".",
- VCL_COMPILER_VERSION_MINOR,
- " or later");
- }
-}
-
-} // namespace
-
namespace intel_npu {
-static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
+using vcl_version_utils::checkVclVersion;
+using vcl_version_utils::getUsedVclVersion;
+using vcl_version_utils::UsedVersion;
+
+static inline std::string getLatestVCLLog(const VCLFunctionTable& functions, vcl_log_handle_t logHandle) {
Logger _logger("VCLAPI", Logger::global().level());
_logger.debug("getLatestVCLLog start");
vcl_version_info_t compilerVersion;
vcl_version_info_t profilingVersion;
- vcl_result_t ret = vclGetVersion(&compilerVersion, &profilingVersion);
+ vcl_result_t ret = functions.vclGetVersion(&compilerVersion, &profilingVersion);
if (ret != VCL_RESULT_SUCCESS || compilerVersion.major < 3) {
_logger.warning("Failed to get VCL version: 0x%x", ret);
@@ -75,7 +47,7 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
// Get log size
size_t size = 0;
// Null graph handle to get error log
- ret = vclLogHandleGetString(logHandle, &size, nullptr);
+ ret = functions.vclLogHandleGetString(logHandle, &size, nullptr);
if (VCL_RESULT_SUCCESS != ret) {
return "Failed to get size of latest VCL log";
}
@@ -87,7 +59,7 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
// Get log content
std::string logContent{};
logContent.resize(size);
- ret = vclLogHandleGetString(logHandle, &size, const_cast<char*>(logContent.data()));
+ ret = functions.vclLogHandleGetString(logHandle, &size, logContent.data());
if (VCL_RESULT_SUCCESS != ret) {
return "Size of latest error log > 0, failed to get content";
}
@@ -95,10 +67,11 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {
return logContent;
}
-static std::optional<std::string> getVCLCompatibilityString(vcl_executable_handle_t executable,
+static std::optional<std::string> getVCLCompatibilityString(const VCLFunctionTable& functions,
+ vcl_executable_handle_t executable,
vcl_log_handle_t logHandle) {
uint64_t compatibilityStringSize = 0;
- auto result = vclExecutableGetCompatibilityString(executable, nullptr, &compatibilityStringSize);
+ auto result = functions.vclExecutableGetCompatibilityString(executable, nullptr, &compatibilityStringSize);
if (result == VCL_RESULT_ERROR_UNSUPPORTED_FEATURE) {
return std::nullopt;
}
@@ -107,20 +80,21 @@ static std::optional<std::string> getVCLCompatibilityString(vcl_executable_handl
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(logHandle));
+ getLatestVCLLog(functions, logHandle));
}
if (compatibilityStringSize > std::numeric_limits<size_t>::max()) {
OPENVINO_THROW("Compatibility string size is too large to allocate a local buffer");
}
std::string compatibilityString(static_cast<size_t>(compatibilityStringSize), '\0');
- result = vclExecutableGetCompatibilityString(executable, compatibilityString.data(), &compatibilityStringSize);
+ result =
+ functions.vclExecutableGetCompatibilityString(executable, compatibilityString.data(), &compatibilityStringSize);
if (result != VCL_RESULT_SUCCESS) {
OPENVINO_THROW("Failed to get compatibility string. vclExecutableGetCompatibilityString result: 0x",
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(logHandle));
+ getLatestVCLLog(functions, logHandle));
}
if (compatibilityStringSize > compatibilityString.size()) {
OPENVINO_THROW("Returned compatibility string size exceeds the allocated buffer size");
@@ -134,31 +108,42 @@ static std::optional<std::string> getVCLCompatibilityString(vcl_executable_handl
return compatibilityString;
}
-#define THROW_ON_FAIL_FOR_VCL(step, ret, logHandle) \
- { \
- vcl_result_t result = ret; \
- if (result != VCL_RESULT_SUCCESS) { \
- OPENVINO_THROW("Failed to call VCL API : ", \
- step, \
- " result: 0x", \
- std::hex, \
- result, \
- " - ", \
- getLatestVCLLog(logHandle)); \
- } \
- }
-
-VCLCompilerImpl::VCLCompilerImpl(const std::string& libraryDir,
+/**
+ * @brief Throws with the VCL error log appended when `ret` is not VCL_RESULT_SUCCESS.
+ * @param functions The function table to fetch the error log through, passed explicitly rather than
+ * captured from the enclosing scope so the macro is usable outside VCLCompilerImpl members.
+ */
+#define THROW_ON_FAIL_FOR_VCL(functions, step, ret, logHandle) \
+ do { \
+ const vcl_result_t vclResult_ = (ret); \
+ if (vclResult_ != VCL_RESULT_SUCCESS) { \
+ OPENVINO_THROW("Failed to call VCL API : ", \
+ step, \
+ " result: 0x", \
+ std::hex, \
+ vclResult_, \
+ " - ", \
+ getLatestVCLLog((functions), logHandle)); \
+ } \
+ } while (0)
+
+VCLCompilerImpl::VCLCompilerImpl(std::shared_ptr<const VCLFunctionTable> functions,
const std::optional<IDevice::DeviceProperties>& deviceProperties)
- : _logHandle(nullptr),
+ : _functions(std::move(functions)),
+ _logHandle(nullptr),
_logger("VCLCompilerImpl", Logger::global().level()) {
_logger.debug("VCLCompilerImpl constructor start");
- // Load VCL library
- (void)VCLApi::getInstance(libraryDir);
+ OPENVINO_ASSERT(_functions != nullptr, "VCLCompilerImpl requires a non-null VCLFunctionTable");
+ OPENVINO_ASSERT(_functions->hasAllRequiredSymbols(),
+ "VCLCompilerImpl received a VCLFunctionTable with unresolved entry points. Was "
+ "it populated from a VCLLoader?");
// Initialize the VCL API
- THROW_ON_FAIL_FOR_VCL("vclGetVersion", vclGetVersion(&_vclVersion, &_vclProfilingVersion), nullptr);
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetVersion",
+ _functions->vclGetVersion(&_vclVersion, &_vclProfilingVersion),
+ nullptr);
_logger.info("Plugin VCL API Version: %d.%d", VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR);
_logger.info("Plugin VCL Profiling API Version: %d.%d", VCL_PROFILING_VERSION_MAJOR, VCL_PROFILING_VERSION_MINOR);
_logger.info("Lib VCL Compiler Version: %d.%d", _vclVersion.major, _vclVersion.minor);
@@ -206,11 +191,13 @@ VCLCompilerImpl::VCLCompilerImpl(const std::string& libraryDir,
vclDeviceDesc = {sizeof(vcl_device_desc_t), 0x00, std::numeric_limits<uint16_t>::max(), defaultTileCount};
}
- THROW_ON_FAIL_FOR_VCL("vclCompilerCreate",
- vclCompilerCreate(&compilerDesc, &vclDeviceDesc, &_compilerHandle, &_logHandle),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclCompilerCreate",
+ _functions->vclCompilerCreate(&compilerDesc, &vclDeviceDesc, &_compilerHandle, &_logHandle),
nullptr);
- THROW_ON_FAIL_FOR_VCL("vclCompilerGetProperties",
- vclCompilerGetProperties(_compilerHandle, &_compilerProperties),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclCompilerGetProperties",
+ _functions->vclCompilerGetProperties(_compilerHandle, &_compilerProperties),
_logHandle);
_logger.info("VCL Compiler created successfully");
_logger.info("VCL Compiler Properties: ID: %s, Version: %d.%d, Supported Opsets: %u",
@@ -222,12 +209,12 @@ VCLCompilerImpl::VCLCompilerImpl(const std::string& libraryDir,
VCLCompilerImpl::~VCLCompilerImpl() {
if (_compilerHandle) {
- vcl_result_t result = vclCompilerDestroy(_compilerHandle);
+ vcl_result_t result = _functions->vclCompilerDestroy(_compilerHandle);
_compilerHandle = nullptr;
if (result != VCL_RESULT_SUCCESS) {
_logger.warning("Failed to destroy VCL compiler: result 0x%x - %s",
result,
- getLatestVCLLog(_logHandle).c_str());
+ getLatestVCLLog(*_functions, _logHandle).c_str());
}
}
@@ -237,10 +224,6 @@ VCLCompilerImpl::~VCLCompilerImpl() {
_logger.info("VCL Compiler destroyed successfully");
}
-std::shared_ptr<void> VCLCompilerImpl::getLinkedLibrary() const {
- return VCLApi::getInstance()->getLibrary();
-}
-
std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
const std::shared_ptr<const ov::Model>& model,
const FilteredConfig& config) const {
@@ -254,9 +237,14 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
_logger.debug("compile start");
/// Check the linked vcl version whether supported in plugin
- UsedVersion usedVersion = getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion);
- _logger.debug("the finally used compiler vcl version is %d.%d", usedVersion.Major, usedVersion.Minor);
- checkVclVersion(usedVersion, _vclVersion);
+ UsedVersion usedVersion =
+ getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion.major, _vclVersion.minor);
+ _logger.debug("The final vcl compiler version used is %d.%d", usedVersion.Major, usedVersion.Minor);
+ checkVclVersion(usedVersion,
+ _vclVersion.major,
+ _vclVersion.minor,
+ VCL_COMPILER_VERSION_MAJOR,
+ VCL_COMPILER_VERSION_MINOR);
const auto maxOpsetVersion = _compilerProperties.supportedOpsets;
_logger.info("getSupportedOpsetVersion Max supported version of opset in CiD: %d", maxOpsetVersion);
@@ -305,8 +293,12 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
uint64_t blobSize = 0;
vcl_executable_handle_t executable = nullptr;
- auto result =
- vclAllocatedExecutableCreate4(_compilerHandle, exeDesc, allocator.get(), &blob, &blobSize, &executable);
+ auto result = _functions->vclAllocatedExecutableCreate4(_compilerHandle,
+ exeDesc,
+ allocator.get(),
+ &blob,
+ &blobSize,
+ &executable);
if (result != VCL_RESULT_SUCCESS) {
// Check if allocations were performed before throwing exception
auto tracked_allocations = allocator->m_info;
@@ -314,13 +306,13 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
allocator->deallocate(allocator.get(), buffer);
}
if (executable != nullptr) {
- vclExecutableDestroy(executable);
+ _functions->vclExecutableDestroy(executable);
}
OPENVINO_THROW("Compilation failed. vclAllocatedExecutableCreate4 result: 0x",
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(_logHandle));
+ getLatestVCLLog(*_functions, _logHandle));
}
OPENVINO_ASSERT(executable != nullptr, "Failed to create VCL executable, executable handle is null");
OPENVINO_ASSERT(blobSize != 0 && blob != nullptr,
@@ -345,9 +337,9 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
std::optional<std::string> compatibilityString;
try {
- compatibilityString = getVCLCompatibilityString(executable, _logHandle);
+ compatibilityString = getVCLCompatibilityString(*_functions, executable, _logHandle);
} catch (...) {
- vclExecutableDestroy(executable);
+ _functions->vclExecutableDestroy(executable);
throw;
}
if (!compatibilityString.has_value()) {
@@ -359,13 +351,13 @@ std::pair<ov::Tensor, std::optional<std::string>> VCLCompilerImpl::compile(
_logger.debug("Compatibility string from VCL: %s", compatibilityString->c_str());
}
- result = vclExecutableDestroy(executable);
+ result = _functions->vclExecutableDestroy(executable);
if (result != VCL_RESULT_SUCCESS) {
OPENVINO_THROW("Failed to destroy VCL executable. vclExecutableDestroy result: 0x",
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(_logHandle));
+ getLatestVCLLog(*_functions, _logHandle));
}
return std::make_pair<ov::Tensor, std::optional<std::string>>(std::move(alignedBlob),
@@ -378,9 +370,14 @@ std::pair<std::vector<ov::Tensor>, std::optional<std::string>> VCLCompilerImpl::
_logger.debug("compileWsOneShot start");
/// Check the linked vcl version whether supported in plugin
- UsedVersion usedVersion = getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion);
- _logger.debug("the finally used compiler vcl version is %d.%d", usedVersion.Major, usedVersion.Minor);
- checkVclVersion(usedVersion, _vclVersion);
+ UsedVersion usedVersion =
+ getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion.major, _vclVersion.minor);
+ _logger.debug("The final vcl compiler version used is %d.%d", usedVersion.Major, usedVersion.Minor);
+ checkVclVersion(usedVersion,
+ _vclVersion.major,
+ _vclVersion.minor,
+ VCL_COMPILER_VERSION_MAJOR,
+ VCL_COMPILER_VERSION_MINOR);
const auto maxOpsetVersion = _compilerProperties.supportedOpsets;
_logger.info("getSupportedOpsetVersion Max supported version of opset in CiD: %d", maxOpsetVersion);
@@ -428,23 +425,24 @@ std::pair<std::vector<ov::Tensor>, std::optional<std::string>> VCLCompilerImpl::
auto allocator = std::make_shared<vcl_allocator_2>();
vcl_executable_handle_t executable = nullptr;
- auto result = vclAllocatedExecutableCreateWSOneShot2(_compilerHandle, exeDesc, allocator.get(), &executable);
+ auto result =
+ _functions->vclAllocatedExecutableCreateWSOneShot2(_compilerHandle, exeDesc, allocator.get(), &executable);
if (result != VCL_RESULT_SUCCESS) {
if (executable != nullptr) {
- vclExecutableDestroy(executable);
+ _functions->vclExecutableDestroy(executable);
}
OPENVINO_THROW("Compilation failed. vclAllocatedExecutableCreateWSOneShot2 result: 0x",
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(_logHandle));
+ getLatestVCLLog(*_functions, _logHandle));
}
if (executable == nullptr) {
OPENVINO_THROW("Failed to create VCL executable, executable handle is null");
}
if (allocator->m_info.size() == 0) {
- vclExecutableDestroy(executable);
+ _functions->vclExecutableDestroy(executable);
OPENVINO_THROW("Failed to create VCL executable, blobCount is zero");
}
@@ -457,9 +455,9 @@ std::pair<std::vector<ov::Tensor>, std::optional<std::string>> VCLCompilerImpl::
std::optional<std::string> compatibilityString;
try {
- compatibilityString = getVCLCompatibilityString(executable, _logHandle);
+ compatibilityString = getVCLCompatibilityString(*_functions, executable, _logHandle);
} catch (...) {
- vclExecutableDestroy(executable);
+ _functions->vclExecutableDestroy(executable);
throw;
}
if (!compatibilityString.has_value()) {
@@ -470,13 +468,13 @@ std::pair<std::vector<ov::Tensor>, std::optional<std::string>> VCLCompilerImpl::
_logger.debug("Compatibility string from VCL: %s", compatibilityString->c_str());
}
- result = vclExecutableDestroy(executable);
+ result = _functions->vclExecutableDestroy(executable);
if (result != VCL_RESULT_SUCCESS) {
OPENVINO_THROW("Failed to destroy executable. vclExecutableDestroy result: 0x",
std::hex,
uint64_t(result),
" - ",
- getLatestVCLLog(_logHandle));
+ getLatestVCLLog(*_functions, _logHandle));
}
return std::make_pair(std::move(initMainTensors), std::move(compatibilityString));
@@ -500,13 +498,15 @@ std::vector<ov::ProfilingInfo> VCLCompilerImpl::process_profiling_output(const s
vcl_profiling_handle_t profilingHandle;
vcl_profiling_input_t profilingInput = {network.data(), network.size(), profData.data(), profData.size()};
vcl_log_handle_t logHandle;
- THROW_ON_FAIL_FOR_VCL("vclProfilingCreate",
- vclProfilingCreate(&profilingInput, &profilingHandle, &logHandle),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingCreate",
+ _functions->vclProfilingCreate(&profilingInput, &profilingHandle, &logHandle),
nullptr);
vcl_profiling_properties_t profProperties;
- THROW_ON_FAIL_FOR_VCL("vclProfilingGetProperties",
- vclProfilingGetProperties(profilingHandle, &profProperties),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingGetProperties",
+ _functions->vclProfilingGetProperties(profilingHandle, &profProperties),
logHandle);
_logger.info("VCL Profiling Properties: Version: %d.%d",
@@ -518,8 +518,9 @@ std::vector<ov::ProfilingInfo> VCLCompilerImpl::process_profiling_output(const s
vcl_profiling_output_t profOutput;
profOutput.data = NULL;
- THROW_ON_FAIL_FOR_VCL("vclGetDecodedProfilingBuffer",
- vclGetDecodedProfilingBuffer(profilingHandle, request, &profOutput),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetDecodedProfilingBuffer",
+ _functions->vclGetDecodedProfilingBuffer(profilingHandle, request, &profOutput),
logHandle);
if (profOutput.data == NULL) {
OPENVINO_THROW("Failed to get VCL profiling output");
@@ -531,7 +532,10 @@ std::vector<ov::ProfilingInfo> VCLCompilerImpl::process_profiling_output(const s
std::memcpy(layerInfo.data(), profOutput.data, profOutput.size);
}
- THROW_ON_FAIL_FOR_VCL("vclProfilingDestroy", vclProfilingDestroy(profilingHandle), logHandle);
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclProfilingDestroy",
+ _functions->vclProfilingDestroy(profilingHandle),
+ logHandle);
// Return processed profiling info
return intel_npu::profiling::convertLayersToIeProfilingInfo(layerInfo);
@@ -546,8 +550,14 @@ ov::SupportedOpsMap VCLCompilerImpl::query(const std::shared_ptr<const ov::Model
_logger.debug("query start");
/// Check the linked vcl version whether supported in plugin
- UsedVersion usedVersion = getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion);
- _logger.debug("the finally used vcl version is %d.%d", usedVersion.Major, usedVersion.Minor);
+ UsedVersion usedVersion =
+ getUsedVclVersion(VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR, _vclVersion.major, _vclVersion.minor);
+ _logger.debug("The final vcl compiler version used is %d.%d", usedVersion.Major, usedVersion.Minor);
+ checkVclVersion(usedVersion,
+ _vclVersion.major,
+ _vclVersion.minor,
+ VCL_COMPILER_VERSION_MAJOR,
+ VCL_COMPILER_VERSION_MINOR);
const auto maxOpsetVersion = _compilerProperties.supportedOpsets;
_logger.info("getSupportedOpsetVersion Max supported version of opset in CiD: %d", maxOpsetVersion);
@@ -580,20 +590,29 @@ ov::SupportedOpsMap VCLCompilerImpl::query(const std::shared_ptr<const ov::Model
vcl_query_handle_t queryHandle;
vcl_query_desc_t queryDesc = {serializedIR.buffer.get(), serializedIR.size, buildFlags.c_str(), buildFlags.size()};
- THROW_ON_FAIL_FOR_VCL("vclQueryNetworkCreate",
- vclQueryNetworkCreate(_compilerHandle, queryDesc, &queryHandle),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclQueryNetworkCreate",
+ _functions->vclQueryNetworkCreate(_compilerHandle, queryDesc, &queryHandle),
_logHandle);
uint64_t size = 0;
- THROW_ON_FAIL_FOR_VCL("vclQueryNetwork", vclQueryNetwork(queryHandle, nullptr, &size), _logHandle);
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclQueryNetwork",
+ _functions->vclQueryNetwork(queryHandle, nullptr, &size),
+ _logHandle);
std::vector<char> supportedLayers(size);
- THROW_ON_FAIL_FOR_VCL("vclQueryNetwork",
- vclQueryNetwork(queryHandle, reinterpret_cast<uint8_t*>(supportedLayers.data()), &size),
+ THROW_ON_FAIL_FOR_VCL(
+ *_functions,
+ "vclQueryNetwork",
+ _functions->vclQueryNetwork(queryHandle, reinterpret_cast<uint8_t*>(supportedLayers.data()), &size),
+ _logHandle);
+
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclQueryNetworkDestroy",
+ _functions->vclQueryNetworkDestroy(queryHandle),
_logHandle);
- THROW_ON_FAIL_FOR_VCL("vclQueryNetworkDestroy", vclQueryNetworkDestroy(queryHandle), _logHandle);
-
const std::string deviceName = "NPU";
ov::SupportedOpsMap result;
const auto parsedSupportedLayers = parseQueryResult(supportedLayers);
@@ -605,33 +624,53 @@ ov::SupportedOpsMap VCLCompilerImpl::query(const std::shared_ptr<const ov::Model
return result;
}
-void VCLCompilerImpl::get_supported_options(std::vector<char>& options) const {
+std::vector<std::string> VCLCompilerImpl::get_supported_options() const {
_logger.debug("get_supported_options start");
size_t str_size = 0;
- THROW_ON_FAIL_FOR_VCL("vclGetCompilerSupportedOptions",
- vclGetCompilerSupportedOptions(_compilerHandle, nullptr, &str_size),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetCompilerSupportedOptions",
+ _functions->vclGetCompilerSupportedOptions(_compilerHandle, nullptr, &str_size),
_logHandle);
if (str_size == 0) {
_logger.debug("Option list size 0!");
- return;
+ return {};
}
_logger.debug("obtain list");
- options.resize(str_size);
- THROW_ON_FAIL_FOR_VCL("vclGetCompilerSupportedOptions",
- vclGetCompilerSupportedOptions(_compilerHandle, options.data(), &str_size),
+ std::vector<char> options(str_size);
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetCompilerSupportedOptions",
+ _functions->vclGetCompilerSupportedOptions(_compilerHandle, options.data(), &str_size),
_logHandle);
_logger.debug("Option list size %d, got option list", str_size);
+
+ // VCL hands back a char buffer that may carry trailing NULs. Trimming and tokenising here keeps that
+ // calling convention out of IVCLCompiler.
+ auto trailingNul = std::find(options.begin(), options.end(), '\0');
+ std::string optionsStr(options.begin(), trailingNul);
+
+ // Marker grepped by tests/functional/internal/plugin/test_compiler_option_support_helper.cpp to
+ // assert the bulk retrieval runs exactly once per compiler-type key. Keep the text in sync.
+ _logger.debug("VCLCompilerImpl return supported_options: %s", optionsStr.c_str());
+
+ std::vector<std::string> result;
+ std::istringstream iss(optionsStr);
+ std::string token;
+ while (iss >> token) {
+ result.push_back(token);
+ }
+ return result;
}
bool VCLCompilerImpl::is_option_supported(const std::string& option, const std::optional<std::string>& optValue) const {
try {
const char* optname_ch = option.c_str();
const char* optvalue_ch = optValue.has_value() ? optValue.value().c_str() : nullptr;
- THROW_ON_FAIL_FOR_VCL("vclGetCompilerIsOptionSupported",
- vclGetCompilerIsOptionSupported(_compilerHandle, optname_ch, optvalue_ch),
+ THROW_ON_FAIL_FOR_VCL(*_functions,
+ "vclGetCompilerIsOptionSupported",
+ _functions->vclGetCompilerIsOptionSupported(_compilerHandle, optname_ch, optvalue_ch),
_logHandle);
return true;
} catch (const std::exception& e) {
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
index 16314e9cabd..595e62ea358 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
@@ -8,7 +8,6 @@
#include <iterator>
#include <ostream>
-#include "compiler_impl.hpp"
#include "intel_npu/common/compiler_adapter_factory.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/prefix.hpp"
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
index 6330ff40b16..011426d1afa 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -9,6 +9,7 @@
#include "compiler_impl.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/utils/utils.hpp"
+#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
@@ -155,7 +156,7 @@ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> Graph::export_blob(std
std::vector<ov::ProfilingInfo> Graph::process_profiling_output(const std::vector<uint8_t>& profData) const {
auto ov_lib_path = ov::util::path_to_string(ov::util::get_ov_lib_path());
- auto compiler = std::make_shared<VCLCompilerImpl>(ov_lib_path);
+ auto compiler = std::make_shared<VCLCompilerImpl>(VCLLoader::getInstance(ov_lib_path)->sharedFunctions());
OPENVINO_ASSERT(compiler != nullptr, "Profiling post-processing requires the NPU plugin compiler library");
std::vector<uint8_t> blob(_blob->get_byte_size());
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
index 0b02b7f44a8..e74c47f838f 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp
@@ -44,9 +44,13 @@ PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStruc
_logger.info("Loading PLUGIN compiler");
try {
auto ovLibPath = ov::util::path_to_string(ov::util::get_ov_lib_path());
- auto vclCompilerPtr = std::make_shared<VCLCompilerImpl>(ovLibPath, deviceProperties);
+ auto vclLoader = VCLLoader::getInstance(ovLibPath);
+ OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");
+ auto vclCompilerPtr = std::make_shared<VCLCompilerImpl>(vclLoader->sharedFunctions(), deviceProperties);
OPENVINO_ASSERT(vclCompilerPtr != nullptr, "VCL compiler is nullptr");
- auto vclLib = vclCompilerPtr->getLinkedLibrary();
+ // Pair the compiler with the library so the .so cannot be unloaded while the compiler
+ // dispatches into it. The compiler itself no longer knows a library is involved.
+ auto vclLib = vclLoader->getLibrary();
_logger.info("PLUGIN VCL compiler is loading");
OPENVINO_ASSERT(vclLib != nullptr, "VCL library is nullptr");
_compiler = ov::SoPtr<VCLCompilerImpl>(vclCompilerPtr, vclLib);
@@ -287,25 +291,7 @@ uint32_t PluginCompilerAdapter::get_version() const {
}
std::vector<std::string> PluginCompilerAdapter::get_supported_options() const {
- std::vector<char> options;
- _compiler->get_supported_options(options);
- size_t optionsSize = options.size();
- while (optionsSize > 0 && options[optionsSize - 1] == '\0') {
- --optionsSize;
- }
- if (optionsSize == 0) {
- return {};
- }
-
- std::string compilerOptionsStr(options.data(), optionsSize);
- _logger.debug("VCLCompilerImpl return supported_options: %s", compilerOptionsStr.c_str());
- // vectorize string
- std::istringstream suppstream(compilerOptionsStr);
- std::vector<std::string> compilerOpts = {};
- std::string option;
- while (suppstream >> option) {
- compilerOpts.push_back(option);
- }
+ const std::vector<std::string> compilerOpts = _compiler->get_supported_options();
if (_optionSupportCache) {
_optionSupportCache->setSupportedOptions(pluginOptionSupportKey, compilerOpts);
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
index 0a982f95989..106358aadbc 100644
--- 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
@@ -5,6 +5,7 @@
#pragma once
#include <memory>
+#include <string>
#include "intel_npu/utils/logger/logger.hpp"
#include "openvino/core/except.hpp"
@@ -32,51 +33,81 @@ namespace intel_npu {
vcl_symbol_statement(vclExecutableGetCompatibilityString) \
vcl_symbol_statement(vclGetCompilerSupportedOptions) \
vcl_symbol_statement(vclGetCompilerIsOptionSupported) \
+ vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot2) \
// symbols that may not be supported in older versions of vcl
#define vcl_weak_symbols_list() \
- vcl_symbol_statement(vclAllocatedExecutableCreate2) \
- vcl_symbol_statement(vclAllocatedExecutableCreateWSOneShot2) // clang-format on
+ vcl_symbol_statement(vclAllocatedExecutableCreate2) // clang-format on
-class VCLApi {
+/**
+ * @brief The VCL entry points, as a plain aggregate.
+ *
+ * Deliberately holds no library handle and does no loading: it is data, not behaviour. Every entry
+ * point defaults to null, so a default-constructed table is a legitimate value - an unpopulated
+ * table
+ */
+struct VCLFunctionTable {
+#define vcl_symbol_statement(vcl_symbol) decltype(&::vcl_symbol) vcl_symbol = nullptr;
+ vcl_symbols_list();
+ vcl_weak_symbols_list();
+#undef vcl_symbol_statement
+
+ /**
+ * @brief True when every non-weak entry point is populated.
+ *
+ * Weak symbols are excluded on purpose: they are legitimately null when the loaded library
+ * predates them. Consumers that need the full table assert on this at construction, so an
+ * unpopulated table fails with a diagnosable error instead of dispatching through a null
+ * function pointer at the first call. Generated from `vcl_symbols_list()`, so it cannot drift
+ * as the list grows.
+ */
+ bool hasAllRequiredSymbols() const {
+#define vcl_symbol_statement(vcl_symbol) \
+ if (this->vcl_symbol == nullptr) { \
+ return false; \
+ }
+ vcl_symbols_list();
+#undef vcl_symbol_statement
+ return true;
+ }
+};
+
+/**
+ * @brief Owns the loaded VCL compiler library and the function table resolved out of it.
+ *
+ * The loading constructor is private: `getInstance` is the only way to load, so the process cannot
+ * end up with two independently dlopen'd copies of the compiler library.
+ */
+class VCLLoader final : public std::enable_shared_from_this<VCLLoader> {
public:
- VCLApi(const std::string& library_dir);
- VCLApi(const VCLApi& other) = delete;
- VCLApi(VCLApi&& other) = delete;
- void operator=(const VCLApi&) = delete;
- void operator=(VCLApi&&) = delete;
+ VCLLoader(const VCLLoader& other) = delete;
+ VCLLoader(VCLLoader&& other) = delete;
+ void operator=(const VCLLoader&) = delete;
+ void operator=(VCLLoader&&) = delete;
+
+ static const std::shared_ptr<const VCLLoader> getInstance(const std::string& library_dir = std::string());
+
+ /**
+ * @brief The function table, sharing this loader's lifetime.
+ *
+ * An aliasing `shared_ptr`, so a holder of the returned table keeps the library loaded without
+ * having to know a library exists.
+ */
+ std::shared_ptr<const VCLFunctionTable> sharedFunctions() const {
+ return {shared_from_this(), &_functions};
+ }
- static const std::shared_ptr<VCLApi> getInstance(const std::string& library_dir = std::string());
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:
+ explicit VCLLoader(const std::string& library_dir);
+
+ VCLFunctionTable _functions;
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/vcl/vcl_api.cpp b/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
index b1eedc0e8a3..04d0d2d7247 100644
--- a/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
+++ b/src/plugins/intel_npu/src/utils/src/vcl/vcl_api.cpp
@@ -4,13 +4,15 @@
#include "intel_npu/utils/vcl/vcl_api.hpp"
+#include <filesystem>
#include <mutex>
+#include <stdexcept>
#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"
namespace intel_npu {
-VCLApi::VCLApi(const std::string& library_dir) : _logger("VCLApi", Logger::global().level()) {
+VCLLoader::VCLLoader(const std::string& library_dir) : _logger("VCLLoader", Logger::global().level()) {
const auto baseName = "openvino_intel_npu_compiler_loader";
try {
@@ -24,7 +26,7 @@ VCLApi::VCLApi(const std::string& library_dir) : _logger("VCLApi", Logger::globa
try {
#define vcl_symbol_statement(vcl_symbol) \
- this->vcl_symbol = reinterpret_cast<decltype(&::vcl_symbol)>(ov::util::get_symbol(lib, #vcl_symbol));
+ _functions.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) {
@@ -32,38 +34,34 @@ VCLApi::VCLApi(const std::string& library_dir) : _logger("VCLApi", Logger::globa
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); \
- this->vcl_symbol = nullptr; \
+#define vcl_symbol_statement(vcl_symbol) \
+ try { \
+ _functions.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); \
+ _functions.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(const std::string& library_dir) {
+const std::shared_ptr<const VCLLoader> VCLLoader::getInstance(const std::string& library_dir) {
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
static std::string initialized_dir;
- static std::shared_ptr<VCLApi> instance = nullptr;
+ static std::shared_ptr<const VCLLoader> instance = nullptr;
if (!instance) {
if (library_dir.empty()) {
- OPENVINO_THROW("VCLApi instance has not been loaded yet, and no valid path was provided to load it.");
+ OPENVINO_THROW("VCLLoader instance has not been loaded yet, and no valid path was provided to load it.");
}
initialized_dir = library_dir;
- instance = std::make_shared<VCLApi>(library_dir);
+ // Not make_shared: the loading constructor is private so that this is the only way to load.
+ instance = std::shared_ptr<const VCLLoader>(new VCLLoader(library_dir));
} else {
if (!library_dir.empty() && library_dir != initialized_dir) {
- OPENVINO_THROW("VCLApi has already been initialized with path: '",
+ OPENVINO_THROW("VCLLoader has already been initialized with path: '",
initialized_dir,
"'. Dynamic switching to a new compiler path: '",
library_dir,
diff --git a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/vcl_allocator_test.cpp b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/vcl_allocator_test.cpp
index 843f534b0af..7e50bfd83e4 100644
--- a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/vcl_allocator_test.cpp
+++ b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/vcl_allocator_test.cpp
@@ -2,8 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include <algorithm>
+#include "intel_npu/utils/vcl/vcl_allocator.hpp"
+
#include <gtest/gtest.h>
+
+#include <algorithm>
#include <memory>
#include <vector>
@@ -11,7 +14,6 @@
#include "common_test_utils/file_utils.hpp"
#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"
#include "intel_npu/utils/utils.hpp"
-#include "intel_npu/utils/vcl/vcl_allocator.hpp"
#include "intel_npu/utils/vcl/vcl_api.hpp"
#include "model_serializer.hpp"
#include "openvino/core/except.hpp"
@@ -36,6 +38,7 @@ protected:
std::string targetDevice;
std::shared_ptr<ov::Model> model;
std::shared_ptr<::intel_npu::vcl_allocator_2> allocator;
+ std::shared_ptr<const ::intel_npu::VCLFunctionTable> functions;
void SetUp() override {
targetDevice = GetParam();
@@ -44,7 +47,7 @@ protected:
try {
std::string ov_lib_dir = ov::test::utils::getOpenvinoLibDirectory();
- ::intel_npu::VCLApi::getInstance(ov_lib_dir);
+ functions = ::intel_npu::VCLLoader::getInstance(ov_lib_dir)->sharedFunctions();
} catch (const std::exception&) {
GTEST_SKIP() << "Couldn't load compiler library";
}
@@ -52,6 +55,8 @@ protected:
// Helper struct and function to reduce code duplication
struct CompilerSetupState {
+ // Held so the destructor can reach vclCompilerDestroy, and so the loader outlives the handle.
+ std::shared_ptr<const ::intel_npu::VCLFunctionTable> functions;
std::string buildFlags;
::intel_npu::SerializedIR serializedIR;
vcl_compiler_handle_t compiler = nullptr;
@@ -61,7 +66,8 @@ protected:
CompilerSetupState(const CompilerSetupState&) = delete;
CompilerSetupState& operator=(const CompilerSetupState&) = delete;
CompilerSetupState(CompilerSetupState&& other) noexcept
- : buildFlags(std::move(other.buildFlags)),
+ : functions(std::move(other.functions)),
+ buildFlags(std::move(other.buildFlags)),
serializedIR(std::move(other.serializedIR)),
compiler(other.compiler),
logHandle(other.logHandle) {
@@ -71,6 +77,7 @@ protected:
CompilerSetupState& operator=(CompilerSetupState&& other) noexcept {
if (this != &other) {
release();
+ functions = std::move(other.functions);
buildFlags = std::move(other.buildFlags);
serializedIR = std::move(other.serializedIR);
compiler = other.compiler;
@@ -88,7 +95,7 @@ protected:
private:
void release() {
if (compiler != nullptr) {
- ::intel_npu::vclCompilerDestroy(compiler);
+ functions->vclCompilerDestroy(compiler);
compiler = nullptr;
}
}
@@ -96,6 +103,7 @@ protected:
CompilerSetupState createCompilerAndDescriptor() {
CompilerSetupState state;
+ state.functions = functions;
state.buildFlags = ::intel_npu::compiler_utils::serializeIOInfo(model, true);
@@ -109,7 +117,7 @@ protected:
vcl_version_info_t vclVersion = {};
vcl_version_info_t vclProfilingVersion = {};
- ::intel_npu::vclGetVersion(&vclVersion, &vclProfilingVersion);
+ functions->vclGetVersion(&vclVersion, &vclProfilingVersion);
vcl_compiler_desc_t compilerDesc = {};
compilerDesc.version = vclVersion;
@@ -126,7 +134,7 @@ protected:
std::numeric_limits<uint16_t>::max(),
defaultTileCount};
- ::intel_npu::vclCompilerCreate(&compilerDesc, &deviceDesc, &state.compiler, &state.logHandle);
+ functions->vclCompilerCreate(&compilerDesc, &deviceDesc, &state.compiler, &state.logHandle);
if (state.compiler == nullptr) {
ADD_FAILURE() << "vclCompilerCreate failed";
@@ -135,7 +143,7 @@ protected:
ze_graph_compiler_version_info_t vclVersionInfo = {0, 0};
vcl_compiler_properties_t compilerProp = {};
- ::intel_npu::vclCompilerGetProperties(state.compiler, &compilerProp);
+ functions->vclCompilerGetProperties(state.compiler, &compilerProp);
vclVersionInfo.major = compilerProp.version.major;
vclVersionInfo.minor = compilerProp.version.minor;
@@ -157,9 +165,9 @@ protected:
return state;
}
- static std::string getCompatibilityString(vcl_executable_handle_t executable) {
+ std::string getCompatibilityString(vcl_executable_handle_t executable) {
uint64_t compatibilityStringSize = 0;
- auto result = ::intel_npu::vclExecutableGetCompatibilityString(executable, nullptr, &compatibilityStringSize);
+ auto result = functions->vclExecutableGetCompatibilityString(executable, nullptr, &compatibilityStringSize);
if (result != VCL_RESULT_SUCCESS || compatibilityStringSize == 0) {
ADD_FAILURE() << "Failed to get compatibility string size";
return {};
@@ -170,9 +178,9 @@ protected:
return {};
}
std::vector<char> compatibilityStringBuffer(static_cast<size_t>(compatibilityStringSize), '\0');
- result = ::intel_npu::vclExecutableGetCompatibilityString(executable,
- compatibilityStringBuffer.data(),
- &compatibilityStringSize);
+ result = functions->vclExecutableGetCompatibilityString(executable,
+ compatibilityStringBuffer.data(),
+ &compatibilityStringSize);
if (result != VCL_RESULT_SUCCESS) {
ADD_FAILURE() << "Failed to get compatibility string";
return {};
@@ -202,12 +210,12 @@ TEST_P(VclAllocatorFuncTests, VerifyAllocation) {
setup.buildFlags.c_str(),
setup.buildFlags.size()};
- auto result = ::intel_npu::vclAllocatedExecutableCreate4(setup.compiler,
- desc,
- allocator.get(),
- &blobBuffer,
- &blobSize,
- &executable);
+ auto result = functions->vclAllocatedExecutableCreate4(setup.compiler,
+ desc,
+ allocator.get(),
+ &blobBuffer,
+ &blobSize,
+ &executable);
EXPECT_EQ(result, VCL_RESULT_SUCCESS);
EXPECT_NE(blobBuffer, nullptr);
@@ -225,7 +233,7 @@ TEST_P(VclAllocatorFuncTests, VerifyAllocation) {
});
EXPECT_NE(blobIt, allocator->m_info.end());
- EXPECT_EQ(::intel_npu::vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
+ EXPECT_EQ(functions->vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
}
TEST_P(VclAllocatorFuncTests, VerifyDeallocation) {
@@ -241,12 +249,12 @@ TEST_P(VclAllocatorFuncTests, VerifyDeallocation) {
setup.buildFlags.c_str(),
setup.buildFlags.size()};
- auto result = ::intel_npu::vclAllocatedExecutableCreate4(setup.compiler,
- desc,
- allocator.get(),
- &blobBuffer,
- &blobSize,
- &executable);
+ auto result = functions->vclAllocatedExecutableCreate4(setup.compiler,
+ desc,
+ allocator.get(),
+ &blobBuffer,
+ &blobSize,
+ &executable);
EXPECT_EQ(result, VCL_RESULT_SUCCESS);
ASSERT_NE(executable, nullptr);
@@ -267,7 +275,7 @@ TEST_P(VclAllocatorFuncTests, VerifyDeallocation) {
EXPECT_EQ(blobIt, allocator->m_info.end());
EXPECT_EQ(allocator->m_info.size(), 0);
- EXPECT_EQ(::intel_npu::vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
+ EXPECT_EQ(functions->vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
}
TEST_P(VclAllocatorFuncTests, VerifyOwnershipTransferToTensor) {
@@ -283,12 +291,12 @@ TEST_P(VclAllocatorFuncTests, VerifyOwnershipTransferToTensor) {
setup.buildFlags.c_str(),
setup.buildFlags.size()};
- auto result = ::intel_npu::vclAllocatedExecutableCreate4(setup.compiler,
- desc,
- allocator.get(),
- &blobBuffer,
- &blobSize,
- &executable);
+ auto result = functions->vclAllocatedExecutableCreate4(setup.compiler,
+ desc,
+ allocator.get(),
+ &blobBuffer,
+ &blobSize,
+ &executable);
EXPECT_EQ(result, VCL_RESULT_SUCCESS);
ASSERT_NE(executable, nullptr);
@@ -319,7 +327,7 @@ TEST_P(VclAllocatorFuncTests, VerifyOwnershipTransferToTensor) {
// the tracking info in the allocator should be empty.
EXPECT_EQ(allocator->m_info.size(), 0);
- EXPECT_EQ(::intel_npu::vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
+ EXPECT_EQ(functions->vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
}
TEST_P(VclAllocatorFuncTests, VerifyOrphanMemoryCleanupOnDestruction) {
@@ -335,12 +343,12 @@ TEST_P(VclAllocatorFuncTests, VerifyOrphanMemoryCleanupOnDestruction) {
setup.buildFlags.c_str(),
setup.buildFlags.size()};
- auto result = ::intel_npu::vclAllocatedExecutableCreate4(setup.compiler,
- desc,
- allocator.get(),
- &blobBuffer,
- &blobSize,
- &executable);
+ auto result = functions->vclAllocatedExecutableCreate4(setup.compiler,
+ desc,
+ allocator.get(),
+ &blobBuffer,
+ &blobSize,
+ &executable);
EXPECT_EQ(result, VCL_RESULT_SUCCESS);
ASSERT_NE(executable, nullptr);
@@ -348,7 +356,7 @@ TEST_P(VclAllocatorFuncTests, VerifyOrphanMemoryCleanupOnDestruction) {
EXPECT_FALSE(compatibilityString.empty());
EXPECT_EQ(allocator->m_info.size(), 1); // 1 allocation: blob
- EXPECT_EQ(::intel_npu::vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
+ EXPECT_EQ(functions->vclExecutableDestroy(executable), VCL_RESULT_SUCCESS);
// Purpose: Simulate VCL crash or early return where the memory is temporarily tracked as an orphan leak
// When the allocator goes out of scope and gets destroyed, it should cleanly free all tracked memory
diff --git a/src/plugins/intel_npu/tests/functional/internal/plugin/test_compiler_option_support_helper.cpp b/src/plugins/intel_npu/tests/functional/internal/plugin/test_compiler_option_support_helper.cpp
index 679a57decaa..132afc018df 100644
--- a/src/plugins/intel_npu/tests/functional/internal/plugin/test_compiler_option_support_helper.cpp
+++ b/src/plugins/intel_npu/tests/functional/internal/plugin/test_compiler_option_support_helper.cpp
@@ -43,7 +43,7 @@ size_t countOccurrences(const std::string& haystack, const std::string& needle)
}
// Only PluginCompilerAdapter's successful bulk load logs a distinctive, identifiable marker (see
-// "VCLCompilerImpl return supported_options" in plugin_compiler_adapter.cpp). DriverCompilerAdapter has
+// "VCLCompilerImpl return supported_options" in compiler_impl.cpp). DriverCompilerAdapter has
// no equivalent marker on its success path, so "exactly once" bulk-load checks below only apply to PLUGIN.
std::string bulkLoadMarkerFor(ov::intel_npu::CompilerType compilerType) {
return compilerType == ov::intel_npu::CompilerType::PLUGIN ? "VCLCompilerImpl return supported_options" : "";
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp
new file mode 100644
index 00000000000..300991c0f36
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/compiler_impl_test.cpp
@@ -0,0 +1,736 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "compiler_impl.hpp"
+
+#include <gtest/gtest.h>
+
+#include <cstdint>
+#include <limits>
+#include <memory>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "fake_vcl.hpp"
+#include "intel_npu/common/filtered_config.hpp"
+#include "intel_npu/config/options.hpp"
+#include "intel_npu/utils/utils.hpp"
+#include "model_serializer.hpp"
+#include "openvino/core/except.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/parameter.hpp"
+#include "ze_graph_ext_wrappers.hpp"
+
+using ::fake_vcl::FakeVcl;
+using ::intel_npu::FilteredConfig;
+using ::intel_npu::IDevice;
+using ::intel_npu::OptionsDesc;
+using ::intel_npu::VCLCompilerImpl;
+
+namespace {
+
+/// Registers just the options the compiler-in-plugin path reads, so `config.get<>` resolves.
+std::shared_ptr<OptionsDesc> makeOptionsDesc() {
+ auto desc = std::make_shared<OptionsDesc>();
+ desc->add<::intel_npu::MODEL_SERIALIZER_VERSION>();
+ desc->add<::intel_npu::WS_COMPILE_CALL_NUMBER>();
+ return desc;
+}
+
+FilteredConfig makeConfig() {
+ // Registration is all that is needed: compileWsIterative writes WS_COMPILE_CALL_NUMBER via
+ // update(), and MODEL_SERIALIZER_VERSION is read through config.get<>.
+ return FilteredConfig(makeOptionsDesc());
+}
+
+/// A minimal model with one weight, enough for the serializer to produce a real IR.
+std::shared_ptr<ov::Model> makeModel() {
+ auto weights = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{5}, std::vector<float>{1.0f});
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{5});
+ input->set_friendly_name("Parameter_0");
+ auto add = std::make_shared<ov::op::v1::Add>(input, weights);
+ add->set_friendly_name("Add_1");
+ return std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{input}, "compiler_impl_test_model");
+}
+
+struct VCLCompilerImplTest : public ::testing::Test {
+ FakeVcl fake;
+
+ std::shared_ptr<VCLCompilerImpl> makeCompiler(
+ const std::optional<IDevice::DeviceProperties>& props = std::nullopt) {
+ return std::make_shared<VCLCompilerImpl>(fake.functions(), props);
+ }
+};
+
+//
+// --- construction ---
+//
+
+TEST_F(VCLCompilerImplTest, ConstructionQueriesVersionCreatesCompilerAndReadsProperties) {
+ auto compiler = makeCompiler();
+ ASSERT_NE(compiler, nullptr);
+
+ EXPECT_TRUE(fake.called("vclGetVersion"));
+ EXPECT_EQ(fake.callCount("vclCompilerCreate"), 1u);
+ EXPECT_EQ(fake.callCount("vclCompilerGetProperties"), 1u);
+ // vclGetVersion must precede compiler creation: the negotiated version goes into the desc.
+ EXPECT_LT(fake.indexOf("vclGetVersion"), fake.indexOf("vclCompilerCreate"));
+}
+
+TEST_F(VCLCompilerImplTest, ConstructionForwardsTheNegotiatedVersionInTheCompilerDesc) {
+ fake.reportedCompilerVersion = {VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR};
+ auto compiler = makeCompiler();
+
+ ASSERT_EQ(fake.compilerDescs.size(), 1u);
+ EXPECT_EQ(fake.compilerDescs[0].version.major, VCL_COMPILER_VERSION_MAJOR);
+ EXPECT_EQ(fake.compilerDescs[0].version.minor, VCL_COMPILER_VERSION_MINOR);
+}
+
+TEST_F(VCLCompilerImplTest, DevicePropertiesAreForwardedExactly) {
+ IDevice::DeviceProperties props{0x1234u, 7u, 4u};
+ auto compiler = makeCompiler(props);
+
+ ASSERT_EQ(fake.deviceDescs.size(), 1u);
+ const auto& desc = fake.deviceDescs[0];
+ EXPECT_EQ(desc.size, sizeof(vcl_device_desc_t));
+ EXPECT_EQ(desc.deviceID, 0x1234u);
+ EXPECT_EQ(desc.revision, 7u);
+ EXPECT_EQ(desc.tileCount, 4u);
+}
+
+TEST_F(VCLCompilerImplTest, OversizedSubdeviceIdClampsToTheInvalidRevisionSentinel) {
+ constexpr auto sentinel = std::numeric_limits<uint16_t>::max();
+ // Anything at or above the sentinel cannot fit the 16-bit revision field.
+ IDevice::DeviceProperties props{0x1u, static_cast<uint32_t>(sentinel) + 5u, 1u};
+ auto compiler = makeCompiler(props);
+
+ ASSERT_EQ(fake.deviceDescs.size(), 1u);
+ EXPECT_EQ(fake.deviceDescs[0].revision, sentinel);
+}
+
+TEST_F(VCLCompilerImplTest, SubdeviceIdExactlyAtTheSentinelAlsoClamps) {
+ constexpr auto sentinel = std::numeric_limits<uint16_t>::max();
+ IDevice::DeviceProperties props{0x1u, static_cast<uint32_t>(sentinel), 1u};
+ auto compiler = makeCompiler(props);
+
+ ASSERT_EQ(fake.deviceDescs.size(), 1u);
+ EXPECT_EQ(fake.deviceDescs[0].revision, sentinel);
+}
+
+TEST_F(VCLCompilerImplTest, AbsentDevicePropertiesUseDefaultSentinels) {
+ auto compiler = makeCompiler(std::nullopt);
+
+ ASSERT_EQ(fake.deviceDescs.size(), 1u);
+ const auto& desc = fake.deviceDescs[0];
+ EXPECT_EQ(desc.size, sizeof(vcl_device_desc_t));
+ EXPECT_EQ(desc.deviceID, 0x00u);
+ EXPECT_EQ(desc.revision, std::numeric_limits<uint16_t>::max());
+ EXPECT_EQ(desc.tileCount, std::numeric_limits<uint32_t>::max());
+}
+
+TEST_F(VCLCompilerImplTest, NullApiTableIsRejected) {
+ EXPECT_THROW(
+ {
+ auto compiler = std::make_shared<VCLCompilerImpl>(nullptr);
+ (void)compiler;
+ },
+ ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, UnwiredFunctionTableIsRejected) {
+ // A default-constructed table: every entry point is null. Without the hasAllRequiredSymbols
+ // guard this would dispatch through a null vclGetVersion instead of throwing.
+ auto unwired = std::make_shared<const intel_npu::VCLFunctionTable>();
+ EXPECT_THROW(
+ {
+ auto compiler = std::make_shared<VCLCompilerImpl>(unwired);
+ (void)compiler;
+ },
+ ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, MissingWeakSymbolsDoNotBlockConstruction) {
+ // Weak symbols are legitimately null against an older compiler library, so the required-symbol
+ // guard must ignore them. FakeVcl already leaves the whole weak list null.
+ ASSERT_TRUE(fake.mutableFunctions()->vclAllocatedExecutableCreate2 == nullptr);
+
+ EXPECT_TRUE(fake.functions()->hasAllRequiredSymbols());
+ EXPECT_NO_THROW(makeCompiler());
+}
+
+TEST_F(VCLCompilerImplTest, MissingRequiredSymbolIsRejected) {
+ // vclAllocatedExecutableCreateWSOneShot2 is required, not weak: compileWsOneShot calls it with
+ // no null guard, so a library lacking it must be refused at construction rather than crashing
+ // on the first weights-separation compile.
+ fake.mutableFunctions()->vclAllocatedExecutableCreateWSOneShot2 = nullptr;
+
+ EXPECT_FALSE(fake.functions()->hasAllRequiredSymbols());
+ EXPECT_THROW(makeCompiler(), ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, GetVersionFailureThrows) {
+ fake.failWith("vclGetVersion", VCL_RESULT_ERROR_UNKNOWN);
+ EXPECT_THROW(makeCompiler(), ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, CompilerCreateFailureThrowsWithTheVclLogAppended) {
+ fake.logString = "compiler-create-exploded";
+ fake.failWith("vclCompilerCreate", VCL_RESULT_ERROR_OUT_OF_MEMORY);
+
+ try {
+ makeCompiler();
+ FAIL() << "Expected construction to throw";
+ } catch (const ov::Exception& error) {
+ const std::string what = error.what();
+ EXPECT_NE(what.find("vclCompilerCreate"), std::string::npos) << what;
+ EXPECT_NE(what.find("compiler-create-exploded"), std::string::npos) << what;
+ }
+}
+
+TEST_F(VCLCompilerImplTest, CompilerGetPropertiesFailureThrows) {
+ fake.failWith("vclCompilerGetProperties", VCL_RESULT_ERROR_UNKNOWN);
+ EXPECT_THROW(makeCompiler(), ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, ConstructionAcceptsALibraryBelowTheFloorAndDefersTheCheck) {
+ // Documents where the version gate actually lives: construction succeeds even for a too-old
+ // library, and the refusal happens on first compile/query (see CompileThrowsWhenTheLibraryIs...).
+ fake.reportedCompilerVersion = {VCL_COMPILER_VERSION_MAJOR - 1, 0};
+ auto compiler = makeCompiler();
+
+ ASSERT_NE(compiler, nullptr);
+ EXPECT_EQ(fake.callCount("vclCompilerCreate"), 1u);
+}
+
+//
+// --- destruction ---
+//
+
+TEST_F(VCLCompilerImplTest, DestructionDestroysTheCompilerExactlyOnce) {
+ {
+ auto compiler = makeCompiler();
+ }
+ EXPECT_EQ(fake.compilerDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, DestructionSwallowsCompilerDestroyFailure) {
+ fake.failWith("vclCompilerDestroy", VCL_RESULT_ERROR_UNKNOWN);
+ // A throwing destructor would terminate; the implementation only warns.
+ EXPECT_NO_THROW({ auto compiler = makeCompiler(); });
+ EXPECT_EQ(fake.compilerDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, FailedConstructionDoesNotDestroyAnUncreatedCompiler) {
+ fake.failWith("vclCompilerCreate", VCL_RESULT_ERROR_UNKNOWN);
+ EXPECT_THROW(makeCompiler(), ov::Exception);
+ EXPECT_EQ(fake.compilerDestroyCount, 0);
+}
+
+//
+// --- get_version ---
+//
+
+TEST_F(VCLCompilerImplTest, GetVersionPacksTheReportedPropertiesVersion) {
+ fake.propertiesVersion = {9, 3};
+ auto compiler = makeCompiler();
+
+ EXPECT_EQ(compiler->get_version(), ZE_MAKE_VERSION(9, 3));
+ EXPECT_EQ(compiler->get_version() >> 16, 9u);
+ EXPECT_EQ(compiler->get_version() & 0xFFFFu, 3u);
+}
+
+//
+// --- is_option_supported ---
+//
+
+TEST_F(VCLCompilerImplTest, IsOptionSupportedReturnsTrueOnSuccess) {
+ auto compiler = makeCompiler();
+ EXPECT_TRUE(compiler->is_option_supported("SOME_OPTION"));
+}
+
+TEST_F(VCLCompilerImplTest, IsOptionSupportedPassesNullptrWhenNoValueIsGiven) {
+ auto compiler = makeCompiler();
+ compiler->is_option_supported("SOME_OPTION");
+
+ ASSERT_EQ(fake.optionSupportQueries.size(), 1u);
+ EXPECT_EQ(fake.optionSupportQueries[0].first, "SOME_OPTION");
+ EXPECT_FALSE(fake.optionSupportQueries[0].second.has_value());
+}
+
+TEST_F(VCLCompilerImplTest, IsOptionSupportedForwardsTheValueWhenGiven) {
+ auto compiler = makeCompiler();
+ compiler->is_option_supported("SOME_OPTION", std::string("SOME_VALUE"));
+
+ ASSERT_EQ(fake.optionSupportQueries.size(), 1u);
+ EXPECT_EQ(fake.optionSupportQueries[0].first, "SOME_OPTION");
+ ASSERT_TRUE(fake.optionSupportQueries[0].second.has_value());
+ EXPECT_EQ(*fake.optionSupportQueries[0].second, "SOME_VALUE");
+}
+
+TEST_F(VCLCompilerImplTest, IsOptionSupportedSwallowsErrorsAndReportsFalse) {
+ auto compiler = makeCompiler();
+ // The exception is deliberately swallowed: older libraries lack this entry point.
+ fake.failWith("vclGetCompilerIsOptionSupported", VCL_RESULT_ERROR_UNSUPPORTED_FEATURE);
+ EXPECT_FALSE(compiler->is_option_supported("SOME_OPTION"));
+
+ fake.failWith("vclGetCompilerIsOptionSupported", VCL_RESULT_ERROR_UNKNOWN);
+ EXPECT_FALSE(compiler->is_option_supported("SOME_OPTION"));
+}
+
+//
+// --- get_supported_options ---
+//
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsUsesTheTwoCallSizeProtocol) {
+ auto compiler = makeCompiler();
+ const auto options = compiler->get_supported_options();
+
+ EXPECT_EQ(fake.callCount("vclGetCompilerSupportedOptions"), 2u);
+ EXPECT_EQ(options, std::vector<std::string>({"OPT_A", "OPT_B", "OPT_C"}));
+}
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsReturnsEmptyOnZeroSizeWithoutASecondCall) {
+ fake.supportedOptionsBuffer.clear();
+ auto compiler = makeCompiler();
+ const auto options = compiler->get_supported_options();
+
+ EXPECT_TRUE(options.empty());
+ // Size 0 short-circuits: only the sizing call happens.
+ EXPECT_EQ(fake.callCount("vclGetCompilerSupportedOptions"), 1u);
+}
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsTrimsTrailingNulsAndTokenises) {
+ // VCL pads the buffer with NULs; they must not become part of an option name.
+ fake.supportedOptionsBuffer = std::string("OPT_A OPT_B") + std::string(5, '\0');
+ auto compiler = makeCompiler();
+ const auto options = compiler->get_supported_options();
+
+ ASSERT_EQ(options.size(), 2u);
+ EXPECT_EQ(options[0], "OPT_A");
+ EXPECT_EQ(options[1], "OPT_B");
+}
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsCollapsesArbitraryWhitespace) {
+ fake.supportedOptionsBuffer = " OPT_A \t OPT_B \n OPT_C ";
+ auto compiler = makeCompiler();
+ EXPECT_EQ(compiler->get_supported_options(), std::vector<std::string>({"OPT_A", "OPT_B", "OPT_C"}));
+}
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsReturnsEmptyWhenTheBufferIsAllNuls) {
+ fake.supportedOptionsBuffer = std::string(8, '\0');
+ auto compiler = makeCompiler();
+ EXPECT_TRUE(compiler->get_supported_options().empty());
+}
+
+TEST_F(VCLCompilerImplTest, GetSupportedOptionsThrowsWhenTheSizingCallFails) {
+ auto compiler = makeCompiler();
+ fake.failWith("vclGetCompilerSupportedOptions", VCL_RESULT_ERROR_UNKNOWN);
+ EXPECT_THROW(compiler->get_supported_options(), ov::Exception);
+}
+
+//
+// --- process_profiling_output ---
+//
+
+TEST_F(VCLCompilerImplTest, ProcessProfilingOutputFollowsCreateGetDestroyOrdering) {
+ fake.profilingPayload.assign(2 * sizeof(ze_profiling_layer_info), 0);
+ auto compiler = makeCompiler();
+
+ const std::vector<uint8_t> profData{1, 2, 3};
+ const std::vector<uint8_t> network{4, 5, 6, 7};
+ const auto info = compiler->process_profiling_output(profData, network);
+
+ EXPECT_EQ(fake.callCount("vclProfilingCreate"), 1u);
+ EXPECT_EQ(fake.callCount("vclProfilingGetProperties"), 1u);
+ EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+
+ EXPECT_LT(fake.indexOf("vclProfilingCreate"), fake.indexOf("vclProfilingGetProperties"));
+ EXPECT_LT(fake.indexOf("vclProfilingGetProperties"), fake.indexOf("vclGetDecodedProfilingBuffer"));
+ EXPECT_LT(fake.indexOf("vclGetDecodedProfilingBuffer"), fake.indexOf("vclProfilingDestroy"));
+
+ // One entry per ze_profiling_layer_info in the returned buffer.
+ EXPECT_EQ(info.size(), 2u);
+}
+
+TEST_F(VCLCompilerImplTest, ProcessProfilingOutputSizesByLayerInfoStride) {
+ fake.profilingPayload.assign(5 * sizeof(ze_profiling_layer_info), 0);
+ auto compiler = makeCompiler();
+ EXPECT_EQ(compiler->process_profiling_output({1}, {2}).size(), 5u);
+}
+
+TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsOnNullData) {
+ fake.forceNullProfilingData = true;
+ auto compiler = makeCompiler();
+
+ try {
+ compiler->process_profiling_output({1}, {2});
+ FAIL() << "Expected a throw on NULL profiling data";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("Failed to get VCL profiling output"), std::string::npos);
+ }
+}
+
+TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsWhenCreateFails) {
+ // A decodable payload, so the scripted vclProfilingCreate failure is the only reason to throw.
+ fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
+ auto compiler = makeCompiler();
+ fake.failWith("vclProfilingCreate", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ compiler->process_profiling_output({1}, {2});
+ FAIL() << "Expected a throw on vclProfilingCreate failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclProfilingCreate"), std::string::npos);
+ }
+ // Nothing was created, so nothing must be destroyed.
+ EXPECT_EQ(fake.profilingDestroyCount, 0);
+}
+
+TEST_F(VCLCompilerImplTest, ProcessProfilingOutputThrowsWhenDestroyFails) {
+ // The payload must decode successfully, otherwise the null-data guard throws first and the
+ // destroy-failure path is never reached.
+ fake.profilingPayload.assign(sizeof(ze_profiling_layer_info), 0);
+ auto compiler = makeCompiler();
+ fake.failWith("vclProfilingDestroy", VCL_RESULT_ERROR_UNKNOWN);
+
+ try {
+ compiler->process_profiling_output({1}, {2});
+ FAIL() << "Expected a throw on vclProfilingDestroy failure";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("vclProfilingDestroy"), std::string::npos);
+ }
+ // The decode ran to completion before destroy was attempted.
+ EXPECT_EQ(fake.callCount("vclGetDecodedProfilingBuffer"), 1u);
+ EXPECT_EQ(fake.profilingDestroyCount, 1);
+}
+
+//
+// --- compile ---
+//
+
+TEST_F(VCLCompilerImplTest, CompileProducesABlobAndACompatibilityString) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), config);
+
+ EXPECT_EQ(fake.callCount("vclAllocatedExecutableCreate4"), 1u);
+ EXPECT_GT(tensor.get_byte_size(), 0u);
+ ASSERT_TRUE(compatibility.has_value());
+ EXPECT_EQ(*compatibility, "fake-compat");
+}
+
+TEST_F(VCLCompilerImplTest, CompileBuildFlagsAreIoInfoThenSpaceThenSerializedConfig) {
+ // This is the plugin's actual contract with the compiler; nothing else pins it down.
+ auto compiler = makeCompiler();
+ // compile() stamps the resolved serializer version into a local copy of the config, but only
+ // when the compiler advertises the option. Model a compiler that does not, so the flags are a
+ // pure function of the config the test holds. The stamping branch is covered separately.
+ fake.unsupportedOptions.insert(std::string(ov::intel_npu::model_serializer_version.name()));
+ auto config = makeConfig();
+ const auto model = makeModel();
+
+ const auto [tensor, compatibility] = compiler->compile(model, config);
+ (void)tensor;
+ (void)compatibility;
+
+ ze_graph_compiler_version_info_t compilerVersion{};
+ compilerVersion.major = fake.propertiesVersion.major;
+ compilerVersion.minor = fake.propertiesVersion.minor;
+
+ const auto isSupported = [&compiler](const std::string& name) {
+ return compiler->is_option_supported(name);
+ };
+ const std::string expected = ::intel_npu::compiler_utils::serializeIOInfo(model, true) + " " +
+ ::intel_npu::compiler_utils::serializeConfig(config, compilerVersion, isSupported);
+
+ ASSERT_EQ(fake.buildFlags.size(), 1u);
+ EXPECT_EQ(fake.buildFlags[0], expected);
+}
+
+TEST_F(VCLCompilerImplTest, CompileStampsTheResolvedSerializerVersionWhenAdvertised) {
+ // compile() serializes the IR first, then writes back the serializer version it actually used
+ // so the compiler parses the IR the same way. The value is serializeIR's choice, so pin the key.
+ auto compiler = makeCompiler();
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), makeConfig());
+ (void)tensor;
+ (void)compatibility;
+
+ const std::string key = std::string(ov::intel_npu::model_serializer_version.name()) + "=\"";
+ ASSERT_EQ(fake.buildFlags.size(), 1u);
+ EXPECT_NE(fake.buildFlags[0].find(key), std::string::npos);
+}
+
+TEST_F(VCLCompilerImplTest, CompileOmitsTheSerializerVersionWhenNotAdvertised) {
+ // Sending an option the compiler does not know about is a build-flag parse error, so the
+ // write-back must be gated on is_option_supported.
+ auto compiler = makeCompiler();
+ fake.unsupportedOptions.insert(std::string(ov::intel_npu::model_serializer_version.name()));
+
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), makeConfig());
+ (void)tensor;
+ (void)compatibility;
+
+ ASSERT_EQ(fake.buildFlags.size(), 1u);
+ EXPECT_EQ(fake.buildFlags[0].find(ov::intel_npu::model_serializer_version.name()), std::string::npos);
+}
+
+TEST_F(VCLCompilerImplTest, CompileReturnsTheAlignedAllocatorSizeNotTheVclBlobSize) {
+ // VCL reports the logical blob size; the tensor must expose the page-aligned allocation, because
+ // that is what was actually reserved and what the deleter will free.
+ fake.blobPayload.assign(5, 0xAB);
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), config);
+ (void)compatibility;
+
+ const size_t alignedExpected = ::intel_npu::utils::align_size_to_standard_page_size(5);
+ EXPECT_EQ(tensor.get_byte_size(), alignedExpected);
+ EXPECT_NE(tensor.get_byte_size(), 5u);
+ // The payload still lands at the start of the buffer.
+ EXPECT_EQ(static_cast<const uint8_t*>(tensor.data())[0], 0xAB);
+}
+
+TEST_F(VCLCompilerImplTest, CompileDestroysTheExecutableOnTheSuccessPath) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto result = compiler->compile(makeModel(), config);
+ (void)result;
+
+ EXPECT_EQ(fake.executableDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, CompileCleansUpAllocationsWhenExecutableCreationFails) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.logString = "create4-failed";
+ fake.failWith("vclAllocatedExecutableCreate4", VCL_RESULT_ERROR_OUT_OF_MEMORY);
+
+ try {
+ compiler->compile(makeModel(), config);
+ FAIL() << "Expected compile to throw";
+ } catch (const ov::Exception& error) {
+ const std::string what = error.what();
+ EXPECT_NE(what.find("vclAllocatedExecutableCreate4"), std::string::npos) << what;
+ EXPECT_NE(what.find("create4-failed"), std::string::npos) << what;
+ }
+}
+
+TEST_F(VCLCompilerImplTest, CompileDestroysTheExecutableWhenTheCompatibilityLookupThrows) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ // A hard failure (not UNSUPPORTED_FEATURE) propagates, but must not leak the executable.
+ fake.failWith("vclExecutableGetCompatibilityString", VCL_RESULT_ERROR_UNKNOWN);
+
+ EXPECT_THROW(compiler->compile(makeModel(), config), ov::Exception);
+ EXPECT_EQ(fake.executableDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, CompileTreatsUnsupportedCompatibilityStringAsAbsentNotAnError) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.compatibilityString.reset(); // makes the fake report UNSUPPORTED_FEATURE
+
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), config);
+ (void)tensor;
+
+ EXPECT_FALSE(compatibility.has_value());
+ EXPECT_EQ(fake.executableDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, CompileTrimsTheTrailingNulFromTheCompatibilityString) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.compatibilityString = std::string("compat-value");
+
+ const auto [tensor, compatibility] = compiler->compile(makeModel(), config);
+ (void)tensor;
+
+ ASSERT_TRUE(compatibility.has_value());
+ // No embedded NUL should survive into the string.
+ EXPECT_EQ(*compatibility, "compat-value");
+ EXPECT_EQ(compatibility->size(), std::string("compat-value").size());
+}
+
+TEST_F(VCLCompilerImplTest, CompileThrowsOnZeroSizedCompatibilityString) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.compatibilityString = std::string("ignored");
+ fake.compatibilityStringSizeOverride = 0u;
+
+ EXPECT_THROW(compiler->compile(makeModel(), config), ov::Exception);
+ EXPECT_EQ(fake.executableDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, CompileThrowsWhenExecutableDestroyFails) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.failWith("vclExecutableDestroy", VCL_RESULT_ERROR_UNKNOWN);
+
+ EXPECT_THROW(compiler->compile(makeModel(), config), ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, CompileThrowsWhenTheLibraryIsBelowTheSupportedFloor) {
+ fake.reportedCompilerVersion = {VCL_COMPILER_VERSION_MAJOR - 1, 0};
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ EXPECT_THROW(compiler->compile(makeModel(), config), ov::Exception);
+ // The version gate fires before any executable is created.
+ EXPECT_FALSE(fake.called("vclAllocatedExecutableCreate4"));
+}
+
+TEST_F(VCLCompilerImplTest, QueryThrowsWhenTheLibraryIsBelowTheSupportedFloor) {
+ // query() negotiates the version like compile() does, so it must apply the same floor: an
+ // unsupported library would otherwise be asked to parse an IR it cannot understand.
+ fake.reportedCompilerVersion = {VCL_COMPILER_VERSION_MAJOR - 1, 0};
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ EXPECT_THROW(compiler->query(makeModel(), config), ov::Exception);
+ // The version gate fires before the query handle is created.
+ EXPECT_FALSE(fake.called("vclQueryNetworkCreate"));
+}
+
+//
+// --- compileWsOneShot ---
+//
+
+TEST_F(VCLCompilerImplTest, CompileWsOneShotReturnsOneTensorPerAllocation) {
+ fake.wsBlobSizes = {8, 16, 32};
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto [tensors, compatibility] = compiler->compileWsOneShot(makeModel(), config);
+
+ EXPECT_EQ(fake.callCount("vclAllocatedExecutableCreateWSOneShot2"), 1u);
+ ASSERT_EQ(tensors.size(), 3u);
+ ASSERT_TRUE(compatibility.has_value());
+ EXPECT_EQ(*compatibility, "fake-compat");
+}
+
+TEST_F(VCLCompilerImplTest, CompileWsOneShotOrdersInitSchedulesBeforeMain) {
+ // The adapter consumes the last tensor as the main schedule, so allocation order is load-bearing.
+ fake.wsBlobSizes = {8, 16, 4096 * 3};
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto [tensors, compatibility] = compiler->compileWsOneShot(makeModel(), config);
+ (void)compatibility;
+
+ ASSERT_EQ(tensors.size(), 3u);
+ EXPECT_EQ(tensors.back().get_byte_size(), ::intel_npu::utils::align_size_to_standard_page_size(4096 * 3));
+}
+
+TEST_F(VCLCompilerImplTest, CompileWsOneShotThrowsAndDestroysExecutableWhenNothingWasAllocated) {
+ fake.wsBlobSizes.clear(); // no allocations -> m_info stays empty
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ try {
+ compiler->compileWsOneShot(makeModel(), config);
+ FAIL() << "Expected compileWsOneShot to throw";
+ } catch (const ov::Exception& error) {
+ EXPECT_NE(std::string(error.what()).find("blobCount is zero"), std::string::npos) << error.what();
+ }
+ EXPECT_EQ(fake.executableDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, CompileWsOneShotThrowsWhenCreationFails) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.failWith("vclAllocatedExecutableCreateWSOneShot2", VCL_RESULT_ERROR_UNKNOWN);
+
+ EXPECT_THROW(compiler->compileWsOneShot(makeModel(), config), ov::Exception);
+}
+
+//
+// --- compileWsIterative ---
+//
+
+TEST_F(VCLCompilerImplTest, CompileWsIterativeGoesThroughTheSingleBlobPath) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto [tensor, compatibility] = compiler->compileWsIterative(makeModel(), config, 2);
+ (void)compatibility;
+
+ EXPECT_EQ(fake.callCount("vclAllocatedExecutableCreate4"), 1u);
+ EXPECT_GT(tensor.get_byte_size(), 0u);
+}
+
+//
+// --- query ---
+//
+
+TEST_F(VCLCompilerImplTest, QueryParsesSupportedLayersAndKeysThemToNPU) {
+ const std::string payload = "<Parameter_0><Add_1>";
+ fake.queryResultBuffer.assign(payload.begin(), payload.end());
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto supported = compiler->query(makeModel(), config);
+
+ ASSERT_EQ(supported.size(), 2u);
+ ASSERT_TRUE(supported.count("Parameter_0"));
+ ASSERT_TRUE(supported.count("Add_1"));
+ EXPECT_EQ(supported.at("Parameter_0"), "NPU");
+ EXPECT_EQ(supported.at("Add_1"), "NPU");
+}
+
+TEST_F(VCLCompilerImplTest, QueryUsesTheTwoCallSizeProtocolAndDestroysTheHandle) {
+ const std::string payload = "<Add_1>";
+ fake.queryResultBuffer.assign(payload.begin(), payload.end());
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ const auto supported = compiler->query(makeModel(), config);
+ (void)supported;
+
+ EXPECT_EQ(fake.callCount("vclQueryNetworkCreate"), 1u);
+ EXPECT_EQ(fake.callCount("vclQueryNetwork"), 2u);
+ EXPECT_EQ(fake.queryDestroyCount, 1);
+}
+
+TEST_F(VCLCompilerImplTest, QueryReturnsAnEmptyMapForAnEmptyResult) {
+ fake.queryResultBuffer.clear();
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+
+ EXPECT_TRUE(compiler->query(makeModel(), config).empty());
+}
+
+TEST_F(VCLCompilerImplTest, QueryThrowsWhenCreationFails) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.failWith("vclQueryNetworkCreate", VCL_RESULT_ERROR_INVALID_IR);
+
+ EXPECT_THROW(compiler->query(makeModel(), config), ov::Exception);
+ EXPECT_EQ(fake.queryDestroyCount, 0);
+}
+
+TEST_F(VCLCompilerImplTest, QueryThrowsWhenTheResultFetchFails) {
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.failWith("vclQueryNetwork", VCL_RESULT_ERROR_UNKNOWN);
+
+ EXPECT_THROW(compiler->query(makeModel(), config), ov::Exception);
+}
+
+TEST_F(VCLCompilerImplTest, QueryThrowsWhenDestroyFails) {
+ const std::string payload = "<Add_1>";
+ fake.queryResultBuffer.assign(payload.begin(), payload.end());
+ auto compiler = makeCompiler();
+ auto config = makeConfig();
+ fake.failWith("vclQueryNetworkDestroy", VCL_RESULT_ERROR_UNKNOWN);
+
+ EXPECT_THROW(compiler->query(makeModel(), config), ov::Exception);
+}
+
+} // namespace
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl.hpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl.hpp
new file mode 100644
index 00000000000..ee39d212f1c
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl.hpp
@@ -0,0 +1,573 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <cstdint>
+#include <cstring>
+#include <map>
+#include <memory>
+#include <optional>
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "intel_npu/utils/vcl/vcl_api.hpp"
+
+namespace fake_vcl {
+
+//
+// The VCL entry points are plain C function pointers with no user-data parameter, so the fake has to
+// route through a file-static "current instance" pointer. FakeVcl sets it on construction and clears
+// it on destruction, which keeps one fake per test.
+//
+class FakeVcl;
+inline FakeVcl*& current() {
+ static FakeVcl* instance = nullptr;
+ return instance;
+}
+
+/// State objects the opaque VCL handles point at. Never dereferenced by production code, so empty
+/// structs with distinct addresses are enough.
+struct FakeCompilerState {
+ int tag = 1;
+};
+struct FakeExecutableState {
+ int tag = 2;
+};
+struct FakeQueryState {
+ int tag = 3;
+};
+struct FakeProfilingState {
+ int tag = 4;
+};
+struct FakeLogState {
+ int tag = 5;
+};
+
+class FakeVcl {
+public:
+ FakeVcl() {
+ current() = this;
+ // A default-constructed table is all-null, which is a legitimate value. No test-only
+ // constructor, tag, or friend declaration is needed to get one.
+ _functions = std::make_shared<intel_npu::VCLFunctionTable>();
+ wire();
+ }
+
+ ~FakeVcl() {
+ current() = nullptr;
+ }
+
+ FakeVcl(const FakeVcl&) = delete;
+ FakeVcl& operator=(const FakeVcl&) = delete;
+
+ /// The function table to inject into VCLCompilerImpl.
+ std::shared_ptr<const intel_npu::VCLFunctionTable> functions() const {
+ return _functions;
+ }
+ /// Same table, writable, for tests that need to null an entry point out.
+ std::shared_ptr<intel_npu::VCLFunctionTable> mutableFunctions() const {
+ return _functions;
+ }
+
+ //
+ // --- scripting ---
+ //
+
+ /// Force a specific entry point to fail. Cleared per entry point.
+ void failWith(const std::string& fn, vcl_result_t result) {
+ _results[fn] = result;
+ }
+ void succeed(const std::string& fn) {
+ _results.erase(fn);
+ }
+
+ vcl_result_t resultFor(const std::string& fn) {
+ calls.push_back(fn);
+ const auto it = _results.find(fn);
+ return it == _results.end() ? VCL_RESULT_SUCCESS : it->second;
+ }
+
+ //
+ // --- inputs the fake reports back to production code ---
+ //
+
+ vcl_version_info_t reportedCompilerVersion{VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR};
+ vcl_version_info_t reportedProfilingVersion{VCL_PROFILING_VERSION_MAJOR, VCL_PROFILING_VERSION_MINOR};
+ vcl_version_info_t propertiesVersion{VCL_COMPILER_VERSION_MAJOR, VCL_COMPILER_VERSION_MINOR};
+ uint32_t supportedOpsets = 11;
+ std::string compilerId = "fake-vcl";
+
+ std::string logString = "fake vcl log";
+
+ /// Blob bytes handed back by vclAllocatedExecutableCreate4.
+ std::vector<uint8_t> blobPayload{1, 2, 3, 4, 5};
+ /// Per-blob sizes handed back by vclAllocatedExecutableCreateWSOneShot2 (init schedules, then main).
+ std::vector<size_t> wsBlobSizes{8, 16, 32};
+
+ /// nullopt makes vclExecutableGetCompatibilityString report UNSUPPORTED_FEATURE.
+ std::optional<std::string> compatibilityString = std::string("fake-compat");
+ /// When set, the reported size is used instead of compatibilityString->size() + 1.
+ std::optional<uint64_t> compatibilityStringSizeOverride;
+
+ /// Raw buffer returned by vclGetCompilerSupportedOptions (trailing NULs are meaningful).
+ std::string supportedOptionsBuffer = std::string("OPT_A OPT_B OPT_C");
+
+ /// Options vclGetCompilerIsOptionSupported reports as UNSUPPORTED_FEATURE. Everything else
+ /// follows failWith("vclGetCompilerIsOptionSupported", ...), so a fake can model a compiler
+ /// that advertises most options but not a specific one.
+ std::set<std::string> unsupportedOptions;
+
+ /// Raw buffer returned by vclQueryNetwork.
+ std::vector<char> queryResultBuffer;
+
+ /// Bytes returned by vclGetDecodedProfilingBuffer.
+ std::vector<uint8_t> profilingPayload;
+ /// The only route to a null `data` pointer. An empty profilingPayload reports size 0 with a
+ /// non-null pointer instead, so "no profiling bytes" and "the compiler returned nothing" stay
+ /// distinct states - conflating them let a destroy-failure test pass on the null-data path.
+ bool forceNullProfilingData = false;
+ /// Handed out as `data` when profilingPayload is empty; never dereferenced, since size is 0.
+ uint8_t emptyPayloadSentinel = 0;
+
+ //
+ // --- recordings ---
+ //
+
+ std::vector<std::string> calls;
+ std::vector<vcl_device_desc_t> deviceDescs;
+ std::vector<vcl_compiler_desc_t> compilerDescs;
+ /// The build-flags string handed to VCL, per executable-creating call.
+ std::vector<std::string> buildFlags;
+ /// Model IR bytes handed to VCL, per executable-creating call.
+ std::vector<uint64_t> modelIrSizes;
+ std::vector<std::string> queryBuildFlags;
+ /// (option, value) pairs seen by vclGetCompilerIsOptionSupported; value is nullopt for nullptr.
+ std::vector<std::pair<std::string, std::optional<std::string>>> optionSupportQueries;
+
+ int compilerDestroyCount = 0;
+ int executableDestroyCount = 0;
+ int queryDestroyCount = 0;
+ int profilingDestroyCount = 0;
+
+ size_t callCount(const std::string& fn) const {
+ size_t n = 0;
+ for (const auto& c : calls) {
+ if (c == fn) {
+ ++n;
+ }
+ }
+ return n;
+ }
+
+ bool called(const std::string& fn) const {
+ return callCount(fn) > 0;
+ }
+
+ /// Index of the first occurrence of fn in the call log, or npos.
+ size_t indexOf(const std::string& fn) const {
+ for (size_t i = 0; i < calls.size(); ++i) {
+ if (calls[i] == fn) {
+ return i;
+ }
+ }
+ return std::string::npos;
+ }
+
+ // Handle-backing state, kept alive for the fake's lifetime.
+ FakeCompilerState compilerState;
+ FakeExecutableState executableState;
+ FakeQueryState queryState;
+ FakeProfilingState profilingState;
+ FakeLogState logState;
+
+private:
+ void wire();
+
+ std::shared_ptr<intel_npu::VCLFunctionTable> _functions;
+ std::map<std::string, vcl_result_t> _results;
+};
+
+//
+// --- thunks ---
+//
+
+#define FAKE_GUARD(fn) \
+ FakeVcl* self = current(); \
+ if (self == nullptr) { \
+ return VCL_RESULT_ERROR_UNKNOWN; \
+ } \
+ const vcl_result_t scripted = self->resultFor(#fn); \
+ if (scripted != VCL_RESULT_SUCCESS) { \
+ return scripted; \
+ }
+
+inline vcl_result_t VCL_APICALL fake_vclGetVersion(vcl_version_info_t* compilerVersion,
+ vcl_version_info_t* profilingVersion) {
+ FAKE_GUARD(vclGetVersion)
+ if (compilerVersion != nullptr) {
+ *compilerVersion = self->reportedCompilerVersion;
+ }
+ if (profilingVersion != nullptr) {
+ *profilingVersion = self->reportedProfilingVersion;
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclCompilerCreate(vcl_compiler_desc_t* compilerDesc,
+ vcl_device_desc_t* deviceDesc,
+ vcl_compiler_handle_t* compiler,
+ vcl_log_handle_t* logHandle) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ // Record the descriptors even on the failure path: the test asserts what was forwarded.
+ if (compilerDesc != nullptr) {
+ self->compilerDescs.push_back(*compilerDesc);
+ }
+ if (deviceDesc != nullptr) {
+ self->deviceDescs.push_back(*deviceDesc);
+ }
+ const vcl_result_t scripted = self->resultFor("vclCompilerCreate");
+ if (scripted != VCL_RESULT_SUCCESS) {
+ return scripted;
+ }
+ if (compiler != nullptr) {
+ *compiler = reinterpret_cast<vcl_compiler_handle_t>(&self->compilerState);
+ }
+ if (logHandle != nullptr) {
+ *logHandle = reinterpret_cast<vcl_log_handle_t>(&self->logState);
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclCompilerDestroy(vcl_compiler_handle_t) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ ++self->compilerDestroyCount;
+ return self->resultFor("vclCompilerDestroy");
+}
+
+inline vcl_result_t VCL_APICALL fake_vclCompilerGetProperties(vcl_compiler_handle_t,
+ vcl_compiler_properties_t* properties) {
+ FAKE_GUARD(vclCompilerGetProperties)
+ if (properties != nullptr) {
+ properties->id = self->compilerId.c_str();
+ properties->version = self->propertiesVersion;
+ properties->supportedOpsets = self->supportedOpsets;
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclLogHandleGetString(vcl_log_handle_t, size_t* logSize, char* log) {
+ FAKE_GUARD(vclLogHandleGetString)
+ if (logSize == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ if (log == nullptr) {
+ *logSize = self->logString.size();
+ return VCL_RESULT_SUCCESS;
+ }
+ std::memcpy(log, self->logString.data(), self->logString.size());
+ *logSize = self->logString.size();
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclAllocatedExecutableCreate4(vcl_compiler_handle_t,
+ vcl_executable_desc_t desc,
+ vcl_allocator2_t* allocator,
+ uint8_t** blobBuffer,
+ uint64_t* blobSize,
+ vcl_executable_handle_t* executable) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ if (desc.options != nullptr) {
+ self->buildFlags.emplace_back(desc.options, static_cast<size_t>(desc.optionsSize));
+ }
+ self->modelIrSizes.push_back(desc.modelIRSize);
+
+ const vcl_result_t scripted = self->resultFor("vclAllocatedExecutableCreate4");
+ if (scripted != VCL_RESULT_SUCCESS) {
+ return scripted;
+ }
+ if (allocator == nullptr || blobBuffer == nullptr || blobSize == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+
+ const size_t size = self->blobPayload.size();
+ uint8_t* buffer = allocator->allocate(allocator, size);
+ if (buffer == nullptr) {
+ return VCL_RESULT_ERROR_OUT_OF_MEMORY;
+ }
+ std::memcpy(buffer, self->blobPayload.data(), size);
+ *blobBuffer = buffer;
+ *blobSize = size;
+ if (executable != nullptr) {
+ *executable = reinterpret_cast<vcl_executable_handle_t>(&self->executableState);
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclAllocatedExecutableCreateWSOneShot2(vcl_compiler_handle_t,
+ vcl_executable_desc_t desc,
+ vcl_allocator2_t* allocator,
+ vcl_executable_handle_t* executable) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ if (desc.options != nullptr) {
+ self->buildFlags.emplace_back(desc.options, static_cast<size_t>(desc.optionsSize));
+ }
+ self->modelIrSizes.push_back(desc.modelIRSize);
+
+ const vcl_result_t scripted = self->resultFor("vclAllocatedExecutableCreateWSOneShot2");
+ if (scripted != VCL_RESULT_SUCCESS) {
+ return scripted;
+ }
+ if (allocator == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ // One allocation per blob: init schedules first, main last.
+ for (size_t size : self->wsBlobSizes) {
+ uint8_t* buffer = allocator->allocate(allocator, size);
+ if (buffer == nullptr) {
+ return VCL_RESULT_ERROR_OUT_OF_MEMORY;
+ }
+ std::memset(buffer, static_cast<int>(size & 0xFF), size);
+ }
+ if (executable != nullptr) {
+ *executable = reinterpret_cast<vcl_executable_handle_t>(&self->executableState);
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclExecutableGetCompatibilityString(vcl_executable_handle_t,
+ char* buffer,
+ uint64_t* size) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ const vcl_result_t scripted = self->resultFor("vclExecutableGetCompatibilityString");
+ if (scripted != VCL_RESULT_SUCCESS) {
+ return scripted;
+ }
+ if (!self->compatibilityString.has_value()) {
+ return VCL_RESULT_ERROR_UNSUPPORTED_FEATURE;
+ }
+ if (size == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ // VCL reports the size including the NUL terminator.
+ const std::string& value = *self->compatibilityString;
+ const uint64_t reported = self->compatibilityStringSizeOverride.value_or(static_cast<uint64_t>(value.size()) + 1u);
+ if (buffer == nullptr) {
+ *size = reported;
+ return VCL_RESULT_SUCCESS;
+ }
+ const size_t toCopy = static_cast<size_t>(reported == 0 ? 0 : reported - 1);
+ std::memcpy(buffer, value.data(), std::min(toCopy, value.size()));
+ if (reported > 0) {
+ buffer[reported - 1] = '\0';
+ }
+ *size = reported;
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclExecutableDestroy(vcl_executable_handle_t) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ ++self->executableDestroyCount;
+ return self->resultFor("vclExecutableDestroy");
+}
+
+inline vcl_result_t VCL_APICALL fake_vclQueryNetworkCreate(vcl_compiler_handle_t,
+ vcl_query_desc_t desc,
+ vcl_query_handle_t* query) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ if (desc.options != nullptr) {
+ self->queryBuildFlags.emplace_back(desc.options, static_cast<size_t>(desc.optionsSize));
+ }
+ const vcl_result_t scripted = self->resultFor("vclQueryNetworkCreate");
+ if (scripted != VCL_RESULT_SUCCESS) {
+ return scripted;
+ }
+ if (query != nullptr) {
+ *query = reinterpret_cast<vcl_query_handle_t>(&self->queryState);
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclQueryNetwork(vcl_query_handle_t, uint8_t* queryResult, uint64_t* size) {
+ FAKE_GUARD(vclQueryNetwork)
+ if (size == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ if (queryResult == nullptr) {
+ *size = self->queryResultBuffer.size();
+ return VCL_RESULT_SUCCESS;
+ }
+ std::memcpy(queryResult, self->queryResultBuffer.data(), self->queryResultBuffer.size());
+ *size = self->queryResultBuffer.size();
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclQueryNetworkDestroy(vcl_query_handle_t) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ ++self->queryDestroyCount;
+ return self->resultFor("vclQueryNetworkDestroy");
+}
+
+inline vcl_result_t VCL_APICALL fake_vclProfilingCreate(p_vcl_profiling_input_t,
+ vcl_profiling_handle_t* profilingHandle,
+ vcl_log_handle_t* logHandle) {
+ FAKE_GUARD(vclProfilingCreate)
+ if (profilingHandle != nullptr) {
+ *profilingHandle = reinterpret_cast<vcl_profiling_handle_t>(&self->profilingState);
+ }
+ if (logHandle != nullptr) {
+ *logHandle = reinterpret_cast<vcl_log_handle_t>(&self->logState);
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclProfilingGetProperties(vcl_profiling_handle_t,
+ vcl_profiling_properties_t* properties) {
+ FAKE_GUARD(vclProfilingGetProperties)
+ if (properties != nullptr) {
+ properties->version = self->reportedProfilingVersion;
+ }
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclGetDecodedProfilingBuffer(vcl_profiling_handle_t,
+ vcl_profiling_request_type_t,
+ p_vcl_profiling_output_t output) {
+ FAKE_GUARD(vclGetDecodedProfilingBuffer)
+ if (output == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ if (self->forceNullProfilingData) {
+ output->data = nullptr;
+ output->size = 0;
+ return VCL_RESULT_SUCCESS;
+ }
+ // An empty vector's data() is allowed to be null, which would masquerade as the
+ // forceNullProfilingData case. Hand out a sentinel instead so size 0 still means "success with
+ // no bytes" rather than "the compiler returned nothing".
+ output->data = self->profilingPayload.empty() ? &self->emptyPayloadSentinel : self->profilingPayload.data();
+ output->size = self->profilingPayload.size();
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclProfilingDestroy(vcl_profiling_handle_t) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ ++self->profilingDestroyCount;
+ return self->resultFor("vclProfilingDestroy");
+}
+
+inline vcl_result_t VCL_APICALL fake_vclGetCompilerSupportedOptions(vcl_compiler_handle_t,
+ char* result,
+ uint64_t* size) {
+ FAKE_GUARD(vclGetCompilerSupportedOptions)
+ if (size == nullptr) {
+ return VCL_RESULT_ERROR_INVALID_ARGUMENT;
+ }
+ const std::string& buffer = self->supportedOptionsBuffer;
+ if (result == nullptr) {
+ *size = buffer.size();
+ return VCL_RESULT_SUCCESS;
+ }
+ std::memcpy(result, buffer.data(), buffer.size());
+ *size = buffer.size();
+ return VCL_RESULT_SUCCESS;
+}
+
+inline vcl_result_t VCL_APICALL fake_vclGetCompilerIsOptionSupported(vcl_compiler_handle_t,
+ const char* option,
+ const char* value) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ const std::string optionName = option != nullptr ? std::string(option) : std::string();
+ self->optionSupportQueries.emplace_back(
+ optionName,
+ value != nullptr ? std::optional<std::string>(std::string(value)) : std::nullopt);
+ if (self->unsupportedOptions.count(optionName) != 0) {
+ self->calls.push_back("vclGetCompilerIsOptionSupported");
+ return VCL_RESULT_ERROR_UNSUPPORTED_FEATURE;
+ }
+ return self->resultFor("vclGetCompilerIsOptionSupported");
+}
+
+// Entry points the production code under test never calls; wired so a stray call is obvious.
+inline vcl_result_t VCL_APICALL fake_vclExecutableCreate(vcl_compiler_handle_t,
+ vcl_executable_desc_t,
+ vcl_executable_handle_t*) {
+ FakeVcl* self = current();
+ return self == nullptr ? VCL_RESULT_ERROR_UNKNOWN : self->resultFor("vclExecutableCreate");
+}
+
+inline vcl_result_t VCL_APICALL fake_vclExecutableGetSerializableBlob(vcl_executable_handle_t,
+ uint8_t*,
+ uint64_t* blobSize) {
+ FakeVcl* self = current();
+ if (self == nullptr) {
+ return VCL_RESULT_ERROR_UNKNOWN;
+ }
+ if (blobSize != nullptr) {
+ *blobSize = 0;
+ }
+ return self->resultFor("vclExecutableGetSerializableBlob");
+}
+
+#undef FAKE_GUARD
+
+inline void FakeVcl::wire() {
+ _functions->vclGetVersion = &fake_vclGetVersion;
+ _functions->vclCompilerCreate = &fake_vclCompilerCreate;
+ _functions->vclCompilerDestroy = &fake_vclCompilerDestroy;
+ _functions->vclCompilerGetProperties = &fake_vclCompilerGetProperties;
+ _functions->vclQueryNetworkCreate = &fake_vclQueryNetworkCreate;
+ _functions->vclQueryNetwork = &fake_vclQueryNetwork;
+ _functions->vclQueryNetworkDestroy = &fake_vclQueryNetworkDestroy;
+ _functions->vclExecutableCreate = &fake_vclExecutableCreate;
+ _functions->vclExecutableDestroy = &fake_vclExecutableDestroy;
+ _functions->vclExecutableGetSerializableBlob = &fake_vclExecutableGetSerializableBlob;
+ _functions->vclProfilingCreate = &fake_vclProfilingCreate;
+ _functions->vclGetDecodedProfilingBuffer = &fake_vclGetDecodedProfilingBuffer;
+ _functions->vclProfilingDestroy = &fake_vclProfilingDestroy;
+ _functions->vclProfilingGetProperties = &fake_vclProfilingGetProperties;
+ _functions->vclLogHandleGetString = &fake_vclLogHandleGetString;
+ _functions->vclAllocatedExecutableCreate4 = &fake_vclAllocatedExecutableCreate4;
+ _functions->vclExecutableGetCompatibilityString = &fake_vclExecutableGetCompatibilityString;
+ _functions->vclGetCompilerSupportedOptions = &fake_vclGetCompilerSupportedOptions;
+ _functions->vclGetCompilerIsOptionSupported = &fake_vclGetCompilerIsOptionSupported;
+ _functions->vclAllocatedExecutableCreateWSOneShot2 = &fake_vclAllocatedExecutableCreateWSOneShot2;
+ // Weak symbols the production path does not use stay null, matching an older library.
+ _functions->vclAllocatedExecutableCreate2 = nullptr;
+}
+
+} // namespace fake_vcl
diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_version_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_version_test.cpp
new file mode 100644
index 00000000000..3070cd24b0b
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/vcl_version_test.cpp
@@ -0,0 +1,114 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <cstdint>
+#include <string>
+
+#include "intel_npu/utils/vcl/vcl.h"
+#include "openvino/core/except.hpp"
+#include "vcl_version_utils.hpp"
+
+namespace {
+
+using ::intel_npu::vcl_version_utils::checkVclVersion;
+using ::intel_npu::vcl_version_utils::getUsedVclVersion;
+using ::intel_npu::vcl_version_utils::UsedVersion;
+
+// The floor the plugin was built against.
+constexpr uint16_t kFloorMajor = VCL_COMPILER_VERSION_MAJOR;
+constexpr uint16_t kFloorMinor = VCL_COMPILER_VERSION_MINOR;
+
+// Convenience wrapper: negotiate against the real plugin floor, then validate.
+void negotiateAndCheck(uint16_t loadedMajor, uint16_t loadedMinor) {
+ const UsedVersion used = getUsedVclVersion(kFloorMajor, kFloorMinor, loadedMajor, loadedMinor);
+ checkVclVersion(used, loadedMajor, loadedMinor, kFloorMajor, kFloorMinor);
+}
+
+//
+// getUsedVclVersion — version negotiation
+//
+
+TEST(VclVersionTests, SameMajorTakesTheLowerMinor) {
+ // Plugin minor is the lower one.
+ EXPECT_EQ(getUsedVclVersion(7, 10, 7, 20).Major, 7);
+ EXPECT_EQ(getUsedVclVersion(7, 10, 7, 20).Minor, 10);
+
+ // Loaded minor is the lower one.
+ EXPECT_EQ(getUsedVclVersion(7, 20, 7, 10).Major, 7);
+ EXPECT_EQ(getUsedVclVersion(7, 20, 7, 10).Minor, 10);
+}
+
+TEST(VclVersionTests, SameMajorAndMinorIsUnchanged) {
+ const UsedVersion used = getUsedVclVersion(7, 10, 7, 10);
+ EXPECT_EQ(used.Major, 7);
+ EXPECT_EQ(used.Minor, 10);
+}
+
+TEST(VclVersionTests, PluginMajorNewerThanLibraryDowngradesToLibrary) {
+ // Plugin 9.3 against library 7.20 -> speak the library's 7.20, minor included.
+ const UsedVersion used = getUsedVclVersion(9, 3, 7, 20);
+ EXPECT_EQ(used.Major, 7);
+ EXPECT_EQ(used.Minor, 20);
+}
+
+TEST(VclVersionTests, PluginMajorOlderThanLibraryKeepsPluginVersion) {
+ // Plugin 7.10 against library 9.3 -> keep 7.10; the library is expected to be
+ // backward compatible.
+ const UsedVersion used = getUsedVclVersion(7, 10, 9, 3);
+ EXPECT_EQ(used.Major, 7);
+ EXPECT_EQ(used.Minor, 10);
+}
+
+//
+// checkVclVersion — floor enforcement
+//
+
+TEST(VclVersionTests, VersionAtTheFloorIsAccepted) {
+ EXPECT_NO_THROW(checkVclVersion(UsedVersion{7, 10}, 7, 10, 7, 10));
+}
+
+TEST(VclVersionTests, VersionAboveTheFloorIsAccepted) {
+ EXPECT_NO_THROW(checkVclVersion(UsedVersion{7, 11}, 7, 11, 7, 10));
+ EXPECT_NO_THROW(checkVclVersion(UsedVersion{8, 0}, 8, 0, 7, 10));
+}
+
+TEST(VclVersionTests, MinorBelowTheFloorThrows) {
+ EXPECT_THROW(checkVclVersion(UsedVersion{7, 9}, 7, 9, 7, 10), ov::Exception);
+}
+
+TEST(VclVersionTests, MajorBelowTheFloorThrows) {
+ EXPECT_THROW(checkVclVersion(UsedVersion{6, 99}, 6, 99, 7, 10), ov::Exception);
+}
+
+TEST(VclVersionTests, ThrowMessageReportsLoadedAndRequiredVersions) {
+ try {
+ checkVclVersion(UsedVersion{6, 1}, 6, 1, 7, 10);
+ FAIL() << "Expected checkVclVersion to throw";
+ } catch (const ov::Exception& error) {
+ const std::string what = error.what();
+ EXPECT_NE(what.find("Unsupported VCL version: 6.1"), std::string::npos) << what;
+ EXPECT_NE(what.find("please use VCL 7.10 or later"), std::string::npos) << what;
+ }
+}
+
+//
+// Negotiation and enforcement together, against the real plugin floor
+//
+
+TEST(VclVersionTests, LibraryOlderThanTheFloorIsRejected) {
+ // Negotiation downgrades to the library's version, which then fails the floor check.
+ ASSERT_GT(kFloorMinor, 0u) << "test assumes a non-zero plugin floor minor";
+ EXPECT_THROW(negotiateAndCheck(kFloorMajor, static_cast<uint16_t>(kFloorMinor - 1)), ov::Exception);
+ EXPECT_THROW(negotiateAndCheck(static_cast<uint16_t>(kFloorMajor - 1), 99), ov::Exception);
+}
+
+TEST(VclVersionTests, LibraryAtOrNewerThanTheFloorIsAccepted) {
+ EXPECT_NO_THROW(negotiateAndCheck(kFloorMajor, kFloorMinor));
+ EXPECT_NO_THROW(negotiateAndCheck(kFloorMajor, static_cast<uint16_t>(kFloorMinor + 1)));
+ EXPECT_NO_THROW(negotiateAndCheck(static_cast<uint16_t>(kFloorMajor + 1), 0));
+}
+
+} // namespace