With the release of CUDA 3.2 RC and Nsight 1.5 this blog post is out of date. Do yourself a favor and get the latest bits and save a lot of hassle.
I spent a few hours today working out how to fix it so that you can compile a CUDA 3.1 project from within VS 2010 using the VS 2008 compiler. There are a couple of blog posts and forum entries they give you most of the detail (see The Details section below if you’re really interested).
Replace your existing files with these and you should be able to build your CUDA project using the custom build rule from VS 2010 provided you have an earlier version of the compiler installed on the machine. This could either be from VS 2005 or 2008 or the appropriate Windows SDK.
The “Path “ field specifies the VcCompilerPath property. This should point to the root directory of the C++ install. It expects to find $(VcCompilerPath)\bin\cl.exe and $(VcCompilerPath)\vcvarsall.bat.
Currently the original dropdown menu items have been replaced with numerical indexes. This isn’t ideal but I’m hoping for a release from Nvidia soon.
In case you really care… There are essentially a couple of hurdles here. Firstly the upgrade tool for VS 2010 breaks the CUDA custom rules file. You can read more about that here and here. Basically “MSBuild does not support expanding environment variables if they are part of the switches when generating tasks”. Which means that EnumValue Switch attributes defined in the Cuda.xml file and that contain properties do not get expanded in the Cuda.targets file. You can fix it by replacing the EnumProperty with a StringProperty and adding a new ItemGroup to the targets file. This applies to the NvccCompilation, CompilerPath and compileout properties.
The next problem is that the CUDA compiler, NVCC, takes a dependency the Visual C++ compiler, CL.EXE, and expects to find it at $(VCINSTALLDIR)\bin. If you are running in VS 2010 this will point to the newer 10.0 compiler and that’s not supported. The simplest solution to this is to add another custom build property which allows the user to specify the path to the version of CL.EXE
See here for a nasty bug which crashes the build unless the Switch="[value]" attributes contain a trailing whitespace.
Cuda.props – Adds a VcCompilerPath property, modified CommandLineTemplate property.
Cuda.xml – Replaces the NvccCompilation, CompilerPath and compileout EnumProperties with StringProperties.
Cuda.targets – Contains ItemGroups to set the correct values for NvccCompilation, compilerPath, compileout and Outputs with property expansion. Adds the VcCompilerPath attribute to the CUDA_Build_Rule.
Each of the changes in clearly commented in the code. Each comment starts “VS2010: “.