直接问题:如何在 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 &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 设置或随附的 NvCudaRuntimeApi.v3.2.rules 文件CUDA 3.2 RC?
提前致谢!我会提供赏金,但我总共只有 65 分.
CUDA TOOLKIT 4.0 及更高版本
构建自定义文件(安装到 Program FilesMSBuildMicrosoft.Cppv4.0BuildCustomizations
目录中)教"Visual Studio 如何编译和链接您的任何 .cu 文件项目到您的应用程序.如果您选择跳过安装自定义,或者如果您在 CUDA 之后安装了 VS2010,您可以稍后按照 Program FilesNVIDIA GPU Computing ToolkitCUDAv4.0extrasvisual_studio_integration
.
.cu
文件,那么您需要将 .cu
文件的类型设置为 CUDA C/C++
(右击文件,Properties,设置Item Type)cudart.lib
到附加依赖项)顺便说一句,如果可能的话,我会提倡避免cutil,而是自己进行检查.Cutil 不受 NVIDIA 支持,它只是用来尝试使 SDK 中的示例专注于实际程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析).如果您自己编写,那么您将有更好的控制权,并且会知道发生了什么.例如,如果函数失败,cutilSafeCall
包装器会调用 exit()
- 真正的应用程序(而不是示例)可能应该更优雅地处理失败!
注意
<块引用>
计算元素中AssemblyFile"属性的值$(CudaBuildTasksPath)"的结果"无效
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.
CUDA TOOLKIT 4.0 and later
The build customisations file (installed into the Program FilesMSBuildMicrosoft.Cppv4.0BuildCustomizations
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 in Program FilesNVIDIA GPU Computing ToolkitCUDAv4.0extrasvisual_studio_integration
.
.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)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 calls exit()
if the function fails - a real application (as opposed to a sample) should probably handle the failure more elegantly!
NOTE
The result "" of evaluating the value "$(CudaBuildTasksPath)" of the "AssemblyFile" attribute in the element is not valid
这篇关于如何在 Visual Studio 2010 中启动 CUDA 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!