You are on page 1of 5

Configuring Windows and Visual Studio 2005 for use with CUDA

Prerequisites and Windows Configuration 1) x86 CPU based system running Microsoft Windows XP or Vista Operating System with all available service packs, patches and updates 2) Compute-capable NVIDIA GPU on system: See
http://www.nvidia.com/object/cuda_learn_products.html

3) CUDA 2.1 compatible Driver and CUDA 2.1 Toolkit a) Laptop/Notebook Drivers for GeForce and Quadro NVS GPUs i) http://www.nvidia.com/object/notebook_drivers.html b) For Windows XP, 32 bit edition i) Desktop PC Driver:
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/drivers/180.60_CUDA_XP_beta.exe

ii) Toolkit:
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/toolkit/windows/CudaSetup-win32-relnightly-2.1.1635-3046817.exe

c) For Windows XP, 64 bit edition i) Desktop PC Driver:


http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/drivers/180.60_CUDA_XP64_beta.exe

ii) Toolkit:
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/toolkit/windows/CudaSetup-win64-relnightly-2.1.1635-3046817.exe

d) For Windows Vista, 32 bit edition i) Desktop PC Driver:


http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/drivers/180.60_CUDA_Vista_beta.exe

ii) Toolkit:
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/toolkit/windows/CudaSetup-win32-relnightly-2.1.1635-3046817.exe

e) For Windows Vista, 64 bit edition i) Desktop PC Driver:


http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/drivers/180.60_CUDA_Vista64_beta.exe

ii) Toolkit:
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/2.1-Beta/toolkit/windows/CudaSetup-win64-relnightly-2.1.1635-3046817.exe

4) Note that the CUDA Toolkit installation should create the following definitions in your system Environment Variables (assuming you accepted the default installation parameters): i) CUDA_BIN_PATH should be defined as: ii) CUDA_INC_PATH should be defined as: iii) CUDA_LIB_PATH should be defined as:
c:\CUDA\bin c:\CUDA\include c:\CUDA\lib

iv) Check these by Left-Clicking on Start, Right-Clicking on My Computer (XP) or Computer (Vista) and Left-Clicking on Properties. In the dialog box presented, Left-Click on the Advanced tab (XP) or Advanced System Settings item (Vista) and Left-click on the Environment Variables button. Review the list presented in the Environment Variables dialog presented. If the above entries are not listed, add them using the ew button and typing in the Names above (e.g. CUDA_BIN_PATH) and the Paths above (e.g. c:\CUDA\bin)

5) Set Windows file association and default file icon for .cu files a) This procedure will cause Windows to open CUDA .cu files with Visual Studio and will cause file icons in Windows file explorer, your desktop and within the Visual Studio solution explorer pane to bear the Visual Studio icon. b) If you do not have a sample CUDA *.cu code file, created an empty / dummy *.cu file: i) Right-click on your desktop, select New from the popup menu, and select Text Document from the additional drop-down popup menu that appears.

ii) Change the default extension from .txt to .cu c) Find a sample or dummy CUDA *.cu code file on your desktop or in the Windows file explorer. d) Right-click on a *.cu file, and select Properties from the pop-up menu e) In the General tab, just underneath the label Type of File: CU File, look for the Change button to the right of a label entitled Opens With: Program, where Program is probably Notepad or some other editor. f) Click the Change button and you will see the Open With dialog box. Scroll amongst the list of programs presented and select Microsoft Visual Studio (or Microsoft Visual Studio version Selector if you have more than one version of VS installed). g) Click OK to exit the Open With dialog box, and then click Apply to exit the file Properties dialog box. Visual Studio Configuration 6) Visual Studio 2005 Professional/Team Edition with SP1 and security updates installed. (Visual Studio 2008 is also supported and the procedures are nearly identical). Note The following steps 7 - 10 affect all projects and solutions being manipulated on a Visual Studio installation, not just a specific project or solution 7) Add the Library, Include and Bin paths used for the CUDA Toolkit and SDK a) Start Visual Studio 2005 b) Select Tools->Options from the center of the main menu bar at the top of the Visual Studio window. The Options dialog box will appear. c) Expand the Projects and Solutions node from the tree view at the left and select VC++ Directories. d) On the top right of the dialog, select Library Files from the Show directories for: list. e) Click the Add icon to create a new line in the folder list, and enter: $(CUDA_LIB_PATH) f) Left-Click the down arrow several times to move this path to the bottom of the list to ensure the default library paths are searched first. g) At the top right of the dialog, select Include Files from the Show directories for: list. h) Click the Add icon to create a new line in the folder list, and enter: i) j) l) $(CUDA_I C_PATH) Left-click the down arrow several times to move this path to the bottom of the list to insure the default library paths are searched first. At the top right of the dialog, select Executable Files from the Show directories for: list. $(CUDA_BI _PATH) Left-Click the down arrow several times to move this path to the bottom of the list to insure the default library paths are searched first.

k) Click the Add icon to create a new line in the folder list, and enter:

8) Set up syntax highlighting for CUDA .cu files a) This will allow different keywords to be highlighted in color just like Visual Studio does by default for .c, .h, .cpp, etc. files with built in support. b) Check to see if you have a file called usertype.dat in your Visual Studio install directory within the \Common7\IDE folder (default path: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE). i) If you do not have a usertype.dat file in this directory copy the CUDA-specific usertype.dat file provided to the \Common 7\IDE folder in the Visual Studio install path.

ii) If you do already have a usertype.dat file in the in the Visual Studio \Common7\IDE directory, open it using Notepad, UltraEdit or another editor. Then also open the CUDA-specific usertype.dat file provided, copy the contents of the CUDA-specific file, and paste the contents into your pre-existing usertype.dat file. Then save and close the CUDA-specific usertype.dat file. c) Run Visual Studio d) Select Tools-> Options from the center of the main menu bar at the top of the Visual Studio window. The Options dialog box will appear. e) Expand the Text Editor node from the tree view at the left and select File Extension. f) At the top left of the dialog in the box labeled Extension, enter .cu. g) Select Microsoft Visual C++ in the drop down menu to the immediate right, and then click the Add button further to the right and the OK button at the bottom right of the dialog. h) Close and restart Visual Studio.

9) Turn on line number display a) Open the Options dialog again (Tools->Options from the main menu). b) Select Text Editor from the left hand tree view and select All Languages. c) Check Line numbers to turn on line numbering. Note A useful trick to remember is to use CTRL-g at any time in a code file to jump to a particular line number. 10) Setup Custom Build Rules files in Visual Studio to manage custom build options for CUDA CUDA files (.cu files) are compiled in Visual Studio 2005 by invocation of the nvcc.exe compiler using a Custom Build Rules file, which is an xml file that tells Visual Studio to invoke the nvcc.exe compiler, passes along desired switches and arguments to nvcc.exe, and also incorporates formatting information to present these rules for viewing/modification in convenient dialog boxes within VS 2005. Custom Build Rules in a rules file can be applied to all of the files in a VS 2005 project, a group of files in the project, or on a file-by-file basis within a project. Once the rules file is installed in the project, settings exposed by the rules file can be customized for each project configuration (release, debug, emu, etc) of each .cu file, using convenient dialog boxes generated by VS 2005 and based upon the information in the xml rules file. To configure custom build rules file in your project, do the following: a) Store the rules file provided in a standardized location of your choice (such as c:\CUDA\doc) b) This document assumes the developer is using the Custom Build Rules file Cuda21.rules. c) The main options exposed in this particular Custom Build Rules file (Cuda.rules) correspond to the nvcc.exe options described in the NVCC reference manual nvcc_2.x.pdf that comes with the CUDA Toolkit. Refer to that document for a detailed description of nvcc function and options.

d) Install the rules file in the Project i) Right-Click on the Project name for the project containing .cu files in the Solution Explorer pane, and select Custom Build Rules from the pop-up menu.

ii) This will cause the Visual C++ Custom Build Rules Files dialog to pop up. Click on the Find Existing button: iii) Then browse to and double click on the Cuda21.rules file in the Find Existing Rule File dialog iv) If you then see a dialog box asking whether you want to add the directory containing the selected rules file to the Visual Studio rules file search path, click the "Yes" button. This tells Visual Studio to always include this path when searching for rules files and will make this rules file accessible to all of your VS projects: v) Returning to the Visual C++ Custom Build Rules Files dialog box, now check the box to the left of the Cuda Build Rule v2.1.x listing in the Available Rule Files pane, and then click the OK button. e) To customize CUDA/NVCC settings applicable to ALL .cu files in your project i) Set the configuration (Release, Debug, etc) you wish the options to apply to using the drop down combo box menu in the toolbars at the top of the Visual Studio IDE window:

ii) Right-Click on the VS 2005 project name in the Solution Explorer and select Properties from the popup menu. iii) At the Project Name Property Pages dialog, select the CUDA Build Rule 2.1.x item and find the option you wish to customize. Adjust the setting as desired and then click the OK button. Settings chnaged in this manner will apply to all .cu files for the currently selected configuration (Release, Debug, etc). iv) For example, a common setting for all cu files in the Release configuration would be the preprocessor constant WI 32, which is entered as a string in the Preprocessor field. v) As another example, a common setting for all cu files in the Debug configuration would be the preprocessor defined constants WI 32 and _DEBUG: f) To customize settings for O E .cu file or a SubGgroup of .cu files in your project i) Set the configuration (Release, Debug, etc) you wish the options to apply to using the drop down combo box menu in the toolbars at the top of the Visual Studio IDE window:

ii) For each configuration (i.e. Release, Debug, etc) select a .cu file (or multiple .cu files using Ctrl-Left-click for multiple files) in your Source Files list, then Right-click on the file(s) chosen and select Properties. iii) At the Property Pages dialog for the file, select the General item and click the drop-down arrow next to the Tool entry. Then find and select CUDA Build Rule v2.1.x on the drop down list and then click the OK button to exit the dialog and accept the default custom build rule options (which are specified within the rules file). iv) Select the desired custom build rule item to set under the CUDA Build Rule v2.1.x node, choose the suboption in the pane to the right, and set the option as desired. This setting will apply to the selected files for the currently selected configuration. v) As an example, consider a stituation where you want to override the default arch setting of sm_10 for a couple of .cu files in your project that are optimized to take advantage of features only present in later GPUs, (e.g. SMEM Atomics). (1) To do this, set the configuration (Release, Debug, etc) and select the file(s) in the source file list, RightClick on the file(s) selected, chose the Properties item from the popup menu. (2) Then choose the General item under the CUDA Build Rule v 2.1.x node, click the drop-down arrow to the right of the GPU Architecture field, and select the sm_xx option desired. This setting will then be set on all selected files for the currently selected configuration (Release, Debug, etc).

11) Add CUDA Toolkit and SDK lib files to your project a) Right-Click on the project name in the Solution Explorer, and select Properties from the popup menu b) At the project Property Pages dialog, select Linker-> Input->Additional Dependencies c) If not already present, add: cudart.lib cuda.lib (for each configuration such as Debug and Release). d) To resolve linker conflicts, depending upon the project type, you may need to make an entry under Ignore Specific Library in the same dialog box. For example, you may need to ignore MSVCRT.lib for the Release version of a DLL project or LIBCMT.lib for the Debug version of a DLL project.