Skip to content

Commit 652860a

Browse files
authored
[NPU] Get value or default value in case of std::optional is not set (#29466)
### Details: - *Get value or default value in case of std::optional is not set* Signed-off-by: Bogdan Pereanu <bogdan.pereanu@intel.com>
1 parent 6a8185f commit 652860a

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ void ZeroInferRequest::add_state(const IODescriptor& descriptor, size_t tensorIn
793793
descriptor.nameFromCompiler,
794794
get_user_input(tensorIndex),
795795
tensorIndex,
796-
*descriptor.relatedDescriptorIndex,
796+
descriptor.relatedDescriptorIndex.value(),
797797
_config));
798798
}
799799

src/plugins/intel_npu/src/plugin/src/remote_context.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:
6262
}
6363

6464
// Merge local remote properties with global remote properties.
65-
if (!mem_type_object.has_value()) {
65+
if (!mem_type_object.has_value() && _mem_type_object.has_value()) {
6666
mem_type_object = _mem_type_object;
6767
}
68-
if (!tensor_type_object.has_value()) {
68+
if (!tensor_type_object.has_value() && _tensor_type_object.has_value()) {
6969
tensor_type_object = _tensor_type_object;
7070
}
71-
if (!mem_handle_object.has_value()) {
71+
if (!mem_handle_object.has_value() && _mem_handle_object.has_value()) {
7272
mem_handle_object = _mem_handle_object;
7373
}
7474

@@ -82,27 +82,25 @@ ov::SoPtr<ov::IRemoteTensor> RemoteContextImpl::create_tensor(const ov::element:
8282
}
8383

8484
// Mem_handle shall be set if mem_type is a shared memory type.
85-
if (*mem_type_object == MemType::SHARED_BUF && !mem_handle_object.has_value()) {
85+
if (mem_type_object.value() == MemType::SHARED_BUF && !mem_handle_object.has_value()) {
8686
OPENVINO_THROW("No parameter ", mem_handle.name(), " found in parameters map");
8787
}
8888

89-
return _device->createRemoteTensor(
90-
get_this_shared_ptr(),
91-
type,
92-
shape,
93-
_config,
94-
tensor_type_object.has_value() ? *tensor_type_object : ov::intel_npu::TensorType::BINDED,
95-
*mem_type_object,
96-
*mem_handle_object);
89+
return _device->createRemoteTensor(get_this_shared_ptr(),
90+
type,
91+
shape,
92+
_config,
93+
tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED),
94+
mem_type_object.value_or(ov::intel_npu::MemType::L0_INTERNAL_BUF),
95+
mem_handle_object.value_or(nullptr));
9796
}
9897

9998
ov::SoPtr<ov::ITensor> RemoteContextImpl::create_host_tensor(const ov::element::Type type, const ov::Shape& shape) {
100-
return _device->createHostTensor(
101-
get_this_shared_ptr(),
102-
type,
103-
shape,
104-
_config,
105-
_tensor_type_object.has_value() ? *_tensor_type_object : ov::intel_npu::TensorType::BINDED);
99+
return _device->createHostTensor(get_this_shared_ptr(),
100+
type,
101+
shape,
102+
_config,
103+
_tensor_type_object.value_or(ov::intel_npu::TensorType::BINDED));
106104
}
107105

108106
const std::string& RemoteContextImpl::get_device_name() const {

0 commit comments

Comments
 (0)