如何在 Visual Studio 2008 中启动新的 CUDA 项目?
这是一个非常基本的问题,但如何在 Visual Studio 2008 中启动新的 CUDA 项目?我找到了大量关于 CUDA 相关问题的文档,但没有找到关于如何启动新项目的信息。我正在使用 Windows 7 x64 Visual Studio 2008 C++。我真的很想找到某种非常非常基本的 Hello World 应用程序来编译和运行基本程序。
编辑:
我尝试了你的步骤汤姆。我设置了一个控制台应用程序。然后,我删除了它放入的默认 .cpp 并复制了模板项目中的三个文件,只是为了编译一些东西。当我编译它时,template_gold.cpp 抱怨没有包含 stdafx.h,所以我包含了它。现在构建失败了:
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:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\x64\Debug\CUDASandbox.exe : fatal error LNK1120: 1 unresolved externals 1>Build log was saved at "file://d:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\CUDASandbox\x64\Debug\BuildLog.htm" 1>CUDASandbox - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
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:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\x64\Debug\CUDASandbox.exe : fatal error LNK1120: 1 unresolved externals 1>Build log was saved at "file://d:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\CUDASandbox\x64\Debug\BuildLog.htm" 1>CUDASandbox - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
注意随着 CUDA 工具包 3.2 版的发布,NVIDIA 现在将规则文件包含在工具包中,而不是 SDK。因此,我将这个答案分成两半,使用适合您的工具包版本的正确说明。
注意这些说明对 Visual Studio 2005 和 2008 有效。对于 Visual Studio 2010,请参阅 这个答案。
CUDA TOOLKIT 3.2 及更高版本
我建议使用
NvCudaRuntimeApi.rules
文件(如果使用驱动程序,则使用NvCudaDriverApi.rules
API)由 NVIDIA 提供,随工具包一起发布,并以友好的方式支持最新的编译器标志。就我个人而言,我建议不要使用 VS 向导,但这只是因为我真的认为您不需要它。规则文件(安装到 Program Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults 目录中)“教导”Visual Studio 如何编译项目中的任何 .cu 文件并将其链接到应用程序中。
NvCudaRuntimeApi.rules
(右键单击项目,自定义构建规则,勾选相关框),请参阅注释1$(CUDA_PATH)\lib\$(PlatformName)
添加到其他库目录和链接器 - > 输入将cudart.lib
添加到附加依赖项),请参阅注释[2]和[3]$(CUDA_PATH)\include
添加到其他包含目录),请参阅注释 [3]其他一些提示:
\C\doc\syntax_highlighting\visual_studio_8
中的 readme.txt >我还建议使用以下注册表项启用 Intellisense 支持(对于 VS2005,而不是 VS2008,将 9.0 替换为 8.0):
顺便说一句,我会提倡如果可能的话避免 cutil,而是进行自己的检查。 Cutil不受NVIDIA支持,它只是用来尽量让SDK中的示例集中于实际的程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析)。如果您自己编写,那么您将拥有更好的控制力并且知道发生了什么。例如,如果函数失败,
cutilSafeCall
包装器将调用exit()
- 真实的应用程序(而不是示例)可能应该更优雅地处理失败!CUDA TOOLKIT 3.1 及更早版本
我会使用 NVIDIA 随 SDK 提供的
Cuda.rules
文件,该文件与工具包一起发布,并支持以友好的方式标记最新的编译器标志。就我个人而言,我建议不要使用 VS 向导,但这只是因为我真的认为您不需要它。规则文件(位于 SDK 的 C\common 目录中)“教导”Visual Studio 如何编译项目中的任何 .cu 文件并将其链接到应用程序中。
Cuda.rules
(右键单击项目,自定义构建规则,浏览规则文件并确保选中它)$(CUDA_LIB_PATH)
添加到附加库目录并在链接器->输入中 将cudart.lib
添加到其他依赖项),请参阅下面的注释 [2]其他一些提示:
\C\doc\syntax_highlighting\visual_studio_8
中的 readme.txt >我还建议使用以下注册表项启用 Intellisense 支持(对于 VS2005,而不是 VS2008,将 9.0 替换为 8.0):
顺便说一句,我建议如果可能的话,避免 cutil,而是进行自己的检查。 Cutil不受NVIDIA支持,它只是用来尽量让SDK中的示例集中于实际的程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析)。如果您自己编写,那么您将拥有更好的控制力并且知道发生了什么。例如,如果函数失败,
cutilSafeCall
包装器将调用exit()
- 真实的应用程序(而不是示例)可能应该更优雅地处理失败!注意
NvCudaRuntimeApi.v3.2.rules
。这意味着,它不会在 %CUDA_PATH% 中查找 CUDA 工具包,而是在 %CUDA_PATH_V3_2% 中查找,这又意味着您可以在系统上安装多个版本的 CUDA 工具包,并且不同的项目可以针对不同的版本。另请参见注释[3]。LNK4098: defaultlib 'LIBCMT' 与其他库的使用冲突
)或标准库函数的多重定义符号,那么这应该是您的第一个怀疑。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 (orNvCudaDriverApi.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 Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults
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 addcudart.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>\C\doc\syntax_highlighting\visual_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):
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 callsexit()
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 C\common 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 addcudart.lib
to the Additional Dependencies), see note [2] below$(CUDA_INC_PATH)
to the Additional Include Directories)Some other tips:
<sdk_install_dir>\C\doc\syntax_highlighting\visual_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):
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 callsexit()
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.多么好的问题啊!!对于所有 CUDA 文档,我一直认为这是一个明显的遗漏......事实上,我真的很高兴找到这篇文章,因为在使用 CUDA 相当长一段时间后,我仍然没有'没有找到一个官方的、正确的方法让 VS 从头开始生成 CUDA 程序。
当我需要启动一个新的 CUDA 程序时,我总是只是从 SDK 目录中复制并修改“模板”示例。这可能不完全是您正在寻找的,因为它并不是全新开始的,但它是一种让支持 CUDA 的项目在 VS 中使用所有正确的项目/文件工作的快速方法名称...
What a great question!! For all the CUDA documentation out there, this is something that I've always thought was an obvious omission... In fact, I'm really glad I found this post, because after using CUDA for quite a while, I still hadn't found an official, correct way to get VS to produce a CUDA program from scratch.
When I've needed to start a new CUDA program, I've always just copied and modified the "template" example from the SDK directory. This may not be exactly what you're looking for, because it doesn't start fresh, but it is a quick way to get a CUDA-capable project working in VS with all the correct project/file names...
可以找到有关在 VS2008 上安装 CUDA 向导的其他信息 此处 和 此处
[编辑]
如果您不想使用向导,则必须手动设置 CUDA lib/include/nvcc 路径并向每个新的 CUDA 程序添加自定义构建规则。有关如何操作的更多信息,请查看 Tom's Answer。
Additional info about installing CUDA wizard on VS2008 can be found here and here
[edit]
If you don't want to use wizard you have to setup CUDA lib/include/nvcc paths manually and add custom build rules to each new CUDA program. For additional info how to do it take a look at Tom's Answer.
您可能需要查看本指南: http://www.programmerfish.com/how-to-run-cuda-on-visual-studio-2008-vs08/
You may want to take a look at this guide: http://www.programmerfish.com/how-to-run-cuda-on-visual-studio-2008-vs08/