OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Create CiP handle using device properties if the device exists (#36571)
Bogdan Pereanu5938dcad982a
diff --git a/src/plugins/intel_npu/src/backend/include/zero_device.hpp b/src/plugins/intel_npu/src/backend/include/zero_device.hppindex 259e36b247c..500f4eaff58 100644--- a/src/plugins/intel_npu/src/backend/include/zero_device.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_device.hpp@@ -39,6 +39,8 @@ public:bool validateCompatibilityDescriptor(const std::string& compatibilityDescriptor) const override;+ DeviceProperties getDeviceProperties() const override;+ZeroDevice& operator=(const ZeroDevice&) = delete;ZeroDevice(const ZeroDevice&) = delete;diff --git a/src/plugins/intel_npu/src/backend/src/zero_device.cpp b/src/plugins/intel_npu/src/backend/src/zero_device.cppindex d72776dd0bb..606c3fcfd6f 100644--- a/src/plugins/intel_npu/src/backend/src/zero_device.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_device.cpp@@ -220,3 +220,7 @@ bool ZeroDevice::validateCompatibilityDescriptor(const std::string& compatibilitreturn output.result == ZE_VALIDATE_RUNTIME_REQUIREMENTS_RESULT_REQUIREMENTS_MET ||output.result == ZE_VALIDATE_RUNTIME_REQUIREMENTS_RESULT_REQUIREMENTS_MET_RECOMPILATION_ADVISABLE;}++IDevice::DeviceProperties ZeroDevice::getDeviceProperties() const {+ return {_device_properties.deviceId, _device_properties.subdeviceId, _device_properties.numSlices};+}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.hppindex 8ee4245e6a9..8ed4d06c78b 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@@ -68,6 +68,11 @@ public:class IDevice : public std::enable_shared_from_this<IDevice> {public:using Uuid = ov::device::UUID;+ struct DeviceProperties {+ uint32_t deviceId;+ uint32_t subdeviceId;+ uint32_t numSlices;+ };virtual std::string getName() const = 0;virtual std::string getFullDeviceName() const = 0;@@ -86,6 +91,7 @@ public:virtual void updateInfo(const ov::AnyMap& properties) = 0;virtual bool validateCompatibilityDescriptor(const std::string& compatibilityDescriptor) const = 0;+ virtual DeviceProperties getDeviceProperties() const = 0;protected:virtual ~IDevice() = default;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hppindex cb0e8affeab..2ad7782da7d 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/compiler_impl.hpp@@ -8,6 +8,7 @@#include <optional>#include "intel_npu/common/filtered_config.hpp"+#include "intel_npu/common/npu.hpp"#include "intel_npu/utils/vcl/vcl_api.hpp"#include "openvino/core/except.hpp"#include "openvino/core/model.hpp"@@ -19,7 +20,8 @@ namespace intel_npu {class VCLCompilerImpl final : public std::enable_shared_from_this<VCLCompilerImpl> {public:- VCLCompilerImpl(const std::string& library_dir);+ VCLCompilerImpl(const std::string& libraryDir,+ const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt);~VCLCompilerImpl();/**@@ -53,7 +55,7 @@ public:* Allocate W3 -> Init2** This is why there is an additional parameter callNumber:- * Compiler should somehow understand wich Init(or Main) to return+ * Compiler should somehow understand which Init (or Main) to return* Plugin does not know total numbers of Init schedules*/ov::Tensor compileWsIterative(const std::shared_ptr<ov::Model>& model,@@ -85,20 +87,13 @@ public:*/bool get_supported_options(std::vector<char>& options) const;- bool is_option_supported(const std::string& option,- const std::optional<std::string>& optValue = std::nullopt) const;-/**- * @brief Checks whether the given option and value are supported by the compiler for the specified device.- * This overload is used when a device descriptor is available, allowing device-specific validation.- * @param in_device_desc Pointer to a device descriptor containing the device ID, number of- * tiles and stepping information used for device-specific checks+ * @brief Checks whether the given option and value are supported by the compiler* @param option The option name to check* @param optValue The option value to validate- * @return true if the option and value are supported for the given device, false otherwise+ * @return true if the option and value are supported, false otherwise*/- bool is_option_supported(vcl_device_desc_t* in_device_desc,- const std::string& option,+ bool is_option_supported(const std::string& option,const std::optional<std::string>& optValue = std::nullopt) const;std::shared_ptr<void> getLinkedLibrary() const;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hppindex 8ed80b82cbb..c9f25234d72 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp@@ -6,8 +6,11 @@#pragma once+#include <optional>+#include "compiler_impl.hpp"#include "intel_npu/common/icompiler_adapter.hpp"+#include "intel_npu/common/npu.hpp"#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_init.hpp"#include "openvino/runtime/so_ptr.hpp"@@ -17,7 +20,8 @@ namespace intel_npu {class PluginCompilerAdapter final : public ICompilerAdapter {public:- PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct);+ PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ const std::optional<IDevice::DeviceProperties>& deviceProperties = std::nullopt);std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,const FilteredConfig& config) const override;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cppindex 539ea6ac99e..ec3b1295d94 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp@@ -23,13 +23,16 @@ ov::intel_npu::CompilerType CompilerAdapterFactory::determineAppropriateCompilerstd::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(const ov::SoPtr<IEngineBackend>& engineBackend,ov::intel_npu::CompilerType& compilerType,std::string_view platform) const {+ const auto device = engineBackend != nullptr ? engineBackend->getDevice() : nullptr;+if (compilerType == ov::intel_npu::CompilerType::PREFER_PLUGIN) {- if (engineBackend != nullptr) {+ if (device != nullptr) {compilerType = determineAppropriateCompilerTypeBasedOnPlatform(platform);if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {if (_pluginCompilerIsPresent) {try {- return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());+ return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs(),+ device->getDeviceProperties());} catch (...) {_pluginCompilerIsPresent = false;compilerType = ov::intel_npu::CompilerType::DRIVER;@@ -46,20 +49,20 @@ std::unique_ptr<ICompilerAdapter> CompilerAdapterFactory::getCompiler(const ov::}if (compilerType == ov::intel_npu::CompilerType::PLUGIN) {- if (engineBackend == nullptr) {+ if (device == nullptr) {return std::make_unique<PluginCompilerAdapter>(nullptr);}- return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs());+ return std::make_unique<PluginCompilerAdapter>(engineBackend->getInitStructs(), device->getDeviceProperties());} else if (compilerType == ov::intel_npu::CompilerType::DRIVER) {- if (engineBackend == nullptr || engineBackend->getDevice() == nullptr) {+ if (device == nullptr) {OPENVINO_THROW("Could not find an NPU device. The 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();+ auto deviceName = device->getName();if (!platform.empty() && deviceName != platform && deviceName != "AUTO_DETECT") {OPENVINO_THROW("Could not find a valid NPU device for the provided configuration.");}diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cppindex a9355190061..335c50f877c 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@@ -94,13 +94,14 @@ static inline std::string getLatestVCLLog(vcl_log_handle_t logHandle) {} \}-VCLCompilerImpl::VCLCompilerImpl(const std::string& library_dir)+VCLCompilerImpl::VCLCompilerImpl(const std::string& libraryDir,+ const std::optional<IDevice::DeviceProperties>& deviceProperties): _logHandle(nullptr),_logger("VCLCompilerImpl", Logger::global().level()) {_logger.debug("VCLCompilerImpl constructor start");// Load VCL library- (void)VCLApi::getInstance(library_dir);+ (void)VCLApi::getInstance(libraryDir);// Initialize the VCL APITHROW_ON_FAIL_FOR_VCL("vclGetVersion", vclGetVersion(&_vclVersion, &_vclProfilingVersion), nullptr);@@ -125,16 +126,34 @@ VCLCompilerImpl::VCLCompilerImpl(const std::string& library_dir)compilerDesc.version = _vclVersion;compilerDesc.debugLevel = static_cast<__vcl_log_level_t>(static_cast<int>(Logger::global().level()) + 1);- // This information cannot be determined during the initialization phase; set device desc default value, the related- // info will be processed in compile phase if passed by user.- _logger.info("Device description is not provided, using default values");- uint32_t defaultTileCount = std::numeric_limits<uint32_t>::max();- vcl_device_desc_t device_desc = {sizeof(vcl_device_desc_t),- 0x00,- std::numeric_limits<uint16_t>::max(),- defaultTileCount};+ vcl_device_desc_t vclDeviceDesc = {};+ if (deviceProperties.has_value()) {+ constexpr auto invalidRevision = std::numeric_limits<uint16_t>::max();+ const auto revision = deviceProperties->subdeviceId >= invalidRevision+ ? invalidRevision+ : static_cast<uint16_t>(deviceProperties->subdeviceId);++ if (revision == invalidRevision) {+ _logger.warning("Device subdeviceId %u does not fit into VCL revision field; using invalid revision "+ "sentinel instead",+ deviceProperties->subdeviceId);+ }++ _logger.info("Device description is provided, using deviceID: 0x%X, subdeviceID: %u, maxTiles: %u",+ deviceProperties->deviceId,+ deviceProperties->subdeviceId,+ deviceProperties->numSlices);+ vclDeviceDesc = {sizeof(vcl_device_desc_t), deviceProperties->deviceId, revision, deviceProperties->numSlices};+ } else {+ // This information cannot be determined during the initialization phase; set device desc default value, the+ // related info will be processed in compile phase if passed by user.+ _logger.info("Device description is not provided, using default values");+ uint32_t defaultTileCount = std::numeric_limits<uint32_t>::max();+ vclDeviceDesc = {sizeof(vcl_device_desc_t), 0x00, std::numeric_limits<uint16_t>::max(), defaultTileCount};+ }+THROW_ON_FAIL_FOR_VCL("vclCompilerCreate",- vclCompilerCreate(&compilerDesc, &device_desc, &_compilerHandle, &_logHandle),+ vclCompilerCreate(&compilerDesc, &vclDeviceDesc, &_compilerHandle, &_logHandle),nullptr);THROW_ON_FAIL_FOR_VCL("vclCompilerGetProperties",vclCompilerGetProperties(_compilerHandle, &_compilerProperties),@@ -540,42 +559,4 @@ bool VCLCompilerImpl::is_option_supported(const std::string& option, const std::return false;}-bool VCLCompilerImpl::is_option_supported(vcl_device_desc_t* in_device_desc,- const std::string& option,- const std::optional<std::string>& optValue) const {- vcl_compiler_desc_t compilerDesc;- compilerDesc.version = _vclVersion;- compilerDesc.debugLevel = static_cast<vcl_log_level_t>(static_cast<int>(Logger::global().level()) + 1);-- // Create a temporary compiler instance for the query to pass the correct device description.- // The private compiler instance used by this class was created with default device description.- vcl_log_handle_t logHandle = nullptr;- vcl_compiler_handle_t compilerHandle = nullptr;- try {- THROW_ON_FAIL_FOR_VCL("vclCompilerCreate",- vclCompilerCreate(&compilerDesc, in_device_desc, &compilerHandle, &logHandle),- nullptr);-- const char* optname_ch = option.c_str();- const char* optvalue_ch = optValue.has_value() ? optValue.value().c_str() : nullptr;- _logger.debug("is_option_supported start for option: %s, value: %s",- optname_ch,- optvalue_ch ? optvalue_ch : "null");- THROW_ON_FAIL_FOR_VCL("vclGetCompilerIsOptionSupported",- vclGetCompilerIsOptionSupported(compilerHandle, optname_ch, optvalue_ch),- logHandle);- if (compilerHandle) {- vclCompilerDestroy(compilerHandle);- }- return true;- } catch (const std::exception& e) {- _logger.debug("Exception in is_option_supported: %s", e.what());- if (compilerHandle) {- vclCompilerDestroy(compilerHandle);- }- }-- return false;-}-} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cppindex cb9851d5739..b1c4402795d 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@@ -16,7 +16,6 @@#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/utils.hpp"#include "intel_npu/utils/vm/npu_vm_runtime_api.hpp"-#include "intel_npu/utils/zero/zero_api.hpp"#include "intel_npu/utils/zero/zero_result.hpp"#include "mem_usage.hpp"#include "openvino/core/model.hpp"@@ -28,22 +27,23 @@namespace intel_npu {-PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct)+PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ const std::optional<IDevice::DeviceProperties>& deviceProperties): _zeroInitStruct(zeroInitStruct),_logger("PluginCompilerAdapter", Logger::global().level()) {_logger.info("initialize PluginCompilerAdapter start");_logger.info("Loading PLUGIN compiler");try {- auto ov_lib_path = ov::util::path_to_string(ov::util::get_ov_lib_path());- auto vclCompilerPtr = std::make_shared<VCLCompilerImpl>(ov_lib_path);+ auto ovLibPath = ov::util::path_to_string(ov::util::get_ov_lib_path());+ auto vclCompilerPtr = std::make_shared<VCLCompilerImpl>(ovLibPath, deviceProperties);OPENVINO_ASSERT(vclCompilerPtr != nullptr, "VCL compiler is nullptr");auto vclLib = vclCompilerPtr->getLinkedLibrary();_logger.info("PLUGIN VCL compiler is loading");OPENVINO_ASSERT(vclLib != nullptr, "VCL library is nullptr");_compiler = ov::SoPtr<VCLCompilerImpl>(vclCompilerPtr, vclLib);- } catch (const std::exception& vcl_exception) {- OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vcl_exception.what());+ } catch (const std::exception& vclException) {+ OPENVINO_THROW("VCL compiler loading failed, aborting. Error: ", vclException.what());}if (_zeroInitStruct == nullptr) {@@ -120,9 +120,9 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(std::shared_ptr<ov::Mod_logger.info("SEPARATE_WEIGHTS_VERSION: %s",SEPARATE_WEIGHTS_VERSION::toString(localConfig.get<SEPARATE_WEIGHTS_VERSION>()).c_str());- int64_t compile_model_mem_start = 0;+ int64_t compileModelMemStart = 0;if (_logger.level() >= ov::log::Level::INFO) {- compile_model_mem_start = get_peak_memory_usage();+ compileModelMemStart = get_peak_memory_usage();}std::vector<ov::Tensor> tensorsInits;@@ -224,11 +224,11 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(std::shared_ptr<ov::Mod}if (_logger.level() >= ov::log::Level::INFO) {- auto compile_model_mem_end = get_peak_memory_usage();- _logger.debug("Start of compilation memory usage: Peak %lld KB", compile_model_mem_start);- _logger.debug("End of compilation memory usage: Peak %lld KB", compile_model_mem_end);+ auto compileModelMemEnd = get_peak_memory_usage();+ _logger.debug("Start of compilation memory usage: Peak %lld KB", compileModelMemStart);+ _logger.debug("End of compilation memory usage: Peak %lld KB", compileModelMemEnd);// Note: Following log is parsed by CI. Take care when modifying it.- _logger.info("Compilation memory usage: Peak %lld KB", compile_model_mem_end - compile_model_mem_start);+ _logger.info("Compilation memory usage: Peak %lld KB", compileModelMemEnd - compileModelMemStart);}_logger.debug("compile end");@@ -285,45 +285,6 @@ std::optional<std::vector<std::string>> PluginCompilerAdapter::get_supported_optbool PluginCompilerAdapter::is_option_supported(const std::string& optname,const std::optional<std::string>& optValue) const {- if (optname == COMPATIBILITY_CHECK::key()) {- if (_zeroInitStruct == nullptr || _zeroInitStruct->getDevice() == nullptr) {- _logger.warning("No device is found, compatibility check is not available");- return false;- }-- ze_device_properties_t device_properties = {};- device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;- auto result = zeDeviceGetProperties(_zeroInitStruct->getDevice(), &device_properties);-- if (result == ZE_RESULT_SUCCESS) {- vcl_device_desc_t vcl_desc = {sizeof(vcl_device_desc_t),- device_properties.deviceId,- static_cast<uint16_t>(device_properties.subdeviceId),- device_properties.numSlices};-- _logger.info("Validating compatibility logic using deviceID: 0x%X, maxTiles: %u",- vcl_desc.deviceID,- vcl_desc.tileCount);-- const bool hasValue = optValue.has_value();- const std::string value = hasValue ? optValue.value() : "";- if (_compiler->is_option_supported(&vcl_desc, optname, optValue)) {- _logger.debug("Option %s is supported `%s` by VCLCompilerImpl",- optname.c_str(),- hasValue ? value.c_str() : "null");- return true;- } else {- _logger.debug("Option %s is not supported `%s` by VCLCompilerImpl",- optname.c_str(),- hasValue ? value.c_str() : "null");- return false;- }- } else {- _logger.warning("Can not get device properties, compatibility check is not available");- return false;- }- }-const bool hasValue = optValue.has_value();const std::string value = hasValue ? optValue.value() : "";if (_compiler->is_option_supported(optname, optValue)) {