tim
tim

Reputation: 10186

String lookup error for global variable in CUDA?

I have something like either:

depending upon some preprocessor selections. I then use this variable:

cudaMemcpyToSymbol("PNT", point, pntSize)

However, sometimes (and I really CAN'T say when which really confuses me) I get the error message:

duplicate global variable looked up by string name

when checking for CUDA errors. I tried replacing "PNT" with PNT and strangely, this works:

cudaMemcpyToSymbol(PNT, point, pntSize)

Shound I use this solution in practice (instead of using a string "PNT")?

Upvotes: 0

Views: 875

Answers (1)

talonmies
talonmies

Reputation: 72372

The underlying problem has nothing to do with cudaMemcpyToSymbol. The error you are seeing is generated by the CUDA runtime when it searches for the symbol you have supplied because it is multiply defined in the context in which your code is running. CUDA runtime versions have been getting progressively better at detecting duplicate definitions (things like __constant__ declarations, textures, __device__ functions).

The solution is to refactor your code so that symbols are only ever defined once within an application. Because CUDA doesn't have a linker, there will be no compilation time errors if you define a symbol in two files. But when the CUDA runtime loads the resulting binary payloads from the final linked application into a context, duplicate symbol conflicts can occur and runtime errors can result.

Upvotes: 3

Related Questions