From b7edd5df69ebfd8565efa4f62d89ac8f4816b3f9 Mon Sep 17 00:00:00 2001 From: Sun Xiaoxia Date: Fri, 24 Nov 2023 14:52:44 +0800 Subject: [PATCH] migrate threading related interface from API 1.0 to 2.0 (#21167) * migrate threading related interface from API 1.0 to 2.0 * fix code style * fix @ref issue in doc * change <> to quotation marks * restore threading related interface API 1.0 * restore the changes of legacy code --- docs/snippets/example_itask_executor.cpp | 11 +++++---- .../threading/cpu_streams_executor.hpp | 5 ++++ .../runtime/threading/immediate_executor.hpp | 7 +++++- .../runtime/threading/istreams_executor.hpp | 5 ++++ .../runtime/threading/itask_executor.hpp | 5 ++++ .../src/dev/threading/istreams_executor.cpp | 2 +- src/inference/src/ie_core.cpp | 4 ++-- .../tests/functional/task_executor_tests.cpp | 23 ++++++++++--------- src/plugins/auto/src/plugin.cpp | 1 - src/plugins/intel_cpu/src/compiled_model.cpp | 4 ++-- src/plugins/intel_cpu/src/plugin.cpp | 1 - .../intel_gna/src/gna_executable_network.hpp | 1 - .../tests/deprecated/helpers/tests_common.cpp | 6 ++--- .../include/behavior/infer_request/config.hpp | 22 +++++++++--------- 14 files changed, 59 insertions(+), 38 deletions(-) diff --git a/docs/snippets/example_itask_executor.cpp b/docs/snippets/example_itask_executor.cpp index 08adef43871..e951917249f 100644 --- a/docs/snippets/example_itask_executor.cpp +++ b/docs/snippets/example_itask_executor.cpp @@ -6,16 +6,16 @@ # define IN_OV_COMPONENT # define WAS_OV_LIBRARY_DEFINED #endif -#include +#include "openvino/runtime/threading/cpu_streams_executor.hpp" #ifdef WAS_OV_LIBRARY_DEFINED # undef IN_OV_COMPONENT # undef WAS_OV_LIBRARY_DEFINED #endif -#include #include #include +#include void example1() { // ! [itask_executor:define_pipeline] @@ -24,9 +24,12 @@ void example1() { // When the promise is created we can get std::future to wait the result auto future = promise->get_future(); // Rather simple task - InferenceEngine::Task task = [] {std::cout << "Some Output" << std::endl; }; + ov::threading::Task task = [] { + std::cout << "Some Output" << std::endl; + }; // Create an executor - InferenceEngine::ITaskExecutor::Ptr taskExecutor = std::make_shared(); + ov::threading::ITaskExecutor::Ptr taskExecutor = + std::make_shared(ov::threading::IStreamsExecutor::Config{}); if (taskExecutor == nullptr) { // ProcessError(e); return; diff --git a/src/inference/dev_api/openvino/runtime/threading/cpu_streams_executor.hpp b/src/inference/dev_api/openvino/runtime/threading/cpu_streams_executor.hpp index 0faf37fc6cf..998dc401af9 100644 --- a/src/inference/dev_api/openvino/runtime/threading/cpu_streams_executor.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/cpu_streams_executor.hpp @@ -27,6 +27,11 @@ namespace threading { */ class OPENVINO_RUNTIME_API CPUStreamsExecutor : public IStreamsExecutor { public: + /** + * @brief A shared pointer to a CPUStreamsExecutor object + */ + using Ptr = std::shared_ptr; + /** * @brief Constructor * @param config Stream executor parameters diff --git a/src/inference/dev_api/openvino/runtime/threading/immediate_executor.hpp b/src/inference/dev_api/openvino/runtime/threading/immediate_executor.hpp index 01d48c6bf07..fe21d66f210 100644 --- a/src/inference/dev_api/openvino/runtime/threading/immediate_executor.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/immediate_executor.hpp @@ -12,7 +12,7 @@ #include #include -#include "threading/ie_itask_executor.hpp" +#include "openvino/runtime/threading/itask_executor.hpp" namespace ov { namespace threading { @@ -23,6 +23,11 @@ namespace threading { */ class ImmediateExecutor : public ITaskExecutor { public: + /** + * @brief A shared pointer to a ImmediateExecutor object + */ + using Ptr = std::shared_ptr; + /** * @brief Destroys the object. */ 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 738377ddce4..784196f311c 100644 --- a/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/istreams_executor.hpp @@ -32,6 +32,11 @@ namespace threading { */ class OPENVINO_RUNTIME_API IStreamsExecutor : virtual public ITaskExecutor { public: + /** + * A shared pointer to IStreamsExecutor interface + */ + using Ptr = std::shared_ptr; + /** * @brief Defines inference thread binding type */ diff --git a/src/inference/dev_api/openvino/runtime/threading/itask_executor.hpp b/src/inference/dev_api/openvino/runtime/threading/itask_executor.hpp index 3cb42e3200b..527f417a8b0 100644 --- a/src/inference/dev_api/openvino/runtime/threading/itask_executor.hpp +++ b/src/inference/dev_api/openvino/runtime/threading/itask_executor.hpp @@ -46,6 +46,11 @@ run tasks in current thread. */ class OPENVINO_RUNTIME_API ITaskExecutor { public: + /** + * A shared pointer to ITaskExecutor interface + */ + using Ptr = std::shared_ptr; + /** * @brief Destroys the object. */ diff --git a/src/inference/src/dev/threading/istreams_executor.cpp b/src/inference/src/dev/threading/istreams_executor.cpp index f19833921ce..4c7dc2c2ede 100644 --- a/src/inference/src/dev/threading/istreams_executor.cpp +++ b/src/inference/src/dev/threading/istreams_executor.cpp @@ -16,7 +16,7 @@ #include "openvino/runtime/properties.hpp" #include "openvino/runtime/threading/cpu_streams_info.hpp" #include "openvino/util/log.hpp" -#include "threading/ie_parallel_custom_arena.hpp" +#include "parallel_custom_arena.hpp" namespace ov { namespace threading { diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index a5babd91927..5da90bde36e 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "any_copy.hpp" @@ -38,6 +37,7 @@ #include "openvino/runtime/compiled_model.hpp" #include "openvino/runtime/core.hpp" #include "openvino/runtime/device_id_parser.hpp" +#include "openvino/runtime/threading/executor_manager.hpp" #include "openvino/util/common_util.hpp" #include "openvino/util/file_util.hpp" #include "openvino/util/shared_object.hpp" @@ -391,7 +391,7 @@ Parameter Core::GetConfig(const std::string& deviceName, const std::string& name } if (name == CONFIG_KEY(FORCE_TBB_TERMINATE)) { - const auto flag = executorManager()->getTbbFlag(); + const auto flag = ov::threading::executor_manager()->get_property(ov::force_tbb_terminate.name()).as(); return flag ? CONFIG_VALUE(YES) : CONFIG_VALUE(NO); } diff --git a/src/inference/tests/functional/task_executor_tests.cpp b/src/inference/tests/functional/task_executor_tests.cpp index 5e7e712b46e..0d239685549 100644 --- a/src/inference/tests/functional/task_executor_tests.cpp +++ b/src/inference/tests/functional/task_executor_tests.cpp @@ -8,13 +8,14 @@ #include #include #include -#include -#include + +#include "openvino/runtime/threading/cpu_streams_executor.hpp" +#include "openvino/runtime/threading/immediate_executor.hpp" using namespace ::testing; using namespace std; -using namespace InferenceEngine; -using namespace InferenceEngine::details; +using namespace ov; +using namespace threading; static constexpr const auto MAX_NUMBER_OF_TASKS_IN_QUEUE = 10; @@ -210,7 +211,7 @@ TEST_P(ASyncTaskExecutorTests, runAndWaitDoesNotOwnTasks) { useCount = sharedCounter.use_count(); }}; sharedCounter.reset(); - taskExecutor->runAndWait(tasks); + taskExecutor->run_and_wait(tasks); ASSERT_EQ(1, useCount); } @@ -218,7 +219,7 @@ class StreamsExecutorConfigTest : public ::testing::Test {}; static auto Executors = ::testing::Values( [] { - auto streams = getNumberOfCPUCores(); + auto streams = get_number_of_cpu_cores(); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", @@ -227,7 +228,7 @@ static auto Executors = ::testing::Values( IStreamsExecutor::ThreadBindingType::NONE}); }, [] { - auto streams = getNumberOfLogicalCPUCores(true); + auto streams = get_number_of_logical_cpu_cores(true); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", @@ -236,7 +237,7 @@ static auto Executors = ::testing::Values( IStreamsExecutor::ThreadBindingType::NONE}); }, [] { - auto streams = getNumberOfLogicalCPUCores(false); + auto streams = get_number_of_logical_cpu_cores(false); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", @@ -252,7 +253,7 @@ INSTANTIATE_TEST_SUITE_P(TaskExecutorTests, TaskExecutorTests, Executors); static auto AsyncExecutors = ::testing::Values( [] { - auto streams = getNumberOfCPUCores(); + auto streams = get_number_of_cpu_cores(); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", @@ -261,7 +262,7 @@ static auto AsyncExecutors = ::testing::Values( IStreamsExecutor::ThreadBindingType::NONE}); }, [] { - auto streams = getNumberOfLogicalCPUCores(true); + auto streams = get_number_of_logical_cpu_cores(true); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", @@ -270,7 +271,7 @@ static auto AsyncExecutors = ::testing::Values( IStreamsExecutor::ThreadBindingType::NONE}); }, [] { - auto streams = getNumberOfLogicalCPUCores(false); + auto streams = get_number_of_logical_cpu_cores(false); auto threads = parallel_get_max_threads(); return std::make_shared( IStreamsExecutor::Config{"TestCPUStreamsExecutor", diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp index 8e5131b7a3c..658058b0b5f 100644 --- a/src/plugins/auto/src/plugin.cpp +++ b/src/plugins/auto/src/plugin.cpp @@ -13,7 +13,6 @@ #include #include -#include #include "openvino/runtime/auto/properties.hpp" #include "openvino/runtime/device_id_parser.hpp" #include "openvino/runtime/internal_properties.hpp" diff --git a/src/plugins/intel_cpu/src/compiled_model.cpp b/src/plugins/intel_cpu/src/compiled_model.cpp index fa6a55a0e05..cc863d841c9 100644 --- a/src/plugins/intel_cpu/src/compiled_model.cpp +++ b/src/plugins/intel_cpu/src/compiled_model.cpp @@ -13,7 +13,7 @@ #include "openvino/core/type/element_type.hpp" #include "openvino/runtime/intel_cpu/properties.hpp" #include "serialize.h" -#include "threading/ie_executor_manager.hpp" +#include "openvino/runtime/threading/executor_manager.hpp" #include "transformations/transformation_pipeline.h" #define FIX_62820 0 #if FIX_62820 && ((IE_THREAD == IE_THREAD_TBB) || (IE_THREAD == IE_THREAD_TBB_AUTO)) @@ -22,7 +22,7 @@ #include "openvino/runtime/properties.hpp" #include "openvino/util/common_util.hpp" -#include "threading/ie_cpu_streams_executor.hpp" +#include "openvino/runtime/threading/cpu_streams_executor.hpp" #include "transformations/utils/utils.hpp" #include diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp index 72de4a5dcd2..6dcff628398 100644 --- a/src/plugins/intel_cpu/src/plugin.cpp +++ b/src/plugins/intel_cpu/src/plugin.cpp @@ -21,7 +21,6 @@ #include "openvino/runtime/threading/executor_manager.hpp" #include "performance_heuristics.hpp" #include "serialize.h" -#include "threading/ie_executor_manager.hpp" #include "transformations/transformation_pipeline.h" #include "transformations/utils/utils.hpp" #include "utils/denormals.hpp" diff --git a/src/plugins/intel_gna/src/gna_executable_network.hpp b/src/plugins/intel_gna/src/gna_executable_network.hpp index bb14f9d4f0e..e6f1c6d1e43 100644 --- a/src/plugins/intel_gna/src/gna_executable_network.hpp +++ b/src/plugins/intel_gna/src/gna_executable_network.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "gna_infer_request.hpp" diff --git a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp index 97a7f47faf8..d82114d26d7 100644 --- a/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp +++ b/src/plugins/intel_gna/tests/deprecated/helpers/tests_common.cpp @@ -7,7 +7,7 @@ #include #include "tests_common.hpp" -#include +#include "openvino/runtime/threading/executor_manager.hpp" #ifdef _WIN32 # ifndef NOMINMAX @@ -65,11 +65,11 @@ void TestsCommon::SetUp() { if (memsize != 0) { std::cout << "\nMEM_USAGE=" << getVmSizeInKB() << "KB\n"; } - InferenceEngine::executorManager()->clear(); + ov::threading::executor_manager()->clear(); } void TestsCommon::TearDown() { - InferenceEngine::executorManager()->clear(); + ov::threading::executor_manager()->clear(); } /** diff --git a/src/tests/functional/plugin/shared/include/behavior/infer_request/config.hpp b/src/tests/functional/plugin/shared/include/behavior/infer_request/config.hpp index 6a0c90e944c..4cbe7c180dc 100644 --- a/src/tests/functional/plugin/shared/include/behavior/infer_request/config.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/infer_request/config.hpp @@ -4,7 +4,7 @@ #pragma once -#include "threading/ie_executor_manager.hpp" +#include "openvino/runtime/threading/executor_manager.hpp" #include "base/behavior_test_utils.hpp" @@ -79,30 +79,30 @@ protected: }; TEST_P(InferRequestConfigTest, canSetExclusiveAsyncRequests) { - ASSERT_EQ(0ul, InferenceEngine::executorManager()->getExecutorsNumber()); + ASSERT_EQ(0ul, ov::threading::executor_manager()->get_executors_number()); ASSERT_NO_THROW(createInferRequestWithConfig()); if (target_device.find(ov::test::utils::DEVICE_AUTO) == std::string::npos && target_device.find(ov::test::utils::DEVICE_MULTI) == std::string::npos && target_device.find(ov::test::utils::DEVICE_HETERO) == std::string::npos && target_device.find(ov::test::utils::DEVICE_BATCH) == std::string::npos) { - ASSERT_EQ(streamExecutorNumber, InferenceEngine::executorManager()->getExecutorsNumber()); + ASSERT_EQ(streamExecutorNumber, ov::threading::executor_manager()->get_executors_number()); } } TEST_P(InferRequestConfigTest, withoutExclusiveAsyncRequests) { - ASSERT_EQ(0u, InferenceEngine::executorManager()->getExecutorsNumber()); + ASSERT_EQ(0u, ov::threading::executor_manager()->get_executors_number()); ASSERT_NO_THROW(createInferRequestWithConfig()); if (target_device.find(ov::test::utils::DEVICE_AUTO) == std::string::npos && target_device.find(ov::test::utils::DEVICE_MULTI) == std::string::npos && target_device.find(ov::test::utils::DEVICE_HETERO) == std::string::npos && target_device.find(ov::test::utils::DEVICE_BATCH) == std::string::npos) { - ASSERT_EQ(streamExecutorNumber, InferenceEngine::executorManager()->getExecutorsNumber()); + ASSERT_EQ(streamExecutorNumber, ov::threading::executor_manager()->get_executors_number()); } } TEST_P(InferRequestConfigTest, ReusableCPUStreamsExecutor) { - ASSERT_EQ(0u, InferenceEngine::executorManager()->getExecutorsNumber()); - ASSERT_EQ(0u, InferenceEngine::executorManager()->getIdleCPUStreamsExecutorsNumber()); + ASSERT_EQ(0u, ov::threading::executor_manager()->get_executors_number()); + ASSERT_EQ(0u, ov::threading::executor_manager()->get_idle_cpu_streams_executors_number()); { // Load config @@ -118,13 +118,13 @@ TEST_P(InferRequestConfigTest, ReusableCPUStreamsExecutor) { execNet = ie->LoadNetwork(cnnNet, target_device, config); execNet.CreateInferRequest(); if (target_device == ov::test::utils::DEVICE_KEEMBAY) { - ASSERT_EQ(1u, InferenceEngine::executorManager()->getExecutorsNumber()); - ASSERT_EQ(0u, InferenceEngine::executorManager()->getIdleCPUStreamsExecutorsNumber()); + ASSERT_EQ(1u, ov::threading::executor_manager()->get_executors_number()); + ASSERT_EQ(0u, ov::threading::executor_manager()->get_idle_cpu_streams_executors_number()); } else if ((target_device == ov::test::utils::DEVICE_AUTO) || (target_device == ov::test::utils::DEVICE_MULTI)) { } else { - ASSERT_EQ(0u, InferenceEngine::executorManager()->getExecutorsNumber()); - ASSERT_GE(2u, InferenceEngine::executorManager()->getIdleCPUStreamsExecutorsNumber()); + ASSERT_EQ(0u, ov::threading::executor_manager()->get_executors_number()); + ASSERT_GE(2u, ov::threading::executor_manager()->get_idle_cpu_streams_executors_number()); } } }