OpenCL and Processing

I have done a number of testings with various Java implementations of OpenCL and Processing. The major Java bindings of OpenCL include

The are two major OpenCL libraries for Processing at the time I do the testing, MSAOpenCL using the JavaCL and openclp5 using the JOCL. I do not use the Processing libraries and call directly the Java binding codes. Each of the implementation contains a Hello World example kernel that performs calculation across a large array. In my test, I modify the kernel program to do a multiplication between two floating point numbers with an array size of a million cells.

The sample kernel program code is

__kernel void sampleKernel(__global const float *a,
        __global const float *b,
        __global float *c,
        int n)
{
	int gid = get_global_id(0);
	if (gid >= n)
		return;
	c[gid] = a[gid] * b[gid];
}

I use a MacBook Pro for the testing. The operating system is OSX Lion. It includes the OpenCL implementation in the default OS. The graphics card is Nvidia GeForce 9400M with 256M graphic memory. The Processing version is alpha build 2.0a5 running in 64-bit mode. Various JAR files have to be copied to the code folder. Here is the summary.

JOCL

  • JOCL-0.1.7.jar

Java OpenCL (jogamp)

  • jocl.jar
  • gluegen-rt.jar
  • gluegen-rt-natives-macosx-universal.jar
  • libjocl.dylib

JavaCL

  • javacl-1.0.0-RC2-shaded.jar

I did ten consecutive runs of each implementation. The final figure is an average of the ten runs. Each measurement is taken just before and after the kernel execution. The first implementation (JOCL) has more fluctuated results. The second implementation has only a single command to invoke the kernel execution and passing back the result. Therefore, it is not easy to single out the execution time of the GPU. The third implementation (JavaCL) is obviously the fastest one and more stable in terms of parallel execution.

Performance with one million cells

Implementation ms
JOCL 3.207
Java OpenCL 17.0008
JavaCL 2.9865
CPU 10.952

Performance with half a million cells

Implementation ms
JOCL 3.9424
Java OpenCL 8.5672
JavaCL 2.9354
CPU 9.2368

The source files of the testings can be downloaded here:

3 Replies to “OpenCL and Processing”

  1. Hi Bryan,

    I’ve run your code in Processing with JavaCL 1.0-RC2 and the latest optimized snapshot version (1.0-20120625), here’s what I got :

    JavaCL 1.0-RC2:
    – Time used: 2.763ms
    – Time used: 2.662ms

    JavaCL 1.0-20120625:
    – Time used: 1.865ms
    – Time used: 1.939ms

    (MacBook Pro 15″, Core i7 2.66 GHz, 8 MB ram, NVIDIA GeForce GT 330M)

    Hope you’ll get similar improvements 🙂

    Keep up the good work / hacking!

  2. Hi Bryan,

    Nice post! (being the author of JavaCL, I’m obviously relieved it performed relatively better than the other options you tested ;-))
    FYI I’ve just improved the performance of JavaCL by quite a good margin. It may or may not change the figures you’ve got, but I wanted to make sure you were notified 🙂

    (latest snapshot is available for download from the project’s website)

    Live long and prosper 🙂
    ~Olivier

Comments are closed.