彻底解决CUDA安装,从翻译文档开始_Compiling CUDA Programs

前面一番折腾解决了安装问题,懒得再走回头路去记录了,直接从这里开始吧

3. Compiling CUDA Programs(编译CUDA程序)

The project files in the CUDA Samples have been designed to provide simple, one-click builds of the programs that include all source code.

CUDA例子中的项目已经被设计成提供包含所有源代码的简单一键构建的程序(一直编译的都是自己的小程序,可能整个项目的编译惯例叫“build”)

To build the Windows projects (for release or debug mode), use the provided *.sln solution files for Microsoft Visual Studio 2010, 2012, or 2013. You can use either the solution files located in each of the examples directories in

要构建Windows项目(用于发布或调试模式),请使用Microsoft Visual Studio 2010、2012或2013提供的* .sln解决方案文件。您可以使用位于以下每个示例目录中的解决方案文件

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1\<category>\<sample_name>

or the global solution files Samples*.sln located in

或位于以下位置的全局解决方案文件Sample * .sln

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1

CUDA Samples are organized according to <category>. Each sample is organized into one of the following folders: (0_Simple, 1_Utilities, 2_Graphics, 3_Imaging, 4_Finance, 5_Simulations, 6_Advanced, 7_CUDALibraries).

CUDA例子是根据<类别>进行组织的。 每个例子都被组织为以下文件夹之一:(0_Simple,1_Utilities,2_Graphics,3_Imaging,4_Finance,5_Simulations,6_Advanced,7_CUDALibraries)。

3.1. Compiling Sample Projects(编译例子项目)

The bandwidthTest project is a good sample project to build and run. It is located in the NVIDIA Corporation\CUDA Samples\v10.1\1_Utilities\bandwidthTest directory.

带宽测试项目是一个很好的示例项目,可以构建和运行。 它位于NVIDIA Corporation \ CUDA Samples \ v10.1 \ 1_Utilities \ bandwidthTest目录中。

If you elected to use the default installation location, the output is placed in CUDA Samples\v10.1\bin\win64\Release. Build the program using the appropriate solution file and run the executable. If all works correctly, the output should be similar to Figure 2.

如果选择使用默认安装位置,则输出将放置在CUDA Samples \ v10.1 \ bin \ win64 \ Release中。 使用适当的解决方案文件生成程序并运行可执行文件。 如果所有操作均正常,则输出应类似于图2。

Valid Results from bandwidthTest CUDA Sample.

3.2. Sample Projects

The sample projects come in two configurations: debug and release (where release contains no debugging information) and different Visual Studio projects.

示例项目有两种配置:调试和发布(其中发布不包含调试信息)和不同的Visual Studio项目。

A few of the example projects require some additional setup. The simpleD3D9 example requires the system to have a Direct3D SDK (June 2010 or later) installed and the Visual C++ directory paths (located in Tools > Options...) properly configured. Consult the Direct3D documentation for additional details.

一些示例项目需要一些其他设置。 simpleD3D9示例要求系统安装Direct3D SDK(2010年6月或更高版本)并正确配置Visual C ++目录路径(位于工具>选项...中)。 有关其他详细信息,请查阅Direct3D文档。

These sample projects also make use of the $CUDA_PATH environment variable to locate where the CUDA Toolkit and the associated .props files are.

这些示例项目还利用$ CUDA_PATH环境变量来定位CUDA工具包和关联的.props文件所在的位置。

The environment variable is set automatically using the Build Customization CUDA 10.1.props file, and is installed automatically as part of the CUDA Toolkit installation process.

环境变量是使用Build Customization CUDA 10.1.props文件自动设置的,并在CUDA Toolkit安装过程中自动安装。(看好多博主有自己设置环境变量的,有这句话10.1大概是不需要再自己设了吧)

Table 4. CUDA Visual Studio .props locations
Visual StudioCUDA 10.1 .props file Install Directory
Visual Studio 2019C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations
Visual Studio 2017<Visual Studio Install Dir>\Common7\IDE\VC\VCTargets\BuildCustomizations
Visual Studio 2015C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations
Visual Studio 2013C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations
Visual Studio 2012C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations

You can reference this CUDA 10.1.props file when building your own CUDA applications.

您可以在构建自己的CUDA应用程序时引用此CUDA 10.1.props文件。

3.3. Build Customizations for New Projects

When creating a new CUDA application, the Visual Studio project file must be configured to include CUDA build customizations. To accomplish this, click File-> New | Project... NVIDIA-> CUDA->, then select a template for your CUDA Toolkit version.

创建新的CUDA应用程序时,必须将Visual Studio项目文件配置为包括CUDA构建自定义项。 为此,请单击“文件”->“新建” |“新建”。 项目... NVIDIA-> CUDA->,然后为您的CUDA Toolkit版本选择一个模板。

For example, selecting the "CUDA 10.1 Runtime" template will configure your project for use with the CUDA 10.1 Toolkit. The new project is technically a C++ project (.vcxproj) that is preconfigured to use NVIDIA's Build Customizations. All standard capabilities of Visual Studio C++ projects will be available.

例如,选择“ CUDA 10.1 Runtime”模板将配置您的项目以与CUDA 10.1 Toolkit一起使用。 从技术上讲,该新项目是一个C ++项目(.vcxproj),该项目已预先配置为使用NVIDIA的Build Customizations。 Visual Studio C ++项目的所有标准功能都将可用。

To specify a custom CUDA Toolkit location, under CUDA C/C++, select Common, and set the CUDA Toolkit Custom Dir field as desired. Note that the selected toolkit must match the version of the Build Customizations.

要指定自定义CUDA Toolkit的位置,请在CUDA C / C ++下选择Common,然后根据需要设置CUDA Toolkit Custom Dir字段。 请注意,所选工具箱必须与“构建定制”的版本匹配。

3.4. Build Customizations for Existing Projects

When adding CUDA acceleration to existing applications, the relevant Visual Studio project files must be updated to include CUDA build customizations. This can be done using one of the following two methods:

将CUDA加速添加到现有应用程序时,必须更新相关的Visual Studio项目文件以包括CUDA构建自定义项。 可以使用以下两种方法之一来完成此操作:

  1. Open the Visual Studio project, right click on the project name, and select Build Customizations..., then select the CUDA Toolkit version you would like to target. 
    打开Visual Studio项目,右键单击项目名称,然后选择``Build Customizations ...'',然后选择要定位的CUDA Toolkit版本。
  2. Alternatively, you can configure your project always to build with the most recently installed version of the CUDA Toolkit. First add a CUDA build customization to your project as above. Then, right click on the project name and select Properties. Under CUDA C/C++, select Common, and set the CUDA Toolkit Custom Dir field to $(CUDA_PATH) . Note that the $(CUDA_PATH) environment variable is set by the installer.
    或者,您可以始终将项目配置为使用最新安装的CUDA Toolkit版本进行构建。 首先,如上所述,将CUDA构建自定义项添加到您的项目中。 然后,右键单击项目名称,然后选择“属性”。 在CUDA C / C ++下,选择Common,然后将CUDA Toolkit自定义目录字段设置为$(CUDA_PATH)。 请注意,$(CUDA_PATH)环境变量由安装程序设置。

While Option 2 will allow your project to automatically use any new CUDA Toolkit version you may install in the future, selecting the toolkit version explicitly as in Option 1 is often better in practice, because if there are new CUDA configuration options added to the build customization rules accompanying the newer toolkit, you would not see those new options using Option 2.

尽管选项2允许您的项目自动使用您将来可能安装的任何新CUDA工具包版本,但实际上,如选项1中那样明确选择工具包版本通常会更好,因为在构建定制中添加了新的CUDA配置选项 新工具包附带的规则,则使用选项2不会看到这些新选项。

If you use the $(CUDA_PATH) environment variable to target a version of the CUDA Toolkit for building, and you perform an installation or uninstallation of any version of the CUDA Toolkit, you should validate that the $(CUDA_PATH) environment variable points to the correct installation directory of the CUDA Toolkit for your purposes. You can access the value of the $(CUDA_PATH) environment variable via the following steps:

如果您使用$(CUDA_PATH)环境变量来定位要构建的CUDA工具包版本,并且执行了任何版本的CUDA工具包的安装或卸载,则应验证$(CUDA_PATH)环境变量是否指向 正确使用CUDA Toolkit的安装目录。 您可以通过以下步骤访问$(CUDA_PATH)环境变量的值:

  1. Open a run window from the Start Menu
  2. Run:
    control sysdm.cpl
  3. Select the "Advanced" tab at the top of the window
  4. Click "Environment Variables" at the bottom of the window

Files which contain CUDA code must be marked as a CUDA C/C++ file. This can done when adding the file by right clicking the project you wish to add the file to, selecting Add\New Item, selecting NVIDIA CUDA 10.1\Code\CUDA C/C++ File, and then selecting the file you wish to add.

包含CUDA代码的文件必须标记为CUDA C / C ++文件。 通过右键单击要添加文件的项目,选择添加\新项,选择NVIDIA CUDA10.1 \ Code \ CUDA C / C ++文件,然后选择要添加的文件来添加文件。

Note for advanced users: If you wish to try building your project against a newer CUDA Toolkit without making changes to any of your project files, go to the Visual Studio command prompt, change the current directory to the location of your project, and execute a command such as the following:

高级用户注意事项:如果您希望尝试使用较新的CUDA工具包构建项目而不更改任何项目文件,请转到Visual Studio命令提示符,将当前目录更改为项目的位置,然后执行 命令如下:

msbuild <projectname.extension> /t:Rebuild /p:CudaToolkitDir="drive:/path/to/new/toolkit/"

4. Additional Considerations

Now that you have CUDA-capable hardware and the NVIDIA CUDA Toolkit installed, you can examine and enjoy the numerous included programs. To begin using CUDA to accelerate the performance of your own applications, consult the CUDA C Programming Guide, located in the CUDA Toolkit documentation directory.

现在,您已经具有支持CUDA的硬件并安装了NVIDIA CUDA Toolkit,您可以检查并享受众多附带的程序。 要开始使用CUDA来提高自己的应用程序的性能,请参阅CUDA Toolkit文档目录中的``CUDA C编程指南''。

A number of helpful development tools are included in the CUDA Toolkit or are available for download from the NVIDIA Developer Zone to assist you as you develop your CUDA programs, such as NVIDIA® Nsight™ Visual Studio Edition, NVIDIA Visual Profiler, and cuda-memcheck.

CUDA工具包中包含许多有用的开发工具,或者可以从NVIDIA开发人员专区下载许多有用的开发工具,以帮助您开发CUDA程序,例如NVIDIA®Nsight™Visual Studio Edition,NVIDIA Visual Profiler和cuda-memcheck 。

For technical support on programming questions, consult and participate in the developer forums at

要获得有关编程问题的技术支持,请咨询并参与以下开发人员论坛:

 http://developer.nvidia.com/cuda/.

Notices

Notice

ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, "MATERIALS") ARE BEING PROVIDED "AS IS." NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.

所有NVIDIA设计规范,参考板,文件,工程图,诊断,列表和其他文件(统称“材料”)均按“原样”提供。 NVIDIA对材料不做任何明示,暗示,法定或其他形式的保证,并明确否认对特定目的的非侵权性,适销性和适用性的所有暗示保证。

Information furnished is believed to be accurate and reliable. However, NVIDIA Corporation assumes no responsibility for the consequences of use of such information or for any infringement of patents or other rights of third parties that may result from its use. No license is granted by implication of otherwise under any patent rights of NVIDIA Corporation. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all other information previously supplied. NVIDIA Corporation products are not authorized as critical components in life support devices or systems without express written approval of NVIDIA Corporation.

提供的资料被认为是准确可靠的。 但是,NVIDIA Corporation不承担因使用此类信息而导致的后果,也不承担因使用此类信息而导致的任何专利或第三方权利的侵犯。 NVIDIA Corporation的任何专利权均不暗示授予许可。 本出版物中提到的规格如有更改,恕不另行通知。 本出版物将取代并替代以前提供的所有其他信息。 未经NVIDIA Corporation明确书面许可,未将NVIDIA Corporation产品授权为生命支持设备或系统中的关键组件。

 

Trademarks

NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA Corporation in the U.S. and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.

NVIDIA和NVIDIA徽标是NVIDIA Corporation在美国和其他国家(地区)的商标或注册商标。 其他公司名称和产品名称可能是与它们相关的相应公司的商标。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值