OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Fix coverity issues (#35334)
Alexandru Enacheaf9152cdd65d
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.cppindex 5d73ff709bb..ff41fa8cf6c 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@@ -310,19 +310,11 @@ void DynamicPipeline::update_graph_arguments(uint32_t index,"Command list index is higher than the number of Command lists ",batch_index);- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {- _command_lists.at(batch_index)- ->updateMutableCommandList(index,- zeroTensor->data(),- get_strides(tensor->get_strides(), elementSize),- tensor->get_shape());- } else {- _command_lists.at(batch_index)- ->updateMutableCommandList(index,- zeroTensor->data(),- get_strides(tensor->get_strides(), elementSize),- tensor->get_shape());- }+ _command_lists.at(batch_index)+ ->updateMutableCommandList(index,+ zeroTensor->data(),+ get_strides(tensor->get_strides(), elementSize),+ tensor->get_shape());}} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cppindex 572bd6821ee..8987914d4e9 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@@ -43,7 +43,7 @@ std::optional<size_t> determine_dynamic_batch_size(const IODescriptor& desc,return std::nullopt;}- auto batchFromModel = ioShape[intel_npu::utils::BATCH_AXIS];+ const auto& batchFromModel = ioShape[intel_npu::utils::BATCH_AXIS];auto batchModelFromIR =desc.shapeFromIRModel.has_value() && desc.shapeFromIRModel.value()[intel_npu::utils::BATCH_AXIS].is_dynamic();if (!batchFromModel.is_dynamic() && !batchModelFromIR) {diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cppindex c5c2caea423..76dd94241f6 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/compiler_impl.cpp@@ -98,13 +98,13 @@ ov::Tensor make_tensor_from_aligned_addr(uint8_t* allocated, size_t size) {ov::Allocator allocator;auto tensor = ov::Tensor(ov::element::u8, ov::Shape{size}, allocated);auto impl = ov::get_tensor_impl(std::move(tensor));- std::shared_ptr<void> ptr(allocated, [allocator, size](uint8_t* p) mutable {+ std::shared_ptr<void> ptr(allocated, [allocator = std::move(allocator), size](uint8_t* p) mutable {if (p == nullptr) {OPENVINO_THROW("Pointer is nullptr in memory deallocation of make_tensor_from_aligned_addr!");}allocator.deallocate(p, size, intel_npu::utils::STANDARD_PAGE_SIZE);});- impl._so = ptr;+ impl._so = std::move(ptr);return ov::make_tensor(impl);}diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cppindex 9bf5c960f02..817666f24d6 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp@@ -24,7 +24,7 @@ public:using MemRefType = DynamicGraph::MemRefType;public:- DynamicGraphImpl() : _logger("DynamicGraphImpl", Logger::global().level()) {}+ DynamicGraphImpl() : _engineProperties{}, _logger("DynamicGraphImpl", Logger::global().level()) {}void initialize(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) override;void createExecutionEngine(std::optional<ov::Tensor>& blob);void prepareMetadata(NetworkMetadata& metadata);@@ -230,10 +230,10 @@ void DynamicGraphImpl::prepareMetadata(NetworkMetadata& metadata) {ioDesc.supportsStridedLayout = true;switch (arg.type) {case ZE_GRAPH_ARGUMENT_TYPE_INPUT: {- metadata.inputs.push_back(ioDesc);+ metadata.inputs.push_back(std::move(ioDesc));} break;case ZE_GRAPH_ARGUMENT_TYPE_OUTPUT: {- metadata.outputs.push_back(ioDesc);+ metadata.outputs.push_back(std::move(ioDesc));} break;default: {OPENVINO_THROW("Invalid ze_graph_argument_type_t found in ze_graph_argument_properties_3_t object: ",diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/model_serializer.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/model_serializer.cppindex 88e0acf2158..6d924775b02 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/model_serializer.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/model_serializer.cpp@@ -435,7 +435,7 @@ public:OPENVINO_ASSERT(offset == sizeOfSerializedIR);- return {buffer, sizeOfSerializedIR, ov::intel_npu::ModelSerializerVersion::ALL_WEIGHTS_COPY, hash};+ return {std::move(buffer), sizeOfSerializedIR, ov::intel_npu::ModelSerializerVersion::ALL_WEIGHTS_COPY, hash};}private:@@ -517,7 +517,7 @@ public:std::optional<uint64_t> hash = computeModelHash ? std::make_optional<uint64_t>(0) : std::nullopt;serialize_model_to_buffer(model, buffer.get(), hash);- return {buffer, serializedModelSize, ov::intel_npu::ModelSerializerVersion::NO_WEIGHTS_COPY, hash};+ return {std::move(buffer), serializedModelSize, ov::intel_npu::ModelSerializerVersion::NO_WEIGHTS_COPY, hash};}private:diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cppindex 8e857f9e081..1578ee10e1b 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp@@ -279,16 +279,17 @@ std::optional<std::vector<std::string>> PluginCompilerAdapter::get_supported_opt}bool PluginCompilerAdapter::is_option_supported(std::string optname, std::optional<std::string> optValue) const {- const char* optvalue_ch = optValue.has_value() ? optValue.value().c_str() : nullptr;- if (_compiler->is_option_supported(optname, optValue)) {+ const bool hasValue = optValue.has_value();+ const std::string value = hasValue ? optValue.value() : "";+ if (_compiler->is_option_supported(optname, std::move(optValue))) {_logger.debug("Option %s is supported `%s` by VCLCompilerImpl",optname.c_str(),- optvalue_ch ? optvalue_ch : "null");+ hasValue ? value.c_str() : "null");return true;} else {_logger.debug("Option %s is not supported `%s` by VCLCompilerImpl",optname.c_str(),- optvalue_ch ? optvalue_ch : "null");+ hasValue ? value.c_str() : "null");return false;}}diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cppindex b02e99ced3d..ca6a73f7d4d 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp@@ -53,7 +53,7 @@ std::unordered_map<size_t, std::shared_ptr<ov::op::v0::Constant>> get_all_consta"This may indicate a bug in OV model compression.");continue;}- constant = constantNode;+ constant = std::move(constantNode);}}@@ -411,7 +411,7 @@ WeightlessGraph::InputData WeightlessGraph::allocate_inputs(constants.erase(id);}- return {initInputsViewTensors, initInputsAllocatedTensor};+ return {std::move(initInputsViewTensors), initInputsAllocatedTensor};}WeightlessGraph::OutputData WeightlessGraph::allocate_outputs(const size_t initIndex) {@@ -441,7 +441,7 @@ WeightlessGraph::OutputData WeightlessGraph::allocate_outputs(const size_t initIoffset += ov::util::get_memory_size(descriptor.precision, shape_size(descriptor.shapeFromCompiler.to_shape()));}- return {initOutputsViewTensorsVector, initOutputsAllocatedTensor, initOutputsViewTensorsMap};+ return {std::move(initOutputsViewTensorsVector), initOutputsAllocatedTensor, std::move(initOutputsViewTensorsMap)};}void WeightlessGraph::run_init_single_threaded() {diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex e5d4647c045..43e9c084385 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -440,7 +440,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<// available devices (if any)const auto compilationPlatform =utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());CompilerAdapterFactory factory;@@ -560,7 +560,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<_logger.debug("performing compile");// Determine which model to use- auto modelToCompile = successfullyDebatched ? batchedModel : model->clone();+ auto modelToCompile = successfullyDebatched ? std::move(batchedModel) : model->clone();const bool performanceHintSetByUser = localConfig.has(ov::hint::performance_mode.name());const bool shouldForceThroughput = successfullyDebatched && !performanceHintSetByUser;@@ -786,7 +786,7 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&const auto compilationPlatform =utils::getCompilationPlatform(_propertiesManager->determinePlatform(localProperties),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());CompilerAdapterFactory factory;diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cppindex 557088633c9..5087ad818f5 100644--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp@@ -628,7 +628,9 @@ void Properties::registerPluginProperties() {REGISTER_SIMPLE_METRIC(ov::device::pci_info, true, _metrics->GetPciInfo(get_specified_device_name(config)));REGISTER_SIMPLE_METRIC(ov::device::gops, true, _metrics->GetGops(get_specified_device_name(config)));REGISTER_SIMPLE_METRIC(ov::device::type, true, _metrics->GetDeviceType(get_specified_device_name(config)));- REGISTER_SIMPLE_METRIC(ov::internal::supported_properties, false, _internalSupportedProperties);+ REGISTER_CUSTOM_METRIC(ov::internal::supported_properties, false, [&](const Config&) {+ return _internalSupportedProperties;+ });REGISTER_SIMPLE_METRIC(ov::internal::cache_header_alignment, false, utils::STANDARD_PAGE_SIZE);REGISTER_SIMPLE_METRIC(ov::intel_npu::device_alloc_mem_size,true,@@ -676,7 +678,7 @@ void Properties::registerPluginProperties() {auto compilationPlatform = utils::getCompilationPlatform(config.get<PLATFORM>(),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());CompilerAdapterFactory factory;@@ -835,7 +837,7 @@ ov::Any Properties::getProperty(const std::string& name) {auto compilationPlatform = utils::getCompilationPlatform(_config.get<PLATFORM>(),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());// Create a compiler to get the type and fetch version and supported options if needed@@ -915,7 +917,7 @@ void Properties::setProperty(const ov::AnyMap& properties) {auto compilationPlatform = utils::getCompilationPlatform(determinePlatform(properties),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());// Create a compiler to get the type and fetch version and supported options if needed@@ -999,7 +1001,7 @@ bool Properties::isPropertySupported(const std::string& name) {auto compilationPlatform = utils::getCompilationPlatform(_config.get<PLATFORM>(),- device == nullptr ? deviceId : device->getName(),+ device == nullptr ? std::move(deviceId) : device->getName(),_backend == nullptr ? std::vector<std::string>() : _backend->getDeviceNames());// Create a compiler to get the type and fetch version and supported options if needed@@ -1027,7 +1029,7 @@ bool Properties::isPropertySupported(const std::string& name) {registerProperties();_compilerConfigsFilteredByCompiler = true;_currentlyUsedCompiler = compilerType;- _currentlyUsedPlatform = compilationPlatform;+ _currentlyUsedPlatform = std::move(compilationPlatform);}}@@ -1107,7 +1109,7 @@ FilteredConfig Properties::getConfigWithCompilerPropertiesDisabled(const ov::Any}if (properties.empty()) {- return updatedConfig;+ return std::move(updatedConfig);}const std::map<std::string, std::string> rawConfig = any_copy(properties);@@ -1135,7 +1137,7 @@ FilteredConfig Properties::getConfigWithCompilerPropertiesDisabled(const ov::AnyupdatedConfig.update(cfgsToSet);- return updatedConfig;+ return std::move(updatedConfig);}ov::intel_npu::CompilerType Properties::determineCompilerType(const ov::AnyMap& properties) const {