From 9cca05def8b1ae7d8db15302aa7d910ff4f58bb8 Mon Sep 17 00:00:00 2001 From: Sun Xiaoxia Date: Mon, 4 Dec 2023 13:52:52 +0800 Subject: [PATCH] Only use current thread with TBB when -nstreams=0 (#20975) * only use current thread when -nstreams=0 with TBB * add comments * fix building issue * fix comments * only use current thread when -nstreams=0 with TBB * add comments * fix building issue * fix comments --- .../runtime/threading/istreams_executor.hpp | 5 +++++ .../src/dev/threading/cpu_streams_executor.cpp | 5 ++++- .../src/dev/threading/istreams_executor.cpp | 17 +++++++++++++++++ src/plugins/intel_cpu/src/compiled_model.cpp | 2 +- src/plugins/intel_cpu/src/plugin.cpp | 2 ++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp b/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp index 66f34be0bd6..363b7a912b1 100644 --- a/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp @@ -194,6 +194,11 @@ public: int threads_per_stream, PreferredCoreType core_type, bool cpu_pinning); + /** + * @brief Set _streams_info_table and _cpu_reservation in cpu streams executor config when nstreams = 0, + * that is, only create one thread with TBB + */ + void set_config_zero_stream(); }; /** diff --git a/src/inference/src/dev/threading/cpu_streams_executor.cpp b/src/inference/src/dev/threading/cpu_streams_executor.cpp index 8068359ad93..0a4719854ab 100644 --- a/src/inference/src/dev/threading/cpu_streams_executor.cpp +++ b/src/inference/src/dev/threading/cpu_streams_executor.cpp @@ -186,7 +186,10 @@ struct CPUStreamsExecutor::Impl { int max_threads_per_core; StreamCreateType stream_type; const auto org_proc_type_table = get_org_proc_type_table(); - const auto stream_id = _streamId >= _impl->_config._streams ? _impl->_config._streams - 1 : _streamId; + const auto stream_id = + _impl->_config._streams == 0 + ? 0 + : (_streamId >= _impl->_config._streams ? _impl->_config._streams - 1 : _streamId); get_cur_stream_info(stream_id, _impl->_config._cpu_reservation, diff --git a/src/inference/src/dev/threading/istreams_executor.cpp b/src/inference/src/dev/threading/istreams_executor.cpp index 4c7dc2c2ede..e77a9256c6f 100644 --- a/src/inference/src/dev/threading/istreams_executor.cpp +++ b/src/inference/src/dev/threading/istreams_executor.cpp @@ -659,5 +659,22 @@ void IStreamsExecutor::Config::update_executor_config(int stream_nums, } } +void IStreamsExecutor::Config::set_config_zero_stream() { + std::vector> proc_type_table = get_proc_type_table(); + int core_type = MAIN_CORE_PROC; + int numa_id = 0; + int socket_id = 0; + + if (proc_type_table.size() > 0) { + core_type = proc_type_table[0][MAIN_CORE_PROC] > 0 + ? MAIN_CORE_PROC + : (proc_type_table[0][EFFICIENT_CORE_PROC] > 0 ? EFFICIENT_CORE_PROC : HYPER_THREADING_PROC); + numa_id = std::max(0, proc_type_table[0][PROC_NUMA_NODE_ID]); + socket_id = std::max(0, proc_type_table[0][PROC_SOCKET_ID]); + } + _streams_info_table.push_back({1, core_type, 1, numa_id, socket_id}); + _cpu_reservation = false; +} + } // namespace threading } // namespace ov diff --git a/src/plugins/intel_cpu/src/compiled_model.cpp b/src/plugins/intel_cpu/src/compiled_model.cpp index 8b33f6ca75f..c19bee36c5d 100644 --- a/src/plugins/intel_cpu/src/compiled_model.cpp +++ b/src/plugins/intel_cpu/src/compiled_model.cpp @@ -247,7 +247,7 @@ ov::Any CompiledModel::get_property(const std::string& name) const { } else if (name == ov::optimal_number_of_infer_requests) { const auto streams = config.streamExecutorConfig._streams; return decltype(ov::optimal_number_of_infer_requests)::value_type( - streams); // ov::optimal_number_of_infer_requests has no negative values + streams > 0 ? streams : 1); // ov::optimal_number_of_infer_requests has no negative values } else if (name == ov::num_streams) { const auto streams = config.streamExecutorConfig._streams; return decltype(ov::num_streams)::value_type( diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp index bf58d77a25e..03bd79e28c8 100644 --- a/src/plugins/intel_cpu/src/plugin.cpp +++ b/src/plugins/intel_cpu/src/plugin.cpp @@ -330,6 +330,8 @@ void Engine::get_performance_streams(Config& config, const std::shared_ptr