From 52f6fe7d2b31b25f462d0b11dd50639a0a3403a5 Mon Sep 17 00:00:00 2001 From: Sun Xiaoxia Date: Wed, 21 Aug 2024 12:04:09 +0800 Subject: [PATCH] Fix creating too many useless threads in cpu executor (#25704) ### Details: - *When compilide_mode() is based on async mode, main thread do not create additional stream for get_graph() and reuse information from streams(0)* ### Tickets: - *CVS-137803* Co-authored-by: Wanglei Shen --- .../dev/threading/cpu_streams_executor.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/inference/src/dev/threading/cpu_streams_executor.cpp b/src/inference/src/dev/threading/cpu_streams_executor.cpp index 9e55cd2be18592..4fca252e13ea9a 100644 --- a/src/inference/src/dev/threading/cpu_streams_executor.cpp +++ b/src/inference/src/dev/threading/cpu_streams_executor.cpp @@ -313,6 +313,21 @@ struct CPUStreamsExecutor::Impl { } } + bool find_thread_id() { + auto id = std::this_thread::get_id(); + auto search = _thread_ids.find(id); + if (search != _thread_ids.end()) { + return true; + } + std::lock_guard guard(_stream_map_mutex); + for (auto& item : _stream_map) { + if (item.first->get_id() == id) { + return true; + } + } + return false; + } + private: std::set _thread_ids; Impl* _impl; @@ -445,6 +460,9 @@ struct CPUStreamsExecutor::Impl { }; int CPUStreamsExecutor::get_stream_id() { + if (!_impl->_streams.find_thread_id()) { + return 0; + } auto stream = _impl->_streams.local(); return stream->_streamId; } @@ -454,11 +472,17 @@ int CPUStreamsExecutor::get_streams_num() { } int CPUStreamsExecutor::get_numa_node_id() { + if (!_impl->_streams.find_thread_id()) { + return 0; + } auto stream = _impl->_streams.local(); return stream->_numaNodeId; } int CPUStreamsExecutor::get_socket_id() { + if (!_impl->_streams.find_thread_id()) { + return 0; + } auto stream = _impl->_streams.local(); return stream->_socketId; }