How do I start a CUDA app in Visual Studio 2010?

CUDA TOOLKIT 4.0 and later

The build customisations file (installed into the Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations directory) “teaches” Visual Studio how to compile and link any .cu files in your project into your application. If you chose to skip installing the customisations, or if you installed VS2010 after CUDA, you can add them later by following the instructions in Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration.

  • Create a new project using the standard MS wizards (e.g. an empty console project)
  • Implement your host (serial) code in .c or .cpp files
  • Add the NVIDIA build customisation (right click on the project, Build customizations, tick the relevant CUDA box)
  • See note 1 if using CUDA 4.0
  • Implement your wrappers and kernels in .cu files
  • If you added .cu files before the build customisations, then you’ll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
  • Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> Input add cudart.lib to the Additional Dependencies)
  • Then just build your project and the .cu files will be compiled to .obj and added to the link automatically

Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it’s just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall wrapper calls exit() if the function fails – a real application (as opposed to a sample) should probably handle the failure more elegantly!


NOTE

  1. For CUDA 4.0 only you may need to apply this fix to the build customisations. This patch fixes the following message:

The result “” of evaluating the value “$(CudaBuildTasksPath)” of the “AssemblyFile” attribute in the element is not valid

Leave a Comment