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

Obtaining a javacv build without multithreading #396

Closed
malcolmgreaves opened this issue Apr 26, 2016 · 9 comments
Closed

Obtaining a javacv build without multithreading #396

malcolmgreaves opened this issue Apr 26, 2016 · 9 comments
Labels

Comments

@malcolmgreaves
Copy link

Hello!

I have enjoyed using the javacv project a great deal. It is really quite excellent getting access to OpenCV from the JVM (also tesseract and a billion other libraries!).

I am, unfortunately, running into a really nasty bug within OpenCV. I have a multi-threaded program that is attempting to use a particular function from OpenCV: cv::cvtColor.

Unfortunately for me, cv::cvtColor is compiled with to take advantage of multiple threads to perform color conversion. This functionality is baked into the OpenCV build. Each platform has its own different backend for multithreading. There's Grand Central Dispatch (GCD) for OSX only, pthreads and OpenMP for both Linux and OSX, and the Intel Thread Building Blocks (TBB) library for Windows and Linux.

On OSX, GCD does not obey the cv::setNumThreads(0) semantics: it's not possible to tell GCD to not run multithreaded code with only one thread. [https://github.com/opencv/opencv/issues/6461]

Would it be possible to collaborate and release platform-specific builds of javacv that use opencv built without any multithreading support?

If not that, then what about building javacv with opencv built with pthreads backends for both OSX and Linux?

@malcolmgreaves malcolmgreaves changed the title Obtaining a javacv build with no multithreading Obtaining a javacv build without multithreading Apr 26, 2016
@saudet saudet added the bug label Apr 28, 2016
@saudet
Copy link
Member

saudet commented Apr 28, 2016

If the pthreads backend now works well enough, sure, send a pull request and let's change all the builds to that! Thanks

@malcolmgreaves
Copy link
Author

Hi @saudet I'll spend some time in the next 10 days or so trying to get a build out. I'm really quite terrible and inexperienced with C++ (so I might pipe up again on the channel =D).... but we'll see how it goes!

@fjank
Copy link

fjank commented Dec 24, 2016

I do have some code (based on javacpp-preset 1.1) that changes the threading library for the opencv build to TBB. I actually have not had any problems with cvtColor running with 10 simultaneous java threads (windows), neither with the defaults in 1.1 nor with TBB. But I got a minor 5-10% performance increase on our system by switching to TBB. I can check out pthreads, and if that works out good I can make a pull request to change OpenCV default to pthreads.

@saudet
Copy link
Member

saudet commented Dec 24, 2016

@fjank Yes TBB is kind of annoying. If pthreads work just as well, I'd switch to that. Thanks!

@saudet
Copy link
Member

saudet commented Jan 18, 2018

Is this still an issue with JavaCV 1.4 and OpenCV 3.4.0?

saudet added a commit to bytedeco/javacpp-presets that referenced this issue Nov 15, 2018
@saudet
Copy link
Member

saudet commented Nov 15, 2018

It's done, OpenCV now gets built with pthreads on both Linux and Mac! On Linux, OpenMP causes issues with multithreading for some reason, so pthreads it is. In any case, please give it a try with the snapshots and let me know if you encounter any issues with it: http://bytedeco.org/builds/ Thanks!

@saudet
Copy link
Member

saudet commented Jan 13, 2019

And now part of JavaCV 1.4.4! Enjoy

@saudet saudet closed this as completed Jan 13, 2019
@nicoulaj
Copy link

On linux x86_64, I see libgomp messages in some cases:

libgomp: Thread creation failed: Resource temporarily unavailable

And there is still a libgomp.so in the jar in current versions, see for example current snapshot.

Did I miss something ?

@saudet
Copy link
Member

saudet commented Mar 27, 2020

@nicoulaj It's just there for backward compatibility of dependent libraries. OpenCV itself won't use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants