OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Clean vm runtime 1.0 api usage (#39519)
Xin Wang28104fb15e06
diff --git a/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hppindex 7a0db145587..e699df3acd6 100644--- a/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp@@ -23,13 +23,12 @@ struct VMExecutionContext {VMExecutionContext& operator=(VMExecutionContext&&) = delete;~VMExecutionContext();- npu_vm_runtime_execution_context_handle_t ensure(npu_vm_runtime_handle_t vmRuntime);- npu_vm_runtime_execution_context_handle_t ensureV2(npu_vm_runtime_handle_t vmRuntime,- ze_context_handle_t ctx,- ze_device_handle_t device,- ze_command_queue_handle_t commandQueue,- ze_graph_dditable_ext_t* graphDdiTableExt,- ze_command_queue_npu_dditable_ext_t* queueDdiTableExt);+ npu_vm_runtime_execution_context_handle_t ensure(npu_vm_runtime_handle_t vmRuntime,+ ze_context_handle_t ctx,+ ze_device_handle_t device,+ ze_command_queue_handle_t commandQueue,+ ze_graph_dditable_ext_t* graphDdiTableExt,+ ze_command_queue_npu_dditable_ext_t* queueDdiTableExt);npu_vm_runtime_execution_context_handle_t handle() const {return _handle;}@@ -43,10 +42,6 @@ struct DynamicArguments {std::vector<npu_vm_runtime_mem_ref_handle_t> _outputMemRefHandles;npu_vm_runtime_execute_params2_t _executeParams2 = {};- // True once the command lists have been recorded by a first npuVMRuntimeExecute call. Subsequent- // executions can be replayed without re-recording when no tensor changed (see execute_vm_runtime).- bool _commandListsRecorded = false;-DynamicArguments() = default;DynamicArguments(const DynamicArguments&) = delete;DynamicArguments& operator=(const DynamicArguments&) = delete;@@ -62,29 +57,9 @@ struct DynamicArguments {class DynamicPipeline final : public IPipeline {struct PipelinedCommandLists {- std::shared_ptr<DynamicArguments> _arguments;-- 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,- bool useV2 = false) {- if (!useV2) {- // Only initialize command lists for v1, v2 handles command lists inside runtime- _commandLists.reserve(numCommandLists);- for (size_t i = 0; i < numCommandLists; i++) {- _commandLists.emplace_back(std::make_unique<CommandList>(init_structs));- }-- for (size_t i = 0; i < numCommandLists; i++) {- _commandListHandles.push_back(_commandLists[i]->handle());- }- }+ std::shared_ptr<DynamicArguments> _arguments = std::make_shared<DynamicArguments>();- _arguments = std::make_shared<DynamicArguments>();- }+ PipelinedCommandLists() = default;// Use metadata to initialize, which will later be updated again by setArgumentPropertiesvoid initArguments(const NetworkMetadata& metadata) {@@ -107,10 +82,6 @@ class DynamicPipeline final : public IPipeline {}}- std::vector<ze_command_list_handle_t>& getHandles() {- return _commandListHandles;- }-DynamicArguments& getArguments() {return *_arguments;}@@ -168,14 +139,8 @@ public:private:void execute_vm_runtime(npu_vm_runtime_handle_t vmRuntime,DynamicArguments& 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);- void execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,- DynamicArguments& args,- ze_command_queue_handle_t commandQueue,- const npu_vm_runtime_config_desc_t* pConfig);+ const npu_vm_runtime_config_desc_t* pConfig);const npu_vm_runtime_config_desc_t* update_runtime_config(const CommandQueueDesc& previousCommandQueueDesc,const CommandQueueDesc& currentCommandQueueDesc);@@ -184,7 +149,7 @@ private:std::vector<std::shared_ptr<CommandQueue>> _vm_referenced_command_queues;// VM execution context owned by this pipeline; shared between shape prediction and execution.VMExecutionContext _executionContext;- npu_vm_runtime_version_t _apiVersion = NPU_VM_RUNTIME_VERSION_1_0;+ npu_vm_runtime_version_t _apiVersion = NPU_VM_RUNTIME_VERSION_2_0;NpuVMRuntimeConfigChain _runtimeConfigChain;CommandQueueDesc _runtime_config_command_queue_desc;bool _runtime_config_command_queue_desc_valid = 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.cppindex f12a7c95472..b6bfd4e6988 100644--- a/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp@@ -50,8 +50,8 @@ struct MemRefTypeImpl {}}- bool UpdateMemRefHandleStatus(MemRefType& memref, bool useV2Api = false) {- // Update current MemRef handle to use latest metadata+ bool UpdateMemRefHandleStatus(MemRefType& memref) {+ // Update current MemRef handle to use latest metadata.bool newMemRefHandleCreated = false;if (_memRef == nullptr) {createMemRef(memref._dimsCount);@@ -60,9 +60,9 @@ struct MemRefTypeImpl {// Determine the dirty flag based on whether a new MemRef handle was created or existing metadata was modified.const uint32_t dirtyFlag = newMemRefHandleCreated ? MemRefType::ALL_DIRTY : memref.getDirtyFlag();if (dirtyFlag != 0) {- // V2 runtime accepts nullptr for metadata fields that were not changed.- const auto sizes = useV2Api && !(dirtyFlag & MemRefType::SHAPE_DIRTY) ? nullptr : memref._sizes.data();- const auto strides = useV2Api && !(dirtyFlag & MemRefType::STRIDE_DIRTY) ? nullptr : memref._strides.data();+ // The v2 runtime accepts nullptr for unchanged metadata entries.+ const auto sizes = !(dirtyFlag & MemRefType::SHAPE_DIRTY) ? nullptr : memref._sizes.data();+ const auto strides = !(dirtyFlag & MemRefType::STRIDE_DIRTY) ? nullptr : memref._strides.data();auto result = npuVMRuntimeSetMemRef(_memRef,memref._basePtr,memref._data,@@ -102,15 +102,7 @@ VMExecutionContext::~VMExecutionContext() {}}-npu_vm_runtime_execution_context_handle_t VMExecutionContext::ensure(npu_vm_runtime_handle_t vmRuntime) {- if (_handle == nullptr) {- const npu_vm_runtime_result_t result = npuVMRuntimeCreateExecutionContext(vmRuntime, &_handle);- OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS, "Failed to create a VM execution context");- }- return _handle;-}--npu_vm_runtime_execution_context_handle_t VMExecutionContext::ensureV2(+npu_vm_runtime_execution_context_handle_t VMExecutionContext::ensure(npu_vm_runtime_handle_t vmRuntime,ze_context_handle_t ctx,ze_device_handle_t device,@@ -171,46 +163,27 @@ DynamicPipeline::DynamicPipeline(const std::shared_ptr<ZeroInitStructsHolder>& iOPENVINO_ASSERT(versionResult == NPU_VM_RUNTIME_RESULT_SUCCESS,"Failed to get VM runtime version, error code: ",versionResult);+ _logger.debug("DynamicPipeline: using VM runtime API %u.%u",+ ZE_MAJOR_VERSION(_apiVersion),+ ZE_MINOR_VERSION(_apiVersion));- // v2 lets the runtime manage command-list recording and execution-context setup;- // v1 requires the plugin to create the execution context and provide command lists.- if (use_npu_vm_runtime_v2_api(_apiVersion)) {- _logger.debug("DynamicPipeline: using v2.0 VM runtime API");- const npu_vm_runtime_handle_t vmRuntime = static_cast<npu_vm_runtime_handle_t>(_graph->get_handle());- const auto commandQueueDesc = _graph->get_command_queue_desc();- _executionContext.ensureV2(vmRuntime,- init_structs->getContext(),- init_structs->getDevice(),- commandQueueDesc.sharedCommonQueue() ? _command_queue->handle() : nullptr,- _init_structs->getGraphDdiTable().getImpl(),- _init_structs->getCommandQueueDdiTable().getImpl());- if (commandQueueDesc.sharedCommonQueue()) {- _vm_referenced_command_queues.push_back(_command_queue);- }- _runtime_config_command_queue_desc = commandQueueDesc;- _runtime_config_command_queue_desc_valid = true;- } else {- _logger.debug("DynamicPipeline: using v1.x VM runtime API");- const npu_vm_runtime_handle_t vmRuntime = static_cast<npu_vm_runtime_handle_t>(_graph->get_handle());- _executionContext.ensure(vmRuntime);+ const npu_vm_runtime_handle_t vmRuntime = static_cast<npu_vm_runtime_handle_t>(_graph->get_handle());+ const auto commandQueueDesc = _graph->get_command_queue_desc();+ _executionContext.ensure(vmRuntime,+ init_structs->getContext(),+ init_structs->getDevice(),+ commandQueueDesc.sharedCommonQueue() ? _command_queue->handle() : nullptr,+ _init_structs->getGraphDdiTable().getImpl(),+ _init_structs->getCommandQueueDdiTable().getImpl());+ if (commandQueueDesc.sharedCommonQueue()) {+ _vm_referenced_command_queues.push_back(_command_queue);}+ _runtime_config_command_queue_desc = commandQueueDesc;+ _runtime_config_command_queue_desc_valid = true;- // v2 synchronizes through npuVMRuntimeHostSync, so only v1 needs plugin-side- // events or fences for output synchronization.- if (!use_npu_vm_runtime_v2_api(_apiVersion) && !_sync_output_with_fences) {- _event_pool = std::make_shared<EventPool>(_init_structs, 1);- _events.emplace_back(std::make_shared<Event>(_event_pool, 0));- }_logger.debug("Event pool and command queue setup completed");- const uint64_t num_of_subgraphs = _graph->get_metadata().numberOfSubgraphs;- if (!use_npu_vm_runtime_v2_api(_apiVersion) && _sync_output_with_fences) {- _fences.emplace_back(std::make_unique<Fence>(_command_queue));- }-- _command_list_group = std::make_unique<PipelinedCommandLists>(num_of_subgraphs,- _init_structs,- use_npu_vm_runtime_v2_api(_apiVersion));+ _command_list_group = std::make_unique<PipelinedCommandLists>();auto& commandLists = _command_list_group;commandLists->initArguments(_graph->get_metadata());@@ -254,41 +227,24 @@ void DynamicPipeline::push() {const npu_vm_runtime_handle_t vmRuntime = static_cast<npu_vm_runtime_handle_t>(_graph->get_handle());OPENVINO_ASSERT(vmRuntime != nullptr, "DynamicPipeline requires a valid VM runtime engine");- // v2 passes queue property changes as runtime config descriptors (and only- // refreshes the queue handle when a shared queue changes); v1 recreates the- // plugin-owned queue and, when needed, its fences.- const auto useV2Api = use_npu_vm_runtime_v2_api(_apiVersion);const auto commandQueueDesc = _graph->get_command_queue_desc();const bool commandQueueVersionChanged = (commandQueueDesc.key() != _command_queue->desc().key());const npu_vm_runtime_config_desc_t* runtimeConfig = nullptr;- if (useV2Api) {- if (commandQueueVersionChanged && commandQueueDesc.sharedCommonQueue()) {- // The outgoing queue stays alive in _vm_referenced_command_queues until Execute2 rebinds off it.- _command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, commandQueueDesc);- }-- if (_runtime_config_command_queue_desc_valid) {- runtimeConfig = update_runtime_config(_runtime_config_command_queue_desc, commandQueueDesc);- } else {- _runtime_config_command_queue_desc = commandQueueDesc;- _runtime_config_command_queue_desc_valid = true;- }- } else if (commandQueueVersionChanged) {- // v1 Fences own a shared_ptr to their queue, so the old queue outlives the fence recreation below;- // no extra retention is needed here (unlike the v2 runtime-owned fence migrated in Execute2).+ if (commandQueueVersionChanged && commandQueueDesc.sharedCommonQueue()) {+ // The outgoing queue stays alive in _vm_referenced_command_queues until Execute2 rebinds off it._command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, commandQueueDesc);+ }- if (_sync_output_with_fences) {- for (size_t i = 0; i < _fences.size(); i++) {- _fences[i] = std::make_unique<Fence>(_command_queue);- }- }+ if (_runtime_config_command_queue_desc_valid) {+ runtimeConfig = update_runtime_config(_runtime_config_command_queue_desc, commandQueueDesc);+ } else {+ _runtime_config_command_queue_desc = commandQueueDesc;+ _runtime_config_command_queue_desc_valid = true;}- const auto commandQueueHandle =- useV2Api && !commandQueueDesc.sharedCommonQueue() ? nullptr : _command_queue->handle();+ const auto commandQueueHandle = commandQueueDesc.sharedCommonQueue() ? _command_queue->handle() : nullptr;OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PUSH, itt::domains::LevelZeroBackend, "Pipeline", "push");auto& commandLists = _command_list_group;auto& dynamicArguments = commandLists->getArguments();@@ -305,14 +261,9 @@ void DynamicPipeline::push() {// Keep the v2 execute parameters in DynamicArguments because HostSync uses// the same parameter structure after push() returns.- if (useV2Api) {- execute_vm_runtime_v2(vmRuntime, dynamicArguments, commandQueueHandle, runtimeConfig);- _runtime_config_command_queue_desc = commandQueueDesc;- _runtime_config_command_queue_desc_valid = true;- } else {- const ze_fence_handle_t fence = _sync_output_with_fences ? _fences.front()->handle() : nullptr;- execute_vm_runtime(vmRuntime, dynamicArguments, commandLists->getHandles(), commandQueueHandle, fence, nullptr);- }+ execute_vm_runtime(vmRuntime, dynamicArguments, commandQueueHandle, runtimeConfig);+ _runtime_config_command_queue_desc = commandQueueDesc;+ _runtime_config_command_queue_desc_valid = true;_logger.debug("push - completed");}@@ -339,93 +290,9 @@ const npu_vm_runtime_config_desc_t* DynamicPipeline::update_runtime_config(void DynamicPipeline::execute_vm_runtime(npu_vm_runtime_handle_t vmRuntime,DynamicArguments& 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) {- _logger.debug("Start to execute graph with runtime engine");-- const bool firstInference = !args._commandListsRecorded;- bool noTensorChange = true;-- // These vectors only stage the memref handle pointers for the npuVMRuntimeExecute call below. The handle objects- // themselves are owned by the persistent DynamicArguments (args._inputsMemRef[i]._impl), so keeping these vectors- // local is safe even though device execution is async.- std::vector<npu_vm_runtime_mem_ref_handle_t> inputMemRefHandles, outputMemRefHandles;-- auto processMemRefs = [&](auto& memRefs, auto& targetMemRefHandles) {- targetMemRefHandles.clear();- targetMemRefHandles.reserve(memRefs.size());-- for (auto& memref : memRefs) {- std::shared_ptr<MemRefTypeImpl> impl = std::static_pointer_cast<MemRefTypeImpl>(memref._impl);- if (impl == nullptr) {- impl = std::make_shared<MemRefTypeImpl>();- memref._impl = impl;- }- const bool memRefUpdated = impl->UpdateMemRefHandleStatus(memref);-- // VM runtime execute path always needs current memref handles.- targetMemRefHandles.push_back(impl->_memRef);-- if (memRefUpdated) {- noTensorChange = false;- }- }- };-- processMemRefs(args._inputsMemRef, inputMemRefHandles);- processMemRefs(args._outputsMemRef, outputMemRefHandles);-- if (!firstInference && noTensorChange) {- _logger.debug("Reuse command list without update since no tensor change detected");- auto result = zeCommandQueueExecuteCommandLists(commandQueue,- static_cast<uint32_t>(commandLists.size()),- commandLists.data(),- fence);- OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, "Failed to submit command lists");- return;- }-- _logger.debug("Reset command list to run with runtime");- // Reset commandLists since there are tensor with new shapes or it is the first execution, can not reuse command- // list with update- for (auto& cmdList : commandLists) {- const auto result = zeCommandListReset(cmdList);- OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, "Failed to reset command list");- }-- npu_vm_runtime_execute_params_t params = {};- params.executionContext = _executionContext.ensure(vmRuntime);- params.pInputs = inputMemRefHandles.data();- params.numOfInputs = static_cast<uint32_t>(inputMemRefHandles.size());- params.pOutputs = outputMemRefHandles.data();- params.numOfOutputs = static_cast<uint32_t>(outputMemRefHandles.size());- params.ctx = _init_structs->getContext();- params.device = _init_structs->getDevice();- params.graphDdiTableExt = _init_structs->getGraphDdiTable().getImpl();- params.commandLists = commandLists.data();- params.numCommandLists = static_cast<uint64_t>(commandLists.size());- params.commandQueue = commandQueue;- params.inferenceFence = fence;- params.event = event;-- _logger.debug("Execute graph with runtime engine");- const auto result = npuVMRuntimeExecute(vmRuntime, ¶ms);- OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS,- "Failed to execute VM runtime engine, error code: ",- result);- _logger.debug("Execution runtime engine is created successfully.");-- args._commandListsRecorded = true;- _logger.debug("Completed to execute graph with runtime engine");-}--void DynamicPipeline::execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,- DynamicArguments& args,- ze_command_queue_handle_t commandQueue,- const npu_vm_runtime_config_desc_t* pConfig) {- _logger.debug("execute_vm_runtime_v2 - started");+ const npu_vm_runtime_config_desc_t* pConfig) {+ _logger.debug("execute_vm_runtime - started");// Keep these arrays in DynamicArguments: the v2 execute parameters are reused// by HostSync after this function returns, so their pInputs/pOutputs pointers@@ -439,7 +306,7 @@ void DynamicPipeline::execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,impl = std::make_shared<MemRefTypeImpl>();memref._impl = impl;}- impl->UpdateMemRefHandleStatus(memref, true);+ impl->UpdateMemRefHandleStatus(memref);targetHandles.push_back(impl->_memRef);}};@@ -456,7 +323,7 @@ void DynamicPipeline::execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,params.numOfOutputs = static_cast<uint32_t>(args._outputMemRefHandles.size());params.executionContext = _executionContext.handle();- _logger.debug("execute_vm_runtime_v2 - calling npuVMRuntimeExecute2");+ _logger.debug("execute_vm_runtime - calling npuVMRuntimeExecute2");const auto result = npuVMRuntimeExecute2(vmRuntime, ¶ms);if (commandQueue != nullptr) {auto& queues = _vm_referenced_command_queues;@@ -470,7 +337,7 @@ void DynamicPipeline::execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,"Failed to execute VM runtime engine (v2), error code: ",result);- _logger.debug("execute_vm_runtime_v2 - completed");+ _logger.debug("execute_vm_runtime - completed");}std::vector<ov::Shape> DynamicPipeline::predict_output_shapes(@@ -527,7 +394,7 @@ std::vector<ov::Shape> DynamicPipeline::predict_output_shapes(impl = std::make_shared<MemRefTypeImpl>();memref._impl = impl;}- impl->UpdateMemRefHandleStatus(memref, use_npu_vm_runtime_v2_api(_apiVersion));+ impl->UpdateMemRefHandleStatus(memref);destMemRefHandles.push_back(impl->_memRef);}};@@ -538,25 +405,14 @@ std::vector<ov::Shape> DynamicPipeline::predict_output_shapes(npu_vm_runtime_result_t result = NPU_VM_RUNTIME_RESULT_SUCCESS;_logger.debug("VM runtime version: %u.%u", ZE_MAJOR_VERSION(_apiVersion), ZE_MINOR_VERSION(_apiVersion));- if (_apiVersion == NPU_VM_RUNTIME_VERSION_1_0) {- npu_vm_runtime_predict_output_shape_params_t params{};- params.pInputs = inputMemRefHandles.data();- params.numOfInputs = static_cast<uint32_t>(inputMemRefHandles.size());- params.pOutputs = outputMemRefHandles.data();- params.numOfOutputs = static_cast<uint32_t>(outputMemRefHandles.size());+ npu_vm_runtime_predict_output_shape_params_t2 params{};+ params.pInputs = inputMemRefHandles.data();+ params.numOfInputs = static_cast<uint32_t>(inputMemRefHandles.size());+ params.pOutputs = outputMemRefHandles.data();+ params.numOfOutputs = static_cast<uint32_t>(outputMemRefHandles.size());+ params.executionContext = _executionContext.handle();- result = npuVMRuntimePredictOutputShape(vmRuntime, ¶ms);- } else {- npu_vm_runtime_predict_output_shape_params_t2 params{};- params.pInputs = inputMemRefHandles.data();- params.numOfInputs = static_cast<uint32_t>(inputMemRefHandles.size());- params.pOutputs = outputMemRefHandles.data();- params.numOfOutputs = static_cast<uint32_t>(outputMemRefHandles.size());- params.executionContext =- use_npu_vm_runtime_v2_api(_apiVersion) ? _executionContext.handle() : _executionContext.ensure(vmRuntime);-- result = npuVMRuntimePredictOutputShape2(vmRuntime, ¶ms);- }+ result = npuVMRuntimePredictOutputShape2(vmRuntime, ¶ms);OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS,"Failed to predict output shape with VM runtime engine, error code: ",@@ -608,20 +464,11 @@ void DynamicPipeline::pull() {_logger.debug("pull - started");OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PULL, itt::domains::LevelZeroBackend, "DynamicPipeline", "pull");- const npu_vm_runtime_handle_t vmRuntime =- use_npu_vm_runtime_v2_api(_apiVersion) ? static_cast<npu_vm_runtime_handle_t>(_graph->get_handle()) : nullptr;-- // v2 exposes host synchronization through the runtime; v1 completes through- // the event or fence created by the plugin.- if (use_npu_vm_runtime_v2_api(_apiVersion)) {- auto& dynamicArguments = _command_list_group->getArguments();- const auto result = npuVMRuntimeHostSync(vmRuntime, &dynamicArguments._executeParams2);- OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS, "npuVMRuntimeHostSync failed, error code: ", result);- } else if (_sync_output_with_fences) {- _fences.front()->hostSynchronize();- } else {- _events.front()->hostSynchronize();- }+ const npu_vm_runtime_handle_t vmRuntime = static_cast<npu_vm_runtime_handle_t>(_graph->get_handle());++ auto& dynamicArguments = _command_list_group->getArguments();+ const auto result = npuVMRuntimeHostSync(vmRuntime, &dynamicArguments._executeParams2);+ OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS, "npuVMRuntimeHostSync failed, error code: ", result);_logger.debug("pull - completed");}@@ -634,15 +481,7 @@ std::vector<ov::ProfilingInfo> DynamicPipeline::get_profiling_info() const {}void DynamicPipeline::reset() const {- _logger.debug("reset - started");- if (!use_npu_vm_runtime_v2_api(_apiVersion)) {- if (_sync_output_with_fences) {- _fences.front()->reset();- } else {- _events.front()->reset();- }- }- _logger.debug("reset - completed");+ // No-op for the dynamic pipeline reset path.}void DynamicPipeline::update_graph_arguments(uint32_t index,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.hppindex d5987285d4a..0d0483b6062 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp@@ -88,7 +88,7 @@ private:npu_vm_runtime_handle_t _engine = nullptr;npu_vm_runtime_properties_t _engineProperties{};- npu_vm_runtime_version_t _apiVersion = NPU_VM_RUNTIME_VERSION_1_0;+ npu_vm_runtime_version_t _apiVersion = NPU_VM_RUNTIME_VERSION_2_0;// Set once the VM engine is created and _metadata is populated from it; get_metadata() throws before thatstd::atomic<bool> _metadataInitialized{false};};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.cppindex 0f96b5923db..1eebf5581f3 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp@@ -51,15 +51,13 @@ void DynamicGraph::create_execution_engine(const Config& config) {if (npuVMRuntimeGetAPIVersion(&_apiVersion) != NPU_VM_RUNTIME_RESULT_SUCCESS) {OPENVINO_THROW("Failed to get VM runtime API version");}+ _logger.debug("DynamicGraph: using VM runtime API %u.%u",+ ZE_MAJOR_VERSION(_apiVersion),+ ZE_MINOR_VERSION(_apiVersion));- const auto result = [&]() {- if (use_npu_vm_runtime_v2_api(_apiVersion)) {- NpuVMRuntimeConfigChain runtimeConfig;- populateRuntimeConfigChain(runtimeConfig, config);- return npuVMRuntimeCreate2(&blobDesc, runtimeConfig.head(), &_engine, &_engineProperties);- }- return npuVMRuntimeCreate(&blobDesc, &_engine, &_engineProperties);- }();+ NpuVMRuntimeConfigChain runtimeConfig;+ populateRuntimeConfigChain(runtimeConfig, config);+ const auto result = npuVMRuntimeCreate2(&blobDesc, runtimeConfig.head(), &_engine, &_engineProperties);if (result != NPU_VM_RUNTIME_RESULT_SUCCESS) {OPENVINO_THROW("Failed to create VM runtime engine");@@ -300,7 +298,7 @@ void DynamicGraph::initialize_impl(const Config& runtimeConfig) {this,sharedCommonQueue};- if (!use_npu_vm_runtime_v2_api(_apiVersion) && sharedCommonQueue == false) {+ if (!sharedCommonQueue) {// Keep it alive per compiled model when the shared common queue feature is disabled._commandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, _commandQueueDesc);}diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_api.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_api.hppindex 8f4659849b7..b523da21609 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_api.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_api.hpp@@ -16,29 +16,24 @@namespace intel_npu {// clang-format off-#define nvm_symbols_list() \- nvm_symbol_statement(npuVMRuntimeGetAPIVersion) \- nvm_symbol_statement(npuVMRuntimeCreate) \- nvm_symbol_statement(npuVMRuntimeDestroy) \- nvm_symbol_statement(npuVMRuntimeGetMetadata) \- nvm_symbol_statement(npuVMRuntimeExecute) \- nvm_symbol_statement(npuVMRuntimePredictOutputShape) \- nvm_symbol_statement(npuVMRuntimeCreateMemRef) \- nvm_symbol_statement(npuVMRuntimeDestroyMemRef) \- nvm_symbol_statement(npuVMRuntimeSetMemRef) \- nvm_symbol_statement(npuVMRuntimeParseMemRef) \- nvm_symbol_statement(npuVMRuntimeCreateExecutionContext) \- nvm_symbol_statement(npuVMRuntimeDestroyExecutionContext) \- nvm_symbol_statement(npuVMRuntimeUpdateMutableCommandList)--// symbols that may not be supported in older versions-#define nvm_weak_symbols_list() \+#define nvm_symbols_list() \+ nvm_symbol_statement(npuVMRuntimeGetAPIVersion) \+ nvm_symbol_statement(npuVMRuntimeDestroy) \+ nvm_symbol_statement(npuVMRuntimeGetMetadata) \+ nvm_symbol_statement(npuVMRuntimeCreateMemRef) \+ nvm_symbol_statement(npuVMRuntimeDestroyMemRef) \+ nvm_symbol_statement(npuVMRuntimeSetMemRef) \+ nvm_symbol_statement(npuVMRuntimeParseMemRef) \+ nvm_symbol_statement(npuVMRuntimeDestroyExecutionContext) \+ nvm_symbol_statement(npuVMRuntimeCreate2) \+ nvm_symbol_statement(npuVMRuntimeCreateExecutionContext2) \nvm_symbol_statement(npuVMRuntimePredictOutputShape2) \- nvm_symbol_statement(npuVMRuntimeCreate2) \- nvm_symbol_statement(npuVMRuntimeCreateExecutionContext2) \- nvm_symbol_statement(npuVMRuntimeExecute2) \+ nvm_symbol_statement(npuVMRuntimeExecute2) \nvm_symbol_statement(npuVMRuntimeHostSync)+#define nvm_weak_symbols_list() \+ /* 2.0 API is required; no legacy weak fallback is kept */+// clang-format onclass NPUVMRuntimeApi {diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_utils.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_utils.hppindex 48967e4c1ef..8c577927c85 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_utils.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime_utils.hpp@@ -12,10 +12,6 @@namespace intel_npu {-inline bool use_npu_vm_runtime_v2_api(npu_vm_runtime_version_t apiVersion) {- return apiVersion >= NPU_VM_RUNTIME_VERSION_2_0;-}-class NpuVMRuntimeConfigChain final {public:NpuVMRuntimeConfigChain() = default;diff --git a/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cpp b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cppindex 722f09fab92..8ab0ccf01aa 100644--- a/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile.cpp@@ -133,8 +133,6 @@ public:const ov::Tensor& inputTensor,const std::string& dumpPrefix);- static bool logContains(const ScopedLogCapture& logCapture, const std::string& expectedEntry);-static std::shared_ptr<ov::Model> createModelByName(const std::string& modelName);RuntimeCompareSetupResult prepareRuntimeCompareContext(const std::shared_ptr<ov::Model>& model);@@ -208,15 +206,6 @@ void InferWithHostCompileTests::setInputInferAndCompare(const std::shared_ptr<ovinferAndCompare(model, reqDynamic, reqReference, stage);}-bool InferWithHostCompileTests::logContains(const ScopedLogCapture& logCapture, const std::string& expectedEntry) {- const auto logs = logCapture.str();- if (logs.find("execute_vm_runtime_v2 - started") != std::string::npos) {- // VM runtime v2 manages command lists internally, so plugin-side legacy command list logs are not required- return true;- }- return logCapture.str().find(expectedEntry) != std::string::npos;-}-std::shared_ptr<ov::Model> InferWithHostCompileTests::createModelByName(const std::string& modelName) {return createESPCNX2ModelByName(modelName);}@@ -282,8 +271,8 @@ TEST_P(InferWithHostCompileTests, CompileAndImportAndInfer) {OV_ASSERT_NO_THROW(reqDynamic.infer());}-// Compile, infer with a large shape, then shrink the input shape and verify both output correctness and command-list-// reuse behavior.+// Compile, infer with a large shape, then shrink the input shape and verify the dynamic v2 execution path still+// produces the expected outputs and runtime state transitions.TEST_P(InferWithHostCompileTests, CompileAndInferWithDecreasedSize) {// Skip test according to plugin specific disabledTestPatterns() (if any)SKIP_IF_CURRENT_TEST_IS_DISABLED()@@ -313,17 +302,9 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithDecreasedSize) {testContext.reqReference,inTensor,"CompileAndInferWithDecreasedSize_first");- // The first run materializes runtime state for the initial shape.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime', but got: " << logCapture.str();logCapture.clear();inferAndCompare(model, testContext.reqDynamic, testContext.reqReference, "CompileAndInferWithDecreasedSize_second");- // Reusing the same input should keep the existing command list intact.- ASSERT_TRUE(logContains(logCapture, "Reuse command list without update since no tensor change detected"))- << "Expected log to contain 'Reuse command list without update since no tensor change detected' for second "- "inference, but got: "- << logCapture.str();ov::Tensor inTensor1 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);setInputInferAndCompare(model,@@ -342,15 +323,10 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithDecreasedSize) {testContext.reqReference,inTensor3,"CompileAndInferWithDecreasedSize_fourth");- // Shrinking the shape should force runtime reconfiguration for the new tensor layout.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for fourth inference with new shape, but "- "got: "- << logCapture.str();}-// Compile, infer with a small shape, then grow the input shape and verify both output correctness and command-list-// reuse behavior.+// Compile, infer with a small shape, then grow the input shape and verify the dynamic v2 execution path still+// produces the expected outputs and runtime state transitions.TEST_P(InferWithHostCompileTests, CompileAndInferWithIncreasedSize) {// Skip test according to plugin specific disabledTestPatterns() (if any)SKIP_IF_CURRENT_TEST_IS_DISABLED()@@ -381,17 +357,9 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithIncreasedSize) {testContext.reqReference,inTensor,"CompileAndInferWithIncreasedSize_first");- // The first run materializes runtime state for the initial shape.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime', but got: " << logCapture.str();logCapture.clear();inferAndCompare(model, testContext.reqDynamic, testContext.reqReference, "CompileAndInferWithIncreasedSize_second");- // Reusing the same input should keep the existing command list intact.- ASSERT_TRUE(logContains(logCapture, "Reuse command list without update since no tensor change detected"))- << "Expected log to contain 'Reuse command list without update since no tensor change detected' for second "- "inference, but got: "- << logCapture.str();ov::Tensor inTensor1 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);setInputInferAndCompare(model,@@ -409,14 +377,10 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithIncreasedSize) {testContext.reqReference,inTensor3,"CompileAndInferWithIncreasedSize_fourth");- // Growing the shape should force runtime reconfiguration for the new tensor layout.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for fourth inference with new shape, but "- "got: "- << logCapture.str();}-// Exercise imported Level Zero tensors and verify both output correctness and command-list pointer updates.+// Exercise imported Level Zero tensors and verify output correctness and runtime state transitions for host-backed+// input/output tensors.TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {// Skip test according to plugin specific disabledTestPatterns() (if any)SKIP_IF_CURRENT_TEST_IS_DISABLED()@@ -446,17 +410,10 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {inTensor,"CompileAndInferWithZeroTensor_first");- // The first run materializes runtime state for the initial shape.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime', but got: " << logCapture.str();-logCapture.clear();ov::InferRequest reqDynamic1 = testContext.compiledModel.create_infer_request();ov::InferRequest reqReference1 = testContext.referenceCompiledModel.create_infer_request();setInputInferAndCompare(model, reqDynamic1, reqReference1, inTensor, "CompileAndInferWithZeroTensor_second");- // A fresh infer request rebuilds runtime state on its first execution.- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime', but got: " << logCapture.str();logCapture.clear();auto zeroContext = core.get_default_context(target_device);@@ -472,11 +429,6 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {reqReference1,inputTensorForThirdInfer,"CompileAndInferWithZeroTensor_third");- // Feeding a context-allocated tensor with a new data pointer rebuilds the runtime state.- // TODO: Update commandlist once dynamic stride supported- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for third inference, but got: "- << logCapture.str();logCapture.clear();auto inputHostTensorForForthInfer = zeroContext.create_host_tensor(model->input().get_element_type(), shape);@@ -492,11 +444,6 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {reqReference1,inputHostTensorForForthInfer,"CompileAndInferWithZeroTensor_fourth");- // Feeding a context-allocated host tensor, ptr change detected and rebuild runtime- // TODO: Update commandlist once dynamic stride supported- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for fourth inference, but got: "- << logCapture.str();logCapture.clear();auto outputShape = reqDynamic1.get_tensor(model->output()).get_shape();@@ -511,11 +458,6 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {hostTensorSourceForOutputForFifthInfer.get_byte_size());OV_ASSERT_NO_THROW(reqDynamic1.set_tensor(model->output(), zeroOutputTensorForFifthInfer));inferAndCompare(model, reqDynamic1, reqReference1, "CompileAndInferWithZeroTensor_fifth");- // Feeding a context-allocated host tensor as output, ptr change detected and rebuild runtime- // TODO: Update commandlist once dynamic stride supported- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for fifth inference, but got: "- << logCapture.str();logCapture.clear();auto inputTensorForSixthInfer =@@ -540,11 +482,6 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {reqReference1,inputTensorForSixthInfer,"CompileAndInferWithZeroTensor_sixth");- // Feeding a context-allocated host tensor, ptr change detected and rebuild runtime- // TODO: Update commandlist once dynamic stride supported- ASSERT_TRUE(logContains(logCapture, "Reset command list to run with runtime"))- << "Expected log to contain 'Reset command list to run with runtime' for sixth inference, but got: "- << logCapture.str();}TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {@@ -593,8 +530,7 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {return count;};const auto countVMExecutions = [&countMarker](const std::string& log) {- return countMarker(log, "Start to execute graph with runtime engine") +- countMarker(log, "execute_vm_runtime_v2 - started");+ return countMarker(log, "execute_vm_runtime - started");};ASSERT_EQ(countVMExecutions(logCapture.str()), 1u) << logCapture.str();@@ -618,8 +554,8 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {// ── V2: NPU_SHARED_COMMON_QUEUE=YES and =NO baseline ─────────────────────────//-// shared=YES → DynamicPipeline::DynamicPipeline() calls ensureV2(..., queue->handle(), ...)-// shared=NO → ensureV2(..., nullptr, ...) (vm_runtime owns the internal queue)+// shared=YES → DynamicPipeline::DynamicPipeline() calls ensure(..., queue->handle(), ...)+// shared=NO → ensure(..., nullptr, ...) (vm_runtime owns the internal queue)// Verifies first-infer, reuse (same ptr), new-ptr, and shape-change for both modes.TEST_P(InferWithHostCompileTests, SharedCommonQueue_BasicInferAndReuse) {SKIP_IF_CURRENT_TEST_IS_DISABLED()@@ -931,7 +867,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_CombinedPriorityAndWorkload) {// → command_queue_desc.key() != _command_queue->desc().key() (changed)// → [shared=YES] _command_queue = ZeroCmdQueuePool::getCommandQueue(new_desc)// → update_runtime_config(prev_desc, curr_desc) → QUEUE_PRIORITY diff → pConfig-// → execute_vm_runtime_v2(..., pConfig) → npuVMRuntimeExecute2 with pConfig+// → execute_vm_runtime(..., pConfig) → npuVMRuntimeExecute2 with pConfig//// Transitions: LOW → HIGH → MEDIUM → LOW; also verifies a new InferRequest created// after set_property picks up the updated CommandQueueDesc.@@ -1414,7 +1350,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_Priority_BetweenTwoRequests_NonSha// - different shape// Validates output correctness for all cases (this test does not assert on specific log messages).// The test is skipped when the v2 code path is not active (i.e., when-// "execute_vm_runtime_v2 - started" is absent from the first-inference logs).+// "execute_vm_runtime - started" is absent from the first-inference logs).TEST_P(InferWithHostCompileTests, MemRefReuse_SamePtrSameShape) {SKIP_IF_CURRENT_TEST_IS_DISABLED()if (!isTargetDevice) {