JavaCL problem

I have a problem with JavaCL , not sure if i’m doing somthing wrong or is it a bug. Here is my code :

public class CLProcessor {
    private static String source ="__kernel void add(__global const float* src_a,"+
                                                    "__global const float* src_b,"+
                                                    "__global float* res)"+
                                                    "{const int idx = get_global_id(0);"+
                                                    "res[idx] = src_a[idx] + src_b[idx];}";

    static void process(){
        CLContext clContext = JavaCL.createBestContext();
        CLQueue queue = clContext.createDefaultQueue();
        ByteOrder byteOrder = clContext.getByteOrder();

        int n = 1;
        FloatBuffer bFloatBuffer = NIOUtils.directFloats(n * 4, byteOrder);
        FloatBuffer aFloatBuffer = NIOUtils.directFloats(n * 4, byteOrder);
        aFloatBuffer.put(2.0f);
        bFloatBuffer.put(1.0f);
        CLBuffer<Float> aBuffer = clContext.createFloatBuffer(CLMem.Usage.Input,aFloatBuffer,true);
        CLBuffer<Float> bBuffer = clContext.createFloatBuffer(CLMem.Usage.Input,bFloatBuffer,true);

        CLBuffer<Float> rBuffer = clContext.createFloatBuffer(CLMem.Usage.Output,n);

        CLProgram clProgram = clContext.createProgram(source).build();
        CLKernel clKernel = clProgram.createKernel("add");
        clKernel.setArgs(aBuffer,bBuffer,rBuffer);
        CLEvent clAdd = clKernel.enqueueNDRange(queue,new int[n]);
        FloatBuffer rFloatBuffer = rBuffer.read(queue,clAdd);
        System.out.println(rFloatBuffer.get(0));


    }
}

The problem is that the result of rFloatBuffer.get(0) is 0.0 while it should 3.0.

Hello

This forum is about JOCL from http://jocl.org/ . If you have questions specifially about JavaCL, you might want to ask at http://groups.google.com/group/nativelibs4java or contact Olivier directly.

However, I tried to find potential errors in the code. Unfortunately, the API Documentation does not say much about certain methods, for example, whether they are blocking or not, or whether, for example, “clContext.createFloatBuffer” takes into account the position and limit of the given FloatBuffer (in this case, you should not use
aFloatBuffer.put(2.0f);
but
aFloatBuffer.put(0, 2.0f);
but that’s not clear)

I also tried to compare this example to the Vector Addition Sample from the JavaCL website, and some aspects seem to be different (although the program should do the same). Maybe you can use the program from the website: If it works, you can probably find out what was wrong with your code. If it does not work, Olivier will most likely update it quickly when you tell him about that.

Sorry that I can’t help any further at the moment