Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable breakpoints set in cu and cuh files #4585

Merged
merged 2 commits into from
Nov 12, 2019

Conversation

trxcllnt
Copy link
Contributor

This PR adds a "language": "cuda" entry to package.json breakpoints list to allow setting breakpoints for the vscode-cpptools plugin in .cu and .cuh files.

This new entry shouldn't have any effect on regular users, but should enable breakpoints in .cu and .cuh files for users with the vscode-cudacpp plugin installed. That plugin contributes a CUDA language definition (with "languageId": "cuda"), and handles some of the cuda-specific syntax like the <<< >>> kernel launch parameters.

This PR opts for the minimum changes necessary to get these two plugins working together. An alternate approach is to include the vscode-cudacpp CUDA language definitions in vscode-cpptools itself, which would enable vscode-cpptools to support CUDA out of the box.

In my testing, debugging CUDA is largely already supported by adding the following to any "type": "cppdbg" launch.json debugging configuration:

"MIMode": "gdb",
"miDebuggerPath": "/usr/local/cuda/bin/cuda-gdb",

@sean-mcmanus sean-mcmanus requested review from a team, pieandcakes and WardenGnaw and removed request for a team November 11, 2019 19:54
@sean-mcmanus sean-mcmanus removed the request for review from pieandcakes November 12, 2019 01:33
@sean-mcmanus sean-mcmanus merged commit 2fd3214 into microsoft:master Nov 12, 2019
@pieandcakes
Copy link
Contributor

@trxcllnt Thanks for your PR. We have had some users asking questions about how to configure CUDA debugging. is the vscode-cudacpp extension a good place for them to go and ask questions? I don't have experience with CUDA debugging at all.

@trxcllnt
Copy link
Contributor Author

@pieandcakes I can't say one way or the other. vscode-cudacpp doesn't seem actively maintained, but it does still work for CUDA 10.1 syntax highlighting.

I use vscode-cudacpp for syntax highlighting, vscode-clangd (and clangd-10) for C/C++/CUDA intellisense, and vscode-cpptools for debugging. vscode-clangd and vscode-cpptools intellisense tend to clash, so I disable vscode-cpptools intellisense with these options:

// Place this in either `settings.json` or `some_workspace.vscode-workspace`
        "C_Cpp.formatting": "Disabled",
        "C_Cpp.autocomplete": "Disabled",
        "C_Cpp.errorSquiggles": "Disabled",
        "C_Cpp.intelliSenseEngine": "Disabled",
        "C_Cpp.configurationWarnings": "Disabled",
        "C_Cpp.autoAddFileAssociations": false,
        "C_Cpp.vcpkg.enabled": false,

After that, I have a custom build step to generate a .vscode/launch.json file that looks like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug C++ and CUDA tests",
            "type": "cppdbg",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "envFile": "${workspaceFolder}/.env",
            "program": "${workspaceFolder}/build/gtests/${input:TEST_NAME}",
            "MIMode": "gdb", "miDebuggerPath": "/usr/local/cuda/bin/cuda-gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ],
    "inputs": [
        {
            "id": "TEST_NAME",
            "type": "pickString",
            "description": "Please select a test to run",
            "options": ["TEST_1","TEST_2","TEST_3","TEST_4"]
        }
    ]
}

Having this as part of the build means the test names are automatically inserted into the "inputs" list, so clicking the debugger button opens up the dropdown to select a test, rather than having to manually type each test name by hand.

Hope this helps,
Paul

@vakokako
Copy link

Hey @trxcllnt, idk if it's a right place for it, but could you share how you use clangd with cuda files, since cmake doesn't provide compile_commands.json for .cu files?

@trxcllnt
Copy link
Contributor Author

@friendnick CMake should include .cu files in the compilation database if you do enable_language(CUDA) (or add LANGUAGES CUDA to your project() declaration).

@vakokako
Copy link

@trxcllnt do you tweak cuda compiler setting in cmake to use clang then?

by default cmake uses nvcc and then clangd fails to translate that to clang, giving "Language no recognized: 'cu'" error

@trxcllnt
Copy link
Contributor Author

trxcllnt commented May 13, 2020

@friendnick ah right. No, we use gcc and nvcc in CMake (with the -GNinja cmake generator), but we have to massage the compile_commands.json output after the configure step to translate a few of the nvcc-specific flags to ones that clang understands.

Here's a quick run-down of the setup:

  • First, I recommend using the clangd dev releases (currently clangd-11) from apt.llvm.org.
    Here's the TLRD install command for Debian/Ubuntu.
  • See the cpp/CMakeLists.txt in any of the RAPIDS repositories for general guidance on our CMake and CUDA configurations (cuDF's is the most complex).
  • Here's the bash function of sed commands we run post-configure to fix compile_commands.json. CMake prior to 3.17 has a bug with the Ninja generator where it put the entire $PRE_LINK && /usr/bin/g++ ... command into compile_commands.json, but this script corrects that too.

That bash script also has some other things in it you may find useful like CCaching for nvcc. You have to use CMake>=3.17.0 and ccache 4.0 (currently only available if built from master), then set the compiler symlinks manually (unfortunately using update-alternatives to switch to ccache doesn't work for nvcc like it does for gcc/g++).

@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants