Passing array of arrays to OpenCL via JOCL?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing array of arrays to OpenCL via JOCL?

Giovanni Idili
Are you ready for yet another OpenCL/JOCL beginner question?

Here we go: I am in need of passing down to a given kernel an array of arrays, frantically looking for examples but can't seem to find any.

Can I do something like the following?

CLBuffer<CLBuffer<FloatBuffer>> clBufferOfBuffers = new etc.

Or am I better off just passing different buffers one for each of the items I need to pass for a given index?

Any help/advice appreciated.



Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

Michael Bien
  Hello John,

i am afraid but i believe you can't do that with OpenCL yet.
for example a kernel declaration would have to look like:
kernel void compute(global int** array) { }

but that won't compile with current drivers.

OpenCL spec 6.8 Language Restrictions:
"Arguments to __kernel functions in a program cannot be declared as a
pointer to a
pointer(s). Variables inside a function or arguments to non __kernel
functions in a
program can be declared as a pointer to a pointer(s)."

So you will have to find a workaround. You could try to flatten out your
ND buffer in a 1D buffer and calculate the offset in the kernel.
If its rather a small array of buffers but not a ND buffer, you could
just pass every buffer as kernel argument.

a few features which might be useful:
  - you can create CLSubBuffers from CLBuffers if you are using CL1.1
  - (or you could just use a plain CLBuffer, calculate offsets in the
kernel and .slice() the java.util.Buffer for your convenience)

just keep your questions coming :)

best regards,
michael

On 05/10/2011 02:47 PM, John_Idol [via jogamp] wrote:

>
> Are you ready for yet another OpenCL/JOCL beginner question?
>
> Here we go: I am in need of passing down to a given kernel an array of
> arrays, frantically looking for examples but can't seem to find any.
>
> Can I do something like the following?
>
> CLBuffer&lt;CLBuffer&lt;FloatBuffer&gt;>  clBufferOfBuffers = new etc.
>
> Or am I better off just passing different buffers one for each the items I
> need to pass for a given index?
>
> Any help/advice appreciated.
>

Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

Giovanni Idili
Thanks a lot for this Michael,

I think I will pass every buffer as a kernel argument as I need to pass down only a few variable, so I won't bother calculating offsets.

As a matter of interest though, would you be able to point me to an usage example of CLSubBuffers and how they are declared in the __kernel functions?

Best Regards,

Giovanni

Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

Michael Bien
  sub buffers are behaving just like normal buffers and are used in the
kernel like normal global memory.
They are views of certain buffer regions and may even overlap with other
subbuffers.

     CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(64);
     CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(start,
lenght);

CLSubBuffer extends CLBuffer. OpenCL 1.1 does only support creating
subbuffers from buffers, deeper hierarchies are not supported.

(very similar as the java.nio.Buffer.slice() API but you can slice() as
deep as you wish)

best regards,
michael

On 05/10/2011 05:38 PM, John_Idol [via jogamp] wrote:

> Thanks a lot for this Michael,
>
> I think I will pass every buffer as a kernel argument as I need to pass down
> only a few variable, so I won't bother calculating offsets.
>
> As a matter of interest though, would you be able to point me to an usage
> example of CLSubBuffers and how they are declared in the __kernel functions?
>
> Best Regards,
>
> Giovanni
>

Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

Giovanni Idili
I went for separate buffers, but this is very useful info - Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

inayamike
Hi,
I am working with a image processing code (using Image2d class). According to the ImageTest example in jocl i have coded the program but i am facing below exception while executing the kernel?
Attitude
Reply | Threaded
Open this post in threaded view
|

Re: Passing array of arrays to OpenCL via JOCL?

Wade Walker
Administrator
I don't see your exception trace. Does ImageTest fail for you, or is it just your own new code that's failing?