I need to write the code into several .cu files. But where should I define the device variables which are use for many .cu files.
An example
File common.h
__device__ int x;
File A.cu
__global__ void a()
File B.cu
__global__ void b()
a(),b() both use x. what should I do?
In C language, I should write something like
extern device int x;
Then I define device int x in another place. But in CUDA I can not do it. If I do, it tells me ‘……….’ previously declared here
EDIT : @talonmies was right (as usual). So I’ve deleted my comment about CUDA 4.1
Furthermore the compiling commands I gave were not quite right. So let me replace my answer with one that demonstrably works and has the proper instructions.
You need CUDA 5.0 and a compute capability 2.0 or greater device for this to work.
I’m sure there’s probably a better way, but this seems to work for me:
com.h:
a.cu:
b.cu:
compiling:
output:
Sorry for my previous errors.