OpenCL on the Nexus 10, A Simple Example

>> Saturday, February 23, 2013

It's taken a while, but I finished coding an Android app that uses OpenCL to access the Mali GPU on the Nexus 10. It's not exciting, but here's the code for the top-level Activity:

public class TestNdkActivity extends Activity {

  static {
    System.load("/system/vendor/lib/egl/libGLES_mali.so");
    System.loadLibrary("TestNDK");
  }

  private native int getNumDevices();

  public void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.testndk);
    TextView tv = (TextView)findViewById(R.id.tv);
    tv.setText("Number of connected devices: " + getNumDevices());
  }
}

To execute, the application needs two shared libraries: libGLES_mali.so and libTestNDK.so. The first can be found in the /system/vendor/lib/egl directory on the Nexus 10. The second is compiled by ndk-build using the following makefile (Android.mk):
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE      := TestNDK
LOCAL_C_INCLUDES  := $(LOCAL_PATH)/../include
LOCAL_LDLIBS      := $(LOCAL_PATH)/../external/libGLES_mali.so
LOCAL_SRC_FILES   := test_ndk.c
LOCAL_ARM_MODE    := arm

include $(BUILD_SHARED_LIBRARY)

To get the compilation to work, I put a copy of libGLES_mali.so in the project's 'external' directory. I also copied the $MALI_SDK/include/CL folder into the project's 'include' directory. There must be a better way to do this.

Here's my simple JNI code (test_ndk.c). It finds the first OpenCL platform and returns the number of available devices.
#include <CL/cl.h>
#include "test_ndk.h"

JNIEXPORT jint JNICALL Java_com_testndk_TestNdkActivity_getNumDevices
  (JNIEnv *env, jobject obj) {

    cl_platform_id platform;
    cl_device_id device;
    cl_uint num_devices;

    clGetPlatformIDs(1, &platform, NULL);
    clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, NULL, &num_devices);
    return num_devices;
}

When I run the app, the TextView tells me that one device is connected. I'll try to get a more interesting example working in the next few days. For now, I'm content.

Read more...

Update

>> Sunday, February 17, 2013

I just got back from a training class, so I haven't had time to try out OpenCL on the Nexus 10. But I want to thank everyone who sent me this link, which provides more information. I'll get started tomorrow and I'll post my findings within the week.

On an unrelated note, my favorite book on the history of technology is called Accidental Empires. The author, Robert Cringely, has freely released the first few chapters on his site, and he may release the entire book.

Read more...

ARM and OpenCL, Part 2

>> Thursday, February 7, 2013

I've just installed the Mali OpenCL SDK, which makes it possible to execute OpenCL kernels on the Mali GPU (the GPU inside the Nexus 10). I can't wait to get started.

Thank you, ARM!

Read more...

Update

>> Tuesday, February 5, 2013

I apologize for being distant but I'm still coming up to speed on Android/ARM programming. Not much has happened lately, but here are some points of interest:

  • Amdahl Software has released their CodeBench tools. Free trials are available.
  • This fascinating blog entry discusses Renderscript development from the perspective of an OpenCL/CUDA developer.
  • This blog entry discusses why we should use WebGL, a topic I've wondered about for some time.

Read more...

  © Blogger template Werd by Ourblogtemplates.com 2009

Back to TOP