cmakecudacuda-gdb

How to write the CMakeLists.txt file when use cuda-gdb?


my CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(cmake_and_cuda CUDA CXX C)
find_package(CUDA REQUIRED)

set(CMAKE_CUDA_COMPILER /usr/local/cuda-11.4/bin/nvcc)
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} " -g -G ")  # enable cuda-gdb

cuda_add_executable(a a.cu)

my cuda code:

#include<stdio.h>
__global__ void helloFromGPU(void){
    printf("Hello  thread %d!\n",threadIdx.x);
}

int main(void){

    helloFromGPU<<<1,10>>>();
    cudaDeviceReset();
    return 0;
}

then I use CUDA-gdb add a breakpoint at function helloFromGPU(void), but I can't enter the kernel function helloFromGPU(void),program break at the end of the function.

I think the cmake file is not written correctly, how can I modify it?


Solution

  • set the “ CUDA_NVCC_FLAGS” as follow:

    set(
            CUDA_NVCC_FLAGS
            ${CUDA_NVCC_FLAGS};
            -g -G
    )