I create two float buffers like so
int size = 1;
inputBuffer = BufferUtils.createFloatBuffer(size);
while (inputBuffer.position() < inputBuffer.capacity()) {
inputBuffer.put(-1.0f);
}
inputBuffer.rewind();
inputMemory = CL10.clCreateBuffer(clContext, CL10.CL_MEM_READ_WRITE, inputBuffer, clErrorBuffer);
outputBuffer = BufferUtils.createFloatBuffer(size);
outputBuffer.rewind();
outputMemory = CL10.clCreateBuffer(clContext, CL10.CL_MEM_READ_WRITE, outputBuffer, clErrorBuffer);
then in my kernel I have
kernel void myKernel(global const float* input, global float* output){
if(input[0] < 0.0f){
output[0] = 1;
} else {
output[0] = 2;
}
}
When I retrieve output[0] in java later it is always 2. Any idea why this is? I explicitly set the input buffer to be -1 for all values, and then in the kernel if input[0] is less than 0, which it should be, set output[0] to 1.
You are missing the CL_MEM_COPY_HOST_PTR flag for clCreateBuffer (or use clEnqueueWriteBuffer). See the documentation:
https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clCreateBuffer.html
That should probably be it. However, it would still be interesting to see how you set the buffer argument to the kernel parameter.
That did the trick! Thanks!
also
clSetKernelArg1p(clKernel, 0, inputMemory);
clSetKernelArg1p(clKernel, 1, outputMemory);