Code from GPU not printing on RTX 3070 laptop and Debian 12

Hi NVIDIA support,

I am trying to compile and run a simple Hello World CUDA program on my RTX 3070 laptop and on debian 12. I am using the following code:

#include <stdio.h>

__global__ void kernel() {
  printf("Hello World from GPU!\n");
}

int main() {
  kernel<<<1, 1>>>();
  return 0;
}`

I am using the following commands to compile and run the code:nvcc -arch=sm_86 hello_world.cu -o hello_world ./hello_world

The compilation is successful, but the output is only “Hello World from CPU!”. The message “Hello World from GPU!” is not printed.

I have tried the following steps to troubleshoot the issue:

  • I have checked that my code is correctly written and there are no syntax errors.
  • I have ensured that I am using the correct CUDA architecture for my graphics card.
  • I have tried compiling my code with the latest version of nvcc.
  • I have tried uncommenting the following line in my CUDA code:

printf("Hello World from GPU!\n");

This line prints the message “Hello World from GPU!” on the CPU, which allows me to verify that the CUDA code is correctly written and that it can access the GPU.

  • I have also checked that my NVIDIA graphics card is detected and running using the following command:

nvidia-smi

This output shows that my NVIDIA graphics card is detected and running. nvcc --version too with cuda 11.8 and nvidia driver 545.23.08. (i follow the step of server world to install it link :Debian 12 Bookworm : NVIDIA Graphic Driver : Install : Server World)

I have followed all of these steps and I am still having problems. Can you please help me troubleshoot this issue?

I have updated the post to include the additional information that you provided. I hope this is helpful.

Kernel launches are asynchronous. Your program terminates without waiting for the kernel to finish. You need to call cudaDeviceSynchronize() after the kernel.