Clangd can't index cuda files

I have a large project (few thousand source files). Indexing would never complete and I isolated the problem to my cuda file entries. If I remove the cuda files, indexing completes eventually.

In effort to better isolate the issue, I created a comp DB with just the cuda files, set the thread count to 1 and started the index. It can’t make it past the first item…clangd just hangs at that point.

I’ve turned on verbose logging and have extracted and redacted (source and paths removed) - see below.

Seems like it’s having trouble with a number of parameters as well as maybe even the specific nvcc we are using? Maybe I need to tweak the command in the compile DB that we are using? Are there some specific flags/options/paths when using cuda files that are problematic?

Any advice about getting cuda files to work - at least just for basic symbol referencing - would be appreciated.

I[09:36:31.969] Ubuntu clangd version 11.1.0-++20210203115409+1fdec59bffc1-1~exp1~20210203230038.161
I[09:36:31.969] PID: 12661
I[09:36:31.969] Working directory: /home/mellery/work/<redacted>
I[09:36:31.969] argv[0]: /usr/lib/llvm-11/bin/clangd
I[09:36:31.969] argv[1]: --clang-tidy
I[09:36:31.969] argv[2]: -j=1
I[09:36:31.969] argv[3]: --cross-file-rename
I[09:36:31.969] argv[4]: --background-index=1
I[09:36:31.969] argv[5]: --suggest-missing-includes
I[09:36:31.969] argv[6]: --log=verbose
I[09:36:31.969] argv[7]: --query-driver=/usr/bin/g++,/usr/bin/g++-7
V[09:36:31.969] User config file is /home/mellery/.config/clangd/config.yaml
I[09:36:31.969] Starting LSP over stdin/stdout
V[09:36:31.969] <<< {"id":0,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dynamicRegistration":true,"isPreferredSupport":true},"codeLens":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"completion":{"completionItem":{"commitCharactersSupport":true,"deprecatedSupport":true,"documentationFormat":["markdown","plaintext"],"preselectSupport":true,"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"contextSupport":true,"dynamicRegistration":true,"editsNearCursor":true},"declaration":{"dynamicRegistration":true},"definition":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"documentSymbol":{"dynamicRegistration":true,"hierarchicalDocumentSymbolSupport":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"foldingRange":{"dynamicRegistration":true,"lineFoldingOnly":true,"rangeLimit":5000},"formatting":{"dynamicRegistration":true},"hover":{"contentFormat":["markdown","plaintext"],"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"publishDiagnostics":{"relatedInformation":true,"tagSupport":{"valueSet":[1,2]},"versionSupport":false},"rangeFormatting":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"selectionRange":{"dynamicRegistration":true},"semanticHighlightingCapabilities":{"semanticHighlighting":true},"signatureHelp":{"contextSupport":true,"dynamicRegistration":true,"signatureInformation":{"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"synchronization":{"didSave":true,"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true},"typeDefinition":{"dynamicRegistration":true}},"window":{"workDoneProgress":true},"workspace":{"applyEdit":true,"configuration":true,"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"workspaceEdit":{"documentChanges":true,"failureHandling":"textOnlyTransactional","resourceOperations":["create","rename","delete"]},"workspaceFolders":true}},"clientInfo":{"name":"coc.nvim","version":"0.0.80"},"initializationOptions":{"clangdFileStatus":true,"fallbackFlags":[]},"processId":12498,"rootPath":"/home/mellery/work/<redacted>","rootUri":"file:///home/mellery/work/<redacted>","trace":"off","workspaceFolders":[{"name":"<redacted>","uri":"file:///home/mellery/work/<redacted>"}]}}

I[09:36:31.969] <-- initialize(0)
I[09:36:31.970] --> reply:initialize(0) 0 ms
V[09:36:31.970] >>> {"id":0,"jsonrpc":"2.0","result":{"capabilities":{"codeActionProvider":{"codeActionKinds":["quickfix","refactor","info"]},"completionProvider":{"allCommitCharacters":[" ","\t","(",")","[","]","{","}","<",">",":",";",",","+","-","/","*","%","^","&","#","?",".","=","\"","'","|"],"resolveProvider":false,"triggerCharacters":[".","<",">",":","\"","/"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"hoverProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"selectionRangeProvider":true,"semanticHighlighting":{"scopes":[["variable.other.cpp"],["variable.other.local.cpp"],["variable.parameter.cpp"],["entity.name.function.cpp"],["entity.name.function.method.cpp"],["entity.name.function.method.static.cpp"],["variable.other.field.cpp"],["variable.other.field.static.cpp"],["entity.name.type.class.cpp"],["entity.name.type.enum.cpp"],["variable.other.enummember.cpp"],["entity.name.type.typedef.cpp"],["entity.name.type.dependent.cpp"],["entity.name.other.dependent.cpp"],["entity.name.namespace.cpp"],["entity.name.type.template.cpp"],["entity.name.type.concept.cpp"],["storage.type.primitive.cpp"],["entity.name.function.preprocessor.cpp"],["meta.disabled"]]},"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":[],"tokenTypes":["variable","variable","parameter","function","member","function","member","variable","class","enum","enumConstant","type","dependent","dependent","namespace","typeParameter","concept","type","macro","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"serverInfo":{"name":"clangd","version":"Ubuntu clangd version 11.1.0-++20210203115409+1fdec59bffc1-1~exp1~20210203230038.161"}}}

V[09:36:31.973] <<< {"jsonrpc":"2.0","method":"initialized","params":{}}

I[09:36:31.973] <-- initialized
V[09:36:31.973] <<< {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cuda","text":"<REDACTED>","uri":"file:///home/mellery/work/<redacted>","version":1}}}

I[09:36:31.973] <-- textDocument/didOpen
I[09:36:31.978] Loaded compilation database from /home/mellery/work/<redacted>
I[09:36:31.981] --> window/workDoneProgress/create(0)
V[09:36:31.981] >>> {"id":0,"jsonrpc":"2.0","method":"window/workDoneProgress/create","params":{"token":"backgroundIndexProgress"}}

I[09:36:31.981] Enqueueing 189 commands for indexing
V[09:36:31.981] System include extraction: not allowed driver /home/mellery/work/<redacted>/bin/nvcc
I[09:36:31.981] ASTWorker building file /home/mellery/work/<redacted>.cu version 1 with command
[/home/mellery/work/<redacted>]
<redacted>/bin/nvcc  -DLINUX -U_FORTIFY_SOURCE  -DNDEBUG -O3 -D_FORTIFY_SOURCE=1 -ccbin /usr/bin/g++ --keep --keep-dir <redacted> -x cu --gpu-architecture=compute_53 - cross-execution-space-call --gpu-code=compute_53,sm_60,sm_61,sm_62,sm_72,sm_70,sm_75 -Xcompiler -Xcompiler -Xcompiler -Xcompiler -std=c++14 -I <LOTS OF INCLUDE PATHS> -c src/<redacted> -o <redacted>.o  -include <redacted> -Xcompiler -D <REDACTED> -frandom-seed=<redacted>.o -Xcompiler -ffunction-sections,-fdata-sections -use_fast_math -fsyntax-only -resource-dir=/usr/lib/llvm-11/lib/clang/11.1.0
V[09:36:31.985] <<< {"id":0,"jsonrpc":"2.0","result":null}

I[09:36:31.985] <-- reply(0)
I[09:36:31.985] --> $/progress
V[09:36:31.985] >>> {"jsonrpc":"2.0","method":"$/progress","params":{"token":"backgroundIndexProgress","value":{"kind":"begin","percentage":0,"title":"indexing"}}}

I[09:36:31.985] --> $/progress
V[09:36:31.985] >>> {"jsonrpc":"2.0","method":"$/progress","params":{"token":"backgroundIndexProgress","value":{"kind":"report","message":"0/1","percentage":0}}}

V[09:36:31.985] Failed to load shard: <REDACTED> -- one of these messages for each cuda file
V[09:36:31.994] Ignored diagnostic. Unknown CUDA version. version.txt: 10.2.152. Assuming the latest supported version 10.1
V[09:36:31.994] Ignored diagnostic. /usr/bin/g++: 'linker' input unused
V[09:36:31.994] Ignored diagnostic. <redacted path to obj file>: 'linker' input unused
I[09:36:31.995] --> $/progress
V[09:36:31.995] >>> {"jsonrpc":"2.0","method":"$/progress","params":{"token":"backgroundIndexProgress","value":{"kind":"report","message":"0/190","percentage":0}}}

I[09:36:31.995] --> $/progress
V[09:36:31.995] >>> {"jsonrpc":"2.0","method":"$/progress","params":{"token":"backgroundIndexProgress","value":{"kind":"report","message":"1/190","percentage":0.52631578947368418}}}

I[09:36:31.995] --> $/progress
V[09:36:31.995] >>> {"jsonrpc":"2.0","method":"$/progress","params":{"token":"backgroundIndexProgress","value":{"kind":"report","message":"1/190","percentage":0.52631578947368418}}}

V[09:36:31.995] Indexing <redacted> (digest:=F1B2D45D70FE66CE)
V[09:36:31.995] Driver produced command: cc1 -cc1 -triple x86_64-pc-linux-gnu -target-sdk-version=10.2 -aux-triple nvptx64-nvidia-cuda -fsyntax-only -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-11/lib/clang/11.1.0 -internal-isystem /usr/lib/llvm-11/lib/clang/11.1.0/include/cuda_wrappers -internal-isystem /usr/local/cuda/include -include __clang_cuda_runtime_wrapper.h  -isystem <LOTS OF INCLUDES> -D LINUX -U _FORTIFY_SOURCE  -D NDEBUG -D _FORTIFY_SOURCE=1  -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.1.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.1.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/mellery/work/<redacted> -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -faddrsig -x cuda -
I[09:36:31.995] --> textDocument/clangd.fileStatus
V[09:36:31.995] >>> {"jsonrpc":"2.0","method":"textDocument/clangd.fileStatus","params":{"state":"parsing includes,running Update (1)","uri":"file:///home/mellery/work/<redacted>"}}

V[09:36:31.995] Building first preamble for /home/mellery/work/<redacted> version 1
V[09:36:31.996] Ignored diagnostic. unsupported option '--keep'
V[09:36:31.996] Ignored diagnostic. unsupported option '--keep-dir'
V[09:36:31.998] Ignored diagnostic. unsupported option '--gpu-architecture=compute_53'
V[09:36:32.000] Ignored diagnostic. unsupported option '--gpu-code=compute_53,sm_60,sm_61,sm_62,sm_72,sm_70,sm_75'
V[09:36:32.001] Ignored diagnostic. unknown argument: '-ccbin'
V[09:36:32.004] Ignored diagnostic. unknown argument: '-ffunction-sections,-fdata-sections'
V[09:36:32.005] Ignored diagnostic. Unknown CUDA version. version.txt: 10.2.152. Assuming the latest supported version 10.1
V[09:36:32.005] Ignored diagnostic. /usr/bin/g++: 'linker' input unused
V[09:36:32.005] Ignored diagnostic. <path redacted>: 'linker' input unused
V[09:36:32.005] Ignored diagnostic. cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
V[09:36:32.005] Ignored diagnostic. GPU arch sm_20 is supported by CUDA versions between 7.0 and 8.0 (inclusive), but installation at /usr/local/cuda is 10.2. Use --cuda-path to specify a different CUDA install, pass a different GPU arch with --cuda-gpu-arch, or pass --no-cuda-version-check.
V[09:36:32.005] Ignored diagnostic. cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
V[09:36:32.005] Ignored diagnostic. cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.