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.
2 comments:
Question: why are you using the *driver* API?
In my current project I need to perform run-time compilation. Have you ever tried it?
http://docs.nvidia.com/cuda/nvrtc/index.html#axzz3mgYJWYeX
Post a Comment