clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
629 stars 106 forks source link

How to make clangd provide intelligence for .cu files #557

Closed shadow150519 closed 5 months ago

shadow150519 commented 10 months ago

I have a very strange problem for my clangd. It can provide intellgence for my cpp files correctly, but when it comes to .cu files, it don't work. Here's my situation.I've add the torch lib in my project. when I include <torch/library.h>. clangd works correctly. memory_utils.cpp However, when I include <torch/library.h> in a .cu file. clangd doesn't seem to be working. memory_utils.cu But when I rename the .cu file to .cpp file. It works again. memory_utils_gpu.cpp The three files are in the same directory. I can make sure there is no problem with my cmake configuration.

Logs when I hover on the #include<torch/library.h> in the .cu file

V[15:53:33.482] <<< {
  "id": 73,
  "jsonrpc": "2.0",
  "method": "textDocument/hover",
  "params": {
    "position": {
      "character": 24,
      "line": 8
    },
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[15:53:33.482] <-- textDocument/hover(73)
V[15:53:33.483] ASTWorker running Hover on version 5 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[15:53:33.483] --> reply:textDocument/hover(73) 0 ms
V[15:53:33.483] >>> {
  "id": 73,
  "jsonrpc": "2.0",
  "result": null
}

I[15:53:33.483] --> textDocument/clangd.fileStatus
V[15:53:33.483] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "idle",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}

V[15:53:33.642] <<< {
  "id": 74,
  "jsonrpc": "2.0",
  "method": "textDocument/codeAction",
  "params": {
    "context": {
      "diagnostics": [
        {
          "code": "pp_file_not_found",
          "message": "'torch/library.h' file not found",
          "range": {
            "end": {
              "character": 26,
              "line": 8
            },
            "start": {
              "character": 9,
              "line": 8
            }
          },
          "relatedInformation": [],
          "severity": 1,
          "source": "clang"
        }
      ],
      "only": [
        "quickfix"
      ],
      "triggerKind": 1
    },
    "range": {
      "end": {
        "character": 26,
        "line": 8
      },
      "start": {
        "character": 9,
        "line": 8
      }
    },
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[15:53:33.643] <-- textDocument/codeAction(74)
V[15:53:33.643] ASTWorker running EnumerateTweaks on version 5 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[15:53:33.643] --> reply:textDocument/codeAction(74) 0 ms
V[15:53:33.643] >>> {
  "id": 74,
  "jsonrpc": "2.0",
  "result": []
}

I[15:53:33.643] --> textDocument/clangd.fileStatus
V[15:53:33.643] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "idle",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}

when I hover on the #include<torch/library.h> in the .cpp file

V[15:54:34.829] <<< {
  "id": 81,
  "jsonrpc": "2.0",
  "method": "textDocument/hover",
  "params": {
    "position": {
      "character": 24,
      "line": 9
    },
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops_gpu.cpp"
    }
  }
}

I[15:54:34.829] <-- textDocument/hover(81)
V[15:54:34.829] ASTWorker running Hover on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops_gpu.cpp
I[15:54:34.830] --> reply:textDocument/hover(81) 0 ms
V[15:54:34.830] >>> {
  "id": 81,
  "jsonrpc": "2.0",
  "result": {
    "contents": {
      "kind": "markdown",
      "value": "### `library.h`  \n\n---\n```\n/home/wtx/miniconda3/envs/dgl/lib/python3.10/site-packages/torch/include/torch/library.h\n```"
    }
  }
}

I[15:54:34.830] --> textDocument/clangd.fileStatus
V[15:54:34.830] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "idle",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops_gpu.cpp"
  }
}

System information Clangd version (from the log, or clangd --version):

clangd version 15.0.6
Features: linux
Platform: x86_64-unknown-linux-gnu

clangd extension version: v0.1.25 Operating system: Ubuntu 20.04.5 LTS

HighCommander4 commented 7 months ago

Can you provide clangd logs which are more complete (also covering clangd startup, and the opening of the affected files)?

shadow150519 commented 7 months ago

clangd restart

he flag `-cross-file-rename` is obsolete and ignored.
The flag `-clang-tidy-checks` is obsolete and ignored.
I[22:05:57.646] clangd version 15.0.6
I[22:05:57.646] Features: linux
I[22:05:57.646] PID: 2182825
I[22:05:57.646] Working directory: /home/wtx/workspace/cpp_project/uvm
I[22:05:57.646] argv[0]: /home/wtx/.local/clang+llvm-15/bin/clangd
I[22:05:57.646] argv[1]: --log=verbose
I[22:05:57.646] argv[2]: --pretty
I[22:05:57.646] argv[3]: --all-scopes-completion
I[22:05:57.646] argv[4]: --completion-style=bundled
I[22:05:57.646] argv[5]: --cross-file-rename
I[22:05:57.646] argv[6]: --header-insertion-decorators
I[22:05:57.646] argv[7]: --background-index
I[22:05:57.646] argv[8]: --clang-tidy
I[22:05:57.646] argv[9]: --clang-tidy-checks=cppcoreguidelines-*,performance-*,bugprone-*,portability-*,modernize-*,google-*
I[22:05:57.646] argv[10]: -j=2
I[22:05:57.646] argv[11]: --pch-storage=disk
I[22:05:57.646] argv[12]: --function-arg-placeholders=false
I[22:05:57.646] argv[13]: --compile-commands-dir=build
V[22:05:57.646] User config file is /home/wtx/.config/clangd/config.yaml
I[22:05:57.646] Starting LSP over stdin/stdout
V[22:05:57.646] <<< {
  "id": 0,
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "general": {
        "markdown": {
          "parser": "marked",
          "version": "1.1.0"
        },
        "positionEncodings": [
          "utf-16"
        ],
        "regularExpressions": {
          "engine": "ECMAScript",
          "version": "ES2020"
        },
        "staleRequestSupport": {
          "cancel": true,
          "retryOnContentModified": [
            "textDocument/semanticTokens/full",
            "textDocument/semanticTokens/range",
            "textDocument/semanticTokens/full/delta"
          ]
        }
      },
      "notebookDocument": {
        "synchronization": {
          "dynamicRegistration": true,
          "executionSummarySupport": true
        }
      },
      "textDocument": {
        "callHierarchy": {
          "dynamicRegistration": true
        },
        "codeAction": {
          "codeActionLiteralSupport": {
            "codeActionKind": {
              "valueSet": [
                "",
                "quickfix",
                "refactor",
                "refactor.extract",
                "refactor.inline",
                "refactor.rewrite",
                "source",
                "source.organizeImports"
              ]
            }
          },
          "dataSupport": true,
          "disabledSupport": true,
          "dynamicRegistration": true,
          "honorsChangeAnnotations": false,
          "isPreferredSupport": true,
          "resolveSupport": {
            "properties": [
              "edit"
            ]
          }
        },
        "codeLens": {
          "dynamicRegistration": true
        },
        "colorProvider": {
          "dynamicRegistration": true
        },
        "completion": {
          "completionItem": {
            "commitCharactersSupport": true,
            "deprecatedSupport": true,
            "documentationFormat": [
              "markdown",
              "plaintext"
            ],
            "insertReplaceSupport": true,
            "insertTextModeSupport": {
              "valueSet": [
                1,
                2
              ]
            },
            "labelDetailsSupport": true,
            "preselectSupport": true,
            "resolveSupport": {
              "properties": [
                "documentation",
                "detail",
                "additionalTextEdits"
              ]
            },
            "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
            ]
          },
          "completionList": {
            "itemDefaults": [
              "commitCharacters",
              "editRange",
              "insertTextFormat",
              "insertTextMode"
            ]
          },
          "contextSupport": true,
          "dynamicRegistration": true,
          "editsNearCursor": true,
          "insertTextMode": 2
        },
        "declaration": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "definition": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "diagnostic": {
          "dynamicRegistration": true,
          "relatedDocumentSupport": false
        },
        "documentHighlight": {
          "dynamicRegistration": true
        },
        "documentLink": {
          "dynamicRegistration": true,
          "tooltipSupport": true
        },
        "documentSymbol": {
          "dynamicRegistration": true,
          "hierarchicalDocumentSymbolSupport": true,
          "labelSupport": 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,
          "foldingRange": {
            "collapsedText": false
          },
          "foldingRangeKind": {
            "valueSet": [
              "comment",
              "imports",
              "region"
            ]
          },
          "lineFoldingOnly": true,
          "rangeLimit": 5000
        },
        "formatting": {
          "dynamicRegistration": true
        },
        "hover": {
          "contentFormat": [
            "markdown",
            "plaintext"
          ],
          "dynamicRegistration": true
        },
        "implementation": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "inactiveRegionsCapabilities": {
          "inactiveRegions": true
        },
        "inlayHint": {
          "dynamicRegistration": true,
          "resolveSupport": {
            "properties": [
              "tooltip",
              "textEdits",
              "label.tooltip",
              "label.location",
              "label.command"
            ]
          }
        },
        "inlineValue": {
          "dynamicRegistration": true
        },
        "linkedEditingRange": {
          "dynamicRegistration": true
        },
        "onTypeFormatting": {
          "dynamicRegistration": true
        },
        "publishDiagnostics": {
          "codeDescriptionSupport": true,
          "dataSupport": true,
          "relatedInformation": true,
          "tagSupport": {
            "valueSet": [
              1,
              2
            ]
          },
          "versionSupport": false
        },
        "rangeFormatting": {
          "dynamicRegistration": true
        },
        "references": {
          "dynamicRegistration": true
        },
        "rename": {
          "dynamicRegistration": true,
          "honorsChangeAnnotations": true,
          "prepareSupport": true,
          "prepareSupportDefaultBehavior": 1
        },
        "selectionRange": {
          "dynamicRegistration": true
        },
        "semanticTokens": {
          "augmentsSyntaxTokens": true,
          "dynamicRegistration": true,
          "formats": [
            "relative"
          ],
          "multilineTokenSupport": false,
          "overlappingTokenSupport": false,
          "requests": {
            "full": {
              "delta": true
            },
            "range": true
          },
          "serverCancelSupport": true,
          "tokenModifiers": [
            "declaration",
            "definition",
            "readonly",
            "static",
            "deprecated",
            "abstract",
            "async",
            "modification",
            "documentation",
            "defaultLibrary"
          ],
          "tokenTypes": [
            "namespace",
            "type",
            "class",
            "enum",
            "interface",
            "struct",
            "typeParameter",
            "parameter",
            "variable",
            "property",
            "enumMember",
            "event",
            "function",
            "method",
            "macro",
            "keyword",
            "modifier",
            "comment",
            "string",
            "number",
            "regexp",
            "operator",
            "decorator"
          ]
        },
        "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,
          "linkSupport": true
        },
        "typeHierarchy": {
          "dynamicRegistration": true
        }
      },
      "window": {
        "showDocument": {
          "support": true
        },
        "showMessage": {
          "messageActionItem": {
            "additionalPropertiesSupport": true
          }
        },
        "workDoneProgress": true
      },
      "workspace": {
        "applyEdit": true,
        "codeLens": {
          "refreshSupport": true
        },
        "configuration": true,
        "diagnostics": {
          "refreshSupport": true
        },
        "didChangeConfiguration": {
          "dynamicRegistration": true
        },
        "didChangeWatchedFiles": {
          "dynamicRegistration": true,
          "relativePatternSupport": true
        },
        "executeCommand": {
          "dynamicRegistration": true
        },
        "fileOperations": {
          "didCreate": true,
          "didDelete": true,
          "didRename": true,
          "dynamicRegistration": true,
          "willCreate": true,
          "willDelete": true,
          "willRename": true
        },
        "inlayHint": {
          "refreshSupport": true
        },
        "inlineValue": {
          "refreshSupport": true
        },
        "semanticTokens": {
          "refreshSupport": true
        },
        "symbol": {
          "dynamicRegistration": true,
          "resolveSupport": {
            "properties": [
              "location.range"
            ]
          },
          "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": {
          "changeAnnotationSupport": {
            "groupsOnLabel": true
          },
          "documentChanges": true,
          "failureHandling": "textOnlyTransactional",
          "normalizesLineEndings": true,
          "resourceOperations": [
            "create",
            "rename",
            "delete"
          ]
        },
        "workspaceFolders": true
      }
    },
    "clientInfo": {
      "name": "Visual Studio Code",
      "version": "1.87.0"
    },
    "initializationOptions": {
      "clangdFileStatus": true,
      "fallbackFlags": []
    },
    "locale": "en",
    "processId": 2181886,
    "rootPath": "/home/wtx/workspace/cpp_project/uvm",
    "rootUri": "file:///home/wtx/workspace/cpp_project/uvm",
    "trace": "off",
    "workspaceFolders": [
      {
        "name": "uvm",
        "uri": "file:///home/wtx/workspace/cpp_project/uvm"
      }
    ]
  }
}

I[22:05:57.646] <-- initialize(0)
I[22:05:57.647] --> reply:initialize(0) 0 ms
V[22:05:57.647] >>> {
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
    "capabilities": {
      "astProvider": true,
      "callHierarchyProvider": true,
      "clangdInlayHintsProvider": true,
      "codeActionProvider": {
        "codeActionKinds": [
          "quickfix",
          "refactor",
          "info"
        ]
      },
      "compilationDatabase": {
        "automaticReload": true
      },
      "completionProvider": {
        "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,
      "implementationProvider": true,
      "inlayHintProvider": true,
      "memoryUsageProvider": true,
      "referencesProvider": true,
      "renameProvider": {
        "prepareProvider": true
      },
      "selectionRangeProvider": true,
      "semanticTokensProvider": {
        "full": {
          "delta": true
        },
        "legend": {
          "tokenModifiers": [
            "declaration",
            "deprecated",
            "deduced",
            "readonly",
            "static",
            "abstract",
            "virtual",
            "dependentName",
            "defaultLibrary",
            "usedAsMutableReference",
            "functionScope",
            "classScope",
            "fileScope",
            "globalScope"
          ],
          "tokenTypes": [
            "variable",
            "variable",
            "parameter",
            "function",
            "method",
            "function",
            "property",
            "variable",
            "class",
            "interface",
            "enum",
            "enumMember",
            "type",
            "type",
            "unknown",
            "namespace",
            "typeParameter",
            "concept",
            "type",
            "macro",
            "comment"
          ]
        },
        "range": false
      },
      "signatureHelpProvider": {
        "triggerCharacters": [
          "(",
          ")",
          "{",
          "}",
          "<",
          ">",
          ","
        ]
      },
      "standardTypeHierarchyProvider": true,
      "textDocumentSync": {
        "change": 2,
        "openClose": true,
        "save": true
      },
      "typeDefinitionProvider": true,
      "typeHierarchyProvider": true,
      "workspaceSymbolProvider": true
    },
    "serverInfo": {
      "name": "clangd",
      "version": "clangd version 15.0.6 linux x86_64-unknown-linux-gnu"
    }
  }
}

V[22:05:57.647] <<< {
  "jsonrpc": "2.0",
  "method": "initialized",
  "params": {}
}

I[22:05:57.648] <-- initialized

open .cu file

V[22:07:05.160] <<< {
  "jsonrpc": "2.0",
  "method": "textDocument/didOpen",
  "params": {
    "textDocument": {
      "languageId": "cuda-cpp",
      "text": "/*\r\n * Copyright (c) Meta Platforms, Inc. and affiliates.\r\n * All rights reserved.\r\n *\r\n * This source code is licensed under the BSD-style license found in the\r\n * LICENSE file in the root directory of this source tree.\r\n */\r\n\r\n#include <torch/library.h>\r\n#include \"common.cuh\"\r\n\r\nnamespace uvm {\r\n\r\nTORCH_LIBRARY_FRAGMENT(uvm, m) {\r\n  DISPATCH_TO_CUDA(\"uvm_to_cpu\", uvm_to_cpu);\r\n  DISPATCH_TO_CUDA(\"new_managed_tensor\", new_managed_tensor);\r\n  DISPATCH_TO_META(\"new_managed_tensor\", new_managed_tensor_meta);\r\n  DISPATCH_TO_CUDA(\"new_host_mapped_tensor\", new_host_mapped_tensor);\r\n  DISPATCH_TO_CUDA(\"new_unified_tensor\", new_unified_tensor);\r\n  DISPATCH_TO_CUDA(\"new_vanilla_managed_tensor\", new_vanilla_managed_tensor);\r\n}\r\n\r\n} // namespace uvm\r\n",
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu",
      "version": 1
    }
  }
}

I[22:07:05.160] <-- textDocument/didOpen
V[22:07:05.160] Released memory via malloc_trim
V[22:07:05.160] <<< {
  "id": 1,
  "jsonrpc": "2.0",
  "method": "textDocument/documentSymbol",
  "params": {
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.160] <-- textDocument/documentSymbol(1)
V[22:07:05.160] <<< {
  "id": 2,
  "jsonrpc": "2.0",
  "method": "textDocument/semanticTokens/full",
  "params": {
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.160] <-- textDocument/semanticTokens/full(2)
V[22:07:05.160] <<< {
  "id": 3,
  "jsonrpc": "2.0",
  "method": "textDocument/codeAction",
  "params": {
    "context": {
      "diagnostics": [],
      "triggerKind": 2
    },
    "range": {
      "end": {
        "character": 0,
        "line": 0
      },
      "start": {
        "character": 0,
        "line": 0
      }
    },
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.160] <-- textDocument/codeAction(3)
I[22:07:05.160] Loaded compilation database from /home/wtx/workspace/cpp_project/uvm/build/compile_commands.json
V[22:07:05.160] Broadcasting compilation database from /home/wtx/workspace/cpp_project/uvm/build
I[22:07:05.161] --> window/workDoneProgress/create(0)
V[22:07:05.161] >>> {
  "id": 0,
  "jsonrpc": "2.0",
  "method": "window/workDoneProgress/create",
  "params": {
    "token": "backgroundIndexProgress"
  }
}

I[22:07:05.161] Enqueueing 4 commands for indexing
V[22:07:05.161] <<< {
  "id": 0,
  "jsonrpc": "2.0",
  "result": null
}

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

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

I[22:07:05.161] ASTWorker building file /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu version 1 with command 
[/home/wtx/workspace/cpp_project/uvm/build]
/home/wtx/.local/cuda-11.7/bin/nvcc -forward-unknown-to-host-compiler -DTORCH_EXTENSION_NAME=libuvm_utils -DUSE_C10D_GLOO -DUSE_C10D_NCCL -DUSE_DISTRIBUTED -DUSE_RPC -DUSE_TENSORPIPE -DWITH_PYTHON -Duvm_utils_EXPORTS --options-file -DONNX_NAMESPACE=onnx_c2 -gencode -Xcudafe --diag_suppress=cc_clobber_ignored,--diag_suppress=integer_sign_change,--diag_suppress=useless_using_declaration,--diag_suppress=set_but_not_used,--diag_suppress=field_without_dll_interface,--diag_suppress=base_class_has_different_dll_interface,--diag_suppress=dll_interface_conflict_none_assumed,--diag_suppress=dll_interface_conflict_dllexport_assumed,--diag_suppress=implicit_return_from_non_void_function,--diag_suppress=unsigned_compare_with_zero,--diag_suppress=declared_but_not_referenced,--diag_suppress=bad_friend_decl --expt-relaxed-constexpr --expt-extended-lambda -g -Xcompiler=-fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -c -std=c++17 -resource-dir=/home/wtx/.local/clang+llvm-15/lib/clang/15.0.6 -- /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
V[22:07:05.167] <<< {
  "id": 4,
  "jsonrpc": "2.0",
  "method": "textDocument/documentLink",
  "params": {
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.167] <-- textDocument/documentLink(4)
V[22:07:05.167] <<< {
  "id": 5,
  "jsonrpc": "2.0",
  "method": "textDocument/inlayHint",
  "params": {
    "range": {
      "end": {
        "character": 0,
        "line": 23
      },
      "start": {
        "character": 0,
        "line": 0
      }
    },
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.167] <-- textDocument/inlayHint(5)
V[22:07:05.168] Ignored diagnostic. CUDA version is newer than the latest supported version 11.5
V[22:07:05.169] Driver produced command: cc1 -cc1 -triple x86_64-unknown-linux-gnu -target-sdk-version=11.5 -aux-triple nvptx64-nvidia-cuda -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name memory_utils_ops.cu -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fcoverage-compilation-dir=/home/wtx/workspace/cpp_project/uvm/build -resource-dir /home/wtx/.local/clang+llvm-15/lib/clang/15.0.6 -internal-isystem /home/wtx/.local/clang+llvm-15/lib/clang/15.0.6/include/cuda_wrappers -include __clang_cuda_runtime_wrapper.h -D TORCH_EXTENSION_NAME=libuvm_utils -D USE_C10D_GLOO -D USE_C10D_NCCL -D USE_DISTRIBUTED -D USE_RPC -D USE_TENSORPIPE -D WITH_PYTHON -D uvm_utils_EXPORTS -D ONNX_NAMESPACE=onnx_c2 -D _GLIBCXX_USE_CXX11_ABI=0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /home/wtx/.local/clang+llvm-15/lib/clang/15.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /home/wtx/.local/clang+llvm-15/lib/clang/15.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /home/wtx/.local/cuda-11.8/include -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/home/wtx/workspace/cpp_project/uvm/build -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -no-round-trip-args -cuid=836bf3fc9ee51f5b -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x cuda /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.169] --> textDocument/clangd.fileStatus
V[22:07:05.169] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "parsing includes, running Update",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}

V[22:07:05.169] Building first preamble for /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu version 1
V[22:07:05.271] <<< {
  "jsonrpc": "2.0",
  "method": "$/cancelRequest",
  "params": {
    "id": 1
  }
}

I[22:07:05.271] <-- $/cancelRequest
V[22:07:05.271] <<< {
  "id": 6,
  "jsonrpc": "2.0",
  "method": "textDocument/documentSymbol",
  "params": {
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.271] <-- textDocument/documentSymbol(6)
V[22:07:05.381] <<< {
  "jsonrpc": "2.0",
  "method": "$/cancelRequest",
  "params": {
    "id": 3
  }
}

I[22:07:05.381] <-- $/cancelRequest
V[22:07:05.415] BackgroundIndex: building version 1 after loading index from disk
V[22:07:05.424] <<< {
  "id": 7,
  "jsonrpc": "2.0",
  "method": "textDocument/documentSymbol",
  "params": {
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:05.424] <-- textDocument/documentSymbol(7)
V[22:07:05.482] indexed preamble AST for /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu version 1:
  symbol slab: 9318 symbols, 3678322 bytes
  ref slab: 0 symbols, 0 refs, 128 bytes
  relations slab: 147 relations, 4376 bytes
V[22:07:05.528] Build dynamic index for header symbols with estimated memory usage of 7567703 bytes
V[22:07:05.532] Built preamble of size 4757612 for file /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu version 1 in 0.36 seconds
I[22:07:05.532] --> workspace/semanticTokens/refresh(1)
V[22:07:05.532] >>> {
  "id": 1,
  "jsonrpc": "2.0",
  "method": "workspace/semanticTokens/refresh",
  "params": null
}

I[22:07:05.532] --> textDocument/clangd.fileStatus
V[22:07:05.532] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "parsing includes, running Build AST",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}

V[22:07:05.532] <<< {
  "id": 1,
  "jsonrpc": "2.0",
  "result": null
}

I[22:07:05.532] <-- reply(1)
V[22:07:05.550] Trying to fix unresolved name "m" in scopes: [, uvm::]
V[22:07:05.550] Dex query tree: (LIMIT 10000 (& T=m (| S= S=uvm::) ?=Restricted For Code Completion))
V[22:07:05.556] indexed file AST for /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu version 1:
  symbol slab: 2 symbols, 4680 bytes
  ref slab: 1 symbols, 1 refs, 4248 bytes
  relations slab: 0 relations, 24 bytes
V[22:07:05.556] Build dynamic index for main-file symbols with estimated memory usage of 11984 bytes
I[22:07:05.556] --> textDocument/publishDiagnostics
V[22:07:05.556] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "diagnostics": [
      {
        "code": "drv_unsupported_opt",
        "message": "Unsupported option '--options-file'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "drv_unsupported_opt",
        "message": "Unsupported option '--diag_suppress=cc_clobber_ignored,--diag_suppress=integer_sign_change,--diag_suppress=useless_using_declaration,--diag_suppress=set_but_not_used,--diag_suppress=field_without_dll_interface,--diag_suppress=base_class_has_different_dll_interface,--diag_suppress=dll_interface_conflict_none_assumed,--diag_suppress=dll_interface_conflict_dllexport_assumed,--diag_suppress=implicit_return_from_non_void_function,--diag_suppress=unsigned_compare_with_zero,--diag_suppress=declared_but_not_referenced,--diag_suppress=bad_friend_decl'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "drv_unsupported_opt",
        "message": "Unsupported option '--expt-relaxed-constexpr'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "drv_unsupported_opt",
        "message": "Unsupported option '--expt-extended-lambda'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "drv_unknown_argument",
        "message": "Unknown argument: '-forward-unknown-to-host-compiler'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "drv_unknown_argument",
        "message": "Unknown argument: '-gencode'",
        "range": {
          "end": {
            "character": 0,
            "line": 0
          },
          "start": {
            "character": 0,
            "line": 0
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "pp_file_not_found",
        "message": "'torch/library.h' file not found",
        "range": {
          "end": {
            "character": 26,
            "line": 8
          },
          "start": {
            "character": 9,
            "line": 8
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "missing_type_specifier",
        "message": "A type specifier is required for all declarations",
        "range": {
          "end": {
            "character": 22,
            "line": 13
          },
          "start": {
            "character": 0,
            "line": 13
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "unexpected_namespace",
        "message": "Unexpected namespace name 'uvm': expected expression",
        "range": {
          "end": {
            "character": 26,
            "line": 13
          },
          "start": {
            "character": 23,
            "line": 13
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "undeclared_var_use",
        "message": "Use of undeclared identifier 'm'",
        "range": {
          "end": {
            "character": 29,
            "line": 13
          },
          "start": {
            "character": 28,
            "line": 13
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      },
      {
        "code": "invalid_token_after_toplevel_declarator",
        "message": "Expected ';' after top level declarator (fix available)",
        "range": {
          "end": {
            "character": 32,
            "line": 13
          },
          "start": {
            "character": 31,
            "line": 13
          }
        },
        "relatedInformation": [],
        "severity": 1,
        "source": "clang"
      }
    ],
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu",
    "version": 1
  }
}

I[22:07:05.556] --> reply:textDocument/documentSymbol(1) 395 ms, error: Task was cancelled.
V[22:07:05.556] >>> {
  "error": {
    "code": -32800,
    "message": "Request cancelled"
  },
  "id": 1,
  "jsonrpc": "2.0"
}

V[22:07:05.556] ASTWorker running SemanticHighlights on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.556] --> reply:textDocument/semanticTokens/full(2) 395 ms
V[22:07:05.556] >>> {
  "id": 2,
  "jsonrpc": "2.0",
  "result": {
    "data": [
      11,
      10,
      3,
      15,
      8193,
      2,
      0,
      22,
      0,
      8193
    ],
    "resultId": "1"
  }
}

I[22:07:05.556] --> reply:textDocument/codeAction(3) 395 ms, error: Task was cancelled.
V[22:07:05.556] >>> {
  "error": {
    "code": -32800,
    "message": "Request cancelled"
  },
  "id": 3,
  "jsonrpc": "2.0"
}

V[22:07:05.556] ASTWorker running DocumentLinks on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.556] --> reply:textDocument/documentLink(4) 388 ms
V[22:07:05.556] >>> {
  "id": 4,
  "jsonrpc": "2.0",
  "result": [
    {
      "range": {
        "end": {
          "character": 21,
          "line": 9
        },
        "start": {
          "character": 9,
          "line": 9
        }
      },
      "target": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/common.cuh"
    }
  ]
}

V[22:07:05.556] ASTWorker running InlayHints on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.556] --> reply:textDocument/inlayHint(5) 388 ms
V[22:07:05.556] >>> {
  "id": 5,
  "jsonrpc": "2.0",
  "result": []
}

V[22:07:05.556] ASTWorker running DocumentSymbols on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.556] --> reply:textDocument/documentSymbol(6) 285 ms
V[22:07:05.556] >>> {
  "id": 6,
  "jsonrpc": "2.0",
  "result": [
    {
      "children": [
        {
          "detail": "int",
          "kind": 13,
          "name": "TORCH_LIBRARY_FRAGMENT",
          "range": {
            "end": {
              "character": 22,
              "line": 13
            },
            "start": {
              "character": 0,
              "line": 13
            }
          },
          "selectionRange": {
            "end": {
              "character": 22,
              "line": 13
            },
            "start": {
              "character": 0,
              "line": 13
            }
          }
        }
      ],
      "kind": 3,
      "name": "uvm",
      "range": {
        "end": {
          "character": 1,
          "line": 22
        },
        "start": {
          "character": 0,
          "line": 11
        }
      },
      "selectionRange": {
        "end": {
          "character": 13,
          "line": 11
        },
        "start": {
          "character": 10,
          "line": 11
        }
      }
    }
  ]
}

V[22:07:05.556] ASTWorker running DocumentSymbols on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:05.556] --> reply:textDocument/documentSymbol(7) 132 ms
V[22:07:05.556] >>> {
  "id": 7,
  "jsonrpc": "2.0",
  "result": [
    {
      "children": [
        {
          "detail": "int",
          "kind": 13,
          "name": "TORCH_LIBRARY_FRAGMENT",
          "range": {
            "end": {
              "character": 22,
              "line": 13
            },
            "start": {
              "character": 0,
              "line": 13
            }
          },
          "selectionRange": {
            "end": {
              "character": 22,
              "line": 13
            },
            "start": {
              "character": 0,
              "line": 13
            }
          }
        }
      ],
      "kind": 3,
      "name": "uvm",
      "range": {
        "end": {
          "character": 1,
          "line": 22
        },
        "start": {
          "character": 0,
          "line": 11
        }
      },
      "selectionRange": {
        "end": {
          "character": 13,
          "line": 11
        },
        "start": {
          "character": 10,
          "line": 11
        }
      }
    }
  ]
}

I[22:07:05.556] --> textDocument/clangd.fileStatus
V[22:07:05.556] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "idle",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}

[Error - 10:07:05 PM] Request textDocument/documentSymbol failed.
[object Object]
[Error - 10:07:05 PM] Request textDocument/codeAction failed.
[object Object]
V[22:07:05.774] BackgroundIndex: serving version 1 (98605001 bytes)
I[22:07:05.805] --> $/progress
V[22:07:05.805] >>> {
  "jsonrpc": "2.0",
  "method": "$/progress",
  "params": {
    "token": "backgroundIndexProgress",
    "value": {
      "kind": "report",
      "message": "0/1",
      "percentage": 0
    }
  }
}

I[22:07:05.805] --> $/progress
V[22:07:05.805] >>> {
  "jsonrpc": "2.0",
  "method": "$/progress",
  "params": {
    "token": "backgroundIndexProgress",
    "value": {
      "kind": "end"
    }
  }
}

V[22:07:06.047] <<< {
  "id": 8,
  "jsonrpc": "2.0",
  "method": "textDocument/semanticTokens/full/delta",
  "params": {
    "previousResultId": "1",
    "textDocument": {
      "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
    }
  }
}

I[22:07:06.047] <-- textDocument/semanticTokens/full/delta(8)
V[22:07:06.047] ASTWorker running SemanticHighlights on version 1 of /home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu
I[22:07:06.047] --> reply:textDocument/semanticTokens/full/delta(8) 0 ms
V[22:07:06.047] >>> {
  "id": 8,
  "jsonrpc": "2.0",
  "result": {
    "edits": [],
    "resultId": "2"
  }
}

I[22:07:06.047] --> textDocument/clangd.fileStatus
V[22:07:06.047] >>> {
  "jsonrpc": "2.0",
  "method": "textDocument/clangd.fileStatus",
  "params": {
    "state": "idle",
    "uri": "file:///home/wtx/workspace/cpp_project/uvm/memory_utils/memory_utils_ops.cu"
  }
}
HighCommander4 commented 7 months ago

The command for memory_utils_ops.cu in compile_commands.json is an nvcc command. Clangd expects a clang command, or at least a command with compatible syntax that clang can recognize.

In this case, the command seems to contain a bunch of options that clang does not recognize, and it seems to be missing a -I option needed for clangd to locate the <torch/library.h> include.

I think your options are (1) make edits to the command using the clangd config file to remove unsupported options and add necessary ones like -I, or (2) get your build system to generate a clang command to begin with.

shadow150519 commented 5 months ago

The command for memory_utils_ops.cu in compile_commands.json is an nvcc command. Clangd expects a clang command, or at least a command with compatible syntax that clang can recognize.

In this case, the command seems to contain a bunch of options that clang does not recognize, and it seems to be missing a -I option needed for clangd to locate the <torch/library.h> include.

I think your options are (1) make edits to the command using the clangd config file to remove unsupported options and add necessary ones like -I, or (2) get your build system to generate a clang command to begin with.

@HighCommander4 Hi, sorry for the late response. I try to add a .clangd file in the root_dir of my project and add the included directories. But clangd still can't find <torch/library.h> in .cu files. Could you please tell me what I should do? Here is my .clangd file:

If:
  PathMatch: .*\.cu
CompileFlags:
  Add: [-I/home/wtx/miniconda3/envs/dgl/lib/python3.10/site-packages/torch/include -I/home/wtx/miniconda3/envs/dgl/lib/python3.10/site-packages/torch/include/torch/csrc/api/include]
  Compiler: nvcc
HighCommander4 commented 5 months ago

@shadow150519: Every element in the array after Add: becomes a single command-line argument.

Here, the array has a single element, so it's as if you had written "-I/home/wtx/miniconda3/envs/dgl/lib/python3.10/site-packages/torch/include -I/home/wtx/miniconda3/envs/dgl/lib/python3.10/site-packages/torch/include/torch/csrc/api/include" on the command line (which does not work).

Adding a comma to separate the two elements, as in Add: [-I/path/one, -I/path/two] should fix it.

HighCommander4 commented 5 months ago

By the way, you can look in the logs to see the synthesized command (with edits like Add: applied). Look for "ASTWorker building file".

shadow150519 commented 5 months ago

Thanks for your help! It does work. I also find i need to write configuration for .h and .cuh files otherwise clangd can't find the include files. I have one more question:, can you tell me why using cmake include_directories() can't make clangd find my include_dirs correctly? I use Clion to open my project and it turns out Clion can find all my include files just using include_directories without a .clangd file

HighCommander4 commented 5 months ago

can you tell me why using cmake include_directories() can't make clangd find my include_dirs correctly?

Clangd does not look at (or know about) cmake files directly. It looks at the compile_commands.json file which cmake (among other tools) can generate.

So the first thing to check here is, do the include directories in question show up in compile_commands.json?

If so, the next thing to look at would be clangd logs.