cudaMemcpyToSymbol(symbol, &variable, sizeof(variable));
Piace of cake. But how does it work with the CUDA driver API? Well, it is not clearly explained in the programming guide (at least, I couldn't find any examples). It turns out that the process requires two steps:
- get a reference to the __constant__ variable in the device;
- initialize it using a memcpy "Host to Device".
CUdeviceptr constDevPtr;
cuModuleGetGlobal(&constDevPtr, NULL, module, "symbol");
cuMemcpyHtoD(constDevPtr, &variable, sizeof(variable));
I tested the code above and it works seemlessly. I hope this will save some headaches to CUDA developers.