views:

947

answers:

1

Direct Question: How do I create a simple hello world CUDA project within visual studio 2010?

Background: I've written CUDA kernels. I'm intimately familiar with the .vcproj files from Visual Studio 2005 -- tweaked several by hand. In VS 2005, if I want to build a CUDA kernel, I add a custom build rule and then explicitly define the nvcc call to build the files.

I have migrated to Win 7, and VS 2010 because I really want to try out nSight. I have nSight 1.5 installed. But this is where I'm totally lost. If I proceed as before, nvcc reports that it only supports msvc 8.0 & 9.0. But the website clearly states that it supports VS 2010.

I read somewhere else that I need to have VS 2008 (msvc 9.0) also installed -- my word. Doing so now.

But I'm guessing that at least part of my problems stem from the homegrown custom build tool specifications. Several websites talk about adding a *.rules file to the build, but I've gathered that this is only applicable to VS 2008. Under "Build Customizations" I see CUDA 3.1 and 3.2, but when I add kernels to the project they aren't built. Another website proclaims that the key is three files: Cuda.props Cuda.xml Cuda.targets, but it doesn't say how or where to add these files -- or rather I'll gamble that I just don't understand the notes referenced in the website.

So does anyone know how to create a simple project in VS 2010 which builds a CUDA kernel -- using either the nSight 1.5 setup or the NvCudaRuntimeApi.v3.2.rules file which ships with the CUDA 3.2 RC?

Thanks in advance! I'd offer a bounty, but I only have 65 points total.

+1  A: 

You need either VS 2008 or the 6.1 Windows SDK installed. That's because NSight 1.5 RC or the CUDA 3.2 SDK use the VC 9 compiler under the hood. I've got this working successfully with 2008 installed and am told it should work with the SDK but haven't tried.

With NSight 1.5 and/or the CUDA 3.2 SDK you shouldn't need to muck with any custom build rules. I've been there and it's painful. With the latest builds all that goes away:

  • Create your VC++ project.
  • Add a .CU file to it.
  • Select the project file in the Solution Explorer.
  • Open Project | Build Customizations...
  • Check the "CUDA 3.2 (.targets, .props)" customization.
  • Select a .CU file in your project and hit Alt-Enter to show it's properties.
  • Make sure it's Item Type is set to "CUDA C/C++"

It should just build. Let me know if this helps and if you run into problems as this is from memory.

The good news it getting CUDA working with VS 2010 just got much easier.

Ade

BTW: I'll update my blog post.

Ade Miller
I'm accepting your answer, but as I've temporarily regressed to VS 2008 I haven't had a chance to confirm your answer. I'll do so over the weekend! Thanks so much!
M. Tibbits
I did the same thing and only moved back to VS 2010 a few weeks back (for GTC). It should work let me know if you have issues.
Ade Miller