现在位置:首页 >> 正文
关于CUDA的配置与入门
发表时间:2009-06-24
开始接触CUDA,我安装好后完全不知道怎么运行demo,当然也没有见到详细的安装说明。下面说说我的经验。

开始接触CUDA,我安装好后完全不知道怎么运行demo,当然也没有见到详细的安装说明。下面说说我的经验。

 Platform:Win XP64

IDE:VS2008

 

1 获取可访问以下网址:
http://www.nvidia.com/object/cuda_get.html

共需下载3个应用程序,分别是:

1>     CUDA Driver

2>     CUDA Toolkit

3>     CUDA SDK code samples

可以选择合适的操作系统,例如我选的是WIN XP 64-bit。

 

2 安装
a)         其中CUDA Driver是为了使CUDA和硬件交互,CUDA 2.2中驱动文件版本是185.85,我原来的显卡驱动是17*.*,所以需要安装升级。

b)        接下来安装Toolkit,里面是一些头文件和库,nVidia的编译器,还有帮助文档。安装后,会自动在系统的环境变量里注册路径

CUDA_BIN_PATH (defaults to C:\CUDA\bin) contains the compiler executables and runtime libraries.

CUDA_INC_PATH (defaults to C:\CUDA\include) contains the include files needed to compile CUDA programs.

CUDA_LIB_PATH (defaults to C:\CUDA\lib) contains the libraries needed for linking CUDA codes.

c)        然后安装SDK,里面有很多示例和模版,可以参照。安装后进入\NVIDIA CUDA SDK\common文件夹,将Release.sln(2005)或Release_vc90.sln(2008)编译。新生成的.lib和.dll会在\NVIDIA CUDA SDK\common\lib里。

 

3 使用
以Visual Studio 2008 TeamSuite为例:

1)         文本编辑

由于CUDA使用的源文件是.cu文件,因此默认情况下VS不会识别它里面的语法,会把它当成普通的txt文件。

Tools->options,左侧树形图展开Text Editor,在File Extension子项中:

Extension:cu              Editor:Microsoft Visual C++

点击Add,这样cu文件就会被当做cpp文件显示了。由于VS不会立即更新,需要重新启动VS。

2)        路径包含

Tools->options,左侧树形图展开Projects and Solutions,选VC++ Directories子项,

Platform:     x64(默认是win32,但是我的是x64,所以需要选这个)

Show directories for:

       Include files添加:

a)         C:\CUDA\include

b)        C:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc

Library files添加:

a)         C:\CUDA\lib

b)        C:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA CUDA SDK\common\lib

3)        编译配置

Build->Configuration Manager,

Active Solution Configuration:Release(or Debug)

Active Solution Platform:       x64(如果没有需要new一个)

Project->Custom Build Rules,Find existing,找到\NVIDIA CUDA SDK\common\cuda.rules,打开,并在左侧勾选上,这样就可以调用nvcc来编译cu文件了。

在工程上点右键->Properties,左侧树形控件Configuration Properties->Linker->Input,在右侧Additional Dependencies里添加”cudart.dll cutil64.dll”(不包括引号),这样基本上编译就不会出问题了。

      如果是driver API,需要添加”cuda.lib cudart.lib”,头文件#include <cuda.h>,#include <cuda_runtime.h>

4)        运行

运行时可能出现某个dll无法找到的情况,这是需要将dll复制到解决方案编译下的exe所在文件夹,或者干脆复制到system32里。

 

 

 

当前我所用的显卡详细信息:

CUDA device's Name: GeForce 8500 GT

Multi-Processors : 4

canMapHostMemory : 0

clockRate : 1188000

computeMode : 0

deviceOverlap : 1

integrated : 0

kernelExecTimeoutEnabled : 1

compute capa : 1 1

maxGridsize : 2358912

maxThreadsDim : 2358900

maxThreadsPerBlock : 512

memPitch : 262144

regsPerBlock : 8192

sharedMemPerBlock : 16384

textureAlignment : 256

totalConstMem : 65536

totalGlobalMem : 133890048

warpSize : 32

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/gogdizzy/archive/2009/06/19/4278746.aspx

正在载入评论列表...