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] Create AdapterDescriptor struct to be consumed by the compiler adapters (#38501)
Bogdan Pereanuf044a18f80a0
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/icompiler_adapter.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/icompiler_adapter.hppindex d42a4299b98..76729ba4f3d 100644--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/icompiler_adapter.hpp+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/icompiler_adapter.hpp@@ -9,10 +9,27 @@namespace intel_npu {+/**+ * @brief Settings consumed by the compiler adapter itself.+ * Each adapter decides which of them are relevant and may ignore the rest.+ */+struct AdapterDescriptor {+ // If set, the adapter skips any internal caching it may have for the compiled graph.+ bool bypassCache = false;+ // If set, the adapter requests secure compilation from its backend, if supported.+ bool secureCompile = false;+};+class ICompilerAdapter {public:+ /**+ * @param model The model that will be compiled.+ * @param config Will be passed to the compiler.+ * @param adapterDesc Adapter-specific settings, not forwarded to the compiler. See "AdapterDescriptor".+ */virtual std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,- const Config& config) const = 0;+ const Config& config,+ const AdapterDescriptor& adapterDesc) const = 0;/*** @brief Compiles the model, weights separation enabled.@@ -26,9 +43,12 @@ public:* @param config Will be passed to the compiler. Additionally, the "SEPARATE_WEIGHTS_VERSION" option will determine* which weights separation implementation will be used. See the weights separation specific methods within* "icompiler.hpp".+ * @param adapterDesc Adapter-specific settings, not forwarded to the compiler. See "AdapterDescriptor".* @return A "WeightlessGraph" type of object.*/- virtual std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model, const Config& config) const = 0;+ virtual std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model,+ const Config& config,+ const AdapterDescriptor& adapterDesc) const = 0;virtual ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const = 0;virtual uint32_t get_version() const = 0;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hppindex e6b377f0117..4a88bfa4004 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp@@ -23,9 +23,13 @@ public:DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr);- std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;+ std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,+ const Config& config,+ const AdapterDescriptor& adapterDesc) const override;- std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model, const Config& config) const override;+ std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model,+ const Config& config,+ const AdapterDescriptor& adapterDesc) const override;ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;diff --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 8aefc7c0d17..ffed996b5b7 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@@ -25,9 +25,13 @@ public:const std::shared_ptr<OptionSupportCache>& optionSupportCache = nullptr,const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt);- std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;+ std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,+ const Config& config,+ const AdapterDescriptor& adapterDesc) const override;- std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model, const Config& config) const override;+ std::shared_ptr<IGraph> compileWS(std::shared_ptr<ov::Model>&& model,+ const Config& config,+ const AdapterDescriptor& adapterDesc) const override;ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cppindex 5ab1471cdb7..558ba301943 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp@@ -88,7 +88,8 @@ DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr<ZeroInitStruc}std::shared_ptr<IGraph> DriverCompilerAdapter::compile(const std::shared_ptr<const ov::Model>& model,- const Config& config) const {+ const Config& config,+ const AdapterDescriptor& adapterDesc) const {OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "DriverCompilerAdapter", "compile");const ze_graph_compiler_version_info_t& compilerVersion = _compilerProperties.compilerVersion;@@ -127,12 +128,10 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::compile(const std::shared_ptr<con_logger.debug("compileIR Build flags : %s", buildFlags.c_str());_logger.debug("compile start");- // If UMD Caching is requested to be bypassed or if OV cache is enabled, disable driver caching- const bool bypassCache = !updatedConfig.get<CACHE_DIR>().empty() || updatedConfig.get<BYPASS_UMD_CACHING>();- // If blob encryption is requested, enable secure compilation in the driver- const bool secureCompile = updatedConfig.has(CACHE_ENCRYPTION_CALLBACKS::key().data()) &&- updatedConfig.get<CACHE_ENCRYPTION_CALLBACKS>().encrypt != nullptr;- auto graphDesc = _zeGraphExt->getGraphDescriptor(std::move(serializedIR), buildFlags, bypassCache, secureCompile);+ auto graphDesc = _zeGraphExt->getGraphDescriptor(std::move(serializedIR),+ buildFlags,+ adapterDesc.bypassCache,+ adapterDesc.secureCompile);_logger.debug("compile end");OV_ITT_TASK_NEXT(COMPILE_BLOB, "getNetworkMeta");@@ -148,7 +147,8 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::compile(const std::shared_ptr<con}std::shared_ptr<IGraph> DriverCompilerAdapter::compileWS(std::shared_ptr<ov::Model>&& model,- const Config& config) const {+ const Config& config,+ const AdapterDescriptor& adapterDesc) const {OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "DriverCompilerAdapter", "compileWS");const ze_graph_compiler_version_info_t& compilerVersion = _compilerProperties.compilerVersion;@@ -224,9 +224,10 @@ std::shared_ptr<IGraph> DriverCompilerAdapter::compileWS(std::shared_ptr<ov::ModbuildFlags += compiler_utils::serializeConfig(updatedConfig, compilerVersion, isOptionSupportedByCompiler);_logger.debug("compile start");- // If UMD Caching is requested to be bypassed or if OV cache is enabled, disable driver caching- const bool bypassCache = !updatedConfig.get<CACHE_DIR>().empty() || updatedConfig.get<BYPASS_UMD_CACHING>();- auto graphDesc = _zeGraphExt->getGraphDescriptor(serializedIR, buildFlags, bypassCache);+ auto graphDesc = _zeGraphExt->getGraphDescriptor(serializedIR,+ buildFlags,+ adapterDesc.bypassCache,+ adapterDesc.secureCompile);_logger.debug("compile end");OV_ITT_TASK_NEXT(COMPILE_BLOB, "getNetworkMeta");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 77733001cd5..350f50783d7 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@@ -76,7 +76,8 @@ PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStruc}std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<const ov::Model>& model,- const Config& config) const {+ const Config& config,+ const AdapterDescriptor&) const {OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "PluginCompilerAdapter", "compile");_logger.debug("compile start");@@ -128,7 +129,8 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<con}std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(std::shared_ptr<ov::Model>&& model,- const Config& config) const {+ const Config& config,+ const AdapterDescriptor&) const {OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "PluginCompilerAdapter", "compileWS");_logger.debug("compile start");diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex 0dd6cb61111..7ff83c19d5a 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -430,13 +430,20 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<std::shared_ptr<intel_npu::IGraph> graph;+ AdapterDescriptor adapterDesc;+ // Bypass the adapter's internal cache if requested explicitly or if the OV cache is enabled+ adapterDesc.bypassCache = !localConfig.get<CACHE_DIR>().empty() || localConfig.get<BYPASS_UMD_CACHING>();+ // Request secure compilation if blob encryption is requested+ adapterDesc.secureCompile = localConfig.has(ov::cache_encryption_callbacks.name()) &&+ localConfig.get<CACHE_ENCRYPTION_CALLBACKS>().encrypt != nullptr;+auto compileWithConfig = [&](auto&& modelToCompile, const auto& config) {if (!localConfig.get<ENABLE_WEIGHTLESS>()) {- return compiler->compile(modelToCompile, config);+ return compiler->compile(modelToCompile, config, adapterDesc);}check_weightless_cache_attribute_occurrence(model);- return compiler->compileWS(std::move(modelToCompile), config);+ return compiler->compileWS(std::move(modelToCompile), config, adapterDesc);};try {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 44e0290b494..155501cc3d8 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@@ -239,7 +239,7 @@ TEST_P(ZeroInferRequestTests, BooleanSetTensorSetTensorsWork) {copy_model = batchedModel;}- auto graph = compiler->compile(copy_model, *npu_config);+ auto graph = compiler->compile(copy_model, *npu_config, ::intel_npu::AdapterDescriptor{});if (batch) {graph->set_batch_size(batch.value());}