History

lavfi/dnn: DNNAsyncExecModule Execution Failure Handling

This commit adds the case handling if the asynchronous execution of a request fails by checking the exit status of the thread when joining before starting another execution. On failure, it does the cleanup as well.

Shubhanshu Saxena committed 5 years ago

Commit 20637451 parent 371e5672 files · +28 −5Browse files

Unified · Split

2 files
  1. libavfilter/dnn/dnn_backend_common.c +19 −4
  2. libavfilter/dnn/dnn_backend_tf.c +9 −1
libavfilter/dnn/dnn_backend_common.c+19−4
@@ -23,6 +23,9 @@ · 22 unmodified lines
2323
2424 #include "dnn_backend_common.h"
2525
26+#define DNN_ASYNC_SUCCESS (void *)0
27+#define DNN_ASYNC_FAIL (void *)-1
28+
2629 int ff_check_exec_params(void *ctx, DNNBackendType backend, DNNFunctionType func_type, DNNExecBaseParams *exec_params)
2730 {
2831 if (!exec_params) {
@@ -79,18 +82,25 @@ static void *async_thread_routine(void *args) · 50 unmodified lines
7982 DNNAsyncExecModule *async_module = args;
8083 void *request = async_module->args;
8184
82− async_module->start_inference(request);
85+ if (async_module->start_inference(request) != DNN_SUCCESS) {
86+ return DNN_ASYNC_FAIL;
87+ }
8388 async_module->callback(request);
84− return NULL;
89+ return DNN_ASYNC_SUCCESS;
8590 }
8691
8792 DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module)
8893 {
94+ void *status = 0;
8995 if (!async_module) {
9096 return DNN_ERROR;
9197 }
9298 #if HAVE_PTHREAD_CANCEL
93− pthread_join(async_module->thread_id, NULL);
99+ pthread_join(async_module->thread_id, &status);
100+ if (status == DNN_ASYNC_FAIL) {
101+ av_log(NULL, AV_LOG_ERROR, "Last Inference Failed.\n");
102+ return DNN_ERROR;
103+ }
94104 #endif
95105 async_module->start_inference = NULL;
96106 async_module->callback = NULL;
@@ -101,6 +111,7 @@ DNNReturnType ff_dnn_async_module_cleanup(DNNAsyncExecModule *async_module) · 4 unmodified lines
101111 DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_module)
102112 {
103113 int ret;
114+ void *status = 0;
104115
105116 if (!async_module) {
106117 av_log(ctx, AV_LOG_ERROR, "async_module is null when starting async inference.\n");
@@ -108,7 +119,11 @@ DNNReturnType ff_dnn_start_inference_async(void *ctx, DNNAsyncExecModule *async_ · 1 unmodified line
108119 }
109120
110121 #if HAVE_PTHREAD_CANCEL
111− pthread_join(async_module->thread_id, NULL);
122+ pthread_join(async_module->thread_id, &status);
123+ if (status == DNN_ASYNC_FAIL) {
124+ av_log(ctx, AV_LOG_ERROR, "Unable to start inference as previous inference failed.\n");
125+ return DNN_ERROR;
126+ }
112127 ret = pthread_create(&async_module->thread_id, NULL, async_thread_routine, async_module);
113128 if (ret != 0) {
114129 av_log(ctx, AV_LOG_ERROR, "Unable to start async inference.\n");
libavfilter/dnn/dnn_backend_tf.c+9−1
@@ -91,6 +91,7 @@ AVFILTER_DEFINE_CLASS(dnn_tensorflow); · 90 unmodified lines
9191
9292 static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *inference_queue);
9393 static void infer_completion_callback(void *args);
94+static inline void destroy_request_item(TFRequestItem **arg);
9495
9596 static void free_buffer(void *data, size_t length)
9697 {
@@ -172,6 +173,10 @@ static DNNReturnType tf_start_inference(void *args) · 75 unmodified lines
172173 request->status);
173174 if (TF_GetCode(request->status) != TF_OK) {
174175 av_log(&tf_model->ctx, AV_LOG_ERROR, "%s", TF_Message(request->status));
176+ tf_free_request(infer_request);
177+ if (ff_safe_queue_push_back(tf_model->request_queue, request) < 0) {
178+ destroy_request_item(&request);
179+ }
175180 return DNN_ERROR;
176181 }
177182 return DNN_SUCCESS;
@@ -1095,7 +1100,10 @@ static DNNReturnType execute_model_tf(TFRequestItem *request, Queue *inference_q · 917 unmodified lines
10951100 }
10961101
10971102 if (task->async) {
1098− return ff_dnn_start_inference_async(ctx, &request->exec_module);
1103+ if (ff_dnn_start_inference_async(ctx, &request->exec_module) != DNN_SUCCESS) {
1104+ goto err;
1105+ }
1106+ return DNN_SUCCESS;
10991107 } else {
11001108 if (tf_start_inference(request) != DNN_SUCCESS) {
11011109 goto err;

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