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
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