When I compile code with device type functions the compiler gives me a warning that the device has been defined but not used. Specifically for the file
//main.cu
#include <stdio.h>
#include <stdlib.h>
__device__ void d_test(int *buf, int indice)
{
buf[indice] *= 2;
}
__global__ void g_test(int *buf)
{
int indice = threadIdx.x + blockDim.x*blockIdx.x;
buf[indice] = indice;
d_test(buf,indice);
}
int main()
{
int i;
int buf_size = 100;
int num_blocks = 10;
int threads_per_block = 10;
int *buf_d;
int *buf_h = (int *)calloc(buf_size, sizeof(*buf_h));
cudaMalloc( (void **) &buf_d, buf_size*sizeof(*buf_d) );
g_test<<< num_blocks, threads_per_block >>>( buf_d );
cudaThreadSynchronize();
cudaMemcpy( buf_h, buf_d, buf_size*sizeof(*buf_h), cudaMemcpyDeviceToHost );
for (i=0;i<10;i++)
printf("%d\n",buf_h[i]);
return 0;
}
Which I compile and link using
$ nvcc main.cu -Xcompiler -Wall -o test
I get the warning
In file included from /tmp/tmpxft_0000770d_00000000-1_main.cudafe1.stub.c:2:
main.cu:5: warning: ‘void d_test(int*, int)’ defined but not used
The program runs fine and produces the correct output. I also see this warning when I compile some of the SDK examples. Am I doing something wrong or should I just ignore this message?
Thanks,
David