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

cv::cuda::GpuMat.convertTo() seems not to support in-place, while cv::Mat does #13092

Closed
chacha21 opened this issue Nov 9, 2018 · 11 comments
Closed
Labels
category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib
Milestone

Comments

@chacha21
Copy link
Contributor

chacha21 commented Nov 9, 2018

Visual Studio 2017, Windows 7 64 bits, OpenCV 3.4.3
Cuda 10

the following code raises an exception :

  cv::cuda::GpuMat m(cv::Size(1280, 1024), CV_32FC1);
  cv::cuda::Stream stream;
  m.convertTo(m, CV_8UC1, 1, 0, stream);
  cv::cuda::threshold(m, m, 128, 255, cv::THRESH_BINARY, stream);

OpenCV(3.4.3) Error: Gpu API call (an illegal memory access was encountered) in
cv::cudev::grid_transform_detail::TransformDispatcher<true, Policy>::call, file
e:\opencv-3.4.3\opencv\sources\modules\cudev\include\opencv2\cudev\grid\detail/t
ransform.hpp, line 318

Using a second matrix as a destination for the convertTo() gets rid of the problem.

So it seems that convertTo() is no safe to use in-place with cuda::GpuMat, while the same code with cv::Mat would be ok.
Is it a bug or a missing documentation ?

@chacha21
Copy link
Contributor Author

Maybe a shared problem with #13149 ?

@harsv
Copy link

harsv commented May 15, 2019

I am having similar problem with opencv 3.4, Cuda10, Ubuntu18.04
This code works:
` cv::cuda::GpuMat gpu_image;

gpu_image_init.convertTo(gpu_image, CV_32FC3, 1.0, 0);`

However, this does not works:
gpu_image_init.convertTo(gpu_image_init, CV_32FC3, 1.0, 0);

In my case, the code runs but the resultant matrix has garbage values.

@nglee
Copy link
Contributor

nglee commented Jul 8, 2020

I am not able to reproduce this error on the latest 3.4 branch. (win10, vs2019, cuda10.2)
Although we are allowed to call GpuMat::convertTo() with one GpuMat for both input and output, it is not strictly an in-place conversion. Inside GpuMat::convertTo(), it allocates device memory for result data.

@chacha21
Copy link
Contributor Author

chacha21 commented Jul 8, 2020

As long as it does not crash, it is not a problem that it is not a real "in-place". I will check with my 4.3.0 build tomorrow

@chacha21
Copy link
Contributor Author

chacha21 commented Jul 9, 2020

The bug (as mentionned in initial post) is still present in 4.3.0

@nglee
Copy link
Contributor

nglee commented Jul 9, 2020

This is getting confusing. Even with Ubuntu 18.04(Jetson TX2) and the latest master branch build(4.4.0-pre), I wasn't able to reproduce the error. I've added the following googletest code to cudaarithm test codes and it seems to be working.

TEST(Issue13092, Issue13092)
{
    cv::cuda::GpuMat m(cv::Size(1280, 1024), CV_32FC1);
    cv::cuda::Stream stream;
    m.convertTo(m, CV_8UC1, 1, 0, stream);
    cv::cuda::threshold(m, m, 128, 255, cv::THRESH_BINARY, stream);
}
$ ./opencv_test_cudaarithm --gtest_filter=*13092*

...

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 10.0, CUDA Runtime Version = 10.0, NumDevs = 1

CTEST_FULL_OUTPUT
OpenCV version: 4.4.0-pre
OpenCV VCS version: 4.3.0-586-gd0e6d2438c
Build type: Release
Compiler: /usr/bin/c++  (ver 7.5.0)
Parallel framework: pthreads (nthreads=6)
CPU features: NEON? FP16?
OpenCL is disabled
TEST: Skip tests with tags: 'mem_6gb', 'verylong'
Note: Google Test filter = *13092*
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Issue13092
[ RUN      ] Issue13092.Issue13092
[       OK ] Issue13092.Issue13092 (550 ms)
[----------] 1 test from Issue13092 (550 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (551 ms total)
[  PASSED  ] 1 test.

I'll try again with x64 machine tomorrow.

@chacha21
Copy link
Contributor Author

chacha21 commented Jul 9, 2020

I forgot to mention that I now use VS2019 and CUDA 10.2 but it is of less importance; apart form that this is still under W7 64b

@nglee
Copy link
Contributor

nglee commented Jul 17, 2020

After increasing the GpuMat size, I see the same issue. The GPU model is RTX 2080 Ti.

@mshabunin
Copy link
Contributor

Perhaps this issue is similar to #17840 which have been resolved by using CUDA function designed for in-place processing.

@nglee
Copy link
Contributor

nglee commented Jul 29, 2020

@chacha21 @mshabunin
I believe this can fix this issue.
Could you please take a look?

@chacha21
Copy link
Contributor Author

I confirm that it seems to fix the problem.

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
Projects
None yet
Development

No branches or pull requests

5 participants