Skip to content

cuda::flip - Use in-place npp function for inplace arguments #17863

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

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

nglee
Copy link
Contributor

@nglee nglee commented Jul 16, 2020

Resolves #17840

#17863 (comment)

cv::cuda::GpuMat::create does not allocate a new GpuMat if required size and type equals existing size and type.

if (rows == _rows && cols == _cols && type() == _type && data)
return;

This PR implements cv::cuda::detachOutput to allocate a new GpuMat in such cases. Unfortunately, _dst is const so assignment is not possible. Instead, this implementation clones src.

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 OpenCV (BSD) 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

@nglee nglee force-pushed the dev_cudaDetachOutput branch from 3900414 to bfefe79 Compare July 16, 2020 17:42
@nglee nglee marked this pull request as ready for review July 16, 2020 17:57
Copy link
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.

It is not a CUDA-only issue for this particular function.

It is related to many CPU and OpenCL implementations (almost zero tests for this mode).
So some robust generic approach should be applied.

Possible fixes degrade performance, so we want to forbid such usages (to keep OpenCV library and applications optimized).
We don't want to trying fixing that and adding corresponding tests.

see also #13570 (it is closed without raising a general issue)

@nglee nglee force-pushed the dev_cudaDetachOutput branch from bfefe79 to bb34398 Compare July 18, 2020 14:12
@nglee
Copy link
Contributor Author

nglee commented Jul 18, 2020

@alalek
The updated code referred to the following lines.
https://github.com/opencv/opencv/blob/3.4/modules/imgproc/src/filter.dispatch.cpp#L918-L924

Consulting this issue comment, should we raise an exception instead?

@nglee nglee force-pushed the dev_cudaDetachOutput branch from bb34398 to 58dcd52 Compare July 18, 2020 21:10
@asmorkalov asmorkalov added category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib and removed RFC labels Jul 20, 2020
@nglee nglee force-pushed the dev_cudaDetachOutput branch from 58dcd52 to 9411cd6 Compare July 21, 2020 01:28
@nglee
Copy link
Contributor Author

nglee commented Jul 21, 2020

#17840 (comment)

Instead of copying the source matrix, this code calls in-place npp function if given in-place arguments.

@nglee nglee changed the title Implement cv::cuda::detachOutput cuda::flip - Use in-place npp function for inplace arguments Jul 21, 2020
@nglee nglee marked this pull request as draft July 21, 2020 02:37
@asmorkalov
Copy link
Contributor

Looks good to me. Passed test on Ubuntu 18.04 with CUDA 10.2 and GPU 1080Ti.

@nglee nglee marked this pull request as ready for review July 21, 2020 12:30
@mshabunin mshabunin requested a review from asmorkalov July 21, 2020 16:41
Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov added the backport is needed Label for maintainers. Authors of PR can ignore this label Jul 22, 2020
@asmorkalov
Copy link
Contributor

@nglee The same issue is reproducible with master branch too, but the code for master is moved to opencv_contrib repo. Could you propose yet another PR to contrib repository too?

@nglee
Copy link
Contributor Author

nglee commented Jul 22, 2020

@asmorkalov
I've opened one: opencv/opencv_contrib#2612

@opencv-pushbot opencv-pushbot merged commit 0fa06b1 into opencv:3.4 Jul 22, 2020
@nglee nglee deleted the dev_cudaDetachOutput branch July 22, 2020 10:38
@mshabunin mshabunin added port/backport done Label for maintainers. Authors of PR can ignore this and removed backport is needed Label for maintainers. Authors of PR can ignore this labels Jul 22, 2020
@tomoaki0705
Copy link
Contributor

nglee The same issue is reproducible with master branch too, but the code for master is moved to opencv_contrib repo. Could you propose yet another PR to contrib repository too?

@asmorkalov Once in the past, I was pointed from @alalek that this is not necessary, porting one PR from opencv to opencv_contrib.

#12666 (review)

once this modification is approved, I'll open a PR for opencv_contrib, too.

It is not necessary. I will merge these changes during next regular "Merge 3.4" PRs.

And alalek also did the same recently
original
ported

Was there any special reason for this PR to be ported to opencv_contrib ?
I'm just curious.

@asmorkalov
Copy link
Contributor

It's good idea to have CUDA implementations aligned between branches, especially if the patch could be ported as is without serious modifications.

@alalek alalek mentioned this pull request Jul 28, 2020
@tomoaki0705
Copy link
Contributor

@asmorkalov , my point is not "why", but "who".
If I make modification for CUDA stuff in 3.4 branch, should "I" port it to contrib, or can I keep it untouched so "alalek" can port it ?

@asmorkalov
Copy link
Contributor

General approach is to merge 3.4 to master weekly or so. Alalek does it and you usually hould not worry about it. Cuda changes cannot be just merged to contrib with git and some manual work is required. I usually ask the PR author to do porting as soon as author is in context can can do it faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib port/backport done Label for maintainers. Authors of PR can ignore this
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants