nvcc compiler can not tell me if an external device variable has been defined.

nvcc compiler can not tell me even if an external device variable has been defined.

nvcc compiler can not tell me the error even if an external device variable has been defined.

For example,

I have the following code,

File: test1.cu

[codebox]

#include <stdio.h>

device constant extern int Adev;

global void test(void)

{

int B;

B=Adev;  

}

int main(void)

{

test<<<1,1>>>();

return 0;

}

[/codebox]

The file can be compiled into an executable file a.exe

nvcc test1.cu

But in fact, as the definiton of external device variable has been defined yet, the executable file a.exe should be incorrect.

In contract, if the host side external is not defined, the compiler will tell me the error and will not generate an executable file.

File: test2.cu

[codebox]

#include <stdio.h>

extern int A;

int main(void)

{

A=1234;

return 0;

}

[/codebox]

Anyone can tell me why and how make the nvcc also tell me the error if I forget the definiton of an external device variable.

Thank you in advance.

There is a simple solution to your issue. You cannot use extern. Check under section 4.2.2.4: Restrictions in the programming guide (2.0). It says that device and constant variables cannot be declared as extern. I believe you will find that if you do so (it has been a while since I checked) that each separate compilation unit get’s its own separate version of the variable.

Now, why the compiler doesn’t generate an error message on documented invalid code is another question entirely.

Regarding the first, see this post.