I would like to organize my CUDA code into separate object files that will be linked at the end of compilation, as in C ++. To do this, I would like to declare an extern pointer to __constant__ memory in the header file and put the definition in one of the .cu files, also following the pattern from C ++. But it seems that when I do this, nvcc ignores "extern" - it takes each declaration as a definition. Is there any way around this?
To be more specific regarding code and errors, I have this in the header file:
extern __device__ void* device_function_table[];
and then in the .cu file:
void* __device__ device_function_table[200];
which gives this error when compiling:
(path).cu:40: error: redefinition of 'void* device_function_table [200]' (path).hh:29: error: 'void* device_function_table [200]' previously declared here
My current solution is to use the magic of Makefile to merge all my .cu files and, in fact, one large translation unit, but some semblance of file organization. But this is already slowing down, compiling noticeably, since a change to any of my classes means recompiling all of them; and I expect to add some more classes.
Edit: I see that I put __constant__ in the text and __device__ in the example; the question concerns both.
source share