Nsight Compute

ncu主要是获取更细粒度的intra kernel的hardware counters。

cu在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的。

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
Pro Tips

简单来说当warp在等待memory access的时候,不算是active,active cycle不会统计这个,但是elapsed会统计。