Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OpenCL on Android?

For plattform independence (desktop, cloud, mobile, ...) it would be great to use OpenCL for GPGPU development when speed does matter. I know Google pushes RenderScript as an alternative, but it seems to be only be available for Android and is unlikely to be ever included in iOS.

Therefore I seek for a solution to execute OpenCL code within Android Apps.

like image 383
Rodja Avatar asked Jan 25 '12 15:01

Rodja


People also ask

Does Android use OpenCL?

Strictly speaking, Android does not support OpenCL. That is Google's (bad) choice. However, you can run OpenCL applications on your Android device if you can get hold of an OpenCL library for it.

What is Windows OpenCL?

OpenCL™ (Open Computing Language) is a low-level API for heterogeneous computing that runs on CUDA-powered GPUs. Using the OpenCL API, developers can launch compute kernels written using a limited subset of the C programming language on a GPU.


2 Answers

The only Android devices I know that support OpenCL are the ones based on the Mali T600 family of chips (article here). They have an OpenCL SDK. Apparently it is OpenCL 1.1 full profile as well.

The Nexus 10 is a device that uses such a chip. The Samsung Exynos 5 dual SoC uses a Mali T604, so anything using this supposedly could be used with the Mali T600 OpenCL SDK (havne't tried any of this myself).

The author of the OpenCL blog is trying to have a go with this, so it might be worth following his series of articles.

But, OpenCL support on Android is brand new (as of 16/2/2013) so, while great for experimentation, it might be worth being cautious until there is more support (who says how buggy the intitial support of OpenCL 1.1 is)

like image 182
prunge Avatar answered Oct 02 '22 20:10

prunge


Although time has passed since the original question was asked, I think this is still a question for a lot of developers.

There are two aspects in the answer. First, unfortunately, Google doesn't support OpenCL officially.

Second, fortunately, many chip vendors provide their libraries to support OpenCL. As the time for now, most of the flagship and middle-tier smartphones (with Qualcomm Adreno GPU, ARM Mali GPU, or Imagination PowerVR GPU) include the OpenCL libraries.

To use OpenCL on Android, there are several steps:

  1. check if there is OpenCL library on the device. This can be done by using OpenCL-Z Android. This is a great tool to check the OpenCL availability on Android devices, and it also provides raw compute performance metrics, which could be very helpful.

The OpenCL libraries for the major chip vendors can be found in the devices: The followings are the location of the OpenCL library:

Qualcomm Adreno:

/system/vendor/lib/libOpenCL.so or /system/lib/libOpenCL.so (older devices) 

ARM Mali:

/system/vendor/lib/egl/libGLES_mali.so or /system/lib/egl/libGLES_mali.so 

PowerVR:

/system/vendor/lib/libPVROCL.so 
  1. Write your OpenCL program using C or C++

  2. Create NDK project to compile your C/C++ code, and test them on the device as executable.

  3. Create JNI interface for your NDK program functions.

  4. Create Android project, using JNI functions in the JAVA code to call native functions involving with OpenCL.

The sony tutorial is a good source to refer. The techniques presented in that tutorial can be applied to any Qualcomm Adreno GPU. With very minimal modification, that code and makefiles can also run on other OpenCL-capable devices (such as Mali and PowerVR).

Hope this helps.

like image 35
Robert Wang Avatar answered Oct 02 '22 19:10

Robert Wang