启动内核时共享内存和流 [英] Shared memory and streams when launching kernel

查看:123
本文介绍了启动内核时共享内存和流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的CUDA和在个人项目。我知道,如果你想在启动指定共享内存量:

I'm new to CUDA and working on a personal project. I know that, if you want to specify the amount of shared memory at launch:

kernel<<<grid_size,block_size,shared_mem_size>>>(parameters);

在另一方面,如果我想提出一个内核到流:

On the other hand, if I want to put a kernel into a stream:

kernel<<<grid_size,block_size,0,stream_being_used>>>(parameters);

我不明白为什么第三个参数流的情况下为0? (我的例子CUDA得到它在第10章桑德斯和Kandrot)。

I don't understand why the third parameter is 0 in the case of stream? (I'm getting it from chapter 10 in "CUDA by examples" by Sanders and Kandrot).

如果我想指定在启动共享内存,并把它变成一个流,我该怎么做对了吗?换句话说,应该在两者之间&LT参数;&LT;&LT; ... >>>什么样子的?

If I want to specify the shared memory at launch AND put it into a stream, how do I do that correctly? In other words, what should the parameters in between <<<...>>> look like?

推荐答案

的唯一原因0是有,因为在这特殊的例子,没有的动态的共享内存是必须的。

The only reason that 0 is there is because in that particular example, no dynamic shared memory is required.

共享内存既可以分配静态(不使用的extern 在这种情况下,大小在声明中明确规定)或动态(使用的extern ,和大小显示为内核启动配置中的第三个参数)。

Shared memory can be allocated either statically (without using extern in which case the size is explicitly stated in the declaration) or dynamically(using extern, and the size shows up as the 3rd parameter in the kernel launch configuration).

内核启动配置参数&LT;&LT;&LT; ...&GT;&GT;&GT; 总是以相同的顺序显示出来:

The kernel launch configuration parameters <<<...>>> always show up in the same order:


  1. 网格尺寸

  2. 的threadblock尺寸

  3. 动态分配共享内存的大小(字节的)

  4. 流启动内核

1和2是强制性的,3和4是可选的。但是,如果你需要指定参数4(流)的您必须提供的参数3,即使是零。

1 and 2 are mandatory, 3 and 4 are optional. But if you need to specify parameter 4 (the stream) you must supply parameter 3, even if it is zero.

因此​​,正确的顺序是:

so the correct sequence is:

kernel_name<<<grid_dim, threadblock_dim, dynamic_shared_memory_size, stream>>>(...);

您可以阅读更多关于它在文档

You can read more about it in the documentation

这篇关于启动内核时共享内存和流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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