环境 WSL2 + Ubuntu 22.04 + CUDA Toolkit 12.2 我们来编写一个`Hello World`程序。 代码: ```c /* *hello_world.cu */ #include __global__ void hello_world(void) { printf("GPU: Hello world!\n"); } int main(int argc,char **argv) { printf("CPU: Hello world!\n"); hello_world<<<1,10>>>(); cudaDeviceReset();//if no this line ,it can not output hello world from gpu return 0; } ``` 编译: ``` root@FF-ACER:~/demo# nvcc -arch sm_60 hello_world.cu -o hello_world ``` 运行: ```bash root@FF-ACER:~/demo# ./hello_world CPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! GPU: Hello world! ```