CUDA:启动请求的资源过多

6

我在使用计算能力为2.0的GTX 480运行代码时遇到了一些问题。

如果我使用每个块1024个线程启动内核,就会出现以下错误:

========= CUDA-MEMCHECK
========= Program hit cudaErrorLaunchOutOfResources (error 7) due to "too many resources requested for launch" on CUDA API call to cudaLaunch.
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:/usr/lib/x86_64-linux-gnu/libcuda.so.1 [0x2ef613]
=========     Host Frame:/usr/local/cuda-6.5/lib64/libcudart.so.6.5 (cudaLaunch + 0x17e) [0x3686e]
=========     Host Frame:./bin/myProgram [0x3a50]
=========     Host Frame:./bin/myProgram [0x388a]
=========     Host Frame:./bin/myProgram [0x38e3]
=========     Host Frame:./bin/myProgram [0x2a99]
=========     Host Frame:./bin/myProgram [0x1410]
=========     Host Frame:./bin/myProgram [0x1da0]
=========     Host Frame:/lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main + 0xed) [0x2176d]
=========     Host Frame:./bin/myProgram [0x1139]
=========

我运行了该程序多次,使用不同的块和线程数:

5 Blocks, 512 Threads per Block => Works
5 Blocks, 1024 Threads per Block => Error
10 Blocks, 512 Threads per Block => Works
10 Blocks, 1024 Threads per Block => Error
15 Blocks, 512 Threads per Block => Works
15 Blocks, 1024 Threads per Block => Error

我检查了使用的寄存器,看起来没问题。使用了这么多线程的内核是具有28个寄存器的“Function4”。所有其他内核每次调用只使用<<<1, 32>>>。

ptxas info    : 0 bytes gmem
ptxas info    : Function properties for _Z7function1Py
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Compiling entry function '_Z13function2PyS_i' for 'sm_20'
ptxas info    : Function properties for _Z13function2PyS_i
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Used 22 registers, 52 bytes cmem[0]
ptxas info    : Compiling entry function '_Z6function3PyiS_' for 'sm_20'
ptxas info    : Function properties for _Z6function3PyiS_
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Used 22 registers, 56 bytes cmem[0]
ptxas info    : Compiling entry function '_Z17function4PyiiS_Phji' for 'sm_20'
ptxas info    : Function properties for _Z17function4PyiiS_Phji
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Used 28 registers, 72 bytes cmem[0]

我也在我的GTX 660上使用CC 3.0运行了这个程序,每个块1024个线程,没有遇到任何问题。不知道问题出在哪里,有人有什么想法吗?


可能是每个线程的寄存器问题。尝试使用-maxrregcount 28(或24)编译代码,看看是否影响了失败的情况。 - Robert Crovella
1个回答

16

我遇到了同样的错误。

感谢http://cuda-programming.blogspot.fr/2013/01/handling-cuda-error-messages.html,我理解了错误的原因。他们说:

"请求启动的资源过多 - 这个错误意味着在多处理器上可用的寄存器数量已经超出了限制。 减少每个块中的线程数可以解决这个问题。"

基本上,我的代码以前可以每个块拥有给定数量的线程(对于一个 3D Kernel 来说是 8x8x16 = 1024)。但是,如果你嵌套了内核调用,你会进一步减少可用的寄存器数量。


有趣的是,我发现使用一个特定的内核(相当大,有很多嵌套调用)时,在调试模式下可以启动512个线程,但在编译发布版本时失败了,只能使用256个线程。似乎发布版本的寄存器使用更重。 - Rags

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接