Variable in constant memory or as parameter

Hello,

I’ve been developing a while in CUDA now, I have a performance question about fixed-variables values.
Suppose I have 2 vectors of size N, what is the best practice to have the size in memory of the GPU,

should I put the size in the constant memory of the GPU?

or

should I pass the size as a parameter to the kernel? in this question there’s another issue, because I was told that if I pass the size as a kernel parameter, the size is repeated as many times as blocks/threads I launch with the kernel.

So what’s the best practice to get the best performance?

Thanks in advance

I don’t think there’s a big performance difference, so I’d just do whatever is more convenient. On compute capability 2.x devices kernel parameters end up in constant memory anyway, it’s just that the copying there is done for you by the driver. On compute capability 1.x parameters end up in shared memory, which is as fast or even faster, but you might want to save the shared memory for better uses.

Thanks for answering. i had that question because I was told that if I pass a variable as a parameter it is repeated all over the memory for each block I launch, I mean if I have the parameter size and launch 1024 blocks I will have 1024 copies of size so I that kept me thinking about and the only solution i found was put the size variable on constant memory. So you say that parameters end up in constant memory so when I launch the kernel automatically all the params are copied to constant memory before starting the execution of the blocks/threads?

Thank you.

P.S. Is there some info about that on the programming guide?

Where the parameters end up depends on the compute capability of the device. For compute capability 1.x devices (i.e up to GTX 3xx) they end up in shared memory and are duplicated per block, as you say. For compute capability 2.x (GTX 4xx and higher) they are copied to constant memory. This is mentioned in Appendix B.1.4.1 of the Programming Guide.

Ok thanks ! that completely resolves my doubt !