Someone asked me how to get intellisense working with CUDA files. So here’s a quick post on the couple of simple steps it takes to get it working…
The following assumes you’ve setup a CUDA project with the correct include paths and it builds correctly.
First make sure Visual Studio knows .cu files are C/C++ files:
- Open Tools | Options | Projects and Solutions | VC++ Project Settings
- Add “.cu” to the Extensions To Include (VS2010)
Next add the CUDA include path to the project’s VC++ Directories:
- Open the project’s properties dialog
- Select the Configuration Properties | VC++ Directories tab
- Append $(CUDA_INC_PATH) to the list of Include Directories
Your include Directories property probably looks something like this now, “$(IncludePath);$(CUDA_INC_PATH)”.
Adding the CUDA include path will allow VS to find included CUDA headers, line “cuda.h” in the IDE. Without this step CUDA projects will still compile but right clicking on a CUDA header file and selecting Open Document will not work. If you are using other libraries like Thrust then you will want to make sure that it’s include path is also added here.
If you want to do this for lots of projects you could create a Property Sheet for it.
Then add the CUDA specific keywords to the user defined list:
- Open C:\Users\<USER>\AppData\Local\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\doc\syntax_highlighting\visual_studio_8\usertype.dat (this may be in a hidden AppData folder).
- If usertype.dat isn’t there then try C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\doc\syntax_highlighting\visual_studio_8. (thanks Vlad).
- Create or open the usertype.dat in the same folder as devenv.exe. This is Program Files\Microsoft Visual Studio 10.0\Common7\IDE (or Program Files (x86) on x64 machines. You may have to create this file.
- Copy the contents of the NVIDIA provided file into the one in the devenev.exe folder.
- Restart Visual Studio.
Finally include the right header files in the .cu file:
Typically you should include the following headers:
#include "cuda.h" #include "cuda_runtime.h" #include "device_launch_parameters.h"
This allows the IDE to recognize CUDA specific types like __global__ and not flag them as unknown.
If you open a .cu file you should now see CUDA specific keywords like __device__ colored blue (only blue coloring is supported, this is a bug/limitation).
The end result is a .cu file which recognizes CUDA specific keywords like __device__ and recognizes types like float4.