Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    11

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

    Hi All,

    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)!

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

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

    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.

    Can I for example pass-down/return an array of float4 vectors?
    Sure you can. You can also pass arrays of structs.

    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.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    11

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

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

    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?).

    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!

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

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

    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.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. Support of Multi-dimensional arrays
    By Sheliak in forum Suggestions for next release
    Replies: 1
    Last Post: 10-19-2011, 04:16 PM
  2. Replies: 4
    Last Post: 08-09-2011, 04:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •