6

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

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

to

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

and the 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 config file as it should in the beginning. In normal C/C++ source files YCM works correct.

Any ideas what is missing?

3
  • You probably need to whitelist it in g:ycm_filetype_whitelist or some other vim script variable.
    – FDinoff
    Commented Nov 18, 2014 at 18:44
  • I took your advice and used the whitelist option, using both general * and 'cuda' keywords, but no luck. I had hope that option would be the solution.
    – labotsirc
    Commented Nov 18, 2014 at 18:59
  • since CUDA uses the 'nvcc' compiler, I start to believe maybe it is not possible.
    – labotsirc
    Commented Nov 18, 2014 at 19:56

1 Answer 1

4

I got this working by the following steps:

First remap .cu files to cpp in your .vimrc

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

Next update .ycm_extra_conf.py with flags for Clang CUDA support.

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 in a header file to your .cu file so Ycm can parse the CUDA builtins. This file, cuda_builtin_vars.h was in my local Clang build.

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

Even with all this, the Clang parser still doesn't seem to accept that my __global__ functions are actually __global__ (even though it can handle the kernel call syntax with any problems), so I usually wrap them with #ifndef __clang__

Sources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.