Sunday, February 17, 2013

How to make a new CUDA project in VS 2012

this post is an update for How to make a new CUDA project in VS 2010 but this time for 2012

I'm using Windows 8 64-bit with Microsoft Visual Studio 2012, and Nvidia CUDA 5.0

first you must do these steps once:

1- copy files "CUDA 5.0.props, CUDA 5.0.targets, CUDA 5.0.xml, and Nvda.Build.CudaTasks.v5.0.dll" to:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations

2- copy "host_config.h" and replace the one in:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include

3- copy "usertype.dat" from:
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\doc\syntax_highlighting\visual_studio_8
to:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

4- in Visual Studio 2012 IDE Select Tools menu -> Options -> Text Editor -> File Extension
type "cu" under Extension and select "Microsoft Visual C++" from Editor list and click Add

then these steps are for creating a new project:

1- create a New Project -> C++ Win32 Console Application -> Empty Project

2- mark the project in the Solution Explorer, then select Project menu -> Build Customizations -> CUDA 5.0 or whatever version you're using

3- right click the project in the Solution Explorer and select Properties

4- select VC++ Directories and add to Include Directories:
$(CUDA_INC_PATH)

5- select Linker -> General and add to Additional Library Directories:
$(CUDA_PATH)/lib/$(PlatformName)

6- select Linker -> Input and add to Additional Dependencies:
cudart.lib

7- now add your .cu file

hint: include 
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
because Visual Studio will give you error for some CUDA keywords but will compile fine

your comments are welcomed

special thanks to Angga Reza Fardana for modifying the files and to Ade Miller too

5 comments:

  1. Thank you for posting this, it was extremly helpful!

    ReplyDelete
  2. Hi,y`ll
    I have profesional VS 2012
    and I configured Cuda and VS says :"cannot locate project_name.exe"
    I know all compilers have an exe file to create exe file in project!!
    Help ME

    ReplyDelete
    Replies
    1. hello,
      assuming you installed CUDA and Nvidia Developer Driver, correctly:

      1- please try running any of the CUDA samples in "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v5.0\bin\win64\Release" or you can use the shortcut "NVIDIA CUDA Samples Browser v5.0" on Desktop

      now assuming you followed all the steps in the blog

      2- please try the this program http://www.mediafire.com/?n4ks77lymz0b7aw
      and please re-check all the configurations again before running because some configurations may change when you copy a project

      if this example worked the error would be in your code
      I would be pleased to help you further

      best wishes

      Delete