Skip to content

G-API: Fix infer hanging#19971

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
TolyaTalamanov:at/infer-hangs-fix
Apr 27, 2021
Merged

G-API: Fix infer hanging#19971
opencv-pushbot merged 1 commit intoopencv:masterfrom
TolyaTalamanov:at/infer-hangs-fix

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov commented Apr 24, 2021

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Description

Infer kernels in IE backend works asynchronously and implemented via RequestPool which has a set of InferRequest's and concurrent bounded queue to track free requests.

Before run the task RequestPool pop first free request and if there are no free requests it blocks. (*)
When execution is finished (all frames are processed or at least started processing) need to wait for all requests are free.
There is some trick: try to pop all requests from queue, if specific request is busy it blocks until it's free. When it finishes guarantee all requests are free, but the queue of free requests is empty.

cv::GArray<cv::Rect> rr;
cv::GMat in;
cv::GArray<cv::GMat> age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(rr, in);
cv::GComputation comp(cv::GIn(in, rr), cv::GOut(age, gender));

// Start RequestPool
cc = comp.compile(/* args */);

// Run first time
cc(cv::gin(/* inputs */), cv::gout(/* outputs */));
// RequestPool emptied the queue of free requests

// Second run cause hanging because the queue of free request is empty, see (*)
cc(cv::gin(/* inputs */), cv::gout(/* outputs */));

Build configuration

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.3.0:20.04
build_image:Custom Win=openvino-2021.3.0
build_image:Custom Mac=openvino-2021.3.0

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

// NB: It will be blocked if at least one request is busy.
for (size_t i = 0; i < m_requests.size(); ++i) {
size_t id = 0u;
m_idle_ids.pop(id);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fill queue again to use it in next infer calls

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dbudniko @dmatveev Have a look, please

@TolyaTalamanov TolyaTalamanov requested a review from dmatveev April 24, 2021 19:01
@dmatveev dmatveev self-assigned this Apr 27, 2021
@dmatveev dmatveev added this to the 4.5.3 milestone Apr 27, 2021
Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the idea but please write a meaningful root case / fix description

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek Can it be merged ?

@TolyaTalamanov TolyaTalamanov requested a review from alalek April 27, 2021 07:08
@opencv-pushbot opencv-pushbot merged commit 0c171c0 into opencv:master Apr 27, 2021
@alalek alalek mentioned this pull request Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants