{"action":"opened","issue":{"url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1766","labels_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1766/labels{/name}","comments_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1766/comments","events_url":"https://api.github.com/repos/Valloric/YouCompleteMe/issues/1766/events","html_url":"https://github.com/Valloric/YouCompleteMe/issues/1766","id":116469367,"number":1766,"title":"CUDA C completions with YCM","user":{"login":"ethanwilloner","id":3634794,"avatar_url":"https://avatars.githubusercontent.com/u/3634794?v=3","gravatar_id":"","url":"https://api.github.com/users/ethanwilloner","html_url":"https://github.com/ethanwilloner","followers_url":"https://api.github.com/users/ethanwilloner/followers","following_url":"https://api.github.com/users/ethanwilloner/following{/other_user}","gists_url":"https://api.github.com/users/ethanwilloner/gists{/gist_id}","starred_url":"https://api.github.com/users/ethanwilloner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethanwilloner/subscriptions","organizations_url":"https://api.github.com/users/ethanwilloner/orgs","repos_url":"https://api.github.com/users/ethanwilloner/repos","events_url":"https://api.github.com/users/ethanwilloner/events{/privacy}","received_events_url":"https://api.github.com/users/ethanwilloner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-12T02:56:12Z","updated_at":"2015-11-12T02:56:12Z","closed_at":null,"body":"I have been trying to get completion with CUDA headers working with YCM, and it has been a bit of a tough road. I have not really found anything comprehensive on the internet to get this working, so I thought I would document it here, and maybe get some feedback from others in the community on how I have done this. I am not trying to, nor do I need, really advanced completion like what one may find in Visual Studio, but enough to make development not a pain. Hopefully this can help anyone else who is looking for this solution.\r\n\r\nWhat I have found so far is this:\r\nIn C or C++ files (.c or .cpp) , by including various cuda headers, such as the following, I can have properly functioning completion for cuda functions (ie: cudaMemcpy, cudaMalloc, etc).\r\n```CUDA\r\n#include <cuda.h>\r\n#include <cuda_runtime.h>\r\n#include <cuda_device_runtime_api.h>\r\n#include <device_functions.h>\r\n```\r\nThis said, as soon as I transition to CUDA C files (.cu or .cuh), the completion stops working.\r\n```\r\nOption 'omnifunc' is not set\r\n```\r\nTo get around this, I use the following in my .vimrc to set any files of type 'cuda' to type 'c':\r\n```VimL\r\nautocmd FileType cuda set ft=c\r\n```\r\nThis workaround is effective for getting autocompletion to work, However it obviously breaks some CUDA syntax highlighting provided by some plugins (In my case Syntastic). This also requires having the above CUDA headers included somewhere. Additionally, I found a reference to\r\n```CUDA\r\n#include <cuda_builtin_vars.h>\r\n```\r\nin the ycmd source code, and including that header seems to enable some additional completions of things like threadIdx, gridDim, blockDim and blockIdx, although this is very much a file reference built into LLVM, so you must include\r\n```CUDA\r\n#ifdef __clang__\r\n#include <cuda_builtin_vars.h>\r\n#endif\r\n```\r\nin your .cu files to ensure that NVCC doesnt try to include it.\r\n\r\nThe last piece of information that I have found is that if you are creating something which will be compiled and linked to C applications, you are going to have some issues. From what I understand, the NVCC compiles your CUDA C code as C++, which means that there is going to be name mangling. To get around this, one must use \r\n```C\r\nextern \"C\" {\r\n#include \"myheaderfile.h\"\r\n}\r\n```\r\nto prompt the compiler to not mangle the names so that they can be called from regular C code (and of course declaring it in the header file as extern). However, this seems to break YCM's autocompletion, and reverts to only being able to do completions with functions that are already being used in the source file. The only thing I could think of to fix this was to re-include the CUDA headers in the .cu file instead of just in the .h file, but doing that does not seem to resolve the issue. Any insight into getting this to actually function would be awesome.\r\n\r\nI suppose this has evolved into slightly more than just relating to YCM, but hopefully the intent is clear: I am just hoping for some feedback and input that might help me figure out how to get this working a bit more optimally, if possible, or if there is something that needs to be done in YCM itself to overcome some of these issues. My setup is currently Debian Unstable with CUDA 6.5, so I am not sure if this is more easily addressed in newer versions of the NVCC, which as I understand now supports the LLVM compiler.\r\n\r\nFeel free to just close this if this is not within the scope of being fixed, or on topic. I just felt the need to document the issues I had with CUDA C and YCM and make sure that people have a way to find some of the solutions to the problems that I sort of struggled through to get this all working in a mostly functional manner. Any additional input would be great! And please tell me if this needs some sample source code or not.\r\n\r\nThanks!"}}