5 Replies Latest reply on Sep 9, 2011 4:25 AM by spectral

    OpenCL pointer : c++ equivalent ?

    spectral

      Hi,

      I have a OpenCL structure like this. But how can I define a C++ structure that correspond to this . First, I don't know the pointer size. Secondly, I don't know how align the structure !

      Does someone know ?

      Thanks

       

      typedef struct { .... } MyInfo; typedef struct { __global MyInfo* info; } Task;

        • OpenCL pointer : c++ equivalent ?
          nou

          IMHO it is not legal. i mean that only reason why do you want C++ struct is to set it as kernel argument. AFAIK it is not possible to make kernel argument with pointers.

          • OpenCL pointer : c++ equivalent ?
            notzed

             

            Originally posted by: viewon01 Hi,

             

            I have a OpenCL structure like this. But how can I define a C++ structure that correspond to this . First, I don't know the pointer size. Secondly, I don't know how align the structure !

             

            Does someone know ?

             

            Can't pass structs with pointers to kernels (well you can, it's just data, but the pointer will be meaningless), so just pass 'info' as a separate argument, or include it's content in Task if it isn't kernel-global.  I'm assuming here Task is a kernel argument.

            Should you need to access a lot of objects (e.g. one per thread), accessing arrays of structures is usually inefficient, so you're better off flatting the fields into separate arrays (and/or concatenating them if they are the same type, and/or using the vector types if they are related), each passed as an argument.  This also avoids any questions of alignment.  But it kind of depends on what your'e doing as to whether it's worth it.

             

            • OpenCL pointer : c++ equivalent ?
              rick.weber

              The compiler should handle data alignment for you. As for the structure's size, if you put a pointer in it, it's size will be implementation dependent. That being said, using pointers and expecting them to persist across kernels is dangerous.

              On AMD GPUs, memory addresses can map differently across kernel calls which will screw up your data structures. I would recommend using integer offsets instead of pointers, as integers have a predictable size and you can reindex into the buffer they were allocated in at runtime and get the real address.