LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: Dr.Haribo on May 15, 2011, 11:06:30

Title: [CLOSED] CL10.clCreateKernelsInProgram doesn't return CLKernel objects
Post by: Dr.Haribo on May 15, 2011, 11:06:30
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.
Title: Re: [BUG] CL10.clCreateKernelsInProgram doesn't return CLKernel objects
Post by: spasi on May 15, 2011, 13:37:16
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.
Title: Re: [BUG] CL10.clCreateKernelsInProgram doesn't return CLKernel objects
Post by: Dr.Haribo on May 15, 2011, 20:04:27
Ah, IDs are what those long values are.  ;)

Thanks for quick and thorough information!