YouCompleteMe and CUDA Source Files

I am trying to make a YCM vim plugin to work with CUDA source files. Since CUDA is basically C ++ syntax with some extensions, I thought editing a standard .ycm_extra_conf.py file would be enough. I changed the line

SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm'] 

to

 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm', '.cu' ] 

and line

 return extension in [ '.h', '.hxx', '.hpp', '.hh'] 

to

 return extension in [ '.h', '.hxx', '.hpp', '.hh', '.cuh' ] 

But YCM does not work, it does not even ask me to use the configuration file, as in the beginning. In normal C / C ++ source files, YCM works correctly.

Any ideas what is missing?

+5
source share
1 answer

I got this work by following these steps:

First reassign the .cu files to cpp in your .vimrc

 " Map cuda files to c++ so that Ycm can parse autocmd BufNewFile,BufRead *.cu set filetype=cpp 

The next update is .ycm_extra_conf.py with flags to support Clang CUDA.

 import os import ycm_core includes = ['-I/opt/cudatoolkit/6.5/include', '-I/your/includes/here'] common = ['-std=c++11', '-DUSE_CLANG_COMPLETER', '-I/usr/local/include', '-I/usr/include/clang/3.5/include', '-I/usr/include/x86_64-linux-gnu', '-I/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include', '-I/usr/include', '-I/usr/include/c++/4.9'] cpp_flags = ['-x', 'c++',] # http://llvm.org/docs/CompileCudaWithLLVM.html cuda_flags = ['-x', 'cuda', '--cuda-gpu-arch=sm_35'] def FlagsForFile( filename ): compile_flags = cpp_flags if filename.endswith('.cu'): compile_flags = cuda_flags compile_flags.extend(common) compile_flags.extend(includes) return { 'flags': compile_flags, 'do_cache': True } 

Finally, you need to add a header file to your .cu file so that Ycm can parse embedded CUDA. This file, cuda_builtin_vars.h was in my local Clang assembly.

 #ifdef __clang__ #include <cuda_builtin_vars.h> #endif 

Even with all this, the Clang analyzer still does not believe that my __global__ functions are actually __global__ (even if it can handle the kernel invocation syntax with any problems), so I usually wrap them with #ifndef __clang__

Sources:

+1
source

Source: https://habr.com/ru/post/1207150/


All Articles