groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterg <>
Subject OpenCL in GroovyLab with aparapi
Date Sun, 10 Apr 2016 13:25:32 GMT
Hi all,

it seems that OpenCL can be used very easily from 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];


       for (int i = 0; i < size; i++) {
          System.out.printf("%6.2f + %6.2f = %8.2f\n", a[i], b[i], sum[i]);



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

View raw message