Frage

I want to pass a structure to opencl kernel, the structure is

struct test
{
    int *x;
    float *y;
    char *z;
};

and the memory allocation and initialization is like

    struct test t;
t.x = (int*)malloc(sizeof(int)*100);
t.y = (float*) malloc (sizeof(float)*50);
t.z = (char*) malloc (sizeof(char) *25);
  for(i = 0;i<100;i++)
  {
      t.x[i] = i;
      if(i<50)
          {
              t.y[i] = i;
          if(i<25)
              t.z[i] = 'a';
          }
  }

can i pass such a structure to opencl kernel

War es hilfreich?

Lösung

You can pass such a structure, but it will be pointless because x, y and z point to different memory regions. Each of these memory buffers must be transferred on its own.

Andere Tipps

Instead of structure, its better to allocate memory at the host side and send them to kernel as kernel parameters.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top