Can't click "Start CUDA Debugging" (VS2017 + CMake)

I use VS2017 to manage CMake projects. However, CUDA debugger cannot be used.
I can’t click “Start CUDA Debugging” in the menu.

CMakeSettings.txt

{
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [
        "msvc_x64_x64"
      ],
      "buildRoot": "${workspaceRoot}\debug",
      "installRoot": "${env.USERPROFILE}\CMakeBuilds\${workspaceHash}\install\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": ""
    }

CMakeLists.txt

cmake_minimum_required (VERSION 3.8)
project(neural_network LANGUAGES CUDA CXX)

# find cuda
find_package(CUDA)
include_directories(${CUDA_INCLUDE_DIRS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_61,code=sm_61")

if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -std=c++14")
endif()

if (MSVC)
    # warning
    set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=\"/wd 4819\"")

    # static runtime
    # set(CompilerFlags
    #     CMAKE_CXX_FLAGS
    #     CMAKE_CXX_FLAGS_DEBUG
    #     CMAKE_CXX_FLAGS_RELEASE
    #    )
    # foreach(CompilerFlag ${CompilerFlags})
    #   string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    # endforeach()
endif()

# add cuda source
file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/cuda/*.cuh)
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/cuda/*.cu)
file(GLOB PYBIND11_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/python/*.cpp)

source_group("Include" FILES ${HEADERS})
source_group("Source" FILES ${SOURCES} ${PYBIND11_SOURCES})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/cuda)

# add cuda library
add_library(cu STATIC ${SOURCES})
target_link_libraries(cu PUBLIC cuda)

# option
option(WRAP_LIB "wrap library" OFF)
option(UNIT_TEST "unit test" ON)

# wrap library
if(WRAP_LIB)
    # find pybind11
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_parts/pybind11)
    include_directories(${PYBIND11_INCLUDE_DIR})
    if(CMAKE_COMPILER_IS_GNUCXX)
	    set(PYBIND11_CPP_STANDARD "-std=c++14")
    endif()

	pybind11_add_module(neural_network SHARED ${PYBIND11_SOURCES})
	target_link_libraries(neural_network PUBLIC cu)
endif()

# unit test
if(UNIT_TEST)
    # find google test
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_parts/googletest)

    set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/cuda)
    file(GLOB TEST_SRCS ${TEST_DIR}/*.cu)

    add_executable(unit_tests ${TEST_SRCS})
    target_include_directories(unit_tests PRIVATE ${TEST_DIR})
    target_link_libraries(unit_tests gtest_main cu)

    add_test(NAME unit_tests COMMAND unit_tests)
endif()

Hello,

I am not an expert here, but I found this document that might offer some help.

https://docs.nvidia.com/nsight-visual-studio-edition/3.2/Content/Launch_CUDA_Debugger.htm

Best,
Tom
Devtalk Community Manager

Hi, did you find a solution for this? Have you managed to debug using “Start Cuda debugging (next-gen)” on a CMAKE project?

@lior4 @TomNVIDIA

As per the linked thread, this might be a bug which happens because once Visual Studio loads a CMake project it somehow “forgets” to load the NVidia extension.

1 Like

Adding @Elton for support.

Nsight Visual Studio Edition does not currently support directly debugging CMake projects. For now you can work around this by opening the .exe directly in Visual Studio to create an .exe project, which Nsight does support debugging. Once the .exe project is created, you can open the relevant source files and set breakpoints.

1 Like

@Elton thank you for your comment. Any info on when debugging for CMake projects will become available?

As far as I know, CMake has become a first-class citizen on Visual Studio long ago, it is very well integrated in VS What’s new for C++ cross-platform developers in Visual Studio 2022 - C++ Team Blog

@Elton just wanted to ask if there is any info on when debugging for CMake projects will become available?

Thank you.

Hi, @user12396

The debug support for CMake projects should already been enabled.
Please get latest 2023.3.0 or 2023.3.1 to have a try. https://developer.nvidia.com/nsight-visual-studio-edition-2023_3

You’ll see Start CUDA Debugging(Next-Gen) is enabled for CMake project.

This topic was automatically closed after 9 days. New replies are no longer allowed.