Skip to content

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

[NPU] Update properties handling to support cross-device compilation (#33943)

Bogdan Pereanu69ff3cfc76c5
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/device_helpers.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/device_helpers.hpp
index 1eb4fb5d01d..9f6fcfcddf2 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/device_helpers.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/device_helpers.hpp
@@ -7,17 +7,23 @@
#include <cstdint>
#include <map>
-#include "intel_npu/npu_private_properties.hpp"
+#include "intel_npu/common/npu.hpp"
+#include "openvino/runtime/intel_npu/properties.hpp"
namespace intel_npu {
namespace utils {
bool isNPUDevice(const uint32_t deviceId);
uint32_t getSliceIdBySwDeviceId(const uint32_t swDevId);
-std::string getPlatformByDeviceName(const std::string& deviceName);
+std::string getPlatformByDeviceName(const std::string_view deviceName);
std::string getCompilationPlatform(const std::string_view platform,
- const std::string& deviceId,
+ const std::string_view deviceId,
std::vector<std::string> availableDevicesNames);
+
+/**
+ * @brief Gets the device by its ID.
+ */
+std::shared_ptr<IDevice> getDeviceById(const ov::SoPtr<IEngineBackend>& engineBackend, const std::string& deviceId);
} // namespace utils
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/filtered_config.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/filtered_config.hpp
index 1fe4cf44f71..6da0c3f7335 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/filtered_config.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/filtered_config.hpp
@@ -120,22 +120,10 @@ public:
*/
std::string toStringForCompiler() const;
- /**
- * @brief Marks config as initialized
- */
- void markAsInitialized();
-
- /**
- * @brief Checks whether config was initialized
- */
- bool wasInitialized() const;
-
private:
EnableMap _enabled; ///< Map to track whether specific configuration keys are enabled or disabled.
ConfigMap _internal_compiler_configs; ///< Map to store internal (hidden) configurations used for compiler.
-
- bool _initialized = false; ///< Boolean to check whether config was filtered with compiler supported properties
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/src/device_helpers.cpp b/src/plugins/intel_npu/src/common/src/device_helpers.cpp
index 613c9a43191..fbd0375d5de 100644
--- a/src/plugins/intel_npu/src/common/src/device_helpers.cpp
+++ b/src/plugins/intel_npu/src/common/src/device_helpers.cpp
@@ -27,32 +27,48 @@ uint32_t utils::getSliceIdBySwDeviceId(const uint32_t swDevId) {
return sliceId;
}
-std::string utils::getPlatformByDeviceName(const std::string& deviceName) {
+std::string utils::getPlatformByDeviceName(const std::string_view deviceName) {
const auto platformPos = deviceName.rfind('.');
- const auto platformName = (platformPos == std::string::npos) ? deviceName : deviceName.substr(0, platformPos);
+ const std::string_view platformName =
+ (platformPos == std::string::npos) ? deviceName : deviceName.substr(0, platformPos);
- return platformName;
+ return std::string(platformName);
}
std::string utils::getCompilationPlatform(const std::string_view platform,
- const std::string& deviceId,
+ const std::string_view deviceId,
std::vector<std::string> availableDevicesNames) {
// Platform parameter has a higher priority than deviceID
if (platform != ov::intel_npu::Platform::AUTO_DETECT) {
- return std::string(platform);
+ return ov::intel_npu::Platform::standardize(platform);
}
// Get compilation platform from deviceID
if (!deviceId.empty()) {
- return utils::getPlatformByDeviceName(deviceId);
+ return ov::intel_npu::Platform::standardize(utils::getPlatformByDeviceName(deviceId));
}
// Automatic detection of compilation platform
if (availableDevicesNames.empty()) {
- OPENVINO_THROW("No NPU devices were found.");
+ return std::string();
}
- return utils::getPlatformByDeviceName(availableDevicesNames.at(0));
+ return ov::intel_npu::Platform::standardize(utils::getPlatformByDeviceName(availableDevicesNames.at(0)));
+}
+
+std::shared_ptr<IDevice> utils::getDeviceById(const ov::SoPtr<IEngineBackend>& engineBackend,
+ const std::string& deviceId) {
+ if (engineBackend == nullptr) {
+ return nullptr;
+ }
+
+ try {
+ return engineBackend->getDevice(deviceId);
+ } catch (...) {
+ Logger("getDeviceById", Logger::global().level())
+ .warning("The specified device (\"%s\") was not found.", deviceId.c_str());
+ }
+ return nullptr;
}
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/src/filtered_config.cpp b/src/plugins/intel_npu/src/common/src/filtered_config.cpp
index 3c8873b9014..f594677868c 100644
--- a/src/plugins/intel_npu/src/common/src/filtered_config.cpp
+++ b/src/plugins/intel_npu/src/common/src/filtered_config.cpp
@@ -134,12 +134,4 @@ std::string FilteredConfig::toStringForCompiler() const {
return resultStream.str();
}
-void FilteredConfig::markAsInitialized() {
- _initialized = true;
-}
-
-bool FilteredConfig::wasInitialized() const {
- return _initialized;
-}
-
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_adapter_factory.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_adapter_factory.hpp
index df5aa0b1b2d..b10d6ebb623 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_adapter_factory.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_adapter_factory.hpp
@@ -15,46 +15,57 @@ namespace intel_npu {
class CompilerAdapterFactory final {
public:
- static CompilerAdapterFactory& getInstance() {
- static CompilerAdapterFactory instance;
- return instance;
- }
+ ov::intel_npu::CompilerType determinteAppropriateCompilerTypeBasedOnPlatform(std::string_view platform) const {
+ if (platform == ov::intel_npu::Platform::NPU4000 || platform == ov::intel_npu::Platform::NPU5010) {
+ return ov::intel_npu::CompilerType::PLUGIN;
+ }
- CompilerAdapterFactory(const CompilerAdapterFactory&) = delete;
- CompilerAdapterFactory(CompilerAdapterFactory&&) = delete;
- CompilerAdapterFactory& operator=(const CompilerAdapterFactory&) = delete;
- CompilerAdapterFactory& operator=(CompilerAdapterFactory&&) = delete;
+ return ov::intel_npu::CompilerType::DRIVER;
+ }
std::unique_ptr<ICompilerAdapter> getCompiler(const ov::SoPtr<IEngineBackend>& engineBackend,
- ov::intel_npu::CompilerType& compilerType) const {
+ ov::intel_npu::CompilerType& compilerType,
+ std::string_view platform) const {
if (compilerType == ov::intel_npu::CompilerType::PREFER_PLUGIN) {
- if (engineBackend) {
- if (_pluginCompilerIsPresent) {
- try {
- compilerType = ov::intel_npu::CompilerType::PLUGIN;
- return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());
- } catch (...) {
- _pluginCompilerIsPresent = false;
+ if (engineBackend != nullptr) {
+ compilerType = determinteAppropriateCompilerTypeBasedOnPlatform(platform);
+ if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {
+ if (_pluginCompilerIsPresent) {
+ try {
+ return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());
+ } catch (...) {
+ _pluginCompilerIsPresent = false;
+ compilerType = ov::intel_npu::CompilerType::DRIVER;
+ }
+ } else {
+ // plugin compiler isn't present, fallback to driver compiler
compilerType = ov::intel_npu::CompilerType::DRIVER;
}
- } else {
- compilerType = ov::intel_npu::CompilerType::DRIVER;
}
} else {
- // no backend present, offline compilation only
+ // device isn't available, offline compilation only
compilerType = ov::intel_npu::CompilerType::PLUGIN;
}
}
if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {
- if (engineBackend == nullptr || engineBackend->getName() != "LEVEL0") {
+ if (engineBackend == nullptr) {
return std::make_unique<PluginCompilerAdapter>(nullptr);
}
return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());
} else if (compilerType == ov::intel_npu::CompilerType::DRIVER) {
- if (engineBackend == nullptr || engineBackend->getName() != "LEVEL0") {
- OPENVINO_THROW("NPU Compiler Adapter must be used with LEVEL0 backend");
+ if (engineBackend == nullptr || engineBackend->getDevice() == nullptr) {
+ OPENVINO_THROW(
+ "Could not find a NPU device. Using driver compiler requires a valid device to be present in "
+ "the system.");
+ }
+
+ // It is required to check if the device is compatible with the provided platform, as the driver compiler
+ // will be used.
+ auto deviceName = engineBackend->getDevice()->getName();
+ if (deviceName != platform && deviceName != "AUTO_DETECT") {
+ OPENVINO_THROW("Could not find a valid NPU device for the provided configuration.");
}
return std::make_unique<DriverCompilerAdapter>(engineBackend->getInitStructs());
@@ -64,10 +75,7 @@ public:
}
private:
- CompilerAdapterFactory() = default;
- ~CompilerAdapterFactory() = default;
-
- mutable std::atomic<bool> _pluginCompilerIsPresent = true;
+ inline static std::atomic<bool> _pluginCompilerIsPresent{true};
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp
index 703fa544123..5bfb3fd1930 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
@@ -442,9 +442,15 @@ NetworkDescription VCLCompilerImpl::compile(const std::shared_ptr<const ov::Mode
uint8_t* blob = nullptr;
size_t size = 0;
- THROW_ON_FAIL_FOR_VCL("vclAllocatedExecutableCreate2",
- vclAllocatedExecutableCreate2(_compilerHandle, exeDesc, &allocator, &blob, &size),
- _logHandle);
+ auto result = vclAllocatedExecutableCreate2(_compilerHandle, exeDesc, &allocator, &blob, &size);
+ if (result != VCL_RESULT_SUCCESS) {
+ OPENVINO_THROW("Compilation failed. vclAllocatedExecutableCreate2 result: 0x",
+ std::hex,
+ uint64_t(result),
+ " - ",
+ getLatestVCLLog(_logHandle));
+ }
+
if (size == 0 || blob == nullptr) {
OPENVINO_THROW("Failed to create VCL executable, size is zero or blob is null");
}
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.cpp
index 68b940b0e30..6a1286ad14f 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
@@ -41,13 +41,13 @@ namespace intel_npu {
DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct)
: _zeroInitStruct(zeroInitStruct),
_logger("DriverCompilerAdapter", Logger::global().level()) {
- _logger.debug("initialize DriverCompilerAdapter start");
+ _logger.info("initialize DriverCompilerAdapter start");
uint32_t graphExtVersion = _zeroInitStruct->getGraphDdiTable().version();
_compilerProperties = _zeroInitStruct->getCompilerProperties();
- _logger.info("DriverCompilerAdapter creating adapter using graphExtVersion");
+ _logger.debug("DriverCompilerAdapter creating adapter using graphExtVersion");
_zeGraphExt = std::make_shared<ZeGraphExtWrappers>(_zeroInitStruct);
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 f44559fa925..6e8120b9b27 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
@@ -30,7 +30,7 @@ namespace intel_npu {
PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct)
: _zeroInitStruct(zeroInitStruct),
_logger("PluginCompilerAdapter", Logger::global().level()) {
- _logger.debug("initialize PluginCompilerAdapter start");
+ _logger.info("initialize PluginCompilerAdapter start");
_logger.info("Loading PLUGIN compiler");
try {
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
index e44d8368021..25639ece868 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
@@ -402,7 +402,17 @@ GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(SerializedIR serializedIR
_zeroInitStruct->getDevice(),
&desc,
&graphHandle);
- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnCreate2", result, _zeroInitStruct->getGraphDdiTable());
+ if (result != ZE_RESULT_SUCCESS) {
+ OPENVINO_THROW("Compilation failed. Level0 pfnCreate2 result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result),
+ " - ",
+ ze_result_to_description(result),
+ " . ",
+ intel_npu::zeroUtils::getLatestBuildError(_zeroInitStruct->getGraphDdiTable()));
+ }
return GraphDescriptor{graphHandle};
}
diff --git a/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp b/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
index 5d09c758d66..bc06f083aec 100644
--- a/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
@@ -61,7 +61,6 @@ public:
private:
void configure_stream_executors();
- FilteredConfig _config;
Logger _logger;
const std::shared_ptr<IDevice> _device;
std::shared_ptr<ov::threading::ITaskExecutor> _resultExecutor;
diff --git a/src/plugins/intel_npu/src/plugin/include/plugin.hpp b/src/plugins/intel_npu/src/plugin/include/plugin.hpp
index 0e3a30cc5d8..623644f1708 100644
--- a/src/plugins/intel_npu/src/plugin/include/plugin.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/plugin.hpp
@@ -44,9 +44,9 @@ public:
const ov::AnyMap& properties,
const ov::SoPtr<ov::IRemoteContext>& context) const override;
- ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override;
+ ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap& remoteProperties) const override;
- ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override;
+ ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remoteProperties) const override;
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& stream, const ov::AnyMap& properties) const override;
@@ -54,10 +54,10 @@ public:
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override;
- std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor& compiled_blob,
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor& compiledBlob,
const ov::AnyMap& properties) const override;
- std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor& compiled_blob,
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor& compiledBlob,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override;
@@ -65,13 +65,8 @@ public:
const ov::AnyMap& properties) const override;
private:
- void init_options();
- void filter_global_config_safe(
- const std::optional<ov::intel_npu::CompilerType>& compilerChange = std::nullopt) const;
- void filter_config_by_compiler_support(FilteredConfig& cfg) const;
- FilteredConfig fork_local_config(const ov::AnyMap& properties,
- const std::unique_ptr<ICompilerAdapter>& compiler,
- OptionMode mode = OptionMode::Both) const;
+ void init_options(FilteredConfig& filteredConfig);
+ void update_log_level(const ov::AnyMap& properties) const;
/**
* @brief Parses the compiled model found within the stream and tensor and returns a wrapper over the L0 handle that
@@ -96,13 +91,11 @@ private:
ov::SoPtr<IEngineBackend> _backend;
std::shared_ptr<OptionsDesc> _options;
- mutable FilteredConfig _globalConfig;
mutable Logger _logger;
std::shared_ptr<Metrics> _metrics;
- std::unique_ptr<Properties> _properties;
+ std::unique_ptr<Properties> _propertiesManager;
static std::atomic<int> _compiledModelLoadCounter;
- mutable std::mutex _mutex;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/plugin/include/properties.hpp b/src/plugins/intel_npu/src/plugin/include/properties.hpp
index 936476b60cf..03e005be13c 100644
--- a/src/plugins/intel_npu/src/plugin/include/properties.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/properties.hpp
@@ -5,6 +5,7 @@
#pragma once
#include "intel_npu/common/filtered_config.hpp"
+#include "intel_npu/common/icompiler_adapter.hpp"
#include "intel_npu/npuw_private_properties.hpp"
#include "metrics.hpp"
@@ -21,10 +22,13 @@ public:
* @param metrics - reference ptr to the metrics object of the parent object (PLUGIN only)
*/
Properties(const PropertiesType pType,
- FilteredConfig& config,
+ const FilteredConfig& config,
const std::shared_ptr<Metrics>& metrics = nullptr,
const ov::SoPtr<IEngineBackend>& backend = {nullptr});
+ Properties(const Properties& other);
+ Properties& operator=(const Properties& other) = delete;
+
/**
* @brief Initialize the properties map and try registering the properties for npu-plugin and compiled-model
* Can be used for both plugin and compiled-model properties maps, based on the provided pType param to the
@@ -42,7 +46,7 @@ public:
/**
* @brief Get the values of a property in a map
*/
- ov::Any get_property(const std::string& name, const ov::AnyMap& arguments = {}) const;
+ ov::Any getProperty(const std::string& name);
/**
* @brief Set the values of a subset of properties, provided as a map
@@ -50,18 +54,54 @@ public:
* - checks if the property exists, will report if unsupported
* - checks if the property is Read-only, will report error if so
*/
- void set_property(const ov::AnyMap& properties);
+ void setProperty(const ov::AnyMap& properties);
/**
* @brief Checks whether a property was registered by its name
*/
bool isPropertyRegistered(const std::string& propertyName) const;
+ /**
+ * @brief Get a const reference to the stored config
+ */
+ const FilteredConfig& getConfig() const {
+ return _config;
+ }
+
+ /**
+ * @brief Update the config map and register properties for the plugin.
+ * @details
+ * - Checks if the compiler has changed; if so, re-filters properties.
+ * - Checks whether arguments are already registered; if not, checks if the options are supported.
+ * - Filters compiler options based on the current compiler.
+ * - Updates the config with the provided arguments.
+ */
+ void updateConfig(const ov::AnyMap& properties,
+ const ICompilerAdapter* compiler,
+ OptionMode mode = OptionMode::Both);
+
+ /**
+ * @brief Update the config map.
+ * @details
+ * - Updates the config with the provided arguments.
+ */
+ void updateConfig(const ov::AnyMap& properties, OptionMode mode = OptionMode::Both);
+
+ ov::intel_npu::CompilerType determineCompilerType(const ov::AnyMap& properties) const;
+ std::string determinePlatform(const ov::AnyMap& properties) const;
+ std::string determineDeviceId(const ov::AnyMap& properties) const;
+
private:
PropertiesType _pType;
- FilteredConfig& _config;
+ FilteredConfig _config;
std::shared_ptr<Metrics> _metrics;
ov::SoPtr<IEngineBackend> _backend;
+ Logger _logger;
+
+ ov::intel_npu::CompilerType _currentlyUsedCompiler = ov::intel_npu::CompilerType::PREFER_PLUGIN;
+ std::string _currentlyUsedPlatform;
+
+ bool _initialized = false; ///< Boolean to check whether properties was filtered with compiler supported properties
// properties map: {name -> [supported, mutable, eval function]}
std::map<std::string, std::tuple<bool, ov::PropertyMutability, std::function<ov::Any(const Config&)>>> _properties;
@@ -70,6 +110,9 @@ private:
// internal registration functions based on client object
void registerPluginProperties();
void registerCompiledModelProperties();
+ void filterPropertiesByCompilerSupport(const ICompilerAdapter* compiler,
+ const ov::intel_npu::CompilerType compilerType,
+ const std::string& compilationPlatform);
const std::vector<ov::PropertyName> _cachingProperties = {
ov::cache_mode.name(),
@@ -156,6 +199,8 @@ private:
const std::vector<ov::PropertyName> _internalSupportedProperties = {ov::internal::caching_properties.name(),
ov::internal::caching_with_mmap.name(),
ov::internal::cache_header_alignment.name()};
+
+ std::mutex _mutex;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
index 0b6eb503183..2c40fe221c8 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
@@ -29,7 +29,6 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
const FilteredConfig& config,
const std::optional<int64_t>& batchSize)
: ICompiledModel(model, plugin),
- _config(config),
_logger("CompiledModel", config.get<LOG_LEVEL>()),
_device(device),
_graph(graph),
@@ -37,7 +36,7 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "CompiledModel::CompiledModel");
OV_ITT_TASK_CHAIN(COMPILED_MODEL, itt::domains::NPUPlugin, "CompiledModel::CompiledModel", "initialize_properties");
- _properties = std::make_unique<Properties>(PropertiesType::COMPILED_MODEL, _config);
+ _properties = std::make_unique<Properties>(PropertiesType::COMPILED_MODEL, config);
_properties->registerProperties();
configure_stream_executors();
@@ -58,11 +57,11 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() co
OPENVINO_THROW("No available devices. Failed to create infer request!");
}
- if (!_config.get<CREATE_EXECUTOR>() || _config.get<DEFER_WEIGHTS_LOAD>()) {
+ if (!_properties->getConfig().get<CREATE_EXECUTOR>() || _properties->getConfig().get<DEFER_WEIGHTS_LOAD>()) {
if (_graph == nullptr) {
OPENVINO_THROW("Invalid graph handle! Failed to create infer request!");
}
- _graph->initialize(_config);
+ _graph->initialize(_properties->getConfig());
}
if (!_graph->init_completed()) {
@@ -71,7 +70,7 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() co
}
const std::shared_ptr<SyncInferRequest>& syncInferRequest =
- _device->createInferRequest(shared_from_this(), _config);
+ _device->createInferRequest(shared_from_this(), _properties->getConfig());
syncInferRequest->initialize_states();
return std::make_shared<AsyncInferRequest>(syncInferRequest,
@@ -91,7 +90,7 @@ void CompiledModel::export_model(std::ostream& stream) const {
auto [blobSizesBeforeVersioning, initBlobSizes] = _graph->export_blob(stream);
- if (!_config.get<EXPORT_RAW_BLOB>()) {
+ if (!_properties->getConfig().get<EXPORT_RAW_BLOB>()) {
std::optional<std::vector<ov::Layout>> inputLayouts = std::vector<ov::Layout>();
std::optional<std::vector<ov::Layout>> outputLayouts = std::vector<ov::Layout>();
@@ -161,7 +160,7 @@ std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {
void CompiledModel::set_property(const ov::AnyMap& properties) {
// 1. Set the property via Properties interface
- _properties->set_property(properties);
+ _properties->setProperty(properties);
// 2. Extra hooks
if (properties.count(std::string(WORKLOAD_TYPE::key())) != 0) {
@@ -179,7 +178,7 @@ ov::Any CompiledModel::get_property(const std::string& name) const {
return _graph->get_metadata().name;
} else {
// default behaviour
- return _properties->get_property(name);
+ return _properties->getProperty(name);
}
}
@@ -188,7 +187,7 @@ const std::shared_ptr<IGraph>& CompiledModel::get_graph() const {
}
const FilteredConfig& CompiledModel::get_config() const {
- return _config;
+ return _properties->getConfig();
}
void CompiledModel::configure_stream_executors() {
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 9cbcf59af2e..3cae1228737 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -122,35 +122,6 @@ std::shared_ptr<ov::Model> create_dummy_model(const std::vector<IODescriptor>& i
return std::make_shared<ov::Model>(results, parameters);
}
-std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
- std::map<std::string, std::string> result;
- for (auto&& value : params) {
- // The value of cache_encryption_callbacks cannot be converted to std::string
- if (value.first == ov::cache_encryption_callbacks.name()) {
- continue;
- }
- result.emplace(value.first, value.second.as<std::string>());
- }
- return result;
-}
-
-void update_log_level(const ov::AnyMap& properties) {
- if (properties.count(ov::log::level.name()) != 0) {
- Logger::global().setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
- }
-}
-
-static ov::intel_npu::CompilerType resolveCompilerType(const FilteredConfig& base_conf, const ov::AnyMap& local_conf) {
- // first look if provided config changes compiler type
- auto it = local_conf.find(std::string(COMPILER_TYPE::key()));
- if (it != local_conf.end()) {
- // if compiler_type is provided by local config = use that
- return COMPILER_TYPE::parse(it->second.as<std::string>());
- }
- // if there is no compiler_type provided = use base_config value
- return base_conf.get<COMPILER_TYPE>();
-}
-
/**
* @brief Just checks if there is any "WeightlessCacheAttribute" present in the model. In the negative case, an error is
* thrown. The weights separation flow in its current state cannot work without this attribuite.
@@ -239,18 +210,18 @@ int get_ir_version(const std::shared_ptr<const ov::Model>& model, const intel_np
namespace intel_npu {
-Plugin::Plugin()
- : _options(std::make_shared<OptionsDesc>()),
- _globalConfig(_options),
- _logger("NPUPlugin", Logger::global().level()) {
+Plugin::Plugin() : _options(std::make_shared<OptionsDesc>()), _logger("NPUPlugin", Logger::global().level()) {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::Plugin");
set_device_name("NPU");
// parse env_variables to get LOG_LEVEL if needed
_options->add<LOG_LEVEL>();
- _globalConfig.parseEnvVars();
- Logger::global().setLevel(_globalConfig.get<LOG_LEVEL>());
- _logger.setLevel(_globalConfig.get<LOG_LEVEL>());
+
+ FilteredConfig filteredConfig(_options);
+
+ filteredConfig.parseEnvVars();
+ Logger::global().setLevel(filteredConfig.get<LOG_LEVEL>());
+ _logger.setLevel(filteredConfig.get<LOG_LEVEL>());
OV_ITT_TASK_CHAIN(PLUGIN, itt::domains::NPUPlugin, "Plugin::Plugin", "GetBackend");
// backend registry shall be created after configs are updated
@@ -266,15 +237,15 @@ Plugin::Plugin()
_metrics = std::make_unique<Metrics>(_backend);
OV_ITT_TASK_NEXT(PLUGIN, "InitOptions");
- init_options();
+ init_options(filteredConfig);
/// Init and register properties
OV_ITT_TASK_NEXT(PLUGIN, "RegisterProperties");
- _properties = std::make_unique<Properties>(PropertiesType::PLUGIN, _globalConfig, _metrics, _backend);
- _properties->registerProperties();
+ _propertiesManager = std::make_unique<Properties>(PropertiesType::PLUGIN, filteredConfig, _metrics, _backend);
+ _propertiesManager->registerProperties();
}
-void Plugin::init_options() {
+void Plugin::init_options(FilteredConfig& filteredConfig) {
// Initialize (note: it will reset registered options)
_options->reset();
@@ -283,7 +254,7 @@ void Plugin::init_options() {
auto dummyopt = details::makeOptionModel<OPT_TYPE>(); \
std::string o_name = dummyopt.key().data(); \
_options->add<OPT_TYPE>(); \
- _globalConfig.enable(std::move(o_name), false); \
+ filteredConfig.enable(std::move(o_name), false); \
} while (0)
REGISTER_OPTION(LOG_LEVEL);
@@ -346,7 +317,7 @@ void Plugin::init_options() {
}
// parse again env_variables to update registered configs which have env vars set
- _globalConfig.parseEnvVars();
+ filteredConfig.parseEnvVars();
// NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we still need
// to enable those for OV Core to query. Note: do this last to not filter them out. register npuw caching properties
@@ -415,252 +386,61 @@ void Plugin::init_options() {
REGISTER_OPTION(NPUW_KOKORO_BLOCK_SIZE);
REGISTER_OPTION(NPUW_KOKORO_OVERLAP_SIZE);
- _globalConfig.enableRuntimeOptions();
+ filteredConfig.enableRuntimeOptions();
// Special cases
- _globalConfig.enable(ov::log::level.name(), true); // needed also by runtime options
+ filteredConfig.enable(ov::log::level.name(), true); // needed also by runtime options
- if (_globalConfig.get<COMPILER_TYPE>() == ov::intel_npu::CompilerType::PREFER_PLUGIN) {
+ if (filteredConfig.get<COMPILER_TYPE>() == ov::intel_npu::CompilerType::PREFER_PLUGIN) {
if (_backend) {
- auto platformName = _backend->getDevice()->getName();
- if (platformName != ov::intel_npu::Platform::NPU4000 && platformName != ov::intel_npu::Platform::NPU5010) {
- std::ostringstream oss;
- oss << ov::intel_npu::CompilerType::DRIVER;
- _globalConfig.update({{ov::intel_npu::compiler_type.name(), oss.str()}});
- _logger.info("Use %s as default compiler", oss.str().c_str());
- }
- }
- }
-}
-
-void Plugin::filter_config_by_compiler_support(FilteredConfig& cfg) const {
- bool legacy = false;
- bool nocompiler = false;
- std::unique_ptr<ICompilerAdapter> compiler = nullptr;
- std::vector<std::string> compiler_support_list{};
- uint32_t compiler_version = 0;
-
- // create a dummy compiler to fetch version and supported options
- try {
- auto compiler_type = cfg.get<COMPILER_TYPE>();
- compiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compiler_type);
- } catch (...) {
- // assuming getCompiler failed, meaning we are offline
- _logger.warning("No available compiler. Enabling only runtime options ");
- nocompiler = true;
- }
-
- if (!nocompiler || (compiler != nullptr)) {
- compiler_version = compiler->get_version();
- compiler_support_list = compiler->get_supported_options();
- }
- if (compiler_support_list.size() == 0) {
- _logger.info("No compiler support options list received! Fallback to version-based option registration");
- legacy = true;
- }
-
- // Logs
- _logger.debug("Compiler version: %ld", compiler_version);
- _logger.debug("Compiler supported options list (%ld): ", compiler_support_list.size());
- for (const auto& str : compiler_support_list) {
- _logger.debug(" %s ", str.c_str());
- }
- _logger.debug("Legacy registration: %s", legacy ? "true" : "false");
-
- // Parse enables
- cfg.walkEnables([&](const std::string& key) {
- bool isEnabled = false;
- auto opt = cfg.getOpt(key);
- // Runtime (plugin-only) options are always enabled
- if (opt.mode() == OptionMode::RunTime) {
- isEnabled = true;
- } else { // Compiler and common options
- if (nocompiler && (opt.mode() == OptionMode::CompileTime)) {
- // we do not register compileTime options if there is no compiler
- isEnabled = false;
- } else if (legacy) {
- // Compiler or common option in Legacy mode? Checking its supported version
- if (compiler_version >= opt.compilerSupportVersion()) {
- isEnabled = true;
- }
- } else {
- // We have compiler, we are not in legacy mode = we have a valid list of supported options
- // Searching in the list
- auto it = std::find(compiler_support_list.begin(), compiler_support_list.end(), key);
- if (it != compiler_support_list.end()) {
- isEnabled = true;
- } else {
- // Not found in the supported options list.
- if (compiler != nullptr) {
- // Checking if it is a private option?
- isEnabled = compiler->is_option_supported(key);
- } else {
- // Not in the list and not a private option = disabling
- isEnabled = false;
- }
+ auto device = _backend->getDevice();
+ if (device) {
+ auto platformName = device->getName();
+ CompilerAdapterFactory compilerFactory;
+ auto compileType = compilerFactory.determinteAppropriateCompilerTypeBasedOnPlatform(platformName);
+ if (compileType == ov::intel_npu::CompilerType::DRIVER) {
+ filteredConfig.update(
+ {{ov::intel_npu::compiler_type.name(), COMPILER_TYPE::toString(compileType)}});
+ _logger.info("Use %s as default compiler", COMPILER_TYPE::toString(compileType).c_str());
}
}
}
- if (!isEnabled) {
- _logger.debug("Config option %s not supported! Requirements not met.", key.c_str());
- } else {
- _logger.debug("Enabled config option %s", key.c_str());
- }
- // update enable flag
- cfg.enable(key, isEnabled);
- });
-
- // Special case for NPU_TURBO which might not be supported by compiler, but driver will still use it
- // if it exists in config = driver supports it
- // if compiler->is_option_suported is false = compiler doesn't support it and gets marked disabled by default logic
- // however, if driver supports it, we still need it (and will skip giving it to compiler) = force-enable
- if (_backend && _backend->isCommandQueueExtSupported()) {
- cfg.enable(ov::intel_npu::turbo.name(), true);
- }
-}
-
-void Plugin::filter_global_config_safe(const std::optional<ov::intel_npu::CompilerType>& compilerChange) const {
- std::lock_guard<std::mutex> lock(_mutex);
- if (compilerChange.has_value()) {
- _globalConfig.update({{std::string(COMPILER_TYPE::key()), COMPILER_TYPE::toString(compilerChange.value())}});
- }
- if (!_globalConfig.wasInitialized() || compilerChange.has_value()) {
- // filter out unsupported options
- filter_config_by_compiler_support(_globalConfig);
- // reset properties for the new options
- _properties->registerProperties();
- // set globalConfig as filtered
- _globalConfig.markAsInitialized();
- }
-}
-
-FilteredConfig Plugin::fork_local_config(const ov::AnyMap& properties,
- const std::unique_ptr<ICompilerAdapter>& compiler,
- OptionMode mode) const {
- update_log_level(properties);
-
- if (_backend != nullptr) {
- _backend->updateInfo(properties);
- }
-
- // create a copy of the global config
- std::unique_ptr<FilteredConfig>
- localConfigPtr; // no default constructor from FilteredConfig, needed to switch to ptr
- {
- std::lock_guard<std::mutex> lock(_mutex);
- localConfigPtr = std::make_unique<FilteredConfig>(_globalConfig);
- }
- bool compiler_changed = false;
-
- const std::map<std::string, std::string> rawConfig = any_copy(properties);
-
- // Check if compiler was changed
- // 1. Check for compiler change
- auto it = rawConfig.find(std::string(COMPILER_TYPE::key()));
- if (it != rawConfig.end()) {
- if (localConfigPtr->getString<COMPILER_TYPE>() != it->second) {
- // Compiler type has changed!
- // Set new compiler type
- localConfigPtr->update({{std::string(COMPILER_TYPE::key()), it->second}});
- // enable/disable config keys based on what the new compiler supports
- filter_config_by_compiler_support(*localConfigPtr);
- compiler_changed = true;
- // set localConfig as filtered
- localConfigPtr->markAsInitialized();
- }
- }
-
- // If localConfig was not initialized not even by compiler type change, then both localConfig and _globalConfig need
- // to be initialized
- if (!localConfigPtr->wasInitialized()) {
- filter_global_config_safe();
- {
- std::lock_guard<std::mutex> lock(_mutex);
- localConfigPtr = std::make_unique<FilteredConfig>(_globalConfig);
- }
- }
-
- // 2. Revalidate unknown internal configs
- // look for unsupported internals
- // first in what we inherited from globalconfig by forking it - ONLY if compiler has changed
- if (compiler_changed) {
- localConfigPtr->walkInternals([&](const std::string& key) {
- if (!compiler->is_option_supported(key)) {
- OPENVINO_THROW("[ NOT_FOUND ] Option '", key, "' is not supported for current configuration");
- }
- });
- }
- // secondly, in the new config provided by user
- std::map<std::string, std::string> cfgs_to_set;
- for (const auto& [key, value] : rawConfig) {
- if (!localConfigPtr->hasOpt(key)) {
- // not a known config key
- if (!compiler->is_option_supported(key)) {
- OPENVINO_THROW("[ NOT_FOUND ] Option '", key, "' is not supported for current configuration");
- } else {
- localConfigPtr->addOrUpdateInternal(key, value);
- }
- } else {
- cfgs_to_set.emplace(key, value);
- }
}
-
- // 3. If all good so far, update values
- localConfigPtr->update(cfgs_to_set, mode);
- return *localConfigPtr;
}
void Plugin::set_property(const ov::AnyMap& properties) {
if (properties.empty()) {
return;
}
+ update_log_level(properties);
- // 1. Check for compiler change
- if (properties.count(std::string(COMPILER_TYPE::key())) != 0) {
- // Compiler change detected
- // Set new compiler in _globalConfig
- auto it = properties.find(std::string(COMPILER_TYPE::key()));
- if (it != properties.end()) {
- // enable/disable config keys based on what the new compiler supports
- filter_global_config_safe(COMPILER_TYPE::parse(it->second.as<std::string>()));
- }
- }
-
- // 2. Check if configs have been initialized
- for (const auto& prop : properties) {
- if (!_properties->isPropertyRegistered(prop.first)) {
- filter_global_config_safe();
- break;
- }
- }
-
- // 3. Set the property via Properties interface
- _properties->set_property(properties);
-
- // 4. Extra hooks
- // Update log level if it was provided
- if (properties.count(ov::log::level.name()) != 0) {
- Logger::global().setLevel(_globalConfig.get<LOG_LEVEL>());
- }
- // Init backends if needed
if (_backend != nullptr) {
_backend->updateInfo(properties);
}
+
+ _propertiesManager->setProperty(properties);
}
ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& arguments) const {
- auto npu_plugin_properties = arguments;
- exclude_model_ptr_from_map(npu_plugin_properties);
+ auto npuPluginArguments = arguments;
+ exclude_model_ptr_from_map(npuPluginArguments);
- if ((!_properties->isPropertyRegistered(name) || name == ov::supported_properties.name())) {
- filter_global_config_safe();
+ if (!npuPluginArguments.empty()) {
+ // Need to create a temporary copy of the properties manager. The set of arguments we get might change the list
+ // of supported properties, but we cannot alter the global state
+ auto copyPropertiesManager = std::make_unique<Properties>(*_propertiesManager);
+ copyPropertiesManager->setProperty(npuPluginArguments);
+
+ return copyPropertiesManager->getProperty(name);
}
- return _properties->get_property(name, npu_plugin_properties);
+
+ return _propertiesManager->getProperty(name);
}
std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::compile_model");
+ update_log_level(properties);
// Before going any further: if
// ... 1 - NPUW mode is activated
@@ -710,25 +490,39 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
modelSerializerChosenExplicitly = true;
}
- update_log_level(localProperties);
-
- // create compiler
- ov::intel_npu::CompilerType compilerType = resolveCompilerType(_globalConfig, localProperties);
- const bool wasPreferPlugin = (compilerType == ov::intel_npu::CompilerType::PREFER_PLUGIN);
- auto compiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compilerType);
- if (wasPreferPlugin) {
- localProperties[ov::intel_npu::compiler_type.name()] = compilerType;
+ if (_backend != nullptr) {
+ _backend->updateInfo(localProperties);
}
- OV_ITT_TASK_CHAIN(PLUGIN_COMPILE_MODEL, itt::domains::NPUPlugin, "Plugin::compile_model", "fork_local_config");
- auto localConfig = fork_local_config(localProperties, compiler);
+ // Resolving the requested compiler type based on local and global properties.
+ // It can still remain PREFER_PLUGIN even after this point
+ ov::intel_npu::CompilerType compilerType = _propertiesManager->determineCompilerType(localProperties);
+
+ auto deviceId = _propertiesManager->determineDeviceId(localProperties);
+ // DEVICE_ID can be passed both as an index and as a platform name.
+ // Identify the right device object to be taken into account when the target compilation platform is determined
+ std::shared_ptr<IDevice> device = utils::getDeviceById(_backend, deviceId);
- const auto platform =
- utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
- localConfig.get<DEVICE_ID>(),
+ // Determine the final compilation target based on NPU_PLATFORM, determined device name (if any) and the list of
+ // available devices (if any)
+ const auto compilationPlatform =
+ utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),
+ device == nullptr ? deviceId : device->getName(),
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
- auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
- localConfig.update({{ov::intel_npu::platform.name(), platform}});
+
+ CompilerAdapterFactory factory;
+ auto compiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
+
+ localProperties[ov::intel_npu::compiler_type.name()] = compilerType;
+ if (!compilationPlatform.empty()) {
+ localProperties[ov::intel_npu::platform.name()] = compilationPlatform;
+ }
+
+ OV_ITT_TASK_CHAIN(PLUGIN_COMPILE_MODEL, itt::domains::NPUPlugin, "Plugin::compile_model", "fork_local_config");
+ auto copyPropertiesManager = std::make_unique<Properties>(*_propertiesManager);
+ copyPropertiesManager->updateConfig(localProperties, compiler.get());
+ FilteredConfig localConfig = copyPropertiesManager->getConfig();
+ copyPropertiesManager.reset();
auto updateBatchMode = [&](ov::intel_npu::BatchMode mode) {
std::stringstream strStream;
@@ -784,8 +578,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
// Update stepping w/ information from driver, unless provided by user or we are off-device
// Ignore, if compilation was requested for platform, different from current
- if (!localConfig.has<STEPPING>() && device != nullptr &&
- device->getName() == ov::intel_npu::Platform::standardize(platform)) {
+ if (!localConfig.has<STEPPING>() && device != nullptr && device->getName() == compilationPlatform) {
try {
localConfig.update({{ov::intel_npu::stepping.name(), std::to_string(device->getSubDevId())}});
} catch (...) {
@@ -795,8 +588,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
}
// Update max_tiles w/ information from driver, unless provided by user or we are off-device
// Ignore, if compilation was requested for platform, different from current
- if (!localConfig.has<MAX_TILES>() && device != nullptr &&
- device->getName() == ov::intel_npu::Platform::standardize(platform)) {
+ if (!localConfig.has<MAX_TILES>() && device != nullptr && device->getName() == compilationPlatform) {
try {
localConfig.update({{ov::intel_npu::max_tiles.name(), std::to_string(device->getMaxNumSlices())}});
} catch (...) {
@@ -919,41 +711,46 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
}
ov::SoPtr<ov::IRemoteContext> Plugin::create_context(const ov::AnyMap& remoteProperties) const {
- auto npu_plugin_properties = remoteProperties;
- exclude_model_ptr_from_map(npu_plugin_properties);
- return std::make_shared<RemoteContextImpl>(_backend, npu_plugin_properties);
+ auto npuPluginProperties = remoteProperties;
+ exclude_model_ptr_from_map(npuPluginProperties);
+ return std::make_shared<RemoteContextImpl>(_backend, npuPluginProperties);
}
ov::SoPtr<ov::IRemoteContext> Plugin::get_default_context(const ov::AnyMap& remoteProperties) const {
- auto npu_plugin_properties = remoteProperties;
- exclude_model_ptr_from_map(npu_plugin_properties);
+ auto npuPluginProperties = remoteProperties;
+ exclude_model_ptr_from_map(npuPluginProperties);
return std::make_shared<RemoteContextImpl>(_backend);
}
std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::import_model");
+ update_log_level(properties);
if (properties.find(ov::hint::compiled_blob.name()) != properties.end()) {
_logger.warning("ov::hint::compiled_blob is no longer supported for import_model(stream) API! Please use new "
"import_model(tensor) API instead.");
}
- auto npu_plugin_properties = properties;
- // NPUW properties from npu_plugin_properties will be erased if import_model_npuw returns nullptr
- auto compiledModel = import_model_npuw(stream, npu_plugin_properties, shared_from_this());
+ auto npuPluginProperties = properties;
+ // NPUW properties from npuPluginProperties will be erased if import_model_npuw returns nullptr
+ auto compiledModel = import_model_npuw(stream, npuPluginProperties, shared_from_this());
if (compiledModel) {
return compiledModel;
}
+ if (_backend != nullptr) {
+ _backend->updateInfo(npuPluginProperties);
+ }
+
try {
const bool skipCompatibility =
- (npu_plugin_properties.find(DISABLE_VERSION_CHECK::key().data()) != npu_plugin_properties.end())
- ? npu_plugin_properties[DISABLE_VERSION_CHECK::key().data()].as<bool>()
- : _globalConfig.get<DISABLE_VERSION_CHECK>();
+ (npuPluginProperties.find(DISABLE_VERSION_CHECK::key().data()) != npuPluginProperties.end())
+ ? npuPluginProperties[DISABLE_VERSION_CHECK::key().data()].as<bool>()
+ : _propertiesManager->getConfig().get<DISABLE_VERSION_CHECK>();
const bool importRawBlob =
- (npu_plugin_properties.find(IMPORT_RAW_BLOB::key().data()) != npu_plugin_properties.end())
- ? npu_plugin_properties[IMPORT_RAW_BLOB::key().data()].as<bool>()
- : _globalConfig.get<IMPORT_RAW_BLOB>();
+ (npuPluginProperties.find(IMPORT_RAW_BLOB::key().data()) != npuPluginProperties.end())
+ ? npuPluginProperties[IMPORT_RAW_BLOB::key().data()].as<bool>()
+ : _propertiesManager->getConfig().get<IMPORT_RAW_BLOB>();
std::unique_ptr<MetadataBase> metadata = nullptr;
size_t blobSize = MetadataBase::getFileSize(stream);
@@ -972,7 +769,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
OPENVINO_THROW("Blob size is too large to be represented on a std::streamsize!");
}
stream.read(tensor.data<char>(), static_cast<std::streamsize>(blobSize));
- return parse(tensor, std::move(metadata), npu_plugin_properties);
+ return parse(tensor, std::move(metadata), npuPluginProperties);
} catch (const std::exception& ex) {
OPENVINO_THROW("Can't import network: ", ex.what());
} catch (...) {
@@ -991,43 +788,48 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream,
return import_model(stream, properties);
}
-std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compiled_blob,
+std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compiledBlob,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::import_model");
+ update_log_level(properties);
// Need to create intermediate istream for NPUW
- ov::SharedStreamBuffer buffer{compiled_blob.data(), compiled_blob.get_byte_size()};
+ ov::SharedStreamBuffer buffer{compiledBlob.data(), compiledBlob.get_byte_size()};
std::istream stream{&buffer};
- auto npu_plugin_properties = properties;
- // NPUW properties from npu_plugin_properties will be erased if import_model_npuw returns nullptr
- auto compiledModel = import_model_npuw(stream, npu_plugin_properties, shared_from_this());
+ auto npuPluginProperties = properties;
+ // NPUW properties from npuPluginProperties will be erased if import_model_npuw returns nullptr
+ auto compiledModel = import_model_npuw(stream, npuPluginProperties, shared_from_this());
if (compiledModel) {
return compiledModel;
}
+ if (_backend != nullptr) {
+ _backend->updateInfo(npuPluginProperties);
+ }
+
try {
const bool skipCompatibility =
- (npu_plugin_properties.find(DISABLE_VERSION_CHECK::key().data()) != npu_plugin_properties.end())
- ? npu_plugin_properties[DISABLE_VERSION_CHECK::key().data()].as<bool>()
- : _globalConfig.get<DISABLE_VERSION_CHECK>();
+ (npuPluginProperties.find(DISABLE_VERSION_CHECK::key().data()) != npuPluginProperties.end())
+ ? npuPluginProperties[DISABLE_VERSION_CHECK::key().data()].as<bool>()
+ : _propertiesManager->getConfig().get<DISABLE_VERSION_CHECK>();
const bool importRawBlob =
- (npu_plugin_properties.find(IMPORT_RAW_BLOB::key().data()) != npu_plugin_properties.end())
- ? npu_plugin_properties[IMPORT_RAW_BLOB::key().data()].as<bool>()
- : _globalConfig.get<IMPORT_RAW_BLOB>();
+ (npuPluginProperties.find(IMPORT_RAW_BLOB::key().data()) != npuPluginProperties.end())
+ ? npuPluginProperties[IMPORT_RAW_BLOB::key().data()].as<bool>()
+ : _propertiesManager->getConfig().get<IMPORT_RAW_BLOB>();
std::unique_ptr<MetadataBase> metadata = nullptr;
- size_t blobSize = compiled_blob.get_byte_size();
+ size_t blobSize = compiledBlob.get_byte_size();
if (!importRawBlob && !skipCompatibility) {
- metadata = read_metadata_from(compiled_blob);
+ metadata = read_metadata_from(compiledBlob);
blobSize = metadata->get_blob_size();
} else {
_logger.info("Blob compatibility check skipped.");
}
- const ov::Tensor roiTensor(compiled_blob,
+ const ov::Tensor roiTensor(compiledBlob,
ov::Coordinate{0},
ov::Coordinate{blobSize}); // ROI tensor to skip NPU plugin metadata
- return parse(roiTensor, std::move(metadata), npu_plugin_properties);
+ return parse(roiTensor, std::move(metadata), npuPluginProperties);
} catch (const std::exception& ex) {
OPENVINO_THROW("Can't import network: ", ex.what());
} catch (...) {
@@ -1035,19 +837,21 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compi
}
}
-std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compiled_blob,
+std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& compiledBlob,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const {
auto casted = std::dynamic_pointer_cast<RemoteContextImpl>(context._ptr);
if (casted == nullptr) {
OPENVINO_THROW("Invalid remote context type. Can't cast to ov::intel_npu::RemoteContext type");
}
- return import_model(compiled_blob, properties);
+ return import_model(compiledBlob, properties);
}
ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::query_model");
+ update_log_level(properties);
+
auto localProperties = properties;
// There is an on-going migration from "USE_BASE_MODEL_SERIALIZER" to "MODEL_SERIALIZER_VERSION". Until done, make
// sure only the option supported by the compiler is registered in the config.
@@ -1075,22 +879,33 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
modelSerializerChosenExplicitly = true;
}
exclude_model_ptr_from_map(localProperties);
- update_log_level(localProperties);
- ov::intel_npu::CompilerType compilerType = resolveCompilerType(_globalConfig, localProperties);
- const bool wasPreferPlugin = (compilerType == ov::intel_npu::CompilerType::PREFER_PLUGIN);
- auto compiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compilerType);
- if (wasPreferPlugin) {
- localProperties[ov::intel_npu::compiler_type.name()] = compilerType;
+ if (_backend != nullptr) {
+ _backend->updateInfo(localProperties);
}
- auto localConfig = fork_local_config(localProperties, compiler, OptionMode::CompileTime);
- _logger.setLevel(localConfig.get<LOG_LEVEL>());
- const auto platform =
- utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
- localConfig.get<DEVICE_ID>(),
+ ov::intel_npu::CompilerType compilerType = _propertiesManager->determineCompilerType(localProperties);
+ auto deviceId = _propertiesManager->determineDeviceId(localProperties);
+
+ std::shared_ptr<IDevice> device = utils::getDeviceById(_backend, deviceId);
+
+ const auto compilationPlatform =
+ utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),
+ device == nullptr ? deviceId : device->getName(),
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
- localConfig.update({{ov::intel_npu::platform.name(), platform}});
+
+ CompilerAdapterFactory factory;
+ auto compiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
+
+ localProperties[ov::intel_npu::compiler_type.name()] = compilerType;
+ if (!compilationPlatform.empty()) {
+ localProperties[ov::intel_npu::platform.name()] = compilationPlatform;
+ }
+
+ auto copyPropertiesManager = std::make_unique<Properties>(*_propertiesManager);
+ copyPropertiesManager->updateConfig(localProperties, compiler.get(), OptionMode::CompileTime);
+ FilteredConfig localConfig = copyPropertiesManager->getConfig();
+ copyPropertiesManager.reset();
if (modelSerializerChosenExplicitly) {
if (localConfig.isAvailable(ov::intel_npu::use_base_model_serializer.name())) {
@@ -1140,24 +955,24 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
// list of properties
auto originalModel = exclude_model_ptr_from_map(localProperties);
- update_log_level(localProperties);
+ ov::intel_npu::CompilerType compilerType = _propertiesManager->determineCompilerType(localProperties);
+ auto deviceId = _propertiesManager->determineDeviceId(localProperties);
- ov::intel_npu::CompilerType compilerType = resolveCompilerType(_globalConfig, localProperties);
- const bool wasPreferPlugin = (compilerType == ov::intel_npu::CompilerType::PREFER_PLUGIN);
- auto compiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compilerType);
- if (wasPreferPlugin) {
- localProperties[ov::intel_npu::compiler_type.name()] = compilerType;
- }
+ std::shared_ptr<IDevice> device = utils::getDeviceById(_backend, deviceId);
- OV_ITT_TASK_CHAIN(PLUGIN_PARSE_MODEL, itt::domains::NPUPlugin, "Plugin::parse", "fork_local_config");
- auto localConfig = fork_local_config(localProperties, compiler, OptionMode::RunTime);
- _logger.setLevel(localConfig.get<LOG_LEVEL>());
- const auto platform =
- utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
- localConfig.get<DEVICE_ID>(),
+ const auto compilationPlatform =
+ utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),
+ device == nullptr ? deviceId : device->getName(),
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
- localConfig.update({{ov::intel_npu::platform.name(), platform}});
- auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
+
+ CompilerAdapterFactory factory;
+ auto compiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
+
+ OV_ITT_TASK_CHAIN(PLUGIN_PARSE_MODEL, itt::domains::NPUPlugin, "Plugin::parse", "fork_local_config");
+ auto copyPropertiesManager = std::make_unique<Properties>(*_propertiesManager);
+ copyPropertiesManager->updateConfig(localProperties, OptionMode::RunTime);
+ FilteredConfig localConfig = copyPropertiesManager->getConfig();
+ copyPropertiesManager.reset();
const auto loadedFromCache = localConfig.get<LOADED_FROM_CACHE>();
if (!loadedFromCache) {
@@ -1259,6 +1074,13 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
return std::make_shared<CompiledModel>(modelDummy, shared_from_this(), device, graph, localConfig, batchSize);
}
+void Plugin::update_log_level(const ov::AnyMap& properties) const {
+ if (properties.count(ov::log::level.name()) != 0) {
+ Logger::global().setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
+ _logger.setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
+ }
+}
+
std::atomic<int> Plugin::_compiledModelLoadCounter{1};
static const ov::Version version = {CI_BUILD_NUMBER, NPU_PLUGIN_LIB_NAME};
diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cpp
index e83e288c7b3..8a5d1f5282c 100644
--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp
@@ -11,6 +11,22 @@
#include "intel_npu/config/options.hpp"
#include "intel_npu/utils/utils.hpp"
+namespace {
+
+std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
+ std::map<std::string, std::string> result;
+ for (auto&& value : params) {
+ // The value of cache_encryption_callbacks cannot be converted to std::string
+ if (value.first == ov::cache_encryption_callbacks.name()) {
+ continue;
+ }
+ result.emplace(value.first, value.second.as<std::string>());
+ }
+ return result;
+}
+
+} // namespace
+
namespace intel_npu {
//
@@ -282,7 +298,7 @@ static auto get_specified_device_name(const Config config) {
// Note: this is the value provided by the plugin, application should query and consider it, but may supply its own
// preference for number of parallel requests via dedicated configuration
static int64_t getOptimalNumberOfInferRequestsInParallel(const Config& config) {
- const std::string platform = ov::intel_npu::Platform::standardize(config.get<PLATFORM>());
+ const std::string platform = config.get<PLATFORM>();
if (platform == ov::intel_npu::Platform::NPU3720) {
if (config.get<PERFORMANCE_HINT>() == ov::hint::PerformanceMode::THROUGHPUT) {
@@ -300,13 +316,26 @@ static int64_t getOptimalNumberOfInferRequestsInParallel(const Config& config) {
}
Properties::Properties(const PropertiesType pType,
- FilteredConfig& config,
+ const FilteredConfig& config,
const std::shared_ptr<Metrics>& metrics,
const ov::SoPtr<IEngineBackend>& backend)
: _pType(pType),
_config(config),
_metrics(metrics),
- _backend(backend) {}
+ _backend(backend),
+ _logger("Properties", _config.get<LOG_LEVEL>()) {}
+
+Properties::Properties(const Properties& other)
+ : _pType(other._pType),
+ _config(other._config),
+ _metrics(other._metrics),
+ _backend(other._backend),
+ _logger("Properties", _config.get<LOG_LEVEL>()),
+ _currentlyUsedCompiler(other._currentlyUsedCompiler),
+ _currentlyUsedPlatform(other._currentlyUsedPlatform),
+ _initialized(other._initialized),
+ _properties(other._properties),
+ _supportedProperties(other._supportedProperties) {}
void Properties::registerProperties() {
// Reset
@@ -397,8 +426,7 @@ void Properties::registerPluginProperties() {
const auto specifiedDeviceName = get_specified_device_name(config);
return static_cast<int64_t>(_metrics->GetSteppingNumber(specifiedDeviceName));
} catch (...) {
- Logger("Properties", ov::log::Level::WARNING)
- .warning("Metrics GetSteppingNumber failed to get value from device.");
+ _logger.warning("Metrics GetSteppingNumber failed to get value from device.");
}
}
return config.get<STEPPING>();
@@ -409,8 +437,7 @@ void Properties::registerPluginProperties() {
const auto specifiedDeviceName = get_specified_device_name(config);
return static_cast<int64_t>(_metrics->GetMaxTiles(specifiedDeviceName));
} catch (...) {
- Logger("Properties", ov::log::Level::WARNING)
- .warning("Metrics GetMaxTiles failed to get value from device.");
+ _logger.warning("Metrics GetMaxTiles failed to get value from device.");
}
}
return config.get<MAX_TILES>();
@@ -521,7 +548,8 @@ void Properties::registerPluginProperties() {
config,
utils::getCompilationPlatform(
config.get<PLATFORM>(),
- config.get<DEVICE_ID>(),
+ _backend == nullptr ? config.get<DEVICE_ID>()
+ : _backend->getDevice(config.get<DEVICE_ID>())->getName(),
_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames())))));
REGISTER_SIMPLE_METRIC(ov::range_for_async_infer_requests, true, _metrics->GetRangeForAsyncInferRequest());
REGISTER_SIMPLE_METRIC(ov::range_for_streams, true, _metrics->GetRangeForStreams());
@@ -571,7 +599,16 @@ void Properties::registerPluginProperties() {
REGISTER_CUSTOM_METRIC(ov::intel_npu::compiler_version, true, [&](const Config& config) {
/// create dummy compiler
auto compilerType = config.get<COMPILER_TYPE>();
- auto dummyCompiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compilerType);
+ auto deviceId = config.get<DEVICE_ID>();
+ auto device = utils::getDeviceById(_backend, deviceId);
+
+ auto compilationPlatform = utils::getCompilationPlatform(
+ config.get<PLATFORM>(),
+ device == nullptr ? deviceId : device->getName(),
+ _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+
+ CompilerAdapterFactory factory;
+ auto dummyCompiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
return dummyCompiler->get_version();
});
REGISTER_CUSTOM_METRIC(ov::internal::caching_properties, false, [&](const Config& config) {
@@ -687,49 +724,100 @@ void Properties::registerCompiledModelProperties() {
});
}
-ov::Any Properties::get_property(const std::string& name, const ov::AnyMap& arguments) const {
- std::map<std::string, std::string> amends;
- for (auto&& value : arguments) {
- amends.emplace(value.first, value.second.as<std::string>());
- }
- FilteredConfig amendedConfig = _config;
- try {
- amendedConfig.update(amends, OptionMode::Both);
- } catch (const ov::Exception& /* unusedOVException */) {
- Logger("Properties", ov::log::Level::WARNING)
- .warning("Amended config couldn't be updated with the given arguments");
+ov::Any Properties::getProperty(const std::string& name) {
+ std::lock_guard<std::mutex> lock(_mutex);
+ if (_pType == PropertiesType::PLUGIN) {
+ bool propertyIsCompilerConfig = false;
+ bool propertyIsRegistered = true;
+ // If the property is not registered, there is no point of checking the config.
+ if (!isPropertyRegistered(name)) {
+ propertyIsRegistered = false;
+ } else {
+ // Property is already registered but need to re-check if the CompilerTime config is still supported by the
+ // current compiler.
+ if (_config.hasOpt(name) && name != ov::log::level.name()) {
+ auto opt = _config.getOpt(name);
+ if (opt.mode() != OptionMode::RunTime) {
+ propertyIsCompilerConfig = true;
+ }
+ }
+ }
+
+ if (propertyIsCompilerConfig || !propertyIsRegistered || name == ov::supported_properties.name()) {
+ std::unique_ptr<ICompilerAdapter> compiler = nullptr;
+ auto compilerType = _config.get<COMPILER_TYPE>();
+ auto deviceId = _config.get<DEVICE_ID>();
+ auto device = utils::getDeviceById(_backend, deviceId);
+
+ auto compilationPlatform = utils::getCompilationPlatform(
+ _config.get<PLATFORM>(),
+ device == nullptr ? deviceId : device->getName(),
+ _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+
+ // Create a compiler to get the type and fetch version and supported options if needed
+ CompilerAdapterFactory factory;
+ compiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
+
+ filterPropertiesByCompilerSupport(compiler.get(), compilerType, compilationPlatform);
+ }
}
auto&& configIterator = _properties.find(name);
if (configIterator != _properties.cend()) {
- return std::get<2>(configIterator->second)(amendedConfig);
+ return std::get<2>(configIterator->second)(_config);
}
try {
- return amendedConfig.getInternal(name);
+ return _config.getInternal(name);
} catch (...) {
OPENVINO_THROW("Unsupported configuration key: ", name);
}
}
-void Properties::set_property(const ov::AnyMap& properties) {
- std::map<std::string, std::string> cfgs_to_set;
+void Properties::setProperty(const ov::AnyMap& properties) {
+ std::unique_ptr<ICompilerAdapter> compiler = nullptr;
+ std::lock_guard<std::mutex> lock(_mutex);
+ if (_pType == PropertiesType::PLUGIN) {
+ bool propertyIsCompilerConfig = false;
+ bool propertyIsRegistered = true;
+ for (const auto& property : properties) {
+ if (!isPropertyRegistered(property.first)) {
+ propertyIsRegistered = false;
+ break;
+ }
+ if (_config.hasOpt(property.first) && property.first != ov::log::level.name()) {
+ auto opt = _config.getOpt(property.first);
+ if (opt.mode() != OptionMode::RunTime) {
+ propertyIsCompilerConfig = true;
+ break;
+ }
+ }
+ }
+
+ // Check if one of the properties is compiler config which needs to return different values based on compiler
+ // and platform configuration
+ if (propertyIsCompilerConfig || !propertyIsRegistered) {
+ auto compilerType = determineCompilerType(properties);
+ auto deviceId = determineDeviceId(properties);
+ auto device = utils::getDeviceById(_backend, deviceId);
+ auto compilationPlatform = utils::getCompilationPlatform(
+ determinePlatform(properties),
+ device == nullptr ? deviceId : device->getName(),
+ _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+
+ // Create a compiler to get the type and fetch version and supported options if needed
+ CompilerAdapterFactory factory;
+ compiler = factory.getCompiler(_backend, compilerType, compilationPlatform);
+
+ filterPropertiesByCompilerSupport(compiler.get(), compilerType, compilationPlatform);
+ }
+ }
+
+ std::map<std::string, std::string> cfgs_to_set;
for (auto&& value : properties) {
if (_properties.find(value.first) == _properties.end()) {
// property doesn't exist
// checking as internal now
-
- std::unique_ptr<ICompilerAdapter> compiler = nullptr;
- if (_pType == PropertiesType::PLUGIN) {
- try {
- // Only accepting unknown config keys in plugin
- auto compilerType = _config.get<COMPILER_TYPE>();
- compiler = CompilerAdapterFactory::getInstance().getCompiler(_backend, compilerType);
- } catch (...) {
- // just throw the exception below in case unknown property check is called
- }
- }
-
if (compiler != nullptr) {
if (compiler->is_option_supported(value.first)) {
// if compiler reports it supported > registering as internal
@@ -758,4 +846,175 @@ bool Properties::isPropertyRegistered(const std::string& propertyName) const {
return _properties.find(propertyName) != _properties.end();
}
+void Properties::filterPropertiesByCompilerSupport(const ICompilerAdapter* compiler,
+ const ov::intel_npu::CompilerType compilerType,
+ const std::string& compilationPlatform) {
+ // In case properties are not initialized or the compiler/platform was changed since last call -
+ // filter out options again
+ if (_initialized && compilerType == _currentlyUsedCompiler && compilationPlatform == _currentlyUsedPlatform) {
+ return;
+ }
+
+ bool legacy = false;
+ std::vector<std::string> compilerSupportList{};
+ uint32_t compilerVersion = 0;
+
+ if (compiler != nullptr) {
+ compilerVersion = compiler->get_version();
+ compilerSupportList = compiler->get_supported_options();
+ }
+ if (compilerSupportList.size() == 0) {
+ _logger.info("No compiler support options list received! Fallback to version-based option registration");
+ legacy = true;
+ }
+
+ // Logs
+ _logger.debug("Compiler version: %ld", compilerVersion);
+ _logger.debug("Compiler supported options list (%ld): ", compilerSupportList.size());
+ for (const auto& str : compilerSupportList) {
+ _logger.debug(" %s ", str.c_str());
+ }
+ _logger.debug("Legacy registration: %s", legacy ? "true" : "false");
+
+ // Parse enables
+ _config.walkEnables([&](const std::string& key) {
+ bool isEnabled = false;
+ auto opt = _config.getOpt(key);
+ // Runtime (plugin-only) options are always enabled
+ if (opt.mode() == OptionMode::RunTime) {
+ isEnabled = true;
+ } else { // Compiler and common options
+ if (compiler == nullptr && opt.mode() == OptionMode::CompileTime) {
+ // we do not register compileTime options if there is no compiler
+ isEnabled = false;
+ } else if (legacy) {
+ // Compiler or common option in Legacy mode? Checking its supported version
+ if (compilerVersion >= opt.compilerSupportVersion()) {
+ isEnabled = true;
+ }
+ } else {
+ // We have compiler, we are not in legacy mode = we have a valid list of supported options
+ // Searching in the list
+ auto it = std::find(compilerSupportList.begin(), compilerSupportList.end(), key);
+ if (it != compilerSupportList.end()) {
+ isEnabled = true;
+ } else {
+ // Not found in the supported options list.
+ if (compiler != nullptr) {
+ // Checking if it is a private option?
+ isEnabled = compiler->is_option_supported(key);
+ } else {
+ // Not in the list and not a private option = disabling
+ isEnabled = false;
+ }
+ }
+ }
+ }
+ if (!isEnabled) {
+ _logger.debug("Config option %s not supported! Requirements not met.", key.c_str());
+ } else {
+ _logger.debug("Enabled config option %s", key.c_str());
+ }
+ // update enable flag
+ _config.enable(key, isEnabled);
+ });
+
+ // Special case for NPU_TURBO which might not be supported by compiler, but driver will still use it
+ // if it exists in config = driver supports it
+ // if compiler->is_option_suported is false = compiler doesn't support it and gets marked disabled by default logic
+ // however, if driver supports it, we still need it (and will skip giving it to compiler) = force-enable
+ if (_backend && _backend->isCommandQueueExtSupported()) {
+ _config.enable(ov::intel_npu::turbo.name(), true);
+ }
+
+ // reset properties for the new options
+ registerProperties();
+ _initialized = true;
+ _currentlyUsedCompiler = compilerType;
+ _currentlyUsedPlatform = compilationPlatform;
+}
+
+void Properties::updateConfig(const ov::AnyMap& properties, const ICompilerAdapter* compiler, OptionMode mode) {
+ {
+ std::lock_guard<std::mutex> lock(_mutex);
+ std::optional<ov::intel_npu::CompilerType> propertiesCompilerType = std::nullopt;
+ std::optional<std::string> propertiesPlatform = std::nullopt;
+ if (_initialized) {
+ auto compilerType = properties.find(ov::intel_npu::compiler_type.name());
+ if (compilerType != properties.end()) {
+ propertiesCompilerType = compilerType->second.as<ov::intel_npu::CompilerType>();
+ }
+ }
+ auto platform = properties.find(ov::intel_npu::platform.name());
+ if (platform != properties.end()) {
+ propertiesPlatform = platform->second.as<std::string>();
+ }
+
+ // filter out unsupported options
+ filterPropertiesByCompilerSupport(compiler,
+ propertiesCompilerType.value_or(_currentlyUsedCompiler),
+ propertiesPlatform.value_or(_currentlyUsedPlatform));
+ }
+
+ const std::map<std::string, std::string> rawConfig = any_copy(properties);
+ std::map<std::string, std::string> cfgsToSet;
+ for (const auto& [key, value] : rawConfig) {
+ if (!_config.hasOpt(key)) {
+ // not a known config key
+ if (!compiler->is_option_supported(key)) {
+ OPENVINO_THROW("[ NOT_FOUND ] Option '", key, "' is not supported for current configuration");
+ } else {
+ _config.addOrUpdateInternal(key, value);
+ }
+ } else {
+ cfgsToSet.emplace(key, value);
+ }
+ }
+
+ _config.update(cfgsToSet, mode);
+}
+
+void Properties::updateConfig(const ov::AnyMap& properties, OptionMode mode) {
+ const std::map<std::string, std::string> rawConfig = any_copy(properties);
+ std::map<std::string, std::string> cfgsToSet;
+ for (const auto& [key, value] : rawConfig) {
+ if (!_config.hasOpt(key)) {
+ _logger.info(
+ "Config key '%s' is not recognized as a known option, will not be used for current configuration.",
+ key.c_str());
+ } else {
+ cfgsToSet.emplace(key, value);
+ }
+ }
+
+ _config.update(cfgsToSet, mode);
+}
+
+ov::intel_npu::CompilerType Properties::determineCompilerType(const ov::AnyMap& properties) const {
+ // first look if provided config changes compiler type
+ auto it = properties.find(ov::intel_npu::compiler_type.name());
+ if (it != properties.end()) {
+ // if compiler_type is provided by local config = use that
+ return COMPILER_TYPE::parse(it->second.as<std::string>());
+ }
+ // if there is no compiler_type provided = use _config value
+ return _config.get<COMPILER_TYPE>();
+}
+
+std::string Properties::determinePlatform(const ov::AnyMap& properties) const {
+ auto platform = properties.find(ov::intel_npu::platform.name());
+ if (platform != properties.end()) {
+ return platform->second.as<std::string>();
+ }
+ return _config.get<PLATFORM>();
+}
+
+std::string Properties::determineDeviceId(const ov::AnyMap& properties) const {
+ auto device_id = properties.find(std::string(ov::device::id.name()));
+ if (device_id != properties.end()) {
+ return device_id->second.as<std::string>();
+ }
+ return _config.get<DEVICE_ID>();
+}
+
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
index 7f223de9fa0..4ca603f40ee 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
@@ -137,4 +137,14 @@ INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests_ClassExecutableNetworkInvalidDevice
::testing::ValuesIn(invalid_device_ids)),
ClassExecutableNetworkInvalidDeviceIDTestSuite::getTestCaseName);
+std::vector<std::pair<std::string, ov::Any>> valid_device_ids = {
+ {ov::device::id.name(), "NPU"},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests_CheckCompilerType,
+ CheckCompilerTypeProperty,
+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),
+ ::testing::ValuesIn(valid_device_ids)),
+ CheckCompilerTypeProperty::getTestCaseName);
+
} // namespace
diff --git a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.hpp b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.hpp
index f51e65fd4a3..21057d54d99 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.hpp
@@ -10,6 +10,7 @@
#include "behavior/compiled_model/properties.hpp"
#include "common/npu_test_env_cfg.hpp"
#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"
+#include "openvino/core/log.hpp"
using namespace ov::test::behavior;
@@ -224,9 +225,258 @@ using ClassExecutableNetworkInvalidDeviceIDTestSuite = ClassExecutableNetworkGet
TEST_P(ClassExecutableNetworkInvalidDeviceIDTestSuite, InvalidNPUdeviceIDTest) {
deviceName = configValue.as<std::string>();
+
OV_EXPECT_THROW_HAS_SUBSTRING(ov::CompiledModel compiled_model = ie.compile_model(model, deviceName),
ov::Exception,
- "Could not find available NPU device");
+ "Could not find a valid NPU device for the provided configuration.");
+}
+
+using CheckCompilerTypeProperty = ClassExecutableNetworkGetPropertiesTestNPU;
+
+TEST_P(CheckCompilerTypeProperty, CheckCompilerTypePropertyFromCompiledModel) {
+ std::string platform = ov::test::utils::getTestsPlatformFromEnvironmentOr(deviceName);
+ size_t pos0 = platform.find("5010");
+ size_t pos1 = platform.find("4000");
+ ov::Core core;
+
+ ov::CompiledModel compiled_model;
+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, deviceName));
+ auto compiler_type = compiled_model.get_property(ov::intel_npu::compiler_type);
+
+ if (pos0 != std::string::npos || pos1 != std::string::npos) {
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::PLUGIN);
+ } else {
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::DRIVER);
+ }
+
+ OV_ASSERT_NO_THROW(
+ compiled_model =
+ core.compile_model(model, deviceName, {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)}));
+ compiler_type = compiled_model.get_property(ov::intel_npu::compiler_type);
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::DRIVER);
+
+ if (pos0 != std::string::npos || pos1 != std::string::npos) {
+ OV_ASSERT_NO_THROW(compiled_model =
+ core.compile_model(model,
+ deviceName,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN)}));
+ compiler_type = compiled_model.get_property(ov::intel_npu::compiler_type);
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::PLUGIN);
+ }
+}
+
+TEST_P(CheckCompilerTypeProperty, CheckCompilerTypePropertyAfterSettingExtraConfigToGetProperty) {
+ std::string platform = ov::test::utils::getTestsPlatformFromEnvironmentOr(deviceName);
+ size_t pos0 = platform.find("5010");
+ size_t pos1 = platform.find("4000");
+ ov::Core core;
+
+ auto test_custom_compiler_type =
+ core.get_property(deviceName,
+ ov::intel_npu::compiler_type,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)});
+ ASSERT_TRUE(test_custom_compiler_type == ov::intel_npu::CompilerType::DRIVER);
+
+ test_custom_compiler_type = core.get_property(deviceName, ov::intel_npu::compiler_type);
+ if (pos0 != std::string::npos || pos1 != std::string::npos) {
+ ASSERT_TRUE(test_custom_compiler_type == ov::intel_npu::CompilerType::PREFER_PLUGIN);
+ } else {
+ ASSERT_TRUE(test_custom_compiler_type == ov::intel_npu::CompilerType::DRIVER);
+ }
+
+ ov::CompiledModel compiled_model;
+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, deviceName));
+ auto compiler_type = compiled_model.get_property(ov::intel_npu::compiler_type);
+
+ if (pos0 != std::string::npos || pos1 != std::string::npos) {
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::PLUGIN);
+ } else {
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::DRIVER);
+ }
+}
+
+TEST_P(CheckCompilerTypeProperty, CheckLogAfterSettingExtraConfigToGetProperty) {
+ std::string logs;
+ std::mutex logs_mutex;
+ ov::Core core;
+
+ // Keep this std::function alive while logging is active.
+ std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
+ std::lock_guard<std::mutex> lock(logs_mutex);
+ logs.append(msg);
+ logs.push_back('\n');
+ };
+
+ core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN));
+
+ ov::util::set_log_callback(log_cb);
+ auto compiler_type = core.get_property(
+ deviceName,
+ ov::intel_npu::compiler_type,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), ov::intel_npu::qdq_optimization(true)});
+ ov::util::reset_log_callback();
+
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::DRIVER);
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ compiler_type = core.get_property(deviceName, ov::intel_npu::compiler_type);
+ ASSERT_TRUE(compiler_type == ov::intel_npu::CompilerType::PLUGIN);
+}
+
+TEST_P(CheckCompilerTypeProperty, CheckLogAfterGettingPropertyWithExtraConfig) {
+ std::string logs;
+ std::mutex logs_mutex;
+ ov::Core core;
+
+ core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
+
+ // Keep this std::function alive while logging is active.
+ std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
+ std::lock_guard<std::mutex> lock(logs_mutex);
+ logs.append(msg);
+ logs.push_back('\n');
+ };
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.get_property(deviceName,
+ ov::intel_npu::defer_weights_load,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)}));
+ ov::util::reset_log_callback();
+
+ ASSERT_EQ(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.get_property(
+ deviceName,
+ ov::intel_npu::defer_weights_load,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER), ov::intel_npu::qdq_optimization(true)}));
+ ov::util::reset_log_callback();
+
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+}
+
+TEST_P(CheckCompilerTypeProperty, SetRuntimeProperty) {
+ std::string logs;
+ std::mutex logs_mutex;
+ ov::Core core;
+
+ core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
+
+ // Keep this std::function alive while logging is active.
+ std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
+ std::lock_guard<std::mutex> lock(logs_mutex);
+ logs.append(msg);
+ logs.push_back('\n');
+ };
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)));
+ OV_ASSERT_NO_THROW(core.get_property(deviceName, ov::intel_npu::defer_weights_load));
+ ov::util::reset_log_callback();
+
+ ASSERT_EQ(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::intel_npu::qdq_optimization(true)));
+ ov::util::reset_log_callback();
+
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+}
+
+TEST_P(CheckCompilerTypeProperty, SetCompilerPropertyForDifferentCompiler) {
+ std::string logs;
+ std::mutex logs_mutex;
+ ov::Core core;
+
+ core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
+
+ // Keep this std::function alive while logging is active.
+ std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
+ std::lock_guard<std::mutex> lock(logs_mutex);
+ logs.append(msg);
+ logs.push_back('\n');
+ };
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)));
+ OV_ASSERT_NO_THROW(core.get_property(deviceName, ov::intel_npu::defer_weights_load));
+ ov::util::reset_log_callback();
+ ASSERT_EQ(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::intel_npu::qdq_optimization(true)));
+ ov::util::reset_log_callback();
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN)));
+ ov::util::reset_log_callback();
+ ASSERT_EQ(logs.find("initialize PluginCompilerAdapter start"), std::string::npos);
+ ASSERT_EQ(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.set_property(deviceName, ov::intel_npu::qdq_optimization(true)));
+ ov::util::reset_log_callback();
+ ASSERT_NE(logs.find("initialize PluginCompilerAdapter start"), std::string::npos);
+}
+
+TEST_P(CheckCompilerTypeProperty, GetCompilerVersion) {
+ std::string logs;
+ std::mutex logs_mutex;
+ ov::Core core;
+
+ core.set_property(deviceName, ov::log::level(ov::log::Level::INFO));
+
+ // Keep this std::function alive while logging is active.
+ std::function<void(std::string_view)> log_cb = [&](std::string_view msg) {
+ std::lock_guard<std::mutex> lock(logs_mutex);
+ logs.append(msg);
+ logs.push_back('\n');
+ };
+
+ OV_ASSERT_NO_THROW(
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)));
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.get_property(deviceName, ov::intel_npu::compiler_version));
+ ov::util::reset_log_callback();
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+ ASSERT_EQ(logs.find("initialize PluginCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ OV_ASSERT_NO_THROW(
+ core.set_property(deviceName, ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::PLUGIN)));
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.get_property(deviceName, ov::intel_npu::compiler_version));
+ ov::util::reset_log_callback();
+ ASSERT_EQ(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+ ASSERT_NE(logs.find("initialize PluginCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
+
+ ov::util::set_log_callback(log_cb);
+ OV_ASSERT_NO_THROW(core.get_property(deviceName,
+ ov::intel_npu::compiler_version,
+ {ov::intel_npu::compiler_type(ov::intel_npu::CompilerType::DRIVER)}));
+ ov::util::reset_log_callback();
+ ASSERT_NE(logs.find("initialize DriverCompilerAdapter start"), std::string::npos);
+ ASSERT_EQ(logs.find("initialize PluginCompilerAdapter start"), std::string::npos);
+
+ logs.clear();
}
} // namespace
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
index 2e9a8b60e99..8748342beac 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
@@ -2,17 +2,18 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include "test_engine/models/find_model.hpp"
-#include "test_engine/comparators/nrmse.hpp"
-#include "test_engine/simple_llm_pipeline.hpp"
-#include "intel_npu/npuw_private_properties.hpp"
-#include "openvino/util/shared_object.hpp"
-#include "openvino/util/file_util.hpp"
+#include <gtest/gtest.h>
-#include <filesystem>
#include <algorithm>
+#include <filesystem>
-#include <gtest/gtest.h>
+#include "functional_test_utils/skip_tests_config.hpp"
+#include "intel_npu/npuw_private_properties.hpp"
+#include "openvino/util/file_util.hpp"
+#include "openvino/util/shared_object.hpp"
+#include "test_engine/comparators/nrmse.hpp"
+#include "test_engine/models/find_model.hpp"
+#include "test_engine/simple_llm_pipeline.hpp"
using namespace testing;
using namespace ov::npuw::tests;
@@ -41,7 +42,8 @@ using LLMTestParams = std::tuple<std::string, ov::AnyMap, GroundTruth>;
class LLMSmokeAccuracyTestsNPUW : public ::testing::TestWithParam<LLMTestParams> {
public:
- void SetUp() override {
+ void SetUp() override {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
// NOTE: TEMPLATE plugin in OpenVINO works for ~20 minute to generate
// first token from prefill model and crashes on launch of
// 3rd subrequest in generate model.