3 Replies Latest reply on Oct 29, 2009 1:53 AM by david_aiken

    structure navigation

    david_aiken

      hi all..

      I'm passing in an array of structures, with the size of each structure to a kernel. The first member of the structure is a uint and i would like to be able to change only this member within the kernel. I've tried this:

      typedef struct

      {

      unsigned int dataOfInterestToKernel;

      char s[64] notOfInterestToKernel;

      }AStruct;

      AStruct data[40];

      call clEnqueueNDRangeKernel with pointer to data[], sizeof(AStruct) using 40 threads.

       

       

      __kernel void test(__global char *structData, uint structSz)

      {

          uint ndx = get_local_id(0);

          uint* s = (uint*)(structData + ndx *structSz);

          *s = ndx;

      }



      Unfortunately the kernel doesn't build:

       

      error: invalid type conversion

            uint* s = (uint*)(structData + ndx * structSz);



      Is there a good way to do this? It is possible to do it in CUDA.

        • structure navigation
          RyFo18

          I've done this before.  I'm not sure how you have your OpenCL code laid out.  I typically have all of mine in a separte file (i.e. hello.cl).  If I pass a structure to a kernel such as the one you suggested, I will also declare this same structure within hello.cl.  Then you can change the value simply by:

           

          structData[ndx]->dataOfInterestToKernel = ndx;

          • structure navigation
            MicahVillmow
            david_aiken,
            The problem is you are converting between address spaces, which is illegal in OpenCl. The correct way to do this is as follows:
            __kernel void test(__global char *structData, uint structSz)
            {
            uint ndx = get_local_id(0);
            global uint* s = (global uint*)(structData + ndx *structSz);
            *s = ndx;
            }