I am using the “HelloWorld” example on “Google Code Archive - Long-term storage for Google Code Project Hosting.”.
But when compiling it I got a warning and there are some problems about the output, I don’t know how to fix it. Can anyone help me? I am very appreciated about it .
In Terminal:
LINtekiiMac:Hello_world linyu$ nvcc hello_world.cu -o hello_world
util/cuPrintf.cu: In function ‘int outputPrintfData(char*, char*)’:
util/cuPrintf.cu:607: warning: format not a string literal and no format arguments
util/cuPrintf.cu:607: warning: format not a string literal and no format arguments
LINtekiiMac:Hello_world linyu$ ./hello_world
Hello, world from the host!
I don’t know why i didn’t get the output of “hello, world from the device!”
I’m not sure why you’re getting that error.
Also note that Appendix B.17 of the CUDA 5.5 C Programming Guide has a more up to date example that demonstrates how to use the newer printf() facility.
The code winds up looking like this:
#include <stdio.h>
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 200)
#error printf is only supported on devices of compute capability 2.0 and higher, please compile with -arch=sm_20 or higher
#endif
__global__ void device_greetings()
{
printf("Hello, world from the device!\n");
}
int main(void)
{
// greet from the host
printf("Hello, world from the host!\n");
// launch a kernel with a single thread to greet from the device
device_greetings<<<1,1>>>();
cudaDeviceSynchronize();
return 0;
}
Compile with this:
nvcc -m 32 -arch sm_20 hello.cu -o hello