From 34a6dce9bfa8edb5c6c4e39267b4bb1fa4b529b1 Mon Sep 17 00:00:00 2001 From: Alexander Nesterov Date: Mon, 16 Oct 2023 13:02:47 +0200 Subject: [PATCH] new version of enabling scheduler --- .../nodes/executors/acl/acl_ie_scheduler.hpp | 11 ++++++ src/plugins/intel_cpu/src/plugin.cpp | 34 ++----------------- src/plugins/intel_cpu/src/plugin.h | 14 -------- 3 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp index 1148f4ad5edd69..96d249a9db8794 100644 --- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp +++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp @@ -27,5 +27,16 @@ class ACLScheduler final : public IScheduler { private: void schedule_custom(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors); }; + +static std::mutex & get_mtx_acl() { + static std::mutex mtx_acl; + return mtx_acl; +} + +static std::shared_ptr & get_acl_scheduler() { + static std::shared_ptr acl_scheduler = std::make_shared(); + return acl_scheduler; +} + } // namespace intel_cpu } // namespace ov diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp index 96be8734ec0dce..4ab50e19567284 100644 --- a/src/plugins/intel_cpu/src/plugin.cpp +++ b/src/plugins/intel_cpu/src/plugin.cpp @@ -40,7 +40,6 @@ #if defined(OV_CPU_WITH_ACL) #include "nodes/executors/acl/acl_ie_scheduler.hpp" -#include "arm_compute/runtime/CPP/CPPScheduler.h" #endif using namespace InferenceEngine; @@ -142,43 +141,14 @@ class CPUSpecialSetup { }; #endif // __linux__ -#if defined(OV_CPU_WITH_ACL) -std::mutex Engine::SchedulerGuard::mutex; -std::weak_ptr Engine::SchedulerGuard::ptr; - -Engine::SchedulerGuard::SchedulerGuard() { -#if IE_THREAD == IE_THREAD_SEQ - // To save state for ACL cores in single-thread mode - arm_compute::Scheduler::set(arm_compute::Scheduler::Type::ST); -#else - arm_compute::Scheduler::set(std::make_shared()); -#endif -} - -std::shared_ptr Engine::SchedulerGuard::instance() { - std::lock_guard lock{SchedulerGuard::mutex}; - auto scheduler_guard_ptr = SchedulerGuard::ptr.lock(); - if (scheduler_guard_ptr == nullptr) { - SchedulerGuard::ptr = scheduler_guard_ptr = std::make_shared(); - } - return scheduler_guard_ptr; -} - -Engine::SchedulerGuard::~SchedulerGuard() { - // To save the state of scheduler after ACLScheduler has been executed - // TODO: find out the cause of the state - std::lock_guard lock{this->dest_mutex}; - arm_compute::Scheduler::set(arm_compute::Scheduler::Type::ST); -} -#endif - Engine::Engine() : deviceFullName(getDeviceFullName()), specialSetup(new CPUSpecialSetup) { _pluginName = "CPU"; extensionManager->AddExtension(std::make_shared()); #if defined(OV_CPU_WITH_ACL) - scheduler_guard = SchedulerGuard::instance(); + std::lock_guard _lock {get_mtx_acl()}; + arm_compute::Scheduler::set(get_acl_scheduler()); #endif } diff --git a/src/plugins/intel_cpu/src/plugin.h b/src/plugins/intel_cpu/src/plugin.h index 3e9d616dcec02c..20c6d315a2c623 100644 --- a/src/plugins/intel_cpu/src/plugin.h +++ b/src/plugins/intel_cpu/src/plugin.h @@ -63,20 +63,6 @@ class Engine : public InferenceEngine::IInferencePlugin { const std::string deviceFullName; std::shared_ptr specialSetup; - -#if defined(OV_CPU_WITH_ACL) - struct SchedulerGuard { - SchedulerGuard(); - ~SchedulerGuard(); - static std::shared_ptr instance(); - static std::mutex mutex; - // separate mutex for saving ACLScheduler state in destructor - mutable std::mutex dest_mutex; - static std::weak_ptr ptr; - }; - - std::shared_ptr scheduler_guard; -#endif }; } // namespace intel_cpu