且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cuda PTX注册声明和使用

更新时间:2021-11-24 04:14:50

如前所述,PTX是一个中间代码。 PTX寄存器是虚拟寄存器,不一定反映实际的器件寄存器使用。

As indicated already, PTX is an intermediate code. PTX "registers" are virtual registers and don't necessarily reflect actual device register usage.

要想了解实际器件寄存器的使用,请使用ptxas verbose选项进行编译:

To get an idea of actual device register usage, compile using the ptxas verbose option:

nvcc -Xptxas -v ...

或使用其中一个分析器。您也可以直接使用以下方法检查机器代码:

or use one of the profilers. You can also inspect the machine code directly using:

cuobjdump -sass myexe

(其中 myexe 替换为可执行文件的名称)。

(where myexe is replaced with the name of your executable).

要控制寄存器的使用,可以使用nvcc编译选项:

To control register usage, you can use the nvcc compile option:

nvcc -maxrregcount 10 ...

(其中10替换为每个线程需要多少寄存器,您希望代码中的所有内核受限),或者您可以使用启动范围指令,这可以在逐个内核的基础上控制寄存器的使用。

(where 10 is replaced with how many registers per thread you want all kernels in your code to be limited to) or you can use the launch bounds directive in your code, which can control register usage on a kernel-by-kernel basis.