这是一个非常基本的问题,但如何在 Visual Studio 2008 中启动一个新的 CUDA 项目?我找到了大量关于 CUDA 相关问题的文档,但没有找到关于如何开始一个新项目的文档.我正在使用 Windows 7 x64 Visual Studio 2008 C++.我真的很想找到某种非常非常基本的 Hello World 应用程序来编译和运行基本程序.
我试过你的步骤汤姆.我设置了一个控制台应用程序.然后我删除了它放入的默认 .cpp 并复制了模板项目中的三个文件,只是为了编译一些东西.当我编译它时,template_gold.cpp 抱怨没有包含 stdafx.h,所以我包含了它.现在构建失败了:
<前>1>------ 构建开始:项目:CUDASandbox,配置:调试 x64 ------1>编译...1>template_gold.cpp1>链接...1>LIBCMT.lib(crt0.obj): 错误 LNK2019: 函数 __tmainCRTStartup 中引用的未解析的外部符号 main1>D:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxx64DebugCUDASandbox.exe:致命错误 LNK1120:1 个未解析的外部1>构建日志保存在file://d:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxCUDASandboxx64DebugBuildLog.htm"1>CUDASandbox - 2 个错误,0 个警告========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========注意 随着 CUDA Toolkit 3.2 版的发布,NVIDIA 现在包含了 rules 文件与 Toolkit 而不是 SDK.因此,我将这个答案分为两部分,请使用适用于您的 Toolkit 版本的正确说明.
注意这些说明适用于 Visual Studio 2005 和 2008.对于 Visual Studio 2010,请参阅 这个答案.
<小时>CUDA TOOLKIT 3.2 及更高版本
我推荐使用NVIDIA提供的NvCudaRuntimeApi.rules
文件(或者NvCudaDriverApi.rules
如果使用驱动API),这是随工具包发布的,支持最新的编译器以友好的方式标记.我个人建议不要使用 VS 向导,但这只是因为我真的认为您不需要它.
规则文件(安装在 Program FilesMicrosoft Visual Studio 9.0VCVCProjectDefaults
目录中)教导"Visual Studio 如何编译项目中的任何 .cu 文件并将其链接到应用程序中.
NvCudaRuntimeApi.rules
(右击项目,自定义构建规则,勾选相关框),见注释1$(CUDA_PATH)lib$(PlatformName)
到 Additional Library Directory 并在 Linker -> Input 中将 cudart.lib
添加到 Additional Dependencies),见注释 [2] 和 [3]$(CUDA_PATH)include
添加到 Additional Include Directories),参见注释 [3]其他一些提示:
<sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
我还建议使用以下注册表项启用 Intellisense 支持(将 9.0 替换为 VS2005 而不是 VS2008 的 8.0):
[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]"NCB 默认 C/C++ 扩展"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.CL"
顺便说一句,如果可能的话,我会提倡避免cutil,而是自己进行检查.Cutil 不受 NVIDIA 支持,它只是用来尝试使 SDK 中的示例专注于实际程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析).如果您自己编写,那么您将有更好的控制权,并且会知道发生了什么.例如,如果函数失败,cutilSafeCall
包装器会调用 exit()
- 真正的应用程序(而不是示例)可能应该更优雅地处理失败!
CUDA TOOLKIT 3.1 及更早版本
我会将 NVIDIA 提供的 Cuda.rules
文件与 SDK 一起使用,它与工具包一起发布,并以友好的方式支持最新的编译器标志.我个人建议不要使用 VS 向导,但这只是因为我真的认为您不需要它.
规则文件(位于 SDK 的 Ccommon 目录中)教导"Visual Studio 如何编译项目中的任何 .cu 文件并将其链接到应用程序中.
Cuda.rules
(右键单击项目,自定义构建规则,浏览规则文件并确保勾选)$(CUDA_LIB_PATH)
到 Additional Library Directory 并在 Linker -> Input 中添加 cudart.lib
到 Additional Dependencies),见请注意下面的 [2]$(CUDA_INC_PATH)
添加到 Additional Include Directories)其他一些提示:
<sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
我还建议使用以下注册表项启用 Intellisense 支持(将 9.0 替换为 VS2005 而不是 VS2008 的 8.0):
[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]"NCB 默认 C/C++ 扩展"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.CL"
顺便说一句,如果可能的话,我会提倡避免cutil,而是自己进行检查.Cutil 不受 NVIDIA 支持,它只是用来尝试使 SDK 中的示例专注于实际程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析).如果您自己编写,那么您将有更好的控制权,并且会知道发生了什么.例如,如果函数失败,cutilSafeCall
包装器会调用 exit()
- 真正的应用程序(而不是示例)可能应该更优雅地处理失败!
注意
NvCudaRuntimeApi.v3.2.rules
.这意味着不是在 %CUDA_PATH% 中查找 CUDA Toolkit,而是在 %CUDA_PATH_V3_2% 中查找,这反过来意味着您可以在您的系统上安装多个版本的 CUDA Toolkit,并且不同的项目可以针对不同的版本.另见注释 [3].LNK4098: defaultlib 'LIBCMT' 与其他库的使用发生冲突
)或标准库函数的多重定义符号,那么这应该是您的第一个怀疑对象.莉>This is an incredibly basic question, but how do I start a new CUDA project in Visual Studio 2008? I have found tons and tons of documentation about CUDA related matters, but nothing about how to start a new project. I am working with Windows 7 x64 Visual Studio 2008 C++. I would really like to find some sort of really really basic Hello World app to just get a basic program compiling and running.
Edit:
I tried your steps Tom. I setup a console app. I then deleted the default .cpp it drops in and copied over the three files from the template project just to have something to compile. When I compile that, template_gold.cpp complained about not having stdafx.h included, so i included that. Now the build fails with this:
1>------ Build started: Project: CUDASandbox, Configuration: Debug x64 ------ 1>Compiling... 1>template_gold.cpp 1>Linking... 1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup 1>D:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxx64DebugCUDASandbox.exe : fatal error LNK1120: 1 unresolved externals 1>Build log was saved at "file://d:StuffProgrammingVisual Studio 2008ProjectsCUDASandboxCUDASandboxx64DebugBuildLog.htm" 1>CUDASandbox - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
NOTE With the release of version 3.2 of the CUDA Toolkit, NVIDIA now includes the rules file with the Toolkit as opposed to the SDK. Therefore I've split this answer into two halves, use the correct instructions for your version of the Toolkit.
NOTE These instructions are valid for Visual Studio 2005 and 2008. For Visual Studio 2010 see this answer.
CUDA TOOLKIT 3.2 and later
I recommend using the NvCudaRuntimeApi.rules
file (or NvCudaDriverApi.rules
if using the driver API) provided by NVIDIA, this is released with the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.
The rules file (installed into the Program FilesMicrosoft Visual Studio 9.0VCVCProjectDefaults
directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.
NvCudaRuntimeApi.rules
(right click on the project, Custom Build Rules, tick the relevant box), see note 1$(CUDA_PATH)lib$(PlatformName)
to the Additional Library Directories and in Linker -> Input add cudart.lib
to the Additional Dependencies), see notes [2] and [3]$(CUDA_PATH)include
to the Additional Include Directories), see note [3]Some other tips:
<sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):
[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall
wrapper calls exit()
if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
CUDA TOOLKIT 3.1 and earlier
I would use the Cuda.rules
file provided by NVIDIA with the SDK, this is released alongside the toolkit and supports the latest compiler flags in a friendly manner. Personally I would advise against using the VS wizard, but only because I really don't think you need it.
The rules file (in the Ccommon directory of the SDK) "teaches" Visual Studio how to compile and link any .cu files in your project into your application.
Cuda.rules
(right click on the project, Custom Build Rules, browse for the rules file and ensure it is ticked)$(CUDA_LIB_PATH)
to the Additional Library Directories and in Linker -> Input add cudart.lib
to the Additional Dependencies), see note [2] below$(CUDA_INC_PATH)
to the Additional Include Directories)Some other tips:
<sdk_install_dir>Cdocsyntax_highlightingvisual_studio_8
I'd also recommend enabling Intellisense support with the following registry entry (replace 9.0 with 8.0 for VS2005 instead of VS2008):
[HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0LanguagesLanguage ServicesC/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"
Incidentally I would advocate avoiding cutil if possible, instead roll your own checking. Cutil is not supported by NVIDIA, it's just used to try to keep the examples in the SDK focussed on the actual program and algorithm design and avoid repeating the same things in every example (e.g. command line parsing). If you write your own then you will have much better control and will know what is happening. For example, the cutilSafeCall
wrapper calls exit()
if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
NOTE
NvCudaRuntimeApi.v3.2.rules
. This means that instead of looking for the CUDA Toolkit in %CUDA_PATH% it will look in %CUDA_PATH_V3_2%, which in turn means that you can have multiple versions of the CUDA Toolkit installed on your system and different projects can target different versions. See also note [3].LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs
) or multiply defined symbols for standard library functions, then this should be your first suspect.
这篇关于如何在 Visual Studio 2008 中启动新的 CUDA 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!