LWJGL
June 19, 2013, 07:00:08 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [CLOSED] CL10.clCreateKernelsInProgram doesn't return CLKernel objects  (Read 1475 times)
Dr.Haribo
Newbie
*
Posts: 4


« on: May 15, 2011, 04: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.
Logged
spasi
Nerdus Imperius
*****
Posts: 752



WWW
« Reply #1 on: May 15, 2011, 06:37:16 »

Assuming you have a CLProgram object (called "program" in the examples below), you have two options:

1) Using the high level API:

Code:
CLKernel[] kernels = program.createKernelsInProgram();

2) Using the low level API:

Code:
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.
Logged
Dr.Haribo
Newbie
*
Posts: 4


« Reply #2 on: May 15, 2011, 13:04:27 »

Ah, IDs are what those long values are.  Wink

Thanks for quick and thorough information!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!