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.