In order to debug a GPU kernel with cuda-gdb, we add -G -O0 to nvcc command line, which in case of CMake would be:


In HIP it is done differently, because the compiler is a Clang flavor, and inherits its behavior. The HIP frontend compiler invokes backend compilers (which are also clang++) by itself. Therefore, the frontend clang++ needs -Xclang to forward the options down to the backends:

set(CMAKE_HIP_FLAGS_DEBUG "-ggdb -fstandalone-debug -Xclang -O0 -Xclang -gcodeview" ${CMAKE_HIP_FLAGS})

Note the debugging must always be performed with roc-gdb, even for the host code, because HIP’s Clang and GCC these days tend to use incompatible debugging formats. As a result, you should get a beautiful debuggable code in TUI:

alt text