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] Add dynamic host pipeline to support host compile (#33249)
Xin Wang0959946912ce
diff --git a/src/plugins/intel_npu/src/backend/CMakeLists.txt b/src/plugins/intel_npu/src/backend/CMakeLists.txtindex fd6e276e204..930d65ea7ae 100644--- a/src/plugins/intel_npu/src/backend/CMakeLists.txt+++ b/src/plugins/intel_npu/src/backend/CMakeLists.txt@@ -5,6 +5,7 @@set(TARGET_NAME "openvino_npu_level_zero_backend")file(GLOB_RECURSE SOURCES *.cpp *.hpp *.h)+source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})add_library(${TARGET_NAME} STATIC ${SOURCES})diff --git a/src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hpp b/src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hppnew file mode 100644index 00000000000..5b4e0147787--- /dev/null+++ b/src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hpp@@ -0,0 +1,50 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "intel_npu/utils/zero/zero_utils.hpp"+#include "zero_dynamic_pipeline.hpp"+#include "zero_infer_request.hpp"++namespace intel_npu {++class ZeroDynamicInferRequest final : public ZeroInferRequest {+public:+ explicit ZeroDynamicInferRequest(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,+ const std::shared_ptr<const ICompiledModel>& compiledModel,+ const Config& config);++ void infer_async() override;++protected:+ void construct_pipeline() override;++ /**+ * @brief Allocates a tensor on host and stores the reference inside multiple attributes.+ * @param index The index which the allocated tensor shall use.+ * @param isInput Determines the containers in which the newly allocated tensors will be stored.+ * @param batchSize If provided, the value of the shape on the 0th axis is overriden with this value.+ * @return Pointer towards the allocated tensor+ */+ std::shared_ptr<ZeroTensor> allocate_tensor(const size_t index,+ const bool isInput,+ const std::optional<std::size_t> batchSize = std::nullopt) const;++ void update_command_list_for_tensor(SyncInferRequest::FoundPort& foundPort,+ const ov::SoPtr<ov::ITensor>& tensor) override;++ void update_command_list_for_tensors(SyncInferRequest::FoundPort& foundPort,+ const std::vector<ov::SoPtr<ov::ITensor>>& tensors,+ std::optional<size_t> batchSizeCandidate = std::nullopt) override;+ void predict_shapes(std::vector<IDynamicGraph::MemRefType>& outputProps);++ void check_tensor_and_predicted_shapes(const std::vector<IDynamicGraph::MemRefType>& outputProps);++ void update_tensor(const std::vector<IDynamicGraph::MemRefType>& outputProps);++ bool _isTensorChanged = false;+};++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hppnew file mode 100644index 00000000000..3925083f4d9--- /dev/null+++ b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp@@ -0,0 +1,130 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "intel_npu/common/idynamic_graph.hpp"+#include "zero_pipeline.hpp"++namespace intel_npu {++struct DynamicPipeline : public Pipeline {+ struct PipelinedCommandLists {+ mutable IDynamicGraph::GraphArguments _binding;++ std::vector<std::unique_ptr<CommandList>> _commandLists;+ // Store command list handles to pass it to ExecutionEngine+ std::vector<ze_command_list_handle_t> _commandListHandles;++ PipelinedCommandLists(size_t numCommandLists,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const uint32_t& group_ordinal) {+ _commandLists.reserve(numCommandLists);+ for (size_t i = 0; i < numCommandLists; i++) {+ _commandLists.emplace_back(std::make_unique<CommandList>(init_structs, group_ordinal));+ }++ for (size_t i = 0; i < numCommandLists; i++) {+ _commandListHandles.push_back(_commandLists[i]->handle());+ }+ }++ size_t size() const {+ return _commandListHandles.size();+ }++ ze_command_list_handle_t* data() {+ return _commandListHandles.data();+ }++ void bind(IDynamicGraph* graph) {+ graph->getBinding(_binding);+ }++ std::vector<ze_command_list_handle_t>& getHandles() {+ return _commandListHandles;+ }++ IDynamicGraph::GraphArguments& getBinding() {+ return _binding;+ }++ void updateMutableCommandList(uint32_t arg_index,+ const void* arg_value,+ const ov::Strides& strides,+ const ov::Shape& shapes) {+ if (arg_index < _binding._inputs.size()) {+ _binding._inputs[arg_index].setArg(arg_value);+ // Only store the valid shape dimensions+ for (int64_t i = 0; i < _binding._inputs[arg_index]._dimsCount; i++) {+ _binding._inputs[arg_index]._sizes[i] = shapes[i];+ }++ if (!strides.empty()) {+ for (int64_t i = 0; i < _binding._inputs[arg_index]._dimsCount; i++) {+ _binding._inputs[arg_index]._strides[i] = strides[i];+ }+ } else {+ // Need stride based on element but not byte, calc from shape+ _binding._inputs[arg_index].updateStride();+ }+ } else {+ size_t output_index = static_cast<size_t>(arg_index) - _binding._inputs.size();+ if (output_index < _binding._outputs.size()) {+ _binding._outputs[output_index].setArg(arg_value);++ // Only store the valid shape dimensions+ for (int64_t i = 0; i < _binding._outputs[output_index]._dimsCount; i++) {+ _binding._outputs[output_index]._sizes[i] = shapes[i];+ }++ if (!strides.empty()) {+ for (int64_t i = 0; i < _binding._outputs[output_index]._dimsCount; i++) {+ _binding._outputs[output_index]._strides[i] = strides[i];+ }+ } else {+ // Need stride based on element but not byte, calc from shape+ _binding._outputs[output_index].updateStride();+ }+ }+ }+ }++ void resetCommandList() {+ for (auto& cmd_list : _commandLists) {+ cmd_list->reset();+ }+ }+ };++public:+ DynamicPipeline(const Config& config,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const std::shared_ptr<IGraph>& graph,+ const std::vector<std::vector<std::shared_ptr<ZeroTensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ZeroTensor>>& output_tensors,+ size_t batch_size = 1);++ DynamicPipeline(const DynamicPipeline&) = delete;+ DynamicPipeline& operator=(const DynamicPipeline&) = delete;+ virtual ~DynamicPipeline() = default;++ void push() override;+ void pull() override;+ void reset() const override;+ virtual void update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ [[maybe_unused]] std::shared_ptr<ov::ITensor> userTensor = nullptr) override;+ virtual void update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ size_t batch_index,+ [[maybe_unused]] std::shared_ptr<ov::ITensor> userTensor = nullptr) override;++ virtual std::vector<ov::ProfilingInfo> get_profiling_info() const override;++protected:+ std::vector<std::unique_ptr<PipelinedCommandLists>> _command_lists;+};++} // namespace intel_npudiff --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 e0989d86be4..8f526529b92 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@@ -17,7 +17,18 @@namespace intel_npu {-class ZeroInferRequest final : public SyncInferRequest {+constexpr std::size_t SINGLE_TENSOR = 0;+constexpr bool INPUT = true;+constexpr bool OUTPUT = false;++std::optional<size_t> determine_dynamic_batch_size(const IODescriptor& desc,+ const ov::PartialShape& ioShape,+ const std::shared_ptr<ov::ITensor>& tensor,+ const std::optional<size_t> batchSize);++void* get_tensor_data_ptr(const std::shared_ptr<ov::ITensor>& tensor);++class ZeroInferRequest : public SyncInferRequest {public:explicit ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,const std::shared_ptr<const ICompiledModel>& compiledModel,@@ -33,11 +44,12 @@ public:void get_result() override;-private:+protected:std::vector<ov::ProfilingInfo> get_profiling_info() const override;void check_network_precision(const ov::element::Type_t precision) const override;void create_pipeline();+ virtual void construct_pipeline();std::shared_ptr<ZeroTensor>& get_level_zero_input(size_t index, size_t tensorNo = 0) const;std::vector<std::shared_ptr<ZeroTensor>>& get_level_zero_inputs(size_t index) const;@@ -59,6 +71,15 @@ private:void update_pipeline_if_memory_changed();void update_states_if_memory_changed();+ virtual void update_command_list_for_tensor(SyncInferRequest::FoundPort& foundPort,+ const ov::SoPtr<ov::ITensor>& tensor);++ virtual void update_command_list_for_tensors(SyncInferRequest::FoundPort& foundPort,+ const std::vector<ov::SoPtr<ov::ITensor>>& tensors,+ std::optional<size_t> batchSizeCandidate = std::nullopt);++ virtual void prepare_inputs();+const std::shared_ptr<ZeroInitStructsHolder> _initStructs;const std::shared_ptr<IGraph> _graph;const Config _config;diff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hppindex f37893b52a9..05eb0ddedd4 100644--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp@@ -11,7 +11,7 @@namespace intel_npu {-struct Pipeline final {+struct Pipeline {public:Pipeline(const Config& config,const std::shared_ptr<ZeroInitStructsHolder>& init_structs,@@ -20,18 +20,31 @@ public:const std::vector<std::shared_ptr<ZeroTensor>>& output_tensors,size_t batch_size = 1);+ Pipeline(const Config& config,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const std::shared_ptr<IGraph>& graph,+ const std::vector<std::vector<std::shared_ptr<ZeroTensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ZeroTensor>>& output_tensors,+ const char* logName,+ size_t batch_size = 1);+Pipeline(const Pipeline&) = delete;Pipeline& operator=(const Pipeline&) = delete;- ~Pipeline() = default;+ virtual ~Pipeline() = default;- void push();- void pull();- void reset() const;+ virtual void push();+ virtual void pull();+ virtual void reset() const;- void update_graph_arguments(uint32_t index, const std::shared_ptr<ZeroTensor>& tensor);- void update_graph_arguments(uint32_t index, const std::shared_ptr<ZeroTensor>& tensor, size_t batch_index);+ virtual void update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ [[maybe_unused]] std::shared_ptr<ov::ITensor> userTensor = nullptr);+ virtual void update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ size_t batch_index,+ [[maybe_unused]] std::shared_ptr<ov::ITensor> userTensor = nullptr);- std::vector<ov::ProfilingInfo> get_profiling_info() const;+ virtual std::vector<ov::ProfilingInfo> get_profiling_info() const;protected:std::shared_ptr<ZeroInitStructsHolder> _init_structs;diff --git a/src/plugins/intel_npu/src/backend/src/zero_device.cpp b/src/plugins/intel_npu/src/backend/src/zero_device.cppindex db98db56b17..c93ec9d45d2 100644--- a/src/plugins/intel_npu/src/backend/src/zero_device.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_device.cpp@@ -7,6 +7,7 @@#include "intel_npu/common/itt.hpp"#include "intel_npu/utils/zero/zero_api.hpp"#include "intel_npu/utils/zero/zero_utils.hpp"+#include "zero_dynamic_infer_request.hpp"#include "zero_infer_request.hpp"using namespace intel_npu;@@ -176,6 +177,9 @@ ov::device::Type ZeroDevice::getDeviceType() const {std::shared_ptr<SyncInferRequest> ZeroDevice::createInferRequest(const std::shared_ptr<const ICompiledModel>& compiledModel,const Config& config) {+ if (dynamic_cast<IDynamicGraph*>(compiledModel->get_graph().get())) {+ return std::make_shared<ZeroDynamicInferRequest>(_initStructs, compiledModel, config);+ }return std::make_shared<ZeroInferRequest>(_initStructs, compiledModel, config);}diff --git a/src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cppnew file mode 100644index 00000000000..11699ba325a--- /dev/null+++ b/src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cpp@@ -0,0 +1,333 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "zero_dynamic_infer_request.hpp"++#include "intel_npu/common/itt.hpp"+#include "intel_npu/prefix.hpp"+#include "intel_npu/utils/utils.hpp"+#include "openvino/runtime/make_tensor.hpp"++using namespace intel_npu;++ZeroDynamicInferRequest::ZeroDynamicInferRequest(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,+ const std::shared_ptr<const ICompiledModel>& compiledModel,+ const Config& config)+ : ZeroInferRequest(initStructs, compiledModel, config) {+ _logger.setName("ZeroDynamicInferRequest");+}++void ZeroDynamicInferRequest::construct_pipeline() {+ _logger.debug("create_pipeline - constructing pipeline");+ auto batchSize = _graph->get_batch_size();+ // Construct pipeline+ _pipeline =+ std::make_unique<DynamicPipeline>(_config,+ _initStructs,+ _graph,+ _levelZeroInputTensors,+ _levelZeroOutputTensors,+ batchSize.has_value() ? batchSize.value() : utils::DEFAULT_BATCH_SIZE);++ _logger.debug("create_pipeline - completed");+}++void ZeroDynamicInferRequest::update_command_list_for_tensor(SyncInferRequest::FoundPort& foundPort,+ const ov::SoPtr<ov::ITensor>& tensor) {+ OV_ITT_TASK_CHAIN(ZERO_SET_TENSOR, itt::domains::LevelZeroBackend, "set_tensor", "update_command_list_for_tensor");+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {+ auto& levelZeroTensor =+ foundPort.is_input() ? get_level_zero_input(foundPort.idx) : _levelZeroOutputTensors.at(foundPort.idx);++ try {+ _logger.debug("set_tensor - create zero tensor");+ OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "create zero tensor");+ // Try to use the user tensor directly if its underlying data is already allocated in the same Level Zero+ // context.+ levelZeroTensor = std::make_shared<ZeroTensor>(_initStructs, _config, tensor);+ } catch (const ZeroMemException& exception) {+ _logger.debug("set_tensor - exception caught while trying to create a Level Zero tensor "+ "from the user tensor: %s",+ exception.what());++ // Check if the current Level Zero tensor was previously shared with the user. If so, it cannot be reused;+ // allocate a new tensor to back up the user tensor (which cannot be imported or used directly).+ if (_dynamicBatchValueChanged || levelZeroTensor == nullptr || !levelZeroTensor->can_be_reused() ||+ (levelZeroTensor != nullptr && (levelZeroTensor->get_byte_size() < tensor->get_byte_size()))) {+ _logger.debug("set_tensor - allocate locally L0 tensor");+ OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "allocate tensor");++ auto batch = _graph->get_batch_size();+ levelZeroTensor = allocate_tensor(foundPort.idx, foundPort.is_input(), batch);+ } else {+ _logger.debug("set_tensor - reusing the level zero tensor since it is not shared "+ "with the user, and old L0 tensor is large enough");+ }+ }++ if (_pipelineIsCreated && !_dynamicBatchValueChanged) {+ _logger.debug("infer_async - update command list");++ OPENVINO_ASSERT(levelZeroTensor->data(), "Empty buffer");++ OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "update_graph_arguments");+ if (levelZeroTensor->get_byte_size() != tensor->get_byte_size()) {+ _pipeline->update_graph_arguments(foundPort.is_input()+ ? _metadata.inputs.at(foundPort.idx).indexUsedByDriver+ : _metadata.outputs.at(foundPort.idx).indexUsedByDriver,+ levelZeroTensor,+ tensor._ptr);+ _isTensorChanged = true;+ } else {+ // This L0 tensor shall have same info with user tensor+ _pipeline->update_graph_arguments(foundPort.is_input()+ ? _metadata.inputs.at(foundPort.idx).indexUsedByDriver+ : _metadata.outputs.at(foundPort.idx).indexUsedByDriver,+ levelZeroTensor);+ }+ }+ }+ if (!_pipelineIsCreated) {+ // If pipeline is not created, need to predict real output shape+ _isTensorChanged = true;+ }+ // If command list updates are not supported, fallback to copying tensors every time.+}++void ZeroDynamicInferRequest::update_command_list_for_tensors(SyncInferRequest::FoundPort& foundPort,+ const std::vector<ov::SoPtr<ov::ITensor>>& tensors,+ std::optional<size_t> batchSizeCandidate) {+ OV_ITT_TASK_CHAIN(ZERO_SET_TENSORS,+ itt::domains::LevelZeroBackend,+ "set_tensors",+ "update_command_list_for_tensors");+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0) && batchSizeCandidate.has_value()) {+ get_level_zero_inputs(foundPort.idx).resize(tensors.size());++ for (size_t i = 0; i < tensors.size(); i++) {+ try {+ _logger.debug("set_tensors - create zero tensor");+ OV_ITT_TASK_NEXT(ZERO_SET_TENSORS, "create zero tensor");+ get_level_zero_input(foundPort.idx, i) =+ std::make_shared<ZeroTensor>(_initStructs, _config, tensors.at(i));+ } catch (const ZeroMemException& exception) {+ _logger.debug("set_tensors - exception caught while trying to create a Level "+ "Zero tensor "+ "from the user tensor: %s",+ exception.what());++ _logger.debug("set_tensors - allocate locally L0 tensor");+ OV_ITT_TASK_NEXT(ZERO_SET_TENSORS, "allocate tensor");+ get_level_zero_input(foundPort.idx, i) = allocate_tensor(foundPort.idx, INPUT, batchSizeCandidate);+ }++ if (_pipelineIsCreated && !_dynamicBatchValueChanged) {+ OPENVINO_ASSERT(get_level_zero_input(foundPort.idx, i)->data(), "Empty buffer");+ OV_ITT_TASK_NEXT(ZERO_SET_TENSORS, "updateCommandList");+ _pipeline->update_graph_arguments(_metadata.inputs.at(foundPort.idx).indexUsedByDriver,+ get_level_zero_input(foundPort.idx, i),+ i,+ tensors.at(i)._ptr);+ _isTensorChanged = true;+ }+ }+ }+ if (!_pipelineIsCreated) {+ // If pipeline is not created, need to predict real output shape+ _isTensorChanged = true;+ }+ // If command list updates are not supported, fallback to copying tensors every time.+}++std::shared_ptr<ZeroTensor> ZeroDynamicInferRequest::allocate_tensor(const size_t index,+ const bool isInput,+ const std::optional<std::size_t> batchSize) const {+ IODescriptor descriptor = isInput ? _metadata.inputs.at(index) : _metadata.outputs.at(index);+ // Create new IODescriptor based on user input|output and descriptor+ if (isInput && get_user_input(index) != nullptr) {+ _logger.debug("Update input descriptor with shape from user input : %s instead of %s",+ get_user_input(index)->get_shape().to_string().c_str(),+ descriptor.shapeFromCompiler.to_string().c_str());+ descriptor.shapeFromCompiler = get_user_input(index)->get_shape();+ } else if (!isInput && _userOutputTensors.at(index) != nullptr) {+ _logger.debug("Update output descriptor with shape from user output : %s instead of %s",+ _userOutputTensors.at(index)->get_shape().to_string().c_str(),+ descriptor.shapeFromCompiler.to_string().c_str());+ descriptor.shapeFromCompiler = _userOutputTensors.at(index)->get_shape();+ }++ check_network_precision(descriptor.precision);++ ov::Shape allocatedTensorShape = descriptor.shapeFromCompiler.get_max_shape();++ if (batchSize.has_value()) {+ allocatedTensorShape[utils::BATCH_AXIS] = *batchSize;+ }++ auto tensor =+ std::make_shared<ZeroTensor>(_initStructs, _config, descriptor.precision, allocatedTensorShape, isInput);++ if (isInput) {+ if (get_user_input(index) == nullptr) {+ get_user_input(index) = tensor;+ }+ } else if (_userOutputTensors.at(index) == nullptr) {+ _userOutputTensors.at(index) = tensor;+ }++ return tensor;+}++void ZeroDynamicInferRequest::infer_async() {+ _logger.debug("infer_async started");+ OV_ITT_TASK_CHAIN(ZERO_INFER, itt::domains::LevelZeroBackend, "infer_async", "start");+ // Store the predicted output shapes+ std::vector<IDynamicGraph::MemRefType> outputPros;+ predict_shapes(outputPros);+ check_tensor_and_predicted_shapes(outputPros);+ prepare_inputs();+ update_tensor(outputPros);++ OV_ITT_TASK_NEXT(ZERO_INFER, "push");+ _pipeline->push();+}++void ZeroDynamicInferRequest::predict_shapes(std::vector<IDynamicGraph::MemRefType>& outputProps) {+ // TODO: If current output tensor is not large enough to be compatible with input tensor, need recreate pipeline+ // But reshape ZeroTensor can be used to avoid recreate pipeline now+ // bool reCreatePipeline = false;+ // Predict output shapes based on current inputs+ intel_npu::IDynamicGraph* dynamicGraph = dynamic_cast<intel_npu::IDynamicGraph*>(_graph.get());+ if (dynamicGraph && _isTensorChanged) {+ IDynamicGraph::GraphArguments graphArgs;+ // Need change to use arguments in pipeline+ dynamicGraph->getBinding(graphArgs);+ std::vector<IDynamicGraph::MemRefType> inputPros = graphArgs._inputs;+ outputProps = graphArgs._outputs;++ // TODO: Support Batch later+ // Update input Info+ // TENTATIVE CODE TO ALLOCATE a memref handle+ for (size_t i = 0; i < inputPros.size(); ++i) {+ auto& levelZeroTensor = get_level_zero_input(i);+ auto& userTensor = get_user_input(i);+ if (userTensor != nullptr) {+ // If userTensor is set, use userTensor to update memref handle+ inputPros[i].set(get_tensor_data_ptr(userTensor._ptr), 0, userTensor._ptr);+ } else if (levelZeroTensor != nullptr) {+ // If userTensor is not set, use levelZeroTensor to update memref handle+ inputPros[i].set(get_tensor_data_ptr(levelZeroTensor), 0, levelZeroTensor);+ } else {+ // If all tensors are not set, use metadata+ inputPros[i].setArg(nullptr);+ inputPros[i]._offset = 0;+ // TODO : BatchSize not checked here+ inputPros[i].setSize(_metadata.inputs.at(i).shapeFromCompiler.get_max_shape());+ inputPros[i].updateStride();+ }+ }++ // Update output Info+ for (size_t i = 0; i < outputProps.size(); ++i) {+ auto& levelZeroTensor = _levelZeroOutputTensors.at(i);+ auto& userTensor = _userOutputTensors.at(i);+ if (userTensor != nullptr) {+ // If userTensor is set, use userTensor to update memref handle+ outputProps[i].set(get_tensor_data_ptr(userTensor._ptr), 0, userTensor._ptr);+ } else if (levelZeroTensor != nullptr) {+ // If userTensor is not set, use levelZeroTensor to update memref handle+ outputProps[i].set(get_tensor_data_ptr(levelZeroTensor), 0, levelZeroTensor);+ } else {+ // If all tensors are not set, use metadata+ outputProps[i].setArg(nullptr);+ outputProps[i]._offset = 0;+ // TODO : BatchSize not checked here+ outputProps[i].setSize(_metadata.outputs.at(i).shapeFromCompiler.get_max_shape());+ outputProps[i].updateStride();+ }+ }++ auto originalOutputProps = outputProps;++ dynamicGraph->predict_output_shape(inputPros, outputProps);++ for (size_t i = 0; i < outputProps.size(); i++) {+ if (!originalOutputProps[i].compare(outputProps[i])) {+ _logger.debug("Output shape change detected");+ break;+ }+ }+ }+}++void ZeroDynamicInferRequest::check_tensor_and_predicted_shapes(+ const std::vector<IDynamicGraph::MemRefType>& outputProps) {+ // check_tensor in set_tensor already checked the input tensor and output tensor with metadata+ // Check again here to see if the shape is right compared with predicted shape+ // If user set output tensor, need check if the tensor is large enough+ for (size_t i = 0; i < _userOutputTensors.size(); i++) {+ auto& userTensor = _userOutputTensors.at(i);+ auto zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(userTensor._ptr);+ auto& levelZeroTensor = _levelZeroOutputTensors.at(i);+ if (levelZeroTensor != nullptr && zeroTensor != nullptr && zeroTensor == levelZeroTensor) {+ // If user output tensor is ZeroTensor, no need check size here+ // These tensors are allocated by plugin and reshape will used later to resize tensor+ _logger.debug("Output tensor %zu is ZeroTensor, skip size check", i);+ continue;+ }++ ov::Shape predictedShape;+ for (int64_t j = 0; j < outputProps[i]._dimsCount; j++) {+ predictedShape.push_back(outputProps[i]._sizes[j]);+ }+ if (userTensor != nullptr) {+ // User set output tensor, need check size and throw exception if not large enough+ if (shape_size(userTensor->get_shape()) < shape_size(predictedShape)) {+ _logger.error("User output tensor %zu shape %s is different from predicted shape %s, can not "+ "run inference",+ i,+ userTensor->get_shape().to_string().c_str(),+ predictedShape.to_string().c_str());+ OPENVINO_THROW("User output tensor shape is smaller than predicted shape.");+ }+ }++ if (levelZeroTensor != nullptr) {+ if (shape_size(levelZeroTensor->get_shape()) < shape_size(predictedShape)) {+ // Local levelZero output tensor is not large enough, reshape will solve issue+ _logger.debug("LevelZero output tensor %zu shape %s is smaller than predicted shape %s, need "+ "recreate pipeline",+ i,+ levelZeroTensor->get_shape().to_string().c_str(),+ predictedShape.to_string().c_str());+ }+ }+ }+}++void ZeroDynamicInferRequest::update_tensor(const std::vector<IDynamicGraph::MemRefType>& outputProps) {+ // Update local level zero buffer shape with predicted shape to prepare for comparasion+ if (outputProps.size() > 0 && _isTensorChanged) {+ for (size_t i = 0; i < _levelZeroOutputTensors.size(); i++) {+ auto& levelZeroTensor = _levelZeroOutputTensors.at(i);+ if (levelZeroTensor == nullptr) {+ // Do not need to update user output tensor+ continue;+ }+ ov::Shape predictedShape;+ for (int64_t j = 0; j < outputProps[i]._dimsCount; j++) {+ predictedShape.push_back(outputProps[i]._sizes[j]);+ }+ if (levelZeroTensor->get_shape() != predictedShape) {+ _logger.info("Reshape output tensor %d from %s to predicted shape %s",+ i,+ levelZeroTensor->get_shape().to_string().c_str(),+ predictedShape.to_string().c_str());+ levelZeroTensor->set_shape(predictedShape);+ _pipeline->update_graph_arguments(_metadata.outputs.at(i).indexUsedByDriver, levelZeroTensor);+ }+ }+ }+ _isTensorChanged = false;+}diff --git a/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cppnew file mode 100644index 00000000000..eb2142bf2a2--- /dev/null+++ b/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp@@ -0,0 +1,372 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "zero_dynamic_pipeline.hpp"++#include <ze_api.h>+#include <ze_graph_ext.h>++#include <sstream>++#include "intel_npu/common/itt.hpp"+#include "intel_npu/config/options.hpp"+#include "intel_npu/prefix.hpp"+#include "intel_npu/utils/logger/logger.hpp"+#include "intel_npu/utils/zero/zero_api.hpp"+#include "intel_npu/utils/zero/zero_remote_tensor.hpp"+#include "intel_npu/utils/zero/zero_types.hpp"++namespace {+std::vector<size_t> get_strides(const std::vector<size_t>& strides_in_bytes, size_t element_size) {+ std::vector<size_t> element_strides(strides_in_bytes.size());+ std::transform(strides_in_bytes.begin(),+ strides_in_bytes.end(),+ element_strides.begin(),+ [element_size](size_t byte_stride) {+ OPENVINO_ASSERT(byte_stride % element_size == 0,+ "Stride ",+ byte_stride,+ " bytes is not aligned to element size ",+ element_size,+ " bytes. Strides must be multiples of element size.");++ return byte_stride / element_size;+ });++ return element_strides;+};++} // namespace++namespace intel_npu {+DynamicPipeline::DynamicPipeline(const Config& config,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const std::shared_ptr<IGraph>& graph,+ const std::vector<std::vector<std::shared_ptr<ZeroTensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ZeroTensor>>& output_tensors,+ size_t batch_size)+ : Pipeline(config, init_structs, graph, input_tensors, output_tensors, "DynamicPipeline", batch_size) {+ OV_ITT_SCOPED_TASK(itt::domains::LevelZeroBackend, "Zero_infer_request::DynamicPipeline::DynamicPipeline");++ _logger.debug("DynamicPipeline - initialize started, number_of_command_lists %i", _number_of_command_lists);++ intel_npu::IDynamicGraph* dynamicGraph = dynamic_cast<intel_npu::IDynamicGraph*>(graph.get());+ if (!dynamicGraph) {+ OPENVINO_THROW("Failed to cast graph to IDynamicGraph");+ }++ if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&+ _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ _graph->resize_last_submitted_event(_number_of_command_lists);+ }++ OPENVINO_ASSERT(_sync_output_with_fences || !_config.get<RUN_INFERENCES_SEQUENTIALLY>() ||+ _init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 1),+ "In-order execution doesn't work in case synchronization of the inferences is done using events");++ if (_config.has<PERF_COUNT>() && _config.get<PERF_COUNT>()) {+ auto profiling_pool =+ std::make_shared<zeroProfiling::ProfilingPool>(_init_structs, _graph, zeroProfiling::POOL_SIZE);+ _profiling_query = std::make_unique<zeroProfiling::ProfilingQuery>(_init_structs, 0);++ if (profiling_pool->create()) {+ _profiling_query->create(profiling_pool);+ }++ if (_config.get<PROFILING_TYPE>() == ov::intel_npu::ProfilingType::INFER) {+ _logger.debug("ZeroInferRequest::ZeroInferRequest - profiling type == ov::intel_npu::ProfilingType::INFER");+ _npu_profiling =+ std::make_shared<zeroProfiling::NpuInferProfiling>(_init_structs, _config.get<LOG_LEVEL>());+ }+ }++ if (!_sync_output_with_fences || (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&+ _config.get<RUN_INFERENCES_SEQUENTIALLY>())) {+ _event_pool =+ std::make_shared<EventPool>(_init_structs->getDevice(),+ _init_structs->getContext(),+ _number_of_command_lists ? static_cast<uint32_t>(_number_of_command_lists) : 1);++ _events.reserve(_number_of_command_lists);+ for (size_t i = 0; i < _number_of_command_lists; i++) {+ _events.emplace_back(std::make_shared<Event>(_event_pool, static_cast<uint32_t>(i)));+ }+ }+ _logger.debug("DynamicPipeline - emplace_back _event_pool and _command_queue completed");++ uint64_t num_of_subgraphs = dynamicGraph->get_num_subgraphs();++ _command_lists.reserve(_number_of_command_lists);+ for (size_t i = 0; i < _number_of_command_lists; i++) {+ _command_lists.emplace_back(std::make_unique<PipelinedCommandLists>(num_of_subgraphs,+ _init_structs,+ _graph->get_command_queue_group_ordinal()));+ }++ if (_sync_output_with_fences) {+ _fences.reserve(_number_of_command_lists);++ for (size_t i = 0; i < _number_of_command_lists; i++) {+ _fences.emplace_back(std::make_unique<Fence>(_graph->get_command_queue()));+ }+ }++ for (size_t i = 0; i < _number_of_command_lists; i++) {+ _logger.debug("DynamicPipeline - set args for command list number: %zu", i);++ _command_lists.at(i)->bind(dynamicGraph);+ auto& graphArguments = _command_lists.at(i)->getBinding();++ size_t io_index = 0;+ for (const auto& desc : _graph->get_metadata().inputs) {+ if (desc.isMainInputWeights) {+ // These values were set while running the "WeightlessGraph::init" method+ continue;+ }++ if (input_tensors.at(io_index).size() > 1) {+ _logger.debug("DynamicPipeline - set args for input index: %zu", io_index);+ const auto& tensor = input_tensors.at(io_index).at(i);+ if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() ||+ tensor->get_strides().empty()) {+ dynamicGraph->set_argument_value(desc.indexUsedByDriver, tensor->data());+ } else {+ dynamicGraph->set_argument_value_with_strides(+ desc.indexUsedByDriver,+ tensor->data(),+ get_strides(tensor->get_strides(), tensor->get_element_type().size()));+ }+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ graphArguments.setArgumentProperties(desc.indexUsedByDriver,+ tensor->data(),+ tensor->get_shape(),+ get_strides(tensor->get_strides(), elementSize));+ ++io_index;+ continue;+ }++ _logger.debug(" update tensor property for input desc index: %d", desc.indexUsedByDriver);+ const auto& tensor = input_tensors.at(io_index).at(0);+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {+ dynamicGraph->set_argument_value(desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) ++ (i * tensor->get_byte_size()) / _number_of_command_lists);+ graphArguments.setArgumentProperties(desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) ++ (i * tensor->get_byte_size()) / _number_of_command_lists,+ tensor->get_shape(),+ get_strides(tensor->get_strides(), elementSize));+ } else {+ dynamicGraph->set_argument_value_with_strides(+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_strides()[0]),+ get_strides(tensor->get_strides(), tensor->get_element_type().size()));+ graphArguments.setArgumentProperties(+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_strides()[0]),+ tensor->get_shape(),+ get_strides(tensor->get_strides(), elementSize));+ }+ ++io_index;+ }++ io_index = 0;+ for (const auto& desc : _graph->get_metadata().outputs) {+ _logger.debug("DynamicPipeline - update tensor property for output desc index: %d", desc.indexUsedByDriver);+ const auto& tensor = output_tensors.at(io_index);+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {+ dynamicGraph->set_argument_value(desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) ++ (i * tensor->get_byte_size()) / _number_of_command_lists);+ graphArguments.setArgumentProperties(desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) ++ (i * tensor->get_byte_size()) / _number_of_command_lists,+ tensor->get_shape(),+ get_strides(tensor->get_strides(), elementSize));+ } else {+ dynamicGraph->set_argument_value_with_strides(+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_strides()[0]),+ get_strides(tensor->get_strides(), elementSize));++ graphArguments.setArgumentProperties(+ desc.indexUsedByDriver,+ static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_strides()[0]),+ tensor->get_shape(),+ get_strides(tensor->get_strides(), elementSize));+ }+ ++io_index;+ }+ }+ _logger.debug("DynamicPipeline - initialize completed");+}++void DynamicPipeline::push() {+ _logger.debug("DynamicPipeline - push() started");++ if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&+ _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ if (_id) {+ auto previousIndex = _graph->get_last_submitted_id();++ if (_id != ++previousIndex) {+ OPENVINO_THROW("Inferences should be called in the same order they were called the first time!");+ }+ }++ _graph->set_last_submitted_id(_id);+ }++ auto commandQueueHandle = _graph->get_command_queue()->handle();+ for (size_t i = 0; i < _command_lists.size(); ++i) {+ OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PUSH, itt::domains::LevelZeroBackend, "Pipeline", "push");++ ze_fence_handle_t fence = nullptr;+ ze_event_handle_t event = nullptr;+ if (_sync_output_with_fences) {+ fence = _fences.at(i)->handle();+ }++ auto& command_lists = _command_lists.at(i);+ auto& graphArguments = command_lists->getBinding();+ if (_logger.level() >= ov::log::Level::DEBUG) {+ _logger.debug("Inputs info for dynamic graph:");+ for (auto& memType : graphArguments._inputs) {+ _logger.debug("input: %s", memType.toString().c_str());+ }+ _logger.debug("Outputs info for dynamic graph:");+ for (auto& memType : graphArguments._outputs) {+ _logger.debug("output: %s", memType.toString().c_str());+ }+ }++ // L0 wrapper handle closed command list+ command_lists->resetCommandList();++ dynamic_cast<IDynamicGraph*>(_graph.get())+ ->execute(_init_structs,+ command_lists->getBinding(),+ command_lists->getHandles(),+ commandQueueHandle,+ fence,+ event,+ nullptr);+ }++ _logger.debug("DynamicPipeline - push() completed");+}++void DynamicPipeline::pull() {+ _logger.debug("DynamicPipeline - pull() started");+ OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PULL, itt::domains::LevelZeroBackend, "DynamicPipeline", "pull");++ for (size_t i = 0; i < _command_lists.size(); ++i) {+ if (_sync_output_with_fences) {+ _fences.at(i)->hostSynchronize();+ } else {+ _events.at(i)->hostSynchronize();+ }+ /// sample npu timestamps if feature was activated+ if (_npu_profiling != nullptr) {+ _npu_profiling->sampleNpuTimestamps();+ }+ }++ _logger.debug("DynamicPipeline - pull() completed");+}++void DynamicPipeline::reset() const {+ _logger.debug("DynamicPipeline - reset() started");+ for (size_t i = 0; i < _command_lists.size(); ++i) {+ if (_sync_output_with_fences) {+ _fences.at(i)->reset();+ } else {+ _events.at(i)->reset();+ }+ }++ _logger.debug("Pipeline - rest() completed");+}++void DynamicPipeline::update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& zeroTensor,+ std::shared_ptr<ov::ITensor> userTensor) {+ OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "DynamicPipeline", "updateCommandList");+ _logger.debug("DynamicPipeline - updateCommandList");+ // This is the tensor with right shape and strides+ // The required check is alredy done in inferRequest+ const std::shared_ptr<ov::ITensor>& tensor = userTensor ? userTensor : zeroTensor;+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ const size_t number_of_command_lists = _command_lists.size();++ for (size_t i = 0; i < number_of_command_lists; i++) {+ if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {+ _command_lists.at(i)->updateMutableCommandList(index,+ static_cast<const unsigned char*>(zeroTensor->data()) ++ (i * tensor->get_byte_size()) / number_of_command_lists,+ get_strides(tensor->get_strides(), elementSize),+ tensor->get_shape());+ } else {+ _command_lists.at(i)->updateMutableCommandList(+ index,+ static_cast<const unsigned char*>(zeroTensor->data()) + (i * tensor->get_strides()[0]),+ get_strides(tensor->get_strides(), elementSize),+ tensor->get_shape());+ }+ }+}++void DynamicPipeline::update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& zeroTensor,+ size_t batch_index,+ std::shared_ptr<ov::ITensor> userTensor) {+ OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL,+ itt::domains::LevelZeroBackend,+ "DynamicPipeline",+ "updateCommandListIndex");+ _logger.debug("DynamicPipeline - updateCommandListIndex");+ // This is the tensor with right shape and strides+ // The required check is alredy done in inferRequest+ const std::shared_ptr<ov::ITensor>& tensor = userTensor ? userTensor : zeroTensor;+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ const size_t number_of_command_lists = _command_lists.size();++ OPENVINO_ASSERT(batch_index < number_of_command_lists,+ "Command list index is higher than the number of Command lists ",+ batch_index);++ if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {+ _command_lists.at(batch_index)+ ->updateMutableCommandList(index,+ zeroTensor->data(),+ get_strides(tensor->get_strides(), elementSize),+ tensor->get_shape());+ } else {+ _command_lists.at(batch_index)+ ->updateMutableCommandList(index,+ zeroTensor->data(),+ get_strides(tensor->get_strides(), elementSize),+ tensor->get_shape());+ }+}++std::vector<ov::ProfilingInfo> DynamicPipeline::get_profiling_info() const {+ _logger.debug("InferRequest::get_profiling_info started");+ if (!_config.has<PERF_COUNT>() || !_config.get<PERF_COUNT>()) {+ _logger.warning("InferRequest::get_profiling_info complete with empty {}.");+ return {};+ }++ if (_config.get<PROFILING_TYPE>() == ov::intel_npu::ProfilingType::INFER) {+ _logger.debug("InferRequest::get_profiling_info complete with _npu_profiling->getNpuInferStatistics().");+ return _npu_profiling->getNpuInferStatistics();+ }++ _logger.debug("InferRequest::get_profiling_info complete with compiler->process_profiling_output().");+ return _graph->process_profiling_output(_profiling_query->getData<uint8_t>(), _config);+}++} // 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 bf4450566e1..19b691095fb 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@@ -14,14 +14,7 @@#include "openvino/runtime/intel_npu/remote_properties.hpp"#include "openvino/runtime/make_tensor.hpp"#include "zero_variable_state.hpp"--using namespace intel_npu;--namespace {--constexpr std::size_t SINGLE_TENSOR = 0;-constexpr bool INPUT = true;-constexpr bool OUTPUT = false;+namespace intel_npu {std::optional<size_t> determine_dynamic_batch_size(const IODescriptor& desc,const ov::PartialShape& ioShape,@@ -70,8 +63,6 @@ void* get_tensor_data_ptr(const std::shared_ptr<ov::ITensor>& tensor) {}}-} // namespace-//------------------------------------------------------------------------------ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,const std::shared_ptr<const ICompiledModel>& compiledModel,@@ -246,8 +237,12 @@ void ZeroInferRequest::create_pipeline() {}}- _logger.debug("ZeroInferRequest::create_pipeline - constructing pipeline");+ construct_pipeline();+}+void ZeroInferRequest::construct_pipeline() {+ _logger.debug("ZeroInferRequest::create_pipeline - constructing pipeline");+ auto batchSize = _graph->get_batch_size();// Construct pipeline_pipeline = std::make_unique<Pipeline>(_config,_initStructs,@@ -348,6 +343,12 @@ void ZeroInferRequest::set_tensor(const ov::Output<const ov::Node>& port, const_userOutputTensors.at(foundPort.idx) = tensor;}+ update_command_list_for_tensor(foundPort, tensor);+}++void ZeroInferRequest::update_command_list_for_tensor(SyncInferRequest::FoundPort& foundPort,+ const ov::SoPtr<ov::ITensor>& tensor) {+ OV_ITT_TASK_CHAIN(ZERO_SET_TENSOR, itt::domains::LevelZeroBackend, "set_tensor", "update_command_list_for_tensor");if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {auto& levelZeroTensor =foundPort.is_input() ? get_level_zero_input(foundPort.idx) : _levelZeroOutputTensors.at(foundPort.idx);@@ -442,6 +443,16 @@ 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;+ update_command_list_for_tensors(foundPort, tensors, batchSizeCandidate);+}++void ZeroInferRequest::update_command_list_for_tensors(SyncInferRequest::FoundPort& foundPort,+ const std::vector<ov::SoPtr<ov::ITensor>>& tensors,+ std::optional<size_t> batchSizeCandidate) {+ OV_ITT_TASK_CHAIN(ZERO_SET_TENSORS,+ itt::domains::LevelZeroBackend,+ "set_tensors",+ "update_command_list_for_tensors");if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0) && batchSizeCandidate.has_value()) {get_level_zero_inputs(foundPort.idx).resize(tensors.size());@@ -669,7 +680,14 @@ void ZeroInferRequest::infer() {void ZeroInferRequest::infer_async() {_logger.debug("InferRequest::infer_async started");OV_ITT_TASK_CHAIN(ZERO_INFER, itt::domains::LevelZeroBackend, "infer_async", "start");+ prepare_inputs();++ OV_ITT_TASK_NEXT(ZERO_INFER, "push");+ _pipeline->push();+}+void ZeroInferRequest::prepare_inputs() {+ OV_ITT_TASK_CHAIN(ZERO_INFER, itt::domains::LevelZeroBackend, "infer_async", "prepare_inputs");{std::lock_guard<std::mutex> lock(_graph->get_mutex());@@ -775,9 +793,6 @@ void ZeroInferRequest::infer_async() {++inputIndex;}-- OV_ITT_TASK_NEXT(ZERO_INFER, "push");- _pipeline->push();}void ZeroInferRequest::get_result() {@@ -901,3 +916,5 @@ std::shared_ptr<ZeroTensor>& ZeroInferRequest::get_level_zero_input(size_t indexstd::vector<std::shared_ptr<ZeroTensor>>& ZeroInferRequest::get_level_zero_inputs(size_t index) const {return _levelZeroInputTensors.at(index);}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex dc023b53ac8..de219c91420 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -220,6 +220,20 @@ Pipeline::Pipeline(const Config& config,_logger.debug("Pipeline - initialize completed");}+Pipeline::Pipeline(const Config& config,+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const std::shared_ptr<IGraph>& graph,+ const std::vector<std::vector<std::shared_ptr<ZeroTensor>>>& input_tensors,+ const std::vector<std::shared_ptr<ZeroTensor>>& output_tensors,+ const char* logName,+ size_t batch_size)+ : _init_structs(init_structs),+ _graph(graph),+ _config(config),+ _id(_graph->get_unique_id()),+ _number_of_command_lists(batch_size),+ _logger(logName, _config.get<LOG_LEVEL>()) {}+void Pipeline::push() {_logger.debug("Pipeline - push() started");@@ -282,7 +296,9 @@ void Pipeline::reset() const {_logger.debug("Pipeline - rest() completed");};-void Pipeline::update_graph_arguments(uint32_t index, const std::shared_ptr<ZeroTensor>& tensor) {+void Pipeline::update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ std::shared_ptr<ov::ITensor> userTensor) {OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "updateCommandList");_logger.debug("Pipeline - updateCommandList");@@ -302,7 +318,10 @@ void Pipeline::update_graph_arguments(uint32_t index, const std::shared_ptr<Zero}};-void Pipeline::update_graph_arguments(uint32_t index, const std::shared_ptr<ZeroTensor>& tensor, size_t batch_index) {+void Pipeline::update_graph_arguments(uint32_t index,+ const std::shared_ptr<ZeroTensor>& tensor,+ size_t batch_index,+ std::shared_ptr<ov::ITensor> userTensor) {OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_IP_UMCL, itt::domains::LevelZeroBackend, "Pipeline", "updateCommandListIndex");_logger.debug("Pipeline - updateCommandListIndex");diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/idynamic_graph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/idynamic_graph.hppnew file mode 100644index 00000000000..cd9bf9e1e9b--- /dev/null+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/idynamic_graph.hpp@@ -0,0 +1,78 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "intel_npu/common/igraph.hpp"+#include "intel_npu/utils/zero/zero_init.hpp"++namespace intel_npu {++class IDynamicGraph : public IGraph {+public:+ struct MemRefType {+ const void* _basePtr;+ const void* _data;+ int64_t _offset;+ std::vector<int64_t> _sizes;+ std::vector<int64_t> _strides;+ int64_t _dimsCount;+ std::shared_ptr<void> _impl;++ MemRefType() : _basePtr(nullptr), _data(nullptr), _offset(0), _sizes(), _strides(), _dimsCount(0) {}++ MemRefType(const void* basePtr,+ const void* data,+ int64_t offset,+ const std::vector<int64_t>& sizes,+ const std::vector<int64_t>& strides,+ int64_t dimsCount)+ : _basePtr(basePtr),+ _data(data),+ _offset(offset),+ _sizes(sizes),+ _strides(strides),+ _dimsCount(dimsCount) {}++ void setArg(const void* arg);+ void setSize(const ov::Shape& shape);+ void set(const void* basePtr, int64_t offset, std::shared_ptr<ov::ITensor> tensor);+ void updateStride();+ bool compare(const MemRefType& memref);+ friend std::ostream& operator<<(std::ostream& os, const IDynamicGraph::MemRefType& memRef);+ std::string toString();+ };++ struct GraphArguments {+ std::vector<MemRefType> _inputs;+ std::vector<MemRefType> _outputs;+ std::shared_ptr<void> _impl;++ void setArgumentValue(uint32_t argi, const void* argv);+ void setArgumentProperties(uint32_t argi,+ const void* argv,+ const ov::Shape& shapes,+ const std::vector<size_t>& strides);+ };++ IDynamicGraph() = default;+ ~IDynamicGraph() override = default;++ virtual void execute(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t inferenceFence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling);++ virtual void getBinding(GraphArguments& args);++ virtual uint64_t get_num_subgraphs() const;++ virtual void predict_output_shape(std::vector<MemRefType>& inputDescriptors,+ std::vector<MemRefType>& outputDescriptors);+};++} // namespace intel_npudiff --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 120f399fc79..dc5c1f0304f 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@@ -28,29 +28,29 @@ public:* @return A pair made of the size of the main binary object and an optional variable. The optional variable* constitues the size of each init binary object if weights separation is enabled.*/- virtual std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const = 0;+ virtual std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const;virtual std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,- const Config& config) const = 0;+ const Config& config) const;- virtual void set_argument_value(uint32_t id, const void* data) const = 0;+ virtual void set_argument_value(uint32_t id, const void* data) const;virtual void set_argument_value_with_strides(uint32_t id,const void* data,- const std::vector<size_t>& strides) const = 0;+ const std::vector<size_t>& strides) const;- virtual void initialize(const Config& config) = 0;+ virtual void initialize(const Config& config);virtual ~IGraph() = default;- virtual const NetworkMetadata& get_metadata() const = 0;- virtual ze_graph_handle_t get_handle() const = 0;+ virtual const NetworkMetadata& get_metadata() const;+ virtual ze_graph_handle_t get_handle() const;- virtual void update_network_name(std::string_view name) = 0;+ virtual void update_network_name(std::string_view name);- virtual const std::shared_ptr<CommandQueue>& get_command_queue() const = 0;- virtual uint32_t get_command_queue_group_ordinal() const = 0;+ virtual const std::shared_ptr<CommandQueue>& get_command_queue() const;+ virtual uint32_t get_command_queue_group_ordinal() const;- virtual void set_workload_type(const ov::WorkloadType workloadType) const = 0;+ virtual void set_workload_type(const ov::WorkloadType workloadType) const;std::mutex& get_mutex() {return _mutex;@@ -60,16 +60,16 @@ public:return _init_completed;}- virtual void set_last_submitted_event(const std::shared_ptr<Event>& event, size_t indexOfCommandList) = 0;- virtual const std::shared_ptr<Event>& get_last_submitted_event(size_t indexOfCommandList) const = 0;- virtual void resize_last_submitted_event(size_t batch) = 0;- virtual void set_batch_size(std::size_t batch) = 0;+ virtual void set_last_submitted_event(const std::shared_ptr<Event>& event, size_t indexOfCommandList);+ virtual const std::shared_ptr<Event>& get_last_submitted_event(size_t indexOfCommandList) const;+ virtual void resize_last_submitted_event(size_t batch);+ virtual void set_batch_size(std::size_t batch);- virtual const std::optional<std::size_t> get_batch_size() const = 0;+ virtual const std::optional<std::size_t> get_batch_size() const;- virtual uint32_t get_unique_id() = 0;- virtual void set_last_submitted_id(uint32_t id_index) = 0;- virtual uint32_t get_last_submitted_id() const = 0;+ virtual uint32_t get_unique_id();+ virtual void set_last_submitted_id(uint32_t id_index);+ virtual uint32_t get_last_submitted_id() const;virtual std::optional<bool> is_profiling_blob() const = 0;diff --git a/src/plugins/intel_npu/src/common/src/idynamic_graph.cpp b/src/plugins/intel_npu/src/common/src/idynamic_graph.cppnew file mode 100644index 00000000000..fcc82b80469--- /dev/null+++ b/src/plugins/intel_npu/src/common/src/idynamic_graph.cpp@@ -0,0 +1,142 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+//++#include "intel_npu/common/idynamic_graph.hpp"++#include "openvino/core/except.hpp"++namespace intel_npu {++void IDynamicGraph::MemRefType::setArg(const void* arg) {+ _basePtr = _data = arg;+}++void IDynamicGraph::MemRefType::setSize(const ov::Shape& shape) {+ // Note: check difference between shape from compiler and shape from IR.+ _sizes.resize(shape.size());+ _strides.resize(shape.size());+ _dimsCount = static_cast<uint32_t>(shape.size());+ for (size_t i = 0; i < shape.size(); ++i) {+ _sizes[i] = shape[i];+ _strides[i] = 0; // Strides are not set yet, will be updated+ }+}++void IDynamicGraph::MemRefType::set(const void* arg, int64_t offset, std::shared_ptr<ov::ITensor> tensor) {+ _basePtr = _data = arg;+ _offset = offset;+ auto& shape = tensor->get_shape();+ for (size_t j = 0; j < shape.size(); j++) {+ _sizes[j] = shape[j];+ }+ auto& strides = tensor->get_strides();+ size_t elementSize = tensor->get_element_type().bitwidth() < 8 ? 1 : tensor->get_element_type().size();+ for (size_t j = 0; j < strides.size(); j++) {+ _strides[j] = strides[j] / elementSize;+ }+ _dimsCount = shape.size();+}++void IDynamicGraph::MemRefType::updateStride() {+ // Note: NCHW layout style+ uint64_t stride = 1;+ for (int64_t i = _dimsCount - 1; i >= 0; --i) {+ _strides[i] = stride;+ stride *= _sizes[i];+ }+}++// The comparision only checks shape and strides now+bool IDynamicGraph::MemRefType::compare(const IDynamicGraph::MemRefType& memref) {+ if (memref._dimsCount != _dimsCount || _sizes.size() != memref._sizes.size() ||+ _strides.size() != memref._strides.size())+ return false;+ size_t dimsCount = static_cast<size_t>(_dimsCount);+ if (memref._sizes.size() != dimsCount || memref._strides.size() != dimsCount)+ return false;+ for (size_t i = 0; i < dimsCount; i++) {+ if (_sizes[i] != memref._sizes[i] || _strides[i] != memref._strides[i]) {+ return false;+ }+ }+ return true;+}++std::ostream& operator<<(std::ostream& os, const IDynamicGraph::MemRefType& memRef) {+ os << "BasePtr: " << memRef._basePtr << ", Data: " << memRef._data << ", Offset: " << memRef._offset+ << ", Sizes: [";+ for (int64_t size : memRef._sizes) {+ os << size << " ";+ }+ os << "], Strides: [";+ for (int64_t stride : memRef._strides) {+ os << stride << " ";+ }+ os << "]";+ return os;+}++std::string IDynamicGraph::MemRefType::toString() {+ std::stringstream stream;+ stream << *this;+ return stream.str();+}++void IDynamicGraph::GraphArguments::setArgumentValue(uint32_t argi, const void* argv) {+ if (argi < _inputs.size()) {+ _inputs[argi]._basePtr = _inputs[argi]._data = const_cast<void*>(argv);+ } else {+ auto idx = argi - _inputs.size();+ if (idx < _outputs.size()) {+ _outputs[idx]._basePtr = _outputs[idx]._data = const_cast<void*>(argv);+ }+ }+}++void IDynamicGraph::GraphArguments::setArgumentProperties(uint32_t argi,+ const void* argv,+ const ov::Shape& sizes,+ const std::vector<size_t>& strides) {+ if (argi < _inputs.size()) {+ _inputs[argi]._basePtr = _inputs[argi]._data = const_cast<void*>(argv);+ for (int64_t i = 0; i < _inputs[argi]._dimsCount; i++) {+ _inputs[argi]._sizes[i] = sizes[i];+ _inputs[argi]._strides[i] = strides[i];+ }+ } else {+ auto idx = argi - _inputs.size();+ if (idx < _outputs.size()) {+ _outputs[idx]._basePtr = _outputs[idx]._data = const_cast<void*>(argv);+ for (int64_t i = 0; i < _outputs[idx]._dimsCount; i++) {+ _outputs[idx]._sizes[i] = sizes[i];+ _outputs[idx]._strides[i] = strides[i];+ }+ }+ }+}++void IDynamicGraph::execute(const std::shared_ptr<ZeroInitStructsHolder>&,+ GraphArguments&,+ std::vector<ze_command_list_handle_t>&,+ ze_command_queue_handle_t,+ ze_fence_handle_t,+ ze_event_handle_t,+ ze_graph_profiling_pool_handle_t) {+ OPENVINO_THROW("execute not implemented");+}++void IDynamicGraph::getBinding(GraphArguments&) {+ OPENVINO_THROW("getBinding not implemented");+}++uint64_t IDynamicGraph::get_num_subgraphs() const {+ OPENVINO_THROW("get_num_subgraphs not implemented");+}++void IDynamicGraph::predict_output_shape(std::vector<MemRefType>&, std::vector<MemRefType>&) {+ OPENVINO_THROW("predict_output_shape not implemented");+}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/common/src/igraph.cpp b/src/plugins/intel_npu/src/common/src/igraph.cppnew file mode 100644index 00000000000..034d82ee140--- /dev/null+++ b/src/plugins/intel_npu/src/common/src/igraph.cpp@@ -0,0 +1,87 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "intel_npu/common/igraph.hpp"++#include "openvino/core/except.hpp"++namespace intel_npu {++std::pair<uint64_t, std::optional<std::vector<uint64_t>>> IGraph::export_blob(std::ostream&) const {+ OPENVINO_THROW("export_blob not implemented");+}++std::vector<ov::ProfilingInfo> IGraph::process_profiling_output(const std::vector<uint8_t>&, const Config&) const {+ OPENVINO_THROW("process_profiling_output not implemented");+}++void IGraph::set_argument_value(uint32_t, const void*) const {+ OPENVINO_THROW("set_argument_value not implemented");+}++void IGraph::set_argument_value_with_strides(uint32_t, const void*, const std::vector<size_t>&) const {+ OPENVINO_THROW("set_argument_value_with_strides not implemented");+}++void IGraph::initialize(const Config&) {+ OPENVINO_THROW("initialize not implemented");+}++const NetworkMetadata& IGraph::get_metadata() const {+ OPENVINO_THROW("get_metadata not implemented");+}++ze_graph_handle_t IGraph::get_handle() const {+ OPENVINO_THROW("get_handle not implemented");+}++void IGraph::update_network_name(std::string_view) {+ OPENVINO_THROW("update_network_name not implemented");+}++const std::shared_ptr<CommandQueue>& IGraph::get_command_queue() const {+ OPENVINO_THROW("get_command_queue not implemented");+}++uint32_t IGraph::get_command_queue_group_ordinal() const {+ OPENVINO_THROW("get_command_queue_group_ordinal not implemented");+}++void IGraph::set_workload_type(const ov::WorkloadType) const {+ OPENVINO_THROW("set_workload_type not implemented");+}++void IGraph::set_last_submitted_event(const std::shared_ptr<Event>&, size_t) {+ OPENVINO_THROW("set_last_submitted_event not implemented");+}++const std::shared_ptr<Event>& IGraph::get_last_submitted_event(size_t) const {+ OPENVINO_THROW("get_last_submitted_event not implemented");+}++void IGraph::resize_last_submitted_event(size_t) {+ OPENVINO_THROW("resize_last_submitted_event not implemented");+}++void IGraph::set_batch_size(std::size_t) {+ OPENVINO_THROW("set_batch_size not implemented");+}++const std::optional<std::size_t> IGraph::get_batch_size() const {+ OPENVINO_THROW("get_batch_size not implemented");+}++uint32_t IGraph::get_unique_id() {+ OPENVINO_THROW("get_unique_id not implemented");+}++void IGraph::set_last_submitted_id(uint32_t) {+ OPENVINO_THROW("set_last_submitted_id not implemented");+}++uint32_t IGraph::get_last_submitted_id() const {+ OPENVINO_THROW("get_last_submitted_id not implemented");+}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txtindex 64c94078763..2dfe3cf1fb6 100644--- a/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt+++ b/src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt@@ -5,6 +5,7 @@set(TARGET_NAME "openvino_npu_driver_compiler_adapter")file(GLOB_RECURSE SOURCES *.cpp *.hpp *.h)+source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})add_library(${TARGET_NAME} STATIC ${SOURCES})diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hppnew file mode 100644index 00000000000..5eeb3331de0--- /dev/null+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp@@ -0,0 +1,205 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <ze_graph_ext.h>++#include "compiler_impl.hpp"+#include "intel_npu/common/idynamic_graph.hpp"+#include "intel_npu/network_metadata.hpp"+#include "intel_npu/utils/zero/zero_init.hpp"+#include "npu_mlir_runtime_api.hpp"+#include "openvino/runtime/so_ptr.hpp"++namespace intel_npu {+class DynamicGraph final : public IDynamicGraph {+public:+ struct MemRefTypeImpl {+ npu_mlir_runtime_mem_ref_handle_t _memRef;++ MemRefTypeImpl() : _memRef(nullptr) {}++ ~MemRefTypeImpl() {+ destroyMemRef();+ }++ void UpdateMemRefHandleStatus(MemRefType& memref) {+ // Update current MemRef handle to use latest metadata+ if (_memRef == nullptr) {+ createMemRef(memref._dimsCount);+ }+ auto result = npuMLIRRuntimeSetMemRef(_memRef,+ memref._basePtr,+ memref._data,+ memref._offset,+ memref._sizes.data(),+ memref._strides.data(),+ memref._dimsCount);+ if (result != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ throw std::runtime_error("Failed to update MemRef handle");+ }+ }++ void alignWithHandle(MemRefType& memref) {+ if (_memRef == nullptr) {+ return;+ }++ if (npuMLIRRuntimeParseMemRef(_memRef,+ &memref._basePtr,+ &memref._data,+ &memref._offset,+ memref._sizes.data(),+ memref._strides.data(),+ &memref._dimsCount) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ throw std::runtime_error("Failed to parse MemRef handle");+ }+ }++ private:+ void createMemRef(int64_t dimsCount) {+ if (_memRef == nullptr) {+ auto result = npuMLIRRuntimeCreateMemRef(dimsCount, &_memRef);+ if (result != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ OPENVINO_THROW("Failed to create MemRef handle");+ }+ }+ }++ void destroyMemRef() {+ if (_memRef != nullptr) {+ npuMLIRRuntimeDestroyMemRef(_memRef);+ _memRef = nullptr;+ }+ }+ };++ struct GraphArgumentsImpl : public GraphArguments {+ std::vector<npu_mlir_runtime_mem_ref_handle_t> _inputMemRefs;+ std::vector<npu_mlir_runtime_mem_ref_handle_t> _outputMemRefs;+ npu_mlir_runtime_execute_params_t _executeParams = {};+ };++ class Impl {+ using MemRefTypeImpl = DynamicGraph::MemRefTypeImpl;++ public:+ virtual void initialize(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) = 0;+ virtual void setArgumentValue(uint32_t argi, const void* argv) = 0;+ virtual void setArgumentValueWithStrides(uint32_t argi,+ const void* argv,+ const std::vector<size_t>& strides) = 0;+ virtual uint64_t getNumSubgraphs() = 0;+ virtual void getBinding(GraphArguments& binding) = 0;+ virtual void executeGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t fence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling) = 0;+ virtual void predictOutputShape(std::vector<MemRefType>& inputDescriptors,+ std::vector<MemRefType>& outputDescriptors) = 0;+ virtual ~Impl() {};+ };++ DynamicGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ std::optional<ov::Tensor> blob,+ bool blobAllocatedByPlugin,+ const Config& config,+ const ov::SoPtr<VCLCompilerImpl>& compiler = {nullptr});++ std::pair<uint64_t, std::optional<std::vector<uint64_t>>> export_blob(std::ostream& stream) const override;++ std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,+ const Config& config) const override;++ void set_argument_value(uint32_t argi, const void* argv) const override;++ void set_argument_value_with_strides(uint32_t id,+ const void* data,+ const std::vector<size_t>& strides) const override;++ ze_graph_handle_t get_handle() const override;++ void initialize(const Config& config) override;++ ~DynamicGraph() override;++ const NetworkMetadata& get_metadata() const override;++ void update_network_name(std::string_view name) override;++ const std::shared_ptr<CommandQueue>& get_command_queue() const override;+ uint32_t get_command_queue_group_ordinal() const override;++ void set_workload_type(const ov::WorkloadType workloadType) const override;++ void set_batch_size(std::size_t batch) override;++ const std::optional<std::size_t> get_batch_size() const override;++ uint32_t get_unique_id() override;+ void set_last_submitted_id(uint32_t id_index) override;+ uint32_t get_last_submitted_id() const override;++ void execute(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t inferenceFence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling) override;++ void getBinding(GraphArguments& args) override;++ uint64_t get_num_subgraphs() const override;++ void predict_output_shape(std::vector<MemRefType>& inputDescriptors,+ std::vector<MemRefType>& outputDescriptors) override;++ std::optional<bool> is_profiling_blob() const override;++private:+ bool release_blob(const Config& config);+ std::optional<size_t> determine_batch_size();++ std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;++ NetworkMetadata _metadata;++ /**+ * @brief Stores the number of subgraphs for dynamic models+ * @note the number of subgraphs will be one for static models+ */+ uint64_t _num_of_subgraphs = 1;++ std::shared_ptr<CommandQueue> _commandQueue;+ uint32_t _commandQueueGroupOrdinal = 0;+ std::vector<std::shared_ptr<Event>> _lastSubmittedEvent;++ std::optional<ov::Tensor> _blob;++ // In the case of the import path, the blob is released after graph initialization so it can not be any longer+ // exported+ bool _blobIsReleased = false;+ bool _blobAllocatedByPlugin = false;++ uint32_t _uniqueId = 0;+ uint32_t _lastSubmittedId = 0;++ /**+ * @brief The batch size used by the corresponding model.+ * @details The attribute contains a value only if the plugin performs the batches splitting operation.+ */+ std::optional<std::size_t> _batchSize = std::nullopt;++ const ov::SoPtr<VCLCompilerImpl> _compiler;+ Logger _logger;++ std::unique_ptr<Impl> _impl;+};++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/include/npu_mlir_runtime_api.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/npu_mlir_runtime_api.hppnew file mode 100644index 00000000000..1747798164a--- /dev/null+++ b/src/plugins/intel_npu/src/compiler_adapter/include/npu_mlir_runtime_api.hpp@@ -0,0 +1,72 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <memory>++#include "intel_npu/npu_mlir_runtime.hpp"+#include "openvino/core/except.hpp"++namespace intel_npu {++// clang-format off+#define nmr_symbols_list() \+ nmr_symbol_statement(npuMLIRRuntimeGetAPIVersion) \+ nmr_symbol_statement(npuMLIRRuntimeCreate) \+ nmr_symbol_statement(npuMLIRRuntimeDestroy) \+ nmr_symbol_statement(npuMLIRRuntimeGetMetadata) \+ nmr_symbol_statement(npuMLIRRuntimeExecute) \+ nmr_symbol_statement(npuMLIRRuntimePredictOutputShape) \+ nmr_symbol_statement(npuMLIRRuntimeCreateMemRef) \+ nmr_symbol_statement(npuMLIRRuntimeDestroyMemRef) \+ nmr_symbol_statement(npuMLIRRuntimeSetMemRef) \+ nmr_symbol_statement(npuMLIRRuntimeParseMemRef)+++//unsupported symbols with older runtime versions+#define nmr_weak_symbols_list() \+ nmr_symbol_statement(npuMLIRRuntimeCreateExecutionContext) \+ nmr_symbol_statement(npuMLIRRuntimeDestroyExecutionContext) \+ nmr_symbol_statement(npuMLIRRuntimeUpdateMutableCommandList)+// clang-format on++class NPUMLIRRuntimeApi {+public:+ NPUMLIRRuntimeApi();+ NPUMLIRRuntimeApi(const NPUMLIRRuntimeApi& other) = delete;+ NPUMLIRRuntimeApi(NPUMLIRRuntimeApi&& other) = delete;+ void operator=(const NPUMLIRRuntimeApi&) = delete;+ void operator=(NPUMLIRRuntimeApi&&) = delete;++ ~NPUMLIRRuntimeApi() = default;++ static const std::shared_ptr<NPUMLIRRuntimeApi>& getInstance();++#define nmr_symbol_statement(symbol) decltype(&::symbol) symbol;+ nmr_symbols_list();+ nmr_weak_symbols_list();+#undef nmr_symbol_statement++private:+ std::shared_ptr<void> lib;+};++#define nmr_symbol_statement(symbol) \+ template <typename... Args> \+ inline typename std::invoke_result<decltype(&::symbol), Args...>::type wrapped_##symbol(Args... args) { \+ const auto& ptr = NPUMLIRRuntimeApi::getInstance(); \+ if (ptr->symbol == nullptr) { \+ OPENVINO_THROW("Unsupported symbol " #symbol); \+ } \+ return ptr->symbol(std::forward<Args>(args)...); \+ }+nmr_symbols_list();+nmr_weak_symbols_list();+#undef nmr_symbol_statement+#define nmr_symbol_statement(symbol) inline decltype(&::symbol) symbol = wrapped_##symbol;+nmr_symbols_list();+nmr_weak_symbols_list();+#undef nmr_symbol_statement+} // namespace intel_npudiff --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 12e237eab69..703fa544123 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@@ -334,7 +334,7 @@ VCLCompilerImpl::VCLCompilerImpl() : _logHandle(nullptr), _logger("VCLCompilerImvcl_compiler_desc_t compilerDesc;compilerDesc.version = _vclVersion;- compilerDesc.debugLevel = static_cast<__vcl_log_level_t>(static_cast<int>(Logger::global().level()) - 1);+ 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.diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cppnew file mode 100644index 00000000000..43bc505a6ac--- /dev/null+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp@@ -0,0 +1,749 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "dynamic_graph.hpp"++#include <iostream>+#include <iterator>++#include "intel_npu/config/options.hpp"+#include "intel_npu/prefix.hpp"+#include "intel_npu/utils/utils.hpp"+#include "intel_npu/utils/zero/zero_api.hpp"+#include "openvino/runtime/make_tensor.hpp"++namespace intel_npu {++class DynamicGraphImpl : public DynamicGraph::Impl {+public:+ using MemRefType = DynamicGraph::MemRefType;++public:+ DynamicGraphImpl() : _logger("DynamicGraphImpl", Logger::global().level()) {}+ void initialize(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) override;+ void createExecutionEngine(std::optional<ov::Tensor>& blob);+ void prepareMetadata(NetworkMetadata& metadata);+ void initializeDynamicGraphExecution(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata);+ void setArgumentValue(uint32_t argi, const void* argv) override;+ void setArgumentValueWithStrides(uint32_t argi, const void* argv, const std::vector<size_t>& strides) override;+ uint64_t getNumSubgraphs() override {+ return _engineProperties.numOfSubGraphs;+ }+ void executeGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ DynamicGraph::GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t inferenceFence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling) override;+ void getBinding(DynamicGraph::GraphArguments& binding) override;++ virtual ~DynamicGraphImpl() {+ destroy();+ }++ void destroy() {+ if (_engine != nullptr) {+ npuMLIRRuntimeDestroy(_engine);+ _engine = nullptr;+ }+ }++ void predictOutputShape(std::vector<DynamicGraph::MemRefType>& inputDescriptors,+ std::vector<DynamicGraph::MemRefType>& outputDescriptors) override;++public:+ npu_mlir_runtime_handle_t _engine = nullptr;+ npu_mlir_runtime_properties_t _engineProperties;+ DynamicGraph::GraphArguments _binding;+ bool _initializedMLIR = false;+ Logger _logger;+};++void DynamicGraphImpl::initialize(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) {+ if (!_initializedMLIR) {+ initializeDynamicGraphExecution(blob, metadata);+ _initializedMLIR = true;+ }++ _binding._inputs.resize(metadata.inputs.size());++ // dump output of _metadata+ _logger.debug("Dump metadata info from blob");+ _logger.debug("Metadata inputs: %d", metadata.inputs.size());+ for (const auto& input : metadata.inputs) {+ _logger.debug("Input compiler name: %s input node name: %s shapeFromCompiler: %s shapeFromIRModel: %s",+ input.nameFromCompiler.c_str(),+ input.nodeFriendlyName.c_str(),+ input.shapeFromCompiler.to_string().c_str(),+ input.shapeFromIRModel.has_value() ? input.shapeFromIRModel->to_string().c_str() : "N/A");+ }+ _logger.debug("Metadata outputs: %d", metadata.outputs.size());+ for (const auto& output : metadata.outputs) {+ _logger.debug("Output compiler name: %s output node name: %s shapeFromCompiler: %s shapeFromIRModel: %s",+ output.nameFromCompiler.c_str(),+ output.nodeFriendlyName.c_str(),+ output.shapeFromCompiler.to_string().c_str(),+ output.shapeFromIRModel.has_value() ? output.shapeFromIRModel->to_string().c_str() : "N/A");+ }++ auto& inputs = _binding._inputs;+ for (size_t i = 0; i < inputs.size(); ++i) {+ // Use size as placeholder of stride+ const auto& shape = metadata.inputs[i].shapeFromCompiler.get_shape();+ std::vector<int64_t> shapeVec(shape.begin(), shape.end());+ inputs[i] = MemRefType(nullptr, nullptr, 0, shapeVec, shapeVec, shapeVec.size());+ // Calc real stride+ inputs[i].updateStride();+ }++ _binding._outputs.resize(metadata.outputs.size());+ auto& outputs = _binding._outputs;+ for (size_t i = 0; i < outputs.size(); ++i) {+ const auto& shape = metadata.outputs[i].shapeFromCompiler.get_shape();+ std::vector<int64_t> shapeVec(shape.begin(), shape.end());+ outputs[i] = MemRefType(nullptr, nullptr, 0, shapeVec, shapeVec, shapeVec.size());+ outputs[i].updateStride();+ }+}++void DynamicGraphImpl::createExecutionEngine(std::optional<ov::Tensor>& blob) {+ _npu_mlir_runtime_blob_desc_t blobDesc;+ blobDesc.pInput = reinterpret_cast<const uint8_t*>(blob.value().data());+ blobDesc.inputSize = blob.value().get_byte_size();++ if (npuMLIRRuntimeCreate(&blobDesc, &_engine, &_engineProperties) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ OPENVINO_THROW("Failed to create MLIR runtime engine");+ }+}++/**+ * @brief Extracts the I/O metadata from Level Zero specific structures and converts them into OpenVINO specific+ * ones.+ *+ * @param arg The main Level Zero structure from which most metadata will be extracted.+ * @param metadata The secondary Level Zero structure from which metadata will be extracted. More specifically, the+ * argument is used for populating "shapeFromIRModel". Not providing this argument will lead to an empty value for+ * 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,+ const std::optional<ze_graph_argument_metadata_t>& metadata) {+ auto logger = Logger::global().clone("getIODescriptor");+ ov::element::Type_t precision = zeroUtils::toOVElementType(arg.devicePrecision);+ ov::Shape shapeFromCompiler;+ ov::PartialShape shapeFromIRModel;+ std::unordered_set<std::string> outputTensorNames;++ for (uint32_t id = 0; id < arg.associated_tensor_names_count; id++) {+ outputTensorNames.insert(arg.associated_tensor_names[id]);+ }+ for (uint32_t id = 0; id < arg.dims_count; id++) {+ shapeFromCompiler.push_back(arg.dims[id]);+ }+ if (metadata.has_value()) {+ const auto dynamicDim = std::numeric_limits<uint64_t>::max();+ shapeFromIRModel.reserve(metadata->shape_size);+ for (uint32_t id = 0; id < metadata->shape_size; id++) {+ if (metadata->shape[id] != dynamicDim) {+ shapeFromIRModel.push_back(metadata->shape[id]);+ } else {+ // lower bound is ignored, so we set it to 1 just to satisfy the Dimension constructor,+ // upper bound is set to the value from shapeFromCompiler as it is filled with upper bounds+ // in case of dynamic dimensions+ if (id == utils::BATCH_AXIS && shapeFromCompiler[id] == utils::DEFAULT_BATCH_SIZE) {+ logger.info("Ignore dynamic batch size upper limit, but keep the dimension dynamic as a metadata "+ "from compiler has been lost.");+ // We need to kepp batch dimension dynamic+ shapeFromIRModel.push_back(ov::Dimension(1, dynamicDim));+ } else {+ shapeFromIRModel.push_back(ov::Dimension(1, shapeFromCompiler[id]));+ }+ }+ }+ }++ // Flags will be used instead of indices for informing the type of the current entry+ std::string nameFromCompiler = arg.name;+ const bool isInput = (arg.type == ZE_GRAPH_ARGUMENT_TYPE_INPUT);+ bool isStateInput = false;+ bool isStateOutput = false;+ bool isShapeTensor = false;+ bool isInitInputWeights = false;+ bool isInitOutputWeights = false;+ bool isMainInputWeights = false;+ if (isInput && isStateInputName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(READVALUE_PREFIX.length());+ isStateInput = true;+ } else if (!isInput && isStateOutputName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(ASSIGN_PREFIX.length());+ isStateOutput = true;+ } else if (isShapeTensorName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(SHAPE_TENSOR_PREFIX.length());+ isShapeTensor = true;+ } else if (isInput && isInitInputWeightsName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(INIT_INPUT_WEIGHTS_PREFIX.length());+ isInitInputWeights = true;+ } else if (!isInput && isInitOutputWeightsName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(INIT_OUTPUT_WEIGHTS_PREFIX.length());+ isInitOutputWeights = true;+ } else if (isInput && isMainInputWeightsName(nameFromCompiler)) {+ nameFromCompiler = nameFromCompiler.substr(MAIN_INPUT_WEIGHTS_PREFIX.length());+ isMainInputWeights = true;+ }++ return {std::move(nameFromCompiler),+ precision,+ shapeFromCompiler,+ isStateInput,+ isStateOutput,+ isShapeTensor,+ isInitInputWeights,+ isInitOutputWeights,+ isMainInputWeights,+ std::nullopt,+ arg.debug_friendly_name,+ std::move(outputTensorNames),+ metadata.has_value() ? std::optional(shapeFromIRModel) : std::nullopt};+}++void DynamicGraphImpl::prepareMetadata(NetworkMetadata& metadata) {+ metadata.inputs.clear();+ metadata.outputs.clear();+ for (uint32_t i = 0; i < _engineProperties.numOfGraphArgs; ++i) {+ // TODO: follow graph ext to support Optional metadata for weightless model+ ze_graph_argument_properties_3_t arg;+ ze_graph_argument_metadata_t meta;+ std::vector<int64_t> upperBound;+ upperBound.reserve(ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE);+ if (npuMLIRRuntimeGetMetadata(_engine, i, &arg, &meta, upperBound.data()) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ OPENVINO_THROW("Failed to get MLIR runtime metadata");+ }+ IODescriptor ioDesc = getIODescriptor(arg, meta);+ // TODO: Once runtime returns right value, can remove change on index and layout+ ioDesc.indexUsedByDriver = i;+ ioDesc.supportsStridedLayout = true;+ switch (arg.type) {+ case ZE_GRAPH_ARGUMENT_TYPE_INPUT: {+ metadata.inputs.push_back(ioDesc);+ } break;+ case ZE_GRAPH_ARGUMENT_TYPE_OUTPUT: {+ metadata.outputs.push_back(ioDesc);+ } break;+ default: {+ OPENVINO_THROW("Invalid ze_graph_argument_type_t found in ze_graph_argument_properties_3_t object: ",+ arg.type);+ }+ }+ }+ metadata.bindRelatedDescriptors();+}++void DynamicGraphImpl::getBinding(DynamicGraph::GraphArguments& binding) {+ binding = _binding;+}++void DynamicGraphImpl::initializeDynamicGraphExecution(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) {+ createExecutionEngine(blob);+ prepareMetadata(metadata);++ _logger.debug("num of subgraphs: %d inputs: %d outputs: %d",+ _engineProperties.numOfSubGraphs,+ metadata.inputs.size(),+ metadata.outputs.size());+}++void DynamicGraphImpl::setArgumentValue(uint32_t argi, const void* argv) {+ auto& inputs = _binding._inputs;+ if (argi < inputs.size()) {+ _logger.debug("setArgumentValue for index %d (input %d)", argi, argi);+ inputs[argi].setArg(argv);+ } else {+ auto& outputs = _binding._outputs;+ auto idx = argi - inputs.size();+ _logger.debug("setArgumentValue for index %d (output %d)", argi, idx);+ if (idx < outputs.size()) {+ outputs[idx].setArg(argv);+ }+ }+}++void DynamicGraphImpl::setArgumentValueWithStrides(uint32_t argi,+ const void* argv,+ const std::vector<size_t>& strides) {+ _logger.debug("setArgumentValueWithStrides for index %d", argi);+ auto& inputs = _binding._inputs;+ if (argi < inputs.size()) {+ _logger.debug("setArgumentValueWithStrides for index %d (input %d)", argi, argi);+ inputs[argi].setArg(argv);++ for (int64_t i = 0; i < inputs[argi]._dimsCount; i++) {+ inputs[argi]._strides[i] = strides[i];+ }+ } else {+ auto& outputs = _binding._outputs;+ auto idx = argi - inputs.size();+ _logger.debug("setArgumentValueWithStrides for index %d (output %d)", argi, idx);+ if (idx < outputs.size()) {+ outputs[idx].setArg(argv);++ for (int64_t i = 0; i < outputs[idx]._dimsCount; i++) {+ outputs[idx]._strides[i] = strides[i];+ }+ }+ }+}++void DynamicGraphImpl::executeGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ IDynamicGraph::GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t fence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling) {+ std::shared_ptr<DynamicGraph::GraphArgumentsImpl> argsImpl =+ args._impl ? std::static_pointer_cast<DynamicGraph::GraphArgumentsImpl>(args._impl)+ : std::make_shared<DynamicGraph::GraphArgumentsImpl>();++ npu_mlir_runtime_execute_params_t* params = &argsImpl->_executeParams;++ for (auto& in : args._inputs) {+ std::shared_ptr<DynamicGraph::MemRefTypeImpl> inImpl =+ std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(in._impl);+ if (inImpl == nullptr) {+ inImpl = std::make_shared<DynamicGraph::MemRefTypeImpl>();+ in._impl = inImpl;+ }+ inImpl->UpdateMemRefHandleStatus(in);+ if (args._impl == nullptr) {+ argsImpl->_inputMemRefs.push_back(inImpl->_memRef);+ }+ }+ for (auto& out : args._outputs) {+ std::shared_ptr<DynamicGraph::MemRefTypeImpl> outImpl =+ std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(out._impl);+ if (outImpl == nullptr) {+ outImpl = std::make_shared<DynamicGraph::MemRefTypeImpl>();+ out._impl = outImpl;+ }+ outImpl->UpdateMemRefHandleStatus(out);+ if (args._impl == nullptr) {+ argsImpl->_outputMemRefs.push_back(outImpl->_memRef);+ }+ }++ params->pInputs = argsImpl->_inputMemRefs.data();+ params->numOfInputs = static_cast<uint32_t>(argsImpl->_inputMemRefs.size());+ params->pOutputs = argsImpl->_outputMemRefs.data();+ params->numOfOutputs = static_cast<uint32_t>(argsImpl->_outputMemRefs.size());+ params->ctx = zeroInitStruct->getContext();+ params->device = zeroInitStruct->getDevice();+ params->graphDdiTableExt = zeroInitStruct->getGraphDdiTable().getImpl();+ params->commandLists = commandLists.data();+ params->numCommandLists = static_cast<uint64_t>(commandLists.size());+ params->commandQueue = commandQueue;+ params->inferenceFence = fence;+ params->event = event;++ if (npuMLIRRuntimeExecute(_engine, params) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ OPENVINO_THROW("Failed to execute MLIR runtime engine");+ }++ if (args._impl == nullptr) {+ args._impl = argsImpl;+ }+}++void DynamicGraphImpl::predictOutputShape(std::vector<MemRefType>& inputDescriptors,+ std::vector<MemRefType>& outputDescriptors) {+ std::vector<npu_mlir_runtime_mem_ref_handle_t> inputs;+ for (auto& in : inputDescriptors) {+ std::shared_ptr<DynamicGraph::MemRefTypeImpl> inImpl =+ std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(in._impl);+ if (inImpl == nullptr) {+ inImpl = std::make_shared<DynamicGraph::MemRefTypeImpl>();+ in._impl = inImpl;+ }+ inImpl->UpdateMemRefHandleStatus(in);+ inputs.push_back(inImpl->_memRef);+ }+ std::vector<npu_mlir_runtime_mem_ref_handle_t> outputs;+ for (auto& out : outputDescriptors) {+ std::shared_ptr<DynamicGraph::MemRefTypeImpl> outImpl =+ std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(out._impl);+ if (outImpl == nullptr) {+ outImpl = std::make_shared<DynamicGraph::MemRefTypeImpl>();+ out._impl = outImpl;+ }+ outImpl->UpdateMemRefHandleStatus(out);+ outputs.push_back(outImpl->_memRef);+ }++ npu_mlir_runtime_predict_output_shape_params_t params;+ params.pInputs = inputs.data();+ params.numOfInputs = static_cast<uint32_t>(inputs.size());+ params.pOutputs = outputs.data();+ params.numOfOutputs = static_cast<uint32_t>(outputs.size());++ if (npuMLIRRuntimePredictOutputShape(_engine, ¶ms) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {+ OPENVINO_THROW("Failed to execute MLIR runtime engine");+ } else {+ for (auto& out : outputDescriptors) {+ std::shared_ptr<DynamicGraph::MemRefTypeImpl> outImpl =+ std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(out._impl);+ if (outImpl == nullptr) {+ OPENVINO_THROW("MemRefType implementation is broken, unkown error happens in shape prediction.");+ }+ outImpl->alignWithHandle(out);+ }+ _logger.debug("Output shape prediction is done successfully.");+ }+}++DynamicGraph::DynamicGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ std::optional<ov::Tensor> blob,+ bool blobAllocatedByPlugin,+ const Config& config,+ const ov::SoPtr<VCLCompilerImpl>& compiler)+ : _zeroInitStruct(zeroInitStruct),+ _blob(std::move(blob)),+ _blobAllocatedByPlugin(blobAllocatedByPlugin),+ _compiler(compiler),+ _logger("DynamicGraph", config.get<LOG_LEVEL>()) {+ _logger.info("Create DynamicGraph");+ if (!config.get<CREATE_EXECUTOR>() || config.get<DEFER_WEIGHTS_LOAD>()) {+ _logger.info("Graph initialize is deferred from the \"Graph\" constructor");+ return;+ }++ _impl = std::make_unique<DynamicGraphImpl>();+ // TODO: metadata needs to be parsed even when CREATE_EXECUTOR is 0 or DEFER_WEIGHTS_LOAD is YES, keep here to+ // support pure compilation without mlir runtime initialize MLIR execution engine, metadata, input&output+ // descriptors+ _impl->initialize(_blob, _metadata);++ _num_of_subgraphs = _impl->getNumSubgraphs();++ initialize(config);+}++std::pair<uint64_t, std::optional<std::vector<uint64_t>>> DynamicGraph::export_blob(std::ostream& stream) const {+ const uint8_t* blobPtr = nullptr;+ size_t blobSize = 0;++ std::vector<uint8_t> blobVec; // plugin needs to keep a copy of the blob for older drivers++ if (_blobIsReleased) {+ OPENVINO_THROW("Model was optimized away. Try importing it using `ov::hint::compiled_blob` property to extend "+ "its lifetime.");+ }++ if (_blob ==+ std::nullopt) { // when compiling the model using Compiler in Driver, the blob is handled by the driver+ OPENVINO_THROW("No CiD is supported yet!");+ } else { // in all other cases, the blob is handled by the plugin+ blobPtr = static_cast<const uint8_t*>(_blob->data());+ blobSize = _blob->get_byte_size();+ }++ if (blobSize > static_cast<decltype(blobSize)>(std::numeric_limits<std::streamsize>::max())) {+ OPENVINO_THROW("Blob size is too large to be represented on a std::streamsize!");+ }+ stream.write(reinterpret_cast<const char*>(blobPtr), static_cast<std::streamsize>(blobSize));++ if (!stream) {+ _logger.error("Write blob to stream failed. Blob is broken!");+ return std::make_pair(0, std::nullopt);+ }++ if (_logger.level() >= ov::log::Level::INFO) {+ std::uint32_t result = 1171117u;+ for (const uint8_t* it = blobPtr; it != blobPtr + blobSize; ++it) {+ result = ((result << 7) + result) + static_cast<uint32_t>(*it);+ }++ std::stringstream str;+ str << "Blob size: " << blobSize << ", hash: " << std::hex << result;+ _logger.info(str.str().c_str());+ }++ size_t size = utils::align_size_to_standard_page_size(blobSize);+ size_t paddingSize = size - blobSize;+ if (paddingSize > 0) {+ std::fill_n(std::ostream_iterator<char>(stream), paddingSize, 0);+ if (!stream) {+ _logger.error("Write padding to stream failed. Blob is broken!");+ return std::make_pair(0, std::nullopt);+ }+ _logger.info("Blob size with padding: %ld", size);+ }+ _logger.info("Write blob to stream successfully.");+ return std::make_pair(size, std::nullopt);+}++const NetworkMetadata& DynamicGraph::get_metadata() const {+ return _metadata;+}++void DynamicGraph::update_network_name(std::string_view name) {+ _metadata.name = name;+}++const std::shared_ptr<CommandQueue>& DynamicGraph::get_command_queue() const {+ return _commandQueue;+}++uint32_t DynamicGraph::get_command_queue_group_ordinal() const {+ return _commandQueueGroupOrdinal;+}++void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) const {+ if (_commandQueue == nullptr) {+ return;+ }++ ze_command_queue_workload_type_t zeWorkloadType;+ switch (workloadType) {+ case ov::WorkloadType::DEFAULT:+ zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_DEFAULT;+ break;+ case ov::WorkloadType::EFFICIENT:+ zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_BACKGROUND;+ break;+ default:+ OPENVINO_THROW("Unknown value for WorkloadType!");+ }++ _commandQueue->setWorkloadType(zeWorkloadType);+}++std::vector<ov::ProfilingInfo> DynamicGraph::process_profiling_output(const std::vector<uint8_t>& profData,+ const Config& config) const {+ if (_compiler == nullptr) {+ OPENVINO_THROW("Profiling post-processing is not supported.");+ }++ std::vector<uint8_t> blob(_blob->get_byte_size());+ blob.assign(reinterpret_cast<const uint8_t*>(_blob->data()),+ reinterpret_cast<const uint8_t*>(_blob->data()) + _blob->get_byte_size());+ return _compiler->process_profiling_output(profData, blob, config);+}++void DynamicGraph::set_argument_value(uint32_t argi, const void* argv) const {+ if (_impl == nullptr) {+ _logger.warning("Graph handle is null, dynamic pipeline to handle set_argument_value");+ return;+ }++ _impl->setArgumentValue(argi, argv);+}++void DynamicGraph::set_argument_value_with_strides(uint32_t id,+ const void* data,+ const std::vector<size_t>& strides) const {+ if (_impl == nullptr) {+ _logger.warning("Graph handle is null, dynamic pipeline to handle set_argument_value");+ return;+ }++ _impl->setArgumentValueWithStrides(id, data, strides);+}++ze_graph_handle_t DynamicGraph::get_handle() const {+ _logger.warning("DynamicGraph does not support get_handle() method.");+ return nullptr;+}++void DynamicGraph::initialize(const Config& config) {+ _logger.debug("Graph initialize start");++ if (!_impl) {+ _impl = std::make_unique<DynamicGraphImpl>();+ // initialize MLIR execution engine, metadata, input&output descriptors+ _impl->initialize(_blob, _metadata);+ _num_of_subgraphs = _impl->getNumSubgraphs();+ }++ if (!_zeroInitStruct || _init_completed) {+ _logger.warning("Zero device is not available, skip graph initialize!");+ return;+ }++ if (_commandQueue == nullptr) {+ _logger.debug("Graph initialize without graph handle");++ _commandQueueGroupOrdinal =+ zeroUtils::findCommandQueueGroupOrdinal(_zeroInitStruct->getDevice(),+ ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE);++ uint32_t commandQueueOptions = 0;++ if (config.has<TURBO>() && config.get<TURBO>()) {+ if (_zeroInitStruct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 0)) {+ OPENVINO_THROW("Turbo is not supported by the current driver");+ }+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;+ }++ if (_zeroInitStruct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 1) &&+ config.has<RUN_INFERENCES_SEQUENTIALLY>() && config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC;+ }++ _commandQueue = std::make_shared<CommandQueue>(_zeroInitStruct,+ zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),+ _commandQueueGroupOrdinal,+ commandQueueOptions);++ if (config.has<WORKLOAD_TYPE>()) {+ set_workload_type(config.get<WORKLOAD_TYPE>());+ }++ _logger.debug("Graph initialize finish");++ _batchSize = determine_batch_size();++ if (_zeroInitStruct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&+ config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ auto numberOfCommandLists = _batchSize.has_value() ? *_batchSize : 1;++ _lastSubmittedEvent.resize(numberOfCommandLists);+ }+ }++ // To ensure that the initialization of the graph does not exit prematurely due to nullptrs+ _init_completed = true;+}++bool DynamicGraph::release_blob(const Config& config) {+ _logger.warning("Release blob is skipped, no handle for DynamicGraph");+ return false;+};++void DynamicGraph::set_batch_size(std::size_t batch) {+ _batchSize = batch;+}++uint32_t DynamicGraph::get_unique_id() {+ return _uniqueId++;+}++void DynamicGraph::set_last_submitted_id(uint32_t id_index) {+ _lastSubmittedId = id_index;+}++uint32_t DynamicGraph::get_last_submitted_id() const {+ return _lastSubmittedId;+}++std::optional<size_t> DynamicGraph::determine_batch_size() {+ if (!_metadata.outputs.at(0).shapeFromIRModel.has_value()) {+ _logger.debug("Batching on the plugin is not used, batching is handled by the compiler");+ return std::nullopt;+ }++ const ov::PartialShape& firstShape = *_metadata.outputs.at(0).shapeFromIRModel;+ if (firstShape.is_dynamic() || firstShape.rank().get_length() == 0) {+ return std::nullopt;+ }++ const size_t candidateBatchSize = firstShape[utils::BATCH_AXIS].get_max_length();+ if (candidateBatchSize == 0 || candidateBatchSize == utils::DEFAULT_BATCH_SIZE) {+ _logger.debug("Batching on the plugin is not used, batching is handled by the compiler");+ return std::nullopt;+ }++ auto checkDescriptorsUseCandidateBatchSize = [candidateBatchSize](const std::vector<IODescriptor>& descriptors) {+ for (const IODescriptor& descriptor : descriptors) {+ OPENVINO_ASSERT(descriptor.shapeFromIRModel.has_value(),+ "Missing value for the \"shapeFromIRModel\" attribute, I/O descriptor");++ const ov::PartialShape& shapeFromCompiler = descriptor.shapeFromCompiler;+ const ov::PartialShape& shapeFromIRModel = *descriptor.shapeFromIRModel;++ if (shapeFromCompiler.is_dynamic() || shapeFromCompiler.rank().get_length() == 0 ||+ *shapeFromCompiler.begin() != utils::DEFAULT_BATCH_SIZE) {+ return false;+ }++ if (!descriptor.isStateInput && !descriptor.isStateOutput && !descriptor.isShapeTensor) {+ if (shapeFromIRModel.is_dynamic() || shapeFromIRModel.rank().get_length() == 0 ||+ *shapeFromIRModel.begin() != candidateBatchSize) {+ return false;+ }+ }+ }++ return true;+ };++ if (!checkDescriptorsUseCandidateBatchSize(_metadata.inputs) ||+ !checkDescriptorsUseCandidateBatchSize(_metadata.outputs)) {+ _logger.debug("Batching on the plugin is not used, batching is handled by the compiler");+ return std::nullopt;+ }++ _logger.debug("Batching is handled by the plugin");++ return candidateBatchSize;+}++const std::optional<std::size_t> DynamicGraph::get_batch_size() const {+ return _batchSize;+}++DynamicGraph::~DynamicGraph() {+ if (!_lastSubmittedEvent.empty()) {+ _lastSubmittedEvent.clear();+ }++ if (_commandQueue != nullptr) {+ _commandQueue.reset();+ }+}++void DynamicGraph::execute(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,+ DynamicGraph::GraphArguments& args,+ std::vector<ze_command_list_handle_t>& commandLists,+ ze_command_queue_handle_t commandQueue,+ ze_fence_handle_t inferenceFence,+ ze_event_handle_t event,+ ze_graph_profiling_pool_handle_t profiling) {+ auto impl = reinterpret_cast<DynamicGraphImpl*>(_impl.get());++ if (impl == nullptr)+ return;++ impl->executeGraph(zeroInitStruct, args, commandLists, commandQueue, inferenceFence, event, profiling);+}++void DynamicGraph::getBinding(GraphArguments& args) {+ auto impl = reinterpret_cast<DynamicGraphImpl*>(_impl.get());++ if (impl == nullptr)+ return;++ impl->getBinding(args);+}++uint64_t DynamicGraph::get_num_subgraphs() const {+ return _num_of_subgraphs;+}++void DynamicGraph::predict_output_shape(std::vector<MemRefType>& inputDescriptors,+ std::vector<MemRefType>& outputDescriptors) {+ auto impl = reinterpret_cast<DynamicGraphImpl*>(_impl.get());++ if (impl == nullptr)+ return;++ impl->predictOutputShape(inputDescriptors, outputDescriptors);+}++std::optional<bool> DynamicGraph::is_profiling_blob() const {+ _logger.warning("Profiling is not supported for DynamicGraph");+ return std::nullopt;+}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/compiler_adapter/src/npu_mlir_runtime_api.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/npu_mlir_runtime_api.cppnew file mode 100644index 00000000000..6edda898362--- /dev/null+++ b/src/plugins/intel_npu/src/compiler_adapter/src/npu_mlir_runtime_api.cpp@@ -0,0 +1,49 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "npu_mlir_runtime_api.hpp"++#include "openvino/util/file_util.hpp"+#include "openvino/util/shared_object.hpp"++namespace intel_npu {+NPUMLIRRuntimeApi::NPUMLIRRuntimeApi() {+ const std::string baseName = "npu_mlir_runtime";+ try {+ auto libPath = ov::util::make_plugin_library_name(ov::util::get_ov_lib_path(), baseName + OV_BUILD_POSTFIX);+ this->lib = ov::util::load_shared_object(libPath);+ } catch (const std::runtime_error& error) {+ OPENVINO_THROW(error.what());+ }++ try {+#define nmr_symbol_statement(symbol) \+ this->symbol = reinterpret_cast<decltype(&::symbol)>(ov::util::get_symbol(lib, #symbol));+ nmr_symbols_list();+#undef nmr_symbol_statement+ } catch (const std::runtime_error& error) {+ OPENVINO_THROW(error.what());+ }++#define nmr_symbol_statement(symbol) \+ try { \+ this->symbol = reinterpret_cast<decltype(&::symbol)>(ov::util::get_symbol(lib, #symbol)); \+ } catch (const std::runtime_error&) { \+ this->symbol = nullptr; \+ }+ nmr_weak_symbols_list();+#undef nmr_symbol_statement++#define nmr_symbol_statement(symbol) symbol = this->symbol;+ nmr_symbols_list();+ nmr_weak_symbols_list();+#undef nmr_symbol_statement+}++const std::shared_ptr<NPUMLIRRuntimeApi>& NPUMLIRRuntimeApi::getInstance() {+ static std::shared_ptr<NPUMLIRRuntimeApi> instance = std::make_shared<NPUMLIRRuntimeApi>();+ return instance;+}++} // 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 0d8759e69a0..f44559fa925 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@@ -7,6 +7,7 @@#include <memory>#include <string>+#include "dynamic_graph.hpp"#include "graph.hpp"#include "intel_npu/common/device_helpers.hpp"#include "intel_npu/common/itt.hpp"@@ -69,6 +70,12 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<conov::Tensor tensor;tensor = std::move(networkDesc.compiledNetworkTensor);+ if (config.get<COMPILATION_MODE>() == "HostCompile") {+ // no _compiler::parse call is required. networkmetadata will be obtained in DynamicGraph constructor+ _logger.debug("blob is not ELF format, create graph for LLVM IR!");+ return std::make_shared<DynamicGraph>(_zeroInitStruct, std::move(tensor), true, config, _compiler);+ }+GraphDescriptor graphDesc;NetworkMetadata networkMeta;@@ -253,6 +260,22 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::parse(const ov::Tensor& mainBlob,std::optional<std::shared_ptr<const ov::Model>>&& model) const {OV_ITT_TASK_CHAIN(PARSE_BLOB, itt::domains::NPUPlugin, "PluginCompilerAdapter", "parse");+ const void* data = mainBlob.data();+ size_t size = mainBlob.get_byte_size();+ std::string header;+ if (size >= 20) {+ header.assign(static_cast<const char*>(data), 20);+ } else {+ header.assign(static_cast<const char*>(data), size);+ }+ if (header.find("ELF") == std::string::npos) {+ // no _compiler::parse call is required. networkmetadata will be obtained in DynamicGraph constructor+ _logger.debug("blob is not ELF format, create graph for LLVM IR!");+ return std::make_shared<DynamicGraph>(_zeroInitStruct, std::move(mainBlob), true, config, _compiler);+ } else {+ _logger.debug("blob is ELF format, create graph for elf blob!");+ }+GraphDescriptor mainGraphDesc;NetworkMetadata mainNetworkMetadata;diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hppindex 2a8da3172f2..caedeec6826 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp@@ -43,6 +43,10 @@ private:}public:+ ze_graph_dditable_ext_t* const getImpl() {+ return _impl;+ }+ze_graph_dditable_ext_decorator(ze_graph_dditable_ext_t* impl, uint32_t driverExtVersion): _impl(impl),_driverExtVersion(driverExtVersion),diff --git a/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.cpp b/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.cppnew file mode 100644index 00000000000..238d7f54685--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.cpp@@ -0,0 +1,25 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "infer_with_host_compile.hpp"++#include "common/npu_test_env_cfg.hpp"+#include "common/utils.hpp"+#include "intel_npu/config/options.hpp"+#include "intel_npu/npu_private_properties.hpp"++const std::vector<ov::AnyMap> configs = {{{"NPU_COMPILER_TYPE", "PLUGIN"},+ {"NPU_PLATFORM", "NPU4000"},+ {"NPU_COMPILATION_MODE", "HostCompile"},+ {"NPU_CREATE_EXECUTOR", "0"}},+ {{"NPU_COMPILER_TYPE", "PLUGIN"},+ {"NPU_PLATFORM", "NPU5010"},+ {"NPU_COMPILATION_MODE", "HostCompile"},+ {"NPU_CREATE_EXECUTOR", "0"}}};++INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,+ InferWithHostCompileTests,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::ValuesIn(configs)),+ ov::test::utils::appendPlatformTypeTestName<InferWithHostCompileTests>);diff --git a/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hpp b/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hppnew file mode 100644index 00000000000..f15d37e410a--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/internal/dynamic_host_pipeline/infer_with_host_compile.hpp@@ -0,0 +1,123 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <common_test_utils/ov_tensor_utils.hpp>+#include <iostream>+#include <sstream>+#include <string>+#include <vector>++#include "openvino/openvino.hpp"+#include "openvino/opsets/opset6.hpp"+#include "openvino/pass/manager.hpp"+#include "openvino/pass/serialize.hpp"+#include "shared_test_classes/base/ov_behavior_test_utils.hpp"+namespace ov {+namespace test {+namespace behavior {++inline std::shared_ptr<ov::Model> createMaxPoolModel() {+ auto input =+ std::make_shared<ov::op::v0::Parameter>(element::f16, PartialShape{1, 16, 720, ov::Dimension(10, 1280)});+ input->set_friendly_name("input1");++ auto maxpool = std::make_shared<ov::op::v1::MaxPool>(input,+ Strides{1, 1},+ Shape{0, 0},+ Shape{0, 0},+ Shape{1, 1},+ op::RoundingType::FLOOR,+ op::PadType::EXPLICIT);+ maxpool->set_friendly_name("MaxPool_2");++ auto result = std::make_shared<ov::op::v0::Result>(maxpool);+ result->set_friendly_name("output");++ return std::make_shared<Model>(ResultVector{result}, ParameterVector{input}, "MaxPool");+}++using InferWithHostCompileParams = std::tuple<std::string, // Device name+ ov::AnyMap // Config+ >;++// These tests are required by the NPU plugin to verify the support of dynamic shape during+// compilation and inference on different NPU drivers+class InferWithHostCompileTests : public testing::WithParamInterface<InferWithHostCompileParams>,+ public OVInferRequestTestBase {+public:+ static std::string getTestCaseName(testing::TestParamInfo<InferWithHostCompileParams> obj) {+ std::string target_device;+ ov::AnyMap configuration;+ std::tie(target_device, configuration) = obj.param;+ std::replace(target_device.begin(), target_device.end(), ':', '.');+ std::ostringstream result;+ result << "targetDevice=" << target_device << "_";+ if (!configuration.empty()) {+ for (auto& configItem : configuration) {+ result << "configItem=" << configItem.first << "_";+ configItem.second.print(result);+ result << "_";+ }+ }+ return result.str();+ }++ void SetUp() {+ // Skip test according to plugin specific disabledTestPatterns() (if any)+ SKIP_IF_CURRENT_TEST_IS_DISABLED()++ std::tie(target_device, configuration) = this->GetParam();++ APIBaseTest::SetUp();+ }++protected:+ std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();+ ov::AnyMap configuration;+};++TEST_P(InferWithHostCompileTests, CompileAndImport) {+ // Skip test according to plugin specific disabledTestPatterns() (if any)+ SKIP_IF_CURRENT_TEST_IS_DISABLED()+ auto model = createMaxPoolModel();++ ov::CompiledModel compiledModel;+ // Compilation shall pass since load of npu_mlir_runtime is deffered with NPU_CREATE_EXECUTOR=0+ OV_ASSERT_NO_THROW(compiledModel = core->compile_model(model, target_device, configuration));++ std::stringstream modelStream;+ OV_ASSERT_NO_THROW(compiledModel.export_model(modelStream));++ // With HostCompile, the modelStream shall contain "llvm.func"+ std::string line;+ auto pos = modelStream.tellg();+ modelStream.seekg(0, std::ios::beg);+ bool isLLVMStream = false;+ int searchRegion = 10;+ while (std::getline(modelStream, line)) {+ if (line.find("llvm.func") != std::string::npos) {+ modelStream.clear();+ modelStream.seekg(pos);+ isLLVMStream = true;+ break;+ }+ if (searchRegion-- < 0) {+ break;+ }+ }+ modelStream.clear();+ modelStream.seekg(pos);+ ASSERT_TRUE(isLLVMStream) << "CompiledStream from HostCompile mode shall has 'llvm.func' inside it";++ ov::CompiledModel importedModel;+ OV_ASSERT_NO_THROW(core->import_model(modelStream, target_device, configuration));++ ov::InferRequest reqDynamic;+ // Add shape check once npu_mlir_runtime is inside test package+ EXPECT_THROW(reqDynamic = importedModel.create_infer_request(), ov::Exception);+}++} // namespace behavior+} // namespace test+} // namespace ov