Cuda-gdb cannot run properly on WSL2

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:
image

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?

Hi, @karhoutam

We canā€™t reproduce your issue using CUDA12.3+WSL+Ampere card. Please see below.

test@cqa-r2-2:~$ cd 284763/
test@cqa-r2-2:~/284763$ ls
script.cu
test@cqa-r2-2:~/284763$ nvcc -g -G -O0 -arch compute_86 -o script script.cu
test@cqa-r2-2:~/284763$ ./script
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!
test@cqa-r2-2:~/284763$ cuda-gdb script
NVIDIA (R) CUDA Debugger
CUDA Toolkit 12.3 release
Portions Copyright (C) 2007-2023 NVIDIA Corporation
GNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
ā€¦
(cuda-gdb) set cuda break_on_launch app
(cuda-gdb) r
Starting program: /home/test/284763/script
[Thread debugging using libthread_db enabled]
Using host libthread_db library ā€œ/lib/x86_64-linux-gnu/libthread_db.so.1ā€.
CPU: Hello world!
[New Thread 0x7ffff6dff000 (LWP 1115)]
[New Thread 0x7ffff5b21000 (LWP 1116)]
[Detaching after fork from child process 1117]
[New Thread 0x7ffff4fff000 (LWP 1125)]
[Thread 0x7ffff4fff000 (LWP 1125) exited]
[New Thread 0x7ffff4fff000 (LWP 1126)]
[Switching focus to CUDA kernel 0, grid 1, block (0,0,0), thread (0,0,0), device 0, sm 0, warp 0, lane 0]
hello_world<<<(1,1,1),(10,1,1)>>> () at script.cu:4
4 printf(ā€œGPU: Hello world!\nā€);
(cuda-gdb) s
hello_world<<<(1,1,1),(10,1,1)>>> () at script.cu:5
5 }
(cuda-gdb) info cuda devices
Dev PCI Bus/Dev ID Name Description SM Type SMs Warps/SM Lanes/Warp Max Regs/Lane Active SMs Mask

  • 0 03:00.0 NVIDIA GeForce RTX 3070 GA104-A sm_86 46 48 32 256 0x000000000001
    (cuda-gdb)

My GPU is nvidia rtx 3070 laptop gpu and my wsl2 is ubuntu 22.04. I have tried debugging in the same way but on docker container (with ubuntu 20.04 and cuda-11.0) and cuda-gdb works properly.

Is some incompatible issues in wsl2 or ubuntu 22.04? I installed cuda 12.3 on my wsl2 in deb(network) way.
Or maybe I missed something?

Please make sure this capability is enabled via the registry key >HKEY_LOCAL_MACHINE\SOFTWARE\NVIDIA Corporation\GPUDebugger\EnableInterface set to (DWORD) 1

Refer CUDA-GDB

cannot find the GPUDebugger folder
image

Please create 1 if you donā€™t have. (I think you didnā€™t install cuda toolkit on your windows)

1 Like

Problem solved!
Thanks for your help!

Greatļ¼ Thanks for the update ļ¼

BTW, is it necessary to install cuda on win10 also (I barely code on win10)?
I only code on my WSL2 ubuntu.

Yes. CUDA can be installed on Win10.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.