cudaMemcpyToSymbol using or not using string
c, c++, cuda
Solution
As of CUDA 5, using a string for symbol names is no longer supported. This is covered in the CUDA 5 release notes here
•The use of a character string to indicate a device symbol, which was possible with certain API functions, is no longer supported. Instead, the symbol should be used directly.
One of the reasons for this has to do with enabling of a true device linker, which is new functionality in CUDA 5.
Problem
I was trying to copy a structure to constant memory in this way: ``` struct Foo { int a, b, c; }; __constant__ Foo cData; int main() { Foo hData = {1, 2, 3}; cudaMemcpyToSymbol(cData, &hData, sizeof(Foo)); // ... } ``` And this worked fine, in my kernel I could access the constant data directly: ``` __global__ void kernel() { printf("Data is: %d %d %d\n", cData.a, cData.b, cData.c); // 1 2 3 } ``` But then I tried to use a `const char *` as symbol name, and things stopped working: ``` cudaMemcpyToSymbol("cData", &hData, sizeof(Foo)); // prints 0 0 0 ``` I thought both versions were similar, but it seems I was wrong. What is happening? EDIT: I'd like to report this same behavior with cudaGetSymbolAddress, which works for me if no `const char *` is used: ``` __constant__ int someData[10]; __constant__ int *ptrToData; int *dataPosition; cudaGetSymbolAddress((void **)&dataPosition, someData); // Works // cudaGetSymbolAddress((void **)&dataPosition, "someData"); // Do not work cudaMemcpyToSymbol(ptrToData, &dataPosition, sizeof(int *)); ```