Reputation: 665
EDIT: Realized that I was reinstantiating the cl_context on every iteration. It works now.
Although this is a JOCL specific question, I believe it is applicable to OpenCL in general.
I have a program that sends int arrays to an OpenCL kernel to be processed on the GPU, then returns the results to Java. The program works fine on the first iteration, but when clSetKernelArg is called a second time (with a new array), it throws a CL_INVALID_MEM_OBJECT error.
I don't see why setting a kernel parameter crashes the program on the second iteration only.
Here is a simplified version of the Java code:
... bunch of kernel initialization code that works correctly ...
void doSingleIteration() {
int[] array = new int[length];
fillArrayWithData(array);
cl_mem buf = CL.clCreateBuffer(context, CL.CL_MEM_READ_ONLY,
length * Sizeof.cl_float, null, null);
CL.clEnqueueWriteBuffer(commandQueue, buf, true, 0,
array.length * Sizeof.cl_float, Pointer.to(array), 0, null, null);
CL.clSetKernelArg(kernel, 0, Sizeof.cl_mem, Pointer.to(buf)); // This crashes on the second iteration ONLY??
CL.clEnqueueNDRangeKernel(... this works fine ...)
... some other unrelated code ...
}
doSingleIteration(); // This one is ok
doSingleIteration(); // This one crashes
Here is the header for the corresponding kernel in OpenCL:
kernel void myKernel(global const int* myArray) {
...
}
The only way I have gotten this to work is by reinstantiating the command queue on each iteration. But that is very inefficient. How can I call clSetKernelArg a second time without crashing the program?
Thanks
Upvotes: 0
Views: 382