Skip to content

Implement async version for InferList & Infer2#19709

Merged
alalek merged 5 commits intoopencv:masterfrom
TolyaTalamanov:at/async-inferlist-infer2
Mar 18, 2021
Merged

Implement async version for InferList & Infer2#19709
alalek merged 5 commits intoopencv:masterfrom
TolyaTalamanov:at/async-inferlist-infer2

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov commented Mar 11, 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

Overview

This PR brings functionality to run InferList and Infer2 asynchronously.

Build configuration

Xforce_builders_only=linux,docs
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.1.0:20.04
build_image:Custom Win=openvino-2021.1.0
build_image:Custom Mac=openvino-2021.1.0

test_modules:Custom=gapi
test_modules:Custom Win=gapi
test_modules:Custom Mac=gapi

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

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@AsyaPronina @rgarnov @smirnov-alexey Have a look, please

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@AsyaPronina @rgarnov @smirnov-alexey Could you have a look, please ?

Copy link
Copy Markdown
Contributor

@smirnov-alexey smirnov-alexey left a comment

Choose a reason for hiding this comment

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

Overall, looks good

Copy link
Copy Markdown
Contributor

@rgarnov rgarnov left a comment

Choose a reason for hiding this comment

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

Looks good

@TolyaTalamanov TolyaTalamanov requested a review from dmatveev March 17, 2021 15:01
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dmatveev Could you have a look ?

std::shared_ptr<IECallContext> ctx;
std::vector<std::vector<int>> cached_dims;
};
std::shared_ptr<Priv> m_priv;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need this if class is only in implementation part?

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.

Yes, because it contains atomic which doesn't have copy ctor

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.

Another reason to implement it such way is: object should be shared between async requests

if (finished == size) {
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
auto output = ctx->output(i);
ctx->out.meta(output, cv::GRunArg::Meta{});
Copy link
Copy Markdown
Contributor

@AsyaPronina AsyaPronina Mar 17, 2021

Choose a reason for hiding this comment

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

I am not sure that we can somehow retrieve input meta here from input args, but is it okay to post empty meta?

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.

Yes, it isn't ok and well-known problem, but this PR about: "Support async execution for InferList and Infer2".
But anyway I can fix it in this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We shouldn't introduce new problems now if they are well known, so please address it here too.

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.

Agree, fixed

for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
auto output = ctx->output(i);
ctx->out.meta(output, cv::GRunArg::Meta{});
ctx->out.post(std::move(output));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this code is duplicated, may be we can retrieve it to some common method/function?

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.

Yea, I think it can implemented as a separate function to reuse code

cached_dims[i] = toCV(ie_out->getTensorDesc().getDims());
// FIXME: Isn't this should be done automatically
// by some resetInternalData(), etc? (Probably at the GExecutor level)
ctx->outVecR<cv::Mat>(i).clear();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this code is also duplicated, how much does it cost to retrieve it to some common place?
Do we have some obstacles and this work seems extra?

Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov TolyaTalamanov Mar 17, 2021

Choose a reason for hiding this comment

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

This isn't my code, so I wouldn't touch at least in this PR, moreover it already has a comment about moving this to common place

if (finished == size) {
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
auto output = ctx->output(i);
ctx->out.meta(output, cv::GRunArg::Meta{});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We shouldn't introduce new problems now if they are well known, so please address it here too.

@TolyaTalamanov TolyaTalamanov force-pushed the at/async-inferlist-infer2 branch from b9b6592 to f6c0fc1 Compare March 18, 2021 11:29
// FIXME: Isn't this should be done automatically
// by some resetInternalData(), etc? (Probably at the GExecutor level)
auto& out_vec = ctx->outVecR<cv::Mat>(i);
out_vec.clear();
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.

In fact it isn't necessary because we reset it by calling Mat::create in callback, but I think call clear explicitly is clearer

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.

👍

IE::Blob::Ptr out_blob = req.GetBlob(ctx->uu.params.output_names[i]);
GAPI_Assert(out_blob);

cv::Mat out_mat(cached_dims[i], toCV(out_blob->getTensorDesc().getPrecision()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems you don't need this mat here?

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.

Damn, silly mistake, done

@dmatveev dmatveev self-assigned this Mar 18, 2021
@dmatveev dmatveev added this to the 4.5.2 milestone Mar 18, 2021
@TolyaTalamanov TolyaTalamanov force-pushed the at/async-inferlist-infer2 branch from f6c0fc1 to 1ee49d8 Compare March 18, 2021 17:13
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek Can it be merged ?

@alalek alalek merged commit dc31e20 into opencv:master Mar 18, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…t-infer2

G-API: Implement async version for InferList & Infer2

* Implement async version for InferList & Infer2

* Fix warning

* Fix bug with roi ordering

* Post input meta instead of empty

* Fix comments to review
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.

6 participants