Starting with CUDA. As of this writing, CUDA Toolkit 4.0 is available [e.g

Starting with CUDA Quote: With great power comes great responsibility. Summary How to install and setup CUDA in windows with Visual Studio 2010. Tut...
Author: Horatio Snow
2 downloads 0 Views 654KB Size
Starting with CUDA Quote: With great power comes great responsibility.

Summary How to install and setup CUDA in windows with Visual Studio 2010.

Tutorial Overview Show you which files and how to configure Visual Studio to run CUDA simulations.

Basics Before you even consider installing CUDA, ensure that you have Visual Studio 2010 installed, and you can compile and run native C++ code without any problems. As of this writing, CUDA Toolkit 4.0 is available [e.g. http://developer.nvidia.com/cuda-toolkit-40] We‟ll setup and install CUDA 32bit. Visual Studio 2008. For Windows 7 64, install the 64bit drivers. 1. 2. 3.

Install driver (e.g. devdriver_4.0_winvista-win7_64_270.81_general.exe) Install CUDA Toolkit (e.g. cudatoolkit_4.0.17_win_32.msi) Install CUDA Tools SDK (e.g. cudatools_4.0.17_win_32.msi)

Your installation should have been installed at: “C:\Program Files (x86)\NVIDIA GPU Computing Toolkit” HACK FIX On occasion some people encounter a compile error: 1>------ Build started: Project: code7, Configuration: Debug Win32 -----1>Error: The result "" of evaluating the value "$(CudaBuildTasksPath)" of the "AssemblyFile" attribute in element is not valid. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.0.targets ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== This is a bug with the Custom build files installed by CUDA, (for 32bit install on windows7) located at: “C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations” This is a bug in “CUDA 4.0.targets” file. To fix this, open “CUDA 4.0.props”, and copy the section defining CudaBuildTaskPath, e.g.: $(CudaToolkitCustomDir) v4.0 4.00.0000.0000 $(VCTargetsPath)BuildCustomizations\CUDA 4.0.xml $(VCTargetsPath)BuildCustomizations\Nvda.Build.CudaTasks.v4.0.dll

Then open your “CUDA 4.0.targets”, and paste the contents at the top, just before where it‟s needed. e.g.:

1

$(CudaToolkitCustomDir) v4.0 4.00.0000.0000 $(VCTargetsPath)BuildCustomizations\CUDA 4.0.xml $(VCTargetsPath)BuildCustomizations\Nvda.Build.CudaTasks.v4.0.dll

Visual Studio 2008 When you create a new project, be sure to set the build configuration to v90. Select the project and open the properties (ALT-Enter). In the general tab set the Platform Toolset field to v90 (if you are not able to do this then you probably don’t have VS 2008 installed, this is required by CUDA).

DLL Error System Error. The program can't start because cudart32_40_17.dll is missing from your computer. Try reinstalling the program to fix this problem.

2

This is because you need to let your system know where the DLL‟s for CUDA are located. You can do this by adding the location of your dll‟s to the “Environment Paths” in windows, e.g. Depending on where you‟ve installed CUDA and which version you installed (32bit/64bit): “C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin” Alternatively you can append the working location of the DLL‟s inside Visual Studio: “Project->Properties>Configuration Properties->Debugging” : “Environment” : “Merge Environment” -> True Set Environment to: PATH=%PATH%;C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.

Paths and Includes You‟ll need to tell your code where paths and directories are needed. Ideally you should set the paths in Visual Studio. Right click the project in the Solution Explorer -> Properties -> VC++ Directories -> Include Directories / Library Directories.

3

Alternatively for windows you can specify the libs using the #pragma define: #pragma comment(lib, "cuda.lib") #pragma comment(lib, "cudart.lib")

For hacky and dirty, you can even specify your paths directly inside your code without adding the paths to Visual Studio: #define CUDA_PATH "C:\\Program Files (x86)\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.0\\" #pragma comment(lib, CUDA_PATH "lib\\Win32\\cuda.lib") #pragma comment(lib, CUDA_PATH "lib\\Win32\\cudart.lib") #include "C:\\Program Files (x86)\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.0\\include\\cuda.h" #include "C:\\Program Files (x86)\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.0\\include\\cuda_runtime.h"

“.cu” File CUDA files need to be compiled using the Nvidia compiler. If you create a CUDA project and your compiling and getting errors such as: Your „.cu‟ file isn‟t being included in the build and hence the code can‟t call various functions from it. fatal error LNK1120: x unresolved externals The „.cu‟ file is being included, but its being compiled using the Visual Studio C/C++ compiler which can‟t handle special CUDA C syntax and global defines. error C2065: 'blockIdx' : undeclared identifier error C2059: syntax error : '