调用cuda内核时返回cudaErrorLaunchOutOfResources错误代码

在头文件中的定义如下:

/**

     * This indicates that a launch did not occur because it did not have
     * appropriate resources. Although this error is similar to
     * ::cudaErrorInvalidConfiguration, this error usually indicates that the
     * user has attempted to pass too many arguments to the device kernel, or the
     * kernel launch specifies too many threads for the kernel's register count.
     */
    cudaErrorLaunchOutOfResources         =      7,

  

一种情况就是指定太多线程,而使寄存器的总数超过了最大值时就会出现这种错误。

解决办法如下:

        1、加入编译选项-maxrregcount,限定寄存器个数,如果寄存器个数不够,那么则使用local memory,但这样会有性能上影响;

        2、修改指定配置,使之一个线程块包含的线程数相对减少,这样每个线程所能使用的寄存器数量就会相对变多。


关于查看内核所使用寄存器的情况的方法:加入编译选项,--ptxas-options=-v

这样在编译时就会输出相应的信息,例如:


猜你喜欢

转载自blog.csdn.net/a812073479/article/details/80515062