-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix itt resource memory leak issue #34096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright (C) 2018-2026 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| set(TARGET_NAME openvino_shutdown) | ||
|
|
||
| add_library(${TARGET_NAME} STATIC shutdown.cpp) | ||
|
|
||
| add_library(openvino::shutdown ALIAS ${TARGET_NAME}) | ||
| target_include_directories(${TARGET_NAME} PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) | ||
| set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME shutdown) | ||
| ov_add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}) | ||
|
|
||
| # install & export | ||
| ov_install_static_lib(${TARGET_NAME} ${OV_CPACK_COMP_CORE}) | ||
| ov_developer_package_export_targets(TARGET openvino::shutdown | ||
| INSTALL_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| #pragma once | ||
| #include <functional> | ||
| #include <vector> | ||
|
|
||
| namespace ov { | ||
| // Registers a shutdown callback | ||
| bool register_shutdown_callback(const std::function<void()>& func); | ||
| } | ||
|
|
||
| #define OV_REGISTER_SHUTDOWN_CALLBACK(func) \ | ||
| namespace { \ | ||
| static bool ov_shutdown_register_##func = ov::register_shutdown_callback(func); \ | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| #include "openvino/shutdown.hpp" | ||
|
|
||
| #include <functional> | ||
| #include <vector> | ||
|
|
||
| namespace ov { | ||
|
|
||
| class ShutdownRegistry { | ||
| private: | ||
| std::vector<std::function<void()>> m_callbacks; | ||
| ShutdownRegistry() = default; | ||
| public: | ||
|
|
||
| static ShutdownRegistry& get() { | ||
| static ShutdownRegistry instance; | ||
| return instance; | ||
| } | ||
|
|
||
| bool register_callback(const std::function<void()>& func) { | ||
| if (!func) { | ||
| return false; | ||
| } | ||
| m_callbacks.emplace_back(func); | ||
| return true; | ||
|
Comment on lines
+22
to
+27
|
||
| } | ||
|
|
||
| ~ShutdownRegistry() { | ||
| for (auto& func : m_callbacks) { | ||
| func(); | ||
| } | ||
| m_callbacks.clear(); | ||
| } | ||
|
Comment on lines
+30
to
+35
|
||
| }; | ||
|
|
||
| bool register_shutdown_callback(const std::function<void()>& func) { | ||
| return ShutdownRegistry::get().register_callback(func); | ||
| } | ||
|
|
||
| } // namespace ov | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,4 @@ target_include_directories(${TARGET_NAME} SYSTEM PRIVATE | |
| $<BUILD_INTERFACE:$<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>>) | ||
| set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) | ||
| target_compile_features(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_COMPILE_FEATURES>) | ||
| target_link_libraries(${TARGET_NAME} PRIVATE openvino::shutdown) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to link additional library into frontends? Not sure that for fixing memory leaks we need to create the library?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to unify the resource deallocation logic. In this way, all new modules with resource deallocation requirements can use this interface. I found this case is similar to the ITT case, so change it.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we need to talk about this deallocation logic. May be we need to have another approach.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is small library allow clean resources and is linked with ITT library (plugins use so no additional linking required). @sgbihu
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can find the duplicate steps in the https://jira.devtools.intel.com/browse/CVS-180657, I used the gflags/appverifier to monitor the memory leak issue. I can list the brief steps here:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old way attempts to call
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Linkage to the new library allows to ensure a modular approach. We can put the code directly to the frontend/backends/core as alternative solution but it is a bad practice. So from frontend library perspective nothing is changed if |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OV_REGISTER_SHUTDOWN_CALLBACKexpands to a namespace-scopestatic boolthat is never referenced, which will trigger-Wunused-variableunder-Wall(and can become a build break with warnings-as-errors). Also, usingov_shutdown_register_##funcmakes the macro fail for non-identifier arguments (e.g.,&func, qualified names) and can cause redefinition errors if the macro is invoked twice with the same callback name in one TU. Consider generating a unique variable name (e.g., with__COUNTER__/__LINE__), and marking it[[maybe_unused]](and/orconst) so it is warning-free.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we referenced
src\frontends\onnx\frontend\src\core\operator_set.hpp,#define ONNX_OP(name, range, ...) static bool onnx_op_reg = ONNX_OP_M(name, range, __VA_ARGS__)