OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Extract compiler impl interface (#38480)
Patrik Stepan286b49dbf91f
diff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txtindex edd84e80c69..5267759a9aa 100644--- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt+++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt@@ -10,6 +10,7 @@ set(SOURCES${CMAKE_CURRENT_SOURCE_DIR}/include/driver_compiler_adapter.hpp${CMAKE_CURRENT_SOURCE_DIR}/include/dynamic_graph.hpp${CMAKE_CURRENT_SOURCE_DIR}/include/graph.hpp+ ${CMAKE_CURRENT_SOURCE_DIR}/include/ivcl_compiler.hpp${CMAKE_CURRENT_SOURCE_DIR}/include/mem_usage.hpp${CMAKE_CURRENT_SOURCE_DIR}/include/model_serializer.hpp${CMAKE_CURRENT_SOURCE_DIR}/include/parser.hppdiff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hppindex 90cefbe3629..aea9a07bda7 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@@ -15,15 +15,17 @@#include "intel_npu/common/option_support_cache.hpp"#include "intel_npu/config/config.hpp"#include "intel_npu/utils/vcl/vcl_api.hpp"+#include "ivcl_compiler.hpp"#include "openvino/core/except.hpp"#include "openvino/core/model.hpp"#include "openvino/runtime/common.hpp"#include "openvino/runtime/profiling_info.hpp"+#include "openvino/runtime/so_ptr.hpp"#include "openvino/runtime/tensor.hpp"namespace intel_npu {-class VCLCompilerImpl final : public std::enable_shared_from_this<VCLCompilerImpl> {+class VCLCompilerImpl final : public IVCLCompiler, public std::enable_shared_from_this<VCLCompilerImpl> {public:/*** @param functions A shared pointer to the VCL function table@@ -34,7 +36,7 @@ public:VCLCompilerImpl(std::shared_ptr<const VCLFunctionTable> functions,const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt,ScopedOptionSupportCache optionSupportCache = {});- ~VCLCompilerImpl();+ ~VCLCompilerImpl() override;/*** @brief Transforms a network from the OpenVINO model representation to a format executable@@ -46,7 +48,7 @@ public:* string with runtime requirements for the blob*/std::pair<ov::Tensor, std::optional<std::string>> compile(const std::shared_ptr<const ov::Model>& model,- const Config& config) const;+ const Config& config) const override;/*** @brief Compiles the model, weights separation enabled. All init schedules along with the main one are compiled in@@ -56,7 +58,7 @@ public:*/std::pair<std::vector<ov::Tensor>, std::optional<std::string>> compileWsOneShot(const std::shared_ptr<ov::Model>& model,- const Config& config) const;+ const Config& config) const override;/*** @brief Sequential compilation of Init(s) and Main*@@ -73,7 +75,7 @@ public:*/std::pair<ov::Tensor, std::optional<std::string>> compileWsIterative(const std::shared_ptr<ov::Model>& model,const Config& config,- size_t callNumber) const;+ size_t callNumber) const override;/*** @brief Returns information about supported layers of the network passed* @param model The model to be queried@@ -81,7 +83,7 @@ public:* including config options related to compilation* @returns SupportedOpsMap structure with information about supported layers*/- ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const;+ ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;/*** @brief Returns the compiler version@@ -89,17 +91,17 @@ public:* MSB 16 bits = Major version* LSB 16bits = Minor version*/- uint32_t get_version() const;+ uint32_t get_version() const override;std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,- const std::vector<uint8_t>& network) const;+ const std::vector<uint8_t>& network) const override;/*** @brief Returns the compiler supported options list* @note The result is stored in the option support cache, if one was provided, so that subsequent* "is_option_supported" calls for these options can be answered without querying the compiler.*/- std::vector<std::string> get_supported_options() const;+ std::vector<std::string> get_supported_options() const override;/*** @brief Checks whether the given option and value are supported by the compiler@@ -111,7 +113,7 @@ public:* name alone and cannot tell whether a specific value is accepted.*/bool is_option_supported(const std::string& option,- const std::optional<std::string>& optValue = std::nullopt) const;+ const std::optional<std::string>& optValue = std::nullopt) const override;private:/**@@ -135,4 +137,17 @@ private:Logger _logger;};+/**+ * @brief Loads the VCL compiler library and returns a compiler paired with it.+ *+ * Keeps the load + SoPtr pairing in one place: the returned SoPtr owns the shared library, so the+ * compiler cannot outlive the code it dispatches into.+ *+ * @param optionSupportCache Bound here to the compiler-in-plugin's own cache key. Callers hand over+ * the shared cache rather than a pre-bound one, so a compiler can never be paired with a key+ * that belongs to a different compiler's answers.+ */+ov::SoPtr<IVCLCompiler> makeVCLCompiler(const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt,+ const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr);+} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hppnew file mode 100644index 00000000000..0d2bee85f06--- /dev/null+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ivcl_compiler.hpp@@ -0,0 +1,90 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <cstdint>+#include <memory>+#include <optional>+#include <string>+#include <utility>+#include <vector>++#include "intel_npu/config/config.hpp"+#include "openvino/core/model.hpp"+#include "openvino/runtime/common.hpp"+#include "openvino/runtime/profiling_info.hpp"+#include "openvino/runtime/tensor.hpp"++namespace intel_npu {++/**+ * @brief The compiler-in-plugin surface consumed by PluginCompilerAdapter.+ *+ * Deliberately expressed only in OpenVINO and standard types - no VCL, no Level Zero - so+ * PluginCompilerAdapter depends on this abstraction rather than on VCLCompilerImpl directly.+ */+class IVCLCompiler {+public:+ virtual ~IVCLCompiler() = default;++ /**+ * @brief Transforms a network from the OpenVINO model representation to a format executable+ * by a NPU device.+ * @return a pair containing an ov::Tensor object with the compiled model (blob) and an optional+ * string with runtime requirements for the blob+ */+ virtual std::pair<ov::Tensor, std::optional<std::string>> compile(const std::shared_ptr<const ov::Model>& model,+ const Config& config) const = 0;++ /**+ * @brief Compiles the model, weights separation enabled. All init schedules along with the main+ * one are compiled in the same scope.+ * @return A pair containing one ov::Tensor for each init schedule, followed by another one+ * corresponding to the main part, and an optional compatibility string for the compiled blobs.+ */+ virtual std::pair<std::vector<ov::Tensor>, std::optional<std::string>> compileWsOneShot(+ const std::shared_ptr<ov::Model>& model,+ const Config& config) const = 0;++ /**+ * @brief Sequential compilation of Init(s) and Main ("stateless compiler" approach).+ * @param callNumber Tells the compiler which Init (or Main) to return; the plugin does not know+ * the total number of Init schedules.+ */+ virtual std::pair<ov::Tensor, std::optional<std::string>>+ compileWsIterative(const std::shared_ptr<ov::Model>& model, const Config& config, size_t callNumber) const = 0;++ /**+ * @brief Returns information about supported layers of the network passed.+ */+ virtual ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const = 0;++ /**+ * @brief Returns the compiler version.+ * @return composite uint32_t value: MSB 16 bits = Major version, LSB 16 bits = Minor version.+ */+ virtual uint32_t get_version() const = 0;++ /**+ * @brief Returns the options the compiler supports, already tokenised.+ * @note The VCL calling convention (a char buffer with trailing NULs) is deliberately kept out+ * of this interface; implementations do the trimming and tokenisation themselves.+ */+ virtual std::vector<std::string> get_supported_options() const = 0;++ /**+ * @brief Checks whether the given option and value are supported by the compiler.+ */+ virtual bool is_option_supported(const std::string& option,+ const std::optional<std::string>& optValue = std::nullopt) const = 0;++ /**+ * @brief Decodes raw profiling output produced by a run of the given network.+ */+ virtual std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,+ const std::vector<uint8_t>& network) const = 0;+};++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hppindex ffed996b5b7..36263c3a64f 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp@@ -8,12 +8,11 @@#include <optional>-#include "compiler_impl.hpp"#include "intel_npu/common/icompiler_adapter.hpp"#include "intel_npu/common/npu.hpp"-#include "intel_npu/common/option_support_cache.hpp"#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_init.hpp"+#include "ivcl_compiler.hpp"#include "openvino/runtime/so_ptr.hpp"#include "ze_graph_ext_wrappers.hpp"@@ -21,9 +20,18 @@ namespace intel_npu {class PluginCompilerAdapter final : public ICompilerAdapter {public:+ /**+ * @brief Adapts an already-constructed compiler.+ *+ * The adapter never loads a compiler itself; composition is the caller's job. See+ * makeVCLCompiler() for the compiler-in-plugin.+ *+ * @param zeroInitStruct Pass null to construct without a Level Zero driver; the adapter then+ * produces export-only graphs with no runtime metadata.+ * @param compiler The compiler-in-plugin to adapt; must be non-null.+ */PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,- const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr,- const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt);+ ov::SoPtr<IVCLCompiler> compiler);std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,const Config& config,@@ -45,7 +53,7 @@ public:private:std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;std::shared_ptr<ZeGraphExtWrappers> _zeGraphExt;- ov::SoPtr<VCLCompilerImpl> _compiler;+ ov::SoPtr<IVCLCompiler> _compiler;Logger _logger;};diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cppindex 55017bc3ed3..b45582b4bbe 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp@@ -4,12 +4,29 @@#include "intel_npu/common/compiler_adapter_factory.hpp"+#include "compiler_impl.hpp"#include "driver_compiler_adapter.hpp"#include "intel_npu/npu_private_properties.hpp"#include "plugin_compiler_adapter.hpp"namespace intel_npu {+namespace {+// Loads the compiler-in-plugin, translating any failure into the aborting message callers expect.+// Composing the compiler here, rather than inside PluginCompilerAdapter, keeps the adapter free of+// any knowledge of how a compiler is obtained.+ov::SoPtr<IVCLCompiler> makePluginCompiler(const std::shared_ptr<IDevice>& device,+ const std::shared_ptr<OptionSupportCache>& optionSupportCache) {+ try {+ return makeVCLCompiler(+ device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt,+ optionSupportCache);+ } catch (const std::exception& vclException) {+ OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());+ }+}+} // namespace+std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(const ov::SoPtr<IEngineBackend>& engineBackend,ov::intel_npu::CompilerType& compilerType,@@ -27,10 +44,8 @@ std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(}if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {- return std::make_unique<PluginCompilerAdapter>(- engineBackend ? engineBackend->getInitStructs() : nullptr,- optionSupportCache,- device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt);+ return std::make_unique<PluginCompilerAdapter>(engineBackend ? engineBackend->getInitStructs() : nullptr,+ makePluginCompiler(device, optionSupportCache));}if (compilerType == ov::intel_npu::CompilerType::DRIVER) {@@ -99,10 +114,9 @@ CompilerAdapterFactory::resolvePreferPluginCompiler(const ov::SoPtr<IEngineBackeif (pluginCompilerPresence == PluginCompilerPresence::UNKNOWN) {try {- auto pluginCompiler = std::make_unique<PluginCompilerAdapter>(- engineBackend ? engineBackend->getInitStructs() : nullptr,- optionSupportCache,- device ? std::optional<IDevice::DeviceProperties>{device->getDeviceProperties()} : std::nullopt);+ auto pluginCompiler =+ std::make_unique<PluginCompilerAdapter>(engineBackend ? engineBackend->getInitStructs() : nullptr,+ makePluginCompiler(device, optionSupportCache));_pluginCompilerPresence.store(PluginCompilerPresence::PRESENT, std::memory_order_release);return {std::move(pluginCompiler), ov::intel_npu::CompilerType::PLUGIN};} catch (...) {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.cppindex f58ab298387..24e5feeedda 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@@ -695,4 +695,28 @@ bool VCLCompilerImpl::is_option_supported(const std::string& option, const std::return supported;}+namespace {+// The cache key under which the compiler-in-plugin's option-support answers are stored.+constexpr OptionSupportCache::CacheKey pluginOptionSupportKey =+ static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN);+} // namespace++ov::SoPtr<IVCLCompiler> makeVCLCompiler(const std::optional<IDevice::DeviceProperties>& deviceProperties,+ const std::shared_ptr<OptionSupportCache>& optionSupportCache) {+ auto vclLoader = VCLLoader::getInstance();+ OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");++ auto compiler =+ std::make_shared<VCLCompilerImpl>(vclLoader->sharedFunctions(),+ deviceProperties,+ ScopedOptionSupportCache{optionSupportCache, pluginOptionSupportKey});++ // Pairing the compiler with the library keeps the .so alive for as long as the compiler is. The+ // compiler itself never learns that a library is involved.+ auto vclLib = vclLoader->getLibrary();+ OPENVINO_ASSERT(vclLib != nullptr, "VCL library is nullptr");++ return ov::SoPtr<IVCLCompiler>(compiler, vclLib);+}+} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cppindex c5854470883..a99186e83ea 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp@@ -13,7 +13,6 @@#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "intel_npu/utils/zero/zero_utils.hpp"#include "openvino/runtime/make_tensor.hpp"-#include "openvino/util/file_util.hpp"namespace intel_npu {@@ -153,8 +152,9 @@ 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>(VCLLoader::getInstance(ov_lib_path)->sharedFunctions());+ // Built through the same factory the adapter uses, so the load and library pairing stay in one+ // place. Profiling decode needs no compiler handle, so this does more work than necessary.+ auto compiler = makeVCLCompiler();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.cppindex 350f50783d7..3d83c33531f 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@@ -11,7 +11,6 @@#include "graph.hpp"#include "intel_npu/common/device_helpers.hpp"#include "intel_npu/common/itt.hpp"-#include "intel_npu/common/option_support_cache.hpp"#include "intel_npu/config/options.hpp"#include "intel_npu/npu_private_properties.hpp"#include "intel_npu/utils/logger/logger.hpp"@@ -21,44 +20,19 @@#include "mem_usage.hpp"#include "openvino/core/model.hpp"#include "openvino/runtime/make_tensor.hpp"-#include "openvino/util/file_util.hpp"-#include "openvino/util/shared_object.hpp"#include "weightless_graph.hpp"#include "weightless_utils.hpp"namespace intel_npu {-namespace {-constexpr OptionSupportCache::CacheKey pluginOptionSupportKey =- static_cast<OptionSupportCache::CacheKey>(ov::intel_npu::CompilerType::PLUGIN);-}-PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,- const std::shared_ptr<OptionSupportCache>& optionSupportCache,- const std::optional<IDevice::DeviceProperties>& deviceProperties)+ ov::SoPtr<IVCLCompiler> compiler): _zeroInitStruct(zeroInitStruct),+ _compiler(std::move(compiler)),_logger("PluginCompilerAdapter", Logger::global().level()) {_logger.info("initialize PluginCompilerAdapter start");- _logger.info("Loading PLUGIN compiler");- try {- auto ovLibPath = ov::util::path_to_string(ov::util::get_ov_lib_path());- auto vclLoader = VCLLoader::getInstance(ovLibPath);- OPENVINO_ASSERT(vclLoader != nullptr, "VCL loader is nullptr");- auto vclCompilerPtr =- std::make_shared<VCLCompilerImpl>(vclLoader->sharedFunctions(),- deviceProperties,- ScopedOptionSupportCache{optionSupportCache, pluginOptionSupportKey});- OPENVINO_ASSERT(vclCompilerPtr != nullptr, "VCL compiler is nullptr");- // 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);- } catch (const std::exception& vclException) {- OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());- }+ OPENVINO_ASSERT(_compiler != nullptr, "PluginCompilerAdapter requires a non-null compiler");if (_zeroInitStruct == nullptr) {return;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.hppindex 106358aadbc..50cb5879f12 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@@ -86,7 +86,7 @@ public:void operator=(const VCLLoader&) = delete;void operator=(VCLLoader&&) = delete;- static const std::shared_ptr<const VCLLoader> getInstance(const std::string& library_dir = std::string());+ static const std::shared_ptr<const VCLLoader> getInstance();/*** @brief The function table, sharing this loader's lifetime.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.cppindex 04d0d2d7247..fb5acf9e2c6 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@@ -45,28 +45,19 @@ VCLLoader::VCLLoader(const std::string& library_dir) : _logger("VCLLoader", Logg#undef vcl_symbol_statement}-const std::shared_ptr<const VCLLoader> VCLLoader::getInstance(const std::string& library_dir) {+const std::shared_ptr<const VCLLoader> VCLLoader::getInstance() {static std::mutex mtx;std::lock_guard<std::mutex> lock(mtx);- static std::string initialized_dir;static std::shared_ptr<const VCLLoader> instance = nullptr;if (!instance) {+ const auto library_dir = ov::util::path_to_string(ov::util::get_ov_lib_path());if (library_dir.empty()) {OPENVINO_THROW("VCLLoader instance has not been loaded yet, and no valid path was provided to load it.");}- initialized_dir = 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("VCLLoader has already been initialized with path: '",- initialized_dir,- "'. Dynamic switching to a new compiler path: '",- library_dir,- "' in the same process is not supported.");- }}return instance;diff --git a/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp b/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cppindex 155501cc3d8..23972353fc8 100644--- a/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp+++ b/src/plugins/intel_npu/tests/functional/internal/backend/zero_infer_request_tests.cpp@@ -11,6 +11,7 @@#include "common_test_utils/ov_plugin_cache.hpp"#include "common_test_utils/ov_tensor_utils.hpp"#include "compiled_model.hpp"+#include "compiler_impl.hpp"#include "driver_compiler_adapter.hpp"#include "graph.hpp"#include "intel_npu/common/compiler_adapter_factory.hpp"@@ -208,7 +209,8 @@ TEST_P(ZeroInferRequestTests, BooleanSetTensorSetTensorsWork) {? std::dynamic_pointer_cast<::intel_npu::ICompilerAdapter>(std::make_shared<::intel_npu::DriverCompilerAdapter>(zeroInitStruct)): std::dynamic_pointer_cast<::intel_npu::ICompilerAdapter>(- std::make_shared<::intel_npu::PluginCompilerAdapter>(zeroInitStruct));+ std::make_shared<::intel_npu::PluginCompilerAdapter>(zeroInitStruct,+ ::intel_npu::makeVCLCompiler()));} catch (...) {GTEST_SKIP() << "Couldn't load compiler library";}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.cppindex 7e50bfd83e4..d1b8d7a07d5 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@@ -11,7 +11,6 @@#include <vector>#include "common/npu_test_env_cfg.hpp"-#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_api.hpp"@@ -46,8 +45,7 @@ protected:allocator = std::make_shared<::intel_npu::vcl_allocator_2>();try {- std::string ov_lib_dir = ov::test::utils::getOpenvinoLibDirectory();- functions = ::intel_npu::VCLLoader::getInstance(ov_lib_dir)->sharedFunctions();+ functions = ::intel_npu::VCLLoader::getInstance()->sharedFunctions();} catch (const std::exception&) {GTEST_SKIP() << "Couldn't load compiler library";}diff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hppnew file mode 100644index 00000000000..1f1c4610444--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/fake_vcl_compiler.hpp@@ -0,0 +1,104 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <cstdint>+#include <memory>+#include <optional>+#include <string>+#include <utility>+#include <vector>++#include "ivcl_compiler.hpp"+#include "openvino/core/except.hpp"+#include "openvino/runtime/tensor.hpp"++namespace fake_vcl {++// A trivial IVCLCompiler with settable canned returns, for exercising PluginCompilerAdapter's own+// logic without a driver, a compiler library, or an NPU.+class FakeVCLCompiler : public ::intel_npu::IVCLCompiler {+public:+ // Blob handed back by compile(); a page-sized buffer by default.+ ov::Tensor compileResult = ov::Tensor(ov::element::u8, ov::Shape{4096});+ std::optional<std::string> compatibility = std::string("fake-compat");++ // Tensors handed back by compileWsOneShot(): init schedules first, main last.+ std::vector<ov::Tensor> wsOneShotResult = {ov::Tensor(ov::element::u8, ov::Shape{4096}),+ ov::Tensor(ov::element::u8, ov::Shape{4096})};++ ov::Tensor wsIterativeResult = ov::Tensor(ov::element::u8, ov::Shape{4096});++ ov::SupportedOpsMap queryResult;+ uint32_t version = 0x0007000A;+ std::vector<std::string> supportedOptions = {"OPT_A", "OPT_B"};+ // Options the fake reports as supported; anything else is unsupported.+ std::vector<std::string> supportedOptionNames = {"OPT_A", "OPT_B"};++ bool throwOnCompile = false;++ mutable int compileCalls = 0;+ mutable int compileWsOneShotCalls = 0;+ mutable int compileWsIterativeCalls = 0;+ mutable int queryCalls = 0;+ mutable int getSupportedOptionsCalls = 0;+ mutable std::vector<std::pair<std::string, std::optional<std::string>>> optionSupportQueries;+ mutable std::vector<size_t> wsIterativeCallNumbers;++ std::pair<ov::Tensor, std::optional<std::string>> compile(const std::shared_ptr<const ov::Model>&,+ const ::intel_npu::Config&) const override {+ ++compileCalls;+ if (throwOnCompile) {+ OPENVINO_THROW("FakeVCLCompiler: compile failed on request");+ }+ return {compileResult, compatibility};+ }++ std::pair<std::vector<ov::Tensor>, std::optional<std::string>> compileWsOneShot(+ const std::shared_ptr<ov::Model>&,+ const ::intel_npu::Config&) const override {+ ++compileWsOneShotCalls;+ return {wsOneShotResult, compatibility};+ }++ std::pair<ov::Tensor, std::optional<std::string>> compileWsIterative(const std::shared_ptr<ov::Model>&,+ const ::intel_npu::Config&,+ size_t callNumber) const override {+ ++compileWsIterativeCalls;+ wsIterativeCallNumbers.push_back(callNumber);+ return {wsIterativeResult, compatibility};+ }++ ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>&, const ::intel_npu::Config&) const override {+ ++queryCalls;+ return queryResult;+ }++ uint32_t get_version() const override {+ return version;+ }++ std::vector<std::string> get_supported_options() const override {+ ++getSupportedOptionsCalls;+ return supportedOptions;+ }++ bool is_option_supported(const std::string& option, const std::optional<std::string>& optValue) const override {+ optionSupportQueries.emplace_back(option, optValue);+ for (const auto& known : supportedOptionNames) {+ if (known == option) {+ return true;+ }+ }+ return false;+ }++ std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>&,+ const std::vector<uint8_t>&) const override {+ return {};+ }+};++} // namespace fake_vcldiff --git a/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cppnew file mode 100644index 00000000000..1e1a91765f7--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npu/compiler_adapter/plugin_compiler_adapter_test.cpp@@ -0,0 +1,235 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "plugin_compiler_adapter.hpp"++#include <gtest/gtest.h>++#include <memory>+#include <optional>+#include <string>+#include <vector>++#include "fake_vcl_compiler.hpp"+#include "intel_npu/config/config.hpp"+#include "intel_npu/config/options.hpp"+#include "intel_npu/npu_private_properties.hpp"+#include "openvino/core/except.hpp"+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/parameter.hpp"++using ::fake_vcl::FakeVCLCompiler;+using ::intel_npu::AdapterDescriptor;+using ::intel_npu::Config;+using ::intel_npu::OptionsDesc;+using ::intel_npu::PluginCompilerAdapter;++namespace {++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});+ auto add = std::make_shared<ov::op::v1::Add>(input, weights);+ return std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{input}, "adapter_test_model");+}++// The weights-separation flow requires every participating Constant to carry a+// WeightlessCacheAttribute; WeightlessGraph asserts on its absence.+std::shared_ptr<ov::Model> makeWeightlessModel() {+ auto weights = std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{5}, std::vector<float>{1.0f});+ weights->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] =+ ov::WeightlessCacheAttribute(weights->get_byte_size(), /* bin_offset = */ 0, ov::element::f32);++ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{5});+ auto add = std::make_shared<ov::op::v1::Add>(input, weights);+ return std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{input}, "adapter_ws_test_model");+}++struct PluginCompilerAdapterTest : public ::testing::Test {+ std::shared_ptr<FakeVCLCompiler> compiler = std::make_shared<FakeVCLCompiler>();++ // The adapter is built with a null ZeroInitStructsHolder throughout: that is the no-driver path,+ // which is the only one reachable without an NPU.+ std::unique_ptr<PluginCompilerAdapter> makeAdapter() {+ return std::make_unique<PluginCompilerAdapter>(nullptr, ov::SoPtr<::intel_npu::IVCLCompiler>(compiler));+ }++ static std::shared_ptr<OptionsDesc> makeOptionsDesc() {+ auto desc = std::make_shared<OptionsDesc>();+ desc->add<::intel_npu::LOG_LEVEL>();+ desc->add<::intel_npu::COMPILATION_MODE>();+ desc->add<::intel_npu::SEPARATE_WEIGHTS_VERSION>();+ desc->add<::intel_npu::MODEL_SERIALIZER_VERSION>();+ return desc;+ }++ static Config makeConfig(const std::optional<std::string>& compilationMode = std::nullopt,+ const std::optional<std::string>& wsVersion = std::nullopt) {+ Config config(makeOptionsDesc());+ if (compilationMode.has_value()) {+ config.update({{ov::intel_npu::compilation_mode.name(), *compilationMode}});+ }+ if (wsVersion.has_value()) {+ config.update({{ov::intel_npu::separate_weights_version.name(), *wsVersion}});+ }+ return config;+ }+};++TEST_F(PluginCompilerAdapterTest, InjectedCompilerIsAdapted) {+ auto adapter = makeAdapter();+ ASSERT_NE(adapter, nullptr);+ EXPECT_EQ(adapter->get_version(), compiler->version);+}++TEST_F(PluginCompilerAdapterTest, NullCompilerIsRejected) {+ EXPECT_THROW(+ {+ auto adapter =+ std::make_unique<PluginCompilerAdapter>(nullptr, ov::SoPtr<::intel_npu::IVCLCompiler>(nullptr));+ (void)adapter;+ },+ ov::Exception);+}++TEST_F(PluginCompilerAdapterTest, CompileProducesAGraphEvenWithoutADriver) {+ auto adapter = makeAdapter();+ auto config = makeConfig();++ const auto graph = adapter->compile(makeModel(), config, AdapterDescriptor{});++ ASSERT_NE(graph, nullptr);+ EXPECT_EQ(compiler->compileCalls, 1);+ // No driver means no Level Zero metadata; the graph is export-only but still constructed.+ EXPECT_TRUE(graph->get_metadata().name.empty());+}++TEST_F(PluginCompilerAdapterTest, CompilePropagatesCompilerFailures) {+ compiler->throwOnCompile = true;+ auto adapter = makeAdapter();+ auto config = makeConfig();++ EXPECT_THROW(adapter->compile(makeModel(), config, AdapterDescriptor{}), ov::Exception);+}++TEST_F(PluginCompilerAdapterTest, CompileDefaultsToTheElfBlobType) {+ // Without a HostCompile mode the ELF path is taken, which does not touch the VM runtime.+ auto adapter = makeAdapter();+ auto config = makeConfig(std::string("DefaultHW"));++ const auto graph = adapter->compile(makeModel(), config, AdapterDescriptor{});+ ASSERT_NE(graph, nullptr);+}++TEST_F(PluginCompilerAdapterTest, CompileWSDefaultsToOneShotWhenTheVersionIsUnset) {+ auto adapter = makeAdapter();+ // SEPARATE_WEIGHTS_VERSION is registered but never set, so the adapter must default it.+ auto config = makeConfig();+ ASSERT_FALSE(config.has<::intel_npu::SEPARATE_WEIGHTS_VERSION>());++ const auto graph = adapter->compileWS(makeWeightlessModel(), config, AdapterDescriptor{});++ ASSERT_NE(graph, nullptr);+ EXPECT_EQ(compiler->compileWsOneShotCalls, 1);+ EXPECT_EQ(compiler->compileWsIterativeCalls, 0);+}++TEST_F(PluginCompilerAdapterTest, CompileWSOneShotSplitsMainOffTheBack) {+ // Three tensors: two init schedules plus the main one, which is the last entry.+ compiler->wsOneShotResult = {ov::Tensor(ov::element::u8, ov::Shape{4096}),+ ov::Tensor(ov::element::u8, ov::Shape{4096}),+ ov::Tensor(ov::element::u8, ov::Shape{8192})};+ auto adapter = makeAdapter();+ auto config = makeConfig(std::nullopt, std::string("ONE_SHOT"));++ const auto graph = adapter->compileWS(makeWeightlessModel(), config, AdapterDescriptor{});++ ASSERT_NE(graph, nullptr);+ EXPECT_EQ(compiler->compileWsOneShotCalls, 1);+}++TEST_F(PluginCompilerAdapterTest, CompileWSOneShotToleratesASingleTensor) {+ // Only the main schedule came back: the adapter warns but must still produce a graph.+ compiler->wsOneShotResult = {ov::Tensor(ov::element::u8, ov::Shape{4096})};+ auto adapter = makeAdapter();+ auto config = makeConfig(std::nullopt, std::string("ONE_SHOT"));++ const auto graph = adapter->compileWS(makeWeightlessModel(), config, AdapterDescriptor{});++ ASSERT_NE(graph, nullptr);+ EXPECT_EQ(compiler->compileWsOneShotCalls, 1);+}++TEST_F(PluginCompilerAdapterTest, CompileWSIterativeRequiresAGraphHandle) {+ auto adapter = makeAdapter();+ auto config = makeConfig(std::nullopt, std::string("ITERATIVE"));++ // The iterative flow cannot work without a Level Zero graph handle.+ try {+ adapter->compileWS(makeWeightlessModel(), config, AdapterDescriptor{});+ FAIL() << "Expected compileWS(ITERATIVE) to throw without a graph handle";+ } catch (const ov::Exception& error) {+ EXPECT_NE(std::string(error.what()).find("weights separation"), std::string::npos) << error.what();+ }+ EXPECT_EQ(compiler->compileWsIterativeCalls, 0);+}++TEST_F(PluginCompilerAdapterTest, QueryIsDelegatedToTheCompiler) {+ compiler->queryResult = {{"Add_1", "NPU"}};+ auto adapter = makeAdapter();+ auto config = makeConfig();++ const auto supported = adapter->query(makeModel(), config);++ EXPECT_EQ(compiler->queryCalls, 1);+ ASSERT_EQ(supported.size(), 1u);+ EXPECT_EQ(supported.at("Add_1"), "NPU");+}++TEST_F(PluginCompilerAdapterTest, GetVersionIsDelegatedToTheCompiler) {+ compiler->version = 0x000B0002;+ auto adapter = makeAdapter();+ EXPECT_EQ(adapter->get_version(), 0x000B0002u);+}++TEST_F(PluginCompilerAdapterTest, GetSupportedOptionsIsDelegatedToTheCompiler) {+ auto adapter = makeAdapter();++ EXPECT_EQ(adapter->get_supported_options(), std::vector<std::string>({"OPT_A", "OPT_B"}));+ EXPECT_EQ(compiler->getSupportedOptionsCalls, 1);+}++TEST_F(PluginCompilerAdapterTest, GetSupportedOptionsDelegatesOnEveryCall) {+ auto adapter = makeAdapter();++ adapter->get_supported_options();+ adapter->get_supported_options();++ // The adapter holds no state of its own: it must not answer the second call itself.+ EXPECT_EQ(compiler->getSupportedOptionsCalls, 2);+}++TEST_F(PluginCompilerAdapterTest, IsOptionSupportedForwardsTheValueUnchanged) {+ auto adapter = makeAdapter();++ adapter->is_option_supported("OPT_A", std::string("SOME_VALUE"));++ ASSERT_EQ(compiler->optionSupportQueries.size(), 1u);+ EXPECT_EQ(compiler->optionSupportQueries[0].first, "OPT_A");+ ASSERT_TRUE(compiler->optionSupportQueries[0].second.has_value());+ EXPECT_EQ(*compiler->optionSupportQueries[0].second, "SOME_VALUE");+}++TEST_F(PluginCompilerAdapterTest, IsOptionSupportedIsDelegatedOnEveryCall) {+ auto adapter = makeAdapter();++ EXPECT_TRUE(adapter->is_option_supported("OPT_A"));+ EXPECT_FALSE(adapter->is_option_supported("UNKNOWN_OPTION"));+ // The adapter never answers on its own; deduplication is the compiler's concern.+ EXPECT_EQ(compiler->optionSupportQueries.size(), 2u);+}++} // namespace