Skip to content

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

[NPU] Set the default value to 0 for DEVICE_ID (#38380)

Bogdan Pereanu1a635fd6d97f
diff --git a/src/plugins/intel_npu/README.md b/src/plugins/intel_npu/README.md
index 6a96a0d1050..c7a43830974 100644
--- a/src/plugins/intel_npu/README.md
+++ b/src/plugins/intel_npu/README.md
@@ -221,7 +221,7 @@ The following properties are supported (may differ based on current system confi
| `ov::cache_encryption_callbacks`/</br>`CACHE_ENCRYPTION_CALLBACKS` | WO | Encryption/Decryption functions called when exporting or reading the blob. | ov::EncryptionCallbacks structures populated with any function respecting signature `std::string(const std::string&)` for both encryption and decryption callbacks | ov::EncryptionCallbacks{nullptr, nullptr} |
| `ov::cache_mode`/</br>`CACHE_MODE` | RW | If `CACHE_DIR` has been set, then this option indicates whether or not the size of the compiled model binary object will be reduced by decoupling a portion of the weights. | `OPTIMIZE_SIZE` /</br>`OPTIMIZE_SPEED` | `OPTIMIZE_SPEED` |
| `ov::available_devices`/</br>`AVAILABLE_DEVICES` | RO | Returns the list of enumerated NPU devices. </br> NPU plugin does not currently support multiple devices. | `N/A`| `N/A` |
-| `ov::device::id`/</br>`DEVICE_ID` | RW | Device identifier. Empty means auto detection. | empty/</br> `3720`/</br> `4000`/</br> `5010`/</br> `5020`/</br> `6010` | empty |
+| `ov::device::id`/</br>`DEVICE_ID` | RW | The property for setting the required device to execute on.</br>**Note:** Besides the device index, `DEVICE_ID` also accepts a platform name known by the NPU plugin (e.g. `3720`, `5010`). In that case, the first available device matching that platform is selected.</br>If `NPU_PLATFORM` is also set, `NPU_PLATFORM` takes precedence for compilation, while `DEVICE_ID` is used only to select the device for runtime. | Device ID starts from `0` for the first device, `1` for the second device, and so on. | `0` |
| `ov::device::uuid`/</br> | RO | Returns the Universal Unique ID of the NPU device. | `N/A`| `N/A` |
| `ov::device::architecture`/</br>`DEVICE_ARCHITECTURE` | RO | Returns the platform information. | `N/A`| `N/A` |
| `ov::device::full_name`/</br>`FULL_DEVICE_NAME` | RO | Returns the full name of the NPU device. | `N/A`| `N/A` |
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 22b3d4855fc..b725369ba2f 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
@@ -178,7 +178,7 @@ struct DEVICE_ID final : OptionBase<DEVICE_ID, std::string> {
}
static std::string defaultValue() {
- return {};
+ return "0";
}
static OptionMode mode() {
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 ca7d6eef6e6..8e70c4bda32 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
@@ -16,9 +16,9 @@ namespace utils {
bool isNPUDevice(const uint32_t deviceId);
uint32_t getSliceIdBySwDeviceId(const uint32_t swDevId);
std::string getPlatformByDeviceName(const std::string_view deviceName);
-std::string getCompilationPlatform(const std::string_view platform,
- const std::string_view deviceId,
- std::vector<std::string> availableDevicesNames);
+std::string getCompilationPlatform(const ov::SoPtr<IEngineBackend>& engineBackend,
+ const std::string_view platform,
+ const std::string_view deviceId);
/**
* @brief Gets the device by its ID.
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 594bc325a38..4fd20e2e883 100644
--- a/src/plugins/intel_npu/src/common/src/device_helpers.cpp
+++ b/src/plugins/intel_npu/src/common/src/device_helpers.cpp
@@ -35,9 +35,9 @@ std::string utils::getPlatformByDeviceName(const std::string_view deviceName) {
return std::string(platformName);
}
-std::string utils::getCompilationPlatform(const std::string_view platform,
- const std::string_view deviceId,
- std::vector<std::string> availableDevicesNames) {
+std::string utils::getCompilationPlatform(const ov::SoPtr<IEngineBackend>& engineBackend,
+ const std::string_view platform,
+ const std::string_view deviceId) {
// Platform parameter has a higher priority than deviceID
if (platform != ov::intel_npu::Platform::AUTO_DETECT) {
return ov::intel_npu::Platform::standardize(platform);
@@ -49,6 +49,11 @@ std::string utils::getCompilationPlatform(const std::string_view platform,
}
// Automatic detection of compilation platform
+ if (engineBackend == nullptr) {
+ return std::string();
+ }
+
+ const auto availableDevicesNames = engineBackend->getDeviceNames();
if (availableDevicesNames.empty()) {
return std::string();
}
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp
index f4f68631b9c..ca39abdbfa2 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model_property_manager.cpp
@@ -305,8 +305,8 @@ void CompiledModelPropertyManager::registerProperties() {
[](const ov::AnyMap&) {
return true;
},
- [](const ov::AnyMap&) {
- return ov::Any(std::vector<std::string>{"NPU"});
+ [this](const ov::AnyMap&) {
+ return _device != nullptr ? decltype(ov::execution_devices)::value_type{"NPU.0"} : decltype(ov::execution_devices)::value_type{};
},
readOnlySetter
);
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index a4589516f9f..fd5374c2126 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -266,9 +266,9 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
// 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 ? std::move(deviceId) : device->getName(),
- _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+ utils::getCompilationPlatform(_backend,
+ _propertiesManager->determinePlatform(localProperties),
+ device == nullptr ? std::move(deviceId) : device->getName());
ov::intel_npu::CompilerType compilerType = _propertiesManager->determineCompilerType(localProperties);
CompilerAdapterFactory factory;
@@ -691,9 +691,9 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
std::shared_ptr<IDevice> device = utils::getDeviceById(_backend, deviceId);
const auto compilationPlatform =
- utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),
- device == nullptr ? std::move(deviceId) : device->getName(),
- _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+ utils::getCompilationPlatform(_backend,
+ _propertiesManager->determinePlatform(localProperties),
+ device == nullptr ? std::move(deviceId) : device->getName());
ov::intel_npu::CompilerType compilerType = _propertiesManager->determineCompilerType(localProperties);
CompilerAdapterFactory factory;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp
index c042e5ecc58..3ccb57ebed5 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp
@@ -439,10 +439,8 @@ std::optional<ov::intel_npu::CompilerType> PluginPropertyManager::resolveCompile
try {
auto device = utils::getDeviceById(_backend, deviceId);
- auto compilationPlatform = utils::getCompilationPlatform(
- platform,
- device == nullptr ? deviceId : device->getName(),
- _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+ auto compilationPlatform =
+ utils::getCompilationPlatform(_backend, platform, device == nullptr ? deviceId : device->getName());
CompilerAdapterFactory factory;
factory.decideCompilerType(compilerType, device, compilationPlatform);
@@ -882,9 +880,6 @@ void PluginPropertyManager::registerProperties() {
OPENVINO_THROW("Property is read-only");
};
- register_property(ov::execution_devices.name(), true, ov::PropertyMutability::RO, alwaysSupported, [](const ov::AnyMap&) {
- return std::vector<std::string>{"NPU"};
- }, readOnlySetter);
register_property(ov::device::capabilities.name(), true, ov::PropertyMutability::RO, alwaysSupported, [](const ov::AnyMap&) {
return std::vector<std::string>{ov::device::capability::FP16, ov::device::capability::INT8, ov::device::capability::EXPORT_IMPORT};
}, readOnlySetter);
@@ -1043,9 +1038,10 @@ void PluginPropertyManager::registerProperties() {
auto deviceId = getDeviceId(arguments);
auto device = utils::getDeviceById(_backend, deviceId);
compilationPlatform = utils::getCompilationPlatform(
+ _backend,
platform,
- device == nullptr ? deviceId : device->getName(),
- _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+ device == nullptr ? deviceId : device->getName()
+ );
}
try {
@@ -1065,9 +1061,9 @@ void PluginPropertyManager::registerProperties() {
auto deviceId = getDeviceId(arguments);
auto device = utils::getDeviceById(_backend, deviceId);
compilationPlatform = utils::getCompilationPlatform(
+ _backend,
platform,
- device == nullptr ? deviceId : device->getName(),
- _backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());
+ device == nullptr ? deviceId : device->getName());
}
CompilerAdapterFactory factory;
diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/properties.cpp b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/properties.cpp
index f058118bacf..8b461a9f21d 100644
--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/properties.cpp
+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/compiled_model/properties.cpp
@@ -62,7 +62,7 @@ const std::string& expectedModelName = []() -> std::string {
const std::vector<ov::AnyMap> compatibilityPublicCompiledModelConfigs = {
{{ov::hint::model_priority.name(), ov::Any(ov::hint::Priority::MEDIUM)}},
- {{ov::execution_devices.name(), ov::Any(ov::test::utils::DEVICE_NPU)}},
+ {{ov::execution_devices.name(), ov::Any(std::string(ov::test::utils::DEVICE_NPU) + ".0")}},
{{ov::loaded_from_cache.name(), ov::Any(false)}},
{{ov::model_name.name(), ov::Any(expectedModelName)}},
{{ov::optimal_number_of_infer_requests.name(), ov::Any(1u)}},
@@ -114,7 +114,7 @@ const auto& combineParamsExecDevices = []() -> std::vector<std::pair<ov::AnyMap,
std::vector<std::pair<ov::AnyMap, std::string>> execParams(compiledModelConfigs.size());
for (auto it = compiledModelConfigs.cbegin(); it != compiledModelConfigs.cend(); ++it) {
auto&& distance = it - compiledModelConfigs.cbegin();
- execParams.at(distance) = std::make_pair(*it, ov::test::utils::DEVICE_NPU);
+ execParams.at(distance) = std::make_pair(*it, std::string(ov::test::utils::DEVICE_NPU) + ".0");
}
return execParams;
}();
diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
index cc8f0cbee41..0526ca8aa5b 100644
--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
@@ -77,7 +77,7 @@ const std::vector<ov::AnyMap> compat_CorrectPluginDefaultMutableProperties = {
{{ov::hint::performance_mode.name(), ov::hint::PerformanceMode::LATENCY}},
{{ov::hint::num_requests.name(), 1u}},
{{ov::log::level.name(), getTestsLogLevelFromEnvironmentOr(ov::log::Level::WARNING)}},
- {{ov::device::id.name(), ""}},
+ {{ov::device::id.name(), "0"}},
{{ov::num_streams.name(), ov::streams::AUTO}},
};