如何在 Visual Studio 2010 中启动 CUDA 应用程序?
直接问题:如何在 Visual Studio 2010 中创建一个简单的 hello world CUDA 项目?
背景:我编写了 CUDA 内核。我非常熟悉 Visual Studio 2005 中的 .vcproj 文件——手动调整了几个文件。在 VS 2005 中,如果我想构建 CUDA 内核,我会添加自定义构建规则,然后显式定义 nvcc 调用来构建文件。
我已经迁移到 Win 7 和 VS 2010,因为我真的很想尝试 nSight。我安装了 nSight 1.5。但这就是我完全迷失的地方。如果我像以前一样继续,nvcc 报告它仅支持 msvc 8.0 和 8.0。 9.0。但该网站明确指出它支持 VS 2010。
我在其他地方读到我还需要安装 VS 2008 (msvc 9.0)——我的话。现在就这样做。
但我猜测我的问题至少有一部分源于自制的自定义构建工具规范。 几个 网站谈论添加 * .rules 文件添加到构建中,但我发现这仅适用于 VS 2008。在“构建自定义”下,我看到 CUDA 3.1 和 3.2,但是当我将内核添加到他们没有建造的项目。 另一个网站宣称关键是三个文件:Cuda.props Cuda.xml Cuda.targets,但它没有说明如何或在哪里添加这些文件 - 或者更确切地说我敢打赌我只是不理解网站上引用的注释。
那么有人知道如何在 VS 2010 中创建一个简单的项目来构建 CUDA 内核 - 使用 nSight 1.5 设置或 CUDA 3.2 RC 附带的 NvCudaRuntimeApi.v3.2.rules 文件?
提前致谢!我愿意悬赏,但我总共只有 65 分。
Direct Question: How do I create a simple hello world CUDA project within visual studio 2010?
Background: I've written CUDA kernels. I'm intimately familiar with the .vcproj files from Visual Studio 2005 -- tweaked several by hand. In VS 2005, if I want to build a CUDA kernel, I add a custom build rule and then explicitly define the nvcc call to build the files.
I have migrated to Win 7, and VS 2010 because I really want to try out nSight. I have nSight 1.5 installed. But this is where I'm totally lost. If I proceed as before, nvcc reports that it only supports msvc 8.0 & 9.0. But the website clearly states that it supports VS 2010.
I read somewhere else that I need to have VS 2008 (msvc 9.0) also installed -- my word. Doing so now.
But I'm guessing that at least part of my problems stem from the homegrown custom build tool specifications. Several websites talk about adding a *.rules file to the build, but I've gathered that this is only applicable to VS 2008. Under "Build Customizations" I see CUDA 3.1 and 3.2, but when I add kernels to the project they aren't built. Another website proclaims that the key is three files: Cuda.props Cuda.xml Cuda.targets, but it doesn't say how or where to add these files -- or rather I'll gamble that I just don't understand the notes referenced in the website.
So does anyone know how to create a simple project in VS 2010 which builds a CUDA kernel -- using either the nSight 1.5 setup or the NvCudaRuntimeApi.v3.2.rules file which ships with the CUDA 3.2 RC?
Thanks in advance! I'd offer a bounty, but I only have 65 points total.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CUDA TOOLKIT 4.0 及更高版本
构建自定义文件(安装到
Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations
目录中) “教”Visual Studio 如何编译项目中的任何 .cu 文件并将其链接到应用程序中。如果您选择跳过安装自定义项,或者如果您在 CUDA 之后安装了 VS2010,则可以稍后按照Program Files\NVIDIA GPU Compute Toolkit\CUDA\v4.0\extras\visual_studio_integration
中的说明添加它们>。.cu
文件,那么您需要将.cu
文件的类型设置为CUDA C/C++
(右键单击该文件,属性,设置项目类型)cudart.lib代码> 到附加依赖项)
顺便说一句,我建议如果可能的话避免 cutil,而是进行自己的检查。 Cutil不受NVIDIA支持,它只是用来尽量让SDK中的示例集中于实际的程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析)。如果您自己编写,那么您将拥有更好的控制力并且知道发生了什么。例如,如果函数失败,
cutilSafeCall
包装器将调用exit()
- 真实的应用程序(而不是示例)可能应该更优雅地处理失败!注意
CUDA TOOLKIT 4.0 and later
The build customisations file (installed into the
Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations
directory) "teaches" Visual Studio how to compile and link any .cu files in your project into your application. If you chose to skip installing the customisations, or if you installed VS2010 after CUDA, you can add them later by following the instructions inProgram Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration
..cu
files before the build customisations, then you'll need to set the type of the.cu
files toCUDA C/C++
(right-click on the file, Properties, set Item Type)cudart.lib
to the Additional Dependencies)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
另一个很好的教程在这里:
http://www.stevenmarkford.com/installing-nvidia- cuda-with-visual-studio-2010/
如果您收到有关“<”的错误请注意此步骤(来自之前的答案):
如果您在构建自定义之前添加了 .cu 文件,那么您需要将 .cu 文件的类型设置为 CUDA C/C++(右键单击该文件,属性,设置项目类型)
但是如果你按照他们的步骤操作,它应该可以工作!
Another Good tutorial here:
http://www.stevenmarkford.com/installing-nvidia-cuda-with-visual-studio-2010/
if you get an error about '<' note this step (from a previous answer):
If you added .cu files before the build customisations, then you'll need to set the type of the .cu files to CUDA C/C++ (right-click on the file, Properties, set Item Type)
But if you follow their steps, it should work!
此答案适用于 CUDA 3.2,从 4.0 起 CUDA 直接支持 VC 10 编译器,请参阅其他答案以获取更多信息
您需要安装 VS 2008 或 6.1 Windows SDK。这是因为 NSight 1.5 RC 或 CUDA 3.2 SDK 在底层使用 VC 9 编译器。我已经在安装了 2008 版本的情况下成功使用了它,并被告知它应该可以与 SDK 一起使用,但还没有尝试过。
使用 NSight 1.5 和/或 CUDA 3.2 SDK,您不需要搞乱任何自定义构建规则。我曾经经历过,而且很痛苦。使用最新的版本,一切都消失了:
.props)”自定义。
它应该会直接构建。如果有帮助,请告诉我如果您遇到问题,因为这是我的记忆。
好消息是,让 CUDA 与 VS 2010 一起工作变得更加容易。
顺便
说一句:我将更新我的博客文章。
This answer applies to CUDA 3.2, from 4.0 onwards CUDA supports the VC 10 compiler directly, see other answers for more information
You need either VS 2008 or the 6.1 Windows SDK installed. That's because NSight 1.5 RC or the CUDA 3.2 SDK use the VC 9 compiler under the hood. I've got this working successfully with 2008 installed and am told it should work with the SDK but haven't tried.
With NSight 1.5 and/or the CUDA 3.2 SDK you shouldn't need to muck with any custom build rules. I've been there and it's painful. With the latest builds all that goes away:
.props)" customization.
It should just build. Let me know if this helps and if you run into problems as this is from memory.
The good news it getting CUDA working with VS 2010 just got much easier.
Ade
BTW: I'll update my blog post.