Multiple static variables

I had a hard to track down bug that orginated from the fact that I had two static device variables with the same name in different .cu files. It seems that cudaMemcpyToSymbol accessed one variable and the kernel the other. Do every variables have to be uniqely named in a program even if you use static and have the variables in different .cu files?

I don’t know of any hard rules. This is pure speculation, but it would seem logical that the file scope symbol tables emitted by the compiler get loaded into some sort of name space associated with a runtime context. Because there is no global linker, symbol conflicts can’t be detected at compile/link time. How the context manages name conflicts (if it even tries) is anyone’s guess, but I would suggest it is good practice to try and keep unique names wherever possible for things like texture references, constant memory variables and global memory symbols.

Yes, they need to have different names. An upcoming toolkit release is going to start checking for this and yelling very loudly if you try to circumvent this.

@Olsson,

Vowie! I am surprised you debugged this… Very tricky one…