Search code examples
c++visual-studio-2012cudanvcc

CUDA Multiple Compiler Warnings


I have been developing with CUDA v6.5 in Visual Studio 2012 and have run into a problem: When compiling a .cu file the compiler will output multiple warnings for a single line of source code. Normally this wouldn't be a huge deal, but it has started taking a very long time to build and I suspect this might be why. For example:

int unused = 0;

generates the following error four times:

1>.../GeometryManager.cu(188): warning : variable "unused" was declared but never referenced

These are the command line arguments that are being passed to nvcc:

-gencode=arch=compute_35,code=\"sm_35,compute_35\" --use-local-env --cl-version 2012
-ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"
-G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile
-cudart static -arch sm_20  -g   -DNDEBUG -DWIN32 -D_DEBUG -D_CONSOLE
-D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd  "
-o Debug\GeometryManager.cu.obj "C:\...\GeometryManager.cu" 

When compiling .cpp files, warnings seem to be issued normally. So far I tried changing the value for Code Generation in properties to compute_35,sm_35, (it previously had several of these listed) but it didn't help.

I'd appreciate if someone with CUDA or nvcc experience could shed some light on the situation. Any other advice on how to reduce build times with CUDA would be helpful as well. Thanks.


Solution

  • On reason it generates the warning multiple times is because it is compiling your code multiple times due to the specification of multiple targets:

    -gencode=arch=compute_35,code=\"sm_35,compute_35\"
    

    and

    -arch sm_20
    

    If you don't need both sets of targets, you can reduce the warning messages produced and shorten your compile time by deleting one of these (i.e. removing it from your visual studio project configuration). (I think you'll end up with 2 sets of warnings instead of 4, in this case.)