Visual Studio 2010 Adding Intellisense Support for CUDA C

Thursday, October 28, 2010 – 8:01 PM

nvidia_logo 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:

  1. Open Tools | Options | Projects and Solutions | VC++ Project Settings
  2. Add “.cu” to the Extensions To Include (VS2010)

Next add the CUDA include path to the project’s VC++ Directories:

  1. Open the project’s properties dialog
  2. Select the Configuration Properties | VC++ Directories tab
  3. 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:

  1. 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).
  2. 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).
  3. 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.
  4. Copy the contents of the NVIDIA provided file into the one in the devenev.exe folder.
  5. 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).

CUDA with Intellisense.

The end result is a .cu file which recognizes CUDA specific keywords like __device__ and recognizes types like float4.

  1. 27 Responses to “Visual Studio 2010 Adding Intellisense Support for CUDA C”

  2. Unless I am missing something this doesn’t enable intellisense, it simply colorizes C and CUDA keywords in .cu files. Intellisense is when the editor gives you choices in a pop up list box after typing a letter or two. Like I said I could have missed something.

    By Bob on Nov 13, 2010

  3. Bob,

    Is this not working for you? There are two steps, the first of which should cause VS to recognize .CU files. As you can see from the picture you end up with intellisense dropdowns on float4, a CUDA specific type. As I mention I’ve had some issues with some types of CU files, like ones including the Thrust libraries.

    Ade

    By Ade Miller on Nov 13, 2010

  4. To get the intellisense to fully work, please include the following on the source files:

    #include
    #include

    By Gabe on Dec 7, 2010

  5. Previous post did not escape symbols…
    #include %ltcuda_runtime.h%gt
    #include %ltdevice_launch_parameters.h%gt

    By Gabe on Dec 7, 2010

  6. Thanks Gabe,

    I updated the article accordingly mand added in some more steps so that #includes can be resulved correctly by the IDE.

    Ade

    By Ade Miller on Dec 12, 2010

  7. Ade, first let me thank you for your helpfull pointers. Got both syntax highlighting and intellisense working. One little bit that bugs me is that intellisense complains on the 3rd “<" of the "<<>>” syntax for calling CUDA kernels with: “Intellisense expected an expression”. Are you seeing the same behavior?

    Thanks again,

    Mike

    By Mike on Jan 10, 2011

  8. I cant find devenv.exe even through Windows search. I copied usertype.dat into the said VS folder though but it is not working. Can somebody please help me out

    By Kedar on Jan 15, 2011

  9. Mike,

    Yes. I see the same behavior. The steps I provide here enable intellisense for .CU files and add some additional CUDA keywords but the intellisense engine is still the same. There are some bits of CUDA related syntax it doesn’t know about so there are still some limitations.

    Thanks,

    Ade

    By Ade Miller on Jan 17, 2011

  10. This works. Thanks!

    However I’m still getting the red wavy underline on <<< :)

    By Alex on Feb 12, 2011

  11. Alex,

    I think the red squigglies under <<< and >>> are unavoidable. I guess you could try adding them to the list of keywords but I suspect that isn’t going to help.

    Ade

    By Ade Miller on Feb 12, 2011

  12. Hi Ade,

    I already had syntax highlighting. Checked include paths, manually checked the Text Editor -> All Languages -> General and checked both the settings for intellisense but I still cannot see intellisense. I have Win7 x64, VS2010 and CUDA Toolkit 3.2.

    Do you smell anything that I am not doing?

    By Salman on Feb 26, 2011

  13. Great topic!
    Everytinhg work fine! :)

    Thanks

    By ripper on Mar 2, 2011

  14. For me, the usertype.dat was not located in the “Users” directory, but in “C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\doc\syntax_highlighting\visual_studio_8”. Took me some time to find it. I’m using Win7/64bit.

    By vlad on Apr 18, 2011

  15. I’m getting this error : error MSB4062: The “Nvda.Build.CudaTasks.SanitizePaths” task could not be loaded from the assembly C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\Nvda.Build.CudaTasks.dll
    Do you figure something about it?

    By Pedro on Apr 18, 2011

  16. btw, to get sintax highlighting other than blue in 2010, one can change the ‘C/C++ User Keywords’ entry in the ‘Fonts and Colors’ options tab.

    By max on Apr 19, 2011

  17. Vlad,

    Thanks. I updated the post above. It maybe to do with how I installed the SDK.

    Ade

    By Ade Miller on Apr 22, 2011

  18. Pedro,

    Do other standard SDK samples build OK without this update. I don’t have this DLL. Which version of the CUDA SDK do you have installed?

    Ade

    By Ade Miller on Apr 22, 2011

  19. Hey, I still having some trouble with intellisense picking up kernel calls. I posted a question on stackoverflow here:
    http://stackoverflow.com/questions/6061565/setting-up-vs-2010-intellisense-for-cuda-kernel-calls

    Any chance I can get some help with that?
    Oh, and in case your’re wondering I’m using nsight 2.0 and cuda 4 rc2.

    By SJQ on May 19, 2011

  20. I think the reply on SO is pretty much correct. I’d argue that it’s a bit more than a trick relying on the language similarities in that Visual Studio provides an extension mechanism for this (namely the ability to define new keywords etc) but it has limits and the kernel call syntax is one of them.

    In short this isn’t going to work in any version of CUDA.

    Not the answer you wanted I know, but that’s the way it is.

    Ade

    By Ade Miller on May 20, 2011

  21. Hey I one more question, did you manage to get Intellisense to recognize the __syncthreads() function? Again everything compiles fine, but this time Intellisense doesn’t pick up on the function at all…

    By SJQ on May 22, 2011

  22. Hey guys, Since this is the top result on google right now for: I managed to get intellesense working perfectly by following the directions in the readme.txt file found in the same folder as usertype.dat (the OP left out step #2)

    Or for sake of ease:
    “1. If you don’t have a usertype.dat file in your “Microsoft Visual Studio 8\Common7\IDE” folder, then copy the included usertype.dat file there. If you do, append the contents of the included usertype.dat onto the end of the “Microsoft Visual Studio 8\Common7\IDE\usertype.dat”

    2. Start Visual Studio 8. Select the menu “Tools->Options…”. Open “Text Editor” in the tree view on the left, and click on “File Extension”. Type cu in the “Extension” box, set the editor to “Microsoft Visual C++” and click “Add”. Click “OK” on the dialog box.

    3. Restart Visual Studio and your CUDA code should now have syntax highlighting.”

    By Graham Hayes on Jun 29, 2011

  23. Thank you so much. This worked great for syntax highlighting, but to get intellisense working right, I found I had to

    1. Close VS2010
    2. Delete the .sdf file in the solution’s root folder. I deleted all the output directories for good measure as well
    3. Reopen the solution in VS2010 and recompile

    By Gabriel on Sep 2, 2011

  1. 5 Trackback(s)

  2. Oct 29, 2010: Dew Drop – October 29, 2010 | Alvin Ashcraft's Morning Dew
  3. Oct 30, 2010: progg.ru
  4. Dec 12, 2010: CUDA and Intellisense updated | #2782 - Thinking about agile (small 'a') software development, patterns and practices for building Microsoft .NET applications.
  5. Oct 17, 2011: Is it possible to enable syntax highlighting for CUDA 4.0 in Visual Studio 2010? - Programmers Goodies
  6. Nov 1, 2011: “Hello World!” in CUDA | Brainlings.com

Sorry, comments for this entry are closed at this time.