nvcc redundant warnings

Sometimes nvcc repeats compile warnings. That’s odd, but even weirder is the number of repeats is inconsistent.

I thought it might have something to do with compiling for multiple architectures even when you just ask for one, but that wouldn’t explain why some warnings appear duplicated at different counts than others.

So for example, here’s a kernel:

__global__ void sumRAM(unsigned int *ptr, unsigned int words, unsigned int *sum)

{   

  int unused_variable=0; // just to invoke a compiler warning

int mysum=0;

  for (int index=threadIdx.x+blockIdx.x*blockDim.x; index<words;

	   index+=blockDim.x*gridDim.x)

	mysum+=__popc(ptr[index]);

if (mysum>0) atomicAdd(sum, mysum);

return;

  return; // can never reach here.. just to invoke a compiler warning 

}

When compiled with [i]nvcc -arch sm_11 cosmic.cu -o cosmic

[/i]

I get repeated compiler warnings:

Note that the “unreachable” statement is repeated 3 times, and the “unused” is repeated twice.

This has been harmless but it’s always bugged me. In particular does it mean that nvcc is compiling more than once and I’m wasting time waiting for the needless multiple compiles?

Code attached if you want to compile yourself. Toolkit 2.3, Linux 64 bit, but I think other platforms do the same.

nvcc: Cuda compilation tools, release 2.3, V0.2.1221
cosmic.cu (2.69 KB)

nm, answered my own questions. If you aren’t using templates then there probably isn’t a good reason for this. It may or may not be compiling the same code multiple times. It could be just that different tools (source-to-source compiler, compiler, assembler) are emitting the same warning. For example, I get the following if I run ‘nvcc cosmic-1.cu -I /usr/local/NVIDIA_GPU_Computing_SDK/sdk/C/common/inc/ -arch sm_11’

cosmic-1.cu(45): warning: statement is unreachable

cosmic-1.cu(35): warning: variable "unused_variable" was declared but never referenced

cosmic-1.cu(45): warning: statement is unreachable

cosmic-1.cu(45): warning: statement is unreachable

cosmic-1.cu(35): warning: variable "unused_variable" was declared but never referenced

but this if I only generate ptx with ‘nvcc cosmic-1.cu --ptx -I /usr/local/NVIDIA_GPU_Computing_SDK/sdk/C/common/inc/ -arch sm_11’

cosmic-1.cu(45): warning: statement is unreachable

cosmic-1.cu(35): warning: variable "unused_variable" was declared but never referenced

cosmic-1.cu(45): warning: statement is unreachable