Skip to content

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

[NPU] Fix SDL issues (#28995)

Bogdan Pereanu0b5b439535e8
diff --git a/src/plugins/intel_npu/src/al/src/config/config.cpp b/src/plugins/intel_npu/src/al/src/config/config.cpp
index 343e1e948fd..b9906b1af3e 100644
--- a/src/plugins/intel_npu/src/al/src/config/config.cpp
+++ b/src/plugins/intel_npu/src/al/src/config/config.cpp
@@ -252,7 +252,7 @@ void Config::fromString(const std::string& str) {
auto pos_eq = token.find('=');
auto key = token.substr(0, pos_eq);
auto value = token.substr(pos_eq + 2, token.size() - pos_eq - 3);
- config[key] = value;
+ config[key] = std::move(value);
};
size_t pos = 0;
diff --git a/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp b/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp
index e40d56e07a0..4a42f003ea4 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_tensor.hpp
@@ -24,6 +24,7 @@ namespace intel_npu {
class ZeroTensor final : public ov::ITensor {
public:
ZeroTensor(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
+ const Config& config,
const ov::element::Type element_type,
const ov::Shape& shape,
const ov::Allocator& allocator);
@@ -55,6 +56,7 @@ private:
void destroy_memory();
std::shared_ptr<ZeroInitStructsHolder> _init_structs;
+ Logger _logger;
ov::element::Type _element_type;
ov::Shape _shape;
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 df9cc4eb328..b5829cb0c0a 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
@@ -455,7 +455,7 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {
size_t ioIndex = 0;
for (const auto& levelZeroTensor : _levelZeroInputTensors) {
- const auto inputDescriptor = _metadata.inputs.at(ioIndex);
+ const auto& inputDescriptor = _metadata.inputs.at(ioIndex);
auto zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(levelZeroTensor.at(SINGLE_TENSOR));
if (is_batched_input(ioIndex) || inputDescriptor.isShapeTensor ||
@@ -484,7 +484,7 @@ void ZeroInferRequest::update_pipeline_if_memory_changed() {
ioIndex = 0;
for (const auto& levelZeroTensor : _levelZeroOutputTensors) {
- const auto outputDescriptor = _metadata.outputs.at(ioIndex);
+ const auto& outputDescriptor = _metadata.outputs.at(ioIndex);
auto zeroTensor = std::dynamic_pointer_cast<ZeroTensor>(levelZeroTensor);
if (outputDescriptor.isShapeTensor || is_remote_tensor(levelZeroTensor) || zeroTensor == nullptr) {
@@ -790,7 +790,7 @@ std::shared_ptr<ov::ITensor> ZeroInferRequest::create_tensor(ov::element::Type t
const ov::Allocator& allocator) const {
OPENVINO_ASSERT(allocator, "Allocator mush be provided when creating a zero tensor!");
- return std::make_shared<ZeroTensor>(_initStructs, type, shape, allocator);
+ return std::make_shared<ZeroTensor>(_initStructs, _config, type, shape, allocator);
}
void ZeroInferRequest::add_state(const IODescriptor& descriptor, size_t tensorIndex) const {
diff --git a/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp b/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp
index d5b2c3a5b59..2014f168cdf 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp
@@ -146,7 +146,7 @@ NpuInferStatistics NpuInferProfiling::getNpuInferStatistics() const {
info.exec_type = "INFER_REQ";
info.node_type = "INFER_REQ";
- npuPerfCounts.push_back(info);
+ npuPerfCounts.push_back(std::move(info));
}
}
@@ -163,21 +163,21 @@ NpuInferStatistics NpuInferProfiling::getNpuInferStatistics() const {
"AVG",
"AVG",
"AVG"};
- npuPerfCounts.push_back(info_avg);
+ npuPerfCounts.push_back(std::move(info_avg));
ov::ProfilingInfo info_min = {ov::ProfilingInfo::Status::EXECUTED,
std::chrono::microseconds(convertCCtoUS(_npu_infer_stats_min_cc)),
std::chrono::microseconds(convertCCtoUS(_npu_infer_stats_min_cc)),
"MIN",
"MIN",
"MIN"};
- npuPerfCounts.push_back(info_min);
+ npuPerfCounts.push_back(std::move(info_min));
ov::ProfilingInfo info_max = {ov::ProfilingInfo::Status::EXECUTED,
std::chrono::microseconds(convertCCtoUS(_npu_infer_stats_max_cc)),
std::chrono::microseconds(convertCCtoUS(_npu_infer_stats_max_cc)),
"MAX",
"MAX",
"MAX"};
- npuPerfCounts.push_back(info_max);
+ npuPerfCounts.push_back(std::move(info_max));
return npuPerfCounts;
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp b/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
index 999cfe81140..f87b2eec5ea 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_remote_tensor.cpp
@@ -74,8 +74,15 @@ bool ZeroRemoteTensor::deallocate() noexcept {
if (_data) {
auto result = zeMemFree(_init_structs->getContext(), _data);
if (ZE_RESULT_SUCCESS != result) {
- return false;
+ if (ZE_RESULT_ERROR_UNINITIALIZED == result) {
+ _logger.warning("ZeroRemoteTensor failed to free memory; Level zero context was already destroyed "
+ "and memory was already released by the driver.");
+ } else {
+ _logger.error("zeMemFree failed %#X", uint64_t(result));
+ return false;
+ }
}
+
_data = nullptr;
}
diff --git a/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp b/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
index 6d34186b22b..6cb2d354dea 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_tensor.cpp
@@ -4,6 +4,7 @@
#include "zero_tensor.hpp"
+#include "intel_npu/config/common.hpp"
#include "openvino/core/type/element_iterator.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/runtime/tensor.hpp"
@@ -11,10 +12,12 @@
namespace intel_npu {
ZeroTensor::ZeroTensor(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
+ const Config& config,
const ov::element::Type element_type,
const ov::Shape& shape,
const ov::Allocator& allocator)
: _init_structs(init_structs),
+ _logger("ZeroTensor", config.get<LOG_LEVEL>()),
_element_type{element_type},
_shape{shape},
_capacity{_shape},
@@ -153,7 +156,13 @@ void ZeroTensor::set_tensor_shared_with_user() {
}
ZeroTensor::~ZeroTensor() {
- destroy_memory();
+ try {
+ destroy_memory();
+ } catch (const std::exception& ex) {
+ _logger.error("Failed to destroy Zero Tensor: %s", ex.what());
+ } catch (...) {
+ _logger.error("Unexpected error when Zero Tensor is destroyed");
+ }
}
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
index e1657b1118f..936babb2352 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
@@ -92,7 +92,7 @@ protected:
std::unique_ptr<BlobContainer> _blobPtr;
uint32_t _unique_id = 0;
- uint32_t _last_submitted_id;
+ uint32_t _last_submitted_id = 0;
/**
* @brief The batch size used by the corresponding model.
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ir_serializer.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ir_serializer.cpp
index 7760056e127..5c0d82982c3 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/ir_serializer.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ir_serializer.cpp
@@ -33,7 +33,7 @@ IRSerializer::IRSerializer(const std::shared_ptr<const ov::Model>& origModel, co
void IRSerializer::serializeModelToStream(std::ostream& xml, std::ostream& weights) {
_logger.debug("serializeModelToStream");
const auto passConfig = std::make_shared<ov::pass::PassConfig>();
- ov::pass::Manager manager(passConfig, "NPU:serializeModelToStream");
+ ov::pass::Manager manager(std::move(passConfig), "NPU:serializeModelToStream");
if (_supportedOpset < 11) {
// Downgrade to opset10
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
index d5e793d4fff..a083eaa8582 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp
@@ -219,7 +219,7 @@ static std::unordered_set<std::string> parseQueryResult(std::vector<char>& data)
start = ++i;
} else if (dataString[i] == '>') {
std::string temp(dataString.begin() + start, dataString.begin() + i);
- result.insert(temp);
+ result.insert(std::move(temp));
i++;
} else {
i++;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 3bfbd7aead3..3b0b4d66b80 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -66,7 +66,7 @@ std::shared_ptr<ov::Model> create_dummy_model(const std::vector<IODescriptor>& i
parameter->set_friendly_name(inputDescriptor.nodeFriendlyName);
parameter->output(0).get_tensor().set_names(inputDescriptor.outputTensorNames);
- parameters.push_back(parameter);
+ parameters.push_back(std::move(parameter));
}
// The "result" nodes require a parent node in order to satisfy the API conventions. Additionally, a dummy shape for
@@ -90,7 +90,7 @@ std::shared_ptr<ov::Model> create_dummy_model(const std::vector<IODescriptor>& i
std::shared_ptr<ov::Node> result = std::make_shared<ov::op::v0::Result>(constantDummy);
result->output(0).set_tensor_ptr(tensorDummy);
result->set_friendly_name(outputDescriptor.nodeFriendlyName);
- results.push_back(result);
+ results.push_back(std::move(result));
}
return std::make_shared<ov::Model>(results, parameters);
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
index a7eac18ea30..db8884dff80 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
@@ -323,8 +323,12 @@ ZeroInitStructsHolder::~ZeroInitStructsHolder() {
if (context) {
log.debug("ZeroInitStructsHolder - performing zeContextDestroy");
auto result = zeContextDestroy(context);
- if (result != ZE_RESULT_SUCCESS && result != ZE_RESULT_ERROR_UNINITIALIZED) {
- log.error("zeContextDestroy failed %#X", uint64_t(result));
+ if (result != ZE_RESULT_SUCCESS) {
+ if (result == ZE_RESULT_ERROR_UNINITIALIZED) {
+ log.warning("zeContextDestroy failed to destroy the context; Level zero context was already destroyed");
+ } else {
+ log.error("zeContextDestroy failed %#X", uint64_t(result));
+ }
}
}
}