Skip to content

[NPU]Move part DynamicGraph func toDynamicPipeline and refactor dynamic graph#36099

Open
DanLiu2Intel wants to merge 30 commits into
openvinotoolkit:masterfrom
DanLiu2Intel:master_refactorDynamicGraph
Open

[NPU]Move part DynamicGraph func toDynamicPipeline and refactor dynamic graph#36099
DanLiu2Intel wants to merge 30 commits into
openvinotoolkit:masterfrom
DanLiu2Intel:master_refactorDynamicGraph

Conversation

@DanLiu2Intel

@DanLiu2Intel DanLiu2Intel commented May 27, 2026

Copy link
Copy Markdown
Contributor

Details:

Refactor DynamicGraph interface, move vm_execution logic and add static predict_shape func to DynamicPipeline
Details:

  • Add DynamicPipeline::execute_vm_runtime to replace dynamicGraph->execute in DynamicPipeline::push().
  • Add DynamicPipeline::predict_output_shape to replace dynamicGraph->predict_output_shape in ZeroDynamicInferRequest::infer_predict_shapes. This logic is not moved to DynamicPipeline::push() in this PR to prevent DynamicPipeline from including _userOutputTensors and _userinputTensors from ZeroDynamicInferRequest.
  • Consolidate IDynamicGraph::GraphArgument with DynamicGraph::GraphArgumentsImpl to intel_npu::GraphArgument in dynamic_pipeline. Move DynamicGraph::MemRefTypeImp to the intel_npu::MemRefTypeImp in dynamic_pipeline. Move IDynamicGraph::MemRefType to intel_npu::MemRefType in utils/vm/dynamic_arguments file.
  • Remove the binding methods from GraphArguments and DynamicGraphImpl, and merge the remaining functionality of DynamicGraphImpl into GraphArguments.
  • Update igraph::get_handle to return pointers to npu_vm_runtime_handle_t and ze_graph_handle_t. Add num_subgraphs metadata to deprecate and remove IDynamicGraph. Update DynamicGraph to inherit from IGraph.
  • Include openvino_npu_vm_utils into openvino_npu_common to resolve the ov_npu_unit_tests linking issue.
  • Remove npu_vm_runtime_api target and move npu_vm_runtime.hpp to vm/utils

Tickets:

AI Assistance:

  • AI assistance used: no / yes
  • If yes, summarize how AI was used and what human validation was performed (build/tests/manual checks).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Intel NPU plugin “dynamic graph” path by removing the IDynamicGraph interface, introducing a shared GraphArguments/MemRefType API in common, and moving VM-runtime execution + shape prediction logic into the Level Zero dynamic pipeline. Build wiring is updated so VM utils are a standalone static library target (openvino::npu_vm_utils) and linked where needed.

Changes:

  • Replace IDynamicGraph with IGraph extensions (get_vm_runtime_handle(), get_num_subgraphs()), and simplify DynamicGraph accordingly.
  • Introduce dynamic_graph_arguments.hpp (+ impl header) and migrate argument/VM MemRef tracking to the backend pipeline.
  • Update CMake targets to build/link/install openvino_npu_vm_utils as a static library and link it from dependent components.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/plugins/intel_npu/src/utils/src/vm/CMakeLists.txt Switch VM utils from OBJECT → STATIC lib, add alias and install rule
src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp Remove per-call binding/execute/predict logic; expose VM runtime handle
src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp Move from IDynamicGraph to IGraph, drop old dynamic-graph-specific APIs
src/plugins/intel_npu/src/compiler_adapter/CMakeLists.txt Stop consuming VM utils as object files; link openvino::npu_vm_utils
src/plugins/intel_npu/src/common/src/igraph.cpp Add default get_vm_runtime_handle() / get_num_subgraphs() implementations
src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp Extend IGraph interface with VM-runtime handle + subgraph count
src/plugins/intel_npu/src/common/src/dynamic_graph_arguments.cpp Move MemRef/GraphArguments implementation out of removed IDynamicGraph
src/plugins/intel_npu/src/common/include/intel_npu/common/dynamic_graph_arguments.hpp New shared MemRefType + GraphArguments API
src/plugins/intel_npu/src/common/include/intel_npu/common/dynamic_graph_arguments_impl.hpp New header-only impl for VM MemRef + execute params lifetime tracking
src/plugins/intel_npu/src/common/CMakeLists.txt Link common against VM utils
src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp Implement VM-runtime execute + predict-shape in pipeline
src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp Rework binding to use new GraphArguments; add predict-shape API
src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cpp Route predict-shape through pipeline static helper; use new MemRefType
src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hpp Update signatures to new MemRefType
src/plugins/intel_npu/src/backend/src/zero_device.cpp Detect dynamic graphs via get_vm_runtime_handle() rather than RTTI
src/plugins/intel_npu/src/common/include/intel_npu/common/idynamic_graph.hpp Remove obsolete interface
Comments suppressed due to low confidence (2)

src/plugins/intel_npu/src/common/src/dynamic_graph_arguments.cpp:138

  • [BLOCKER] GraphArguments::setArgumentProperties() can read past the end of the provided strides vector.

In assign_slot(), when _dimsCount==0 the code resizes slot._strides to strides.size(), but then unconditionally loops i < slot._dimsCount (== sizes.size()) and indexes strides[i]. If strides.size() != sizes.size() (e.g. empty strides for scalar/unknown-strides tensors), this is out-of-bounds and will crash in the dynamic pipeline/predict-shape paths.

Please validate strides.size() == sizes.size() (or treat empty strides as contiguous and compute them from sizes), and always size slot._strides to sizes.size().
src/plugins/intel_npu/src/utils/src/vm/CMakeLists.txt:27

  • [MEDIUM] openvino_npu_vm_utils was converted from an OBJECT library to a standalone STATIC library, but it still doesn't declare its link dependencies.

npu_vm_runtime_api.cpp uses ov::util (make_plugin_library_name/load_shared_object/get_symbol). With a STATIC library, relying on every consumer to link the right OpenVINO utility targets is brittle and can cause link-order failures when openvino::npu_vm_utils is consumed independently.

Please add an explicit target_link_libraries(openvino_npu_vm_utils ...) (at least openvino::util; and any other required libs) to make the target self-contained.

add_library(${TARGET_NAME} STATIC ${SOURCES})
add_library(openvino::npu_vm_utils ALIAS ${TARGET_NAME})

set_target_properties(${TARGET_NAME} PROPERTIES
    INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}
    EXPORT_NAME npu_vm_utils)

ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})

target_include_directories(${TARGET_NAME}
    PUBLIC
        $<BUILD_INTERFACE:${NPU_UTILS_SOURCE_DIR}/include>
        $<TARGET_PROPERTY:openvino::util,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:openvino::core::dev,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:npu_vm_runtime_api,INTERFACE_INCLUDE_DIRECTORIES>
        $<TARGET_PROPERTY:openvino_npu_zero_utils,INTERFACE_INCLUDE_DIRECTORIES>
)

Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp Outdated
Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp Outdated
@XinWangIntel XinWangIntel requested a review from Copilot May 28, 2026 06:57
@DanLiu2Intel DanLiu2Intel changed the title [TEST][DO NOT REVIEW]Master refactor dynamic graph [NPU]Move part DynamicGraph func toDynamicPipeline and refactor dynamic graph May 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/plugins/intel_npu/src/common/src/dynamic_graph_arguments.cpp:138

  • [BLOCKER] GraphArguments::setArgumentProperties() can read past the end of strides (and write past _strides) when the caller passes an empty strides vector (common for continuous tensors / tensors with get_strides().empty()). slot._strides is resized to strides.size() (possibly 0), but the subsequent loop indexes strides[i] for i < _dimsCount.

Fix: require strides.empty() || strides.size() == sizes.size(), and when strides.empty() compute contiguous element-strides (e.g., fill _sizes then call slot.updateStride()), otherwise resize _strides to sizes.size() before filling.
src/plugins/intel_npu/src/common/src/dynamic_graph_arguments.cpp:70

  • [HIGH] MemRefType::set() assumes tensor->get_strides() has rank elements and indexes it unconditionally. For OpenVINO tensors, get_strides() can be empty (e.g., sub-byte element types), which would cause out-of-bounds access here.

Fix: if tensor->get_strides().empty(), populate _strides via updateStride() (contiguous row-major) instead of indexing the empty stride vector; otherwise validate strides.size() == _dimsCount before reading.

Comment thread src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp
Comment thread src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp Outdated
Comment thread src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp Outdated
Comment thread src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp Outdated
Comment thread src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp Outdated
Comment thread src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cpp Outdated
@DanLiu2Intel DanLiu2Intel force-pushed the master_refactorDynamicGraph branch 3 times, most recently from 8d63054 to be04321 Compare June 7, 2026 16:21
@DanLiu2Intel DanLiu2Intel requested a review from Copilot June 7, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp:131

  • [BLOCKER] prepare_metadata() passes upperBound.data() from a vector that is only reserved (size==0). upperBound.data() will be nullptr, so npuVMRuntimeGetMetadata may write through a null pointer / out of bounds.

Allocate the buffer with the required size (e.g., ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE) before passing its data pointer.

        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 (npuVMRuntimeGetMetadata(_engine, i, &arg, &meta, upperBound.data()) != NPU_VM_RUNTIME_RESULT_SUCCESS) {

Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 2 comments.

Comment thread src/plugins/intel_npu/src/backend/src/zero_dynamic_infer_request.cpp Outdated
Comment thread src/plugins/intel_npu/src/backend/CMakeLists.txt
@DanLiu2Intel DanLiu2Intel requested a review from a team as a code owner July 2, 2026 03:28
@DanLiu2Intel DanLiu2Intel requested review from whitneyfoster and removed request for a team July 2, 2026 03:28
@github-actions github-actions Bot added the category: docs OpenVINO documentation label Jul 2, 2026
@github-actions github-actions Bot removed the category: docs OpenVINO documentation label Jul 2, 2026
@DanLiu2Intel DanLiu2Intel removed the request for review from whitneyfoster July 2, 2026 03:38
@DanLiu2Intel DanLiu2Intel force-pushed the master_refactorDynamicGraph branch from 614935e to 3aa3eff Compare July 6, 2026 02:53
@DanLiu2Intel DanLiu2Intel force-pushed the master_refactorDynamicGraph branch from 3aa3eff to 5eb56d0 Compare July 6, 2026 08:00
Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp Outdated
Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hpp Outdated
Comment thread src/plugins/intel_npu/src/backend/include/zero_dynamic_infer_request.hpp Outdated
@DanLiu2Intel DanLiu2Intel force-pushed the master_refactorDynamicGraph branch from 2be36d3 to ac57af8 Compare July 14, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: build OpenVINO cmake script / infra category: NPU OpenVINO NPU plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants