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] Clean graph by getting inputs and outputs second time (#32821)
Bogdan Pereanu59fd03ea4293
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/network_metadata.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/network_metadata.hppindex 8d418e1f0b7..8c70f8dc510 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/network_metadata.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/network_metadata.hpp@@ -119,6 +119,13 @@ struct IODescriptor {* by the compiler).*/std::optional<ov::PartialShape> shapeFromIRModel = std::nullopt;++ /**+ * @brief The driver index of the descriptor.+ * @details This value is used by the driver to identify the input/output buffer. Driver indices for inputs and+ * outputs are assigned in the same vector and could have different indexing.+ */+ uint32_t indexUsedByDriver;};struct NetworkMetadata final {diff --git a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hppindex 19121c70cc9..92d3798d690 100644--- a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp@@ -11,7 +11,6 @@#include "intel_npu/common/sync_infer_request.hpp"#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_remote_tensor.hpp"-#include "intel_npu/utils/zero/zero_utils.hpp"#include "intel_npu/utils/zero/zero_wrappers.hpp"#include "zero_pipeline.hpp"#include "zero_tensor.hpp"@@ -65,9 +64,6 @@ private:const Config _config;Logger _logger;- const std::vector<ArgumentDescriptor>& _graphInputDescriptors;- const std::vector<ArgumentDescriptor>& _graphOutputDescriptors;-// A copy of each tensor is needed to maintain the original L0 memory allocation in case the user provides another// memory area for the tensor.mutable std::vector<std::vector<std::shared_ptr<ZeroTensor>>> _levelZeroInputTensors;diff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cppindex d04517b7416..0e8c872d9f1 100644--- a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp@@ -21,56 +21,6 @@ constexpr std::size_t SINGLE_TENSOR = 0;constexpr bool INPUT = true;constexpr bool OUTPUT = false;-/**- * @brief Checks that the metadata of the provided descriptor corresponds to the values registered in the Level Zero- * structure.- * @param ioDescriptor The OpenVINO API specific I/O descriptor which shall be compared.- * @param zeDescriptor The Level Zero specific structure used for comparison.- */-void check_level_zero_attributes_match(const IODescriptor& ioDescriptor, const ArgumentDescriptor& zeDescriptor) {- std::string zeDescriptorName = zeDescriptor.info.name;-- if (isStateInputName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(READVALUE_PREFIX.length());- } else if (isStateOutputName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(ASSIGN_PREFIX.length());- } else if (isShapeTensorName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(SHAPE_TENSOR_PREFIX.length());- } else if (isInitInputWeightsName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(INIT_INPUT_WEIGHTS_PREFIX.length());- } else if (isInitOutputWeightsName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(INIT_OUTPUT_WEIGHTS_PREFIX.length());- } else if (isMainInputWeightsName(zeDescriptorName)) {- zeDescriptorName = zeDescriptorName.substr(MAIN_INPUT_WEIGHTS_PREFIX.length());- }-- OPENVINO_ASSERT(ioDescriptor.nameFromCompiler == zeDescriptorName,- "Name mismatch between the I/O structure used internally and its Level Zero correspondent: ",- ioDescriptor.nameFromCompiler,- " vs. ",- zeDescriptorName,- ". The I/O order may have been altered, which could lead to an erroneous behavior.");- OPENVINO_ASSERT(ioDescriptor.precision == zeroUtils::toOVElementType(zeDescriptor.info.devicePrecision),- "Precision mismatch for input/output named " + ioDescriptor.nameFromCompiler);-- const std::vector<size_t>& ovDimensions = ioDescriptor.shapeFromCompiler.get_max_shape();- OPENVINO_ASSERT(ovDimensions.size() <= ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE,- "Maximum number of dimensions supported: " + std::to_string(ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE) +- '\n' + "Given: " + std::to_string(ovDimensions.size()));-- for (size_t index = 0; index < ovDimensions.size(); ++index) {- OPENVINO_ASSERT(ovDimensions[index] == zeDescriptor.info.dims[index],- "Shape mismatch for input/output named \"" + ioDescriptor.nameFromCompiler +- "\" by dimension index: " + std::to_string(index) +- ". L0 has: " + std::to_string(zeDescriptor.info.dims[index]) +- " but meta has: " + std::to_string(ovDimensions[index]));- }- for (size_t index = ovDimensions.size(); index < ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE; ++index) {- OPENVINO_ASSERT(zeDescriptor.info.dims[index] == 0 || zeDescriptor.info.dims[index] == 1,- "Shape mismatch for input/output named " + ioDescriptor.nameFromCompiler);- }-}-std::optional<size_t> determine_dynamic_batch_size(const IODescriptor& desc,const ov::PartialShape& ioShape,const std::shared_ptr<ov::ITensor>& tensor,@@ -112,16 +62,12 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&_graph(compiledModel->get_graph()),_config(config),_logger("ZeroInferRequest", config.get<LOG_LEVEL>()),- _graphInputDescriptors(_graph->get_input_descriptors()),- _graphOutputDescriptors(_graph->get_output_descriptors()),_levelZeroInputTensors(_metadata.inputs.size(), std::vector<std::shared_ptr<ZeroTensor>>(1, nullptr)),_levelZeroOutputTensors(_metadata.outputs.size(), nullptr) {_logger.debug("ZeroInferRequest::ZeroInferRequest - checking level zero attributes and allocating tensors");size_t ioIndex = 0;for (const IODescriptor& inputDescriptor : _metadata.inputs) {- check_level_zero_attributes_match(inputDescriptor, _graphInputDescriptors.at(ioIndex));-// Tensors for regular inputs will be allocated later, only for ports that were not set by the user.// Allocating only tensors for shapes and states.if (!(inputDescriptor.isStateInput || inputDescriptor.isShapeTensor)) {@@ -140,8 +86,6 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&ioIndex = 0;for (const IODescriptor& outputDescriptor : _metadata.outputs) {- check_level_zero_attributes_match(outputDescriptor, _graphOutputDescriptors.at(ioIndex));-// Tensors for regular outputs will be allocated later, only for ports that were not set by the user.// Allocating only tensors for shapes and states.if (!(outputDescriptor.isStateOutput || outputDescriptor.isShapeTensor)) {@@ -422,8 +366,8 @@ void ZeroInferRequest::set_tensor(const ov::Output<const ov::Node>& port, constOV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "update_graph_arguments");_pipeline->update_graph_arguments(foundPort.is_input()- ? _graph->get_input_descriptors().at(foundPort.idx).idx- : _graph->get_output_descriptors().at(foundPort.idx).idx,+ ? _metadata.inputs.at(foundPort.idx).indexUsedByDriver+ : _metadata.outputs.at(foundPort.idx).indexUsedByDriver,levelZeroTensor->data(),levelZeroTensor->get_byte_size());}@@ -501,7 +445,7 @@ void ZeroInferRequest::set_tensors(const ov::Output<const ov::Node>& port,OPENVINO_ASSERT(get_level_zero_input(foundPort.idx, i)->data(), "Empty buffer");OV_ITT_TASK_NEXT(ZERO_SET_TENSORS, "updateCommandList");- _pipeline->update_graph_arguments_batching(_graph->get_input_descriptors().at(foundPort.idx).idx,+ _pipeline->update_graph_arguments_batching(_metadata.inputs.at(foundPort.idx).indexUsedByDriver,get_level_zero_input(foundPort.idx, i)->data(),i);}@@ -624,7 +568,7 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {_logger.debug("Update input graph descriptor with the new tensor");OPENVINO_ASSERT(levelZeroTensor.at(SINGLE_TENSOR)->data(), "Empty buffer");- _pipeline->update_graph_arguments(_graph->get_input_descriptors().at(ioIndex).idx,+ _pipeline->update_graph_arguments(_metadata.inputs.at(ioIndex).indexUsedByDriver,levelZeroTensor.at(SINGLE_TENSOR)->data(),levelZeroTensor.at(SINGLE_TENSOR)->get_byte_size());@@ -656,7 +600,7 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {_logger.debug("Update output graph descriptor with the new tensor");OPENVINO_ASSERT(levelZeroTensor->data(), "Empty buffer");- _pipeline->update_graph_arguments(_graph->get_output_descriptors().at(ioIndex).idx,+ _pipeline->update_graph_arguments(_metadata.outputs.at(ioIndex).indexUsedByDriver,levelZeroTensor->data(),levelZeroTensor->get_byte_size());@@ -687,12 +631,12 @@ void ZeroInferRequest::update_states_if_memory_changed() {_levelZeroOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_zero_state();zeroState->clear_zero_state_update_pending();- _pipeline->update_graph_arguments(_graphInputDescriptors.at(zeroState->get_tensor_index()).idx,+ _pipeline->update_graph_arguments(_metadata.inputs.at(zeroState->get_tensor_index()).indexUsedByDriver,get_level_zero_input(zeroState->get_tensor_index())->data(),get_level_zero_input(zeroState->get_tensor_index())->get_byte_size());_pipeline->update_graph_arguments(- _graphOutputDescriptors.at(zeroState->get_related_tensor_index()).idx,+ _metadata.outputs.at(zeroState->get_related_tensor_index()).indexUsedByDriver,_levelZeroOutputTensors.at(zeroState->get_related_tensor_index())->data(),_levelZeroOutputTensors.at(zeroState->get_related_tensor_index())->get_byte_size());}diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex c143dff4642..11fcb75d5e2 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -87,8 +87,8 @@ Pipeline::Pipeline(const Config& config,for (size_t i = 0; i < _number_of_command_lists; i++) {_logger.debug("Pipeline - set args for command list number: %zu", i);size_t io_index = 0;- for (const auto& desc : graph->get_input_descriptors()) {- if (isMainInputWeightsName(desc.info.name)) {+ for (const auto& desc : _graph->get_metadata().inputs) {+ if (desc.isMainInputWeights) {// These values were set while running the "WeightlessGraph::init" methodcontinue;}@@ -96,14 +96,14 @@ Pipeline::Pipeline(const Config& config,if (input_tensors.at(io_index).size() > 1) {_logger.debug("Pipeline - set args for input index: %zu", io_index);- graph->set_argument_value(desc.idx, input_tensors.at(io_index).at(i)->data());+ graph->set_argument_value(desc.indexUsedByDriver, input_tensors.at(io_index).at(i)->data());++io_index;continue;}graph->set_argument_value(- desc.idx,+ desc.indexUsedByDriver,static_cast<unsigned char*>(input_tensors.at(io_index).at(0)->data()) +(i * input_tensors.at(io_index).at(0)->get_byte_size()) / _number_of_command_lists);@@ -111,9 +111,9 @@ Pipeline::Pipeline(const Config& config,}io_index = 0;- for (const auto& desc : graph->get_output_descriptors()) {+ for (const auto& desc : _graph->get_metadata().outputs) {graph->set_argument_value(- desc.idx,+ desc.indexUsedByDriver,static_cast<unsigned char*>(output_tensors.at(io_index)->data()) +(i * output_tensors.at(io_index)->get_byte_size()) / _number_of_command_lists);++io_index;diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hppindex b3128454db9..2dfffa36036 100644--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp@@ -9,7 +9,6 @@#include <vector>#include "intel_npu/network_metadata.hpp"-#include "intel_npu/utils/zero/zero_utils.hpp"#include "intel_npu/utils/zero/zero_wrappers.hpp"#include "openvino/runtime/itensor.hpp"#include "openvino/runtime/profiling_info.hpp"@@ -45,8 +44,6 @@ public:virtual void update_network_name(std::string_view name) = 0;- virtual const std::vector<ArgumentDescriptor>& get_input_descriptors() const = 0;- virtual const std::vector<ArgumentDescriptor>& get_output_descriptors() const = 0;virtual const std::shared_ptr<CommandQueue>& get_command_queue() const = 0;virtual uint32_t get_command_queue_group_ordinal() const = 0;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hppindex 45de6b921e0..d9dacc3e7cb 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp@@ -42,8 +42,6 @@ public:void update_network_name(std::string_view name) override;- const std::vector<ArgumentDescriptor>& get_input_descriptors() const override;- const std::vector<ArgumentDescriptor>& get_output_descriptors() const override;const std::shared_ptr<CommandQueue>& get_command_queue() const override;uint32_t get_command_queue_group_ordinal() const override;@@ -73,9 +71,6 @@ protected:GraphDescriptor _graphDesc;NetworkMetadata _metadata;- std::vector<ArgumentDescriptor> _inputDescriptors;- std::vector<ArgumentDescriptor> _outputDescriptors;-std::shared_ptr<CommandQueue> _commandQueue;uint32_t _commandQueueGroupOrdinal = 0;std::vector<std::shared_ptr<Event>> _lastSubmittedEvent;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hppindex bd5682ddec0..69d38f4741c 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/weightless_graph.hpp@@ -108,9 +108,6 @@ private:std::vector<NetworkMetadata> _initsMetadata;std::shared_ptr<const ov::Model> _model;- std::vector<std::vector<ArgumentDescriptor>> _initsInputDescriptors;- std::vector<std::vector<ArgumentDescriptor>> _initsOutputDescriptors;-std::vector<uint32_t> _initsCommandQueueOrdinals;std::vector<std::unique_ptr<CommandList>> _initsCommandLists;std::vector<std::unique_ptr<Fence>> _initsFences;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hppindex 2cf92aef7cf..eb529a34efe 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp@@ -61,7 +61,7 @@ public:private:void getMetadata(ze_graph_handle_t graphHandle,- uint32_t index,+ uint32_t indexUsedByDriver,std::vector<IODescriptor>& inputs,std::vector<IODescriptor>& outputs) const;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cppindex 9494f484bb7..9ace471ea66 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp@@ -50,14 +50,6 @@ void Graph::update_network_name(std::string_view name) {_metadata.name = name;}-const std::vector<ArgumentDescriptor>& Graph::get_input_descriptors() const {- return _inputDescriptors;-}--const std::vector<ArgumentDescriptor>& Graph::get_output_descriptors() const {- return _outputDescriptors;-}-const std::shared_ptr<CommandQueue>& Graph::get_command_queue() const {return _commandQueue;}@@ -171,32 +163,6 @@ void Graph::initialize(const Config& config) {return;}- _logger.debug("performing pfnGetProperties");- ze_graph_properties_t props{};- props.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;- auto result = _zeroInitStruct->getGraphDdiTable().pfnGetProperties(_graphDesc._handle, &props);- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties", result, _zeroInitStruct->getGraphDdiTable());-- _logger.debug("performing pfnGetArgumentProperties3");- for (uint32_t index = 0; index < props.numGraphArgs; ++index) {- ze_graph_argument_properties_3_t arg3{};- arg3.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;- auto result = _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(_graphDesc._handle, index, &arg3);- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable());-- if (arg3.type == ZE_GRAPH_ARGUMENT_TYPE_INPUT) {- _inputDescriptors.push_back(ArgumentDescriptor{arg3, index});- _logger.debug("got pfnGetArgumentProperties3 for input: %s", _inputDescriptors.back().to_string().c_str());- } else {- _outputDescriptors.push_back(ArgumentDescriptor{arg3, index});- _logger.debug("got pfnGetArgumentProperties3 for output: %s",- _outputDescriptors.back().to_string().c_str());- }- }-- _inputDescriptors.shrink_to_fit();- _outputDescriptors.shrink_to_fit();-_commandQueueGroupOrdinal = zeroUtils::findCommandQueueGroupOrdinal(_zeroInitStruct->getDevice(),ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE);diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cppindex 6a636fa398b..4c014c6d560 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@@ -100,12 +100,14 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<conov::Tensor tensor = make_tensor_from_vector(networkDesc.compiledNetwork);GraphDescriptor graphDesc;+ NetworkMetadata networkMeta;if (_zeGraphExt) {// Depending on the config, we may get an error when trying to get the graph handle from the compiled// networktry {graphDesc = _zeGraphExt->getGraphDescriptor(tensor.data(), tensor.get_byte_size());+ networkMeta = _zeGraphExt->getNetworkMeta(graphDesc);} catch (...) {_logger.info("Failed to obtain the level zero graph handle. Inference requests for this model are not ""allowed. Only exports are available");@@ -116,7 +118,7 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<con_zeGraphExt,_zeroInitStruct,graphDesc,- std::move(networkDesc.metadata),+ std::move(networkMeta),std::move(tensor),config,/* persistentBlob = */ true, // exporting the blob shall be available in such a scenario@@ -208,11 +210,13 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(const std::shared_ptr<oov::Tensor tensorMain = make_tensor_from_vector(mainNetworkDescription->compiledNetwork);GraphDescriptor mainGraphDesc;+ NetworkMetadata mainNetworkMetadata;if (_zeGraphExt) {// Depending on the config, we may get an error when trying to// get the graph handle from the compiled networktry {mainGraphDesc = _zeGraphExt->getGraphDescriptor(tensorMain.data(), tensorMain.get_byte_size());+ mainNetworkMetadata = _zeGraphExt->getNetworkMeta(mainGraphDesc);} catch (...) {_logger.info("Failed to obtain the level zero graph handle. Inference requests for this model are not ""allowed. Only exports are available");@@ -228,23 +232,25 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compileWS(const std::shared_ptr<ofor (auto& networkDesc : initNetworkDescriptions) {ov::Tensor tensor = make_tensor_from_vector(networkDesc->compiledNetwork);GraphDescriptor initGraphDesc;+ NetworkMetadata initNetworkMeta;if (_zeGraphExt) {try {initGraphDesc = _zeGraphExt->getGraphDescriptor(tensor.data(), tensor.get_byte_size());+ initNetworkMeta = _zeGraphExt->getNetworkMeta(initGraphDesc);} catch (...) {}}initGraphDescriptors.push_back(initGraphDesc);tensorsInits.push_back(std::move(tensor));- initNetworkMetadata.push_back(std::move(networkDesc->metadata));+ initNetworkMetadata.push_back(std::move(initNetworkMeta));}return std::make_shared<WeightlessGraph>(_zeGraphExt,_zeroInitStruct,mainGraphDesc,- std::move(mainNetworkDescription->metadata),+ std::move(mainNetworkMetadata),std::move(tensorMain),initGraphDescriptors,std::move(initNetworkMetadata),diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cppindex 3b99cc28fb9..1d8549f57f2 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp@@ -277,46 +277,15 @@ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> WeightlessGraph::exporvoid WeightlessGraph::initialize(const Config& config) {// Simplified version for init schedulesconst size_t numberOfInits = _initsGraphDesc.size();- _initsInputDescriptors.resize(numberOfInits);- _initsOutputDescriptors.resize(numberOfInits);_initsCommandQueueOrdinals.resize(numberOfInits);_initsCommandLists.resize(numberOfInits);_initsFences.resize(numberOfInits);for (size_t initIndex = 0; initIndex < numberOfInits; ++initIndex) {_wgLogger.debug("WeightlessGraph initialize start, init schedule ", initIndex);- std::vector<ArgumentDescriptor>& initInputDescriptors = _initsInputDescriptors.at(initIndex);- std::vector<ArgumentDescriptor>& initOutputDescriptors = _initsOutputDescriptors.at(initIndex);uint32_t& initCommandQueueOrdinal = _initsCommandQueueOrdinals.at(initIndex);// Code similar to "Graph::initialize"- _wgLogger.debug("performing pfnGetProperties");- ze_graph_properties_t props{};- props.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;- auto result =- _zeroInitStruct->getGraphDdiTable().pfnGetProperties(_initsGraphDesc.at(initIndex)._handle, &props);- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties", result, _zeroInitStruct->getGraphDdiTable());-- _wgLogger.debug("performing pfnGetArgumentProperties3");- for (uint32_t index = 0; index < props.numGraphArgs; ++index) {- ze_graph_argument_properties_3_t arg3{};- arg3.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;- auto result =- _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(_initsGraphDesc.at(initIndex)._handle,- index,- &arg3);- THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable());-- if (arg3.type == ZE_GRAPH_ARGUMENT_TYPE_INPUT) {- initInputDescriptors.push_back(ArgumentDescriptor{arg3, index});- } else {- initOutputDescriptors.push_back(ArgumentDescriptor{arg3, index});- }- }-- initInputDescriptors.shrink_to_fit();- initOutputDescriptors.shrink_to_fit();-initCommandQueueOrdinal = zeroUtils::findCommandQueueGroupOrdinal(_zeroInitStruct->getDevice(),ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE);@@ -371,8 +340,6 @@ void WeightlessGraph::initialize(const Config& config) {release_graphs();}- _initsInputDescriptors.clear();- _initsOutputDescriptors.clear();_initsCommandQueueOrdinals.clear();_initsCommandLists.clear();_initsFences.clear();@@ -553,15 +520,19 @@ void WeightlessGraph::create_pipeline(const size_t initIndex,_initsFences.at(initIndex) = std::make_unique<Fence>(_initsCommandQueue);size_t io_index = 0;- for (const auto& desc : _initsInputDescriptors.at(initIndex)) {+ for (const auto& desc : _initsMetadata.at(initIndex).inputs) {void* data = inputTensors.at(io_index++)->data();- _zeGraphExt->setGraphArgumentValue(_initsGraphDesc.at(initIndex), desc.idx, static_cast<unsigned char*>(data));+ _zeGraphExt->setGraphArgumentValue(_initsGraphDesc.at(initIndex),+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(data));}io_index = 0;- for (const auto& desc : _initsOutputDescriptors.at(initIndex)) {+ for (const auto& desc : _initsMetadata.at(initIndex).outputs) {void* data = outputTensors.at(io_index++)->data();- _zeGraphExt->setGraphArgumentValue(_initsGraphDesc.at(initIndex), desc.idx, static_cast<unsigned char*>(data));+ _zeGraphExt->setGraphArgumentValue(_initsGraphDesc.at(initIndex),+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(data));}_initsCommandLists.at(initIndex)->appendGraphExecute(@@ -584,18 +555,17 @@ void WeightlessGraph::run_pipeline(const size_t initIndex) {}void WeightlessGraph::set_weights_inputs() {- for (const auto& desc : _inputDescriptors) {- if (!isMainInputWeightsName(desc.info.name)) {+ for (const auto& desc : _metadata.inputs) {+ if (!desc.isMainInputWeights) {continue;}- const std::string weightsInputName = std::string(desc.info.name).substr(MAIN_INPUT_WEIGHTS_PREFIX.size());- OPENVINO_ASSERT(_mainInputsViewTensors.count(weightsInputName),+ OPENVINO_ASSERT(_mainInputsViewTensors.count(desc.nameFromCompiler),"Mismatch between main inputs and init outputs. The input of the main schedule \"",- weightsInputName,+ desc.nameFromCompiler,"\" has no correspondent within the init outputs.");- std::shared_ptr<ov::ITensor> weightsTensor = _mainInputsViewTensors.at(weightsInputName);- set_argument_value(desc.idx, static_cast<unsigned char*>(weightsTensor->data()));+ std::shared_ptr<ov::ITensor> weightsTensor = _mainInputsViewTensors.at(desc.nameFromCompiler);+ set_argument_value(desc.indexUsedByDriver, static_cast<unsigned char*>(weightsTensor->data()));}}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.cppindex 1643bcbedd2..52e8e4a3455 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@@ -36,7 +36,8 @@ using namespace intel_npu;* the referenced attribute.* @returns A descriptor object containing the metadata converted in OpenVINO specific structures.*/-static IODescriptor getIODescriptor(const ze_graph_argument_properties_3_t& arg,+static IODescriptor getIODescriptor(const uint32_t indexUsedByDriver,+ const ze_graph_argument_properties_3_t& arg,const std::optional<ze_graph_argument_metadata_t>& metadata) {auto logger = Logger::global().clone("getIODescriptor");ov::element::Type_t precision = zeroUtils::toOVElementType(arg.devicePrecision);@@ -113,7 +114,8 @@ static IODescriptor getIODescriptor(const ze_graph_argument_properties_3_t& arg,std::nullopt,arg.debug_friendly_name,std::move(outputTensorNames),- metadata.has_value() ? std::optional(shapeFromIRModel) : std::nullopt};+ metadata.has_value() ? std::optional(shapeFromIRModel) : std::nullopt,+ indexUsedByDriver};}} // namespace@@ -414,21 +416,23 @@ bool ZeGraphExtWrappers::isBlobDataImported(const GraphDescriptor& graphDescript}void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,- uint32_t index,+ uint32_t indexUsedByDriver,std::vector<IODescriptor>& inputs,std::vector<IODescriptor>& outputs) const {if (NotSupportArgumentMetadata(_graphExtVersion)) {ze_graph_argument_properties_3_t arg = {};+ arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;_logger.debug("getMetadata - perform pfnGetArgumentProperties3");- auto result = _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, index, &arg);+ auto result =+ _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, indexUsedByDriver, &arg);THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable());switch (arg.type) {case ZE_GRAPH_ARGUMENT_TYPE_INPUT: {- inputs.push_back(getIODescriptor(arg, std::nullopt));+ inputs.push_back(getIODescriptor(indexUsedByDriver, arg, std::nullopt));} break;case ZE_GRAPH_ARGUMENT_TYPE_OUTPUT: {- outputs.push_back(getIODescriptor(arg, std::nullopt));+ outputs.push_back(getIODescriptor(indexUsedByDriver, arg, std::nullopt));} break;default: {OPENVINO_THROW("Invalid ze_graph_argument_type_t found in ze_graph_argument_properties_3_t object: ",@@ -437,8 +441,10 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,}} else {ze_graph_argument_properties_3_t arg = {};+ arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;_logger.debug("getMetadata - perform pfnGetArgumentProperties3");- auto result = _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, index, &arg);+ auto result =+ _zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, indexUsedByDriver, &arg);THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable());std::optional<ze_graph_argument_metadata_t> optionalMetadata = std::nullopt;@@ -448,7 +454,10 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,!isMainInputWeightsName(arg.name)) {_logger.debug("getMetadata - perform pfnGetArgumentMetadata");ze_graph_argument_metadata_t metadata = {};- result = _zeroInitStruct->getGraphDdiTable().pfnGraphGetArgumentMetadata(graphHandle, index, &metadata);+ metadata.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_METADATA;+ result = _zeroInitStruct->getGraphDdiTable().pfnGraphGetArgumentMetadata(graphHandle,+ indexUsedByDriver,+ &metadata);THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGraphGetArgumentMetadata", result, _zeroInitStruct->getGraphDdiTable());optionalMetadata = std::optional(metadata);@@ -456,10 +465,10 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,switch (arg.type) {case ZE_GRAPH_ARGUMENT_TYPE_INPUT: {- inputs.push_back(getIODescriptor(arg, optionalMetadata));+ inputs.push_back(getIODescriptor(indexUsedByDriver, arg, optionalMetadata));} break;case ZE_GRAPH_ARGUMENT_TYPE_OUTPUT: {- outputs.push_back(getIODescriptor(arg, optionalMetadata));+ outputs.push_back(getIODescriptor(indexUsedByDriver, arg, optionalMetadata));} break;default: {OPENVINO_THROW("Invalid ze_graph_argument_type_t found in ze_graph_argument_properties_3_t object: ",@@ -477,8 +486,8 @@ NetworkMetadata ZeGraphExtWrappers::getNetworkMeta(GraphDescriptor& graphDescripauto result = _zeroInitStruct->getGraphDdiTable().pfnGetProperties(graphDescriptor._handle, &graphProperties);THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties", result, _zeroInitStruct->getGraphDdiTable());NetworkMetadata meta;- for (uint32_t index = 0; index < graphProperties.numGraphArgs; ++index) {- getMetadata(graphDescriptor._handle, index, meta.inputs, meta.outputs);+ for (uint32_t indexUsedByDriver = 0; indexUsedByDriver < graphProperties.numGraphArgs; ++indexUsedByDriver) {+ getMetadata(graphDescriptor._handle, indexUsedByDriver, meta.inputs, meta.outputs);}// TODO: support this information in CiD [track: E#33479]meta.numStreams = 1;diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hppindex 427f9cd02f0..1c269d2ebd4 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp@@ -15,22 +15,6 @@namespace intel_npu {-struct ArgumentDescriptor {- ze_graph_argument_properties_3_t info;- uint32_t idx;- std::string to_string() const {- std::stringstream sstream;- sstream << "dims_count: " << info.dims_count << " - [";- for (uint32_t i = 0; i < std::min<uint32_t>(info.dims_count, ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE); i ++) {- sstream << info.dims[i] << ",";- }- sstream << "]"- << ", networkLayout: " << std::to_string(static_cast<size_t>(info.networkLayout))- << ", deviceLayout: " << std::to_string(static_cast<size_t>(info.deviceLayout));- return sstream.str();- }-};-namespace zeroUtils {#define THROW_ON_FAIL_FOR_LEVELZERO_EXT(step, result, graph_ddi_table_ext) \