cudaMemcpyToSymbol do only once at startup?

Hi -

I have several kernels that are called many times (300-500) by a C program. Right now, each time the kernel runs, it sets constant values using cudaMemcpyToSymbol.

  1. Just wondering if I can just do this once before I being the big loop.

  2. Also, I noticed that separate kernels can’t have the same constant variables names so are device constants like globals? However, I couldn’t figure out how to share the same device constant among different kernels (ie: like a constants.h).

Thanks in advance.

Yes, you only need to call cudaMemcpyToSymbol once to update the device memory. The contents will stay for the lifetime of your cuda context (probably the lifetime of your program).

The only way I’ve ever been able to share constant memory between kernels is when all kernels were compiled in the same .cu file.