I have the following structure in the host
struct cluster {
double *centroid;
int num_elements;
double *sum_elements;
};
I want to call a CUDA kernel by dynamically allocating shared memory. The shared memory is an array of the above structure. The above structure has also two dynamic arrays that will be allocated dynamically within the kernel, but they are known before hand, let's call the size of the array - d. I tried to call the kernel using:
kernel<<<block, thread, 2*d*sizeof(double) + sizeof(int)>>>
but I found out that the memory size of the a structure is not equal to the sum of the memory size of its elements. My question is: How can I dynamically allocate the shared memory? Thank you.