使用ncu和nsys cli的笔记,持续更新。
Nsight Compute
ncu主要是获取更细粒度的intra kernel的hardware counters。
ncu在profile的时候,通过--setction
来指定想使用的section。这里的section是指一组hardware counter的集合,可以通过nsightcompute/sections/
来看ncu自带的section有哪些,和ncu-ui中的details page的section含义一致。如果未指定section,则按照与默认的set
关联的section来收集hw coounters的信息。
--list-sets
列出如下列表,可以看到不同的set关联的不同的sections。
$ ncu --list-sets
---------- --------------------------------------------------------------------------- ------- -----------------
Identifier Sections Enabled Estimated Metrics
---------- --------------------------------------------------------------------------- ------- -----------------
default LaunchStats, Occupancy, SpeedOfLight yes 35
detailed ComputeWorkloadAnalysis, InstructionStats, LaunchStats, MemoryWorkloadAnaly no 157
sis, Occupancy, SchedulerStats, SourceCounters, SpeedOfLight, SpeedOfLight_
RooflineChart, WarpStateStats
full ComputeWorkloadAnalysis, InstructionStats, LaunchStats, MemoryWorkloadAnaly no 162
sis, MemoryWorkloadAnalysis_Chart, MemoryWorkloadAnalysis_Tables, Occupancy
, SchedulerStats, SourceCounters, SpeedOfLight, SpeedOfLight_RooflineChart,
WarpStateStats
source SourceCounters no 47
--query-metrics
可以查询并获得ncu支持的所有的hw counters,还有query-metrics-mode
可以设置是否展示suffix. 比如 dram__bytes
有 dram__bytes.avg
,dram__bytes.max
等等。
-c
profiler运行多少次。
--metrics
尽管ncu支持1400多个counters,但默认的set里仅包含一部分,可以通过这个参数添加自己想要的。可以使用regex
来利用正则表达式筛选想要的counters,比如--metrics regex:sm__inst_executed_pipe_*,regex:sm__sass_thread_inst_executed_op*
。如果需要\d
需要双斜杠\\d
。 ncu --list-metrics --query-metrics-mode all
获得所有的counters
--page
跟ncu-ui的page定义一致。如果只处理profiling出来的数据,raw几乎包含了所有的数值,details包含的是user-friendly 的展示数据。
-k
筛选要跑的kernel,支持正则表达式。
--kernel-name
可以指定你输入的kernel名字是function还是mangled的。
--clock-control=none
参考设置NVIDIA GPU的时钟频率
--log-file file
to save the ncu's output.
ncu --csv -k "^bpnn_adjust_weights_cuda$" --metrics sm__inst_executed_pipe_lsu.avg.pct_of_peak_sustained_active --page raw --set full ./backporp > report2.csv
report使用
从ncu 2020.3.1开始,有了绑定source code到report里的功能(--import-source
),可以在服务器端跑出report,然后copy到本地来用ncu-ui打开report查看。
ncu --target-processes all --export output.report --import-source=yes --metrics regex:sm__inst_executed_pipe_*,regex:sm__sass_thread_inst_executed_op* --page raw --set full ./backporp
拷贝生成的output.report到本地用ncu-ui打开。使用ncu --csv --page raw -i output.report.ncu-rep > output.csv
可以导出raw page的counters记录。
source code目前手动从ncu-ui里手动导出。
Nsight System
nsys主要是coarse-grained kernel之间,cpu-gpu之间的信息。
profile matrixmul程序,关注的api是trace模式下的cuda。
nsys profile -t cuda ./matrixMul
csv形式写出到a.*.csv,如果已经存在a.*.csv,强制覆盖。
nsys stats -f csv -o a.csv --force-overwrite ./report1.qdrep
输出简要的统计结果到终端,跟直接nvprof跑程序获得结果类似:
nsys profile --stats=true ./vectorAdd
或者直接从生成的qdrep文件中读取
nsys stats ./reports1.qrdep
Tips
elapsed 和 active是什么区别?https://forums.developer.nv...
简单来说当warp在等待memory access的时候,不算是active,active cycle不会统计这个,但是elapsed会统计。
ncu-ui
出现了error Could not load the Qt platform plugin "xcb" in "" even though it was found.
, 安装如下包解决
sudo apt-get install libxcb-xinput-dev
Reference
https://stackoverflow.com/questions/72042829/ncu-ui-wont-run-could-not-load-the-qt-platform-plugin-xcb-in-even-though/72286609#72286609
https://www.findhao.net/easycoding/2587.html
Comments