History

lavfi/dnn: Extract TaskItem and InferenceItem from OpenVino Backend

Extract TaskItem and InferenceItem from OpenVino backend and convert ov_model to void in TaskItem.

Shubhanshu Saxena committed 5 years ago

Commit f5ab8901 parent 580e1682 files · +40 −37Browse files

Showing the changes to libavfilter (2 of 2 files). Show all

Unified · Split

2 files
  1. libavfilter/dnn/dnn_backend_common.h +19 −0
  2. libavfilter/dnn/dnn_backend_openvino.c +21 −37
libavfilter/dnn/dnn_backend_common.h+19−0
@@ -26,6 +26,25 @@ · 25 unmodified lines
2626
2727 #include "../dnn_interface.h"
2828
29+// one task for one function call from dnn interface
30+typedef struct TaskItem {
31+ void *model; // model for the backend
32+ AVFrame *in_frame;
33+ AVFrame *out_frame;
34+ const char *input_name;
35+ const char *output_name;
36+ int async;
37+ int do_ioproc;
38+ uint32_t inference_todo;
39+ uint32_t inference_done;
40+} TaskItem;
41+
42+// one task might have multiple inferences
43+typedef struct InferenceItem {
44+ TaskItem *task;
45+ uint32_t bbox_index;
46+} InferenceItem;
47+
2948 int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params);
3049
3150 #endif
libavfilter/dnn/dnn_backend_openvino.c+21−37
@@ -59,25 +59,6 @@ typedef struct OVModel{ · 58 unmodified lines
5959 Queue *inference_queue; // holds InferenceItem
6060 } OVModel;
6161
62−// one task for one function call from dnn interface
63−typedef struct TaskItem {
64− OVModel *ov_model;
65− const char *input_name;
66− AVFrame *in_frame;
67− const char *output_name;
68− AVFrame *out_frame;
69− int do_ioproc;
70− int async;
71− uint32_t inference_todo;
72− uint32_t inference_done;
73−} TaskItem;
74−
75−// one task might have multiple inferences
76−typedef struct InferenceItem {
77− TaskItem *task;
78− uint32_t bbox_index;
79−} InferenceItem;
80−
8162 // one request for one call to openvino
8263 typedef struct RequestItem {
8364 ie_infer_request_t *infer_request;
@@ -184,7 +165,7 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request · 100 unmodified lines
184165 request->inferences[i] = inference;
185166 request->inference_count = i + 1;
186167 task = inference->task;
187− switch (task->ov_model->model->func_type) {
168+ switch (ov_model->model->func_type) {
188169 case DFT_PROCESS_FRAME:
189170 if (task->do_ioproc) {
190171 if (ov_model->model->frame_pre_proc != NULL) {
@@ -220,11 +201,12 @@ static void infer_completion_callback(void *args) · 29 unmodified lines
220201 RequestItem *request = args;
221202 InferenceItem *inference = request->inferences[0];
222203 TaskItem *task = inference->task;
223− SafeQueue *requestq = task->ov_model->request_queue;
204+ OVModel *ov_model = task->model;
205+ SafeQueue *requestq = ov_model->request_queue;
224206 ie_blob_t *output_blob = NULL;
225207 ie_blob_buffer_t blob_buffer;
226208 DNNData output;
227− OVContext *ctx = &task->ov_model->ctx;
209+ OVContext *ctx = &ov_model->ctx;
228210
229211 status = ie_infer_request_get_blob(request->infer_request, task->output_name, &output_blob);
230212 if (status != OK) {
@@ -233,9 +215,9 @@ static void infer_completion_callback(void *args) · 2 unmodified lines
233215 char *all_output_names = NULL;
234216 size_t model_output_count = 0;
235217 av_log(ctx, AV_LOG_ERROR, "Failed to get model output data\n");
236− status = ie_network_get_outputs_number(task->ov_model->network, &model_output_count);
218+ status = ie_network_get_outputs_number(ov_model->network, &model_output_count);
237219 for (size_t i = 0; i < model_output_count; i++) {
238− status = ie_network_get_output_name(task->ov_model->network, i, &model_output_name);
220+ status = ie_network_get_output_name(ov_model->network, i, &model_output_name);
239221 APPEND_STRING(all_output_names, model_output_name)
240222 }
241223 av_log(ctx, AV_LOG_ERROR,
@@ -271,11 +253,11 @@ static void infer_completion_callback(void *args) · 29 unmodified lines
271253 task = request->inferences[i]->task;
272254 task->inference_done++;
273255
274− switch (task->ov_model->model->func_type) {
256+ switch (ov_model->model->func_type) {
275257 case DFT_PROCESS_FRAME:
276258 if (task->do_ioproc) {
277− if (task->ov_model->model->frame_post_proc != NULL) {
278− task->ov_model->model->frame_post_proc(task->out_frame, &output, task->ov_model->model->filter_ctx);
259+ if (ov_model->model->frame_post_proc != NULL) {
260+ ov_model->model->frame_post_proc(task->out_frame, &output, ov_model->model->filter_ctx);
279261 } else {
280262 ff_proc_from_dnn_to_frame(task->out_frame, &output, ctx);
281263 }
@@ -285,18 +267,18 @@ static void infer_completion_callback(void *args) · 3 unmodified lines
285267 }
286268 break;
287269 case DFT_ANALYTICS_DETECT:
288− if (!task->ov_model->model->detect_post_proc) {
270+ if (!ov_model->model->detect_post_proc) {
289271 av_log(ctx, AV_LOG_ERROR, "detect filter needs to provide post proc\n");
290272 return;
291273 }
292− task->ov_model->model->detect_post_proc(task->out_frame, &output, 1, task->ov_model->model->filter_ctx);
274+ ov_model->model->detect_post_proc(task->out_frame, &output, 1, ov_model->model->filter_ctx);
293275 break;
294276 case DFT_ANALYTICS_CLASSIFY:
295− if (!task->ov_model->model->classify_post_proc) {
277+ if (!ov_model->model->classify_post_proc) {
296278 av_log(ctx, AV_LOG_ERROR, "classify filter needs to provide post proc\n");
297279 return;
298280 }
299− task->ov_model->model->classify_post_proc(task->out_frame, &output, request->inferences[i]->bbox_index, task->ov_model->model->filter_ctx);
281+ ov_model->model->classify_post_proc(task->out_frame, &output, request->inferences[i]->bbox_index, ov_model->model->filter_ctx);
300282 break;
301283 default:
302284 av_assert0(!"should not reach here");
@@ -445,6 +427,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 142 unmodified lines
445427 InferenceItem *inference;
446428 TaskItem *task;
447429 OVContext *ctx;
430+ OVModel *ov_model;
448431
449432 if (ff_queue_size(inferenceq) == 0) {
450433 return DNN_SUCCESS;
@@ -452,10 +435,11 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 1 unmodified line
452435
453436 inference = ff_queue_peek_front(inferenceq);
454437 task = inference->task;
455− ctx = &task->ov_model->ctx;
438+ ov_model = task->model;
439+ ctx = &ov_model->ctx;
456440
457441 if (task->async) {
458− ret = fill_model_input_ov(task->ov_model, request);
442+ ret = fill_model_input_ov(ov_model, request);
459443 if (ret != DNN_SUCCESS) {
460444 return ret;
461445 }
@@ -471,7 +455,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 9 unmodified lines
471455 }
472456 return DNN_SUCCESS;
473457 } else {
474− ret = fill_model_input_ov(task->ov_model, request);
458+ ret = fill_model_input_ov(ov_model, request);
475459 if (ret != DNN_SUCCESS) {
476460 return ret;
477461 }
@@ -694,7 +678,7 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 216 unmodified lines
694678 task.in_frame = in_frame;
695679 task.output_name = output_name;
696680 task.out_frame = out_frame;
697− task.ov_model = ov_model;
681+ task.model = ov_model;
698682
699683 if (extract_inference_from_task(ov_model->model->func_type, &task, ov_model->inference_queue, NULL) != DNN_SUCCESS) {
700684 av_frame_free(&out_frame);
@@ -814,7 +798,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams * · 113 unmodified lines
814798 task.in_frame = exec_params->in_frame;
815799 task.output_name = exec_params->output_names[0];
816800 task.out_frame = exec_params->out_frame ? exec_params->out_frame : exec_params->in_frame;
817− task.ov_model = ov_model;
801+ task.model = ov_model;
818802
819803 if (extract_inference_from_task(ov_model->model->func_type, &task, ov_model->inference_queue, exec_params) != DNN_SUCCESS) {
820804 av_log(ctx, AV_LOG_ERROR, "unable to extract inference from task.\n");
@@ -861,7 +845,7 @@ DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, DNNExecBasePa · 40 unmodified lines
861845 task->in_frame = exec_params->in_frame;
862846 task->output_name = exec_params->output_names[0];
863847 task->out_frame = exec_params->out_frame ? exec_params->out_frame : exec_params->in_frame;
864− task->ov_model = ov_model;
848+ task->model = ov_model;
865849 if (ff_queue_push_back(ov_model->task_queue, task) < 0) {
866850 av_freep(&task);
867851 av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n");

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