2013-06-27 66 views
2

保持CUDA kenel的寄存器/線程數低有什麼好處嗎?每個線程的寄存器數量

我在想沒有優勢(速度或其他)。上下文切換對於3個reg /線程來說是快速的,因爲它是48個regs /線程。除非你不想使用所有可用的寄存器,否則沒有意義。內核之間不共享寄存器。 這是錯誤的嗎?

編輯: 從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. 

的 「的REG /線程」 計數不出現不亞於總章數無關緊要。

回答

3

由於每個多處理器的寄存器總數有限,因此正在使用的寄存器數量會影響GPU的佔用率。

參見CUDA Occupancy calculator

可以輸入你的計算能力,共享內存大小配置值,每個塊的線程的個數,每個線程和每塊的共享存儲器的字節數寄存器。

該工作表將提供關於每個多處理器(mp)將運行多少個線程,活動多少個線程,每個mp的線程塊數目以及每個mp的佔用情況的信息。

事實上,這取決於您的問題,但您希望儘可能提高您的入住率,以避免浪費資源。另一方面,如果寄存器數量受到限制,代碼可能會變慢。

所以可能有一點不使用所有的寄存器來避免低入住率,但正如我所說這是一個折衷的事情。

0

由於許多塊可以在單個SM上運行,因此可以通過爲每個線程分配過多的寄存器來傷害性能。 SM上的硬件限制 - 如果SM用10個塊變得「飽和」(即它不需要等待塊完成存儲器訪問,因爲它有其他工作要做),但每個塊使用1/5的在該SM註冊,您的利用率將低於標準。

這也適用於共享存儲器,這是限制(IIRC)爲每個SM約32k。 (+/-取決於你的GPU /架構)