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