Reputation: 131
I am beginner to CUDA and I am trying to allocate shared memory for double data type and pointers to double data types. I am allocating data using
extern __shared__ double dataShared[];
Here at I want pointers to this data at specific places
int v = threadIdx.x;
dataShared[v] = &dataShared[v + (v+1)*data.V];
I want a 2D double data array and 1D pointer array which points to each column of the 2D array in shared memory. Here I am avoiding dynamic allocation of the pointer array due to the performance implications. Here the pointer array is shifted and used to access the columns so that the 2D array would be column shifted as a result.
However this is not allowed and is there any other way I can achieve this. Currently I am working using CUDA 7.5 and it would be better if someone can suggest if there is anything new in CUDA 8.0 to achieve this.
Upvotes: -1
Views: 419
Reputation: 326
You can use 2 different pointers, with different types, to point to the same block of shared memory:
extern __shared__ char dataShared[];
double ** columns = (double **) dataShared; //Here you can store pointers to columns
double * realData = (double *) (dataShared + N * sizeof(double *)); //N is the number of columns
Here you use one block of shared memory, but use different offsets for 2 regions of it (offset 0 for the pointers to columns and offset N * sizeof(double *)
for your actual data).
Upvotes: 3