Register or shared memory?

Hi to all,

I am asking myself if is general better using register or shared memory? I think they have approximatively same speed… Any consistent difference?
Thank you!

I’d assume that registers are faster but they are also fewer (in terms of amount of data storage) of them. The other big thing to consider is shared memory bank conflicts, you don’t have to worry about those with registers.

Using it for what?

Register memory is truly local to each thread, whereas shared memory is, well, shared by all threads in a block, so you can easily have memory races within a block if you don’t know what you are doing with shared memory.

On a 1.1 capable device, you can have a maximum of 8192 registers (ie. 32kb) per block, but only 16kb of shared memory. On 1.3 capable devices, the register count limit increases to 16384 (ie. 64Kb) per block, but the shared memory stays at 16kb per block. So while registers can be critical in maintaining high occupancy, there is, in fact, more register space than shared memory space.

Thank you,

you are very kind and helpful! I am writing a program in which I need a lot of resources… Now I am using 51 registers and 16128bytes shared memory, with 304 threads in order to obtain a decent occupancy (1.3 capable device).

I need all of this space because I have to calculate N*N functions which argument is equal to distance (rij) between N points times a parameter (q), something like this:

I += f[ q * rij ]

problem is that I need:
threadNumber * float4 bytes of shared memory for calculating distances

and all remaining resources (registers and shared memory) for calculating q - loop. Now I am able to calculating only 36 q - points for every kernel launch at time, but I need at least 1000 q - value.
So my bottleneck now is lack of resources and I am trying to find a way to remove this limitations. But is not easy! :)
So I am looking for a smarter way to use register and / or shared memory. And so the question!

Thank you! And if you have any suggestion, please, I would be thankful!

Wow, I guess I really didn’t think about that…toooo early in the morning. Thanks for the correction avidday!