cs344 »

CS344/ Setting up the Homework files as a Visual Studio Solution

This page describes the steps required to take the provided homework template files (which have been configured for linux using makefiles) and configure a Visual Studio Solution and project.

Assumptions

  1. You already have Visual Studio installed. I am using VS 2010 for the steps below.
  2. The NVidia CUDA toolkit is installed. I am using CUDA Toolkit V5.0
  3. You have the OpenCV libraries are installed and built locally. Others have written instructions on how to do this step. I have used both OpenCV 2.3.1 and 2.4.3

Steps

  • Create a New Project selecting the NVidia Cuda Template (provide the desired project name, solution name, and location)
  • The above creates a project with a sample "kernel.cu" source file in it which we will remove by right clicking it and selecting "Remove"
  • Copy the HW2 source files ( compare.cpp, compare.h, HW2.cpp, main.cpp, reference_calc.cpp, reference_calc.h, student_func.cu, timer.h, utils.h) to the project directory (i.e. where the above kernel.cu file is).
  • Right click on the Project name in your VS Solution Explorer and select Add->Existing Item
  • From the dialog box, select only the following files: main.cpp, timer.h, utils.h, compare.cpp, compare.h, reference_calc.cpp, reference_calc.h, student_func.cu and hit Add.  If you add other file to the solution they will cause build errors.
  • Now we need to tell it where OpenCV includes and libraries are.
  • Right click on the Project name in your VS Solution Explorer and select properties. In the top left corner of the dialog is a "Configuration" list box. Select this and change it to "All Configurations" since we are going to configure Include directories that apply to Release and Debug builds. 
  • In the Configuration property tree on the left side of the dialog, navigate to and select the "General" node under the "C/C++" one.
  • Add the path to your OpenCV include folder in the "Additional Include Directories" edit box in the right pane.  This OpenCV include folder should contain 2 subfolders named "opencv" and "opencv2".  You can either specify a hard coded path followed by a ; (make sure the path string is quoted if you have any spaces in the path name) or use environment variables. If you use environment variables add something like: $(OPENCV_INCLUDEPATH);
  • Next we need to add the linker configuration for OpenCV.  There are slight differences for Release and Debug, so we need to configure these individually.  To handle Release builds, select the "Configuration" list box in the top left corner and choose "Release" instead of "All Configurations".
  • In the Configuration property tree on the left side of the dialog, navigate to and select the "General" node under the "Linker" node.
  • Add the path for the OpenCV release lib folders to the "Additional Library Directories" edit box (followed by a ;). Again, these can either be explicit paths or environment variables like "$(OPENCV_LIBPATH)\Release;" (note I have appended the Release folder to the general library path, so the same environment variable can be used for both).
  • Now navigate to the "Input" node under "Linker" and edit the "Input" edit box to add the 3 OpenCV lib files which are required, namely (for OpenCV 2.4.3) : opencv_core243.lib;opencv_highgui243.lib;opencv_imgproc243.lib;
  • Note: If you are using a different version of OpenCV, the lib names (and dll names) wil be different as they reference the version in their filenames.
  • Now do the same 4 steps for "Debug" configuration. The only differences will be the location of the debug lib folders, and the library filenames all have a "d" appended (e.g.  opencv_core243.lib becomes opencv_core243d.lib, etc. So you should get opencv_core243d.lib;opencv_highgui243d.lib;opencv_imgproc243d.lib;).
  • The Cuda toolkit defaults to generating code targeting "compute_10,sm_10" devices.  To change this to match your GPU, navigate to the "Device" node under the "CUDA C/C++" node and edit the "code generation" edit box. For example, I use "compute_20,sm_21" to match one of my GPU's. I believe the Udacity web environment uses "compute_20,sm_20".
  • Finally, your release and debug build folders will require access to the OpenCV DLL's in order to run them. So you can either copy them over, or add those folders to your "Path" environment variable.
  • An extra step is to add command-line parameters in Visual Studio which is the name of your file "cinque_terre_small.jpg" for Problem Set 2, you have to go to properties of the project and select debugging and put in the Command Argument field the value "cinque_terre_small.jpg"

Picture by picture steps are presented at StackOverflow — see Installing OpenCV 2.4.3 in Visual C++ 2010 Express.

Notes for VS 2012

Ken Domino added a comment about issues he ran into using CUDA 5.0 with Visual Studio 2012. He also provided a link to an article that described steps on using VS 2012 with CUDA 5.0.