Microsoft has given a complete facelift to the new Visual Studio 2010. A whole bunch of new features and removal of a couple of them. With the new VS 2010, you cannot define custom build rules with .rules file as it was done before. Now there’s a whole new bunch of modules that need to imagebe specified in order to make a set of custom build rules to work with Visual Studio 2010 project. This blog explains the steps involved in making CUDA work on the new Visual Studio 2010.

I have used the following for this guide:

  • Visual Studio 2010 running on Windows 7 x64
  • NVIDIA CUDA Toolkit 3.2 (Download from here)
  • NSight Host and Monitor 1.5 (Download from here)
  • NVIDIA CUDA SDK 3.2 (Download from here)

And yes, you need to have Visual Studio 2008 installed or at least you should have VC90 C compiler on your machine with the appropriate Windows SDK. So this is what I have in addition to the above:

  • Visual Studio 2008
  • Windows SDK v6.0A

The latest CUDA Toolkit 3.2 does not has support for the VS100 C compiler and hence the reason why you still need to have Visual Studio 2008 installed on your machine. Also make sure you have the right Windows SDK (or at least anything below Windows SDK v7.0 which is automatically installed with VS 2010). Now we are ready to get started.

Now the reason why you need to have NSight installed. Without NSight, you will have to manually specify the CUDA properties and target files so in order to avoid that, better download and install NSight (link). Make sure you enable NSight for both VS 2008 and VS 2010. Now we’re ready to roll!

Step 1: Creating an Empty Project

Open VS 2010 and create a new Visual C++ Empty Project:
image

Step 2: Specify Build Customization and Add CUDA Source File

Now go to the Project’s Properties –> Build Customizations. If you have installed CUDA Toolkit 3.2 and NSight 1.5 then you should see the following option:image

I will only add a simple .cu CUDA source file which has a simple kernel that adds a constant number to an integer vector. I have the main function written in the same file that sets up the kernel launch parameters and everything in-between :) I have given the download link of the complete CUDA Visual Studio 2010 template solution at the end of this blog.

Now go to Project –> Properties –> General and change Platform Toolset from V100 to v90. This will specify that you are using v90 C compiler for this project. If you do not have VS 2008 on your machine then you won’t even see this option so make sure you have it installed:

image

Now you are all set to Build your project! Just tune in the right setting of your CUDA application from Projects –> CUDA C/C++ (Host and Device settings) and you’re all set to go.

Common Issues:

In case you cannot find the CUDA 3.2 Target and Props files, look here:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations

Note: I will keep this section updated with more commonly faced issues and their solutions. If you’re facing an issue, post it in the comments and I will respond.

That’s about it. I have uploaded the Sample VS 2010 Solution file which you can download from here. You can use it as a template for your CUDA projects :)

  • Guest

    Hi, thanks for the post. Just one question: Have you ever been able to use the npp library (and cuvilib) in vs2010?

    • Anonymous

      Yes we have used NPP in VS2010 with CUDA 4.0 and we are compiling CUVI for CUDA 4.0 that will also run on VS2010

  • Pingback: NVIDIA CUDA 4.0 Tips and Issues()

  • Randyll

    Hey, I followed your guide and ran in to an ambiguous bit. As your links for the CUDA Toolkit and SDK point to the same page, I thought the SDK came with the toolkit. Which it didn’t! It’s actually in the “GPU Computing SDK code samples” package.

    Specifically, VS2010 was complaining about cUtil64D.lib missing. Installing the SDK code samples fixed that.

    • Anonymous

      The links are to the general CUDA download page which contains all the relevant downloads. Yes the CUTIL comes with the SDK package but starting from CUDA 4.0 you will not get Cutil as a library but rather you will find the whole cutil source as a solution file in the SDK which you will have to compile for your machine.

  • CUDAnoobie

    Hello, I have followed the steps outlined in your post (thanks for making this available). However, when I try to compile the Sample solution file I run into this error:

    nvcc fatal : Unsupported host compiler ‘x86_amd64′

    I’ve been trying to get a CUDA project to compile in VS2010 all day and this is driving me crazy. Any help would be much appreciated.

    • Anonymous

      @CUDANoobie

      Did you change the compiler from VC100 to VC90 in the Project -> Options -> General? Also make sure that CUDA C/C++ Host platform matches the platform of your project.

      • CUDAnoobie

        Thank you for your reply Salman. Yes I have checked that the compiler has been set to VC90. I’m sorry, but I don’t understand what you mean by the CUDA C/C++ Host platform matches the platform of my project. I am using Win7 64-bit VS2010.

        Here is the exact error I get. Thanks for your time.

        1>—— Rebuild All started: Project: VS2010Test, Configuration: Debug x64 ——
        1>Build started 3/20/2011 12:28:37 PM.
        1>_PrepareForClean:
        1> Deleting file “x64DebugVS2010Test.lastbuildstate”.
        1>CudaClean:
        1>
        1> C:UsersSantosDocumentsVisual Studio 2010ProjectsVS2010TestVS2010Test>”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv3.2\binnvcc.exe” -ccbin “C:Program Files (x86)Microsoft Visual Studio 9.0VCbinx86_amd64″ -I”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv3.2\include” –keep-dir “x64Debug\” -maxrregcount=32 –machine 64 –compile -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MTd ” -o “x64Debugkernel.obj” “C:UsersSantosDocumentsVisual Studio 2010ProjectsVS2010TestVS2010Testkernel.cu” -clean
        1> nvcc fatal : Unsupported host compiler ‘x86_amd64′
        1>C:Program Files (x86)MSBuildMicrosoft.Cppv4.0BuildCustomizationsCUDA 3.2.targets(352,3): error MSB3721: The command “”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv3.2\binnvcc.exe” -ccbin “C:Program Files (x86)Microsoft Visual Studio 9.0VCbinx86_amd64″ -I”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv3.2\include” –keep-dir “x64Debug\” -maxrregcount=32 –machine 64 –compile -D_NEXUS_DEBUG -g -Xcompiler “/EHsc /nologo /Od /Zi /MTd ” -o “x64Debugkernel.obj” “C:UsersSantosDocumentsVisual Studio 2010ProjectsVS2010TestVS2010Testkernel.cu” -clean” exited with code -1.
        1>
        1>Build FAILED.
        1>
        1>Time Elapsed 00:00:00.19
        ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

        • CUDAnoobie

          Ah, ok I think I figured out what you mean. I set the platform to Win32 and I no longer get that error. However, now I am getting error messages about unresolved external symbols. Specifically:

          1>kernel.obj : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _main
          1>kernel.obj : error LNK2019: unresolved external symbol _cudaMemcpy@16 referenced in function _main
          1>kernel.obj : error LNK2019: unresolved external symbol _cudaMalloc@8 referenced in function _main
          1>kernel.obj : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function “void __cdecl __device_stub__Z10kernelTestPii(int *,int)” (?__device_stub__Z10kernelTestPii@@YAXPAHH@Z)
          1>kernel.obj : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function “void __cdecl __sti____cudaRegisterAll_41_tmpxft_000006e0_00000000_3_kernel_cpp1_ii_e3d0f572(void)” (?__sti____cudaRegisterAll_41_tmpxft_000006e0_00000000_3_kernel_cpp1_ii_e3d0f572@@YAXXZ)
          1>kernel.obj : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function “void __cdecl __sti____cudaRegisterAll_41_tmpxft_000006e0_00000000_3_kernel_cpp1_ii_e3d0f572(void)” (?__sti____cudaRegisterAll_41_tmpxft_000006e0_00000000_3_kernel_cpp1_ii_e3d0f572@@YAXXZ)
          1>kernel.obj : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function “void __cdecl __cudaUnregisterBinaryUtil(void)” (?__cudaUnregisterBinaryUtil@@YAXXZ)
          1>kernel.obj : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function “enum cudaError __cdecl cudaLaunch(char *)” (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)
          1>C:UsersSantosDocumentsVisual Studio 2010ProjectsVS2010TestDebugVS2010Test.exe : fatal error LNK1120: 8 unresolved externals

          • CUDAnoobie

            Ok, I got it working. Thanks for your wonderful blog. Have a great day!

          • Stanley

            How did you manage with this problem? I suppose you had all names connected with cuda highlighted?

          • Anonymous

            Probably he did not specify the additional dependency (cudart.lib). Try that and it should be resolved.

          • Stanley

            I added cudart and included . Then almost all highlights disappeared, but there remained 3 highlighted: threadIdx, blockIdx and blockDIm.

          • Stanley

            I mean such an error: IntelliSense: identifier “threadIdx” is undefined

          • Seshu

            Hello, I am a beginner in Cuda programming, just still struggling to get my first program compiled :( I had Cuda 4.2 version, Visual studio 2010 installed, and nothing else(Nsight is NOT) I cant see the Cuda4.2.props file in custom build folder so wasnt able to compile anything, What should I do and how to check whether I have a Windoes SDK already installed with Visual studio? please reply asap. Thanks in advance.  

          • Seshu

            Hello, I am a beginner in Cuda programming, just still struggling to get my first program compiled :( I had Cuda 4.2 version, Visual studio 2010 installed, and nothing else(Nsight is NOT) I cant see the Cuda4.2.props file in custom build folder so wasnt able to compile anything, What should I do and how to check whether I have a Windoes SDK already installed with Visual studio? please reply asap. Thanks in advance. 

  • MOtto

    HI,

    I try to get CUDA runnign with VS 2010 like you described. Cuda 3.2 SDK, Nsight 1.51, VS 2008 SP1, and VS 2010 are installed. I choose “Build Customizations” -> Cuda3.2, but I get no additional menu entry “CUDA C / C++” in the property menu of the project. Also the *.cu files are not compiled. In VS 2008 everting works well, I don’t know why not with VS 2010?
    Does anyone know how to fix this?

    • Jacek

      Same here, please help. I have installed everything (excluding VS 2008) and there is no “CUDA C/C++”.

  • John Seers

    Hi Salman
    I seem to be going round in circles trying to get CUDA running but this article looks like the best help I have found to date, so thank you. I am on Windows 7 64 bit, I have installed Visual Studio Express 2008 with SP1. (I am fairly sure I have SP1 installed anyway though I have a small lingering doubt.).   I have also installed Visual Studio 2010 with its SP1. I have cudatoolkit_4.0.17_win_64 and cudatools_4.0.17_win_64 installed. When I try to install Parallel_Nsight_Win64_2.0.11140 it will not let me saying that it cannot find Visual Studio 2010 and Visual Studio 2008 SP1 is not installed. Can you point me in a direction to solve this? Thanks. 
    John Seers

  • Jace

    Hello, I have search in all possible places and couldn’t found “Build Customization Files” dialog in project’s properties. Where is it?

    • Jacek

      OK I get it. It took me long time but I found out that it is NOT in project properties. It is in a context menu when RMB on a project in the solution explorer.

  • Eisenhiem

    I need to integrate CUDA 4.0 with Visual Studio 2010. Can You please post step by step procedure for doing that? thanks.

  • pnss

    hello,
       We are using vs2010,cuda 4.0 toolkit,cuda sdk.The codes are getting executed without any error but we not getting the expected output.It isn’t any logical error,the allocation is not getting done on the cuda device…what must be wrong??pls help!!!

  • http://www.top-password.com/ RecoveryTool

    It’s very useful!

  • Pingback: Install Cuda and Use Managed Code with VS 2008 Express on Windows 7-x64 | Programmer Solution()

  • Paul Dent

    Had same problems as others here with lack of basic tutorials for newbies. Finally got VS 2010 customaized to work “sort of” with CUDA 4.0.  My problem now is, it says “Build Succeeded” but no .exe file is created.

    What am I missing?

    Thanks,

    Paul

  • Mike Pelton

    Just in case you arrived here as I did, all these issues go away with the latest version of Nsight (as of Jan 28th 2012) – the installer does all the heavy lifting and you can do File -> New Project -> NVidia -> Cuda 4.1

    • Travi87

      Hey I am doing the same thing . But i get the error “”cudaError at memory location 0x002ef674″” .  My program just has a single cudaMalloc . Can you help ??

      Regds,
      Raki

    • Qadha

      I that truth?? I have Geforce GTX560 and I have CUDA toolkit 4.1 and Nsight 2.1

  • Christian-roig

  • Seshu

    Can someone please help me out with this, I have Cuda 4.2 version installed(both SDK and tool kit) and VIsual studio 2010. Should I have to download the Windows SDK also? if so what version is compatable with Version 4.2 ? please help me out I need help very soon, Thanks in advance.

  • http://www.creativementor.com.au/myob-training-courses.html myob course online

    Visual studio 2010 is latest version of visual studio and also it has many features and tools to implement in project. This post is very helpful to explain the steps to run CUDA in visual studio 2010.

  • Pingback: “Hello World!” in CUDA – Brainlings.com()

  • Pingback: Install Cuda | HARD-SOFT Something More()