每个 CUDA 设备都有多个流式多处理器 (SM)。每个 SM 可以有多个 warp 调度器和多个执行单元。 CUDA 核心是执行单元而不是“核心”,所以我将在接下来的讨论中避免使用它们。
NVIDIA 分析工具
- CUDA 命令行分析器
- nvprof 命令行分析器(CUDA 5.0 中的新功能)
- 视觉分析器
- Nsight VSE CUDA 分析器
支持为 CUDA 网格启动收集持续时间和 PM 计数器的功能。每个 SM 可以收集 PM 计数器的子集。
我已经为 nvprof 提供了用于收集这两条信息的命令行。这两个示例都在具有 15 个 SM 的 GTX480 上运行 matrixMul 示例的调试构建。
收集网格执行时间
上面列出的每个工具都有简化模式来收集每个内核网格启动的执行持续时间。图形工具可以将其显示在时间轴或表格中。
nvprof --print-gpu-trace matrixMul.exe
======== NVPROF is profiling matrixMul.exe...
======== Command: matrixMul.exe
[Matrix Multiply Using CUDA] - Starting...
GPU Device 0: "GeForce GTX 480" with compute capability 2.0
MatrixA(320,320), MatrixB(640,320)
Computing result using CUDA Kernel...
done
Performance= 39.40 GFlop/s, Time= 3.327 msec, Size= 131072000 Ops, WorkgroupSize= 1024 threads/block
Checking computed result for correctness: OK
Note: For peak performance, please refer to the matrixMulCUBLAS example.
======== Profiling result:
Start Duration Grid Size Block Size Regs* SSMem* DSMem* Size Throughput Device Context Stream Name
267.83ms 71.30us - - - - - 409.60KB 5.74GB/s 0 1 2 [CUDA memcpy HtoD]
272.72ms 139.20us - - - - - 819.20KB 5.88GB/s 0 1 2 [CUDA memcpy HtoD]
272.86ms 3.33ms (20 10 1) (32 32 1) 20 8.19KB 0B - - 0 1 2 void matrixMulCUDA<int=32>(float*, float*, float*, int, int)
277.29ms 3.33ms (20 10 1) (32 32 1) 20 8.19KB 0B - - 0 1 2 void matrixMulCUDA<int=32>(float*, float*, float*, int, int)
为了在其他工具中收集
- CUDA 命令行分析器 - 指定时间戳
- Visual Profiler - 运行生成时间线
- Nsight VSE - 新分析活动 |追踪 |启用 CUDA
收集 SM 活动
您的问题表明您需要每个 GPU 内核的执行时间。这可能意味着每个 GPU(见上文)或每个 SM。可以使用 SM PM 计数器 active_cycles 收集 SM 执行时间。 active_cycles 统计 SM 至少有一个活动 warp 的周期数。
对于输出中的每一行,将有 15 个值(每个 SM 一个)。
nvprof --events active_cycles --aggregate-mode-off matrixMul.exe
======== NVPROF is profiling matrixMul.exe...
======== Command: matrixMul.exe
[Matrix Multiply Using CUDA] - Starting...
GPU Device 0: "GeForce GTX 480" with compute capability 2.0
MatrixA(320,320), MatrixB(640,320)
Computing result using CUDA Kernel...
done
Performance= 12.07 GFlop/s, Time= 10.860 msec, Size= 131072000 Ops, WorkgroupSize= 1024 threads/block
Checking computed result for correctness: OK
Note: For peak performance, please refer to the matrixMulCUBLAS example.
======== Profiling result:
Device Context Stream, Event Name, Kernel, Values
0 1 2, active_cycles, void matrixMulCUDA<int=32>(float*, float*, float*, int, int), 2001108 2001177 2000099 2002857 2152562 2153254 2001086 2153043 2001015 2001192 2000065 2154293 2000071 2000238 2154905
0 1 2, active_cycles, void matrixMulCUDA<int=32>(float*, float*, float*, int, int), 2155340 2002145 2155289 2002374 2003336 2002498 2001865 2155503 2156271 2156429 2002108 2002836 2002461 2002695 2002098