CUDA 知识点:性能分析 | CUDA

调试 CUDA 程序性能常用的性能分析工具:NSight System、PyTorch Profiler 和 NSight Compute。

NSight System

使用如下代码将想要测试的代码段包起来(以 python 为例):

1
2
3
torch.cuda.profiler.start()
# your test code
torch.cuda.profiler.stop()

然后使用如下命令运行代码:

1
nsys profile --capture-range=cudaProfilerApi --output profile/res --force-overwrite true python3 main.py

PyTorch Profiler

使用如下代码将想要测试的代码段包起来:

1
with torch.profiler.profile(on_trace_ready=torch.profiler.tensorboard_trace_handler("./log"), record_shapes=True, with_stack=True):

然后正常运行代码即可,trace 文件会保存在 ./log 文件夹中,使用 https://ui.perfetto.dev 即可可视化查看。

NSight Compute

除去查看 kernel 整体的运行,可能还需要查看单个 kernel 内部的运行情况,这个时候就需要 Nsight Compute,它可以输出每个 kernel 的 SASS 汇编,运行时间等更为细粒度的内容。

CUDA 知识点:性能分析 | CUDA

http://www.zh0ngtian.tech/posts/f66cc6ee.html

作者

zhongtian

发布于

2021-01-28

更新于

2025-05-23

许可协议

评论