Skip to content

Commit c924cff

Browse files
committed
Fix tests that run with PV driver
Signed-off-by: Bogdan Pereanu <[email protected]>
1 parent 1eb1bb5 commit c924cff

File tree

3 files changed

+51
-47
lines changed

3 files changed

+51
-47
lines changed

src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {
594594
}
595595

596596
if (levelZeroTensor.at(SINGLE_TENSOR)->memory_address_changed()) {
597+
if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
598+
OPENVINO_THROW("Reallocation of zero memory is not supported with this driver.");
599+
}
600+
597601
_logger.debug("Update input graph descriptor with the new tensor");
598602
OPENVINO_ASSERT(levelZeroTensor.at(SINGLE_TENSOR)->data(), "Empty buffer");
599603

@@ -620,6 +624,10 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {
620624
}
621625

622626
if (levelZeroTensor->memory_address_changed()) {
627+
if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
628+
OPENVINO_THROW("Reallocation of zero memory is not supported with this driver.");
629+
}
630+
623631
_logger.debug("Update output graph descriptor with the new tensor");
624632
OPENVINO_ASSERT(levelZeroTensor->data(), "Empty buffer");
625633

@@ -644,7 +652,9 @@ void ZeroInferRequest::update_states_if_memory_changed() {
644652
_userOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_user_state();
645653
zeroState->clear_state_update_pending();
646654

647-
if (zeroState->zero_state_update_pending()) {
655+
// If command list updates are not supported, fallback to copying tensors every time.
656+
if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0) &&
657+
zeroState->zero_state_update_pending()) {
648658
get_level_zero_input(zeroState->get_tensor_index()) = zeroState->get_zero_state();
649659
_levelZeroOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_zero_state();
650660
zeroState->clear_zero_state_update_pending();
@@ -684,11 +694,8 @@ void ZeroInferRequest::infer_async() {
684694
_pipelineIsCreated = true;
685695
_dynamicBatchValueChanged = false; // Reset reallocation flag
686696
} else {
687-
if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
688-
update_pipeline_if_memory_changed();
689-
update_states_if_memory_changed();
690-
}
691-
// If command list updates are not supported, fallback to copying tensors every time.
697+
update_pipeline_if_memory_changed();
698+
update_states_if_memory_changed();
692699
}
693700
}
694701

src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,27 @@ void ZeroVariableState::set_state(const ov::SoPtr<ov::ITensor>& new_state) {
3838
m_state = new_state;
3939
_is_state_updated = true;
4040

41-
if (_init_structs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
42-
try {
43-
_logger.debug("ZeroVariableState::set_state - create zero tensor");
44-
// Try to use the user tensor directly if its underlying data is already allocated in the same Level Zero
45-
// context.
46-
_zero_state = std::make_shared<ZeroTensor>(_init_structs, m_state, _config);
41+
try {
42+
_logger.debug("ZeroVariableState::set_state - create zero tensor");
43+
// Try to use the user tensor directly if its underlying data is already allocated in the same Level Zero
44+
// context.
45+
_zero_state = std::make_shared<ZeroTensor>(_init_structs, m_state, _config);
46+
_is_zero_state_update_needed = true;
47+
} catch (const ZeroTensorException&) {
48+
// Check if the current Level Zero tensor was previously shared with the user. If so, it cannot be reused;
49+
// allocate a new tensor to back up the user tensor (which cannot be imported or used directly).
50+
if (_zero_state == nullptr || !_zero_state->can_be_reused()) {
51+
_logger.debug("ZeroVariableState::set_state - allocate locally L0 tensor");
52+
_zero_state = std::make_shared<ZeroTensor>(_init_structs,
53+
_config,
54+
m_state->get_element_type(),
55+
m_state->get_shape(),
56+
false);
4757
_is_zero_state_update_needed = true;
48-
} catch (const ZeroTensorException&) {
49-
// Check if the current Level Zero tensor was previously shared with the user. If so, it cannot be reused;
50-
// allocate a new tensor to back up the user tensor (which cannot be imported or used directly).
51-
if (_zero_state == nullptr || !_zero_state->can_be_reused()) {
52-
_logger.debug("ZeroVariableState::set_state - allocate locally L0 tensor");
53-
_zero_state = std::make_shared<ZeroTensor>(_init_structs,
54-
_config,
55-
m_state->get_element_type(),
56-
m_state->get_shape(),
57-
false);
58-
_is_zero_state_update_needed = true;
59-
} else {
60-
_logger.debug("ZeroVariableState::set_state - reusing the level zero tensor since it is not shared "
61-
"with the user");
62-
}
58+
} else {
59+
_logger.debug("ZeroVariableState::set_state - reusing the level zero tensor since it is not shared "
60+
"with the user");
6361
}
64-
// If command list updates are not supported, fallback to copying tensors every time.
6562
}
6663
}
6764

src/plugins/intel_npu/tests/functional/internal/backend/zero_tensor_tests.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace ov {
4444
namespace test {
4545
namespace behavior {
4646
class ZeroTensorTests : public ov::test::behavior::OVPluginTestBase,
47-
public testing::WithParamInterface<CompilationParams> {
47+
public testing::WithParamInterface<CompilationParams> {
4848
protected:
4949
std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
5050
ov::AnyMap configuration;
@@ -125,17 +125,13 @@ TEST_P(ZeroTensorTests, CheckSetSmallerShape) {
125125
auto new_shape = Shape{1, 10, 10, 10};
126126
auto new_shape_size = ov::shape_size(new_shape);
127127
// Reallocation is not required.
128-
if (init_struct->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
129-
zero_tensor->set_shape(new_shape);
130-
EXPECT_EQ(new_shape, zero_tensor->get_shape());
131-
EXPECT_EQ(new_shape_size, zero_tensor->get_size());
132-
EXPECT_EQ(new_shape_size * sizeof(ov::element::f32), zero_tensor->get_byte_size());
133-
EXPECT_EQ(data, zero_tensor->data());
134-
ASSERT_TRUE(::intel_npu::zeroUtils::memory_was_allocated_in_the_same_l0_context(init_struct->getContext(),
135-
zero_tensor->data()));
136-
} else {
137-
ASSERT_THROW(zero_tensor->set_shape(new_shape), ov::Exception);
138-
}
128+
zero_tensor->set_shape(new_shape);
129+
EXPECT_EQ(new_shape, zero_tensor->get_shape());
130+
EXPECT_EQ(new_shape_size, zero_tensor->get_size());
131+
EXPECT_EQ(new_shape_size * sizeof(ov::element::f32), zero_tensor->get_byte_size());
132+
EXPECT_EQ(data, zero_tensor->data());
133+
ASSERT_TRUE(::intel_npu::zeroUtils::memory_was_allocated_in_the_same_l0_context(init_struct->getContext(),
134+
zero_tensor->data()));
139135
}
140136

141137
TEST_P(ZeroTensorTests, CheckSetBiggerShape) {
@@ -152,13 +148,17 @@ TEST_P(ZeroTensorTests, CheckSetBiggerShape) {
152148
auto new_shape_size = ov::shape_size(new_shape);
153149
// set_shape() will force tensor reallocation for a larger shape. The new data pointer must also be a valid level
154150
// zero address.
155-
zero_tensor->set_shape(new_shape);
156-
EXPECT_EQ(new_shape, zero_tensor->get_shape());
157-
EXPECT_EQ(new_shape_size, zero_tensor->get_size());
158-
EXPECT_EQ(new_shape_size * sizeof(ov::element::f32), zero_tensor->get_byte_size());
159-
ASSERT_TRUE(zero_tensor->memory_address_changed());
160-
ASSERT_TRUE(::intel_npu::zeroUtils::memory_was_allocated_in_the_same_l0_context(init_struct->getContext(),
161-
zero_tensor->data()));
151+
if (init_struct->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
152+
zero_tensor->set_shape(new_shape);
153+
EXPECT_EQ(new_shape, zero_tensor->get_shape());
154+
EXPECT_EQ(new_shape_size, zero_tensor->get_size());
155+
EXPECT_EQ(new_shape_size * sizeof(ov::element::f32), zero_tensor->get_byte_size());
156+
ASSERT_TRUE(zero_tensor->memory_address_changed());
157+
ASSERT_TRUE(::intel_npu::zeroUtils::memory_was_allocated_in_the_same_l0_context(init_struct->getContext(),
158+
zero_tensor->data()));
159+
} else {
160+
ASSERT_THROW(zero_tensor->set_shape(new_shape), ov::Exception);
161+
}
162162
}
163163

164164
TEST_P(ZeroTensorTests, CheckIsContinuousZeroTensorScalar) {

0 commit comments

Comments
 (0)