I seem to understand I cannot pass down/return 2-dimensional arrays in OpenCL (declared smt like float** for example in the kernel signature).

Is there a way to work around this? Can I for example pass-down/return an array of float4 vectors?

Just to give a bit of background, the issue here is that I cannot flatten this data out into separate buffers because it's dynamically determined by one of the other input parameters.

Any help/suggestions appreciated (examples welcome too)!

05-22-2011, 05:37 PM

david.garcia

Re: How to pass/return 2-dimensional arrays in a kernel?

Quote:

I seem to understand I cannot pass down/return 2-dimensional arrays in OpenCL (declared smt like float** for example in the kernel signature).

Right. It is disallowed in section 6.8.

Quote:

Can I for example pass-down/return an array of float4 vectors?

Sure you can. You can also pass arrays of structs.

Quote:

Just to give a bit of background, the issue here is that I cannot flatten this data out into separate buffers because it's dynamically determined by one of the other input parameters.

I don't understand this part. Data can always be flattened. In the very worst case you would need to pass two arguments: one that contains flattened data and another one that is an array of indices into that flattened data.

05-22-2011, 06:04 PM

John_Idol

Re: How to pass/return 2-dimensional arrays in a kernel?

Hi David, first of all thanks for your prompt reply.

Quote:

Sure you can. You can also pass arrays of structs.

you mean I can define a struct and pass it down as a kernel parameter? Sweet, I didn't know (can you point me to any example?).

Quote:

Data can always be flattened. In the very worst case you would need to pass two arguments: one that contains flattened data and another one that is an array of indices into that flattened data.

I see your point, I didn't make myself clear - I meant I cannot flatten it as separate buffers, I would like to avoid having to do that kind of "manual" flattening if I can get away with a float4 array (and in my case I can), but definitely doable.

Thanks for your help!

05-22-2011, 07:39 PM

david.garcia

Re: How to pass/return 2-dimensional arrays in a kernel?

Quote:

you mean I can define a struct and pass it down as a kernel parameter? Sweet, I didn't know (can you point me to any example?).

Yes, it's just like passing any other pointer to a kernel. Be careful with alignment as it may be different on the host and the device.