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
5252 ie_core_t *core;
5353 ie_network_t *network;
5454 ie_executable_network_t *exe_network;
55− ie_infer_request_t *infer_request;
56−
57− /* for async execution */
5855 SafeQueue *request_queue; // holds RequestItem
5956 Queue *task_queue; // holds TaskItem
6057 } OVModel;
@@ -269,12 +266,9 @@ static void infer_completion_callback(void *args) · 208 unmodified lines
269266 ie_blob_free(&output_blob);
270267
271268 request->task_count = 0;
272−
273− if (task->async) {
274− if (ff_safe_queue_push_back(requestq, request) < 0) {
275− av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
276− return;
277− }
269+ if (ff_safe_queue_push_back(requestq, request) < 0) {
270+ av_log(ctx, AV_LOG_ERROR, "Failed to push back request_queue.\n");
271+ return;
278272 }
279273 }
280274
@@ -347,11 +341,6 @@ static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, co · 66 unmodified lines
347341 goto err;
348342 }
349343
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−
355344 // create infer_requests for async execution
356345 if (ctx->options.nireq <= 0) {
357346 // 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
502491 OVModel *ov_model = model;
503492 OVContext *ctx = &ov_model->ctx;
504493 TaskItem task;
505− RequestItem request;
494+ RequestItem *request;
506495 AVFrame *in_frame = NULL;
507496 AVFrame *out_frame = NULL;
508− TaskItem *ptask = &task;
509497 IEStatusCode status;
510498 input_shapes_t input_shapes;
511499
@@ -557,11 +545,16 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 45 unmodified lines
557545 task.out_frame = out_frame;
558546 task.ov_model = ov_model;
559547
560− request.infer_request = ov_model->infer_request;
561− request.task_count = 1;
562− request.tasks = &ptask;
548+ request = ff_safe_queue_pop_front(ov_model->request_queue);
549+ if (!request) {
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;
563556
564− ret = execute_model_ov(&request);
557+ ret = execute_model_ov(request);
565558 *output_width = out_frame->width;
566559 *output_height = out_frame->height;
567560
@@ -633,8 +626,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_n · 65 unmodified lines
633626 OVModel *ov_model = model->model;
634627 OVContext *ctx = &ov_model->ctx;
635628 TaskItem task;
636− RequestItem request;
637− TaskItem *ptask = &task;
629+ RequestItem *request;
638630
639631 if (!in_frame) {
640632 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
674666 task.out_frame = out_frame;
675667 task.ov_model = ov_model;
676668
677− request.infer_request = ov_model->infer_request;
678− request.task_count = 1;
679− request.tasks = &ptask;
669+ request = ff_safe_queue_pop_front(ov_model->request_queue);
670+ if (!request) {
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;
680675
681− return execute_model_ov(&request);
676+ return execute_model_ov(request);
682677 }
683678
684679 DNNReturnType 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
821816 }
822817 ff_queue_destroy(ov_model->task_queue);
823818
824− if (ov_model->infer_request)
825− ie_infer_request_free(&ov_model->infer_request);
826819 if (ov_model->exe_network)
827820 ie_exec_network_free(&ov_model->exe_network);
828821 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