Skip to content
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

[G-API] Pipeline modeling tool: Skip frames #21719

Merged

Conversation

TolyaTalamanov
Copy link
Contributor

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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

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.4.1:20.04
build_image:Custom Win=openvino-2021.4.1
build_image:Custom Mac=openvino-2021.4.1

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=*

auto call_every_nth =
call_every_nth_opt.has_value() ? call_every_nth_opt.value() : 1;
if (call_every_nth <= 0) {
throw std::logic_error(node_name + " call_every_nth must be greater than zero");
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest to print value also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -326,7 +335,7 @@ int main(int argc, char* argv[]) {
}
auto output =
check_and_read<OutputDescr>(node_fn, "output", node_name);
builder.addDummy(node_name, time, output);
builder.addDummy(node_name, call_every_nth_u, time, output);
Copy link
Contributor

Choose a reason for hiding this comment

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

how's about making struct for call_every_nth_u and further possible params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like this:

builder.addDummy(NodeParams{node_name, call_every_nth_u}, time, output);

Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻 yes, something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// G-API doesn't support dynamic number of inputs/outputs.
if (inputs.size() > 1u) {
throw std::logic_error(
"skip_frame_nth is supported only for single input subgraphs");
Copy link
Contributor

Choose a reason for hiding this comment

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

printing of inputs.size() will help in troubleshooting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

call.run(subgr_inputs, subgr_outputs);
auto comp = cv::GComputation(cv::GProtoInputArgs{subgr_inputs},
cv::GProtoOutputArgs{subgr_outputs});
call = CallNode{call.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we over-wrap existing call operation with call_every_nth != 1 by a new operation with call_every_nth == 1 which has a counter and the same comp?
If my understanding is correct than in this case do we just return the previous Mat without actual calculation? if yes then why it is called as "skip frames"? I thought that by skip frames it means receiving something empty frames of increasing next frame awaiting duration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, naming is confusing. This is about calling some nodes(kernels) on every n iterations. (not on every iteration)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see,
Then question - Does it affect final measurement is some sort of way? maybe it had better to print information about node invocation count also in final report?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If node works not on every frame, it obviously improves performance.

maybe it had better to print information about node invocation count also in final report

Not sure that this is useful info, let's wait for the feedback firstly

…eline_modeling_tool-skip-frames-for-nodes
state.reset(new SubGraphState{});
state->cc = comp.compile(in, std::move(compile_args));

GAPI_Assert(state->cc.outMetas().size() == 1u);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no sense to double check it since it was checked in outMeta

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -326,7 +335,7 @@ int main(int argc, char* argv[]) {
}
auto output =
check_and_read<OutputDescr>(node_fn, "output", node_name);
builder.addDummy(node_name, time, output);
builder.addDummy(node_name, call_every_nth_u, time, output);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like this:

builder.addDummy(NodeParams{node_name, call_every_nth_u}, time, output);

call.run(subgr_inputs, subgr_outputs);
auto comp = cv::GComputation(cv::GProtoInputArgs{subgr_inputs},
cv::GProtoOutputArgs{subgr_outputs});
call = CallNode{call.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, naming is confusing. This is about calling some nodes(kernels) on every n iterations. (not on every iteration)

// G-API doesn't support dynamic number of inputs/outputs.
if (inputs.size() > 1u) {
throw std::logic_error(
"skip_frame_nth is supported only for single input subgraphs");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

auto call_every_nth =
call_every_nth_opt.has_value() ? call_every_nth_opt.value() : 1;
if (call_every_nth <= 0) {
throw std::logic_error(node_name + " call_every_nth must be greater than zero");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

Copy link
Contributor

@sivanov-work sivanov-work left a comment

Choose a reason for hiding this comment

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

LGTM

@TolyaTalamanov TolyaTalamanov force-pushed the at/pipeline_modeling_tool-skip-frames-for-nodes branch from 08d11b9 to 702cfb0 Compare March 17, 2022 09:13
@dmatveev dmatveev self-assigned this Mar 22, 2022
Copy link
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.

Have a little idea what happens here but hope the app is ok.

Please provide a meaningful description in the future, it will be mandatory for all our MRs.

modules/gapi/samples/pipeline_modeling_tool.cpp Outdated Show resolved Hide resolved
SubGraphState& state) {
// NB: Make a call on the first iteration and skip the furthers.
if (state.call_counter == 0) {
state.cc(in, state.last_result);
Copy link
Contributor

Choose a reason for hiding this comment

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

So there may be an extra copy, right? Since this internal GComputation has its own writeBack() inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If fact, there is extra copy.
https://github.com/opencv/opencv/blob/4.x/modules/gapi/src/executor/gexecutor.cpp#L163

because adapter->data() == out_mat.data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, there is NO extract copy

Co-authored-by: Dmitry Matveev <dmitry.matveev@intel.com>
Copy link
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.

👍

@TolyaTalamanov
Copy link
Contributor Author

@alalek Could you merge it, please?

@alalek alalek merged commit 9dd8e4d into opencv:4.x Mar 25, 2022
@opencv-pushbot opencv-pushbot mentioned this pull request Apr 23, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…ing_tool-skip-frames-for-nodes

[G-API] Pipeline modeling tool: Skip frames

* Add skip feature

* Refactoring

* Fix warning

* Put more comments

* Fix comments to review

* Agregate common params into structure

* Fix warning

* Clean up & add test

* Add assert

* Fix warning on Mac

* Update modules/gapi/samples/pipeline_modeling_tool.cpp

Co-authored-by: Dmitry Matveev <dmitry.matveev@intel.com>
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.

None yet

5 participants