我试图使
vim的YCM插件适用于CUDA源文件.
由于CUDA基本上是带有一些扩展的C语法,我认为编辑标准的’.ycm_extra_conf.py’文件就足够了.我换了线
由于CUDA基本上是带有一些扩展的C语法,我认为编辑标准的’.ycm_extra_conf.py’文件就足够了.我换了线
SOURCE_EXTENSIONS = [ '.cpp','.cxx','.cc','.c','.m','.mm']
至
SOURCE_EXTENSIONS = [ '.cpp','.mm','.cu' ]
和线
return extension in [ '.h','.hxx','.hpp','.hh']
至
return extension in [ '.h','.hh','.cuh' ]
但YCM不起作用,它甚至没有要求我在开始时使用配置文件.在普通的C/C++源文件中,YCM工作正常.
什么缺少的想法?
解决方法
我通过以下步骤完成了这项工作:
首先将.cu文件重新映射到.vimrc中的cpp
" Map cuda files to c++ so that Ycm can parse autocmd BufNewFile,BufRead *.cu set filetype=cpp
接下来更新.ycm_extra_conf.py,其中包含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 }
最后,您需要将头文件添加到.cu文件中,以便Ycm可以解析CUDA内置文件.这个文件cuda_builtin_vars.h在我当地的Clang构建中.
#ifdef __clang__ #include <cuda_builtin_vars.h> #endif
即使有了这一切,Clang解析器仍然似乎不接受我的__global__函数实际上是__global__(即使它可以处理任何问题的内核调用语法),所以我通常用#ifndef __clang__包装它们
资料来源:
> https://github.com/Valloric/YouCompleteMe/issues/1766
> http://llvm.org/docs/CompileCudaWithLLVM.html
> https://github.com/Microsoft/clang-1/blob/master/test/SemaCUDA/kernel-call.cu
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。