CUDA + Qt + VS2008 编程环境的配置

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

CUDA + Qt + VS2008 编程环境的配置

- 按照常规生成pro文件,进而得到vs的工程文件后,

- 项目名右键,选择自定义生成规则,在可用规则文件里面选择 CUDA Runtime API Rule(v3.2)

- 在配置属性—链接器—常规选项的附加库目录里面,添加 $(NVSDKCOMPUTE_ROOT)\C\common\lib 和$(CUDA_LIB_PATH)

注:参考CUDA SDK中例子的工程文件,它们添加的附加库目录是:$(CUDA_PATH)/lib/$(PlatformName);../../common/lib/$(PlatformName)

以本机为例,各环境变量的值如下:

CUDA_PATH - E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\
$(CUDA_PATH)/lib/$(PlatformName)就相当于E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32,
其中的lib文件是cublas.lib, cuda.lib, cudart.lib, cufft.lib, cuinj.lib, curand.lib, cusparse.lib, npp.lib, nvcuvenc.lib, nvcuvid.lib, OpenCL.lib

../../common/lib/$(PlatformName),各个例子上溯两级目录后是E:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C,
所以../../common/lib/$(PlatformName)就相当于E:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\lib\Win32,
其中的lib文件是cutil32.lib, cutil32D.lib, freeglut.lib, glew32.lib

CUDA_LIB_PATH - %CUDA_PATH%lib\Win32就相当于E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32

NVSDKCOMPUTE_ROOT - E:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2
$(NVSDKCOMPUTE_ROOT)\C\common\lib - E:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\lib,相比之下似乎应该再多一级\Win32

- 在配置属性—链接器—输入选项的附加依赖项里添加 cudart.lib cutil32D.lib

注:关于cutil32D.lib文件,在NVIDIA CUDA GETTING STARTED GUIDE FOR MICROSOFT WINDOWS文档中(对应的文件名可能是 CUDA_Getting_Started_Windows.pdf)指出,好像是需要再编译一次对应的工程才能生成的。实际上结合之前的路径,似乎可以把需要的lib文件都复制到统一的目录下,或者在pro文件中指定,而相应的exe文件(比如nvcc、nvvp等)和dll文件则都可以通过环境变量PATH(用户)和Path(系统)中所设置的路径值获得——这应该是在安装CUDA SDK时,安装程序自动完成的设置。

Most samples link to a utility library called cutil, the source code for which is in NVIDIA GPU Computing SDK\C\common\src. The release versions of these
samples link to cutil32.lib (or cutil64.lib) and dynamically load cutil32.dll (or cutil64.dll). The debug versions of these samples link to cutil32D.lib and dynamically load cutil32D.dll (or their 64-bit equivalents on 64-bit versions of Windows).

To build the Win32 release and/or debug configurations of the cutil library, use the solution files located in NVIDIA GPU Computing SDK\C\common. The output
of the compilation process should be placed in N

VIDIA GPU Computing SDK\C\common\lib:

cutil32.lib and cutil32D.lib (or cutil64.lib and cutil64D.lib) are the release and debug import libraries.

cutil32.dll and cutil32D.dll (or cutil64.dll and cutil64D.dll) are the release and debug dynamic-link libraries, which also are copied to NVIDIA GPU
Computing SDK\C\bin\win32\release and NVIDIA GPU Computing SDK\C\bin\win32\debug respectively. (Substitute \win64 for \win32 on 64-bit Windows.)

Note: The cutil library is primarily intended as a tool for streamlining the GPU Computing SDK samples; its use outside of the SDK samples is not recommended, as the API for the library may change at any time.

These sample projects also make use of the $CUDA_PATH environment variable to locate the CUDA Toolkit and a .rules file to locate and configure the nvcc compiler. The environment variable is set automatically and the .rules file is installed automatically as part of the CUDA Toolkit installation process. The .rules file is installed into $VisualStudioInstallDir\VC\VCProjectDefaults. You can reference this .rules file from your Visual Studio project files when building your own CUDA applications.


实际上,CUDA应用于Qt,相当于在已有的project中添加所谓的CUDA build customizations

在NVIDIA CUDA GETTING STARTED GUIDE FOR MICROSOFT WINDOWS文档中(对应的文件名可能是 CUDA_Getting_Started_Windows.pdf)提到:

BUILD CUSTOMIZATIONS FOR EXISTING PROJECTS

When adding CUDA acceleration to existing applications, the relevant Visual Studio project file must be updated to include CUDA build customizations. For Visual Studio 2010, this can done using one of the following two methods:

1. Open the Visual Studio 2010 project, right click on the project name, and select “Build Customizations...”, then select the CUDA Toolkit version you would like to target.

注:在vs2008中,在右键点击project name后弹出的菜单中,只有Custom Build Rules,然后选择规则文件 CUDA Runtime API Rule

2. Alternatively, you can configure your project always to build with the most recently installed version of the CUDA Toolkit. First add a CUDA build customization to your project as above. Then, right click on the project name and select “Properties”.Under “CUDA C/C++”, select “Common”, and set the “CUDA Toolkit Custom Dir” field to “$(CUDA_PATH)” (without the quotes).

注:参考sdk的样例(convolutionFFT2D),点击Properties后,看到的是CUDA Runtime API,有General、GPU、Host和Command Line。
在General中,主要是指定了Compiler Path - $(CUDA_PATH)\bin\nvcc.exe 和 Required Include Directories - $(CUDA_PATH)\include
在GPU中,指定了NVCC Compilation Type - Generate hybrid object file (--compile / -c) (当然,也有其它选项的),还有就是GPU Architecture(1) - sm_10;GPU Architecture(2) - sm_20;GPU Architecture(3) - sm_30。(至于其余的以及Host部分不是不

重要,只是看不懂:))
而Command Line则是包含了之前选项中所设定的内容,如下:
echo "E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\\include" -maxrregcount=0 --compile -o "Debug/convolutionFFT2D_vs2008.vcproj.obj" convolutionFFT2D_vs2008.vcproj
"E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"E:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.2\\include" -maxrregcount=0 --compile -o "Debug/convolutionFFT2D_vs2008.vcproj.obj" "e:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\src\convolutionFFT2D\convolutionFFT2D_vs2008.vcproj"

While Option 2 will allow your project to automatically use any new CUDA Toolkit version you may install in the future, selecting the toolkit version explicitly as in Option 1 is often better in practice, because if there are new CUDA configuration options added to the build customization rules accompanying the newer toolkit, you would not see those new options using Option 2.

Note for advanced users: if you wish to try building your project against a newer CUDA Toolkit without making changes to any of your project files, go to the Visual Studio 2010 command prompt, change the current directory to the location of your project, and execute a command such as the following:

msbuild /t:Rebuild
/p:CudaToolkitDir="drive:/path/to/new/toolkit/"

相关文档
最新文档