DAY10:阅读CUDA异步并发执行中的Streams

我们正带领大家开始阅读英文的《CUDA C Programming Guide》,今天是第10天,我们用几天时间来学习CUDA 的编程接口,其中最重要的部分就是CUDA C runtime.希望在接下来的90天里,您可以学习到原汁原味的CUDA,同时能养成英文阅读的习惯。

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

重要的是——

如果你已经坚持了10天,你已经共计阅读了8164个字!

前情回顾:

DAY5:阅读 CUDA C编程接口之CUDA C runtime

DAY6:阅读 CUDA C编程接口之CUDA C runtime

DAY7:阅读 CUDA C编程接口之CUDA C runtime

DAY8:阅读CUDA异步并发执行中的Streams

DAY9:阅读CUDA异步并发执行中的Streams

今天继续讲解异步并发执行中的Streams,好消息是,今天讲完就真的把Stream部分讲完了,我们可以继续往下走了:

3.2.5.5.6. Callbacks

The runtime provides a way to insert【插入】 a callback at any point into a stream via cudaStreamAddCallback(). A callback is a function that is executed on the host once all commands issued to the stream before the callback have completed. Callbacks in stream 0 are executed once all preceding tasks and commands issued in all streams before the callback have completed.

The following code sample adds the callback function MyCallback to each of two streams after issuing a host-to-device memory copy, a kernel launch and a device-to-host memory copy into each stream. The callback will begin execution on the host after each of the device-to-host memory copies completes.

The commands that are issued in a stream (or all commands issued to any stream if the callback is issued to stream 0) after a callback do not start executing before the callback has completed. The last parameter of cudaStreamAddCallback() is reserved for future use.

A callback must not make CUDA API calls (directly or indirectly), as it might end up waiting on itself if it makes such a call leading to a deadlock.

3.2.5.5.7. Stream Priorities

The relative priorities of streams can be specified at creation using cudaStreamCreateWithPriority(). The range of allowable priorities, ordered as [ highest priority【优先级】, lowest priority ] can be obtained【获得】 using the cudaDeviceGetStreamPriorityRange() function. At runtime, as blocks in low-priority schemes finish, waiting blocks in higher-priority streams are scheduled in their place.

The following code sample obtains the allowable range of priorities for the current device, and creates streams with the highest and lowest available priorities

本文备注/经验分享:

A callback must not make CUDA API calls (directly or indirectly), as it might end up waiting on itself if it makes such a call leading to a deadlock.

回调函数不能调用任何CUDA API函数,无论是直接的,还是间接的调用。因为如果在回调函数中这样做了,调用CUDA函数的回调函数将自己等待自己,造成死锁。其实这很显然的,流中的下一个任务将需要等待流中的之前任务完成才能继续,因为CUDA Stream是顺序执行的, 而如果你一个流中的某回调函数,继续给某流发布了一个任务,很有可能该回调函数永远也等待不完下一个任务完成,因为等待下一个任务完成首先需要这回调函数先结束,而回调函数却在等待下一个任务完成....于是就死锁了。

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

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

原文发布于微信公众号 - 吉浦迅科技(gpusolution)

原文发表时间:2018-05-13

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏陈仁松博客

ASP.NET Core 'Microsoft.Win32.Registry' 错误修复

今天在发布Asp.net Core应用到Azure的时候出现错误InvalidOperationException: Cannot find compilati...

4798
来自专栏张善友的专栏

LINQ via C# 系列文章

LINQ via C# Recently I am giving a series of talk on LINQ. the name “LINQ via C...

2605
来自专栏我和未来有约会

Silverlight第三方控件专题

这里我收集整理了目前网上silverlight第三方控件的专题,若果有所遗漏请告知我一下。 名称 简介 截图 telerik 商 RadC...

3955
来自专栏Ceph对象存储方案

Luminous版本PG 分布调优

Luminous版本开始新增的balancer模块在PG分布优化方面效果非常明显,操作也非常简便,强烈推荐各位在集群上线之前进行这一操作,能够极大的提升整个集群...

3035
来自专栏张善友的专栏

Miguel de Icaza 细说 Mix 07大会上的Silverlight和DLR

Mono之父Miguel de Icaza 详细报道微软Mix 07大会上的Silverlight和DLR ,上面还谈到了Mono and Silverligh...

2667
来自专栏魂祭心

原 canvas绘制clock

4004
来自专栏一个爱瞎折腾的程序猿

sqlserver使用存储过程跟踪SQL

USE [master] GO /****** Object: StoredProcedure [dbo].[sp_perfworkload_trace_s...

1990
来自专栏落花落雨不落叶

canvas画简单电路图

58311
来自专栏跟着阿笨一起玩NET

c#实现打印功能

2612
来自专栏大内老A

The .NET of Tomorrow

Ed Charbeneau(http://developer.telerik.com/featured/the-net-of-tomorrow/) Exciti...

30810

扫码关注云+社区