diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp index 593c0d4c45d2b2..25361c0dc957c5 100644 --- a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp +++ b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp @@ -123,9 +123,6 @@ struct NetworkMetadata final { */ void bindRelatedDescriptors(); -private: - std::optional findByName(const std::vector& descriptors, const std::string_view targetName); - }; // namespace intel_npu /** diff --git a/src/plugins/intel_npu/src/al/src/icompiler.cpp b/src/plugins/intel_npu/src/al/src/icompiler.cpp index af762582650b98..632a466d17d442 100644 --- a/src/plugins/intel_npu/src/al/src/icompiler.cpp +++ b/src/plugins/intel_npu/src/al/src/icompiler.cpp @@ -6,17 +6,6 @@ namespace intel_npu { -std::optional NetworkMetadata::findByName(const std::vector& descriptors, - const std::string_view targetName) { - for (size_t descriptorIndex = 0; descriptorIndex < descriptors.size(); ++descriptorIndex) { - if (descriptors.at(descriptorIndex).nameFromCompiler == targetName) { - return descriptorIndex; - } - } - - return std::nullopt; -} - void NetworkMetadata::bindRelatedDescriptors() { size_t ioIndex = 0; @@ -27,18 +16,24 @@ void NetworkMetadata::bindRelatedDescriptors() { } if (input.isStateInput) { - const std::optional relatedDescriptorIndex = findByName(outputs, input.nameFromCompiler); - - if (relatedDescriptorIndex.has_value()) { - input.relatedDescriptorIndex = relatedDescriptorIndex; - outputs.at(*relatedDescriptorIndex).relatedDescriptorIndex = std::optional(ioIndex); + const auto relatedDescriptorIterator = + std::find_if(outputs.begin(), outputs.end(), [&](const IODescriptor& output) { + return output.isStateOutput && (output.nameFromCompiler == input.nameFromCompiler); + }); + + if (relatedDescriptorIterator != outputs.end()) { + input.relatedDescriptorIndex = std::distance(outputs.begin(), relatedDescriptorIterator); + outputs.at(*input.relatedDescriptorIndex).relatedDescriptorIndex = ioIndex; } } else if (input.isShapeTensor) { - const std::optional relatedDescriptorIndex = findByName(inputs, input.nameFromCompiler); - - if (relatedDescriptorIndex.has_value() && *relatedDescriptorIndex != ioIndex) { - input.relatedDescriptorIndex = relatedDescriptorIndex; - inputs.at(*relatedDescriptorIndex).relatedDescriptorIndex = std::optional(ioIndex); + const auto relatedDescriptorIterator = + std::find_if(inputs.begin(), inputs.end(), [&](const IODescriptor& candidate) { + return !candidate.isShapeTensor && (candidate.nameFromCompiler == input.nameFromCompiler); + }); + + if (relatedDescriptorIterator != inputs.end()) { + input.relatedDescriptorIndex = std::distance(inputs.begin(), relatedDescriptorIterator); + inputs.at(*input.relatedDescriptorIndex).relatedDescriptorIndex = ioIndex; } } @@ -54,11 +49,14 @@ void NetworkMetadata::bindRelatedDescriptors() { } if (output.isShapeTensor) { - const std::optional relatedDescriptorIndex = findByName(outputs, output.nameFromCompiler); - - if (relatedDescriptorIndex.has_value() && *relatedDescriptorIndex != ioIndex) { - output.relatedDescriptorIndex = relatedDescriptorIndex; - outputs.at(*relatedDescriptorIndex).relatedDescriptorIndex = std::optional(ioIndex); + const auto relatedDescriptorIterator = + std::find_if(outputs.begin(), outputs.end(), [&](const IODescriptor& candidate) { + return !candidate.isShapeTensor && (candidate.nameFromCompiler == output.nameFromCompiler); + }); + + if (relatedDescriptorIterator != outputs.end()) { + output.relatedDescriptorIndex = std::distance(outputs.begin(), relatedDescriptorIterator); + outputs.at(*output.relatedDescriptorIndex).relatedDescriptorIndex = ioIndex; } }