前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >DAY72:阅读Toolkit Support for Dynamic Parallelism

DAY72:阅读Toolkit Support for Dynamic Parallelism

作者头像
GPUS Lady
发布2018-09-29 17:57:07
4590
发布2018-09-29 17:57:07
举报
文章被收录于专栏:GPUS开发者GPUS开发者

我们正带领大家开始阅读英文的《CUDA C Programming Guide》,今天是第72天,我们正在讲解CUDA 动态并行,希望在接下来的28天里,您可以学习到原汁原味的CUDA,同时能养成英文阅读的习惯。

关注微信公众号,查看历史信息,可以看到之前的阅读

本文共计219字,阅读时间15分钟

前情回顾:

DAY61:关于Cooperative Groups

DAY62:阅读Glossary

DAY63:阅读Execution Environment

DAY64:阅读 Memory Model

DAY65:阅读Device-Side Kernel Launch

DAY66:阅读Streams

DAY67:阅读阅读Events、Synchronization和Device Management

DAY68:阅读 Memory Declarations

DAY69:阅读API Errors and Launch Failures

DAY70:阅读API Reference

DAY71:阅读Device-side Launch from PTX

D.3.3. Toolkit Support for Dynamic Parallelism

D.3.3.1. Including Device Runtime API in CUDA Code

Similar to the host-side runtime API, prototypes for the CUDA device runtime API are included automatically during program compilation. There is no need to includecuda_device_runtime_api.h explicitly.

D.3.3.2. Compiling and Linking

CUDA programs are automatically linked with the host runtime library when compiled with nvcc, but the device runtime is shipped as a static library which must explicitly be linked with a program which wishes to use it.

The device runtime is offered as a static library (cudadevrt.lib on Windows, libcudadevrt.a under Linux and MacOS), against which a GPU application that uses the device runtime must be linked. Linking of device libraries can be accomplished through nvcc and/or nvlink. Two simple examples are shown below.

A device runtime program may be compiled and linked in a single step, if all required source files can be specified from the command line:

代码语言:javascript
复制
$ nvcc -arch=sm_35 -rdc=true hello_world.cu -o hello -lcudadevrt

It is also possible to compile CUDA .cu source files first to object files, and then link these together in a two-stage process:

代码语言:javascript
复制
$ nvcc -arch=sm_35 -dc hello_world.cu -o hello_world.o
$ nvcc -arch=sm_35 -rdc=true hello_world.o -o hello -lcudadevrt

Please see the Using Separate Compilation section of The CUDA Driver Compiler NVCC guide for more details.

本文备注/经验分享:

主要是说, 用户在使用动态并行的时候, 需要在头文件中包含哪些头文件(设备端Runtime的头文件), 以及, 连接的时候需要使用哪些库(设备端的库), 还有连接的时候所需要的特殊参数(rdc, Relocatable Device Code)。因为CUDA C相当于C语言的扩展, 所以常见的C语言对一些库的用法, 这里也适合.也就是说, 你需要额外指定一些头文件, 再指定一些链接的库这两个步骤, 部分特别的库还需要特别的编译参数.但CUDA是一种易用为主的语言, 在现在为主的开发包版本中(CUDA 9.2),该头文件和该库都会被自动被链接上去.也就是说, 本章节给出的头文件和库均不需要你记忆和指定了.全部现在都已经是自动的了.唯一需要注意的则是rdc选项(设备端代码重定位), 这个还是需要的.也就是这是为了的本章节的还需要的内容(指定在你的命令行上). 这是对于命令行用户说的. 对于常见的Windows上的VS用户, 如果是使用的默认的安装CUDA时候的CUDA自定义模板,直接在Solution Explorer里面, 右键属性中, 选择rdc打开即可,也就是说, VS点击几下鼠标, 就可以打开开发环境的动态并行支持了. 这个非常简单. 这就是本章节的全部内容.常见的使用动态并行不能, VS用户都是忘记打开了这个选项, 打开即可.需要说明的是, 链接动态并行的库会可能带来额外的性能负担. 这个以后再说.以及, 在你的代码调用动态并行的相关东西, 例如动态并行所需要的设备端库的一些函数的时候,实际在生成PTX这一步, 都是.extern或者.weak形式的占位的, 这里看不到这些代码.

有不明白的地方,请在本文后留言

或者在我们的技术论坛bbs.gpuworld.cn上发帖

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-09-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GPUS开发者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前情回顾:
  • DAY61:关于Cooperative Groups
  • D.3.3. Toolkit Support for Dynamic Parallelism
  • D.3.3.1. Including Device Runtime API in CUDA Code
  • D.3.3.2. Compiling and Linking
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档