加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

vim – YouCompleteMe和CUDA源文件

发布时间:2020-12-15 22:35:13 所属栏目:安全 来源:网络整理
导读:我试图使 vim的YCM插件适用于CUDA源文件. 由于CUDA基本上是带有一些扩展的C语法,我认为编辑标准的’.ycm_extra_conf.py’文件就足够了.我换了线 SOURCE_EXTENSIONS = [ '.cpp','.cxx','.cc','.c','.m','.mm'] 至 SOURCE_EXTENSIONS = [ '.cpp','.mm','.cu' ]
我试图使 vim的YCM插件适用于CUDA源文件.
由于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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读