0

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?

HONG MAO
  • 1
  • 3

1 Answers1

-1

set the “ CUDA_NVCC_FLAGS” as follow:

set(
        CUDA_NVCC_FLAGS
        ${CUDA_NVCC_FLAGS};
        -g -G
)
HONG MAO
  • 1
  • 3
  • Part of the value of CMake is that you don't have to edit your `CMakeLists.txt` every time you change between a debug and a release build. If you use `cmake -DCMAKE_BUILD_TYPE=Debug` you should already get `-g`. To also get `-G` you could take a look at the answers below [this question](https://stackoverflow.com/q/28732209/10107454). – paleonix Nov 28 '22 at 17:39