diff --git a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp index e6edc46b61eeb4..2b7106924945cb 100644 --- a/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp +++ b/src/plugins/intel_npu/src/backend/include/zero_infer_request.hpp @@ -67,7 +67,7 @@ class ZeroInferRequest final : public SyncInferRequest { const ov::Shape& shape, const ov::Allocator& allocator = {}) const override; - void add_state(const IODescriptor& descriptor, size_t index) const override; + void add_state(const IODescriptor& descriptor, size_t tensorIndex) const override; void update_pipeline_if_memory_changed(); void update_states_if_memory_changed(); diff --git a/src/plugins/intel_npu/src/backend/include/zero_variable_state.hpp b/src/plugins/intel_npu/src/backend/include/zero_variable_state.hpp index 1ec6b3df08078e..8275353c40d4e7 100644 --- a/src/plugins/intel_npu/src/backend/include/zero_variable_state.hpp +++ b/src/plugins/intel_npu/src/backend/include/zero_variable_state.hpp @@ -4,41 +4,70 @@ #pragma once -#include "intel_npu/common/variable_state.hpp" #include "intel_npu/config/config.hpp" #include "intel_npu/network_metadata.hpp" #include "intel_npu/utils/logger/logger.hpp" #include "intel_npu/utils/zero/zero_init.hpp" +#include "openvino/runtime/ivariable_state.hpp" namespace intel_npu { -class ZeroVariableState final : public VariableState { +/** + * @brief Interface for zero variable state implementation + * @note In case the memory was allocated in the same level zero context use that memory, otherwise use memcpy at infer + * time. Also, get correct data if remote tensor is used. + */ +class ZeroVariableState final : public ov::IVariableState { public: explicit ZeroVariableState(const std::shared_ptr& init_structs, - const IODescriptor& descriptor, + const std::string& name, const ov::SoPtr& tensor, - size_t index, + size_t tensor_index, + size_t related_tensor_index, const Config& config); void set_state(const ov::SoPtr& new_state) override; void reset() override; - size_t get_index() const; - const IODescriptor& get_descriptor() const; + /** + * @brief Get input tensor index used internally for the state + */ + size_t get_tensor_index() const; + /** + * @brief Get output tensor index used internally for the state + * @details The related tensors are defined by state input, state output pairs. + */ + size_t get_related_tensor_index() const; + + /** + * @brief Get acknowledge if the tensor was updated + */ bool tensor_was_updated() const; + + /** + * @brief Reset tensor updated flag + */ void reset_tensor_updated_flag(); + /** + * @brief Get acknowledge if the zero tensor was updated + * @details In case the memory was allocated in the same level zero context update the zero tensor + */ bool zero_tensor_should_be_updated() const; + + /** + * @brief Reset zero tensor updated flag + */ void reset_zero_tensor_updated_flag(); ~ZeroVariableState() override = default; private: std::shared_ptr _init_structs; - IODescriptor _descriptor; - size_t _index; + size_t _tensor_index; + size_t _related_tensor_index; bool _tensor_updated = false; bool _zero_tensor_updated = false; diff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp index 8785e6a74aaa45..c8a4fdc8df19fc 100644 --- a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp +++ b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp @@ -64,33 +64,6 @@ void check_level_zero_attributes_match(const IODescriptor& ioDescriptor, const A } } -template -Type extract_object(const ov::AnyMap& params, const ov::Property& p) { - auto itrHandle = params.find(p.name()); - ov::Any res = nullptr; - if (itrHandle == params.end()) { - OPENVINO_THROW("No parameter ", p.name(), " found in parameters map"); - } - res = itrHandle->second; - return res.as(); -} - -bool memory_was_allocated_in_the_same_l0_context(ze_context_handle_t hContext, const void* ptr) { - ze_memory_allocation_properties_t desc = {}; - desc.stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES; - auto res = intel_npu::zeMemGetAllocProperties(hContext, ptr, &desc, nullptr); - if (res == ZE_RESULT_SUCCESS) { - if (desc.id) { - if ((desc.type & ZE_MEMORY_TYPE_HOST) || (desc.type & ZE_MEMORY_TYPE_DEVICE) || - (desc.type & ZE_MEMORY_TYPE_SHARED)) { - return true; - } - } - } - - return false; -} - } // namespace //------------------------------------------------------------------------------ @@ -213,21 +186,16 @@ void ZeroInferRequest::create_pipeline() { OPENVINO_ASSERT(zeroState != nullptr, "State is not compatible with NPU plugin"); if (zeroState->tensor_was_updated()) { - OPENVINO_ASSERT(zeroState->get_descriptor().relatedDescriptorIndex.has_value(), - "The link between state descriptors is missing, state name: ", - zeroState->get_descriptor().nameFromCompiler); - - get_user_input(zeroState->get_index()) = zeroState->get_state(); - _userOutputTensors.at(*zeroState->get_descriptor().relatedDescriptorIndex) = zeroState->get_state(); + get_user_input(zeroState->get_tensor_index()) = zeroState->get_state(); + _userOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_state(); zeroState->reset_tensor_updated_flag(); if (zeroState->zero_tensor_should_be_updated()) { zeroState->reset_zero_tensor_updated_flag(); - get_level_zero_input(zeroState->get_index()) = zeroState->get_state()._ptr; - _levelZeroOutputTensors.at(*zeroState->get_descriptor().relatedDescriptorIndex) = - zeroState->get_state()._ptr; + get_level_zero_input(zeroState->get_tensor_index()) = zeroState->get_state()._ptr; + _levelZeroOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_state()._ptr; } } } @@ -257,7 +225,7 @@ void ZeroInferRequest::set_tensor_data(const std::shared_ptr& tenso bool updateCommandListArg = false; OV_ITT_TASK_NEXT(ZERO_SET_TENSOR, "check_data_allocation"); - if (memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), tensor->data())) { + if (zeroUtils::memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), tensor->data())) { _logger.debug("ZeroInferRequest::set_tensor_data - tensor was created in the same L0 context"); levelZeroTensors = tensor; updateCommandListArg = true; @@ -297,7 +265,7 @@ void ZeroInferRequest::set_remote_tensor_data(const std::shared_ptr( - extract_object(tensor->get_context()->get_property(), ov::intel_npu::l0_context)); + zeroUtils::extract_object(tensor->get_context()->get_property(), ov::intel_npu::l0_context)); if (_initStructs->getContext() != l0_context) { OPENVINO_THROW("Using different context for creating the tensor is not supported"); } @@ -308,7 +276,7 @@ void ZeroInferRequest::set_remote_tensor_data(const std::shared_ptrget_properties(), ov::intel_npu::mem_handle); + auto data = zeroUtils::extract_object(tensor->get_properties(), ov::intel_npu::mem_handle); OPENVINO_ASSERT(data, "Empty buffer"); OV_ITT_TASK_NEXT(ZERO_SET_REMOTE_TENSOR, "updateCommandList"); @@ -400,7 +368,8 @@ void ZeroInferRequest::set_tensors(const ov::Output& port, bool tensorHasSameL0Context = false; OV_ITT_TASK_NEXT(SET_TENSORS, "check_data_allocation"); - if (memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), tensors[i]->data())) { + if (zeroUtils::memory_was_allocated_in_the_same_l0_context(_initStructs->getContext(), + tensors[i]->data())) { _logger.debug("ZeroInferRequest::set_tensors - tensor was created in the same L0 context"); get_level_zero_input(foundPort.idx, i) = tensors.at(i)._ptr; @@ -419,7 +388,7 @@ void ZeroInferRequest::set_tensors(const ov::Output& port, } else { _logger.debug("ZeroInferRequest::set_tensors - remote tensor is used"); - data = extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle); + data = zeroUtils::extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle); get_level_zero_input(foundPort.idx, i) = tensors.at(i)._ptr; } @@ -553,36 +522,30 @@ void ZeroInferRequest::update_states_if_memory_changed() { OPENVINO_ASSERT(zeroState != nullptr, "State is not compatible with NPU plugin"); if (zeroState->tensor_was_updated()) { - OPENVINO_ASSERT(zeroState->get_descriptor().relatedDescriptorIndex.has_value(), - "The link between state descriptors is missing, state name: ", - zeroState->get_descriptor().nameFromCompiler); - - get_user_input(zeroState->get_index()) = zeroState->get_state(); - _userOutputTensors.at(*zeroState->get_descriptor().relatedDescriptorIndex) = zeroState->get_state(); + get_user_input(zeroState->get_tensor_index()) = zeroState->get_state(); + _userOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_state(); zeroState->reset_tensor_updated_flag(); if (zeroState->zero_tensor_should_be_updated()) { auto remoteTensor = std::dynamic_pointer_cast(zeroState->get_state()._ptr); - void* userBuffer = !remoteTensor - ? zeroState->get_state()->data() - : extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle); + void* userBuffer = !remoteTensor ? zeroState->get_state()->data() + : zeroUtils::extract_object(remoteTensor->get_properties(), + ov::intel_npu::mem_handle); - _pipeline->updateCommandList(_executorInputDescriptors.at(zeroState->get_index()).idx, + _pipeline->updateCommandList(_executorInputDescriptors.at(zeroState->get_tensor_index()).idx, userBuffer, zeroState->get_state()->get_byte_size()); - _pipeline->updateCommandList( - _executorOutputDescriptors.at(*zeroState->get_descriptor().relatedDescriptorIndex).idx, - userBuffer, - zeroState->get_state()->get_byte_size()); + _pipeline->updateCommandList(_executorOutputDescriptors.at(zeroState->get_related_tensor_index()).idx, + userBuffer, + zeroState->get_state()->get_byte_size()); zeroState->reset_zero_tensor_updated_flag(); - get_level_zero_input(zeroState->get_index()) = zeroState->get_state()._ptr; - _levelZeroOutputTensors.at(*zeroState->get_descriptor().relatedDescriptorIndex) = - zeroState->get_state()._ptr; + get_level_zero_input(zeroState->get_tensor_index()) = zeroState->get_state()._ptr; + _levelZeroOutputTensors.at(zeroState->get_related_tensor_index()) = zeroState->get_state()._ptr; closePipeline = true; } @@ -646,10 +609,10 @@ void ZeroInferRequest::infer_async() { auto userBatchRemoteTensor = std::dynamic_pointer_cast(userTensor.at(i)._ptr); - void* userBuffer = - !userBatchRemoteTensor - ? userTensor.at(i)->data() - : extract_object(userBatchRemoteTensor->get_properties(), ov::intel_npu::mem_handle); + void* userBuffer = !userBatchRemoteTensor + ? userTensor.at(i)->data() + : zeroUtils::extract_object(userBatchRemoteTensor->get_properties(), + ov::intel_npu::mem_handle); if (userBuffer != levelZeroBuffer) { if (userBuffer == nullptr || levelZeroBuffer == nullptr) { @@ -671,9 +634,10 @@ void ZeroInferRequest::infer_async() { for (size_t i = 0; i < userTensor.size(); i++) { auto userBatchRemoteTensor = std::dynamic_pointer_cast(userTensor.at(i)._ptr); - void* userBuffer = !userBatchRemoteTensor ? userTensor.at(i)->data() - : extract_object(userBatchRemoteTensor->get_properties(), - ov::intel_npu::mem_handle); + void* userBuffer = !userBatchRemoteTensor + ? userTensor.at(i)->data() + : zeroUtils::extract_object(userBatchRemoteTensor->get_properties(), + ov::intel_npu::mem_handle); std::memcpy(static_cast(levelZeroBuffer) + (i * userTensor.at(i)->get_byte_size()), userBuffer, @@ -686,9 +650,9 @@ void ZeroInferRequest::infer_async() { } auto userRemoteTensor = std::dynamic_pointer_cast(userTensor.at(SINGLE_TENSOR)._ptr); - void* userBuffer = !userRemoteTensor - ? userTensor.at(SINGLE_TENSOR)->data() - : extract_object(userRemoteTensor->get_properties(), ov::intel_npu::mem_handle); + void* userBuffer = !userRemoteTensor ? userTensor.at(SINGLE_TENSOR)->data() + : zeroUtils::extract_object(userRemoteTensor->get_properties(), + ov::intel_npu::mem_handle); const auto& levelZeroTensor = get_level_zero_input(inputIndex); if (!is_remote_tensor(levelZeroTensor)) { @@ -737,9 +701,9 @@ void ZeroInferRequest::get_result() { } auto userRemoteTensor = std::dynamic_pointer_cast(userTensor._ptr); - void* userBuffer = !userRemoteTensor - ? userTensor->data() - : extract_object(userRemoteTensor->get_properties(), ov::intel_npu::mem_handle); + void* userBuffer = !userRemoteTensor ? userTensor->data() + : zeroUtils::extract_object(userRemoteTensor->get_properties(), + ov::intel_npu::mem_handle); const std::shared_ptr& levelZeroTensor = _levelZeroOutputTensors.at(outputIndex); if (!is_remote_tensor(levelZeroTensor)) { @@ -836,9 +800,17 @@ std::shared_ptr ZeroInferRequest::create_tensor(ov::element::Type t return std::make_shared(_initStructs, type, shape, allocator); } -void ZeroInferRequest::add_state(const IODescriptor& descriptor, size_t index) const { - _variableStates.push_back( - std::make_shared(_initStructs, descriptor, get_user_input(index), index, _config)); +void ZeroInferRequest::add_state(const IODescriptor& descriptor, size_t tensorIndex) const { + OPENVINO_ASSERT(descriptor.relatedDescriptorIndex.has_value(), + "The link between state descriptors is missing, state name: ", + descriptor.nameFromCompiler); + + _variableStates.push_back(std::make_shared(_initStructs, + descriptor.nameFromCompiler, + get_user_input(tensorIndex), + tensorIndex, + *descriptor.relatedDescriptorIndex, + _config)); } std::vector ZeroInferRequest::get_raw_profiling_data() const { diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp index 7ada704c9969d8..a01238a899e0dc 100644 --- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp +++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp @@ -15,21 +15,6 @@ #include "intel_npu/utils/zero/zero_types.hpp" #include "zero_remote_tensor.hpp" -namespace { - -template -Type extract_object(const ov::AnyMap& params, const ov::Property& p) { - auto itrHandle = params.find(p.name()); - ov::Any res = nullptr; - if (itrHandle == params.end()) { - OPENVINO_THROW("No parameter ", p.name(), " found in parameters map"); - } - res = itrHandle->second; - return res.as(); -} - -} // namespace - namespace intel_npu { Pipeline::Pipeline(const Config& config, @@ -80,7 +65,7 @@ Pipeline::Pipeline(const Config& config, if (remote_tensor == nullptr) { data = input_tensors.at(io_index).at(i)->data(); } else { - data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); + data = zeroUtils::extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); } graph->set_argument_value(desc.idx, data); @@ -94,7 +79,7 @@ Pipeline::Pipeline(const Config& config, if (remote_tensor == nullptr) { data = input_tensors.at(io_index).at(0)->data(); } else { - data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); + data = zeroUtils::extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); } graph->set_argument_value( @@ -112,7 +97,7 @@ Pipeline::Pipeline(const Config& config, if (remote_tensor == nullptr) { data = output_tensors.at(io_index)->data(); } else { - data = extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); + data = zeroUtils::extract_object(remote_tensor->get_properties(), ov::intel_npu::mem_handle); } graph->set_argument_value( diff --git a/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp b/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp index ebf2b07b56b576..22a7a38063d7fa 100644 --- a/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp +++ b/src/plugins/intel_npu/src/backend/src/zero_variable_state.cpp @@ -5,52 +5,24 @@ #include "zero_variable_state.hpp" #include "intel_npu/config/common.hpp" -#include "intel_npu/utils/zero/zero_api.hpp" +#include "intel_npu/utils/zero/zero_utils.hpp" #include "zero_remote_tensor.hpp" -namespace { - -template -Type extract_object(const ov::AnyMap& params, const ov::Property& p) { - auto itrHandle = params.find(p.name()); - ov::Any res = nullptr; - if (itrHandle == params.end()) { - OPENVINO_THROW("No parameter ", p.name(), " found in parameters map"); - } - res = itrHandle->second; - return res.as(); -} - -bool memory_was_allocated_in_the_same_l0_context(ze_context_handle_t hContext, const void* ptr) { - ze_memory_allocation_properties_t desc = {}; - desc.stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES; - auto res = intel_npu::zeMemGetAllocProperties(hContext, ptr, &desc, nullptr); - if (res == ZE_RESULT_SUCCESS) { - if (desc.id) { - if ((desc.type & ZE_MEMORY_TYPE_HOST) || (desc.type & ZE_MEMORY_TYPE_DEVICE) || - (desc.type & ZE_MEMORY_TYPE_SHARED)) { - return true; - } - } - } - - return false; -} - -} // namespace - namespace intel_npu { ZeroVariableState::ZeroVariableState(const std::shared_ptr& init_structs, - const IODescriptor& descriptor, + const std::string& name, const ov::SoPtr& tensor, - size_t index, + size_t tensor_index, + size_t related_tensor_index, const Config& config) - : VariableState(descriptor.nameFromCompiler, tensor), + : ov::IVariableState(name), _init_structs(init_structs), - _descriptor(descriptor), - _index(index), - _logger("ZeroVariableState", config.get()) {} + _tensor_index(tensor_index), + _related_tensor_index(related_tensor_index), + _logger("ZeroVariableState", config.get()) { + m_state = tensor; +} void ZeroVariableState::set_state(const ov::SoPtr& new_state) { m_state = new_state; @@ -58,7 +30,8 @@ void ZeroVariableState::set_state(const ov::SoPtr& new_state) { if (_init_structs->getMutableCommandListVersion()) { if (!is_remote_tensor(new_state._ptr)) { - if (memory_was_allocated_in_the_same_l0_context(_init_structs->getContext(), new_state->data())) { + if (zeroUtils::memory_was_allocated_in_the_same_l0_context(_init_structs->getContext(), + new_state->data())) { _logger.debug("ZeroInferRequest::set_tensor_data - tensor was created in the same L0 context"); _zero_tensor_updated = true; } @@ -73,18 +46,19 @@ void ZeroVariableState::set_state(const ov::SoPtr& new_state) { void ZeroVariableState::reset() { auto remoteTensor = std::dynamic_pointer_cast(m_state._ptr); - void* userBuffer = - !remoteTensor ? m_state->data() : extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle); + void* userBuffer = !remoteTensor + ? m_state->data() + : zeroUtils::extract_object(remoteTensor->get_properties(), ov::intel_npu::mem_handle); std::memset(userBuffer, 0, m_state->get_byte_size()); } -size_t ZeroVariableState::get_index() const { - return _index; +size_t ZeroVariableState::get_tensor_index() const { + return _tensor_index; } -const IODescriptor& ZeroVariableState::get_descriptor() const { - return _descriptor; +size_t ZeroVariableState::get_related_tensor_index() const { + return _related_tensor_index; } bool ZeroVariableState::tensor_was_updated() const { diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp index b3b47eb5aa59f6..f7406413c9f197 100644 --- a/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp +++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/sync_infer_request.hpp @@ -167,7 +167,7 @@ class SyncInferRequest : public ov::IInferRequest { const ov::Shape& shape, const ov::Allocator& allocator = {}) const; - virtual void add_state(const IODescriptor& descriptor, const size_t index) const; + virtual void add_state(const IODescriptor& descriptor, const size_t tensorIndex) const; bool is_batched_input(size_t idx) const; diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/variable_state.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/variable_state.hpp index bd6576e14b6053..0987f2b44bbb04 100644 --- a/src/plugins/intel_npu/src/common/include/intel_npu/common/variable_state.hpp +++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/variable_state.hpp @@ -9,7 +9,7 @@ namespace intel_npu { -class VariableState : public ov::IVariableState { +class VariableState final : public ov::IVariableState { public: explicit VariableState(const std::string& name, const ov::SoPtr& tensor) : ov::IVariableState(name) { m_state = tensor; diff --git a/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp b/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp index 86730fc582be2f..775113ef0d39bf 100644 --- a/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp +++ b/src/plugins/intel_npu/src/common/src/sync_infer_request.cpp @@ -341,8 +341,9 @@ std::shared_ptr SyncInferRequest::create_tensor(ov::element::Type t return ov::make_tensor(type, shape, allocator); } -void SyncInferRequest::add_state(const IODescriptor& descriptor, const size_t index) const { - _variableStates.push_back(std::make_shared(descriptor.nameFromCompiler, get_user_input(index))); +void SyncInferRequest::add_state(const IODescriptor& descriptor, const size_t tensorIndex) const { + _variableStates.push_back( + std::make_shared(descriptor.nameFromCompiler, get_user_input(tensorIndex))); } bool SyncInferRequest::is_batched_input(size_t idx) const { diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp index db9dc1c9f51d34..0c2367b680851e 100644 --- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp +++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp @@ -277,5 +277,32 @@ static inline std::string getLatestBuildError(ze_graph_dditable_ext_curr_t& _gra } } +template +static inline Type extract_object(const ov::AnyMap& params, const ov::Property& p) { + auto itrHandle = params.find(p.name()); + ov::Any res = nullptr; + if (itrHandle == params.end()) { + OPENVINO_THROW("No parameter ", p.name(), " found in parameters map"); + } + res = itrHandle->second; + return res.as(); +} + +static inline bool memory_was_allocated_in_the_same_l0_context(ze_context_handle_t hContext, const void* ptr) { + ze_memory_allocation_properties_t desc = {}; + desc.stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES; + auto res = intel_npu::zeMemGetAllocProperties(hContext, ptr, &desc, nullptr); + if (res == ZE_RESULT_SUCCESS) { + if (desc.id) { + if ((desc.type & ZE_MEMORY_TYPE_HOST) || (desc.type & ZE_MEMORY_TYPE_DEVICE) || + (desc.type & ZE_MEMORY_TYPE_SHARED)) { + return true; + } + } + } + + return false; +} + } // namespace zeroUtils } // namespace intel_npu diff --git a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp index b8cc95899eb87a..ab53a442c16cda 100644 --- a/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp +++ b/src/plugins/intel_npu/tests/functional/behavior/infer_request_run.hpp @@ -21,10 +21,7 @@ #include "intel_npu/npu_private_properties.hpp" #include "openvino/core/any.hpp" #include "openvino/core/node_vector.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/multiply.hpp" #include "openvino/op/op.hpp" -#include "openvino/op/sigmoid.hpp" #include "openvino/opsets/opset8.hpp" #include "openvino/runtime/compiled_model.hpp" #include "openvino/runtime/core.hpp" @@ -128,35 +125,6 @@ class InferRequestRunTests : public ov::test::behavior::OVPluginTestBase, return std::make_shared(res, params); } - - std::shared_ptr createModelWithStates(element::Type type, const Shape& shape) { - auto input = std::make_shared(type, shape); - auto mem_i1 = std::make_shared(type, shape, 0); - auto mem_r1 = std::make_shared(mem_i1, "r_1-3"); - auto mul1 = std::make_shared(mem_r1, input); - - auto mem_i2 = std::make_shared(type, shape, 0); - auto mem_r2 = std::make_shared(mem_i2, "c_1-3"); - auto mul2 = std::make_shared(mem_r2, mul1); - auto mem_w2 = std::make_shared(mul2, "c_1-3"); - - auto mem_w1 = std::make_shared(mul2, "r_1-3"); - auto sigm = std::make_shared(mul2); - sigm->set_friendly_name("sigmod_state"); - sigm->get_output_tensor(0).set_names({"sigmod_state"}); - mem_r1->set_friendly_name("Memory_1"); - mem_r1->get_output_tensor(0).set_names({"Memory_1"}); - mem_w1->add_control_dependency(mem_r1); - sigm->add_control_dependency(mem_w1); - - mem_r2->set_friendly_name("Memory_2"); - mem_r2->get_output_tensor(0).set_names({"Memory_2"}); - mem_w2->add_control_dependency(mem_r2); - sigm->add_control_dependency(mem_w2); - - auto function = std::make_shared(ov::NodeVector{sigm}, ov::ParameterVector{input}, "add_output"); - return function; - } }; TEST_P(InferRequestRunTests, AllocatorCanDisposeBlobWhenOnlyInferRequestIsInScope) { diff --git a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/remote_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/remote_run.hpp index dbbfc7ac4e92b1..c1992b3047996d 100644 --- a/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/remote_run.hpp +++ b/src/plugins/intel_npu/tests/functional/behavior/remote_tensor_tests/remote_run.hpp @@ -13,10 +13,6 @@ #include "common/utils.hpp" #include "openvino/core/any.hpp" #include "openvino/core/type/element_iterator.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/multiply.hpp" -#include "openvino/op/op.hpp" -#include "openvino/op/sigmoid.hpp" #include "openvino/runtime/compiled_model.hpp" #include "openvino/runtime/core.hpp" #include "openvino/runtime/intel_npu/level_zero/level_zero.hpp" @@ -80,35 +76,6 @@ class RemoteRunTests : public ov::test::behavior::OVPluginTestBase, return ss.str(); } - std::shared_ptr createModelWithStates(element::Type type, const Shape& shape) { - auto input = std::make_shared(type, shape); - auto mem_i1 = std::make_shared(type, shape, 0); - auto mem_r1 = std::make_shared(mem_i1, "r_1-3"); - auto mul1 = std::make_shared(mem_r1, input); - - auto mem_i2 = std::make_shared(type, shape, 0); - auto mem_r2 = std::make_shared(mem_i2, "c_1-3"); - auto mul2 = std::make_shared(mem_r2, mul1); - auto mem_w2 = std::make_shared(mul2, "c_1-3"); - - auto mem_w1 = std::make_shared(mul2, "r_1-3"); - auto sigm = std::make_shared(mul2); - sigm->set_friendly_name("sigmod_state"); - sigm->get_output_tensor(0).set_names({"sigmod_state"}); - mem_r1->set_friendly_name("Memory_1"); - mem_r1->get_output_tensor(0).set_names({"Memory_1"}); - mem_w1->add_control_dependency(mem_r1); - sigm->add_control_dependency(mem_w1); - - mem_r2->set_friendly_name("Memory_2"); - mem_r2->get_output_tensor(0).set_names({"Memory_2"}); - mem_w2->add_control_dependency(mem_r2); - sigm->add_control_dependency(mem_w2); - - auto function = std::make_shared(ov::NodeVector{sigm}, ov::ParameterVector{input}, "add_output"); - return function; - } - void TearDown() override { if (!m_cache_dir.empty()) { core->set_property({ov::cache_dir()}); diff --git a/src/plugins/intel_npu/tests/functional/common/utils.cpp b/src/plugins/intel_npu/tests/functional/common/utils.cpp index 91f78487934e38..b041e694b19ad0 100644 --- a/src/plugins/intel_npu/tests/functional/common/utils.cpp +++ b/src/plugins/intel_npu/tests/functional/common/utils.cpp @@ -7,6 +7,10 @@ #include #include "intel_npu/npu_private_properties.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/op.hpp" +#include "openvino/op/sigmoid.hpp" std::string getBackendName(const ov::Core& core) { return core.get_property("NPU", ov::intel_npu::backend_name.name()).as(); @@ -99,3 +103,32 @@ std::vector getRWMandatoryPropertiesValues(std::vector p } return props; } + +std::shared_ptr createModelWithStates(ov::element::Type type, const ov::Shape& shape) { + auto input = std::make_shared(type, shape); + auto mem_i1 = std::make_shared(type, shape, 0); + auto mem_r1 = std::make_shared(mem_i1, "r_1-3"); + auto mul1 = std::make_shared(mem_r1, input); + + auto mem_i2 = std::make_shared(type, shape, 0); + auto mem_r2 = std::make_shared(mem_i2, "c_1-3"); + auto mul2 = std::make_shared(mem_r2, mul1); + auto mem_w2 = std::make_shared(mul2, "c_1-3"); + + auto mem_w1 = std::make_shared(mul2, "r_1-3"); + auto sigm = std::make_shared(mul2); + sigm->set_friendly_name("sigmod_state"); + sigm->get_output_tensor(0).set_names({"sigmod_state"}); + mem_r1->set_friendly_name("Memory_1"); + mem_r1->get_output_tensor(0).set_names({"Memory_1"}); + mem_w1->add_control_dependency(mem_r1); + sigm->add_control_dependency(mem_w1); + + mem_r2->set_friendly_name("Memory_2"); + mem_r2->get_output_tensor(0).set_names({"Memory_2"}); + mem_w2->add_control_dependency(mem_r2); + sigm->add_control_dependency(mem_w2); + + auto function = std::make_shared(ov::NodeVector{sigm}, ov::ParameterVector{input}, "add_output"); + return function; +} diff --git a/src/plugins/intel_npu/tests/functional/common/utils.hpp b/src/plugins/intel_npu/tests/functional/common/utils.hpp index 4ad54cc016302c..40ac987bd25487 100644 --- a/src/plugins/intel_npu/tests/functional/common/utils.hpp +++ b/src/plugins/intel_npu/tests/functional/common/utils.hpp @@ -6,6 +6,7 @@ #include #include + #include "common_test_utils/unicode_utils.hpp" std::string getBackendName(const ov::Core& core); @@ -18,6 +19,8 @@ std::string removeDeviceNameOnlyID(const std::string& device_name_id); std::vector getRWMandatoryPropertiesValues(std::vector props); +std::shared_ptr createModelWithStates(ov::element::Type type, const ov::Shape& shape); + template ::value || std::is_same::value)>::type> void removeDirFilesRecursive(const std::basic_string& path) { @@ -72,6 +75,8 @@ struct GenericTestCaseNameClass { }; template -constexpr bool GenericTestCaseNameClass::hasGetTestCaseName< - T, std::void_t().getTestCaseName( - std::declval>()))>> = true; +constexpr bool + GenericTestCaseNameClass::hasGetTestCaseName().getTestCaseName( + std::declval>()))>> = + true;