gpt4 book ai didi

cuda - 每个线程的寄存器数

转载 作者:行者123 更新时间:2023-12-04 04:51:38 25 4
gpt4 key购买 nike

将 CUDA 内核的寄存器/线程数保持在较低水平有什么好处吗?

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

编辑:
来自 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 计数那么重要。

最佳答案

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

CUDA Occupancy calculator

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

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

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

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

关于cuda - 每个线程的寄存器数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17348929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com