本文介绍了如何在Visual Studio 2010中启动CUDA应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直接问题:如何在visual studio 2010中创建一个简单的hello世界CUDA项目?



背景:强>我写了CUDA内核。我非常熟悉.vcproj文件从Visual Studio 2005 - 手动调整几个。在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 3.2 RC附带的nSight 1.5安装程序或NvCudaRuntimeApi.v3.2.rules文件构建CUDA内核?



提前感谢!

解决方案

CUDA TOOLKIT 4.0和



建立自订档案(安装在 Program Files \ MSBuild \Microsoft.Cpp \ v4.0 \BuildCustomizations 目录)教导Visual Studio如何编译和链接您的项目中的任何.cu文件到您的应用程序。如果您选择跳过安装定制,或者如果您在CUDA之后安装了VS2010,则可以稍后按照 Program Files \ NVIDIA GPU计算工具包\CUDA \v4.0\\中的说明添加它们\\extras \visual_studio_integration 。




  • 使用标准MS向导创建一个新项目)

  • 在.c或.cpp文件中实现您的主机(序列)代码

  • 添加NVIDIA构建自定义(右键单击项目, ,请勾选相应的CUDA框)

  • 如果使用CUDA 4.0,请参见注释1

  • 实现您的封装和内核.cu文件

  • 如果在构建自定义之前添加了 .cu 文件,则需要设置 .cu 文件到 CUDA C / C ++ (右键单击文件,属性
  • 添加CUDA运行时库(右键单击项目并选择 - >输入添加 cudart.lib 到附加依赖关系
  • 您的项目和.cu文件将被编译为.obj并自动添加到链接



cutil (如果可能),而是滚动自己的检查。 NVIDIA不支持Cutil,它只是试图保持SDK中的示例关注于实际的程序和算法设计,并避免在每个示例中重复相同的事情(例如命令行解析)。如果你写你自己的,那么你会有更好的控制,并将知道发生了什么。例如, cutilSafeCall 包装器调用 exit()如果函数失败 - 一个真正的应用程序)




  1. 对于CUDA 4.0,您可能需要应用到构建自定义。此修补程序修复了以下消息:




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 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 in Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration.

  • Create a new project using the standard MS wizards (e.g. an empty console project)
  • Implement your host (serial) code in .c or .cpp files
  • Add the NVIDIA build customisation (right click on the project, Build customizations, tick the relevant CUDA box)
  • See note 1 if using CUDA 4.0
  • Implement your wrappers and kernels in .cu files
  • 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)
  • Add the CUDA runtime library (right click on the project and choose Properties, then in Linker -> Input add cudart.lib to the Additional Dependencies)
  • Then just build your project and the .cu files will be compiled to .obj and added to the link automatically

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

  1. For CUDA 4.0 only you may need to apply this fix to the build customisations. This patch fixes the following message:

这篇关于如何在Visual Studio 2010中启动CUDA应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:11