Remove setTBBFlag API

This commit is contained in:
Ilya Churaev 2023-02-22 10:38:36 +04:00
parent ab20e58930
commit 847ec39222
6 changed files with 68 additions and 44 deletions

View File

@ -33,10 +33,31 @@ public:
*/
virtual InferenceEngine::ITaskExecutor::Ptr get_executor(const std::string& id) = 0;
/// @private
/**
* @brief Returns idle cpu streams executor
*
* @param config Streams executor config
*
* @return pointer to streams executor config
*/
virtual InferenceEngine::IStreamsExecutor::Ptr get_idle_cpu_streams_executor(
const InferenceEngine::IStreamsExecutor::Config& config) = 0;
/**
* @brief Allows to configure executor manager
*
* @param properties map with configuration
*/
virtual void set_property(const ov::AnyMap& properties) = 0;
/**
* @brief Returns configuration
*
* @param name property name
*
* @return Property value
*/
virtual ov::Any get_property(const std::string& name) const = 0;
/**
* @cond
*/
@ -48,18 +69,7 @@ public:
/**
* @endcond
*/
virtual ~ExecutorManager() = default;
/**
* @brief Set TBB terminate flag
* @param flag A boolean value:
* True to terminate tbb during destruction
* False to not terminate tbb during destruction
* @return void
*/
virtual void set_tbb_flag(bool flag) = 0;
virtual bool get_tbb_flag() = 0;
};
OPENVINO_API std::shared_ptr<ExecutorManager> executor_manager();

View File

@ -216,10 +216,10 @@ public:
}
void setTbbFlag(bool flag) override {
m_manager->set_tbb_flag(flag);
m_manager->set_property({{ov::force_tbb_terminate.name(), flag}});
}
bool getTbbFlag() override {
return m_manager->get_tbb_flag();
return m_manager->get_property(ov::force_tbb_terminate.name()).as<bool>();
}
};

View File

@ -28,6 +28,7 @@
#include "openvino/pass/manager.hpp"
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/remote_context.hpp"
#include "openvino/runtime/threading/executor_manager.hpp"
#include "openvino/util/common_util.hpp"
#include "openvino/util/shared_object.hpp"
#include "preprocessing/preprocessing.hpp"
@ -57,7 +58,7 @@ void stripDeviceName(std::string& device, const std::string& substr) {
ov::CoreImpl::CoreImpl(bool _newAPI) : m_new_api(_newAPI) {
add_mutex(""); // Register global mutex
executorManagerPtr = InferenceEngine::executorManager();
m_executor_manager = ov::executor_manager();
for (const auto& it : ov::get_available_opsets()) {
opsetNames.insert(it.first);
}
@ -632,7 +633,7 @@ void ov::CoreImpl::set_property(const std::string& device_name, const AnyMap& pr
ov::Any ov::CoreImpl::get_property_for_core(const std::string& name) const {
if (name == ov::force_tbb_terminate.name()) {
const auto flag = InferenceEngine::executorManager()->getTbbFlag();
const auto flag = ov::executor_manager()->get_property(name).as<bool>();
return decltype(ov::force_tbb_terminate)::value_type(flag);
} else if (name == ov::cache_dir.name()) {
return ov::Any(coreConfig.get_cache_dir());
@ -993,7 +994,7 @@ void ov::CoreImpl::CoreConfig::set_and_update(ov::AnyMap& config) {
it = config.find(ov::force_tbb_terminate.name());
if (it != config.end()) {
auto flag = it->second.as<std::string>() == CONFIG_VALUE(YES) ? true : false;
InferenceEngine::executorManager()->setTbbFlag(flag);
ov::executor_manager()->set_property({{it->first, flag}});
config.erase(it);
}

View File

@ -21,7 +21,7 @@
#include "openvino/core/version.hpp"
#include "openvino/runtime/common.hpp"
#include "openvino/runtime/icompiled_model.hpp"
#include "threading/ie_executor_manager.hpp"
#include "openvino/runtime/threading/executor_manager.hpp"
#ifdef OPENVINO_STATIC_LIBRARY
# include "ie_plugins.hpp"
@ -162,7 +162,7 @@ private:
}
};
InferenceEngine::ExecutorManager::Ptr executorManagerPtr;
std::shared_ptr<ov::ExecutorManager> m_executor_manager;
mutable std::unordered_set<std::string> opsetNames;
// TODO: make extensions to be optional with conditional compilation
mutable std::vector<InferenceEngine::IExtensionPtr> extensions;

View File

@ -42,11 +42,16 @@ public:
return m_manager->clear(id);
}
void set_tbb_flag(bool flag) override {
m_manager->setTbbFlag(flag);
void set_property(const ov::AnyMap& property) override {
for (const auto& it : property) {
if (it.first == ov::force_tbb_terminate.name())
m_manager->setTbbFlag(it.second.as<bool>());
}
}
bool get_tbb_flag() override {
return m_manager->getTbbFlag();
ov::Any get_property(const std::string& name) const override {
if (name == ov::force_tbb_terminate.name())
return m_manager->getTbbFlag();
OPENVINO_UNREACHABLE("Cannot find property ", name);
}
};

View File

@ -5,6 +5,7 @@
#include "openvino/runtime/threading/executor_manager.hpp"
#include "openvino/core/parallel.hpp"
#include "openvino/runtime/properties.hpp"
#include "threading/ie_cpu_streams_executor.hpp"
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
# if (TBB_INTERFACE_VERSION < 12000)
@ -30,18 +31,19 @@ public:
size_t get_executors_number() const override;
size_t get_idle_cpu_streams_executors_number() const override;
void clear(const std::string& id = {}) override;
void set_tbb_flag(bool flag) override;
bool get_tbb_flag() override;
void set_property(const ov::AnyMap& properties) override;
ov::Any get_property(const std::string& name) const override;
private:
void reset_tbb();
std::unordered_map<std::string, InferenceEngine::ITaskExecutor::Ptr> executors;
std::vector<std::pair<InferenceEngine::IStreamsExecutor::Config, InferenceEngine::IStreamsExecutor::Ptr>>
cpuStreamsExecutors;
mutable std::mutex streamExecutorMutex;
mutable std::mutex taskExecutorMutex;
bool tbbTerminateFlag = false;
mutable std::mutex tbbMutex;
mutable std::mutex global_mutex;
bool tbbThreadsCreated = false;
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
# if (TBB_INTERFACE_VERSION < 12000)
@ -58,34 +60,40 @@ ExecutorManagerImpl::~ExecutorManagerImpl() {
reset_tbb();
}
void ExecutorManagerImpl::set_tbb_flag(bool flag) {
std::lock_guard<std::mutex> guard(tbbMutex);
tbbTerminateFlag = flag;
void ExecutorManagerImpl::set_property(const ov::AnyMap& properties) {
std::lock_guard<std::mutex> guard(global_mutex);
for (const auto& it : properties) {
if (it.first == ov::force_tbb_terminate.name()) {
tbbTerminateFlag = it.second.as<bool>();
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
if (tbbTerminateFlag) {
if (!tbbTaskScheduler) {
if (tbbTerminateFlag) {
if (!tbbTaskScheduler) {
# if (TBB_INTERFACE_VERSION < 12000)
tbbTaskScheduler = std::make_shared<tbb::task_scheduler_init>();
tbbTaskScheduler = std::make_shared<tbb::task_scheduler_init>();
# elif (TBB_INTERFACE_VERSION < 12060)
tbbTaskScheduler =
std::make_shared<oneapi::tbb::task_scheduler_handle>(oneapi::tbb::task_scheduler_handle::get());
tbbTaskScheduler =
std::make_shared<oneapi::tbb::task_scheduler_handle>(oneapi::tbb::task_scheduler_handle::get());
# else
tbbTaskScheduler = std::make_shared<oneapi::tbb::task_scheduler_handle>(tbb::attach{});
tbbTaskScheduler = std::make_shared<oneapi::tbb::task_scheduler_handle>(tbb::attach{});
# endif
}
} else {
tbbTaskScheduler = nullptr;
}
}
} else {
tbbTaskScheduler = nullptr;
}
#endif
}
}
}
bool ExecutorManagerImpl::get_tbb_flag() {
std::lock_guard<std::mutex> guard(tbbMutex);
return tbbTerminateFlag;
ov::Any ExecutorManagerImpl::get_property(const std::string& name) const {
std::lock_guard<std::mutex> guard(global_mutex);
if (name == ov::force_tbb_terminate.name()) {
return tbbTerminateFlag;
}
OPENVINO_UNREACHABLE("Property ", name, " is not supported.");
}
void ExecutorManagerImpl::reset_tbb() {
std::lock_guard<std::mutex> guard(tbbMutex);
std::lock_guard<std::mutex> guard(global_mutex);
if (tbbTerminateFlag) {
#if OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO
if (tbbTaskScheduler && tbbThreadsCreated) {