vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

How to write CUDA?

Open pogevip opened this issue 4 years ago • 9 comments

image

pogevip avatar Dec 23 '20 03:12 pogevip

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 avatar Jan 04 '21 08:01 cloudhan

Also, clangd 11.0+ is needed.

cloudhan avatar Jan 04 '21 08:01 cloudhan

looks like not work on windows until now

Wongboo avatar Nov 26 '21 03:11 Wongboo

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

cloudhan avatar Nov 26 '21 03:11 cloudhan

@cloudhan , how's your configuration file?

Wongboo avatar Nov 26 '21 04:11 Wongboo

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

cloudhan avatar Nov 26 '21 04:11 cloudhan

@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

  • by my testing, you can remove -LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64 and -IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include from configuration, which still works. My final question is my environment variable already have CUDA_PATH, can I simple write something like -xcuda to use CUDA_PATH ?

Wongboo avatar Nov 26 '21 04:11 Wongboo

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

kadircet avatar Nov 26 '21 09:11 kadircet

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

Wongboo avatar Nov 29 '21 03:11 Wongboo