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