Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUTO] Fix the timing issue in AUTO inference #27290

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b6adcd
update.
yangwang201911 Oct 15, 2024
15f9def
enable sync for handling worker infer requests.
yangwang201911 Oct 28, 2024
e9c7d04
update.
yangwang201911 Oct 29, 2024
7822ef5
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
yangwang201911 Oct 30, 2024
eb727a4
update.
yangwang201911 Nov 12, 2024
fdc866b
update.
yangwang201911 Nov 12, 2024
02f8570
Merge branch 'master' into ywang2/fix_the_timing_issue
yangwang201911 Nov 12, 2024
3507dfe
update.
yangwang201911 Nov 12, 2024
a510c17
Merge branch 'master' into ywang2/fix_the_timing_issue
yangwang201911 Nov 13, 2024
47d40e1
update.
yangwang201911 Nov 14, 2024
47bedb4
Merge branch 'master' into ywang2/fix_the_timing_issue
peterchen-intel Dec 3, 2024
81f346c
remove the condition variable control and increase the number of work…
yangwang201911 Dec 4, 2024
976aa47
update.
yangwang201911 Dec 4, 2024
2ef471a
update.
yangwang201911 Dec 4, 2024
88eaf5a
Merge branch 'master' into ywang2/fix_the_timing_issue
yangwang201911 Dec 9, 2024
10f6a9f
update number of infer requests for throughput mode.
yangwang201911 Dec 10, 2024
83c63a0
Merge branch 'master' into ywang2/fix_the_timing_issue
peterchen-intel Dec 16, 2024
306ac48
update test cases.
yangwang201911 Dec 17, 2024
acdb52e
Merge branch 'master' into ywang2/fix_the_timing_issue
yangwang201911 Dec 18, 2024
4e27715
update.
yangwang201911 Dec 20, 2024
ee75163
update.
yangwang201911 Dec 20, 2024
b90bbaa
Merge branch 'master' into ywang2/fix_the_timing_issue
peterchen-intel Jan 5, 2025
ea49b94
Merge branch 'master' into ywang2/fix_the_timing_issue
peterchen-intel Jan 8, 2025
be94186
Merge branch 'master' into ywang2/fix_the_timing_issue
peterchen-intel Jan 13, 2025
6fbd58c
Merge branch 'master' into ywang2/fix_the_timing_issue
yangwang201911 Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/plugins/auto/src/auto_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ void AutoSchedule::init() {
// initialize containers before run async task
m_idle_worker_requests[device.device_name];
m_worker_requests[device.device_name];
m_worker_requests_conds[device.device_name];
m_infer_pipeline_tasks_device_specific[device.device_name] = nullptr;
}
m_idle_worker_requests["CPU_HELP"];
m_worker_requests["CPU_HELP"];
m_worker_requests_conds["CPU_HELP"];
m_infer_pipeline_tasks_device_specific["CPU_HELP"] = nullptr;
m_executor->run(m_compile_context[CPU].m_task);
m_executor->run(m_compile_context[ACTUALDEVICE].m_task);
Expand Down Expand Up @@ -488,7 +490,11 @@ bool AutoSchedule::schedule_to_worker_infer_request(ov::threading::Task pipeline
if (!preferred_device.empty() && (device.device_name != preferred_device)) {
continue;
}
if (run_pipeline_task(pipeline_task, m_idle_worker_requests[device.device_name], preferred_device)) {
if (run_pipeline_task(pipeline_task,
m_idle_worker_requests[device.device_name],
preferred_device,
m_worker_requests_conds[device.device_name],
m_worker_infer_mutex)) {
return true;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/auto/src/cumulative_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void CumuSchedule::init() {
// initialize containers before run async task, if not initialized, it will hang during infer
m_idle_worker_requests[device.device_name];
m_worker_requests[device.device_name];
m_worker_requests_conds[device.device_name];
m_infer_pipeline_tasks_device_specific[device.device_name] = nullptr;
}
// load devices other than CPU first
Expand Down Expand Up @@ -247,7 +248,11 @@ bool CumuSchedule::schedule_to_worker_infer_request(ov::threading::Task pipeline
}
auto selected_device_name =
preferred_device.empty() ? schedule_to_next_device(devices, current_device_index) : preferred_device;
if (run_pipeline_task(pipeline_task, m_idle_worker_requests[selected_device_name], preferred_device)) {
if (run_pipeline_task(pipeline_task,
m_idle_worker_requests[selected_device_name],
preferred_device,
m_worker_requests_conds[selected_device_name],
m_worker_infer_mutex)) {
return true;
} else {
current_device_index++;
Expand Down
40 changes: 29 additions & 11 deletions src/plugins/auto/src/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,21 @@ void Schedule::run(ov::threading::Task pipeline_task) {
}

bool Schedule::run_pipeline_task(ov::threading::Task& pipeline_task,
NotBusyPriorityWorkerRequests& idle_workerrequests,
const DeviceName& preferred_device) {
NotBusyPriorityWorkerRequests& idle_workerrequests,
const DeviceName& preferred_device,
std::condition_variable& idle_workerrequests_cv,
std::mutex& worker_infer_mutex) {
WorkerInferRequest* worker_request_ptr = nullptr;
std::pair<int, WorkerInferRequest*> worker;
if (idle_workerrequests.try_pop(worker)) {
{
std::unique_lock<std::mutex> lck(worker_infer_mutex);
if (!idle_workerrequests.try_pop(worker)) {
idle_workerrequests_cv.wait(lck, [&idle_workerrequests, &worker] {
return idle_workerrequests.try_pop(worker);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, this solution seems to wait forever until it can get a worker, this is not by design(by design we have m_infer_pipeline_tasks for tasks which are not able to schedule workers at some moment).
maybe we can consider increase cpu worker infer request to 2 to avoid this deadlock, or if we need to use cv to fix this issue, at least can we try align with the m_infer_pipeline_tasks design?

});
}
}
if (worker.second) {
worker_request_ptr = worker.second;
IdleGuard<NotBusyPriorityWorkerRequests> idle_guard{worker_request_ptr, idle_workerrequests};
m_this_worker_infer_request = worker_request_ptr;
Expand Down Expand Up @@ -85,10 +95,13 @@ void Schedule::generate_workers(const std::string& device, const SoCompiledModel
OPENVINO_THROW("Every device used with AUTO should support query optimal_number_of_infer_requests property from compiled model ",
iie.what());
}
const auto num_requests = (m_context->m_device_priorities.end() == it_numrequests ||
it_numrequests->num_requests_per_devices == -1) ? optimal_num : it_numrequests->num_requests_per_devices;
auto num_requests =
(m_context->m_device_priorities.end() == it_numrequests || it_numrequests->num_requests_per_devices == -1)
? optimal_num
: it_numrequests->num_requests_per_devices;
auto& worker_requests = m_worker_requests[device];
auto& idle_worker_requests = m_idle_worker_requests[device];
auto& worker_requests_cv = m_worker_requests_conds[device];
worker_requests.resize(num_requests);
m_infer_pipeline_tasks_device_specific[device] = std::unique_ptr<TaskQueue>(new TaskQueue);
auto* idle_workerrequests_ptr = &(idle_worker_requests);
Expand All @@ -98,9 +111,11 @@ void Schedule::generate_workers(const std::string& device, const SoCompiledModel
worker_request.m_inferrequest = {compiled_model->create_infer_request(), compiled_model._so};
auto* worker_request_ptr = &worker_request;
worker_request_ptr->m_index = num++;
OPENVINO_ASSERT(idle_worker_requests.try_push(std::make_pair(worker_request_ptr->m_index, worker_request_ptr)) == true);
OPENVINO_ASSERT(
idle_worker_requests.try_push(std::make_pair(worker_request_ptr->m_index, worker_request_ptr)) == true);
worker_request.m_inferrequest->set_callback(
[worker_request_ptr, this, device, idle_workerrequests_ptr](std::exception_ptr exception_ptr) mutable {
[worker_request_ptr, this, device, idle_workerrequests_ptr, &worker_requests_cv](
std::exception_ptr exception_ptr) mutable {
IdleGuard<NotBusyPriorityWorkerRequests> idleGuard{worker_request_ptr, *idle_workerrequests_ptr};
worker_request_ptr->m_exception_ptr = std::move(exception_ptr);
{
Expand Down Expand Up @@ -128,17 +143,20 @@ void Schedule::generate_workers(const std::string& device, const SoCompiledModel
} else {
stop_retry_and_continue();
}
// try to return the request to the idle list (fails if the overall object destruction has began)
if (idleGuard.release()->try_push(std::make_pair(worker_request_ptr->m_index, worker_request_ptr))) {
// let's try to pop a task, as we know there is at least one idle request, schedule if succeeded
// if no device-agnostic tasks, let's try pop the device specific task, schedule if succeeded
std::unique_lock<std::mutex> lck(m_worker_infer_mutex);
if (idleGuard.release()->try_push(
std::make_pair(worker_request_ptr->m_index, worker_request_ptr))) {
// let's try to pop a task, as we know there is at least one idle request, schedule if
// succeeded if no device-agnostic tasks, let's try pop the device specific task, schedule
// if succeeded
ov::threading::Task t;
do {
m_infer_pipeline_tasks.try_pop(t);
} while (t && schedule_to_worker_infer_request(std::move(t)));
do {
m_infer_pipeline_tasks_device_specific[device]->try_pop(t);
} while (t && schedule_to_worker_infer_request(std::move(t), device));
worker_requests_cv.notify_all();
}
}
});
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/auto/src/schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ class Schedule : public std::enable_shared_from_this<Schedule>, public ov::threa

protected:
virtual void init() = 0;
static bool run_pipeline_task(ov::threading::Task& pipeline_task, NotBusyPriorityWorkerRequests& idle_worker_request,
const DeviceName& preferred_device);
static bool run_pipeline_task(ov::threading::Task& pipeline_task,
NotBusyPriorityWorkerRequests& idle_worker_request,
const DeviceName& preferred_device,
std::condition_variable& idle_worker_request_cv,
std::mutex& mutex);
virtual void generate_workers(const std::string& device, const SoCompiledModel& compiled_model);
virtual void try_to_compile_model(AutoCompileContext& context, const std::shared_ptr<ov::Model>& model) = 0;
virtual bool schedule_to_worker_infer_request(ov::threading::Task, DeviceName preferred_device = "") = 0;
Expand All @@ -40,6 +43,7 @@ class Schedule : public std::enable_shared_from_this<Schedule>, public ov::threa
std::shared_ptr<ov::threading::IStreamsExecutor> m_executor;
DeviceMap<NotBusyPriorityWorkerRequests> m_idle_worker_requests;
DeviceMap<std::vector<WorkerInferRequest>> m_worker_requests;
DeviceMap<std::condition_variable> m_worker_requests_conds;
TaskQueue m_infer_pipeline_tasks;
DeviceMap<std::unique_ptr<TaskQueue>> m_infer_pipeline_tasks_device_specific;
SoCompiledModel m_passthrough_compiled_model;
Expand All @@ -50,6 +54,7 @@ class Schedule : public std::enable_shared_from_this<Schedule>, public ov::threa
mutable std::atomic<std::size_t> m_request_id = {0};
std::mutex m_dev_infer_mutex;
std::unordered_map<IASyncInferPtr, WorkerInferRequest*> m_dev_infer;
std::mutex m_worker_infer_mutex;
};

} // namespace auto_plugin
Expand Down
Loading