-1

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.

1
  • 2
    It's unclear what you are asking. This line: dataShared[v] = &dataShared[...] doesn't make sense, as you're assigning a value of a pointer type to an array element of type double. I seriously doubt there is an issue with CUDA. You may want to try to come up with a solution for plain C first. It would certainly work for CUDA too. In order to get meaningful answers you will need to post more code and/or to explain your intent better. It may also be a XY problem, so you might want to add some more information about the context of the problem you are trying to solve Commented Nov 22, 2016 at 2:42

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.