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] Use zero tensor to get correct data (#27980)
Bogdan Pereanu281797748397
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 1e8781b0afe..eb103c493e4 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@@ -15,6 +15,7 @@#include "zero_pipeline.hpp"#include "zero_profiling.hpp"#include "zero_remote_tensor.hpp"+#include "zero_tensor.hpp"namespace intel_npu {@@ -62,8 +63,9 @@ private:std::shared_ptr<ov::ITensor>& get_level_zero_input(size_t index, size_t tensorNo = 0) const;std::vector<std::shared_ptr<ov::ITensor>>& get_level_zero_inputs(size_t index) const;- std::optional<TensorData>& get_input_tensor_data(size_t index, size_t tensorNo = 0) const;- std::vector<std::optional<TensorData>>& get_input_tensors_data(size_t index) const;+ std::shared_ptr<ov::ITensor> create_tensor(ov::element::Type type,+ const ov::Shape& shape,+ const ov::Allocator& allocator = {}) const override;const std::shared_ptr<ZeroInitStructsHolder> _initStructs;const std::shared_ptr<IGraph> _graph;@@ -75,9 +77,6 @@ private:mutable std::vector<std::vector<std::shared_ptr<ov::ITensor>>> _levelZeroInputTensors;mutable std::vector<std::shared_ptr<ov::ITensor>> _levelZeroOutputTensors;- mutable std::vector<std::vector<std::optional<TensorData>>> _inputTensorsData;- mutable std::vector<std::optional<TensorData>> _outputTensorsData;-ze_device_properties_t _properties = {};std::shared_ptr<const zeroMemory::HostMemAllocator> _inputAllocator;std::shared_ptr<const zeroMemory::HostMemAllocator> _outputAllocator;diff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hppindex de5e1ac81c4..1bc06d174f6 100644--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp@@ -9,25 +9,20 @@#include "intel_npu/utils/zero/zero_wrappers.hpp"#include "zero_memory.hpp"#include "zero_profiling.hpp"+#include "zero_tensor.hpp"namespace intel_npu {-struct TensorData {- void* mem;- size_t size;- bool levelZeroTensorCreatedLocally = true;-};-struct Pipeline {public:Pipeline(const Config& config,- const std::shared_ptr<ZeroInitStructsHolder>& initStructs,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,const std::shared_ptr<IGraph>& graph,zeroProfiling::ProfilingPool& profiling_pool,zeroProfiling::ProfilingQuery& profiling_query,const std::shared_ptr<zeroProfiling::NpuInferProfiling>& npu_profiling,- const std::vector<std::vector<std::optional<TensorData>>>& inputTensorsData,- const std::vector<std::optional<TensorData>>& outputTensorsData,+ const std::vector<std::vector<std::shared_ptr<ov::ITensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ov::ITensor>>& output_tensors,uint32_t group_ordinal);Pipeline(const Pipeline&) = delete;@@ -38,8 +33,11 @@ public:void pull();void reset() const;- void updateCommandList(const TensorData& tensorsData, uint32_t index);- void updateCommandList(const TensorData& tensorsData, uint32_t index, size_t commandListIndex);+ void updateCommandList(uint32_t arg_index, const void* arg_data, size_t byte_size);+ void updateCommandListIndex(uint32_t arg_index, const void* arg_data, size_t command_list_index);++ void closeCommandList();+ void closeCommandListIndex(size_t command_list_index);protected:std::shared_ptr<IGraph> _graph;diff --git a/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp b/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hppindex aabe5e9bb4e..e102cb3f8e5 100644--- a/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_remote_tensor.hpp@@ -14,7 +14,7 @@namespace intel_npu {-class ZeroRemoteTensor : public RemoteTensor {+class ZeroRemoteTensor final : public RemoteTensor {public:ZeroRemoteTensor(const std::shared_ptr<ov::IRemoteContext>& context,const std::shared_ptr<ZeroInitStructsHolder>& init_structs,@@ -48,4 +48,8 @@ private:bool _external_memory_support = false;};+inline bool is_remote_tensor(const std::shared_ptr<ov::ITensor>& tensor) {+ return std::dynamic_pointer_cast<ZeroRemoteTensor>(tensor) != nullptr;+}+} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp b/src/plugins/intel_npu/src/backend/include/zero_tensor.hppnew file mode 100644index 00000000000..a2a39ee301d--- /dev/null+++ b/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp@@ -0,0 +1,66 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <memory>+#include <mutex>++#include "intel_npu/config/config.hpp"+#include "intel_npu/utils/zero/zero_init.hpp"+#include "openvino/runtime/common.hpp"+#include "openvino/runtime/itensor.hpp"+#include "openvino/runtime/so_ptr.hpp"++namespace intel_npu {++/**+ * @brief Constructs Tensor using element type and shape. Allocate internal host storage using custom allocator.+ * @details The implementation is simillar to the AllocatedTensor class from OV namespace.+ * @note Set_shape method throws an error in case re-allocation is needed but this is not supported by the driver.+ * There are two extra methods to notify the consumer if memory changed or not and to reset the flag.+ */+class ZeroTensor final : public ov::ITensor {+public:+ ZeroTensor(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const ov::element::Type element_type,+ const ov::Shape& shape,+ const ov::Allocator& allocator);++ void* data(const ov::element::Type& type = {}) const override;++ const ov::element::Type& get_element_type() const override;++ const ov::Shape& get_shape() const override;++ void set_shape(ov::Shape new_shape) override;++ const ov::Strides& get_strides() const override;++ bool memory_address_changed();+ void reset_memory_flag();++ ~ZeroTensor();++private:+ static void initialize_elements(void* data, const ov::element::Type& element_type, const ov::Shape& shape);+ void update_strides() const;+ size_t get_capacity() const;+ size_t get_bytes_capacity() const;+ void destroy_elements(size_t begin_ind, size_t end_ind);+ void destroy_memory();++ std::shared_ptr<ZeroInitStructsHolder> _init_structs;++ ov::element::Type _element_type;+ ov::Shape _shape;+ ov::Shape _capacity;+ mutable ov::Strides _strides;+ mutable std::once_flag _strides_once;+ ov::Allocator _allocator;+ void* _ptr = nullptr;+ bool _reset_tensor_memory = false;+};++} // namespace intel_npudiff --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 a0e5d2d11c1..c8c7cb8854d 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@@ -12,7 +12,6 @@#include "intel_npu/utils/zero/zero_api.hpp"#include "openvino/op/util/op_types.hpp"#include "openvino/runtime/intel_npu/remote_properties.hpp"-#include "openvino/runtime/make_tensor.hpp"#include "zero_memory.hpp"using namespace intel_npu;@@ -105,8 +104,6 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&_logger("ZeroInferRequest", config.get<LOG_LEVEL>()),_levelZeroInputTensors(_metadata.inputs.size(), std::vector<std::shared_ptr<ov::ITensor>>(1, nullptr)),_levelZeroOutputTensors(_metadata.outputs.size(), nullptr),- _inputTensorsData(_metadata.inputs.size(), std::vector<std::optional<TensorData>>(1, std::nullopt)),- _outputTensorsData(_metadata.outputs.size(), std::nullopt),_profilingPool(_initStructs, _graph, zeroProfiling::POOL_SIZE),_profilingQuery(_initStructs, 0) {_logger.debug("ZeroInferRequest::ZeroInferRequest - SyncInferRequest");@@ -140,8 +137,6 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&get_level_zero_input(ioIndex) =allocate_tensor(inputDescriptor, ioIndex, INPUT, *_inputAllocator, _graph->get_batch_size());- get_input_tensor_data(ioIndex) =- TensorData{get_level_zero_input(ioIndex)->data(), get_level_zero_input(ioIndex)->get_byte_size()};++ioIndex;}@@ -157,9 +152,6 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&_levelZeroOutputTensors.at(ioIndex) =allocate_tensor(outputDescriptor, ioIndex, OUTPUT, *_outputAllocator, _graph->get_batch_size());- _outputTensorsData.at(ioIndex) =- std::optional(TensorData{_levelZeroOutputTensors.at(ioIndex)->data(),- _levelZeroOutputTensors.at(ioIndex)->get_byte_size()});++ioIndex;}@@ -183,14 +175,13 @@ void ZeroInferRequest::create_pipeline() {continue;}- _logger.debug("ZeroInferRequest::create_pipeline - allocate new tensor");+ _logger.debug("ZeroInferRequest::create_pipeline - allocate new input tensor %s",+ _metadata.inputs.at(inputIndex).nodeFriendlyName.c_str());get_level_zero_input(inputIndex) = allocate_tensor(_metadata.inputs.at(inputIndex),inputIndex,INPUT,*_inputAllocator,_graph->get_batch_size());- get_input_tensor_data(inputIndex) = std::optional(- TensorData{get_level_zero_input(inputIndex)->data(), get_level_zero_input(inputIndex)->get_byte_size()});}for (size_t outputIndex = 0; outputIndex < _metadata.outputs.size(); ++outputIndex) {@@ -199,15 +190,13 @@ void ZeroInferRequest::create_pipeline() {_metadata.outputs.at(outputIndex).nodeFriendlyName.c_str());continue;}- _logger.debug("ZeroInferRequest::create_pipeline - allocate new tensor");+ _logger.debug("ZeroInferRequest::create_pipeline - allocate new output tensor %s",+ _metadata.outputs.at(outputIndex).nodeFriendlyName.c_str());_levelZeroOutputTensors.at(outputIndex) = allocate_tensor(_metadata.outputs.at(outputIndex),outputIndex,OUTPUT,*_outputAllocator,_graph->get_batch_size());- _outputTensorsData.at(outputIndex) =- std::optional(TensorData{_levelZeroOutputTensors.at(outputIndex)->data(),- _levelZeroOutputTensors.at(outputIndex)->get_byte_size()});}// Find the corresponding command queue group.@@ -224,8 +213,8 @@ void ZeroInferRequest::create_pipeline() {_profilingPool,_profilingQuery,_npuProfiling,- _inputTensorsData,- _outputTensorsData,+ _levelZeroInputTensors,+ _levelZeroOutputTensors,groupOrdinal);_logger.debug("ZeroInferRequest::create_pipeline - SyncInferRequest completed");@@ -236,23 +225,15 @@ void ZeroInferRequest::set_tensor_data(const std::shared_ptr<ov::ITensor>& tensoconst bool isInput) {OV_ITT_TASK_CHAIN(ZERO_SET_TENSOR, itt::domains::LevelZeroBackend, "set_tensor", "set_tensor_data");auto& levelZeroTensors = isInput ? get_level_zero_input(index) : _levelZeroOutputTensors.at(index);- auto& tensorsData = isInput ? get_input_tensor_data(index) : _outputTensorsData.at(index);- bool setTensorData = false;- bool levelZeroTensorCreatedLocally = true;+ const auto& zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(tensor);- OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "check_data_allocation");- if (memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), tensor->data())) {- _logger.debug("ZeroInferRequest::set_tensor_data - tensor was created in the same L0 context");- levelZeroTensors = tensor;- levelZeroTensorCreatedLocally = false;- setTensorData = true;- }-- if (!setTensorData) {- // make sure that the L0 tensor was allocated locally and is not received from the user when receiving- // random tensor- if (tensorsData.has_value() && !tensorsData->levelZeroTensorCreatedLocally) {+ if (zeroTensor == nullptr) {+ OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "check_data_allocation");+ if (memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), tensor->data())) {+ _logger.debug("ZeroInferRequest::set_tensor_data - tensor was created in the same L0 context");+ levelZeroTensors = tensor;+ } else {_logger.debug("ZeroInferRequest::set_tensor_data - create locally L0 tensor");OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "allocate tensor");@@ -261,23 +242,19 @@ void ZeroInferRequest::set_tensor_data(const std::shared_ptr<ov::ITensor>& tensoisInput,isInput ? *_inputAllocator : *_outputAllocator,_graph->get_batch_size());-- setTensorData = true;- levelZeroTensorCreatedLocally = true;}- }-- if (setTensorData) {- tensorsData = std::optional(- TensorData{levelZeroTensors->data(), levelZeroTensors->get_byte_size(), levelZeroTensorCreatedLocally});if (_pipelineIsCreated) {_logger.debug("ZeroInferRequest::infer_async - update command list");+ OPENVINO_ASSERT(levelZeroTensors->data(), "Empty buffer");+OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "updateCommandList");- _pipeline->updateCommandList(*tensorsData,- isInput ? _graph->get_input_descriptors().at(index).idx- : _graph->get_output_descriptors().at(index).idx);+ _pipeline->updateCommandList(isInput ? _graph->get_input_descriptors().at(index).idx+ : _graph->get_output_descriptors().at(index).idx,+ levelZeroTensors->data(),+ levelZeroTensors->get_byte_size());+ _pipeline->closeCommandList();}}}@@ -294,23 +271,20 @@ void ZeroInferRequest::set_remote_tensor_data(const std::shared_ptr<ZeroRemoteTe}auto data = extract_object(tensor->get_properties(), ov::intel_npu::mem_handle);- if (data == nullptr) {- OPENVINO_THROW("Empty buffer");- }+ OPENVINO_ASSERT(data, "Empty buffer");auto& levelZeroTensors = isInput ? get_level_zero_input(index) : _levelZeroOutputTensors.at(index);- auto& tensorsData = isInput ? get_input_tensor_data(index) : _outputTensorsData.at(index);-levelZeroTensors = tensor;- tensorsData = std::optional(TensorData{data, tensor->get_byte_size(), false});if (_pipelineIsCreated) {_logger.debug("ZeroInferRequest::infer_async - update command list");OV_ITT_TASK_NEXT(ZERO_SET_REMOTE_TENSOR, "updateCommandList");_pipeline->updateCommandList(- *tensorsData,- isInput ? _graph->get_input_descriptors().at(index).idx : _graph->get_output_descriptors().at(index).idx);+ isInput ? _graph->get_input_descriptors().at(index).idx : _graph->get_output_descriptors().at(index).idx,+ data,+ tensor->get_byte_size());+ _pipeline->closeCommandList();}}@@ -333,8 +307,6 @@ void ZeroInferRequest::set_tensor(const ov::Output<const ov::Node>& port, const}if (is_batched_input(foundPort.idx)) {// resize vector size to 1 if set_tensor is called after set_tensors- get_input_tensors_data(foundPort.idx).resize(1);- get_input_tensors_data(foundPort.idx).shrink_to_fit();get_level_zero_inputs(foundPort.idx).resize(1);get_level_zero_inputs(foundPort.idx).shrink_to_fit();get_user_inputs(foundPort.idx).resize(1);@@ -345,6 +317,7 @@ void ZeroInferRequest::set_tensor(const ov::Output<const ov::Node>& port, const} else {if (_userOutputTensors.at(foundPort.idx)._ptr == tensor._ptr) {// Got set_tensor with the same object here too - do nothing+ _logger.debug("ZeroInferRequest::set_tensor - got the same tensor, do nothing");return;}_userOutputTensors.at(foundPort.idx) = tensor;@@ -382,13 +355,14 @@ void ZeroInferRequest::set_tensors(const ov::Output<const ov::Node>& port,get_user_inputs(foundPort.idx).resize(tensors.size());get_user_inputs(foundPort.idx) = tensors;+ void* data = nullptr;+if (_initStructs->getMutableCommandListVersion()) {if (_graph->get_batch_size().has_value()) {for (size_t i = 0; i < tensors.size(); i++) {auto remoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(tensors[i]._ptr);get_level_zero_inputs(foundPort.idx).resize(tensors.size());- get_input_tensors_data(foundPort.idx).resize(tensors.size());if (remoteTensor == nullptr) {bool tensorHasSameL0Context = false;@@ -409,26 +383,22 @@ void ZeroInferRequest::set_tensors(const ov::Output<const ov::Node>& port,allocate_tensor(_metadata.inputs.at(foundPort.idx), foundPort.idx, true, *_inputAllocator);}- get_input_tensor_data(foundPort.idx, i) =- std::optional(TensorData{get_level_zero_input(foundPort.idx, i)->data(),- get_level_zero_input(foundPort.idx, i)->get_byte_size(),- false});+ data = get_level_zero_input(foundPort.idx, i)->data();} else {_logger.debug("ZeroInferRequest::set_tensors - remote tensor is used");- get_input_tensor_data(foundPort.idx, i) = std::optional(- TensorData{extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle),- remoteTensor->get_byte_size(),- false});+ data = extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle);get_level_zero_input(foundPort.idx, i) = tensors.at(i)._ptr;}if (_pipelineIsCreated) {OV_ITT_TASK_NEXT(SET_TENSORS, "updateCommandList");- _pipeline->updateCommandList(*get_input_tensor_data(foundPort.idx, i),- _graph->get_input_descriptors().at(foundPort.idx).idx,- i);++ OPENVINO_ASSERT(data, "Empty buffer");++ _pipeline->updateCommandListIndex(_graph->get_input_descriptors().at(foundPort.idx).idx, data, i);+ _pipeline->closeCommandListIndex(i);}}}@@ -455,17 +425,17 @@ ov::SoPtr<ov::ITensor> ZeroInferRequest::get_tensor(const ov::Output<const ov::Nreturn userTensors;}- _logger.debug("ZeroInferRequest::get_tensor - tensor is not allocated, create the tensor");+ auto& metadata = isInput ? _metadata.inputs.at(ioIndex) : _metadata.outputs.at(ioIndex);+ _logger.debug("ZeroInferRequest::get_tensor - tensor is not allocated, create tensor %s",+ metadata.nodeFriendlyName.c_str());auto& levelZeroTensors = isInput ? get_level_zero_input(ioIndex) : _levelZeroOutputTensors.at(ioIndex);- auto& tensorsData = isInput ? get_input_tensor_data(ioIndex) : _outputTensorsData.at(ioIndex);- levelZeroTensors = allocate_tensor(isInput ? _metadata.inputs.at(ioIndex) : _metadata.outputs.at(ioIndex),+ levelZeroTensors = allocate_tensor(metadata,ioIndex,isInput,isInput ? *_inputAllocator : *_outputAllocator,_graph->get_batch_size());- tensorsData = std::optional(TensorData{levelZeroTensors->data(), levelZeroTensors->get_byte_size()});return levelZeroTensors;}@@ -491,6 +461,67 @@ void ZeroInferRequest::infer_async() {create_pipeline();_pipelineIsCreated = true;+ } else {+ if (_initStructs->getMutableCommandListVersion()) {+ bool closePipeline = false;+ size_t ioIndex = 0;++ for (const auto& levelZeroTensor : _levelZeroInputTensors) {+ const auto inputDescriptor = _metadata.inputs.at(ioIndex);+ auto zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(levelZeroTensor.at(SINGLE_TENSOR));++ if (is_batched_input(ioIndex) || inputDescriptor.isShapeTensor || inputDescriptor.isStateInput ||+ is_remote_tensor(levelZeroTensor.at(SINGLE_TENSOR)) || zeroTensor == nullptr) {+ ++ioIndex;+ continue;+ }++ if (zeroTensor->memory_address_changed()) {+ _logger.debug("Update input graph descriptor with the new tensor");+ OPENVINO_ASSERT(zeroTensor->data(), "Empty buffer");++ _pipeline->updateCommandList(_graph->get_input_descriptors().at(ioIndex).idx,+ zeroTensor->data(),+ zeroTensor->get_byte_size());+ closePipeline = true;++ zeroTensor->reset_memory_flag();+ }++ ++ioIndex;+ }++ ioIndex = 0;++ for (const auto& levelZeroTensor : _levelZeroOutputTensors) {+ const auto outputDescriptor = _metadata.outputs.at(ioIndex);+ auto zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(levelZeroTensor);++ if (outputDescriptor.isShapeTensor || outputDescriptor.isStateOutput ||+ is_remote_tensor(levelZeroTensor) || zeroTensor == nullptr) {+ ++ioIndex;+ continue;+ }++ if (zeroTensor->memory_address_changed()) {+ _logger.debug("Update output graph descriptor with the new tensor");+ OPENVINO_ASSERT(zeroTensor->data(), "Empty buffer");++ _pipeline->updateCommandList(_graph->get_output_descriptors().at(ioIndex).idx,+ zeroTensor->data(),+ zeroTensor->get_byte_size());+ closePipeline = true;++ zeroTensor->reset_memory_flag();+ }++ ++ioIndex;+ }++ if (closePipeline) {+ _pipeline->closeCommandList();+ }+ }}}@@ -512,9 +543,7 @@ void ZeroInferRequest::infer_async() {if (is_batched_input(inputIndex)) {if (_graph->get_batch_size().has_value()) {for (size_t i = 0; i < userTensor.size(); i++) {- auto levelZeroBatchRemoteTensor =- std::dynamic_pointer_cast<ZeroRemoteTensor>(get_level_zero_input(inputIndex, i));- if (levelZeroBatchRemoteTensor == nullptr) {+ if (!is_remote_tensor(get_level_zero_input(inputIndex, i))) {void* levelZeroBuffer = get_level_zero_input(inputIndex, i)->data();auto userBatchRemoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(userTensor.at(i)._ptr);@@ -563,9 +592,8 @@ void ZeroInferRequest::infer_async() {? userTensor.at(SINGLE_TENSOR)->data(): extract_object(userRemoteTensor->get_properties(), ov::intel_npu::mem_handle);- const std::shared_ptr<ov::ITensor>& levelZeroTensor = get_level_zero_input(inputIndex);- auto levelZeroRemoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(levelZeroTensor);- if (levelZeroRemoteTensor == nullptr) {+ const auto& levelZeroTensor = get_level_zero_input(inputIndex);+ if (!is_remote_tensor(levelZeroTensor)) {void* levelZeroBuffer = levelZeroTensor->data();if (userBuffer != levelZeroBuffer) {@@ -616,8 +644,7 @@ void ZeroInferRequest::get_result() {: extract_object(userRemoteTensor->get_properties(), ov::intel_npu::mem_handle);const std::shared_ptr<ov::ITensor>& levelZeroTensor = _levelZeroOutputTensors.at(outputIndex);- auto levelZeroRemoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(levelZeroTensor);- if (levelZeroRemoteTensor == nullptr) {+ if (!is_remote_tensor(levelZeroTensor)) {void* levelZeroBuffer = levelZeroTensor->data();if (userBuffer != levelZeroBuffer) {@@ -703,6 +730,14 @@ std::vector<ov::ProfilingInfo> ZeroInferRequest::get_profiling_info() const {}}+std::shared_ptr<ov::ITensor> ZeroInferRequest::create_tensor(ov::element::Type type,+ const ov::Shape& shape,+ const ov::Allocator& allocator) const {+ OPENVINO_ASSERT(allocator, "Allocator mush be provided when creating a zero tensor!");++ return std::make_shared<ZeroTensor>(_initStructs, type, shape, allocator);+}+std::vector<uint8_t> ZeroInferRequest::get_raw_profiling_data() const {return _profilingQuery.getData<uint8_t>();}@@ -714,10 +749,3 @@ std::shared_ptr<ov::ITensor>& ZeroInferRequest::get_level_zero_input(size_t indestd::vector<std::shared_ptr<ov::ITensor>>& ZeroInferRequest::get_level_zero_inputs(size_t index) const {return _levelZeroInputTensors.at(index);}--std::optional<TensorData>& ZeroInferRequest::get_input_tensor_data(size_t index, size_t tensorNo) const {- return _inputTensorsData.at(index).at(tensorNo);-}-std::vector<std::optional<TensorData>>& ZeroInferRequest::get_input_tensors_data(size_t index) const {- return _inputTensorsData.at(index);-}diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex d7f06b81381..ef36c98b916 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -13,25 +13,41 @@#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"#include "intel_npu/utils/zero/zero_types.hpp"+#include "zero_remote_tensor.hpp"++namespace {++template <typename Type>+Type extract_object(const ov::AnyMap& params, const ov::Property<Type>& p) {+ auto itrHandle = params.find(p.name());+ ov::Any res = nullptr;+ if (itrHandle == params.end()) {+ OPENVINO_THROW("No parameter ", p.name(), " found in parameters map");+ }+ res = itrHandle->second;+ return res.as<Type>();+}++} // namespacenamespace intel_npu {Pipeline::Pipeline(const Config& config,- const std::shared_ptr<ZeroInitStructsHolder>& initStructs,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,const std::shared_ptr<IGraph>& graph,zeroProfiling::ProfilingPool& profiling_pool,zeroProfiling::ProfilingQuery& profiling_query,const std::shared_ptr<zeroProfiling::NpuInferProfiling>& npu_profiling,- const std::vector<std::vector<std::optional<TensorData>>>& inputTensorsData,- const std::vector<std::optional<TensorData>>& outputTensorsData,+ const std::vector<std::vector<std::shared_ptr<ov::ITensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ov::ITensor>>& output_tensors,uint32_t group_ordinal): _graph(graph),_config(config),_id(_graph->get_unique_id()),_number_of_command_lists(_graph->get_batch_size().has_value() ? *_graph->get_batch_size() : 1),_event_pool{- std::make_shared<EventPool>(initStructs->getDevice(),- initStructs->getContext(),+ std::make_shared<EventPool>(init_structs->getDevice(),+ init_structs->getContext(),_number_of_command_lists ? static_cast<uint32_t>(_number_of_command_lists) : 1)},_npu_profiling(npu_profiling),_logger("Pipeline", _config.get<LOG_LEVEL>()) {@@ -48,36 +64,62 @@ Pipeline::Pipeline(const Config& config,_logger.debug("Pipeline - emplace_back _event_pool and _command_queue");for (size_t i = 0; i < _number_of_command_lists; i++) {_command_lists.emplace_back(- std::make_unique<CommandList>(initStructs,+ std::make_unique<CommandList>(init_structs,group_ordinal,- initStructs->getMutableCommandListVersion() ? true : false));+ init_structs->getMutableCommandListVersion() ? true : false));_events.emplace_back(std::make_shared<Event>(_event_pool, static_cast<uint32_t>(i)));_fences.emplace_back(std::make_unique<Fence>(*_graph->get_command_queue()));}for (size_t i = 0; i < _number_of_command_lists; i++) {- size_t ioIndex = 0;+ size_t io_index = 0;for (const auto& desc : graph->get_input_descriptors()) {- if (inputTensorsData.at(ioIndex).size() > 1) {- graph->set_argument_value(desc.idx, inputTensorsData.at(ioIndex).at(i)->mem);-- ++ioIndex;+ if (input_tensors.at(io_index).size() > 1) {+ void* data = nullptr;+ auto remote_tensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(input_tensors.at(io_index).at(i));+ if (remote_tensor == nullptr) {+ data = input_tensors.at(io_index).at(i)->data();+ } else {+ data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle);+ }++ graph->set_argument_value(desc.idx, data);++ ++io_index;continue;}- graph->set_argument_value(desc.idx,- static_cast<unsigned char*>(inputTensorsData.at(ioIndex).at(0)->mem) +- (i * inputTensorsData.at(ioIndex).at(0)->size) / _number_of_command_lists);+ void* data = nullptr;+ auto remote_tensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(input_tensors.at(io_index).at(0));+ if (remote_tensor == nullptr) {+ data = input_tensors.at(io_index).at(0)->data();+ } else {+ data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle);+ }++ graph->set_argument_value(+ desc.idx,+ static_cast<unsigned char*>(data) ++ (i * input_tensors.at(io_index).at(0)->get_byte_size()) / _number_of_command_lists);- ++ioIndex;+ ++io_index;}- ioIndex = 0;+ io_index = 0;for (const auto& desc : graph->get_output_descriptors()) {- graph->set_argument_value(desc.idx,- static_cast<unsigned char*>(outputTensorsData.at(ioIndex)->mem) +- (i * outputTensorsData.at(ioIndex)->size) / _number_of_command_lists);- ++ioIndex;+ void* data = nullptr;+ auto remote_tensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(output_tensors.at(io_index));+ if (remote_tensor == nullptr) {+ data = output_tensors.at(io_index)->data();+ } else {+ data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle);+ }++ graph->set_argument_value(+ desc.idx,+ static_cast<unsigned char*>(data) ++ (i * output_tensors.at(io_index)->get_byte_size()) / _number_of_command_lists);+ ++io_index;}if (_config.get<RUN_INFERENCES_SEQUENTIALLY>()) {@@ -180,32 +222,54 @@ void Pipeline::reset() const {_logger.debug("Pipeline - rest() completed");};-void Pipeline::updateCommandList(const TensorData& tensorsData, uint32_t index) {+void Pipeline::updateCommandList(uint32_t arg_index, const void* arg_data, size_t byte_size) {OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "updateCommandList");_logger.debug("Pipeline - updateCommandList");- const size_t _number_of_command_lists = _command_lists.size();+ const size_t number_of_command_lists = _command_lists.size();- for (size_t i = 0; i < _number_of_command_lists; i++) {+ for (size_t i = 0; i < number_of_command_lists; i++) {_command_lists.at(i)->updateMutableCommandList(- index,- static_cast<unsigned char*>(tensorsData.mem) + (i * tensorsData.size) / _number_of_command_lists);+ arg_index,+ static_cast<const unsigned char*>(arg_data) + (i * byte_size) / number_of_command_lists);+ }+};++void Pipeline::closeCommandList() {+ OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "closeCommandList");+ _logger.debug("Pipeline - closeCommandList");++ const size_t number_of_command_lists = _command_lists.size();++ for (size_t i = 0; i < number_of_command_lists; i++) {_command_lists.at(i)->close();}};-void Pipeline::updateCommandList(const TensorData& tensorsData, uint32_t index, size_t commandListIndex) {- OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "updateCommandList");- _logger.debug("Pipeline - updateCommandList");+void Pipeline::updateCommandListIndex(uint32_t arg_index, const void* arg_data, size_t command_list_index) {+ OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "updateCommandListIndex");+ _logger.debug("Pipeline - updateCommandListIndex");++ const size_t number_of_command_lists = _command_lists.size();++ OPENVINO_ASSERT(command_list_index < number_of_command_lists,+ "Command list index is higher than the number of Command lists ",+ command_list_index);++ _command_lists.at(command_list_index)->updateMutableCommandList(arg_index, arg_data);+};++void Pipeline::closeCommandListIndex(size_t command_list_index) {+ OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "closeCommandListIndex");+ _logger.debug("Pipeline - closeCommandListIndex");- const size_t _number_of_command_lists = _command_lists.size();+ const size_t number_of_command_lists = _command_lists.size();- OPENVINO_ASSERT(commandListIndex < _number_of_command_lists,- "Command list index is higgher than the number of Command lists ",- commandListIndex);+ OPENVINO_ASSERT(command_list_index < number_of_command_lists,+ "Command list index is higher than the number of Command lists ",+ command_list_index);- _command_lists.at(commandListIndex)->updateMutableCommandList(index, tensorsData.mem);- _command_lists.at(commandListIndex)->close();+ _command_lists.at(command_list_index)->close();};} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp b/src/plugins/intel_npu/src/backend/src/zero_tensor.cppnew file mode 100644index 00000000000..b2b5cc7c9b1--- /dev/null+++ b/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp@@ -0,0 +1,152 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "zero_tensor.hpp"++#include "openvino/core/type/element_iterator.hpp"+#include "openvino/runtime/properties.hpp"+#include "openvino/runtime/tensor.hpp"++namespace intel_npu {++ZeroTensor::ZeroTensor(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const ov::element::Type element_type,+ const ov::Shape& shape,+ const ov::Allocator& allocator)+ : _init_structs(init_structs),+ _element_type{element_type},+ _shape{shape},+ _capacity{_shape},+ _strides{},+ _strides_once{},+ _allocator{allocator} {+ OPENVINO_ASSERT(_element_type != ov::element::undefined && _element_type.is_static());+ OPENVINO_ASSERT(allocator, "Allocator was not initialized");+ const auto byte_size = ov::element::get_memory_size(_element_type, shape_size(_shape));+ auto data = const_cast<ov::Allocator&>(_allocator).allocate(byte_size);+ OPENVINO_ASSERT(byte_size == 0 || data != nullptr, "Failed to allocate memory");+ initialize_elements(data, element_type, _shape);+ _ptr = data;+}++void* ZeroTensor::data(const ov::element::Type& element_type) const {+ if (element_type != ov::element::undefined && element_type != ov::element::dynamic &&+ (element_type.bitwidth() != get_element_type().bitwidth() ||+ element_type.is_real() != get_element_type().is_real() ||+ (element_type == ov::element::string && get_element_type() != ov::element::string) ||+ (element_type != ov::element::string && get_element_type() == ov::element::string))) {+ OPENVINO_THROW("Tensor data with element type ",+ get_element_type(),+ ", is not representable as pointer to ",+ element_type);+ }+ return _ptr;+}++const ov::element::Type& ZeroTensor::get_element_type() const {+ return _element_type;+}++const ov::Shape& ZeroTensor::get_shape() const {+ return _shape;+}++void ZeroTensor::update_strides() const {+ if (_element_type.bitwidth() < 8) {+ return;+ }++ auto& shape = get_shape();+ if (_strides.empty() && !shape.empty()) {+ _strides.resize(shape.size());+ _strides.back() = shape.back() == 0 ? 0 : _element_type.size();+ std::transform(shape.crbegin(),+ shape.crend() - 1,+ _strides.rbegin(),+ _strides.rbegin() + 1,+ std::multiplies<size_t>());+ }+}++const ov::Strides& ZeroTensor::get_strides() const {+ OPENVINO_ASSERT(_element_type.bitwidth() >= 8,+ "Could not get strides for types with bitwidths less then 8 bit. Tensor type: ",+ _element_type);+ std::call_once(_strides_once, &ZeroTensor::update_strides, this);+ return _strides;+}++void ZeroTensor::initialize_elements(void* data, const ov::element::Type& element_type, const ov::Shape& shape) {+ if (element_type == ov::element::Type_t::string) {+ auto num_elements = shape_size(shape);+ auto string_ptr = static_cast<std::string*>(data);+ std::uninitialized_fill_n(string_ptr, num_elements, std::string());+ }+}++size_t ZeroTensor::get_capacity() const {+ return shape_size(_capacity);+}++size_t ZeroTensor::get_bytes_capacity() const {+ return ov::element::get_memory_size(get_element_type(), get_capacity());+}++void ZeroTensor::destroy_elements(size_t begin_ind, size_t end_ind) {+ // it removes elements from tail+ if (get_element_type() == ov::element::Type_t::string) {+ auto strings = static_cast<std::string*>(_ptr);+ for (size_t ind = begin_ind; ind < end_ind; ++ind) {+ using std::string;+ strings[ind].~string();+ }+ }+}++void ZeroTensor::destroy_memory() {+ destroy_elements(0, get_capacity());+ _allocator.deallocate(_ptr, get_bytes_capacity());+ _ptr = nullptr;+}++void ZeroTensor::set_shape(ov::Shape new_shape) {+ if (_shape == new_shape) {+ return;+ }++ _shape = std::move(new_shape);++ if (get_size() > get_capacity()) {+ if (!_init_structs->getMutableCommandListVersion()) {+ OPENVINO_THROW("Re-shaping the tensor with a larger shape is not available using this driver version. "+ "Please update the driver to the latest version.");+ }++ destroy_memory();++ // allocate buffer and initialize objects from scratch+ _capacity = _shape;+ _ptr = _allocator.allocate(get_bytes_capacity());+ initialize_elements(_ptr, _element_type, _shape);++ _reset_tensor_memory = true;+ }++ _strides.clear();+ update_strides();+}++bool ZeroTensor::memory_address_changed() {+ return _reset_tensor_memory;+}++void ZeroTensor::reset_memory_flag() {+ _reset_tensor_memory = false;+}++ZeroTensor::~ZeroTensor() {+ destroy_memory();+}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hppindex 8a6edeb2e8d..e96f02cd582 100644--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/remote_tensor.hpp@@ -24,8 +24,6 @@ public:const ov::element::Type& element_type,const ov::Shape& shape);- ~RemoteTensor() override;-/*** @brief Returns additional information associated with tensor* @return Map of property names to properties@@ -40,7 +38,7 @@ public:/*** @brief Set new shape for tensor- * @note Memory allocation may happen+ * @note Allocation of a bigger tensor is not possible* @param shape A new shape*/void set_shape(ov::Shape shape) override;@@ -70,6 +68,8 @@ protected:virtual bool deallocate() noexcept = 0;void update_strides();+ virtual ~RemoteTensor();+std::shared_ptr<ov::IRemoteContext> _context;ov::element::Type _element_type;diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hppindex 788ce87136a..635802900d3 100644--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp@@ -163,6 +163,10 @@ protected:const ov::Allocator& allocator = {},const std::optional<std::size_t> batchSize = std::nullopt) const;+ virtual std::shared_ptr<ov::ITensor> create_tensor(ov::element::Type type,+ const ov::Shape& shape,+ const ov::Allocator& allocator = {}) const;+bool is_batched_input(size_t idx) const;ov::SoPtr<ov::ITensor>& get_user_input(size_t index) const;diff --git a/src/plugins/intel_npu/src/common/src/remote_tensor.cpp b/src/plugins/intel_npu/src/common/src/remote_tensor.cppindex a12ac7dca81..40804bffed2 100644--- a/src/plugins/intel_npu/src/common/src/remote_tensor.cpp+++ b/src/plugins/intel_npu/src/common/src/remote_tensor.cpp@@ -40,19 +40,18 @@ const ov::AnyMap& RemoteTensor::get_properties() const {}void RemoteTensor::set_shape(ov::Shape new_shape) {+ if (_shape == new_shape) {+ return;+ }+_shape = std::move(new_shape);if (ov::shape_size(_shape) > ov::shape_size(_capacity)) {- if (!deallocate()) {- OPENVINO_THROW("Cannot deallocate tensor while an attempt to enlarge tensor area in set_shape.");- }-- const auto byte_size = ov::element::get_memory_size(_element_type, shape_size(_shape));- allocate(byte_size);- } else {- _strides.clear();- update_strides();+ OPENVINO_THROW("Cannot set a new bigger shape to this tensor.");}++ _strides.clear();+ update_strides();}void RemoteTensor::update_strides() {diff --git a/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp b/src/plugins/intel_npu/src/common/src/sync_infer_request.cppindex 1379112b3a7..fe331a3c6da 100644--- a/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp+++ b/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp@@ -316,10 +316,8 @@ std::shared_ptr<ov::ITensor> SyncInferRequest::allocate_tensor(const IODescripto"The link between state descriptors is missing, state name: ",descriptor.nameFromCompiler);tensor = get_user_input(*descriptor.relatedDescriptorIndex)._ptr;- } else if (allocator) {- tensor = ov::make_tensor(descriptor.precision, allocatedTensorShape, allocator);} else {- tensor = ov::make_tensor(descriptor.precision, allocatedTensorShape);+ tensor = create_tensor(descriptor.precision, allocatedTensorShape, allocator);}if (isInput) {@@ -337,6 +335,12 @@ std::shared_ptr<ov::ITensor> SyncInferRequest::allocate_tensor(const IODescriptoreturn tensor;}+std::shared_ptr<ov::ITensor> SyncInferRequest::create_tensor(ov::element::Type type,+ const ov::Shape& shape,+ const ov::Allocator& allocator) const {+ return ov::make_tensor(type, shape, allocator);+}+bool SyncInferRequest::is_batched_input(size_t idx) const {return _userInputTensors.at(idx).size() > 1;}diff --git a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.cpp b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.cppindex d14f188a18c..a08467bd2a7 100644--- a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.cpp@@ -25,6 +25,12 @@ INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,::testing::ValuesIn(configsInferRequestRunTests)),InferRequestRunTests::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,+ SetShapeInferRunTests,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::ValuesIn(configsInferRequestRunTests)),+ InferRequestRunTests::getTestCaseName);+const std::vector<ov::AnyMap> batchingConfigs = {{ov::log::level(ov::log::Level::WARNING), ov::intel_npu::batch_mode(ov::intel_npu::BatchMode::PLUGIN)},{ov::log::level(ov::log::Level::WARNING), ov::intel_npu::batch_mode(ov::intel_npu::BatchMode::COMPILER)},diff --git a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hppindex 9b63b96ba4e..5f5cf1941d7 100644--- a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp@@ -24,6 +24,7 @@#include "openvino/opsets/opset8.hpp"#include "openvino/runtime/compiled_model.hpp"#include "openvino/runtime/core.hpp"+#include "openvino/runtime/intel_npu/level_zero/level_zero.hpp"#include "overload/overload_test_utils_npu.hpp"using CompilationParams = std::tuple<std::string, // Device name@@ -782,6 +783,76 @@ TEST_P(ROITensorInference, InferenceROITensor) {"The tensor is not continuous");}+using SetShapeInferRunTests = InferRequestRunTests;++TEST_P(SetShapeInferRunTests, checkResultsAfterIOBlobReallocation) {+ // Skip test according to plugin specific disabledTestPatterns() (if any)+ SKIP_IF_CURRENT_TEST_IS_DISABLED()++ auto original_shape = Shape{1, 10, 10, 10};+ auto dummy_shape = Shape{1, 50, 100, 100};+ auto shape_size = ov::shape_size(original_shape);+ auto model = createModel(element::f32, original_shape, "N...");++ auto context = core->get_default_context(target_device);++ compiled_model = core->compile_model(model, target_device, configuration);+ ov::InferRequest inference_request;+ inference_request = compiled_model.create_infer_request();++ input = compiled_model.input();+ output = compiled_model.output();++ ov::Tensor input_tensor, first_output_tensor, second_output_tensor;+ auto in_shape = input.get_shape();+ auto out_shape = output.get_shape();++ OV_ASSERT_NO_THROW(input_tensor = inference_request.get_tensor(input));+ auto* input_data = input_tensor.data<float>();+ for (size_t i = 0; i < shape_size; ++i) {+ input_data[i] = 5.f;+ }++ OV_ASSERT_NO_THROW(inference_request.infer());+ OV_ASSERT_NO_THROW(first_output_tensor = inference_request.get_tensor(output));+ // create dummy Tensors to force the driver to allocate memory for the initial tensor somewhere else+ [[maybe_unused]] auto l0_host_dummy_tensor_0 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_1 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_2 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_3 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_4 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_5 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_6 = context.create_host_tensor(ov::element::f32, dummy_shape);+ [[maybe_unused]] auto l0_host_dummy_tensor_7 = context.create_host_tensor(ov::element::f32, dummy_shape);++ auto* actual = first_output_tensor.data<float>();+ for (size_t i = 0; i < shape_size; ++i) {+ EXPECT_NEAR(actual[i], 6.f, 1e-5) << "Expected=6, actual=" << actual[i] << " for index " << i;+ }++ // imitates blob reallocation+ OV_ASSERT_NO_THROW(input_tensor.set_shape({1, 50, 20, 20}));+ OV_ASSERT_NO_THROW(input_tensor.set_shape(in_shape));++ OV_ASSERT_NO_THROW(second_output_tensor = inference_request.get_tensor(output));+ OV_ASSERT_NO_THROW(second_output_tensor.set_shape({1, 20, 20, 20}));+ OV_ASSERT_NO_THROW(second_output_tensor.set_shape(out_shape));++ OV_ASSERT_NO_THROW(input_tensor = inference_request.get_tensor(input));+ input_data = input_tensor.data<float>();+ for (size_t i = 0; i < shape_size; ++i) {+ input_data[i] = 9.f;+ }++ OV_ASSERT_NO_THROW(inference_request.infer());+ OV_ASSERT_NO_THROW(second_output_tensor = inference_request.get_tensor(output));++ actual = second_output_tensor.data<float>();+ for (size_t i = 0; i < shape_size; ++i) {+ EXPECT_NEAR(actual[i], 10.f, 1e-5) << "Expected=10, actual=" << actual[i] << " for index " << i;+ }+}+} // namespace behavior} // namespace test} // namespace ovdiff --git a/src/plugins/intel_npu/tests/functional/internal/overload/ov_infer_request/io_tensor.hpp b/src/plugins/intel_npu/tests/functional/internal/overload/ov_infer_request/io_tensor.hppindex eb8bc5bd636..e4539d1af09 100644--- a/src/plugins/intel_npu/tests/functional/internal/overload/ov_infer_request/io_tensor.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/overload/ov_infer_request/io_tensor.hpp@@ -5,6 +5,7 @@#pragma once#include <common_test_utils/ov_tensor_utils.hpp>+#include "behavior/ov_infer_request/io_tensor.hpp"#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"#include "overload/overload_test_utils_npu.hpp"@@ -160,6 +161,10 @@ TEST_P(OVInferRequestIOTensorTestNPU, canInferAfterIOBlobReallocation) {auto in_shape = input.get_shape();auto out_shape = output.get_shape();+ OV_ASSERT_NO_THROW(req.infer());+ OV_ASSERT_NO_THROW(req.start_async());+ OV_ASSERT_NO_THROW(req.wait());+// imitates blob reallocationOV_ASSERT_NO_THROW(input_tensor = req.get_tensor(input));OV_ASSERT_NO_THROW(input_tensor.set_shape({5, 5, 5, 5}));diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cppindex 9275e8b1dd2..1cf7a945ad4 100644--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/behavior/ov_infer_request/io_tensor.cpp@@ -22,31 +22,31 @@ const std::vector<ov::AnyMap> multiConfigs = {const std::vector<ov::AnyMap> autoConfigs = {{ov::device::priorities(ov::test::utils::DEVICE_NPU), ov::device::properties(ov::test::utils::DEVICE_NPU, {})}};-INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTests,+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,OVInferRequestIOTensorTest,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),::testing::ValuesIn(configs)),InferRequestParamsAnyMapTestName::getTestCaseName);-INSTANTIATE_TEST_SUITE_P(compatibility_smoke_Multi_BehaviorTests,+INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests,OVInferRequestIOTensorTest,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_MULTI),::testing::ValuesIn(multiConfigs)),InferRequestParamsAnyMapTestName::getTestCaseName);-INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTests,+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,OVInferRequestIOTensorTestNPU,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),::testing::ValuesIn(configs)),InferRequestParamsAnyMapTestName::getTestCaseName);-INSTANTIATE_TEST_SUITE_P(compatibility_smoke_Multi_BehaviorTests,+INSTANTIATE_TEST_SUITE_P(smoke_Multi_BehaviorTests,OVInferRequestIOTensorTestNPU,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_MULTI),::testing::ValuesIn(multiConfigs)),InferRequestParamsAnyMapTestName::getTestCaseName);-INSTANTIATE_TEST_SUITE_P(compatibility_smoke_Auto_BehaviorTests,+INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,OVInferRequestIOTensorTest,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_AUTO),::testing::ValuesIn(autoConfigs)),diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_npu/tests/functional/shared_tests_instances/skip_tests_config.cppindex d62747be75c..134ea3dd36b 100644--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/skip_tests_config.cpp+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/skip_tests_config.cpp@@ -295,13 +295,6 @@ std::vector<std::string> disabledTestPatterns() {".*CompilationForSpecificPlatform.*(3800|3900).*",});- // [Track number: E#67741]- _skipRegistry.addPatterns(- "Cannot call setShape for Blobs", {- R"(.*(smoke_Behavior|smoke_Auto_Behavior|smoke_Multi_Behavior).*OVInferRequestIOTensorTest.*canInferAfterIOBlobReallocation.*)",- R"(.*(smoke_Behavior|smoke_Auto_Behavior|smoke_Multi_Behavior).*OVInferRequestIOTensorTest.*InferStaticNetworkSetChangedInputTensorThrow.*targetDevice=(NPU_|MULTI_configItem=MULTI_DEVICE_PRIORITIES_NPU).*)"- });-// [Track number: E#67749]_skipRegistry.addPatterns("Can't loadNetwork without cache for ReadConcatSplitAssign with precision f32", {