I am a newbie of cuda c programming, and I have some problems in debugging cuda codes on WSL2.
I have installed cuda toolkit 12.3 on my WSL2 and my driver version is 545.33
Here is a simple cuda code:
# script.cu
#include<stdio.h>
__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;
}
I firstly compiled the cuda codes with command:
nvcc -g -G -O0 -arch compute_86 -o script script.cu
And I used cuda-gdb
:
cuda-gdb script
I tagged a breakpoint on hello_world<<<1,10>>>();
and when I approached that line, an error raised:
And I have tried using vsode for debugging also and here are the launch.json
and tasks.json
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Current Dir",
"type": "cuda-gdb",
"request": "launch",
"program": "${workspaceFolder}/script",
"debuggerPath": "/usr/local/cuda-12.3/bin/cuda-gdb",
"preLaunchTask": "mynvcc"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "mynvcc",
"type": "shell",
"command": "nvcc",
"args": [
"-arch",
"compute_86",
"-g",
"-G",
"-O0",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"${file}"
]
}
]
}
And the debugging is stucked at return ::cudaLaunchKernel((const void *)func, gridDim, blockDim, args, sharedMem, stream);
Can someone help me?
BTW, I also tried debugging on the cuda docker container (built by nvidia official image) with cuda-11.0 and it works properly.
So seems the problem is related to WSL2 or cuda-12.3?