You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by sterg <st...@teiemt.gr> on 2016/04/10 15:25:32 UTC
OpenCL in GroovyLab with aparapi
Hi all,
it seems that OpenCL can be used very easily from GroovyLab
(https://github.com/sterglee/GroovyLab) on Mac OS X.
I only copied the libaparapi_x86_64.dylib native Mac OS X library at the
lib folder and
the aparapi.jar file at the default toolboxes folder.
Then the following example compiles and runs directly
from the Groovy compiler within GroovyLab!!
import com.amd.aparapi.Kernel;
import com.amd.aparapi.Range;
public class Main{
public static void main(String[] _args) {
final int size = 512;
final float[] a = new float[size];
final float[] b = new float[size];
for (int i = 0; i < size; i++) {
a[i] = (float) (Math.random() * 100);
b[i] = (float) (Math.random() * 100);
}
final float[] sum = new float[size];
Kernel kernel = new Kernel(){
@Override public void run() {
int gid = getGlobalId();
sum[gid] = a[gid] + b[gid];
}
};
kernel.execute(Range.create(512));
for (int i = 0; i < size; i++) {
System.out.printf("%6.2f + %6.2f = %8.2f\n", a[i], b[i], sum[i]);
}
kernel.dispose();
}
}
I think that for other platforms that do not have OpenCL preinstalled as
Mac OS X,
things will be a little more complicated, but also simple.
I wrote this mail in order to have opinions on whether
OpenCL fits well to provide portable and easy to use parallel
computation from GroovyLab.
Best Regards
Stergios