Skip to content

Commit

Permalink
[core] Move malloc_tim to compile model implementation (#27881)
Browse files Browse the repository at this point in the history
### Details:
- The `malloc_trim` in `CompileModel` class cause to often trigger not
when real implementation is removed but on each destruction of wrapper.
Now the destructor of `ICompileModel` trigger it should be called after
all inference related to this model.

### Tickets:
- CVS-158427

Signed-off-by: Raasz, Pawel <[email protected]>
  • Loading branch information
praasz authored Dec 3, 2024
1 parent 9e9a70b commit 395340e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/inference/dev_api/openvino/runtime/icompiled_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ class OPENVINO_RUNTIME_API ICompiledModel : public std::enable_shared_from_this<

/**
* @brief Release intermediate memory
*
*
*/
virtual void release_memory();

virtual ~ICompiledModel() = default;
virtual ~ICompiledModel();

private:
std::shared_ptr<const ov::IPlugin> m_plugin;
Expand Down
10 changes: 0 additions & 10 deletions src/inference/src/cpp/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/properties.hpp"

#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
# include <malloc.h>
#endif

#define OV_COMPILED_MODEL_CALL_STATEMENT(...) \
if (_impl == nullptr) \
OPENVINO_THROW("CompiledModel was not initialized."); \
Expand All @@ -27,12 +23,6 @@ namespace ov {

CompiledModel::~CompiledModel() {
_impl = {};
#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
// Linux memory margent doesn't return system memory immediate after release.
// It depends on memory chunk size and allocation history.
// Try return memory from a process to system now to reduce memory usage and not wait to the end of the process.
malloc_trim(0);
#endif
}

CompiledModel::CompiledModel(const std::shared_ptr<ov::ICompiledModel>& impl, const std::shared_ptr<void>& so)
Expand Down
13 changes: 13 additions & 0 deletions src/inference/src/dev/icompiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "openvino/runtime/properties.hpp"
#include "transformations/utils/utils.hpp"

#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
# include <malloc.h>
#endif

ov::ICompiledModel::ICompiledModel(const std::shared_ptr<const ov::Model>& model,
const std::shared_ptr<const ov::IPlugin>& plugin,
const std::shared_ptr<ov::threading::ITaskExecutor>& task_executor,
Expand Down Expand Up @@ -151,3 +155,12 @@ void ov::ICompiledModel::set_model_shared_object(ov::Model& model, const std::sh
void ov::ICompiledModel::release_memory() {
// nothing to do
}

ov::ICompiledModel::~ICompiledModel() {
#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
// Linux memory margent doesn't return system memory immediate after release.
// It depends on memory chunk size and allocation history.
// Try return memory from a process to system now to reduce memory usage and not wait to the end of the process.
malloc_trim(0);
#endif
}

0 comments on commit 395340e

Please sign in to comment.