cuda - 单个 CUDA 内核中可以启动的最大线程数

标签 cuda gpu thrust

我对 Fermi GPU 中可以启动的最大线程数感到困惑。

我的 GTX 570 设备查询如下。

  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     65535 x 65535 x 65535

根据我的理解,我对上述说法的理解是:

对于 CUDA 内核,我们最多可以启动 65536 个 block 。每个启动的 block 最多可以包含 1024 个线程。因此原则上,我最多可以启动 65536*1024 (=67108864) 个线程。

这是正确的吗?如果我的线程使用很多寄存器怎么办?我们仍然能够达到这个理论上的最大线程数吗?

编写并启动 CUDA 内核后,我如何知道我启动的线程和 block 的数量确实已实例化。我的意思是,如果我偶然实例化了比该特定内核可能的线程更多的线程,我不希望 GPU 计算出一些垃圾,或者表现得很奇怪。

最佳答案

For a CUDA kernel we can launch at most 65536 blocks. Each launched block can contain upto 1024 threads. Hence in principle, I can launch up to 65536*1024 (=67108864) threads.

不,这是不正确的。您可以启动最多包含 65535 x 65535 x 65535 block 的网格,每个 block 最多有 1024 个线程,但每个线程资源限制可能会将每个 block 的线程总数限制为小于此最大值。

What if my thread uses a lot registers? Will we still be able to reach this theoretical maximum of the number of threads?

不,在这种情况下您将无法达到每个 block 的最大线程数。 NVIDIA CUDA 工具包的每个版本都包含一个占用计算器电子表格,您可以使用它来查看寄存器压力对限制 block 大小的影响。

Also, after writing and launching the CUDA kernel, how do I know that the number of threads and blocks that I have launched have indeed been instantiated. I mean I dont want the GPU to calculate some junk, or behace weirdly, if I have by chance instantiated more threads than are possible for that particular kernel.

如果您选择非法的执行配置(例如不正确的 block 大小或网格大小),内核将不会启动,并且运行时将发出 cudaErrorInvalidConfiguration 错误消息。您可以使用标准 cudaPeekAtLastError()cudaGetLastError() 来检查任何内核启动的状态。

关于cuda - 单个 CUDA 内核中可以启动的最大线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12078080/

相关文章:

c++ - 如何有效地将 vector 重复到cuda中的矩阵?

c++ - 如何使用 Cuda 将动态特征向量传递给 GPU?

cuda - 我应该在这里使用 CUDA 吗?

cuda - 函数 cudaCreateChannelDesc 中的参数 x,y,z,w 的含义是什么

c++ - __syncthreads() 之后的 CUDA 竞赛检查危险

c++ - 在 CUDA C 项目中使用 C++

c++ - Visual Studio .cu 文件显示语法错误但编译成功

html - GPU 加速了 CSS3 的哪些具体部分?

ubuntu - 无法选择功能为 : [[gpu]] 的设备驱动程序 ""

c++ - 推力数组的动态内存分配