Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU]Update host compile test model to espcn_x2_gh (#38764)

Dan Liucb361f7c6a21
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.hpp
index c6e57f641fd..7a0db145587 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
@@ -179,6 +179,9 @@ private:
const npu_vm_runtime_config_desc_t* update_runtime_config(const CommandQueueDesc& previousCommandQueueDesc,
const CommandQueueDesc& currentCommandQueueDesc);
+ // Shared queues the VM runtime may still hold a fence on: a successful Execute2 rebinds to the passed queue, a
+ // failed one may fail before or after rebinding. Declared before _executionContext so these outlive it.
+ 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;
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.cpp
index 372ca5796e7..1aa648aee20 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
@@ -7,6 +7,7 @@
#include <level_zero/ze_api.h>
#include <ze_graph_ext.h>
+#include <algorithm>
#include <sstream>
#include "intel_npu/common/itt.hpp"
@@ -183,6 +184,9 @@ DynamicPipeline::DynamicPipeline(const std::shared_ptr<ZeroInitStructsHolder>& i
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 {
@@ -260,8 +264,10 @@ void DynamicPipeline::push() {
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);
}
@@ -272,6 +278,8 @@ void DynamicPipeline::push() {
_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).
_command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, commandQueueDesc);
if (_sync_output_with_fences) {
@@ -452,6 +460,14 @@ void DynamicPipeline::execute_vm_runtime_v2(npu_vm_runtime_handle_t vmRuntime,
_logger.debug("execute_vm_runtime_v2 - calling npuVMRuntimeExecute2");
const auto result = npuVMRuntimeExecute2(vmRuntime, &params);
+ if (commandQueue != nullptr) {
+ auto& queues = _vm_referenced_command_queues;
+ if (result == NPU_VM_RUNTIME_RESULT_SUCCESS) {
+ queues.assign(1, _command_queue);
+ } else if (std::find(queues.begin(), queues.end(), _command_queue) == queues.end()) {
+ queues.push_back(_command_queue);
+ }
+ }
OPENVINO_ASSERT(result == NPU_VM_RUNTIME_RESULT_SUCCESS,
"Failed to execute VM runtime engine (v2), error code: ",
result);
@@ -538,12 +554,6 @@ std::vector<ov::Shape> DynamicPipeline::predict_output_shapes(
params.numOfInputs = static_cast<uint32_t>(inputMemRefHandles.size());
params.pOutputs = outputMemRefHandles.data();
params.numOfOutputs = static_cast<uint32_t>(outputMemRefHandles.size());
- if (use_npu_vm_runtime_v2_api(_apiVersion)) {
- const auto commandQueueDesc = _graph->get_command_queue_desc();
- if (commandQueueDesc.sharedCommonQueue() && commandQueueDesc.key() != _command_queue->desc().key()) {
- _command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, commandQueueDesc);
- }
- }
params.executionContext =
use_npu_vm_runtime_v2_api(_apiVersion) ? _executionContext.handle() : _executionContext.ensure(vmRuntime);
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime.hpp
index 454165172dc..1ae81b8d68a 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/vm/npu_vm_runtime.hpp
@@ -318,6 +318,9 @@ typedef struct _npu_vm_runtime_create_execution_context_params_t {
/// @brief Initial Level Zero command queue. Used by interpreter to create a fence for host synchronization.
/// Later npuVMRuntimeExecute2 calls may provide a different commandQueue.
+ /// Lifetime: this queue must remain valid until a subsequent npuVMRuntimeExecute2 with a different
+ /// commandQueue has succeeded. The interpreter keeps a fence bound to this queue and destroys it only
+ /// during that migration, so freeing the queue earlier causes a use-after-free inside the runtime.
ze_command_queue_handle_t commandQueue;
/// @brief Graph DDI table extension pointer.
@@ -345,6 +348,11 @@ NPU_VM_RUNTIME_APIEXPORT npu_vm_runtime_result_t NPU_VM_RUNTIME_APICALL npuVMRun
/// If commandQueue differs from the one currently stored in executionContext,
/// runtime updates queue-dependent internal objects as needed.
/// Plugin never creates or manages command lists directly in this path.
+/// Queue lifetime: every commandQueue passed here (and to npuVMRuntimeCreateExecutionContext2) must stay
+/// valid until a later npuVMRuntimeExecute2 with a different commandQueue succeeds; a failed call may
+/// return before the migration. On a queue change the
+/// interpreter destroys the fence bound to the previously stored queue and rebuilds it on the new one;
+/// if the caller already freed the old queue, that destroy is a use-after-free the runtime cannot detect.
typedef struct _npu_vm_runtime_execute_params2_t {
/// @brief Command queue for submitting command lists or configuring internal command lists.
ze_command_queue_handle_t commandQueue;
diff --git a/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/espcn_x2_model.hpp b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/espcn_x2_model.hpp
new file mode 100644
index 00000000000..854547d37b0
--- /dev/null
+++ b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/espcn_x2_model.hpp
@@ -0,0 +1,176 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "openvino/openvino.hpp"
+#include "openvino/opsets/opset6.hpp"
+
+namespace ov::test::behavior {
+
+// Deterministic xorshift32 PRNG so generated weights are reproducible from a fixed seed.
+inline uint32_t espcnXorshift32(uint32_t& state) {
+ state ^= state << 13;
+ state ^= state >> 17;
+ state ^= state << 5;
+ return state;
+}
+
+// Signed, per-element varied weights in [-1, 1] * 1/sqrt(fan_in). Centering around 0 and Xavier-scaling by
+// fan-in keeps the conv cascade + final Tanh out of saturation, so outputs vary with the input instead of
+// collapsing to a constant 1.0 - which is what lets reference comparisons catch stale or cross-request results.
+inline std::vector<float> espcnMakeConvWeights(size_t count, size_t fanIn, uint32_t seed) {
+ const float scale = 1.0f / std::sqrt(static_cast<float>(fanIn));
+ std::vector<float> weights(count);
+ uint32_t state = seed ? seed : 1u;
+ for (size_t i = 0; i < count; ++i) {
+ const float unit = static_cast<float>(espcnXorshift32(state) % 20001u) / 10000.0f - 1.0f; // [-1, 1]
+ weights[i] = unit * scale;
+ }
+ return weights;
+}
+
+inline std::shared_ptr<ov::Model> createESPCNX2Model(ov::Dimension batchDimension = ov::Dimension(1, 2),
+ ov::Dimension heightDimension = ov::Dimension(32, 64),
+ ov::Dimension widthDimension = ov::Dimension(32, 64),
+ bool nhwcLayout = true) {
+ const ov::PartialShape inputShape = nhwcLayout
+ ? ov::PartialShape{batchDimension, heightDimension, widthDimension, 1}
+ : ov::PartialShape{batchDimension, 1, heightDimension, widthDimension};
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, inputShape);
+ input->set_friendly_name("IteratorGetNext:0");
+ input->get_output_tensor(0).set_names({"IteratorGetNext:0"});
+
+ ov::Output<ov::Node> nchwInput = input;
+ if (nhwcLayout) {
+ input->set_layout("NHWC");
+ auto transposeOrder = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {0, 3, 1, 2});
+ nchwInput = std::make_shared<ov::op::v1::Transpose>(input, transposeOrder);
+ } else {
+ input->set_layout("NCHW");
+ }
+
+ // Tests fill inputs up to a few hundred; normalize into Tanh's responsive range so the output is not a
+ // constant saturated 1.0 but varies with the input (needed to detect stale/cross-request results).
+ auto inputScale = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 1, 1, 1}, {1.0f / 128.0f});
+ ov::Output<ov::Node> scaledInput = std::make_shared<ov::op::v1::Multiply>(nchwInput, inputScale);
+
+ const auto makeConvAdd = [](const ov::Output<ov::Node>& data,
+ size_t inputChannels,
+ size_t outputChannels,
+ size_t kernelSize,
+ uint32_t weightSeed,
+ float biasValue) -> ov::Output<ov::Node> {
+ const size_t count = outputChannels * inputChannels * kernelSize * kernelSize;
+ const size_t fanIn = inputChannels * kernelSize * kernelSize;
+ auto weights =
+ ov::op::v0::Constant::create(ov::element::f32,
+ ov::Shape{outputChannels, inputChannels, kernelSize, kernelSize},
+ espcnMakeConvWeights(count, fanIn, weightSeed));
+ auto convolution = std::make_shared<ov::op::v1::Convolution>(data,
+ weights,
+ ov::Strides{1, 1},
+ ov::CoordinateDiff{0, 0},
+ ov::CoordinateDiff{0, 0},
+ ov::Strides{1, 1},
+ ov::op::PadType::SAME_UPPER);
+ auto bias = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, outputChannels, 1, 1}, {biasValue});
+ return std::make_shared<ov::op::v1::Add>(convolution, bias);
+ };
+
+ // Distinct seeds per conv give independent, reproducible weight patterns.
+ auto firstConv = makeConvAdd(scaledInput, 1, 64, 5, 0x9E3779B1u, 0.0f);
+ auto firstRelu = std::make_shared<ov::op::v0::Relu>(firstConv);
+ auto secondConv = makeConvAdd(firstRelu, 64, 32, 3, 0x85EBCA77u, 0.0f);
+ auto secondRelu = std::make_shared<ov::op::v0::Relu>(secondConv);
+ auto thirdConv = makeConvAdd(secondRelu, 32, 4, 3, 0xC2B2AE3Du, 0.0f);
+ auto depthToSpace =
+ std::make_shared<ov::op::v0::DepthToSpace>(thirdConv,
+ ov::op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST,
+ 2);
+ auto output = std::make_shared<ov::op::v0::Tanh>(depthToSpace);
+ output->set_friendly_name("NCHW_output");
+ output->get_output_tensor(0).set_names({"NCHW_output:0"});
+
+ auto result = std::make_shared<ov::op::v0::Result>(output);
+ result->set_layout("NCHW");
+
+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input}, "ESPCN_x2");
+}
+
+struct DynamicModelConfig {
+ ov::Dimension batch;
+ ov::Dimension height;
+ ov::Dimension width;
+ bool nhwcLayout;
+};
+
+inline const std::map<std::string, DynamicModelConfig>& espcnModelConfigs() {
+ static const std::map<std::string, DynamicModelConfig> configs = {
+ {"ESPCN_x2_DynHW_H1080xW960", {ov::Dimension(1), ov::Dimension(10, 1080), ov::Dimension(10, 960), true}},
+ {"ESPCN_x2_DynNHW_H1080xW960", {ov::Dimension(1, 10), ov::Dimension(1, 1080), ov::Dimension(10, 960), true}},
+ {"ESPCN_x2_DynNHW_H1080xW960_NCHW", {ov::Dimension(1, 10), ov::Dimension(10, 1080), ov::Dimension(10, 960), false}},
+ {"ESPCN_x2_DynN_H1080xW960_NCHW", {ov::Dimension(1, 10), ov::Dimension(1080), ov::Dimension(960), false}},
+ };
+ return configs;
+}
+
+inline const DynamicModelConfig& getModelConfig(const std::string& modelName) {
+ const auto& configs = espcnModelConfigs();
+ const auto it = configs.find(modelName);
+ OPENVINO_ASSERT(it != configs.end(), "Unknown ESPCN_x2 model name: ", modelName);
+ return it->second;
+}
+
+inline std::shared_ptr<ov::Model> createESPCNX2ModelByName(const std::string& modelName) {
+ const auto& config = getModelConfig(modelName);
+ return createESPCNX2Model(config.batch, config.height, config.width, config.nhwcLayout);
+}
+
+inline bool hasDynamicBatch(const std::string& modelName) {
+ return getModelConfig(modelName).batch.is_dynamic();
+}
+
+inline bool hasOnlyDynamicBatch(const std::string& modelName) {
+ const auto& config = getModelConfig(modelName);
+ return config.batch.is_dynamic() && !config.height.is_dynamic() && !config.width.is_dynamic();
+}
+
+inline ov::Shape makeInputShape(const std::shared_ptr<ov::Model>& model, size_t batch, bool useLargeShape) {
+ const ov::PartialShape& partialShape = model->input().get_partial_shape();
+
+ ov::Shape shape;
+ shape.reserve(partialShape.size());
+ for (size_t index = 0; index < partialShape.size(); ++index) {
+ const ov::Dimension& dimension = partialShape[index];
+ if (index == 0) {
+ shape.push_back(batch);
+ } else if (dimension.is_static()) {
+ shape.push_back(static_cast<size_t>(dimension.get_length()));
+ } else {
+ const auto interval = dimension.get_interval();
+ const int64_t value =
+ useLargeShape ? interval.get_max_val() : std::max(interval.get_min_val(), interval.get_max_val() / 2);
+ shape.push_back(static_cast<size_t>(value));
+ }
+ }
+ return shape;
+}
+
+inline ov::Shape makeOutputShape(const std::string& modelName, const ov::Shape& inputShape) {
+ const auto& config = getModelConfig(modelName);
+ const size_t heightIndex = config.nhwcLayout ? 1 : 2;
+ const size_t widthIndex = config.nhwcLayout ? 2 : 3;
+ return {inputShape[0], 1, inputShape[heightIndex] * 2, inputShape[widthIndex] * 2};
+}
+
+} // namespace ov::test::behavior
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.cpp
index dc059f9d460..722f09fab92 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
@@ -6,7 +6,6 @@
#include <common_test_utils/ov_tensor_utils.hpp>
#include <cstring>
#include <functional>
-#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
@@ -15,12 +14,11 @@
#include "common/npu_test_env_cfg.hpp"
#include "common/utils.hpp"
+#include "common_test_utils/ov_plugin_cache.hpp"
+#include "espcn_x2_model.hpp"
#include "intel_npu/config/options.hpp"
#include "intel_npu/npu_private_properties.hpp"
#include "openvino/openvino.hpp"
-#include "openvino/opsets/opset6.hpp"
-#include "openvino/pass/manager.hpp"
-#include "openvino/pass/serialize.hpp"
#include "openvino/runtime/intel_npu/properties.hpp"
#include "openvino/runtime/make_tensor.hpp"
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
@@ -29,142 +27,6 @@ namespace ov {
namespace test {
namespace behavior {
-inline std::shared_ptr<ov::Model> createMaxPoolModel(bool dynamicBatch = false, bool nhwcLayout = true) {
- std::shared_ptr<ov::op::v0::Parameter> input;
- if (dynamicBatch) {
- input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16,
- ov::PartialShape{ov::Dimension(1, 10), 16, 1280, 1280});
- } else {
- input = std::make_shared<ov::op::v0::Parameter>(
- ov::element::f16,
- ov::PartialShape{1, 16, ov::Dimension(10, 1280), ov::Dimension(10, 1280)});
- }
-
- std::string inputName = "input1";
- input->set_friendly_name(inputName);
- input->get_output_tensor(0).set_names({inputName});
- if (!nhwcLayout)
- input->set_layout("NCHW");
- 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);
- std::string outputName = "output";
- if (!nhwcLayout)
- result->set_layout("NCHW");
- result->set_friendly_name(outputName);
- result->get_output_tensor(0).set_names({outputName});
-
- auto model = std::make_shared<Model>(ResultVector{result}, ParameterVector{input}, "MaxPool");
-
- // making input and output to be NHWC
- if (nhwcLayout) {
- auto preProc = ov::preprocess::PrePostProcessor(model);
- preProc.input(0).tensor().set_layout("NHWC");
- preProc.input(0).model().set_layout("NCHW");
- preProc.output(0).tensor().set_layout("NHWC");
- preProc.output(0).model().set_layout("NCHW");
-
- model = preProc.build();
- }
-
- return model;
-}
-
-inline std::shared_ptr<ov::Model> createCustomNetModel(bool dynamicBatch = false) {
- const ov::Dimension batchDimension = dynamicBatch ? ov::Dimension(1, 10) : ov::Dimension(1);
- const ov::PartialShape inputShape{batchDimension, 16, ov::Dimension(1, 1280), ov::Dimension(10, 1920)};
- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, inputShape);
- input->set_friendly_name("Parameter_59");
-
- auto make_conv_add = [](const ov::Output<ov::Node>& data,
- const std::string& convName,
- const std::string& addName,
- float weightValue,
- float biasValue) -> ov::Output<ov::Node> {
- const std::vector<float> weightValues(16 * 16, weightValue);
- const std::vector<float> biasValues(16, biasValue);
-
- auto weights = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{16, 16, 1, 1}, weightValues);
- auto conv = std::make_shared<ov::op::v1::Convolution>(data,
- weights,
- ov::Strides{1, 1},
- ov::CoordinateDiff{0, 0},
- ov::CoordinateDiff{0, 0},
- ov::Strides{1, 1},
- ov::op::PadType::EXPLICIT);
- conv->set_friendly_name(convName);
-
- auto bias = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 16, 1, 1}, biasValues);
- auto add = std::make_shared<ov::op::v1::Add>(conv, bias);
- add->set_friendly_name(addName);
- return add;
- };
-
- auto x = make_conv_add(input, "Convolution_61", "Add_63", 0.01f, 0.001f);
- x = make_conv_add(x, "Convolution_65", "Add_67", 0.011f, 0.001f);
-
- auto relu68 = std::make_shared<ov::op::v0::Relu>(x);
- relu68->set_friendly_name("Relu_68");
- x = relu68;
-
- x = make_conv_add(x, "Convolution_70", "Add_72", 0.012f, 0.001f);
- auto relu73 = std::make_shared<ov::op::v0::Relu>(x);
- relu73->set_friendly_name("Relu_73");
- x = relu73;
-
- x = make_conv_add(x, "Convolution_75", "Add_77", 0.013f, 0.001f);
- auto relu78 = std::make_shared<ov::op::v0::Relu>(x);
- relu78->set_friendly_name("Relu_78");
- x = relu78;
-
- x = make_conv_add(x, "Convolution_82", "Add_84", 0.014f, 0.001f);
- auto relu85 = std::make_shared<ov::op::v0::Relu>(x);
- relu85->set_friendly_name("Relu_85");
- x = relu85;
-
- x = make_conv_add(x, "Convolution_87", "Add_89", 0.015f, 0.001f);
- auto relu90 = std::make_shared<ov::op::v0::Relu>(x);
- relu90->set_friendly_name("Relu_90");
- x = relu90;
-
- x = make_conv_add(x, "Convolution_92", "Add_94", 0.016f, 0.001f);
- auto relu95 = std::make_shared<ov::op::v0::Relu>(x);
- relu95->set_friendly_name("Relu_95");
- x = relu95;
-
- auto multiplyScale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 16, 1, 1}, {0.5f});
- auto multiply97 = std::make_shared<ov::op::v1::Multiply>(x, multiplyScale);
- multiply97->set_friendly_name("Multiply_97");
-
- auto add98 = std::make_shared<ov::op::v1::Add>(multiply97, multiply97);
- add98->set_friendly_name("Add_98");
-
- x = make_conv_add(add98, "Convolution_100", "Add_102", 0.017f, 0.001f);
-
- auto result = std::make_shared<ov::op::v0::Result>(x);
- result->set_friendly_name("Result_104");
-
- auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input}, "CustomNet");
-
- // making input and output to be NHWC
- auto preProc = ov::preprocess::PrePostProcessor(model);
- preProc.input(0).tensor().set_layout("NHWC");
- preProc.input(0).model().set_layout("NCHW");
- preProc.output(0).tensor().set_layout("NHWC");
- preProc.output(0).model().set_layout("NCHW");
-
- model = preProc.build();
-
- return model;
-}
-
using InferWithHostCompileParams = std::tuple<std::string, // Device name
ov::AnyMap, // Config
std::string // Model name
@@ -228,13 +90,16 @@ public:
return result.str();
}
- void SetUp() {
+ void SetUp() override {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED();
std::tie(target_device, configuration, selectedModelName) = this->GetParam();
configuration[ov::intel_npu::compile_log_level.name()] = ov::log::Level::ERR;
+ #if !defined(OPENVINO_STATIC_LIBRARY) && !defined(USE_STATIC_IE)
+ ov::test::utils::register_template_plugin(core);
+ #endif // !OPENVINO_STATIC_LIBRARY && !USE_STATIC_IE
std::vector<std::string> deviceNames =
core.get_property("NPU", ov::available_devices.name()).as<std::vector<std::string>>();
for (auto name : deviceNames) {
@@ -248,8 +113,9 @@ public:
APIBaseTest::SetUp();
}
- void TearDown() {
+ void TearDown() override {
core.set_property("NPU", ov::log::level(originalLogLevel));
+ APIBaseTest::TearDown();
}
static void compareInferenceResult(const std::shared_ptr<ov::Model>& model,
@@ -304,11 +170,19 @@ std::string InferWithHostCompileTests::ScopedLogCapture::str() const {
void InferWithHostCompileTests::compareInferenceResult(const std::shared_ptr<ov::Model>& model,
ov::InferRequest& reqDynamic,
ov::InferRequest& reqReference) {
- const auto inputTensor = reqDynamic.get_input_tensor(0);
const auto npuOutputTensor = reqDynamic.get_tensor(model->output());
const auto referenceOutputTensor = reqReference.get_tensor(model->output());
- ov::test::utils::compare(referenceOutputTensor, npuOutputTensor, npuOutputTensor.get_element_type());
+ // NPU HostCompile runs in reduced (f16-class) precision while the TEMPLATE reference is f32, so a few
+ // tenths of a percent of difference is expected. Use a tolerance that accepts that gap but stays far
+ // tighter than any stale/garbage or cross-request difference.
+ constexpr double absThreshold = 0.02;
+ constexpr double relThreshold = 0.02;
+ ov::test::utils::compare(referenceOutputTensor,
+ npuOutputTensor,
+ npuOutputTensor.get_element_type(),
+ absThreshold,
+ relThreshold);
}
void InferWithHostCompileTests::inferAndCompare(const std::shared_ptr<ov::Model>& model,
@@ -344,23 +218,7 @@ bool InferWithHostCompileTests::logContains(const ScopedLogCapture& logCapture,
}
std::shared_ptr<ov::Model> InferWithHostCompileTests::createModelByName(const std::string& modelName) {
- if (modelName == "CustomNet") {
- return createCustomNetModel();
- }
- if (modelName == "CustomNet_DynBatch") {
- return createCustomNetModel(true);
- }
- if (modelName == "MaxPool") {
- return createMaxPoolModel();
- }
- if (modelName == "MaxPool_NCHW") {
- return createMaxPoolModel(false, false);
- }
- if (modelName == "MaxPool_NCHW_DynBatch") {
- return createMaxPoolModel(true, false);
- }
-
- OPENVINO_THROW("Unknown model name for InferWithHostCompileTests: ", modelName);
+ return createESPCNX2ModelByName(modelName);
}
InferWithHostCompileTests::RuntimeCompareSetupResult InferWithHostCompileTests::prepareRuntimeCompareContext(
@@ -380,7 +238,7 @@ InferWithHostCompileTests::RuntimeCompareSetupResult InferWithHostCompileTests::
result.context.referenceCompiledModel = core.compile_model(model, ov::test::utils::DEVICE_TEMPLATE);
} catch (const ov::Exception& e) {
result.status = RuntimeCompareStatus::skip;
- result.message = std::string("CPU plugin is not available for reference comparison: ") + e.what();
+ result.message = std::string("TEMPLATE plugin is not available for reference comparison: ") + e.what();
return result;
}
@@ -446,13 +304,8 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithDecreasedSize) {
}
auto& testContext = setupResult.context;
- // Start with the largest shape in the dynamic range.
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ // Start with the largest shape allowed by the model's declared bounds.
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
setInputInferAndCompare(model,
@@ -481,12 +334,7 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithDecreasedSize) {
logCapture.clear();
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 720, 720};
- } else {
- shape2 = {1, 720, 720, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, false);
ov::Tensor inTensor3 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 100, 0);
setInputInferAndCompare(model,
@@ -524,13 +372,8 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithIncreasedSize) {
auto& testContext = setupResult.context;
- // Start with a smaller valid dynamic shape.
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 1280, 720};
- } else {
- shape = {1, 1280, 720, 16};
- }
+ // Start with the smallest shape allowed by the model's declared bounds.
+ const ov::Shape shape = makeInputShape(model, 1, false);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
setInputInferAndCompare(model,
@@ -558,12 +401,7 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithIncreasedSize) {
"CompileAndInferWithIncreasedSize_third");
logCapture.clear();
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 1280, 1280};
- } else {
- shape2 = {1, 1280, 1280, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, true);
ov::Tensor inTensor3 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 100, 0);
setInputInferAndCompare(model,
@@ -599,13 +437,8 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {
}
auto& testContext = setupResult.context;
- // Start from a regular host tensor.
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ // Start from a regular host tensor sized to the model's upper bounds.
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
setInputInferAndCompare(model,
testContext.reqDynamic,
@@ -626,20 +459,26 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {
<< "Expected log to contain 'Reset command list to run with runtime', but got: " << logCapture.str();
logCapture.clear();
- auto outputTensorFromReq = testContext.reqDynamic.get_tensor(model->output());
+ auto zeroContext = core.get_default_context(target_device);
+ auto inputTensorForThirdInfer = zeroContext.create_host_tensor(model->input().get_element_type(), shape);
+ auto inputSourceForThirdInfer =
+ ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 50);
+ ASSERT_EQ(inputSourceForThirdInfer.get_byte_size(), inputTensorForThirdInfer.get_byte_size());
+ std::memcpy(inputTensorForThirdInfer.data(),
+ inputSourceForThirdInfer.data(),
+ inputSourceForThirdInfer.get_byte_size());
setInputInferAndCompare(model,
reqDynamic1,
reqReference1,
- outputTensorFromReq,
+ inputTensorForThirdInfer,
"CompileAndInferWithZeroTensor_third");
- // Feeding an imported output tensor, ptr change detected and rebuild runtime
+ // 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 zeroContext = core.get_default_context(target_device);
auto inputHostTensorForForthInfer = zeroContext.create_host_tensor(model->input().get_element_type(), shape);
auto hostTensorSourceForForthInfer =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
@@ -661,9 +500,10 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {
logCapture.clear();
auto outputShape = reqDynamic1.get_tensor(model->output()).get_shape();
- auto zeroOutputTensorForFifthInfer = zeroContext.create_host_tensor(model->input().get_element_type(), outputShape);
+ auto zeroOutputTensorForFifthInfer =
+ zeroContext.create_host_tensor(model->output().get_element_type(), outputShape);
auto hostTensorSourceForOutputForFifthInfer =
- ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), outputShape, 100, 0);
+ ov::test::utils::create_and_fill_tensor(model->output().get_element_type(), outputShape, 100, 0);
ASSERT_EQ(hostTensorSourceForOutputForFifthInfer.get_byte_size(), zeroOutputTensorForFifthInfer.get_byte_size())
<< "Source and destination tensors must have identical byte sizes for copy";
std::memcpy(zeroOutputTensorForFifthInfer.data(),
@@ -686,9 +526,9 @@ TEST_P(InferWithHostCompileTests, CompileAndInferWithZeroTensor) {
auto outputShapeForSixthInfer = reqDynamic1.get_tensor(model->output()).get_shape();
auto zeroOutputTensorForSixthInfer =
- zeroContext.create_host_tensor(model->input().get_element_type(), outputShapeForSixthInfer);
+ zeroContext.create_host_tensor(model->output().get_element_type(), outputShapeForSixthInfer);
auto hostTensorSourceForOutputForSixthInfer =
- ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), outputShapeForSixthInfer, 100, 0);
+ ov::test::utils::create_and_fill_tensor(model->output().get_element_type(), outputShapeForSixthInfer, 100, 0);
ASSERT_EQ(hostTensorSourceForOutputForSixthInfer.get_byte_size(), zeroOutputTensorForSixthInfer.get_byte_size())
<< "Source and destination tensors must have identical byte sizes for copy";
std::memcpy(zeroOutputTensorForSixthInfer.data(),
@@ -712,9 +552,7 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {
if (!isTargetDevice) {
GTEST_SKIP() << "Skip test for current device";
}
- // MaxPool dynamic models contain operators that are not yet supported by the dynamic pipeline.
- // CustomNet_DynBatch is used to verify aggregation of N=1 tensors into one N=2 VM execution.
- if (selectedModelName != "CustomNet_DynBatch") {
+ if (!hasDynamicBatch(selectedModelName)) {
GTEST_SKIP() << "Only applies to the dynamic-batch model";
}
@@ -735,7 +573,7 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {
ov::InferRequest reqReference1 = testContext.referenceCompiledModel.create_infer_request();
// A single N=2 tensor must execute as one dynamic VM inference.
- const ov::Shape batchShape = {2, 720, 1280, 16};
+ const ov::Shape batchShape = makeInputShape(model, 2, false);
auto fullBatchTensor =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), batchShape, 100, 0);
setInputInferAndCompare(model,
@@ -743,10 +581,9 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {
reqReference1,
fullBatchTensor,
"DynamicBatchUsesOneVMExecution_full_batch");
- ASSERT_EQ(reqDynamic1.get_tensor(model->output()).get_shape(), batchShape);
+ ASSERT_EQ(reqDynamic1.get_tensor(model->output()).get_shape(), makeOutputShape(selectedModelName, batchShape));
- const auto countVMExecutions = [](const std::string& log) {
- constexpr std::string_view marker = "Start to execute graph with runtime engine";
+ const auto countMarker = [](const std::string& log, std::string_view marker) {
size_t count = 0;
size_t position = 0;
while ((position = log.find(marker, position)) != std::string::npos) {
@@ -755,11 +592,15 @@ 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");
+ };
ASSERT_EQ(countVMExecutions(logCapture.str()), 1u) << logCapture.str();
logCapture.clear();
// Two N=1 tensors must be aggregated into one N=2 inference rather than executed separately.
- const ov::Shape singleBatchShape = {1, 720, 1280, 16};
+ const ov::Shape singleBatchShape = makeInputShape(model, 1, false);
std::vector<ov::Tensor> tensorBatch;
tensorBatch.push_back(
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), singleBatchShape, 100, 0));
@@ -769,10 +610,8 @@ TEST_P(InferWithHostCompileTests, DynamicBatchUsesOneVMExecution) {
OV_ASSERT_NO_THROW(reqReference1.set_tensors(testContext.referenceCompiledModel.input(), tensorBatch));
OV_ASSERT_NO_THROW(reqDynamic1.infer());
OV_ASSERT_NO_THROW(reqReference1.infer());
- ASSERT_EQ(reqDynamic1.get_tensor(model->output()).get_shape(), batchShape);
- ov::test::utils::compare(reqReference1.get_tensor(model->output()),
- reqDynamic1.get_tensor(model->output()),
- model->output().get_element_type());
+ ASSERT_EQ(reqDynamic1.get_tensor(model->output()).get_shape(), makeOutputShape(selectedModelName, batchShape));
+ compareInferenceResult(model, reqDynamic1, reqReference1);
ASSERT_EQ(countVMExecutions(logCapture.str()), 1u) << logCapture.str();
}
@@ -809,12 +648,7 @@ TEST_P(InferWithHostCompileTests, SharedCommonQueue_BasicInferAndReuse) {
auto& ctx = setupResult.context;
const std::string tag = sharedQueue ? "shared" : "nonshared";
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor t0 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, t0, tag + "_first"));
@@ -823,12 +657,7 @@ TEST_P(InferWithHostCompileTests, SharedCommonQueue_BasicInferAndReuse) {
ov::Tensor t1 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 200, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, t1, tag + "_new_ptr"));
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 360, 640};
- } else {
- shape2 = {1, 360, 640, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, false);
ov::Tensor t2 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 50, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, t2, tag + "_shape_change"));
}
@@ -862,12 +691,7 @@ TEST_P(InferWithHostCompileTests, SharedCommonQueue_ZeroTensorInputOutputSet) {
const std::string tag = sharedQueue ? "shared" : "nonshared";
auto zeroContext = core.get_default_context(target_device);
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor hostInput =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(
@@ -886,18 +710,14 @@ TEST_P(InferWithHostCompileTests, SharedCommonQueue_ZeroTensorInputOutputSet) {
OV_ASSERT_NO_THROW(ctx.reqDynamic.set_tensor(model->output(), zeroOutput));
OV_ASSERT_NO_THROW(inferAndCompare(model, ctx.reqDynamic, ctx.reqReference, tag + "_zero_output"));
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 360, 640};
- } else {
- shape2 = {1, 360, 640, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, false);
auto zeroInput2 = zeroContext.create_host_tensor(model->input().get_element_type(), shape2);
auto zeroInputSource2 =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 100, 2);
ASSERT_EQ(zeroInputSource2.get_byte_size(), zeroInput2.get_byte_size());
std::memcpy(zeroInput2.data(), zeroInputSource2.data(), zeroInputSource2.get_byte_size());
- auto zeroOutput2 = zeroContext.create_host_tensor(model->output().get_element_type(), shape2);
+ auto zeroOutput2 = zeroContext.create_host_tensor(model->output().get_element_type(),
+ makeOutputShape(selectedModelName, shape2));
OV_ASSERT_NO_THROW(ctx.reqDynamic.set_tensor(model->output(), zeroOutput2));
OV_ASSERT_NO_THROW(setInputInferAndCompare(model,
ctx.reqDynamic,
@@ -934,12 +754,7 @@ TEST_P(InferWithHostCompileTests, CompileTimeConfig_ModelPriority) {
GTEST_SKIP() << setupResult.message;
}
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model,
@@ -982,12 +797,7 @@ TEST_P(InferWithHostCompileTests, CompileTimeConfig_WorkloadType) {
auto reqDynamic = compiledModel.create_infer_request();
auto reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, reqDynamic, reqRef, inTensor, "CompileTimeWorkload"));
@@ -1026,12 +836,7 @@ TEST_P(InferWithHostCompileTests, CompileTimeConfig_Turbo) {
auto reqDynamic = compiledModel.create_infer_request();
auto reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(reqDynamic.set_input_tensor(0, inTensor));
@@ -1092,12 +897,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_CombinedPriorityAndWorkload) {
auto reqDynamic = compiledModel.create_infer_request();
auto reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, reqDynamic, reqRef, inTensor, "CombinedConfig_baseline"));
@@ -1106,12 +906,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_CombinedPriorityAndWorkload) {
OV_ASSERT_NO_THROW(
inferAndCompare(model, reqDynamic, reqRef, "CombinedConfig_priority_high_workload_efficient"));
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 360, 640};
- } else {
- shape2 = {1, 360, 640, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, false);
ov::Tensor inTensor2 =
ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 100, 1);
OV_ASSERT_NO_THROW(
@@ -1166,12 +961,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_ModelPriority_SingleCompiledModel)
}
auto& ctx = setupResult.context;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
// Baseline at LOW: command_queue_version_changed=false on first push().
@@ -1200,6 +990,72 @@ TEST_P(InferWithHostCompileTests, SetProperty_ModelPriority_SingleCompiledModel)
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, reqNew, reqRefNew, inTensor, "Priority_new_request_after_set"));
}
+// ── V2: queue retained across a failed inference between two queue switches ───
+//
+// Regression for the queue-lifetime hazard across a failed inference and repeated priority changes:
+// 1) set_property(HIGH) then an undersized user output tensor makes
+// check_tensor_and_predicted_shapes() throw before push()/Execute2 runs.
+// 2) set_property(MEDIUM) changes the queue descriptor again before retrying.
+// The queue the runtime's fence is bound to must survive until the retry's Execute2 migrates off it;
+// otherwise the runtime destroys a fence on an already-freed queue (use-after-free).
+TEST_P(InferWithHostCompileTests, SetProperty_Priority_RetryAfterUndersizedOutput) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED()
+ if (!isTargetDevice) {
+ GTEST_SKIP() << "Skip test for current device";
+ }
+
+ ov::AnyMap cfg = configuration;
+ cfg[ov::hint::model_priority.name()] = ov::hint::Priority::LOW;
+ cfg[ov::intel_npu::shared_common_queue.name()] = true;
+
+ auto model = createModelByName(selectedModelName);
+ RuntimeCompareSetupResult setupResult;
+ {
+ auto savedCfg = configuration;
+ configuration = cfg;
+ setupResult = prepareRuntimeCompareContext(model);
+ configuration = savedCfg;
+ }
+ if (setupResult.status == RuntimeCompareStatus::fail) {
+ FAIL() << setupResult.message;
+ }
+ if (setupResult.status == RuntimeCompareStatus::skip) {
+ GTEST_SKIP() << setupResult.message;
+ }
+ auto& ctx = setupResult.context;
+
+ const ov::Shape shape = makeInputShape(model, 1, true);
+ ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
+
+ // Baseline at LOW establishes the initial VM-bound queue.
+ OV_ASSERT_NO_THROW(
+ setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, inTensor, "RetryUndersized_low_baseline"));
+
+ // First switch LOW->HIGH, then feed an undersized user output tensor (shaped for the model's small bound)
+ // together with the large input, so the output size check after shape prediction throws before Execute2 runs.
+ OV_ASSERT_NO_THROW(ctx.compiledModel.set_property({{ov::hint::model_priority.name(), ov::hint::Priority::HIGH}}));
+ const ov::Shape smallInputShape = makeInputShape(model, 1, false);
+ ov::Tensor undersizedOutput =
+ ov::test::utils::create_and_fill_tensor(model->output().get_element_type(),
+ makeOutputShape(selectedModelName, smallInputShape),
+ 100,
+ 0);
+ OV_ASSERT_NO_THROW(ctx.reqDynamic.set_input_tensor(0, inTensor));
+ OV_ASSERT_NO_THROW(ctx.reqDynamic.set_tensor(model->output(), undersizedOutput));
+ ASSERT_ANY_THROW(ctx.reqDynamic.infer());
+
+ // Second switch HIGH->MEDIUM, then retry with a correctly sized output tensor. The retry's Execute2
+ // migrates the fence off the original queue, which must still be alive after both switches.
+ OV_ASSERT_NO_THROW(ctx.compiledModel.set_property({{ov::hint::model_priority.name(), ov::hint::Priority::MEDIUM}}));
+ ov::Tensor validOutput = ov::test::utils::create_and_fill_tensor(model->output().get_element_type(),
+ makeOutputShape(selectedModelName, shape),
+ 100,
+ 0);
+ OV_ASSERT_NO_THROW(ctx.reqDynamic.set_tensor(model->output(), validOutput));
+ OV_ASSERT_NO_THROW(
+ setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, inTensor, "RetryUndersized_retry_medium"));
+}
+
// ── V2: compiledModel.set_property(workload_type) → workload change ───────────
//
// Call chain (shared=YES):
@@ -1247,12 +1103,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_WorkloadType_SingleCompiledModel)
ov::InferRequest reqDynamic = compiledModel.create_infer_request();
ov::InferRequest reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, reqDynamic, reqRef, inTensor, "Workload_default_baseline"));
@@ -1281,12 +1132,7 @@ TEST_P(InferWithHostCompileTests, CompileTimeConfig_Turbo_SharedCommonQueue) {
} catch (const ov::Exception&) {
GTEST_SKIP() << "TEMPLATE plugin unavailable";
}
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
for (bool turbo : {false, true}) {
@@ -1357,12 +1203,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_Priority_BetweenTwoRequests) {
ov::InferRequest reqB = compiledModel.create_infer_request();
ov::InferRequest reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
// Warmup both at LOW.
@@ -1406,12 +1247,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_ModelPriority_SingleCompiledModel_
}
auto& ctx = setupResult.context;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(
@@ -1470,12 +1306,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_WorkloadType_SingleCompiledModel_N
ov::InferRequest reqDynamic = compiledModel.create_infer_request();
ov::InferRequest reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(
@@ -1503,12 +1334,7 @@ TEST_P(InferWithHostCompileTests, CompileTimeConfig_Turbo_NonSharedCommonQueue)
} catch (const ov::Exception&) {
GTEST_SKIP() << "TEMPLATE plugin unavailable";
}
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
for (bool turbo : {false, true}) {
@@ -1565,12 +1391,7 @@ TEST_P(InferWithHostCompileTests, SetProperty_Priority_BetweenTwoRequests_NonSha
ov::InferRequest reqB = compiledModel.create_infer_request();
ov::InferRequest reqRef = refModel.create_infer_request();
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
OV_ASSERT_NO_THROW(setInputInferAndCompare(model, reqA, reqRef, inTensor, "TwoReq_nonshared_A_LOW"));
@@ -1621,12 +1442,7 @@ TEST_P(InferWithHostCompileTests, MemRefReuse_SamePtrSameShape) {
auto& ctx = setupResult.context;
const std::string tag = sharedQueue ? "shared" : "nonshared";
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor t0 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
// 1st inference: recording expected
@@ -1643,12 +1459,7 @@ TEST_P(InferWithHostCompileTests, MemRefReuse_SamePtrSameShape) {
OV_ASSERT_NO_THROW(inferAndCompare(model, ctx.reqDynamic, ctx.reqReference, tag + "_v2_new_ptr_reuse"));
// 5th inference: different shape → recording
- ov::Shape shape2;
- if (selectedModelName == "MaxPool_NCHW") {
- shape2 = {1, 16, 360, 640};
- } else {
- shape2 = {1, 360, 640, 16};
- }
+ const ov::Shape shape2 = makeInputShape(model, 1, false);
ov::Tensor t2 = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape2, 50, 0);
OV_ASSERT_NO_THROW(
setInputInferAndCompare(model, ctx.reqDynamic, ctx.reqReference, t2, tag + "_v2_shape_change"));
@@ -1689,12 +1500,7 @@ TEST_P(InferWithHostCompileTests, MemRefReuse_OutputPtrChange) {
auto& ctx = setupResult.context;
const std::string tag = sharedQueue ? "shared" : "nonshared";
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
+ const ov::Shape shape = makeInputShape(model, 1, true);
ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, 0);
// 1st inference: recording expected
@@ -1750,9 +1556,9 @@ TEST_P(InferWithDefaultHostCompileTests, CompileDynamicModelWithNoHostCompileMod
FAIL() << "Exported model stream is empty";
}
- if (selectedModelName == "MaxPool_NCHW_DynBatch") {
+ if (hasOnlyDynamicBatch(selectedModelName)) {
ASSERT_TRUE(isElfBlob(modelStream.str())) << "Expected exported model to be an ELF blob";
- } else if (selectedModelName == "MaxPool_NCHW") {
+ } else {
ASSERT_TRUE(isByteCodeBlob(modelStream.str())) << "Expected exported model to be a bytecode";
}
@@ -1775,7 +1581,7 @@ TEST_P(InferWithDefaultHostCompileTests, CompileDynamicModelWithNoHostCompileMod
} // namespace test
} // namespace ov
-const std::vector<std::string> devices = {"NPU.4000", "NPU.5010"};
+const std::vector<std::string> devices = {"NPU.4000", "NPU.5010", "NPU.6010"};
const std::vector<ov::AnyMap> configs = {
{
@@ -1800,9 +1606,10 @@ const std::vector<ov::AnyMap> configs = {
},
};
-// Ensure the added test model's input and output shapes are identical and accept concrete NHWC shapes for reuse shape
-// in tests.
-const std::vector<std::string> modelNames = {/*"CustomNet", "CustomNet_DynBatch", "MaxPool", */ "MaxPool_NCHW"};
+const std::vector<std::string> modelNames = {
+ "ESPCN_x2_DynHW_H1080xW960",
+ "ESPCN_x2_DynNHW_H1080xW960",
+};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
InferWithHostCompileTests,
@@ -1823,7 +1630,7 @@ const std::vector<ov::AnyMap> defaultHostCompileconfigs = {
},
};
-const std::vector<std::string> defaultHCModelNames = {"MaxPool_NCHW", "MaxPool_NCHW_DynBatch"};
+const std::vector<std::string> defaultHCModelNames = {"ESPCN_x2_DynN_H1080xW960_NCHW", "ESPCN_x2_DynNHW_H1080xW960_NCHW"};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
InferWithDefaultHostCompileTests,
::testing::Combine(::testing::ValuesIn(devices),
diff --git a/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile_multithread.cpp b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile_multithread.cpp
index 461ee0c59a2..8b25ec8e3cb 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile_multithread.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/dynamic_host_pipeline/infer_with_host_compile_multithread.cpp
@@ -17,10 +17,11 @@
#include <tuple>
#include <vector>
+#include "common_test_utils/ov_plugin_cache.hpp"
#include "common/utils.hpp"
+#include "espcn_x2_model.hpp"
#include "intel_npu/npu_private_properties.hpp"
#include "openvino/openvino.hpp"
-#include "openvino/opsets/opset6.hpp"
#include "openvino/runtime/intel_npu/properties.hpp"
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
@@ -28,138 +29,6 @@ namespace ov {
namespace test {
namespace behavior {
-inline std::shared_ptr<ov::Model> createMaxPoolModelMT(bool dynamicBatch = false, bool nhwcLayout = true) {
- std::shared_ptr<ov::op::v0::Parameter> input;
- if (dynamicBatch) {
- input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16,
- ov::PartialShape{ov::Dimension(1, 10), 16, 1280, 1280});
- } else {
- input = std::make_shared<ov::op::v0::Parameter>(
- ov::element::f16,
- ov::PartialShape{1, 16, ov::Dimension(10, 1280), ov::Dimension(10, 1280)});
- }
-
- std::string inputName = "input1";
- input->set_friendly_name(inputName);
- input->get_output_tensor(0).set_names({inputName});
- if (!nhwcLayout)
- input->set_layout("NCHW");
- 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);
- std::string outputName = "output";
- if (!nhwcLayout)
- result->set_layout("NCHW");
- result->set_friendly_name(outputName);
- result->get_output_tensor(0).set_names({outputName});
-
- auto model = std::make_shared<Model>(ResultVector{result}, ParameterVector{input}, "MaxPool");
-
- if (nhwcLayout) {
- auto preProc = ov::preprocess::PrePostProcessor(model);
- preProc.input(0).tensor().set_layout("NHWC");
- preProc.input(0).model().set_layout("NCHW");
- preProc.output(0).tensor().set_layout("NHWC");
- preProc.output(0).model().set_layout("NCHW");
- model = preProc.build();
- }
-
- return model;
-}
-
-inline std::shared_ptr<ov::Model> createCustomNetModelMT() {
- auto input = std::make_shared<ov::op::v0::Parameter>(
- ov::element::f16,
- ov::PartialShape{1, 16, ov::Dimension(1, 1280), ov::Dimension(10, 1920)});
- input->set_friendly_name("Parameter_59");
-
- auto make_conv_add = [](const ov::Output<ov::Node>& data,
- const std::string& convName,
- const std::string& addName,
- float weightValue,
- float biasValue) -> ov::Output<ov::Node> {
- const std::vector<float> weightValues(16 * 16, weightValue);
- const std::vector<float> biasValues(16, biasValue);
-
- auto weights = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{16, 16, 1, 1}, weightValues);
- auto conv = std::make_shared<ov::op::v1::Convolution>(data,
- weights,
- ov::Strides{1, 1},
- ov::CoordinateDiff{0, 0},
- ov::CoordinateDiff{0, 0},
- ov::Strides{1, 1},
- ov::op::PadType::EXPLICIT);
- conv->set_friendly_name(convName);
-
- auto bias = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 16, 1, 1}, biasValues);
- auto add = std::make_shared<ov::op::v1::Add>(conv, bias);
- add->set_friendly_name(addName);
- return add;
- };
-
- auto x = make_conv_add(input, "Convolution_61", "Add_63", 0.01f, 0.001f);
- x = make_conv_add(x, "Convolution_65", "Add_67", 0.011f, 0.001f);
-
- auto relu68 = std::make_shared<ov::op::v0::Relu>(x);
- relu68->set_friendly_name("Relu_68");
- x = relu68;
-
- x = make_conv_add(x, "Convolution_70", "Add_72", 0.012f, 0.001f);
- auto relu73 = std::make_shared<ov::op::v0::Relu>(x);
- relu73->set_friendly_name("Relu_73");
- x = relu73;
-
- x = make_conv_add(x, "Convolution_75", "Add_77", 0.013f, 0.001f);
- auto relu78 = std::make_shared<ov::op::v0::Relu>(x);
- relu78->set_friendly_name("Relu_78");
- x = relu78;
-
- x = make_conv_add(x, "Convolution_82", "Add_84", 0.014f, 0.001f);
- auto relu85 = std::make_shared<ov::op::v0::Relu>(x);
- relu85->set_friendly_name("Relu_85");
- x = relu85;
-
- x = make_conv_add(x, "Convolution_87", "Add_89", 0.015f, 0.001f);
- auto relu90 = std::make_shared<ov::op::v0::Relu>(x);
- relu90->set_friendly_name("Relu_90");
- x = relu90;
-
- x = make_conv_add(x, "Convolution_92", "Add_94", 0.016f, 0.001f);
- auto relu95 = std::make_shared<ov::op::v0::Relu>(x);
- relu95->set_friendly_name("Relu_95");
- x = relu95;
-
- auto multiplyScale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 16, 1, 1}, {0.5f});
- auto multiply97 = std::make_shared<ov::op::v1::Multiply>(x, multiplyScale);
- multiply97->set_friendly_name("Multiply_97");
-
- auto add98 = std::make_shared<ov::op::v1::Add>(multiply97, multiply97);
- add98->set_friendly_name("Add_98");
-
- x = make_conv_add(add98, "Convolution_100", "Add_102", 0.017f, 0.001f);
-
- auto result = std::make_shared<ov::op::v0::Result>(x);
- result->set_friendly_name("Result_104");
-
- auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input}, "CustomNet");
-
- auto preProc = ov::preprocess::PrePostProcessor(model);
- preProc.input(0).tensor().set_layout("NHWC");
- preProc.input(0).model().set_layout("NCHW");
- preProc.output(0).tensor().set_layout("NHWC");
- preProc.output(0).model().set_layout("NCHW");
- model = preProc.build();
-
- return model;
-}
-
using InferWithHostCompileMTParams = std::tuple<std::string, ov::AnyMap, std::string>;
class InferWithHostCompileMultithreadTests : public testing::WithParamInterface<InferWithHostCompileMTParams>,
@@ -188,10 +57,10 @@ public:
SKIP_IF_CURRENT_TEST_IS_DISABLED();
std::tie(target_device, configuration, selectedModelName) = this->GetParam();
- if (selectedModelName == "CustomNet") {
- GTEST_SKIP() << "CustomNet is currently skipped for multithread host compile tests";
- }
configuration[ov::intel_npu::compile_log_level.name()] = ov::log::Level::ERR;
+ #if !defined(OPENVINO_STATIC_LIBRARY) && !defined(USE_STATIC_IE)
+ ov::test::utils::register_template_plugin(core);
+ #endif // !OPENVINO_STATIC_LIBRARY && !USE_STATIC_IE
std::vector<std::string> deviceNames =
core.get_property("NPU", ov::available_devices.name()).as<std::vector<std::string>>();
@@ -206,16 +75,7 @@ public:
}
static std::shared_ptr<ov::Model> createModelByName(const std::string& modelName) {
- if (modelName == "CustomNet") {
- return createCustomNetModelMT();
- }
- if (modelName == "MaxPool") {
- return createMaxPoolModelMT();
- }
- if (modelName == "MaxPool_NCHW") {
- return createMaxPoolModelMT(false, false);
- }
- OPENVINO_THROW("Unknown model name for InferWithHostCompileMultithreadTests: ", modelName);
+ return createESPCNX2ModelByName(modelName);
}
static void runConcurrently(size_t threadCount,
@@ -340,10 +200,19 @@ public:
runConcurrentlyAsync(threadCount, [](size_t) {}, startInference, waitInference);
}
+ // Requests differ by independent random patterns (distinct seeds) at a fixed small amplitude. DC offsets do
+ // not work: after the 1/128 input scale, Tanh compresses large offsets below the comparison tolerance.
+ static constexpr uint32_t kInputFillRange = 100;
+
static ov::Tensor makeInputTensor(const std::shared_ptr<ov::Model>& model,
const ov::Shape& shape,
- const int startFrom) {
- return ov::test::utils::create_and_fill_tensor(model->input().get_element_type(), shape, 100, startFrom);
+ const int seed) {
+ return ov::test::utils::create_and_fill_tensor(model->input().get_element_type(),
+ shape,
+ kInputFillRange,
+ 0,
+ 1,
+ seed);
}
static void inferAndCompare(ov::InferRequest& reqDynamic, ov::InferRequest& reqReference) {
@@ -352,7 +221,8 @@ public:
const auto npuOutputTensor = reqDynamic.get_output_tensor(0);
const auto referenceOutputTensor = reqReference.get_output_tensor(0);
- ov::test::utils::compare(referenceOutputTensor, npuOutputTensor, npuOutputTensor.get_element_type());
+ // NPU HostCompile runs in reduced (f16-class) precision while the TEMPLATE reference is f32.
+ ov::test::utils::compare(referenceOutputTensor, npuOutputTensor, npuOutputTensor.get_element_type(), 0.02, 0.02);
}
static void waitAndCompare(ov::InferRequest& reqDynamic, ov::InferRequest& reqReference) {
@@ -361,7 +231,8 @@ public:
const auto npuOutputTensor = reqDynamic.get_output_tensor(0);
const auto referenceOutputTensor = reqReference.get_output_tensor(0);
- ov::test::utils::compare(referenceOutputTensor, npuOutputTensor, npuOutputTensor.get_element_type());
+ // NPU HostCompile runs in reduced (f16-class) precision while the TEMPLATE reference is f32.
+ ov::test::utils::compare(referenceOutputTensor, npuOutputTensor, npuOutputTensor.get_element_type(), 0.02, 0.02);
}
static void setInputInferAndCompare(ov::InferRequest& reqDynamic,
@@ -375,9 +246,9 @@ public:
static ov::Tensor makeZeroInputTensor(ov::RemoteContext& zeroContext,
const std::shared_ptr<ov::Model>& model,
const ov::Shape& shape,
- const int startFrom) {
+ const int seed) {
auto zeroInput = zeroContext.create_host_tensor(model->input().get_element_type(), shape);
- auto inputSource = makeInputTensor(model, shape, startFrom);
+ auto inputSource = makeInputTensor(model, shape, seed);
if (inputSource.get_byte_size() != zeroInput.get_byte_size()) {
OPENVINO_THROW("Source and zero input tensors have different byte sizes");
}
@@ -406,19 +277,13 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_PerThreadCompileCreateInfer) {
}
constexpr size_t kThreadCount = 4;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shape = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -434,7 +299,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_PerThreadCompileCreateInfer) {
requests[threadIdx] = std::make_shared<ov::InferRequest>(compiledModel.create_infer_request());
referenceRequests[threadIdx] =
std::make_shared<ov::InferRequest>(referenceCompiledModel.create_infer_request());
- inputs[threadIdx] = makeInputTensor(model, shape, static_cast<int>(100 + threadIdx));
+ inputs[threadIdx] = makeInputTensor(model, shape, static_cast<int>(1 + threadIdx));
requests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
referenceRequests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
},
@@ -447,26 +312,79 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_PerThreadCompileCreateInfer) {
}
}
-TEST_P(InferWithHostCompileMultithreadTests, MT_SingleCompileParallelCreateRequestAndInfer) {
+// Negative control for the per-request seed spacing: distinct requests must produce outputs that differ by
+// more than the comparison tolerance, so comparing one request's NPU output against another request's
+// reference is rejected. This guards the concurrency checks against silently accepting cross-request swaps.
+TEST_P(InferWithHostCompileMultithreadTests, MT_CrossRequestOutputMismatchIsRejected) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
if (!isTargetDevice) {
GTEST_SKIP() << "Skip test for current device";
}
- constexpr size_t kThreadCount = 8;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
+ auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shape = makeInputShape(referenceModel, 1, false);
+ ov::CompiledModel referenceCompiledModel;
+ try {
+ referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();
}
+ const auto cfg = makeConfig(/*sharedQueue=*/true);
+ auto model = createModelByName(selectedModelName);
+ ov::CompiledModel compiledModel;
+ OV_ASSERT_NO_THROW(compiledModel = core.compile_model(model, target_device, cfg));
+
+ auto npuRequestA = compiledModel.create_infer_request();
+ auto referenceRequestA = referenceCompiledModel.create_infer_request();
+ auto referenceRequestB = referenceCompiledModel.create_infer_request();
+
+ // Adjacent seed pairs from the low and high end of the seeds used by the concurrent tests, at both shapes.
+ const ov::Shape shapeLarge = makeInputShape(referenceModel, 1, true);
+ const std::vector<std::tuple<ov::Shape, int, int>> cases = {
+ {shape, 1, 2},
+ {shape, 1023, 1024},
+ {shapeLarge, 23, 24},
+ };
+ for (const auto& [caseShape, seedA, seedB] : cases) {
+ const auto inputA = makeInputTensor(model, caseShape, seedA);
+ const auto inputB = makeInputTensor(model, caseShape, seedB);
+ npuRequestA.set_input_tensor(0, inputA);
+ referenceRequestA.set_input_tensor(0, inputA);
+ referenceRequestB.set_input_tensor(0, inputB);
+
+ OV_ASSERT_NO_THROW(npuRequestA.infer());
+ OV_ASSERT_NO_THROW(referenceRequestA.infer());
+ OV_ASSERT_NO_THROW(referenceRequestB.infer());
+
+ const auto npuOutputA = npuRequestA.get_output_tensor(0);
+ const auto referenceOutputA = referenceRequestA.get_output_tensor(0);
+ const auto referenceOutputB = referenceRequestB.get_output_tensor(0);
+ const auto outputType = npuOutputA.get_element_type();
+
+ // Matching request pair stays within the NPU-calibrated tolerance.
+ OV_ASSERT_NO_THROW(ov::test::utils::compare(referenceOutputA, npuOutputA, outputType, 0.02, 0.02));
+
+ // The other request's reference must be rejected, proving swapped outputs are detectable.
+ ASSERT_THROW(ov::test::utils::compare(referenceOutputB, npuOutputA, outputType, 0.02, 0.02),
+ std::runtime_error);
+ }
+}
+
+TEST_P(InferWithHostCompileMultithreadTests, MT_SingleCompileParallelCreateRequestAndInfer) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED()
+ if (!isTargetDevice) {
+ GTEST_SKIP() << "Skip test for current device";
+ }
+
+ constexpr size_t kThreadCount = 8;
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shape = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -485,7 +403,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_SingleCompileParallelCreateReque
requests[threadIdx] = std::make_shared<ov::InferRequest>(compiledModel.create_infer_request());
referenceRequests[threadIdx] =
std::make_shared<ov::InferRequest>(referenceCompiledModel.create_infer_request());
- inputs[threadIdx] = makeInputTensor(model, shape, static_cast<int>(100 + threadIdx));
+ inputs[threadIdx] = makeInputTensor(model, shape, static_cast<int>(1 + threadIdx));
requests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
referenceRequests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
},
@@ -505,19 +423,13 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_ConcurrentInferThenSetPriorityAn
}
constexpr size_t kThreadCount = 8;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shape = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -541,10 +453,11 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_ConcurrentInferThenSetPriorityAn
referenceRequests.emplace_back(referenceCompiledModel.create_infer_request());
}
+ // Each phase uses fresh seeds so a request's data changes after every priority switch.
std::vector<ov::Tensor> firstInputs;
firstInputs.reserve(kThreadCount);
for (size_t i = 0; i < kThreadCount; ++i) {
- firstInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(100 + i)));
+ firstInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(1 + i)));
requests[i].set_input_tensor(0, firstInputs.back());
referenceRequests[i].set_input_tensor(0, firstInputs.back());
}
@@ -562,7 +475,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_ConcurrentInferThenSetPriorityAn
std::vector<ov::Tensor> secondInputs;
secondInputs.reserve(kThreadCount);
for (size_t i = 0; i < kThreadCount; ++i) {
- secondInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(200 + i)));
+ secondInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(1 + kThreadCount + i)));
requests[i].set_input_tensor(0, secondInputs.back());
referenceRequests[i].set_input_tensor(0, secondInputs.back());
}
@@ -580,7 +493,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_ConcurrentInferThenSetPriorityAn
std::vector<ov::Tensor> thirdInputs;
thirdInputs.reserve(kThreadCount);
for (size_t i = 0; i < kThreadCount; ++i) {
- thirdInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(300 + i)));
+ thirdInputs.emplace_back(makeInputTensor(model, shape, static_cast<int>(1 + 2 * kThreadCount + i)));
requests[i].set_input_tensor(0, thirdInputs.back());
referenceRequests[i].set_input_tensor(0, thirdInputs.back());
}
@@ -605,22 +518,14 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_MultiCompiledModelsMultiRequests
constexpr size_t kModelCount = 3;
constexpr size_t kRequestsPerModel = 2;
constexpr size_t kInferLoops = 3;
- ov::Shape shapeLarge;
- ov::Shape shapeSmall;
- if (selectedModelName == "MaxPool_NCHW") {
- shapeLarge = {1, 16, 720, 1280};
- shapeSmall = {1, 16, 360, 640};
- } else {
- shapeLarge = {1, 720, 1280, 16};
- shapeSmall = {1, 360, 640, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shapeLarge = makeInputShape(referenceModel, 1, true);
+ const ov::Shape shapeSmall = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -673,9 +578,11 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_MultiCompiledModelsMultiRequests
referenceRequests[threadIdx].emplace_back(
referenceCompiledModel.create_infer_request());
}
- const int startFrom =
- static_cast<int>(100 + threadIdx * 17 + modelIdx * 7 + reqIdx * 3 + inferIdx);
- inputs[threadIdx].emplace_back(makeInputTensor(model, shape, startFrom));
+ const int requestSeedIndex = static_cast<int>(
+ threadIdx * (compiledModels.size() * requestsPerModel) +
+ modelIdx * requestsPerModel + reqIdx);
+ const int seed = 1 + requestSeedIndex + static_cast<int>(inferIdx) * 1000;
+ inputs[threadIdx].emplace_back(makeInputTensor(model, shape, seed));
const size_t requestIdx = modelIdx * requestsPerModel + reqIdx;
requests[threadIdx][requestIdx].set_input_tensor(0, inputs[threadIdx].back());
referenceRequests[threadIdx][requestIdx].set_input_tensor(0, inputs[threadIdx].back());
@@ -709,22 +616,14 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_SingleCompileParallelZeroInputOu
constexpr size_t kThreadCount = 4;
constexpr size_t kInferLoops = 3;
- ov::Shape shapeLarge;
- ov::Shape shapeSmall;
- if (selectedModelName == "MaxPool_NCHW") {
- shapeLarge = {1, 16, 720, 1280};
- shapeSmall = {1, 16, 360, 640};
- } else {
- shapeLarge = {1, 720, 1280, 16};
- shapeSmall = {1, 360, 640, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shapeLarge = makeInputShape(referenceModel, 1, true);
+ const ov::Shape shapeSmall = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -759,9 +658,10 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_SingleCompileParallelZeroInputOu
std::make_shared<ov::InferRequest>(referenceCompiledModel.create_infer_request());
}
auto zeroContext = core.get_default_context(target_device);
- const int startFrom = static_cast<int>(100 + threadIdx * 11 + inferIdx);
- inputs[threadIdx] = makeZeroInputTensor(zeroContext, model, shape, startFrom);
- outputs[threadIdx] = zeroContext.create_host_tensor(model->output().get_element_type(), shape);
+ const int seed = static_cast<int>(100 + threadIdx * 11 + inferIdx);
+ inputs[threadIdx] = makeZeroInputTensor(zeroContext, model, shape, seed);
+ outputs[threadIdx] = zeroContext.create_host_tensor(model->output().get_element_type(),
+ makeOutputShape(selectedModelName, shape));
requests[threadIdx]->set_tensor(model->input(), inputs[threadIdx]);
requests[threadIdx]->set_tensor(model->output(), outputs[threadIdx]);
referenceRequests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
@@ -788,22 +688,14 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_PerThreadCompileZeroInputOutputT
constexpr size_t kThreadCount = 4;
constexpr size_t kInferLoops = 3;
- ov::Shape shapeLarge;
- ov::Shape shapeSmall;
- if (selectedModelName == "MaxPool_NCHW") {
- shapeLarge = {1, 16, 720, 1280};
- shapeSmall = {1, 16, 360, 640};
- } else {
- shapeLarge = {1, 720, 1280, 16};
- shapeSmall = {1, 360, 640, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shapeLarge = makeInputShape(referenceModel, 1, true);
+ const ov::Shape shapeSmall = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -841,10 +733,10 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_PerThreadCompileZeroInputOutputT
std::make_shared<ov::InferRequest>(referenceCompiledModel.create_infer_request());
}
auto zeroContext = core.get_default_context(target_device);
- const int startFrom = static_cast<int>(100 + threadIdx * 11 + inferIdx);
- inputs[threadIdx] = makeZeroInputTensor(zeroContext, models[threadIdx], shape, startFrom);
- outputs[threadIdx] =
- zeroContext.create_host_tensor(models[threadIdx]->output().get_element_type(), shape);
+ const int seed = static_cast<int>(100 + threadIdx * 11 + inferIdx);
+ inputs[threadIdx] = makeZeroInputTensor(zeroContext, models[threadIdx], shape, seed);
+ outputs[threadIdx] = zeroContext.create_host_tensor(models[threadIdx]->output().get_element_type(),
+ makeOutputShape(selectedModelName, shape));
requests[threadIdx]->set_tensor(models[threadIdx]->input(), inputs[threadIdx]);
requests[threadIdx]->set_tensor(models[threadIdx]->output(), outputs[threadIdx]);
referenceRequests[threadIdx]->set_input_tensor(0, inputs[threadIdx]);
@@ -871,19 +763,13 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_CompileAndInferOverlap) {
constexpr size_t kModelCount = 4;
constexpr size_t kThreadCount = 4;
- ov::Shape shape;
- if (selectedModelName == "MaxPool_NCHW") {
- shape = {1, 16, 720, 1280};
- } else {
- shape = {1, 720, 1280, 16};
- }
-
auto referenceModel = createModelByName(selectedModelName);
+ const ov::Shape shape = makeInputShape(referenceModel, 1, false);
ov::CompiledModel referenceCompiledModel;
try {
referenceCompiledModel = core.compile_model(referenceModel, ov::test::utils::DEVICE_TEMPLATE);
- } catch (const ov::Exception&) {
- GTEST_SKIP() << "TEMPLATE plugin unavailable";
+ } catch (const ov::Exception& e) {
+ GTEST_SKIP() << "TEMPLATE plugin unavailable" << e.what();;
}
for (bool sharedQueue : {true, false}) {
@@ -933,7 +819,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_CompileAndInferOverlap) {
auto reqDynamic = compiledModel.create_infer_request();
auto reqReference = referenceCompiledModel.create_infer_request();
- auto input = makeInputTensor(model, shape, static_cast<int>(100 + threadIdx));
+ auto input = makeInputTensor(model, shape, static_cast<int>(1 + threadIdx));
reqDynamic.set_input_tensor(0, input);
reqReference.set_input_tensor(0, input);
reqDynamic.start_async();
@@ -993,7 +879,7 @@ TEST_P(InferWithHostCompileMultithreadTests, MT_CompileAndInferOverlap) {
}
}
-const std::vector<std::string> mtDevices = {"NPU.4000", "NPU.5010"};
+const std::vector<std::string> mtDevices = {"NPU.4000", "NPU.5010", "NPU.6010"};
const std::vector<ov::AnyMap> mtConfigs = {
{
@@ -1007,14 +893,14 @@ const std::vector<ov::AnyMap> mtConfigs = {
},
};
-const std::vector<std::string> mtModelNames = {"MaxPool_NCHW" /*, "CustomNet"*/};
+const std::vector<std::string> mtModelNames = {"ESPCN_x2_DynHW_H1080xW960"};
INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests,
InferWithHostCompileMultithreadTests,
::testing::Combine(::testing::ValuesIn(mtDevices),
::testing::ValuesIn(mtConfigs),
::testing::ValuesIn(mtModelNames)),
- InferWithHostCompileMultithreadTests::getTestCaseName);
+ ov::test::utils::appendPlatformTypeTestName<InferWithHostCompileMultithreadTests>);
} // namespace behavior
} // namespace test
diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml
index 2c909326954..2b9f9e263a4 100644
--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml
+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml
@@ -422,30 +422,6 @@ Example:
</filters>
</skip_config>
- <!-- E#239219 -->
- <skip_config>
- <message>HostCompile cannot compile the dynamic MaxPool model because CopyOpTiling cannot compute allocation size for dynamic shapes without bounds.</message>
- <enable_rules>
- <device>4000</device>
- <device>5010</device>
- </enable_rules>
- <filters>
- <filter>.*InferWithDefaultHostCompileTests.CompileDynamicModelWithNoHostCompileMode.*model=MaxPool_NCHW_targetPlatform.*</filter>
- </filters>
- </skip_config>
-
- <skip_config>
- <message>Random accuracy issue for multithread test.</message>
- <enable_rules>
- <device>4000</device>
- <device>5010</device>
- <device>6010</device>
- </enable_rules>
- <filters>
- <filter>.*InferWithHostCompileMultithreadTests.MT_ConcurrentInferThenSetPriorityAndInfer.*</filter>
- </filters>
- </skip_config>
-
<!-- C#195015 -->
<skip_config>
<message>samePlatformProduceTheSameBlobCacheEnabled will be removed as functionality should be tested by driver</message>