-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async Support for TensorFlow Backend #407
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guoyejun I have these two questions regarding these changes.
it doesn't matter if you leave this blank since there's commit log in each change. |
Sure, no problem. |
49e3116
to
3811dcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in commit log line and body: uint8_32 -> uint8_t
for the patch: lavfi/dnn: Use uint8_32 for async and do_ioproc in TaskItems |
a1d1624
to
026a4dd
Compare
e60948f
to
d1df055
Compare
I don't have other comments, please fix the two issues and send the 8 (one new patch) patches to community. @Semmer2 please help to verify the patches once they are in the mail list, by running sr/derain/dnn_processing/dnn_detect with tf backend. |
45b43ee
to
e62b359
Compare
@guoyejun sir, I have added the async status handling patch (b2e78c1) to this pull request. Please have a look at it. Basically, it checks the status of the previously running thread for the same request and if it is |
This commit adds an async execution mechanism for common use in the TensorFlow and Native backends. This commit also adds the documentation of typedefs and functions in the async module for common use in DNN backends. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This commits refactors the get async result function for common use in all three backends. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This commit adds a function for execution of TFInferRequest and documentation for functions related to TFInferRequest. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This commit enables async execution in the TensorFlow backend and adds function to flush extra frames. The async execution mechanism executes the TFInferRequests on a separate thread which is joined before the next execution of same TFRequestItem/while freeing the model. The following is the comparison of this mechanism with the existing sync mechanism on TensorFlow C API 2.5 CPU variant. Async Mode: 4m32.846s Sync Mode: 5m17.582s The above was performed on super resolution filter using SRCNN model. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This patch adds error handling for cases where the execute_model_tf fails, clears the used memory in the TFRequestItem and finally pushes it back to the request queue. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
Since requests are running in parallel, there is inconsistency in the status of the execution. To resolve it, we avoid using mutex as it would result in single TF_Session running at a time. So add TF_Status to the TFRequestItem Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
The frame allocation and filling the TaskItem with execution parameters is common in the three backends. This commit shifts this logic to dnn_backend_common. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
…equest This commit includes the check for the case when the newly created TFInferRequest is NULL. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
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. Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
looks good to me, and any other change beside the last patch? you may send the v3 patches together with is patch, since they are nature to be together. @Semmer2 please help to verify the patches. |
I can't think of anything else to make the patchset better for now. I think that's all for this patchset. |
Thank you for reviewing the pull request, @guoyejun sir. |
Patch Set Description
This patchset is a part of necessary deliverables in the GSoC project Async Support for TensorFlow Backend in FFmpeg.
Objective: Asynchronous Support for TensorFlow backend
Parts under this deliverable:
- Switch the execution mode to
TFRequestItem
based inference.- Implementing a standard asynchronous inference module
DNNAsyncExecModule
for use across the TF and Native backends.- Implement async mode in the TensorFlow backend.
Earlier Merged Patches in this patchset
The below patches move the
TaskItem
andInferenceItem
from the OpenVINO backend to thednn_backend_common
and adjust them for shared use across the three backends. Then we define theTFRequestItem
with execution parameters and switch the execution mechanism in the TensorFlow backend toTFRequestItem
based inference.f5ab890 lavfi/dnn: Extract TaskItem and InferenceItem from OpenVino Backend
446b4f7 lavfi/dnn: Convert output_name to char** in TaskItem
9675ebb lavfi/dnn: Add nb_output to TaskItem
6b961f7 lavfi/dnn: Use uint8_t for async and do_ioproc in TaskItems
5509235 lavfi/dnn: Fill Task using Common Function
68cf14d lavfi/dnn_backend_tf: TaskItem Based Inference
a4de605 lavfi/dnn_backend_tf: Add TFInferRequest and TFRequestItem
08d8b3b lavfi/dnn_backend_tf: Request-based Execution
b849228 lavfi/dnn_backend_tf: Separate function for filling RequestItem
84e4e60 lavfi/dnn_backend_tf: Separate function for Completion Callback
6f9570a lavfi/dnn_backend_tf: Error Handling
Final Patches
The below-mentioned patches implement the
DNNAsyncExecModule
and use them in the TensorFlow backend for adding the async mode. The methodology behind theDNNAsyncExecModule
being to execute a number ofTFRequestItem
's (which can also be set using the backend configuration parameternireq
) concurrently along the main FFmpeg execution thread so that the inference requests can be executed in an asynchronous fashion.Each
TFRequestItem
has its instance ofDNNAsyncExecModule
, which corresponds to a single thread. WhenTF_SessionRun
returns, the thread routine also returns with relevant exit code, and theTFRequestItem
is pushed back to therequest_queue
. This return status is caught when next time the sameTFRequestItem
is used for the execution. In case the previous execution failed, the error message is already printed, and we cancel all further executions by returningDNN_ERROR
.86f0a4f lavfi/dnn: Add Async Execution Mechanism and Documentation
c716578 lavfi/dnn: Common Function to Get Async Result in DNN Backends
e6ae8fc lavfi/dnn_backend_tf: TFInferRequest Execution and Documentation
0985e92 lavfi/dnn: Async Support for TensorFlow Backend
a3db9b5 lavfi/dnn_backend_tf: Error Handling for execute_model_tf
4d627ac lavfi/dnn_backend_tf: Add TF_Status to TFRequestItem
009b2e5 lavfi/dnn: Extract Common Parts from get_output functions
371e567 lavfi/dnn_backend_tf: Error Handling for tf_create_inference_request
2063745 lavfi/dnn: DNNAsyncExecModule Execution Failure Handling