How can I make each thread in the thread block has his own pointer to shared memory? I found some example of declaration of such pointers:
int __shared__ *p;
__shared__ int array[256];
p = &array[threadId];
Is this right or is there another way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No that is not the correct way. In that example code,
pis shared so it means that every thread in the block would be trying to access the same piece of memory. You could do it like this ifthreadIdwas the unique thread index with the block:In this case the compiler would use either a register or thread local memory to store the unique address of an element in static shared memory allocation
arrayfor each thread in the block.