Skip to content

Commit

Permalink
new version of enabling scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
allnes committed Oct 16, 2023
1 parent 44ac909 commit 34a6dce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 46 deletions.
11 changes: 11 additions & 0 deletions src/plugins/intel_cpu/src/nodes/executors/acl/acl_ie_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ov::intel_cpu::ACLScheduler> & get_acl_scheduler() {
static std::shared_ptr<ACLScheduler> acl_scheduler = std::make_shared<ACLScheduler>();
return acl_scheduler;
}

} // namespace intel_cpu
} // namespace ov
34 changes: 2 additions & 32 deletions src/plugins/intel_cpu/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -142,43 +141,14 @@ class CPUSpecialSetup {
};
#endif // __linux__

#if defined(OV_CPU_WITH_ACL)
std::mutex Engine::SchedulerGuard::mutex;
std::weak_ptr<Engine::SchedulerGuard> 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<ACLScheduler>());
#endif
}

std::shared_ptr<Engine::SchedulerGuard> Engine::SchedulerGuard::instance() {
std::lock_guard<std::mutex> lock{SchedulerGuard::mutex};
auto scheduler_guard_ptr = SchedulerGuard::ptr.lock();
if (scheduler_guard_ptr == nullptr) {
SchedulerGuard::ptr = scheduler_guard_ptr = std::make_shared<SchedulerGuard>();
}
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<std::mutex> 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<Extension>());
#if defined(OV_CPU_WITH_ACL)
scheduler_guard = SchedulerGuard::instance();
std::lock_guard<std::mutex> _lock {get_mtx_acl()};
arm_compute::Scheduler::set(get_acl_scheduler());
#endif
}

Expand Down
14 changes: 0 additions & 14 deletions src/plugins/intel_cpu/src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@ class Engine : public InferenceEngine::IInferencePlugin {
const std::string deviceFullName;

std::shared_ptr<void> specialSetup;

#if defined(OV_CPU_WITH_ACL)
struct SchedulerGuard {
SchedulerGuard();
~SchedulerGuard();
static std::shared_ptr<SchedulerGuard> instance();
static std::mutex mutex;
// separate mutex for saving ACLScheduler state in destructor
mutable std::mutex dest_mutex;
static std::weak_ptr<SchedulerGuard> ptr;
};

std::shared_ptr<SchedulerGuard> scheduler_guard;
#endif
};

} // namespace intel_cpu
Expand Down

0 comments on commit 34a6dce

Please sign in to comment.