Skip to content

Conversation

@rietmann-nv
Copy link
Owner

The way CMake compiles cuda files happens in a way that makes it hard for ccls to parse the command and extract the relevant flags to make clang work correctly. I've added a few changes to ccls to add explicit CUDA support in both the file detection and .ccls configuration to make basic things like code completion and jump-to-definition mostly work.

The nvcc command looks like this (notice two step command)

/usr/local/cuda/bin/nvcc -ccbin=gcc-6  -I../src -I../external/cutlass -I../external/cub -isystem=../external/googletest/googletest/include   -Xcompiler -fopenmp --expt-extended-lambda --std=c++11 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -g   -x cu -c /home/max/dev/cuml/ml-prims/test/add.cu -o test/CMakeFiles/mlcommon_test.dir/add.cu.o && /usr/local/cuda/bin/nvcc -ccbin=gcc-6  -I../src -I../external/cutlass -I../external/cub -isystem=../external/googletest/googletest/include   -Xcompiler -fopenmp --expt-extended-lambda --std=c++11 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -g   -x cu -M /home/max/dev/cuml/ml-prims/test/add.cu -MT test/CMakeFiles/mlcommon_test.dir/add.cu.o -o $DEP_FILE

A similar clang command should look something like this:

clang -I../src -I../external/cutlass -I../external/cub -isystem=../external/googletest/googletest/include --std=c++11 --cuda-gpu-arch=sm_70 --cuda-path=/usr/local/cuda-9.2/ -c add.cu

I wanted this for myself and my work, but I know there are others who would like this as well. I wanted to make sure to contribute back, given how much I've been using ccls in the last year. Most of the additions are pretty simple, but the changes I made at project.cc:437 feel a bit hacky, and I wanted your feedback to streamline them into something better, if that is possible. Basically I implemented a whitelist which only allows (-I, -isystem, -std=) type flags. This basically works, but maybe you have a better idea.

Additionally it requires the user to make their .ccls look something like:

%compile_commands.json
%cu --cuda-gpu-arch=sm_70
%cu --cuda-path=/usr/local/cuda-9.2/

The --cuda-gpu-arch=sm_70 and --cuda-path=/usr/local/cuda-9.2/ could possibly be added automatically.

Anyway, thanks for ccls and I look forward to your feedback.

MaskRay and others added 6 commits March 26, 2019 09:02
By default, the background indexer doesn't handle names of no linkage.
They are indexed when their files are opened. This saves memory and
makes cache files smaller.
Reported by David Welch in #350.

This fixes double-free of llvm::MemoryBuffer when parsing fails.
Note with -fretain-comments-from-system-headers, the .gch of bits/stdc++.h becomes larger by 1%, but that is fine.

Fix #373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants