Results 1 to 5 of 5

Thread: Structs Into Kernel?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    25

    Structs Into Kernel?

    This seems like a relatively simple question, but I've sourced out pages on Google that says it is OK to do so, and I've sourced out pages that says it's NOT. Which is it, in short?

    OBVIOUSLY, you can't have structs with pointers in it, because you have a memory arena conflict (GPU memory vs host memory), but what about if it's just a struct full of doubles (I have the cl_khr_fp64 extension enabled)?

    Better yet, my exact problem: What if it's a struct of type OUTER, which contains 3 structs of type INNER, which each contain 3 doubles (so 9 doubles is the size of struct OUTER). I feel this should be allowed as it's just contiguous memory and the OpenCL env. is aware of how large the struct is via the struct definitions, and it's copied onto the GPU from the host via a size parameter in WriteBuffer.

    So is it allowed? Or do I have to pass in a pointer to 9 doubles? The reason I want to use structs (obvious encapsulation) is because the types don't always match, so it's easier to throw 5 doubles and 3 ints into a struct than to have a casting fit void* array and it is certainly more flexible if you want to add...but if I can't, I can't.

    I'm having memory issues, and I believe this may be the root (I'm packaging numbers in structs, both the GPU and host are aware of them, no pointers).

    Thanks in advance.

  2. #2

    Re: Structs Into Kernel?

    I can't tell you what's "allowed", but I can tell you that I pass a struct (1128 bytes) into my kernel all day long. No sub-structs within, but arrays of floats, ints, and chars, also scalars of those types. Works just fine on OSX.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    25

    Re: Structs Into Kernel?

    Quote Originally Posted by Photovore
    I can't tell you what's "allowed", but I can tell you that I pass a struct (1128 bytes) into my kernel all day long. No sub-structs within, but arrays of floats, ints, and chars, also scalars of those types. Works just fine on OSX.
    Yeah, it should work fine :-\.

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Structs Into Kernel?

    Sure this is totally supported.

    You just have to make sure both compilers are using the same packing rules. You need to start by using the opencl types on the host side (e.g. use cl_long, cl_int, rather than long, int).

    This is the sort of stuff which goes in - and is in - the specification.

    See section 6.1.1 built in data types of the specification or the c types. And section 6.1.5 alignment of types for packing rules. And section 6.8 restrictions for more detail. And section 6.10 attribute qualifiers for packed/aligned and some more info on structs.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    25

    Re: Structs Into Kernel?

    Quote Originally Posted by notzed
    Sure this is totally supported.

    You just have to make sure both compilers are using the same packing rules. You need to start by using the opencl types on the host side (e.g. use cl_long, cl_int, rather than long, int).

    This is the sort of stuff which goes in - and is in - the specification.

    See section 6.1.1 built in data types of the specification or the c types. And section 6.1.5 alignment of types for packing rules. And section 6.8 restrictions for more detail. And section 6.10 attribute qualifiers for packed/aligned and some more info on structs.
    Alright, I'll look at the memory alignment and use CL types and see what I come up with. Thanks.

Similar Threads

  1. Replies: 10
    Last Post: 11-08-2011, 06:28 AM
  2. structs and function-declaration
    By toneburst in forum OpenCL
    Replies: 0
    Last Post: 01-04-2010, 05:28 AM

Posting Permissions

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