Skip to content

Not serialize compile arguments which have no S11N<T> template specialization#18651

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
AsyaPronina:asyadev/add_possibility_to_check_that_gcompilearg_has_serialize
Nov 2, 2020
Merged

Not serialize compile arguments which have no S11N<T> template specialization#18651
opencv-pushbot merged 1 commit intoopencv:masterfrom
AsyaPronina:asyadev/add_possibility_to_check_that_gcompilearg_has_serialize

Conversation

@AsyaPronina
Copy link
Copy Markdown
Contributor

@AsyaPronina AsyaPronina commented Oct 23, 2020

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

Xbuild_image:Custom=ubuntu-openvino-2020.3.0:16.04
build_image:Custom Win=openvino-2020.3.0
build_image:Custom Mac=openvino-2020.3.0

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

Xbuildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
Xtest_opencl:Custom=OFF
Xtest_bigdata:Custom=1
Xtest_filter:Custom=*

@AsyaPronina AsyaPronina force-pushed the asyadev/add_possibility_to_check_that_gcompilearg_has_serialize branch 6 times, most recently from cc1eca1 to adb2cb4 Compare October 31, 2020 17:51
@AsyaPronina
Copy link
Copy Markdown
Contributor Author

AsyaPronina commented Oct 31, 2020

@smirnov-alexey , @dmatveev.
Hi Alexey, Dmitry!
Cases where user passes more than 1 variable of certain type as compile arguments to cv::gapi::serialize(GCompileArgs) are not handled.

os << arg.tag;
arg.serialize(os);
ByteMemoryOutStream tmpS;
tmpS << arg.tag;
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.

Tag could be written to a primary stream.

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.

Thanks! Reworked this part!

cv::gapi::s11n::detail::S11N<T>::deserialize(is)
};
static_assert(cv::gapi::s11n::detail::has_S11N_spec<T>::value,
"cv::gapi::deserialize<GCompileArgs, Types...> waits Types to have S11N specializations"
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.

waits -> expects

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

cv::gapi::s11n::IIStream& is = *pIs;

std::string tag;
is >> tag;
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.

Here you read tag directly from the stream, but in the serialization code, you write tag to a temporary stream and then serialize its vector.

In theory, this code should work incorrectly. Please double-check.

https://github.com/opencv/opencv/pull/18651/files#diff-7b0234dbbb6f5f5bae56c90408ad90fe57c7d3070a1ed19af9ee4c909289685fR342

Copy link
Copy Markdown
Contributor Author

@AsyaPronina AsyaPronina Nov 2, 2020

Choose a reason for hiding this comment

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

Here I have a GCompileArg as serialized vector of char, which were deserialized from the main stream and this vector of char should contain that that were deserialized in temporary stream.

https://github.com/opencv/opencv/pull/18651/files/adb2cb4891cafabe2b70b679a0a6a11ed1459505#diff-464a0d9684f92e3f84f3ce12af7c7a8917fcc121480caa99d46884534002cb65R329

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.

Please simplify, the code shouldn't cause the confusion like mine

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.

Simplified, thanks!

GCompileArgs dArgsEmptyVar4 = cv::gapi::deserialize<GCompileArgs, EmptyCustomType>(sArgs4);
EXPECT_EQ(1u, dArgsEmptyVar4.size());
EXPECT_TRUE(cv::gapi::getCompileArg<EmptyCustomType>(dArgsEmptyVar4).has_value());
}
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.

There must be a test failing due to inconsistency in S11N for custom compile arg tags.

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.

Discussed

@AsyaPronina AsyaPronina force-pushed the asyadev/add_possibility_to_check_that_gcompilearg_has_serialize branch from 6145aea to 60ff600 Compare November 2, 2020 13:32
Comment on lines 323 to +330
for (uint32_t i = 0; i < sz; ++i) {
std::string tag;
is >> tag;
args.push_back(cv::gapi::detail::deserialize_arg<std::tuple<Types...>>::exec(is, tag));

std::vector<char> sArg;
is >> sArg;

cv::util::optional<GCompileArg> dArg =
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 whole thing can be further simplified, but let's leave it for now.
Just put a task in our tracker to implement GCompileArgs serialization in a more generic two-stage way (based on vectors).

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

…CompileArgs

- cv::gapi::serialize bypasses compile arguments which have no S11N specialization with serialize/deserialize callbacks for underlying types
- cv::gapi::deserialize can accept arbitraty number of serialized compile args in a stream but will return only those which are requested by user via template parameter pack if they are presented in the stream. If some or all of them are not presented cv::gapi::deserialize will ignore and return only those which are presented
- cv::gapi::deserialize can accept only types which can be deserialized (have S11N<T> specialization with the user callbacks)
- Added cv::gapi::s11n::detail::has_S11N_spec<T> trait to separate compile arguments which have S11N<T> specialization with the user callbacks
@AsyaPronina AsyaPronina force-pushed the asyadev/add_possibility_to_check_that_gcompilearg_has_serialize branch from 60ff600 to 48ccbe3 Compare November 2, 2020 15:57
@opencv-pushbot opencv-pushbot merged commit 6df92b3 into opencv:master Nov 2, 2020
@alalek alalek mentioned this pull request Nov 27, 2020
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.

5 participants