How to Enable Syntax Highlighting for CUDA files in Visual Studio 2005?

 

It’s really awkward if the CUDA file displayed as a normal file in Visual Studio. It’s essentially following C style format. But the keywords are different from C/C++. But Visual Studio is flexible enough to give editor experience for a custom file.

image

So what you’ve to do to enable syntax highlighting for CUDA Source files? It’s clearly described in the CUDA SDK help files.

1. Setup CUDA in your box. (Install the CUDA SDK and CUDA Toolkit)

2. Browse to “Microsoft Visual Studio 8\Common7\IDE” folder from your program files folder

3. Open the user “usertype.dat” file from the folder. If the file doesn’t exists, create a new one in the name.

4. Open the %Program Files%\NVIDIA Corporation\NVIDIA CUDA SDK\doc\syntax_highlighting\visual_studio_8

5. Append the content of “usertype.dat” to the previously opened “usertype.dat” file from “Microsoft Visual Studio 8\Common7\IDE”

6. Save the file

7. Open You IDE and Take Tools -> Options.

8. Under Text Editor -> File Extension tab, specify the extension “cu” as a new type (as pictured below)

image

1. Restart your IDE

2. Enjoy Syntax highlighting

Note that the above settings are applicable for Visual Studio 8 only. For Visual Studio 7 the setup is slightly different. You can see the instruction from NVIDIA Corporation\NVIDIA CUDA SDK\doc\syntax_highlighting\visual_studio_7 folder once you install the CUDA SDK.

Sharing my thoughts...

 
  • http://sarathc.wordpress.com/2008/09/26/how-to-integrate-cuda-with-visual-c/ How to Integrate CUDA with Visual C++ « Sharing my thoughts…

    [...] But in Windows world, most of the developers are much satisfied with the IDE Visual Studio. So may have to leave the world of command line compilation and source editing in favor of improving our productivity. If we can integrate the CUDA development to Visual Studio IDE, that’s pretty nice no? In one of my previous post, I said about enabling syntax highlighting for CUDA files under Visual Studio. [...]

  • RockSamurai

    It was very helpful.
    Thanks

  • Fooble

    Note that this enables syntax highlighting (which is really nice), but it doesn’t enable IntelliSense for .cu files.

  • Nevaco

    That’s correct Fooble. But do you know how to enable IntelliSense so it can support Cuda functions, variables, etc??

  • cr333

    Just to let you know, this also works on Visual Studio 2008 which is supported from CUDA 2.1 beta onwards.

  • MechLab

    It doesn’t Quite work for VS2008 -
    All the c highlighting works fine – from the .cu file association However CUDA keywords are still not highlighted…
    __global__
    __host__
    __device__
    __constant__
    __shared__

  • http://-- RAMIN

    HOW DO Keyword highlight in visual c++ 6.0????
    BACKGROUND TEXT
    OR
    SET COLOR(X,Y)
    visual c++ 6.0
    visual c++ 6.0
    visual c++ 6.0
    visual c++ 6.0

    PLEAS HELP ME
    INTERMANCH@GMAIL.COM

  • ipapag

    Thank you! Really useful! It works for Visual Studio 2005!

  • Anderson

    Syntax Highlighting worked for the VS 2008 as well.

    Thank you!

  • Bruno

    Thank you for the post.
    Worked pretty fine.

  • http://nanowave.com/development/2009/06/08/cuda-environment-setup/ CUDA Environment Setup « NanoWave Development

    [...] Enable CUDA Syntax Highlighting from MS Visual C++ [...]

  • steven

    Thanks very much :)

  • ___Harry___

    Thanks! This is really great!

  • Jahanzeb

    Thank you so much!

    This really helped me out…

  • S.A

    Thank you this worked perfectly : )

  • Bobted

    Works for VS 2008 also!

  • http://www.michalnowicki.com.pl/?p=59 Nvidia Cuda – tutorial | Michał Nowicki

    [...] chyba z wykorzystaniem Visual Studio. Jeżeli ktoś zdecyduje się na taką opcję to polecam ten link. Znajduje się tam krótki tutorial jak ustawić podświetlanie składni kodu dla plików .cu, a [...]