据我理解,
ptxas
(设备汇编器)仅在链接代码时输出寄存器计数。独立的
__device__
函数不会被汇编器链接,它们只是被编译。因此,汇编器不会为设备函数发出寄存器计数值。我不认为有任何解决方法。
然而,仍然可以通过使用
cuobjdump
从汇编器输出中转储elf数据来获取
__device__
函数的寄存器占用量。您可以按以下方式执行此操作:
$ cat vdot.cu
__device__ __noinline__ float vdot(float v1, float v2) {
return (v1 * v2);
}
__device__ __noinline__ float vdot(float2 v1, float2 v2) {
return (v1.x * v2.x) + (v1.y * v2.y);
}
__device__ __noinline__ float vdot(float4 v1, float4 v2) {
return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) + (v1.w * v2.w);
}
$ nvcc -std=c++11 -arch=sm_52 -dc -Xptxas="-v" vdot.cu
ptxas info : 0 bytes gmem
ptxas info : Function properties for cudaDeviceGetAttribute
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for _Z4vdotff
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for cudaOccupancyMaxActiveBlocksPerMultiprocessor
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for _Z4vdot6float4S_
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for cudaMalloc
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for cudaGetDevice
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for _Z4vdot6float2S_
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for cudaOccupancyMaxActiveBlocksPerMultiprocessorWithFlags
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Function properties for cudaFuncGetAttributes
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
这里我们有一个在设备对象文件中单独编译的三个__device__
函数集合。在其上运行cuobjdump
会产生大量输出,但其中你将获得每个函数的寄存器计数:
$ cuobjdump -elf ./vdot.o
Fatbin elf code:
================
arch = sm_52
code version = [1,7]
producer = cuda
host = linux
compile_size = 64bit
compressed
<---Snipped--->
.text._Z4vdotff
bar = 0 reg = 6 lmem=0 smem=0
0xfec007f1 0x001fc000 0x00570003 0x5c980780
0x00470000 0x5c980780 0x00370004 0x5c680000
0xffe007ff 0x001f8000 0x0007000f 0xe3200000
0xff87000f 0xe2400fff 0x00070f00 0x50b00000
在设备函数
dot(float, float)
的输出的第二行中,您可以看到该函数使用了6个寄存器。这是我所知道的检查设备函数寄存器占用情况的唯一方法。
cuobjdump -elf ./vdot.o | c++filt
怎么样? - einpoklum