Skip to content

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

[NPU] Disable idle pruning if property is set (#33364)

Bogdan Pereanu657d60ad1d32
diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst
index e9fe925e535..fc9fac1032b 100644
--- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst
+++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/npu-device.rst
@@ -152,6 +152,7 @@ offer a limited set of supported OpenVINO features.
ov::intel_npu::bypass_umd_caching
ov::intel_npu::defer_weights_load
ov::intel_npu::run_inferences_sequentially
+ ov::intel_npu::disable_idle_memory_prunning
.. tab-item:: Read-only properties
diff --git a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
index 6d952406ef7..6385ca94ce4 100644
--- a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
+++ b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
@@ -351,4 +351,5 @@ void regmodule_properties(py::module m) {
wrap_property_RW(m_intel_npu, ov::intel_npu::qdq_optimization, "qdq_optimization");
wrap_property_RW(m_intel_npu, ov::intel_npu::qdq_optimization_aggressive, "qdq_optimization_aggressive");
wrap_property_RW(m_intel_npu, ov::intel_npu::run_inferences_sequentially, "run_inferences_sequentially");
+ wrap_property_RW(m_intel_npu, ov::intel_npu::disable_idle_memory_prunning, "disable_idle_memory_prunning");
}
diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py
index 3bb30b00496..75f961df991 100644
--- a/src/bindings/python/tests/test_runtime/test_properties.py
+++ b/src/bindings/python/tests/test_runtime/test_properties.py
@@ -496,6 +496,11 @@ def test_properties_ro(ov_property_ro, expected_value):
"NPU_QDQ_OPTIMIZATION_AGGRESSIVE",
((True, True),),
),
+ (
+ intel_npu.disable_idle_memory_prunning,
+ "NPU_DISABLE_IDLE_MEMORY_PRUNING",
+ ((True, True),),
+ ),
(props.enable_weightless, "ENABLE_WEIGHTLESS", ((True, True), (False, False))),
],
)
diff --git a/src/inference/include/openvino/runtime/intel_npu/properties.hpp b/src/inference/include/openvino/runtime/intel_npu/properties.hpp
index 5b38e7d9fc5..b73b627864f 100644
--- a/src/inference/include/openvino/runtime/intel_npu/properties.hpp
+++ b/src/inference/include/openvino/runtime/intel_npu/properties.hpp
@@ -148,5 +148,13 @@ static constexpr ov::Property<bool> defer_weights_load{"NPU_DEFER_WEIGHTS_LOAD"}
*/
static constexpr ov::Property<bool> run_inferences_sequentially{"NPU_RUN_INFERENCES_SEQUENTIALLY"};
+/**
+ * @brief [Only for NPU Plugin]
+ * Type: boolean, default is false.
+ * This option allows to disable pruning of memory during idle time.
+ * @ingroup ov_runtime_npu_prop_cpp_api
+ */
+static constexpr ov::Property<bool> disable_idle_memory_prunning{"NPU_DISABLE_IDLE_MEMORY_PRUNING"};
+
} // namespace intel_npu
} // namespace ov
diff --git a/src/plugins/intel_npu/README.md b/src/plugins/intel_npu/README.md
index 007a24eab21..bec3c830b31 100644
--- a/src/plugins/intel_npu/README.md
+++ b/src/plugins/intel_npu/README.md
@@ -207,6 +207,7 @@ The following properties are supported (may differ based on current system confi
| `ov::intel_npu::bypass_umd_caching`/</br>`NPU_BYPASS_UMD_CACHING` | RW | Bypass the caching of compiled models in UMD. | `YES`/ `NO`| `NO` |
| `ov::intel_npu::defer_weights_load`/</br>`NPU_DEFER_WEIGHTS_LOAD` | RW | Delay loading the weights until inference is created. | `YES`/ `NO`| `NO` |
| `ov::intel_npu::run_inferences_sequentially`/</br>`NPU_RUN_INFERENCES_SEQUENTIALLY` | RW | Run inferences in async mode sequentially in the order in which they are started to optimize host scheduling. | `YES`/ `NO`| `NO` |
+| `ov::intel_npu::disable_idle_memory_prunning`/</br>`NPU_DISABLE_IDLE_MEMORY_PRUNING` | RW | Enable/Disable pruning of memory during idle time. | `YES` / `NO` | `NO` |
<br>
### Compiled_model properties VS Plugin properties
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
index 297cf7208e0..b87934d88a2 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
@@ -1491,4 +1491,22 @@ struct ENABLE_STRIDES_FOR final : OptionBase<ENABLE_STRIDES_FOR, std::string> {
}
};
+struct DISABLE_IDLE_MEMORY_PRUNING final : OptionBase<DISABLE_IDLE_MEMORY_PRUNING, bool> {
+ static std::string_view key() {
+ return ov::intel_npu::disable_idle_memory_prunning.name();
+ }
+
+ static bool defaultValue() {
+ return false;
+ }
+
+ static OptionMode mode() {
+ return OptionMode::RunTime;
+ }
+
+ static bool isPublic() {
+ return true;
+ }
+};
+
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
index ccf174a0557..7123da62a29 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
@@ -28,10 +28,11 @@ public:
bool isCommandQueueExtSupported() const override;
bool isLUIDExtSupported() const override;
+ bool isContextExtSupported() const override;
void* getContext() const override;
- void updateInfo(const Config& config) override;
+ void updateInfo(const ov::AnyMap& properties) override;
const std::shared_ptr<ZeroInitStructsHolder> getInitStructs() const override;
diff --git a/src/plugins/intel_npu/src/backend/include/zero_device.hpp b/src/plugins/intel_npu/src/backend/include/zero_device.hpp
index 97d1107dad2..ca4787274bd 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_device.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_device.hpp
@@ -34,9 +34,8 @@ public:
std::shared_ptr<SyncInferRequest> createInferRequest(const std::shared_ptr<const ICompiledModel>& compiledModel,
const Config& config) override;
- void updateInfo(const Config& config) override {
- log.setLevel(config.get<LOG_LEVEL>());
- }
+
+ void updateInfo(const ov::AnyMap& properties) override;
ZeroDevice& operator=(const ZeroDevice&) = delete;
ZeroDevice(const ZeroDevice&) = delete;
@@ -46,18 +45,15 @@ public:
private:
const std::shared_ptr<ZeroInitStructsHolder> _initStructs;
- ze_device_properties_t device_properties = {};
-
- ze_pci_ext_properties_t pci_properties = {};
-
- ze_device_luid_ext_properties_t device_luid = {};
-
- std::map<ov::element::Type, float> device_gops = {{ov::element::f32, 0.f},
- {ov::element::f16, 0.f},
- {ov::element::bf16, 0.f},
- {ov::element::u8, 0.f},
- {ov::element::i8, 0.f}};
+ ze_device_properties_t _device_properties = {};
+ ze_pci_ext_properties_t _pci_properties = {};
+ ze_device_luid_ext_properties_t _device_luid = {};
+ std::map<ov::element::Type, float> _device_gops = {{ov::element::f32, 0.f},
+ {ov::element::f16, 0.f},
+ {ov::element::bf16, 0.f},
+ {ov::element::u8, 0.f},
+ {ov::element::i8, 0.f}};
- Logger log;
+ Logger _log;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
index 79b0e510a8d..87d73853898 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
@@ -37,6 +37,10 @@ bool ZeroEngineBackend::isLUIDExtSupported() const {
return _initStruct->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0));
}
+bool ZeroEngineBackend::isContextExtSupported() const {
+ return _initStruct->isExtensionSupported(std::string(ZE_CONTEXT_NPU_EXT_NAME), ZE_MAKE_VERSION(1, 0));
+}
+
const std::shared_ptr<IDevice> ZeroEngineBackend::getDevice() const {
if (_devices.empty()) {
_logger.debug("ZeroEngineBackend - getDevice() returning empty list");
@@ -130,11 +134,22 @@ void* ZeroEngineBackend::getContext() const {
return _initStruct->getContext();
}
-void ZeroEngineBackend::updateInfo(const Config& config) {
- _logger.setLevel(config.get<LOG_LEVEL>());
+void ZeroEngineBackend::updateInfo(const ov::AnyMap& properties) {
+ if (properties.count(ov::log::level.name()) != 0) {
+ _logger.setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
+ }
+
+ if (properties.count(ov::intel_npu::disable_idle_memory_prunning.name()) != 0) {
+ if (properties.at(ov::intel_npu::disable_idle_memory_prunning.name()).as<bool>()) {
+ _initStruct->clearContextOptions(ZE_NPU_CONTEXT_OPTION_IDLE_OPTIMIZATIONS);
+ } else {
+ _initStruct->setContextOptions(ZE_NPU_CONTEXT_OPTION_IDLE_OPTIMIZATIONS);
+ }
+ }
+
if (_devices.size() > 0) {
for (auto& dev : _devices) {
- dev.second->updateInfo(config);
+ dev.second->updateInfo(properties);
}
}
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_device.cpp b/src/plugins/intel_npu/src/backend/src/zero_device.cpp
index dbbeb201d85..cb44ec14206 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_device.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_device.cpp
@@ -13,35 +13,35 @@ using namespace intel_npu;
ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs)
: _initStructs(initStructs),
- log("ZeroDevice", Logger::global().level()) {
- log.debug("ZeroDevice::ZeroDevice init");
- device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
+ _log("ZeroDevice", Logger::global().level()) {
+ _log.debug("ZeroDevice::ZeroDevice init");
+ _device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
// Get LUID info, if supported
if (_initStructs->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0))) {
- device_luid.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
- device_properties.pNext = &device_luid;
+ _device_luid.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;
+ _device_properties.pNext = &_device_luid;
}
THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGetProperties",
- zeDeviceGetProperties(_initStructs->getDevice(), &device_properties));
+ zeDeviceGetProperties(_initStructs->getDevice(), &_device_properties));
// Query PCI information
// Older drivers do not have this implementend. Linux driver returns NOT_IMPLEMENTED, while windows driver returns
// zero values. If this is detected, we populate only device with ID from device_properties for backwards
// compatibility. For any other error, we just fall-back to device ID to assure backwards compatibilty with even
// older drivers
- pci_properties.stype = ZE_STRUCTURE_TYPE_PCI_EXT_PROPERTIES;
- ze_result_t retpci = zeDevicePciGetPropertiesExt(_initStructs->getDevice(), &pci_properties);
+ _pci_properties.stype = ZE_STRUCTURE_TYPE_PCI_EXT_PROPERTIES;
+ ze_result_t retpci = zeDevicePciGetPropertiesExt(_initStructs->getDevice(), &_pci_properties);
if (ZE_RESULT_SUCCESS == retpci) {
// windows driver specific backwards compatibility
- if (pci_properties.address.device == 0) {
- log.warning("PCI information not available in driver. Falling back to deviceId");
- pci_properties.address.device = device_properties.deviceId;
+ if (_pci_properties.address.device == 0) {
+ _log.warning("PCI information not available in driver. Falling back to deviceId");
+ _pci_properties.address.device = _device_properties.deviceId;
}
} else {
// general backwards compatibility
- log.warning("PCI information not available in driver. Falling back to deviceId");
- pci_properties.address.device = device_properties.deviceId;
+ _log.warning("PCI information not available in driver. Falling back to deviceId");
+ _pci_properties.address.device = _device_properties.deviceId;
}
/// Calculate and store device GOPS with formula: frequency * number of tiles * ops per tile
@@ -53,12 +53,12 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs
gops_support_drv_version = 1715354569; /// Linux driver version which supports Gops calculations
#endif // _WIN32 || __CYGWIN__
if (_initStructs->getDriverVersion() >= gops_support_drv_version) {
- float gops = (device_properties.coreClockRate / powf(1000, 3)) * device_properties.numSlices *
- device_properties.physicalEUSimdWidth;
- device_gops[ov::element::f32] = 0;
- device_gops[ov::element::u8] = gops;
- device_gops[ov::element::i8] = gops;
- device_gops[ov::element::f16] = 0.5f * gops;
+ float gops = (_device_properties.coreClockRate / powf(1000, 3)) * _device_properties.numSlices *
+ _device_properties.physicalEUSimdWidth;
+ _device_gops[ov::element::f32] = 0;
+ _device_gops[ov::element::u8] = gops;
+ _device_gops[ov::element::i8] = gops;
+ _device_gops[ov::element::f16] = 0.5f * gops;
}
}
@@ -69,7 +69,7 @@ std::string ZeroDevice::getName() const {
#define NPU_4000_DEVICE_ID 0x643E
std::string name;
- switch (device_properties.deviceId) {
+ switch (_device_properties.deviceId) {
case NPU_3720_P_DEVICE_ID:
case NPU_3720_S_DEVICE_ID:
name = ov::intel_npu::Platform::NPU3720;
@@ -85,15 +85,15 @@ std::string ZeroDevice::getName() const {
}
std::string ZeroDevice::getFullDeviceName() const {
- return device_properties.name;
+ return _device_properties.name;
}
IDevice::Uuid ZeroDevice::getUuid() const {
Uuid uuid{};
- static_assert(sizeof(device_properties.uuid.id) == uuid.uuid.size(),
+ static_assert(sizeof(_device_properties.uuid.id) == uuid.uuid.size(),
"ze_device_uuid_t::id size doesn't match intel_npu::Uuid::uuid size");
- std::copy(std::begin(device_properties.uuid.id), std::end(device_properties.uuid.id), std::begin(uuid.uuid));
+ std::copy(std::begin(_device_properties.uuid.id), std::end(_device_properties.uuid.id), std::begin(uuid.uuid));
return uuid;
}
@@ -103,17 +103,17 @@ ov::device::LUID ZeroDevice::getLUID() const {
// incompatibility check
static_assert(ZE_MAX_DEVICE_LUID_SIZE_EXT == ov::device::LUID::MAX_LUID_SIZE, "LUID size mismatch");
for (int i = 0; i < ZE_MAX_DEVICE_LUID_SIZE_EXT; i++) {
- luidstruct.luid[i] = device_luid.luid.id[i];
+ luidstruct.luid[i] = _device_luid.luid.id[i];
}
return luidstruct;
}
uint32_t ZeroDevice::getSubDevId() const {
- return device_properties.subdeviceId;
+ return _device_properties.subdeviceId;
}
uint32_t ZeroDevice::getMaxNumSlices() const {
- return device_properties.numSlices;
+ return _device_properties.numSlices;
}
uint64_t ZeroDevice::getAllocMemSize() const {
@@ -155,14 +155,14 @@ uint64_t ZeroDevice::getTotalMemSize() const {
}
ov::device::PCIInfo ZeroDevice::getPciInfo() const {
- return ov::device::PCIInfo{pci_properties.address.domain,
- pci_properties.address.bus,
- pci_properties.address.device,
- pci_properties.address.function};
+ return ov::device::PCIInfo{_pci_properties.address.domain,
+ _pci_properties.address.bus,
+ _pci_properties.address.device,
+ _pci_properties.address.function};
}
std::map<ov::element::Type, float> ZeroDevice::getGops() const {
- return device_gops;
+ return _device_gops;
}
ov::device::Type ZeroDevice::getDeviceType() const {
@@ -174,3 +174,9 @@ std::shared_ptr<SyncInferRequest> ZeroDevice::createInferRequest(
const Config& config) {
return std::make_shared<ZeroInferRequest>(_initStructs, compiledModel, config);
}
+
+void ZeroDevice::updateInfo(const ov::AnyMap& properties) {
+ if (properties.count(ov::log::level.name()) != 0) {
+ _log.setLevel(properties.at(ov::log::level.name()).as<ov::log::Level>());
+ }
+}
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
index 6b8d29c4fbc..d09b9a5d362 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp
@@ -38,12 +38,14 @@ public:
virtual bool isCommandQueueExtSupported() const = 0;
/** @brief Backend has support for LUID info */
virtual bool isLUIDExtSupported() const = 0;
+ /** @brief Backend has support for npu context dditable ext */
+ virtual bool isContextExtSupported() const = 0;
/** @brief Register backend-specific options */
virtual void registerOptions(OptionsDesc& options) const;
/** @brief Get Level Zero context*/
virtual void* getContext() const;
/** @brief Update backend and device info */
- virtual void updateInfo(const Config& config) = 0;
+ virtual void updateInfo(const ov::AnyMap& properties) = 0;
/** @brief Get LevelZero structures */
virtual const std::shared_ptr<ZeroInitStructsHolder> getInitStructs() const;
@@ -75,7 +77,7 @@ public:
const std::shared_ptr<const ICompiledModel>& compiledModel,
const Config& config) = 0;
- virtual void updateInfo(const Config& config) = 0;
+ virtual void updateInfo(const ov::AnyMap& properties) = 0;
protected:
virtual ~IDevice() = default;
diff --git a/src/plugins/intel_npu/src/plugin/include/plugin.hpp b/src/plugins/intel_npu/src/plugin/include/plugin.hpp
index 72f4cac9c3f..0e3a30cc5d8 100644
--- a/src/plugins/intel_npu/src/plugin/include/plugin.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/plugin.hpp
@@ -69,7 +69,7 @@ private:
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 std::map<std::string, std::string>& rawConfig,
+ FilteredConfig fork_local_config(const ov::AnyMap& properties,
const std::unique_ptr<ICompilerAdapter>& compiler,
OptionMode mode = OptionMode::Both) const;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 48d07358925..119572caf71 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -134,13 +134,9 @@ std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
return result;
}
-void update_log_level(const std::map<std::string, std::string>& propertiesMap) {
- auto it = propertiesMap.find(std::string(LOG_LEVEL::key()));
- if (it != propertiesMap.end()) {
- std::istringstream is(it->second);
- ov::log::Level level;
- is >> level;
- Logger::global().setLevel(level);
+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>());
}
}
@@ -330,6 +326,9 @@ void Plugin::init_options() {
if (_backend->isCommandQueueExtSupported()) {
REGISTER_OPTION(WORKLOAD_TYPE);
}
+ if (_backend->isContextExtSupported()) {
+ REGISTER_OPTION(DISABLE_IDLE_MEMORY_PRUNING);
+ }
// register backend options
_backend->registerOptions(*_options);
}
@@ -508,10 +507,15 @@ void Plugin::filter_global_config_safe(const std::optional<ov::intel_npu::Compil
}
}
-FilteredConfig Plugin::fork_local_config(const std::map<std::string, std::string>& rawConfig,
+FilteredConfig Plugin::fork_local_config(const ov::AnyMap& properties,
const std::unique_ptr<ICompilerAdapter>& compiler,
OptionMode mode) const {
- update_log_level(rawConfig);
+ 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
@@ -521,6 +525,8 @@ FilteredConfig Plugin::fork_local_config(const std::map<std::string, std::string
}
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()));
@@ -606,12 +612,12 @@ void Plugin::set_property(const ov::AnyMap& properties) {
// 4. Extra hooks
// Update log level if it was provided
- if (properties.count(std::string(LOG_LEVEL::key())) != 0) {
+ if (properties.count(ov::log::level.name()) != 0) {
Logger::global().setLevel(_globalConfig.get<LOG_LEVEL>());
}
// Init backends if needed
if (_backend != nullptr) {
- _backend->updateInfo(_globalConfig);
+ _backend->updateInfo(properties);
}
}
@@ -669,15 +675,14 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
localProperties.erase(modelSerializerVersionKey);
}
- const std::map<std::string, std::string> localPropertiesMap = any_copy(localProperties);
- update_log_level(localPropertiesMap);
+ update_log_level(localProperties);
// create compiler
CompilerAdapterFactory compilerAdapterFactory;
auto compiler = compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, properties));
OV_ITT_TASK_CHAIN(PLUGIN_COMPILE_MODEL, itt::domains::NPUPlugin, "Plugin::compile_model", "fork_local_config");
- auto localConfig = fork_local_config(localPropertiesMap, compiler);
+ auto localConfig = fork_local_config(localProperties, compiler);
const auto setCacheDir = localConfig.get<CACHE_DIR>();
if (!setCacheDir.empty()) {
@@ -1035,11 +1040,10 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
npu_plugin_properties.erase(modelSerializerVersionKey);
}
exclude_model_ptr_from_map(npu_plugin_properties);
- const std::map<std::string, std::string> propertiesMap = any_copy(npu_plugin_properties);
- update_log_level(propertiesMap);
+ update_log_level(npu_plugin_properties);
auto compiler =
compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, npu_plugin_properties));
- auto localConfig = fork_local_config(propertiesMap, compiler, OptionMode::CompileTime);
+ auto localConfig = fork_local_config(npu_plugin_properties, compiler, OptionMode::CompileTime);
_logger.setLevel(localConfig.get<LOG_LEVEL>());
const auto platform =
utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
@@ -1096,13 +1100,12 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig,
auto originalModel = exclude_model_ptr_from_map(npu_plugin_properties);
CompilerAdapterFactory compilerAdapterFactory;
- const auto propertiesMap = any_copy(npu_plugin_properties);
- update_log_level(propertiesMap);
+ update_log_level(npu_plugin_properties);
auto compiler =
compilerAdapterFactory.getCompiler(_backend, resolveCompilerType(_globalConfig, npu_plugin_properties));
OV_ITT_TASK_CHAIN(PLUGIN_PARSE_MODEL, itt::domains::NPUPlugin, "Plugin::parse", "fork_local_config");
- auto localConfig = fork_local_config(propertiesMap, compiler, OptionMode::RunTime);
+ auto localConfig = fork_local_config(npu_plugin_properties, compiler, OptionMode::RunTime);
_logger.setLevel(localConfig.get<LOG_LEVEL>());
const auto platform =
utils::getCompilationPlatform(localConfig.get<PLATFORM>(),
diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cpp
index ade86fb10c6..3df1201063b 100644
--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp
@@ -389,6 +389,7 @@ void Properties::registerPluginProperties() {
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::use_base_model_serializer, USE_BASE_MODEL_SERIALIZER);
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::model_serializer_version, MODEL_SERIALIZER_VERSION);
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::enable_strides_for, ENABLE_STRIDES_FOR);
+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::disable_idle_memory_prunning, DISABLE_IDLE_MEMORY_PRUNING);
TRY_REGISTER_CUSTOMFUNC_PROPERTY(ov::intel_npu::stepping, STEPPING, [&](const Config& config) {
if (!config.has<STEPPING>()) {
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
index 24478216cbe..96381a47935 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp
@@ -72,6 +72,9 @@ public:
return _external_memory_fd_win32_supported;
}
+ void setContextOptions(const uint32_t options);
+ void clearContextOptions(const uint32_t options);
+
static const std::shared_ptr<ZeroInitStructsHolder> getInstance();
ze_device_graph_properties_t getCompilerProperties();
@@ -81,6 +84,7 @@ public:
private:
void initNpuDriver();
void getExtensionFunctionAddress(const std::string& name, const uint32_t version, void** function_address);
+ void setContextProperties();
// keep zero_api alive until context is destroyed
std::shared_ptr<ZeroApi> _zero_api;
@@ -96,6 +100,7 @@ private:
std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> _command_queue_npu_dditable_ext_decorator;
std::unique_ptr<ze_graph_profiling_dditable_ext_decorator> _graph_profiling_npu_dditable_ext_decorator;
std::unique_ptr<ze_driver_npu_dditable_ext_decorator> _driver_npu_dditable_ext_decorator;
+ std::unique_ptr<ze_context_npu_dditable_ext_decorator> _context_npu_dditable_ext_decorator;
ze_driver_properties_t _driver_properties = {};
uint32_t _mutable_command_list_ext_version = 0;
@@ -107,6 +112,8 @@ private:
bool _external_memory_standard_allocation_supported = false;
bool _external_memory_fd_win32_supported = false;
+ uint32_t _context_options = 0;
+
std::mutex _mutex;
};
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp
index 89f2a003084..2a8da3172f2 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp
@@ -6,6 +6,7 @@
#include <ze_api.h>
#include <ze_command_queue_npu_ext.h>
+#include <ze_context_npu_ext.h>
#include <ze_driver_npu_ext.h>
#include <ze_graph_ext.h>
#include <ze_graph_profiling_ext.h>
@@ -349,7 +350,59 @@ public:
}
};
+/**
+ * @brief Context function wrappers
+ * @details Use function wrappers for function from within higher driver versions in order to throw when loaded driver
+ * is older than required
+ */
+struct ze_context_npu_dditable_ext_decorator final {
+private:
+ ze_context_npu_dditable_ext_t* const _impl;
+ const uint32_t _contextExtVersion;
+
+ ze_context_npu_dditable_ext_decorator(const ze_context_npu_dditable_ext_decorator&) = delete;
+ ze_context_npu_dditable_ext_decorator(ze_context_npu_dditable_ext_decorator&&) = delete;
+
+ ze_context_npu_dditable_ext_decorator& operator=(const ze_context_npu_dditable_ext_decorator&) = delete;
+ ze_context_npu_dditable_ext_decorator& operator=(ze_context_npu_dditable_ext_decorator&&) = delete;
+
+ void throwWhenUnsupported(std::string_view func, uint32_t since) {
+ if (_contextExtVersion < since) {
+ OPENVINO_THROW("Driver Context extension function ",
+ func,
+ " is only available with version ",
+ ZE_MAJOR_VERSION(since),
+ ".",
+ ZE_MINOR_VERSION(since),
+ " or later");
+ }
+ }
+
+public:
+ ze_context_npu_dditable_ext_decorator(ze_context_npu_dditable_ext_t* impl, uint32_t contextExtVersion)
+ : _impl(impl),
+ _contextExtVersion(contextExtVersion) {}
+ ~ze_context_npu_dditable_ext_decorator() = default;
+
+ inline uint32_t version() const {
+ return _contextExtVersion;
+ }
+
+ // version 1.0
+ ze_result_t ZE_APICALL pfnSetProperties(ze_context_handle_t hContext,
+ ze_context_properties_npu_ext_t* contextProperties) {
+ throwWhenUnsupported("pfnSetProperties", ZE_CONTEXT_NPU_EXT_VERSION_1_0);
+ return _impl->pfnSetProperties(hContext, contextProperties);
+ }
+
+ ze_result_t ZE_APICALL pfnReleaseMemory(ze_context_handle_t hContext) {
+ throwWhenUnsupported("pfnReleaseMemory", ZE_CONTEXT_NPU_EXT_VERSION_1_0);
+ return _impl->pfnReleaseMemory(hContext);
+ }
+};
+
using ze_graph_dditable_ext_curr_t = ze_graph_dditable_ext_decorator;
using ze_command_queue_npu_dditable_ext_curr_t = ze_command_queue_npu_dditable_ext_decorator;
using ze_graph_profiling_dditable_ext_curr_t = ze_graph_profiling_dditable_ext_decorator;
using ze_driver_npu_dditable_ext_curr_t = ze_driver_npu_dditable_ext_decorator;
+using ze_context_npu_dditable_ext_curr_t = ze_context_npu_dditable_ext_decorator;
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
index 69c1f58e535..b6816df3fb3 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
@@ -5,6 +5,7 @@
#include "intel_npu/utils/zero/zero_init.hpp"
#include <ze_command_queue_npu_ext.h>
+#include <ze_context_npu_ext.h>
#include <ze_driver_npu_ext.h>
#include <ze_graph_ext.h>
#include <ze_mem_import_system_memory_ext.h>
@@ -22,6 +23,7 @@ constexpr uint32_t TARGET_ZE_DRIVER_NPU_EXT_VERSION = ZE_DRIVER_NPU_EXT_VERSION_
constexpr uint32_t TARGET_ZE_GRAPH_NPU_EXT_VERSION = ZE_GRAPH_EXT_VERSION_1_16;
constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION = ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1;
constexpr uint32_t TARGET_ZE_PROFILING_NPU_EXT_VERSION = ZE_PROFILING_DATA_EXT_VERSION_1_0;
+constexpr uint32_t TARGET_ZE_CONTEXT_NPU_EXT_VERSION = ZE_CONTEXT_NPU_EXT_VERSION_1_0;
constexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1;
constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;
@@ -288,15 +290,15 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
ZE_MINOR_VERSION(command_queue_ext_version));
// Load npu command queue extension
- ze_command_queue_npu_dditable_ext_t* _command_queue_npu_dditable_ext = nullptr;
+ ze_command_queue_npu_dditable_ext_t* command_queue_npu_dditable_ext = nullptr;
if (command_queue_ext_version) {
getExtensionFunctionAddress(command_queue_ext_name,
command_queue_ext_version,
- reinterpret_cast<void**>(&_command_queue_npu_dditable_ext));
+ reinterpret_cast<void**>(&command_queue_npu_dditable_ext));
}
_command_queue_npu_dditable_ext_decorator =
- std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(_command_queue_npu_dditable_ext,
+ std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(command_queue_npu_dditable_ext,
command_queue_ext_version);
// Query the mutable command list version
@@ -325,13 +327,34 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
queryDriverExtensionVersion(ZE_PROFILING_DATA_EXT_NAME, TARGET_ZE_PROFILING_NPU_EXT_VERSION, extProps, count);
// Load npu profiling extension
- ze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;
+ ze_graph_profiling_dditable_ext_t* graph_profiling_ddi_table_ext = nullptr;
getExtensionFunctionAddress(profiling_ext_name,
profiling_ext_version,
- reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext));
+ reinterpret_cast<void**>(&graph_profiling_ddi_table_ext));
_graph_profiling_npu_dditable_ext_decorator =
- std::make_unique<ze_graph_profiling_dditable_ext_decorator>(_graph_profiling_ddi_table_ext);
+ std::make_unique<ze_graph_profiling_dditable_ext_decorator>(graph_profiling_ddi_table_ext);
+
+ // Query npu context extension version
+ std::string context_ext_name;
+ uint32_t context_ext_version = 0;
+ std::tie(context_ext_version, context_ext_name) =
+ queryDriverExtensionVersion(ZE_CONTEXT_NPU_EXT_NAME, TARGET_ZE_CONTEXT_NPU_EXT_VERSION, extProps, count);
+
+ _log.debug("NPU context version %d.%d",
+ ZE_MAJOR_VERSION(context_ext_version),
+ ZE_MINOR_VERSION(context_ext_version));
+
+ // Load npu command queue extension
+ ze_context_npu_dditable_ext_t* context_npu_dditable_ext = nullptr;
+ if (context_ext_version) {
+ getExtensionFunctionAddress(context_ext_name,
+ context_ext_version,
+ reinterpret_cast<void**>(&context_npu_dditable_ext));
+ }
+
+ _context_npu_dditable_ext_decorator =
+ std::make_unique<ze_context_npu_dditable_ext_decorator>(context_npu_dditable_ext, context_ext_version);
uint32_t device_count = 1;
// Get npu target device
@@ -417,6 +440,25 @@ void ZeroInitStructsHolder::getExtensionFunctionAddress(const std::string& name,
}
}
+void ZeroInitStructsHolder::setContextProperties() {
+ ze_context_properties_npu_ext_t context_properties_npu_ext = {ZE_STRUCTURE_TYPE_CONTEXT_PROPERTIES_NPU_EXT,
+ nullptr,
+ _context_options};
+ _context_npu_dditable_ext_decorator->pfnSetProperties(_context, &context_properties_npu_ext);
+}
+
+void ZeroInitStructsHolder::clearContextOptions(const uint32_t options) {
+ std::lock_guard<std::mutex> lock(_mutex);
+ _context_options &= ~options;
+ setContextProperties();
+}
+
+void ZeroInitStructsHolder::setContextOptions(const uint32_t options) {
+ std::lock_guard<std::mutex> lock(_mutex);
+ _context_options |= options;
+ setContextProperties();
+}
+
ZeroInitStructsHolder::~ZeroInitStructsHolder() {
if (_context) {
_log.debug("ZeroInitStructsHolder - performing zeContextDestroy");
diff --git a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp
index 78f058a32bf..ba7c514118e 100644
--- a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp
+++ b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp
@@ -5,6 +5,7 @@
#include "zero_init_mock.hpp"
#include <ze_command_queue_npu_ext.h>
+#include <ze_context_npu_ext.h>
#include <ze_driver_npu_ext.h>
#include <ze_graph_ext.h>
#include <ze_mem_import_system_memory_ext.h>
@@ -16,6 +17,7 @@ namespace {
constexpr uint32_t TARGET_ZE_DRIVER_NPU_EXT_VERSION = ZE_DRIVER_NPU_EXT_VERSION_1_0;
constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION = ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1;
constexpr uint32_t TARGET_ZE_PROFILING_NPU_EXT_VERSION = ZE_PROFILING_DATA_EXT_VERSION_1_0;
+constexpr uint32_t TARGET_ZE_CONTEXT_NPU_EXT_VERSION = ZE_CONTEXT_NPU_EXT_VERSION_1_0;
constexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1;
constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;
@@ -262,15 +264,15 @@ ZeroInitStructsMock::ZeroInitStructsMock(int extVersion)
ZE_MINOR_VERSION(command_queue_ext_version));
// Load npu command queue extension
- ze_command_queue_npu_dditable_ext_t* _command_queue_npu_dditable_ext = nullptr;
+ ze_command_queue_npu_dditable_ext_t* command_queue_npu_dditable_ext = nullptr;
if (command_queue_ext_version) {
getExtensionFunctionAddress(command_queue_ext_name,
command_queue_ext_version,
- reinterpret_cast<void**>(&_command_queue_npu_dditable_ext));
+ reinterpret_cast<void**>(&command_queue_npu_dditable_ext));
}
_command_queue_npu_dditable_ext_decorator =
- std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(_command_queue_npu_dditable_ext,
+ std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(command_queue_npu_dditable_ext,
command_queue_ext_version);
// Query the mutable command list version
@@ -292,13 +294,34 @@ ZeroInitStructsMock::ZeroInitStructsMock(int extVersion)
queryDriverExtensionVersion(ZE_PROFILING_DATA_EXT_NAME, TARGET_ZE_PROFILING_NPU_EXT_VERSION, extProps, count);
// Load npu profiling extension
- ze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;
+ ze_graph_profiling_dditable_ext_t* graph_profiling_ddi_table_ext = nullptr;
getExtensionFunctionAddress(profiling_ext_name,
profiling_ext_version,
- reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext));
+ reinterpret_cast<void**>(&graph_profiling_ddi_table_ext));
_graph_profiling_npu_dditable_ext_decorator =
- std::make_unique<ze_graph_profiling_dditable_ext_decorator>(_graph_profiling_ddi_table_ext);
+ std::make_unique<ze_graph_profiling_dditable_ext_decorator>(graph_profiling_ddi_table_ext);
+
+ // Query npu context extension version
+ std::string context_ext_name;
+ uint32_t context_ext_version = 0;
+ std::tie(context_ext_version, context_ext_name) =
+ queryDriverExtensionVersion(ZE_CONTEXT_NPU_EXT_NAME, TARGET_ZE_CONTEXT_NPU_EXT_VERSION, extProps, count);
+
+ _log.debug("NPU context version %d.%d",
+ ZE_MAJOR_VERSION(context_ext_version),
+ ZE_MINOR_VERSION(context_ext_version));
+
+ // Load npu command queue extension
+ ze_context_npu_dditable_ext_t* context_npu_dditable_ext = nullptr;
+ if (context_ext_version) {
+ getExtensionFunctionAddress(context_ext_name,
+ context_ext_version,
+ reinterpret_cast<void**>(&context_npu_dditable_ext));
+ }
+
+ _context_npu_dditable_ext_decorator =
+ std::make_unique<ze_context_npu_dditable_ext_decorator>(context_npu_dditable_ext, context_ext_version);
uint32_t device_count = 1;
// Get npu target device
diff --git a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp
index bb95fd28227..87f2b2be3c8 100644
--- a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp
+++ b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp
@@ -37,6 +37,7 @@ struct ZeroInitStructsMock {
std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> _command_queue_npu_dditable_ext_decorator;
std::unique_ptr<ze_graph_profiling_dditable_ext_decorator> _graph_profiling_npu_dditable_ext_decorator;
std::unique_ptr<ze_driver_npu_dditable_ext_decorator> _driver_npu_dditable_ext_decorator;
+ std::unique_ptr<ze_context_npu_dditable_ext_decorator> _context_npu_dditable_ext_decorator;
ze_driver_properties_t _driver_properties = {};
uint32_t _mutable_command_list_ext_version = 0;
@@ -48,6 +49,8 @@ struct ZeroInitStructsMock {
bool _external_memory_standard_allocation_supported = false;
bool _external_memory_fd_win32_supported = false;
+ uint32_t _context_options = 0;
+
std::mutex _mutex;
};