History

lavfi/dnn_backend_openvino.c: unify code for infer request for sync/async

Guo, Yejun committed 5 years ago

Commit 1b5dc711 parent ed409b81 file · +21 −28Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/dnn/dnn_backend_openvino.c+21−28
@@ -52,9 +52,6 @@ typedef struct OVModel{ · 51 unmodified lines
52 ie_core_t *core;52 ie_core_t *core;
53 ie_network_t *network;53 ie_network_t *network;
54 ie_executable_network_t *exe_network;54 ie_executable_network_t *exe_network;
55 ie_infer_request_t *infer_request;
56
57 /* for async execution */
58 SafeQueue *request_queue; // holds RequestItem55 SafeQueue *request_queue; // holds RequestItem
59 Queue *task_queue; // holds TaskItem56 Queue *task_queue; // holds TaskItem
60} OVModel;57} OVModel;
@@ -269,12 +266,9 @@ static void infer_completion_callback(void *args) · 208 unmodified lines
269 ie_blob_free(&output_blob);266 ie_blob_free(&output_blob);
270 267
271 request->task_count = 0;268 request->task_count = 0;
272 269 if (ff_safe_queue_push_back(requestq, request) < 0) {
273 if (task->async) {270 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
274 if (ff_safe_queue_push_back(requestq, request) < 0) {271 return;
275 av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
276 return;
277 }
278 }272 }
279}273}
280 274
@@ -347,11 +341,6 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 66 unmodified lines
347 goto err;341 goto err;
348 }342 }
349 343
350 // create infer_request for sync execution
351 status = ie_exec_network_create_infer_request(ov_model->exe_network, &ov_model->infer_request);
352 if (status != OK)
353 goto err;
354
355 // create infer_requests for async execution344 // create infer_requests for async execution
356 if (ctx->options.nireq <= 0) {345 if (ctx->options.nireq <= 0) {
357 // the default value is a rough estimation346 // the default value is a rough estimation
@@ -502,10 +491,9 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 144 unmodified lines
502 OVModel *ov_model = model;491 OVModel *ov_model = model;
503 OVContext *ctx = &ov_model->ctx;492 OVContext *ctx = &ov_model->ctx;
504 TaskItem task;493 TaskItem task;
505 RequestItem request;494 RequestItem *request;
506 AVFrame *in_frame = NULL;495 AVFrame *in_frame = NULL;
507 AVFrame *out_frame = NULL;496 AVFrame *out_frame = NULL;
508 TaskItem *ptask = &task;
509 IEStatusCode status;497 IEStatusCode status;
510 input_shapes_t input_shapes;498 input_shapes_t input_shapes;
511 499
@@ -557,11 +545,16 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 45 unmodified lines
557 task.out_frame = out_frame;545 task.out_frame = out_frame;
558 task.ov_model = ov_model;546 task.ov_model = ov_model;
559 547
560 request.infer_request = ov_model->infer_request;548 request = ff_safe_queue_pop_front(ov_model->request_queue);
561 request.task_count = 1;549 if (!request) {
562 request.tasks = &ptask;550 av_frame_free(&out_frame);
551 av_frame_free(&in_frame);
552 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
553 return DNN_ERROR;
554 }
555 request->tasks[request->task_count++] = &task;
563 556
564 ret = execute_model_ov(&request);557 ret = execute_model_ov(request);
565 *output_width = out_frame->width;558 *output_width = out_frame->width;
566 *output_height = out_frame->height;559 *output_height = out_frame->height;
567 560
@@ -633,8 +626,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 65 unmodified lines
633 OVModel *ov_model = model->model;626 OVModel *ov_model = model->model;
634 OVContext *ctx = &ov_model->ctx;627 OVContext *ctx = &ov_model->ctx;
635 TaskItem task;628 TaskItem task;
636 RequestItem request;629 RequestItem *request;
637 TaskItem *ptask = &task;
638 630
639 if (!in_frame) {631 if (!in_frame) {
640 av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n");632 av_log(ctx, AV_LOG_ERROR, "in frame is NULL when execute model.\n");
@@ -674,11 +666,14 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 33 unmodified lines
674 task.out_frame = out_frame;666 task.out_frame = out_frame;
675 task.ov_model = ov_model;667 task.ov_model = ov_model;
676 668
677 request.infer_request = ov_model->infer_request;669 request = ff_safe_queue_pop_front(ov_model->request_queue);
678 request.task_count = 1;670 if (!request) {
679 request.tasks = &ptask;671 av_log(ctx, AV_LOG_ERROR, "unable to get infer request.\n");
672 return DNN_ERROR;
673 }
674 request->tasks[request->task_count++] = &task;
680 675
681 return execute_model_ov(&request);676 return execute_model_ov(request);
682}677}
683 678
684DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,679DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame,
@@ -821,8 +816,6 @@ void ff_dnn_free_model_ov(DNNModel **model) · 136 unmodified lines
821 }816 }
822 ff_queue_destroy(ov_model->task_queue);817 ff_queue_destroy(ov_model->task_queue);
823 818
824 if (ov_model->infer_request)
825 ie_infer_request_free(&ov_model->infer_request);
826 if (ov_model->exe_network)819 if (ov_model->exe_network)
827 ie_exec_network_free(&ov_model->exe_network);820 ie_exec_network_free(&ov_model->exe_network);
828 if (ov_model->network)821 if (ov_model->network)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t