String lookup error for global variable in CUDA?
I have something like either:
__constant__ double PNT[ NUMCOORDS ];
__device__ double PNT[ NUMCOORDS ];
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"
)?
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.
精彩评论