After CL10.clCreateKernelsInProgram puts a bunch of kernels in a PointerBuffer and returns, I don't see how I can use them. Each kernel is represented by a long and I can't cast that to CLKernel. The longs look like they may be memory addresses, though. Perhaps PointerBuffer should be able to return an object reference?
JOCL implements clCreateKernelsInProgram differently - it has the following signature:
static int clCreateKernelsInProgram(cl_program program, int num_kernels, cl_kernel[] kernels, int[] num_kernels_ret)
An array of kernel objects like this is much more convenient.
Assuming you have a CLProgram object (called "program" in the examples below), you have two options:
1) Using the high level API:
CLKernel[] kernels = program.createKernelsInProgram();
2) Using the low level API:
IntBuffer numBuffer = BufferUtils.createIntBuffer(1);
clCreateKernelsInProgram(program, null, numBuffer);
int num_kernels = numBuffer.get(0);
if ( num_kernels == 0 )
return null;
PointerBuffer kernelIDs = BufferUtils.createPointerBuffer(num_kernels);
clCreateKernelsInProgram(program, kernelIDs, null);
CLKernel[] kernels = new CLKernel[num_kernels];
for ( int i = 0; i < num_kernels; i++ )
kernels[i] = program.getCLKernel(kernelIDs.get(i));
return kernels;
You can of course skip the first call to clCreateKernelsInProgram if you already know the number of kernels in the program.
Ah, IDs are what those long values are. ;)
Thanks for quick and thorough information!