Skip to content

Commit

Permalink
Fix creating too many useless threads in cpu executor (openvinotoolki…
Browse files Browse the repository at this point in the history
…t#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 <[email protected]>
  • Loading branch information
sunxiaoxia2022 and wangleis authored Aug 21, 2024
1 parent b37ed44 commit 52f6fe7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/inference/src/dev/threading/cpu_streams_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> guard(_stream_map_mutex);
for (auto& item : _stream_map) {
if (item.first->get_id() == id) {
return true;
}
}
return false;
}

private:
std::set<std::thread::id> _thread_ids;
Impl* _impl;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 52f6fe7

Please sign in to comment.