Extract TaskItem and InferenceItem from OpenVino backend and convert ov_model to void in TaskItem.
Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -26,6 +26,25 @@ · 25 unmodified lines | ||
| 26 | 26 | |
| 27 | 27 | #include "../dnn_interface.h" |
| 28 | 28 | |
| 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 | + | |
| 29 | 48 | int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params); |
| 30 | 49 | |
| 31 | 50 | #endif |
| @@ -59,25 +59,6 @@ typedef struct OVModel{ · 58 unmodified lines | ||
| 59 | 59 | Queue *inference_queue; // holds InferenceItem |
| 60 | 60 | } OVModel; |
| 61 | 61 | |
| 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 | − | |
| 81 | 62 | // one request for one call to openvino |
| 82 | 63 | typedef struct RequestItem { |
| 83 | 64 | ie_infer_request_t *infer_request; |
| @@ -184,7 +165,7 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request · 100 unmodified lines | ||
| 184 | 165 | request->inferences[i] = inference; |
| 185 | 166 | request->inference_count = i + 1; |
| 186 | 167 | task = inference->task; |
| 187 | − switch (task->ov_model->model->func_type) { | |
| 168 | + switch (ov_model->model->func_type) { | |
| 188 | 169 | case DFT_PROCESS_FRAME: |
| 189 | 170 | if (task->do_ioproc) { |
| 190 | 171 | if (ov_model->model->frame_pre_proc != NULL) { |
| @@ -220,11 +201,12 @@ static void infer_completion_callback(void *args) · 29 unmodified lines | ||
| 220 | 201 | RequestItem *request = args; |
| 221 | 202 | InferenceItem *inference = request->inferences[0]; |
| 222 | 203 | 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; | |
| 224 | 206 | ie_blob_t *output_blob = NULL; |
| 225 | 207 | ie_blob_buffer_t blob_buffer; |
| 226 | 208 | DNNData output; |
| 227 | − OVContext *ctx = &task->ov_model->ctx; | |
| 209 | + OVContext *ctx = &ov_model->ctx; | |
| 228 | 210 | |
| 229 | 211 | status = ie_infer_request_get_blob(request->infer_request, task->output_name, &output_blob); |
| 230 | 212 | if (status != OK) { |
| @@ -233,9 +215,9 @@ static void infer_completion_callback(void *args) · 2 unmodified lines | ||
| 233 | 215 | char *all_output_names = NULL; |
| 234 | 216 | size_t model_output_count = 0; |
| 235 | 217 | 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); | |
| 237 | 219 | 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); | |
| 239 | 221 | APPEND_STRING(all_output_names, model_output_name) |
| 240 | 222 | } |
| 241 | 223 | av_log(ctx, AV_LOG_ERROR, |
| @@ -271,11 +253,11 @@ static void infer_completion_callback(void *args) · 29 unmodified lines | ||
| 271 | 253 | task = request->inferences[i]->task; |
| 272 | 254 | task->inference_done++; |
| 273 | 255 | |
| 274 | − switch (task->ov_model->model->func_type) { | |
| 256 | + switch (ov_model->model->func_type) { | |
| 275 | 257 | case DFT_PROCESS_FRAME: |
| 276 | 258 | 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); | |
| 279 | 261 | } else { |
| 280 | 262 | ff_proc_from_dnn_to_frame(task->out_frame, &output, ctx); |
| 281 | 263 | } |
| @@ -285,18 +267,18 @@ static void infer_completion_callback(void *args) · 3 unmodified lines | ||
| 285 | 267 | } |
| 286 | 268 | break; |
| 287 | 269 | case DFT_ANALYTICS_DETECT: |
| 288 | − if (!task->ov_model->model->detect_post_proc) { | |
| 270 | + if (!ov_model->model->detect_post_proc) { | |
| 289 | 271 | av_log(ctx, AV_LOG_ERROR, "detect filter needs to provide post proc\n"); |
| 290 | 272 | return; |
| 291 | 273 | } |
| 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); | |
| 293 | 275 | break; |
| 294 | 276 | case DFT_ANALYTICS_CLASSIFY: |
| 295 | − if (!task->ov_model->model->classify_post_proc) { | |
| 277 | + if (!ov_model->model->classify_post_proc) { | |
| 296 | 278 | av_log(ctx, AV_LOG_ERROR, "classify filter needs to provide post proc\n"); |
| 297 | 279 | return; |
| 298 | 280 | } |
| 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); | |
| 300 | 282 | break; |
| 301 | 283 | default: |
| 302 | 284 | av_assert0(!"should not reach here"); |
| @@ -445,6 +427,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 142 unmodified lines | ||
| 445 | 427 | InferenceItem *inference; |
| 446 | 428 | TaskItem *task; |
| 447 | 429 | OVContext *ctx; |
| 430 | + OVModel *ov_model; | |
| 448 | 431 | |
| 449 | 432 | if (ff_queue_size(inferenceq) == 0) { |
| 450 | 433 | return DNN_SUCCESS; |
| @@ -452,10 +435,11 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 1 unmodified line | ||
| 452 | 435 | |
| 453 | 436 | inference = ff_queue_peek_front(inferenceq); |
| 454 | 437 | task = inference->task; |
| 455 | − ctx = &task->ov_model->ctx; | |
| 438 | + ov_model = task->model; | |
| 439 | + ctx = &ov_model->ctx; | |
| 456 | 440 | |
| 457 | 441 | if (task->async) { |
| 458 | − ret = fill_model_input_ov(task->ov_model, request); | |
| 442 | + ret = fill_model_input_ov(ov_model, request); | |
| 459 | 443 | if (ret != DNN_SUCCESS) { |
| 460 | 444 | return ret; |
| 461 | 445 | } |
| @@ -471,7 +455,7 @@ static DNNReturnType execute_model_ov(RequestItem *request, Queue *inferenceq) · 9 unmodified lines | ||
| 471 | 455 | } |
| 472 | 456 | return DNN_SUCCESS; |
| 473 | 457 | } else { |
| 474 | − ret = fill_model_input_ov(task->ov_model, request); | |
| 458 | + ret = fill_model_input_ov(ov_model, request); | |
| 475 | 459 | if (ret != DNN_SUCCESS) { |
| 476 | 460 | return ret; |
| 477 | 461 | } |
| @@ -694,7 +678,7 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu · 216 unmodified lines | ||
| 694 | 678 | task.in_frame = in_frame; |
| 695 | 679 | task.output_name = output_name; |
| 696 | 680 | task.out_frame = out_frame; |
| 697 | − task.ov_model = ov_model; | |
| 681 | + task.model = ov_model; | |
| 698 | 682 | |
| 699 | 683 | if (extract_inference_from_task(ov_model->model->func_type, &task, ov_model->inference_queue, NULL) != DNN_SUCCESS) { |
| 700 | 684 | av_frame_free(&out_frame); |
| @@ -814,7 +798,7 @@ DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams * · 113 unmodified lines | ||
| 814 | 798 | task.in_frame = exec_params->in_frame; |
| 815 | 799 | task.output_name = exec_params->output_names[0]; |
| 816 | 800 | 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; | |
| 818 | 802 | |
| 819 | 803 | if (extract_inference_from_task(ov_model->model->func_type, &task, ov_model->inference_queue, exec_params) != DNN_SUCCESS) { |
| 820 | 804 | 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 | ||
| 861 | 845 | task->in_frame = exec_params->in_frame; |
| 862 | 846 | task->output_name = exec_params->output_names[0]; |
| 863 | 847 | 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; | |
| 865 | 849 | if (ff_queue_push_back(ov_model->task_queue, task) < 0) { |
| 866 | 850 | av_freep(&task); |
| 867 | 851 | av_log(ctx, AV_LOG_ERROR, "unable to push back task_queue.\n"); |