NVIDIA Profiling Tools

前言:目前在用的监控GPU的工具有很多,比较常用的有nvprof、nvvp和Nsight。对这三种工具的使用不是很熟练,尚在学习当中。下面针对前两种自己的使用情况进行记录,如有理解错误,请指出。

NVprof

Nvprof 是一款用以监控GPU和CPU的运行状态的工具。可以采集程序的运行热点,运行时间线,并进行任务以来分析和kenel函数调度分析等。

环境配置
注:1) 版本很重要。之前安装的cuda是9.1版本,怎么调试都没有监控结果,且nvprof的出错信息太简洁了,只显示No Profiling Result,没有具体的出错原因,来回折腾了许久,在同学的帮助下才得以解决,切换成了cuda 10的版本。
2) 在物理机监控容器中运行的python脚本时,需要注意在创建container时需要设置权限:privileged=true,否则容器没有查看物理机GPU硬件层运行状态的权限,同样会导致监控的结果没有任何信息。
3)使用root账户运行监控

1)安装cuda
下载安装文件,官网下载安装包(推荐10.0+)https://developer.nvidia.com/cuda-toolkit-archive

手动安装cuda

检查是否安装成功:

nvcc --version

在这里插入图片描述

nvprof -V

在这里插入图片描述

2)监控数据采集
首先准备一个需要采集trace数据的应用,该应用最好有以下特点(官方提供):
1)The application is a test harness that contains a CUDA implementation of all or part of your algorithm. The test harness initializes the data, invokes the CUDA functions to perform the algorithm, and then checks the results for correctness. Using a test harness is a common and productive way to quickly iterate and test algorithm changes. When profiling, you want to collect profile data for the CUDA functions implementing the algorithm, but not for the test harness code that initializes the data or checks the results.
2)The application operates in phases, where a different set of algorithms is active in each phase. When the performance of each phase of the application can be optimized independently of the others, you want to profile each phase separately to focus your optimization efforts.
3)The application contains algorithms that operate over a large number of iterations, but the performance of the algorithm does not vary significantly across those iterations. In this case you can collect profile data from a subset of the iterations.

也就是说,该程序需要包含CUDA算法实现,包含大量迭代,一般的深度学习模型均可以采用该工具进行trace跟踪。

3)命令
nvprof -h #查看nvprof的相关参数及参数解释
在这里插入图片描述
监控某一个应用程序(train.py),该命令可直接在控制台输出profiling的结果

nvprof python3 train.py

在这里插入图片描述
将结果输出到nvvp文件,改文件格式可以用可视化工具打开并查看

nvprof -o train.nvvp python3 train.py

将结果输出到csv文件

nvprof --csv --log-file output.csv python3 train.py

输出所有支持的metrics

nvprof --metrics all --csv --log-file  output.csv python3 train.py

输出所有支持的events

nvprof --metrics all --csv --log-file  output.csv python3 train.py

指定事件监控:

nvprof --metrics achieved_occupancy,gld_throughput,gst_throughput,gld_efficiency,gst_efficiency,gld_transactions,gst_transactions,gld_transactions_per_request,gst_transactions_per_request ./coalescing

可查看占用率,内存读取带宽,内存存储带宽,内存事物(transations)效率,内存事物数。
./coalescing是当前目录下要分析的程序

可以看shared,和texture的情况:

nvprof --metrics achieved_occupancy,gld_throughput,gst_throughput,gld_efficiency,gst_efficiency,gld_transactions,gst_transactions,gld_transactions_per_request,gst_transactions_per_request,branch_efficiency,shared_store_transactions_per_request,tex_cache_hit_rate,tex_cache_transactions

可视化工具NVVP

NVVP是可以对Nvprof的trace结果.nvvp文件记性图形化展示,也可以直接连接物理机运行你的应用程序,对特定模块进行可视化分析,该工具可以导出PDF形式的分析结果。
1.安装nvvp

 sudo apt install nvidia-visual-profiler

测试

nvvp

会弹出可视化界面可供操作:
在这里插入图片描述

2.运行程序train.py
输入命令nvvp
File->New Session
在这里插入图片描述
之后可直接Next运行就可以了。

后续持续更新。。。

欢迎关注我们的公众号
在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值