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

Unstable result of opencv_core.useOpenCL() #659

Closed
Daniel-Alievsky opened this issue Dec 16, 2018 · 7 comments
Closed

Unstable result of opencv_core.useOpenCL() #659

Daniel-Alievsky opened this issue Dec 16, 2018 · 7 comments

Comments

@Daniel-Alievsky
Copy link

I detected very strange bug. In my test, I intensively call opencv functions from different threads (I repeat all calculations 150 times in a simple loop). Every time I call opencv_core.useOpenCL() method to decide, whether I should use Mat or UMat version of my function. And... sometimes opencv_core.useOpenCL() returns false!

Of course, usually it returns true on my computer. However, in the same program, moreover, in a single Java loop (!) this method sometimes return false.

How is it possible? Maybe, it is also a problem of insufficient synchronization, like in #650 ? Can you advise me some workaround (probably, I need to call this function only once and store the results in some Java constant)?

I work with JavaCPP 1.4 version (OpenCV 3.4.0-1.4)

@Daniel-Alievsky
Copy link
Author

In the latest JavaCPP 1.4.4-SNAPSHOT (OpenCV 4.0.0) there is the same behavior: sometimes useOpenCL() returns false, but usually true,
What does it mean? What exactly means the result of this method?

@saudet
Copy link
Member

saudet commented Dec 17, 2018

Sounds like a bug in your video driver. Upgrade to the latest version, but as usual if that doesn't fix it, please report this issue upstream!

@Daniel-Alievsky
Copy link
Author

I've updated my driver to the latest version from https://www.nvidia.com/Download/index.aspx My version is GeForce GTX 770M, 417.35 (latest for today). It does not help.

I just added the following line to the start of every my OpenCV function:

        System.out.println("haveOpenCL: " 
            + opencv_core.haveOpenCL() + "; useOpenCL: " + opencv_core.useOpenCL()
            + " - " + getClass());

When I call my functions from single thread, results are always correct:
haveOpenCL: true; useOpenCL: true - class com.siams.stare....

But while calling from different parallel threads, the results are another: sometimes I see
haveOpenCL: true; useOpenCL: false - class com.siams.stare...
And the same behavior in the latest 4.0.0-1.4.4-SNAPSHOT

C++ implementation of useOpenCL is almost the same in 3.3.0 and 4.0.0. For example, in 4.0.0 it returns
data->useOpenCL = (int)(haveOpenCL() && Device::getDefault().ptr() && Device::getDefault().available()) ? 1 : 0;

It seems that it checks whether the device in "available" now, and return false if not. What does it mean?

Can you advise me to use always opencv_core.haveOpenCL() function instead of useOpenCL? I don't need to know the current device status, if it can change so quickly; I just need to select between 2 versions of the algorithms: UMat-oriented or Mat-oriented.

@saudet
Copy link
Member

saudet commented Dec 17, 2018 via email

@Daniel-Alievsky
Copy link
Author

Hello Samuel, it seems I found the problem: see opencv/opencv#13472 (comment)
Waiting for their reply...

@saudet
Copy link
Member

saudet commented Dec 24, 2018

I don't think that's issue, unless your OpenCL implementation has a bug and isn't thread-safe, which may very well be the case...

@saudet
Copy link
Member

saudet commented Apr 11, 2019

Let's close this issue as it is now being tracked upstream.
Make sure to ping them once in a while for progress!

@saudet saudet closed this as completed Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants