是cuda内核调用同步还是异步 [英] Are cuda kernel calls synchronous or asynchronous

查看:487
本文介绍了是cuda内核调用同步还是异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到,可以使用内核启动来同步不同的块,即,如果我想在所有块完成操作1之后,他们进入操作2,我应该把操作1在一个内核和操作2在另一个内核。这样,我可以实现块之间的全局同步。然而,cuda c编程指南提到内核调用是异步的。 CPU不等待第一个内核调用完成,因此,CPU也可以在1st完成之前调用第二个内核。然而,如果这是真的,那么我们不能使用内核启动来同步块。请让我知道我在哪里出错

I read that one can use kernel launches to synchronize different blocks i.e., If i want all blocks to complete operation 1 before they go on to operation 2, I should place operation 1 in one kernel and operation 2 in another kernel. This way, I can achieve global synchronization between blocks. However, the cuda c programming guide mentions that kernel calls are asynchronous ie. the CPU does not wait for the first kernel call to finish and thus, the CPU can also call the second kernel before the 1st has finished. However, if this is true, then we cannot use kernel launches to synchronize blocks. Please let me know where i am going wrong

推荐答案

内核调用是从CPU的角度异步的,如果你调用2个内核连续第二个将被调用而不等待第一个完成。

Kernel calls are asynchronous from the point of view of the CPU so if you call 2 kernels in succession the second one will be called without waiting for the first one to finish. It only means that the control returns to the CPU immediately.

在GPU方面,如果您没有指定不同的流来执行内核,它们将被执行。它们被调用的顺序(如果你没有指定一个流,他们都去到默认流,并被串行执行)。只有在第一个内核完成后,第二个内核才会执行。

On the GPU side, if you haven't specified different streams to execute the kernel they will be executed by the order they were called (if you don't specify a stream they both go to the default stream and are executed serially). Only after the first kernel is finished the second one will execute.

此行为适用于支持并发内核执行的计算能力2.x的设备。在其他设备上,即使内核调用仍然是异步的,内核执行总是顺序的。

This behavior is valid for devices with compute capability 2.x which support concurrent kernel execution. On the other devices even though kernel calls are still asynchronous the kernel execution is always sequential.

检查CUDA C编程指南3.2.5节,每个CUDA程序员应该读。

Check the CUDA C programming guide on section 3.2.5 which every CUDA programmer should read.

这篇关于是cuda内核调用同步还是异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆