clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.55k stars 65 forks source link

Clangd gives wrong errors when working on a cuda project. #1938

Closed TaelinSu closed 8 months ago

TaelinSu commented 8 months ago

When I use clangd as the LSP in VSCode to write cuda codes, clangd gives such errors:

My NVIDIA GPU is GeForce RTX 3070Ti, which compute capability is 8.6(sm_86).

The cuda project builds OK. This is compile_commands.json file in my project:

[
    {
        "directory": "/home/sirius/code/cpp/cuda-test",
        "arguments": [
            "/usr/local/cuda/bin/nvcc",
            "-c",
            "-Xcompiler",
            "-fPIE",
            "-O3",
            "-I/usr/local/cuda/include",
            "-m64",
            "-rdc=true",
            "-gencode",
            "arch=compute_86,code=sm_86",
            "-o",
            "build/.objs/cuda-test/linux/x86_64/release/src/main.cu.o",
            "src/main.cu"
        ],
        "file": "src/main.cu"
    }
]

I use xmake as my project build tools, compile_commands.json is generated automatically by xmake. This is my xmake.lua:

add_rules("mode.debug", "mode.release")

target("cuda-test")
    set_kind("binary")
    add_files("src/*.cu")

    -- generate SASS code for SM architecture of current host
    add_cugencodes("native")

Logs

The flag `-clang-tidy-checks` is obsolete and ignored.
The flag `-include-cleaner-stdlib` is obsolete and ignored.
I[13:20:56.318] Ubuntu clangd version 18.1.0 (++20240217043202+8a3d8f0c2531-1~exp1~20240217163220.45)
I[13:20:56.318] Features: linux+grpc
I[13:20:56.318] PID: 12388
I[13:20:56.318] Working directory: /home/sirius/code/cpp/cuda-test
I[13:20:56.318] argv[0]: /usr/bin/clangd-18
I[13:20:56.318] argv[1]: --all-scopes-completion
I[13:20:56.318] argv[2]: --background-index
I[13:20:56.318] argv[3]: --clang-tidy
I[13:20:56.318] argv[4]: --clang-tidy-checks=performance-*, bugprone-*, misc-*, google-*, modernize-*, readability-*, portability-*
I[13:20:56.318] argv[5]: --compile-commands-dir=/home/sirius/code/cpp/cuda-test/.vscode
I[13:20:56.318] argv[6]: --completion-parse=auto
I[13:20:56.318] argv[7]: --completion-style=detailed
I[13:20:56.318] argv[8]: --query-driver=/usr/bin/clang++-18
I[13:20:56.318] argv[9]: --enable-config
I[13:20:56.318] argv[10]: --fallback-style=Webkit
I[13:20:56.318] argv[11]: --function-arg-placeholders=true
I[13:20:56.318] argv[12]: --header-insertion-decorators
I[13:20:56.318] argv[13]: --header-insertion=iwyu
I[13:20:56.318] argv[14]: --include-cleaner-stdlib
I[13:20:56.318] argv[15]: --pch-storage=memory
I[13:20:56.318] argv[16]: --pretty
I[13:20:56.318] argv[17]: --ranking-model=decision_forest
I[13:20:56.318] argv[18]: -j=12
I[13:20:56.318] Starting LSP over stdin/stdout
I[13:20:56.319] <-- initialize(0)
I[13:20:56.339] --> reply:initialize(0) 20 ms
I[13:20:56.343] <-- initialized
I[13:20:56.350] <-- textDocument/didOpen
E[13:20:56.364] System include extraction: driver clang not found in PATH
I[13:20:56.366] --> textDocument/publishDiagnostics
I[13:20:56.367] Loaded compilation database from /home/sirius/code/cpp/cuda-test/.vscode/compile_commands.json
I[13:20:56.367] --> window/workDoneProgress/create(0)
I[13:20:56.367] Enqueueing 1 commands for indexing
I[13:20:56.367] ASTWorker building file /home/sirius/code/cpp/cuda-test/src/main.cu version 1 with command 
[/home/sirius/code/cpp/cuda-test]
/usr/local/cuda-12.1/bin/nvcc -c -Xcompiler -fPIE -O3 -I/usr/local/cuda/include -m64 -rdc=true -gencode -resource-dir=/usr/lib/llvm-18/lib/clang/18 -- /home/sirius/code/cpp/cuda-test/src/main.cu
I[13:20:56.376] --> textDocument/clangd.fileStatus
I[13:20:56.442] <-- $/setTrace
I[13:20:56.442] unhandled notification $/setTrace
I[13:20:56.456] <-- textDocument/documentLink(1)
I[13:20:56.456] <-- textDocument/inlayHint(2)
I[13:20:56.456] <-- textDocument/codeAction(3)
I[13:20:56.508] <-- reply(0)
I[13:20:56.508] --> $/progress
I[13:20:56.508] --> $/progress
I[13:20:56.571] <-- $/setTrace
I[13:20:56.571] unhandled notification $/setTrace
I[13:20:56.655] <-- $/cancelRequest
I[13:20:56.667] <-- textDocument/documentLink(4)
I[13:20:56.682] Built preamble of size 5047684 for file /home/sirius/code/cpp/cuda-test/src/main.cu version 1 in 0.31 seconds
I[13:20:56.683] Indexing c++17 standard library in the context of /home/sirius/code/cpp/cuda-test/src/main.cu
I[13:20:56.683] --> workspace/semanticTokens/refresh(1)
I[13:20:56.696] <-- textDocument/documentSymbol(5)
I[13:20:56.696] <-- textDocument/foldingRange(6)
I[13:20:56.697] --> reply:textDocument/foldingRange(6) 0 ms
I[13:20:56.703] <-- reply(1)
I[13:20:56.717] <-- textDocument/semanticTokens/full(7)
I[13:20:56.719] --> textDocument/publishDiagnostics
I[13:20:56.719] --> textDocument/inactiveRegions
I[13:20:56.719] --> reply:textDocument/documentLink(1) 262 ms, error: Task was cancelled.
I[13:20:56.719] --> reply:textDocument/inlayHint(2) 262 ms
I[13:20:56.719] --> reply:textDocument/codeAction(3) 262 ms
I[13:20:56.719] --> reply:textDocument/documentLink(4) 51 ms
I[13:20:56.719] --> reply:textDocument/documentSymbol(5) 22 ms
I[13:20:56.719] --> reply:textDocument/semanticTokens/full(7) 1 ms
I[13:20:56.719] --> textDocument/clangd.fileStatus
[Error - 1:20:56 PM] Request textDocument/documentLink failed.
[object Object]
I[13:20:56.984] <-- textDocument/codeAction(8)
I[13:20:56.985] --> reply:textDocument/codeAction(8) 0 ms
I[13:20:56.985] --> textDocument/clangd.fileStatus
I[13:20:58.251] Indexed c++17 standard library (incomplete due to errors): 14166 symbols, 6604 filtered
I[13:20:58.389] <-- textDocument/documentSymbol(9)
I[13:20:58.389] <-- textDocument/codeAction(10)
I[13:20:58.389] --> reply:textDocument/documentSymbol(9) 0 ms
I[13:20:58.389] --> reply:textDocument/codeAction(10) 0 ms
I[13:20:58.389] --> textDocument/clangd.fileStatus
I[13:21:00.983] <-- textDocument/inlayHint(11)
I[13:21:00.983] --> reply:textDocument/inlayHint(11) 0 ms
I[13:21:00.983] --> textDocument/clangd.fileStatus

System information

Output of clangd --version:

image

Editor/LSP plugin: VSCode/clangd

Operating system: Ubuntu-22.04 LTS in WSL 2(Windows 11)

HighCommander4 commented 8 months ago

When I use clangd as the LSP in VSCode to write cuda codes, clangd gives such errors:

  • Unknown argument: '-rdc=true'
  • Unknown argument: '-gencode'

Searching around for other CUDA issues suggests these flags need to be removed, which can be done using clangd's config file (https://github.com/clangd/clangd/issues/1907#issuecomment-1894800711).

  • GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda-12.1 is 12.1; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

Have you tried adding one of the flags suggested in the error message?

TaelinSu commented 8 months ago

When I use clangd as the LSP in VSCode to write cuda codes, clangd gives such errors:

  • Unknown argument: '-rdc=true'
  • Unknown argument: '-gencode'

Searching around for other CUDA issues suggests these flags need to be removed, which can be done using clangd's config file (#1907 (comment)).

  • GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda-12.1 is 12.1; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

Have you tried adding one of the flags suggested in the error message?

Sure, I add and remove these flags using clangd's config file. The errors disappear.

This is my config.yaml:

CompileFlags:
  Add: [--cuda-gpu-arch=sm_86]
  Remove:
    - -rdc=true
    - -gencode

Thank you~