clangd / vscode-clangd

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

How to write CUDA? #125

Open pogevip opened 3 years ago

pogevip commented 3 years ago

image

cloudhan commented 3 years ago

You should add a .clangd file

CompileFlags:
  Add:
    - -std=c++11
    - --cuda-path=/usr/local/cuda
    - --cuda-gpu-arch=sm_61
    - -L/usr/local/cuda/lib64
    - -I/usr/local/cuda/include

clangd seems to not working on windows though...

cloudhan commented 3 years ago

Also, clangd 11.0+ is needed.

Wongboo commented 2 years ago

looks like not work on windows until now

cloudhan commented 2 years ago

@Wongboo It works, but you need to carefully configure it though...

Wongboo commented 2 years ago

@cloudhan , how's your configuration file?

cloudhan commented 2 years ago

This should work: .clangd file:

CompileFlags:
  Add:
    - -std=c++14
    - --cuda-path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
    - --cuda-gpu-arch=sm_61
    - -LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64
    - -IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include

You must not quote your path and must not escape the backslash in the path. Pretty weird here, though.

And you should set your .cu file to cpp mode via vscode's "Chang Language Mode".

image

image

Wongboo commented 2 years ago

@cloudhan, thank you for your code, I think vscode-clangd may make some improvement: vscode-clangd should work under cuda and cuda-cpp language mode

kadircet commented 2 years ago

Some improvements are being discussed in https://reviews.llvm.org/D114326. Feel free to state your opinions there.

Wongboo commented 2 years ago

I think a very simple but useful improvement is to add cuda-cpp to file1 and file2, vscode add language defintion for cuda-cpp