3

I want to write a cross-platform code for computer vision issue. This code should be run on PC with GPU (nVidia), iPhone with GPU and Some Android-Based device that may contain GPU and may not. I want to get the max possible utilization of the exist hardware. My programing language is C++ 11 and my computer vision library is OpenCV. What is the best framework, Layer, technique... etc to use in order to write an isolated high-level code that can utilize from the GPU if it is available.

P.S. this could be shown as off-topic as asking for recommendation. But really here I am not asking between many available options. I am just asking about how this usually is done or what is the state of art in this field.

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160

2 Answers2

3

For multiplatform, I'm going to argue for keeping it in C/C++ and use the usual threading libraries.

While in iOS you've got only one vendor and the OpenCV team can devote the efforts to tune as required, on Android there is a mix of CPU/GPU vendors so the Google/Android team went with RenderScript (Why did Google choose RenderScript instead of OpenCL) and doesn't officially support OpenCL. Including an non-RenderScript GPU compute options would have to come from the individual vendors like Intel, Qualcomm, and for completeness nVidia's CUDA.

Realize that mobile platforms have been evolving at a much faster rate than PCs, i.e. the type of phone you could have gotten with Intel first released the Core i series (2008) vs what is available now.

Further down the pipeline there are Compute Shaders in OpenGL ES 3.1 and Vulkan. So if you are looking for baseline - you would be better off in C/C++ thread land.

Now if you really had a mobile app that you needed to push the performance then you can figure out what optimizations are required on the mobile platform of your choice.

Community
  • 1
  • 1
Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
  • Thanks, You mentioned "you would be better off in C/C++ thread land". Does threading library in C++ utilize the GPU ? Or you just mean that I can get more performance by paralleling my work on many cores ? – Humam Helfawi Dec 08 '15 at 07:09
  • 1
    Get more performance by parallelizing work on many CPU cores via thread libraries. – Morrison Chang Dec 08 '15 at 07:38
2

I think the following technology stack makes very much sense for your requirements:

  • OpenCL for all kinds of desktop stations equipped with nVidia GPUs or of any other vendor and for GPU programming on Android.
  • Metal for GPU programming on iOS, because its little effort to port your OpenCL implementation:

If you’re thinking that Metal could be a reason – that language looks very much like OpenCL, as it’s simply OpenCL as Apple would like it to be. Porting between the two languages is therefore quite simple. This also means that with some small fixes a Metel-kernel could be compiled by existing OpenCL-compiler.

(http://streamcomputing.eu/blog/2015-05-09/apples-dragging-opencl-compiler-problem/, Last accessed at 07.12.2015)

Regarding OpenCV

OpenCV partially supports OpenCL (http://docs.opencv.org/2.4/modules/ocl/doc/introduction.html, Last accessed at 07.12.2015), however afaik there is no way OpenCV does utilize the GPU under iOS (OpenCV on iOS - GPU usage?).

So iOS will be the tricky part in terms of porting your OpenCV based algorithm to that platform, if you want it to be GPU accelerated.

Community
  • 1
  • 1
MarkusAtCvlabDotDe
  • 1,032
  • 5
  • 12
  • 1
    OpenCL on Android doesn't have official support from Google/Android (see: http://stackoverflow.com/questions/14385843/why-did-google-choose-renderscript-instead-of-opencl) but it seems that they aren't preventing the individual CPU/GPU vendors from adding it via their own SDKs. – Morrison Chang Dec 07 '15 at 17:01
  • @Morrison Chang Very good point there. Do you know some examples of vendors doing so? – MarkusAtCvlabDotDe Dec 07 '15 at 17:09
  • Intel has a SDK, I may have mistaken nVidia's CUDA support, and I believe Qualcomm's Adreno SDK has support. Although for the OP's question on mobile I'm leaning toward away from using GPU (big screens = max out GPUs) and taking advantage of the extra CPU cores through the usual C/C++ libraries. – Morrison Chang Dec 07 '15 at 17:20
  • So, in this case, I have to write three different implementation for each platform .. OpenCL (or directly CUDA because it is not standard on Android) for PC, RenderScript for Android and Metal for iOS.. SO I can use OpenCV just for the CUDA part and I have to work on the others myself.. Did I get everything right? – Humam Helfawi Dec 08 '15 at 07:15
  • 1
    @HumamHelfawi Yes, thats how i see that! – MarkusAtCvlabDotDe Dec 08 '15 at 09:19
  • @MarkusAtCvlabDotDe Many Thanks,, I will wait a bit before accepting your answer hopping that somebody will suggest a magic thing that work for all :D – Humam Helfawi Dec 08 '15 at 09:33