I have a set of data, buffers and metadata, that I wish to send to a kernel stored in a struct such as

Code :
typedef struct {
  __global float *buffer1;
  __global float *buffer2;
  float value;
  uint numElements;
} ComplexData;
 
__kernel void process(__constant ComplexData *data) {
  ...
}

I tried to make a host side struct where the float pointers were replaced by cl_mems, but that did not work.

Code :
typedef struct {
  cl_mem buffer1;
  cl_mem buffer2;
  float value;
  uint numElements;
} ComplexData;


The application either crashed in clBuildProgram trying to read from address 0x10, or gave garbage when referencing members in the struct. Calling sizeof() on the two structs, one in host code and one in device code, gives different sizes.


What is the correct way to pass a struct like this, or is the only option to send the members one by one?