【问题标题】:Number of registers per thread每个线程的寄存器数
【发布时间】:2013-07-02 02:29:43
【问题描述】:

为 CUDA kenel 保持较低的寄存器/线程数有什么好处吗?

我认为没有优势(速度或其他)。 3 reg/线程的上下文切换与 48 reg/线程一样快。除非您不想使用,否则不使用所有可用寄存器是没有意义的。内核之间不共享寄存器。 这是错的吗?

编辑: 来自CUDA4.2编程指南(5.2.3):

    The number of registers used by a kernel can have a significant impact on the number 
    of resident warps. For example, for devices of compute capability 1.2, if a kernel uses 16 
registers and each block has 512 threads and requires very little shared memory, then two 
    blocks (i.e. 32 warps) can reside on the multiprocessor since they require 2x512x16 
    registers, which exactly matches the number of registers available on the multiprocessor.
     But as soon as the kernel uses one more register, only one block (i.e. 16 warps) can be 
    resident since two blocks would require 2x512x17 registers, which are more registers than 
    are available on the multiprocessor. Therefore, the compiler attempts to minimize register 
    usage while keeping register spilling (see Section 5.3.2.2) and the number of instructions 
    to a minimum.

“regs/thread”计数似乎并不像总 reg 计数那么重要。

【问题讨论】:

    标签: cuda


    【解决方案1】:

    使用中的寄存器数量会影响 GPU 的占用率,因为每个多处理器的寄存器总数是有限的。

    CUDA Occupancy calculator

    您可以输入您的计算能力、共享内存大小配置值、每个块的线程数、每个线程的寄存器和每个块的共享内存字节数。

    该表将为您提供有关每个多处理器 (mp) 将运行多少个线程、多少个 warp 处于活动状态、每个 mp 的线程块数以及每个 mp 的占用率的信息。

    事实上,这取决于您的问题,但您会希望尽可能高的入住率,以避免资源浪费。另一方面,如果寄存器数量受到限制,您的代码可能会变慢。

    因此,不使用所有寄存器以避免低占用率可能是有道理的,但正如我所说,这是一个折衷的事情。

    【讨论】:

      【解决方案2】:

      由于单个 SM 上可以运行许多块,因此为每个线程分配过多的寄存器可能会损害性能。您在 SM 上受到硬件限制 - 如果您的 SM 使用 10 个块“饱和”(即它永远不必等待块完成内存访问,因为它还有其他工作要做),但每个块使用 1/5在那个 SM 注册,你的利用率将低于标准。

      这也适用于共享内存,每个 SM 限制 (IIRC) 为 ~32k。 (+/- 取决于您的 GPU/架构)

      【讨论】:

        猜你喜欢
        • 2013-07-07
        • 1970-01-01
        • 2012-05-09
        • 1970-01-01
        • 2012-08-25
        • 1970-01-01
        • 2018-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多