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
[core] Fix Coverity issues in inference component (#36826)
Pawel Raasz2f2256ec5b74
diff --git a/src/inference/include/openvino/runtime/compiled_model.hpp b/src/inference/include/openvino/runtime/compiled_model.hppindex 9cd907955e2..5347d4befa7 100644--- a/src/inference/include/openvino/runtime/compiled_model.hpp+++ b/src/inference/include/openvino/runtime/compiled_model.hpp@@ -53,6 +53,26 @@ public:*/CompiledModel() = default;+ /**+ * @brief Default copy constructor.+ */+ CompiledModel(const CompiledModel&) = default;++ /**+ * @brief Default copy assignment operator.+ */+ CompiledModel& operator=(const CompiledModel&) = default;++ /**+ * @brief Default move constructor.+ */+ CompiledModel(CompiledModel&&) = default;++ /**+ * @brief Default move assignment operator.+ */+ CompiledModel& operator=(CompiledModel&&) = default;+/*** @brief Destructor that preserves unloading order of an implementation object and reference to library.*/diff --git a/src/inference/src/dev/make_tensor.cpp b/src/inference/src/dev/make_tensor.cppindex d95002f0bf0..9ef2032db14 100644--- a/src/inference/src/dev/make_tensor.cpp+++ b/src/inference/src/dev/make_tensor.cpp@@ -306,20 +306,26 @@ std::shared_ptr<ITensor> make_tensor(const element::Type element_type,* Tensor owns the memory*/class AllocatedTensor : public ViewTensor {+ using MemSpace = std::pair<void*, size_t>;++ static MemSpace do_allocate(const element::Type& element_type, const Shape& shape, const Allocator& allocator) {+ OPENVINO_ASSERT(allocator, "Allocator was not initialized");+ const auto byte_size = util::get_memory_size_safe(element_type, shape);+ OPENVINO_ASSERT(byte_size, bad_alloc_error_msg(element_type, shape));+ auto data = const_cast<Allocator&>(allocator).allocate(*byte_size);+ OPENVINO_ASSERT(*byte_size == 0 || data != nullptr, "Failed to allocate memory");+ initialize_elements(data, element_type, shape);+ return {data, *byte_size};+ }++ AllocatedTensor(const element::Type element_type, const Shape& shape, const Allocator& allocator, MemSpace alloc)+ : ViewTensor{element_type, shape, alloc.first},+ m_allocator{allocator},+ m_bytes_capacity{alloc.second} {}+public:AllocatedTensor(const element::Type element_type, const Shape& shape, const Allocator& allocator)- : ViewTensor{element_type,- shape,- [&shape, &element_type, &allocator] {- OPENVINO_ASSERT(allocator, "Allocator was not initialized");- const auto byte_size = util::get_memory_size_safe(element_type, shape);- OPENVINO_ASSERT(byte_size, bad_alloc_error_msg(element_type, shape));- auto data = const_cast<Allocator&>(allocator).allocate(*byte_size);- OPENVINO_ASSERT(*byte_size == 0 || data != nullptr, "Failed to allocate memory");- initialize_elements(data, element_type, shape);- return data;- }()},- m_allocator{allocator} {}+ : AllocatedTensor{element_type, shape, allocator, do_allocate(element_type, shape, allocator)} {}~AllocatedTensor() {destroy_memory();@@ -338,6 +344,7 @@ public:// allocate buffer and initialize objects from scratchm_capacity = m_shape;m_ptr = m_allocator.allocate(*byte_size);+ m_bytes_capacity = *byte_size;initialize_elements(m_ptr, m_element_type, m_shape);}@@ -376,7 +383,7 @@ private:}size_t get_bytes_capacity() const {- return util::get_memory_size(get_element_type(), get_capacity());+ return m_bytes_capacity;}static std::string bad_alloc_error_msg(const element::Type& element_type, const Shape& shape) {@@ -384,6 +391,7 @@ private:}Allocator m_allocator;+ size_t m_bytes_capacity;};/**diff --git a/src/inference/src/dev/plugin.hpp b/src/inference/src/dev/plugin.hppindex 1a6c5894973..15bbc1c199b 100644--- a/src/inference/src/dev/plugin.hpp+++ b/src/inference/src/dev/plugin.hpp@@ -27,6 +27,10 @@ class Plugin {public:Plugin() = default;+ Plugin(const Plugin&) = default;+ Plugin& operator=(const Plugin&) = default;+ Plugin(Plugin&&) = default;+ Plugin& operator=(Plugin&&) = default;~Plugin();