Skip to content

[G-API]: Eliminates detail::ParamDesc mention from public tests#18913

Closed
OrestChura wants to merge 7 commits intoopencv:masterfrom
OrestChura:oc/fix_paramdesc
Closed

[G-API]: Eliminates detail::ParamDesc mention from public tests#18913
OrestChura wants to merge 7 commits intoopencv:masterfrom
OrestChura:oc/fix_paramdesc

Conversation

@OrestChura
Copy link
Copy Markdown
Contributor

@OrestChura OrestChura commented Nov 24, 2020

This change:

  • replaces explicit ParamDesc objects declarations by brace-enclosed initializer lists
  • has to add constructors for ParamDesc
  • unifies tests appearance as possible

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

build_image:Custom=centos:7
buildworker: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=*

ParamDesc(std::string model, std::string weights, std::string device,
std::vector<std::string> inputNames, std::vector<std::string> outputNames,
std::unordered_map<std::string, ConstInput> constInputs,
std::size_t numIn, std::size_t numOut, Kind kind_, bool isGen, IEConfig config_)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use const reference as input parameters

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.

Of course. Thanks!
Fixed

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.

rolled back and added std::move in initializations to make less copies if rvalues are passed

Copy link
Copy Markdown
Contributor

@smirnov-alexey smirnov-alexey Dec 11, 2020

Choose a reason for hiding this comment

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

@OrestChura Nope, that won't work. All of those objects will be copied to the function's arguments. You should use const reference or universal reference (aka && + std::forward)

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.

@TolyaTalamanov can you take a look?

Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov Dec 14, 2020

Choose a reason for hiding this comment

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

On the one hand no needed implement both overloads (const& and &&)
On the other hand In case copy, ParamsDesc(const& T) make only one copy but ParamDesc(T t) make copy + move

I'm ok with both of them

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.

I'd prefer to leave it as is now as it has some advantages and, actually, no so important because it's not the public code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

because it's not the public code

Actually, it is a public header:

modules/gapi/include/opencv2/gapi/infer/ie.hpp


"copy + move" vs "const reference + copy"

The second one is preferable.
Copying in the first case is done on a caller side. Such copying significantly increases binary code size in cases of multiple use (default).
Copying after "const reference" is limited to 1 instance of binary code.

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.

I see! OK then, thanks. I've returned the const references already.

bool is_generic;
IEConfig config;

ParamDesc(const std::string& model, const std::string& weights, const std::string& device,
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.

Why is it needed ?

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.

Understood, but you make copy 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.

fixed, pls check if OK

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.

returned to const references #18913 (comment)


struct ROIList: public ::testing::Test {
cv::gapi::ie::detail::ParamDesc params;
std::string model_path = "", weights_path = "", device_id = "";
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.

Such kind of initialization isn't necessary, because std::string has default 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.

Oh, OK, thanks! removed

@asmorkalov
Copy link
Copy Markdown
Contributor

@OrestChura @TolyaTalamanov Friendly reminder.

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 10, 2020

Conflicting files
modules/gapi/test/infer/gapi_infer_ie_test.cpp

Rebase is required.

 - replaces explicit ParamDesc objects declarations by brace-enclosed initializer lists
 - has to add constructors for ParamDesc
 - remove initializations for std::string variables
 - reduce copying in ParamDesc constructors
@OrestChura
Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov please look one more time as there are new tests from the recent PR which have required fixes
/cc @smirnov-alexey as backup

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.

Please, fix copying

@OrestChura
Copy link
Copy Markdown
Contributor Author

@alalek Let's merge this please

 - hardcoded key values replaced by IE::PluginConfigParams:: references
@OrestChura
Copy link
Copy Markdown
Contributor Author

@alalek should I squash?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

should I squash?

Not required. There is no mess on GitHub's diff page.

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.

I don't understand what part of what is eliminated, tbh..

There's more new lines than deleted lines, too.

Comment on lines +72 to +76
const std::vector<std::string>& inputNames,
const std::vector<std::string>& outputNames,
const std::unordered_map<std::string, ConstInput>& constInputs,
std::size_t numIn, std::size_t numOut, Kind kind_, bool isGen,
const IEConfig& config_)
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.

Why do we need this constructor at all?

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.

I mean, the {}-thing should work?

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.

Overall - I would not expect any changes at the module API level when there is some test work happening.

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.

This constructor is needed exactly not to change API anywhere else.
I needed the other constructor for possibility to forward ParamDesc in functions via {model, weights, device} statement. But in Params<Net> here the full constructor is used, so I had to add the full constructor explicitly

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.

Let's make a call

params.model_path, params.weights_path, params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
auto pp = cv::gapi::ie::Params<AgeGender> {model_path, weights_path, device_id
}.cfgOutputLayers({ "age_conv3", "prob" });
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.

Something strange happened to this formatting.

it is not supposed to look like this.

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.

I can format to the indentation like it was before in this snippet

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.

@dmatveev please check if OK now

num_out(numOut), kind(kind_), is_generic(isGen), config(config_) {};

ParamDesc(const std::string& model, const std::string& weights, const std::string& device)
: model_path(model), weights_path(weights), device_id(device) {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uninitialized fields (static code scans will come here):

  • num_in
  • num_out
  • kind
  • is_generic

@OrestChura
Copy link
Copy Markdown
Contributor Author

After a discussion, it is decided to leave ::ie::detail::ParamDesc as is not to add these huge constructors. Overall, the problem is more complex and requires deeper refactoring than covered in this PR.
Have to close this and open a new one to avoid misunderstanding of a branch

@dmatveev
Copy link
Copy Markdown
Contributor

Thanks Orest!

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