cuda性能分析工具: nsight systems

安装

1. 安装nsys, nsys可以用命令行生成性能分析报告,参考:

nsys profile

2. 安装Nsight Systems可视化工具NVIDIA Nsight Systems | NVIDIA 开发者

使用方法

1. 找一个可执行的cuda程序,编译成可执行文件,比如main,或者也可以运行python程序,运行的命令如下:

# c++ build main
nsys profile -o timeline --trace=cuda,nvtx,cudnn,cublas --force-overwrite true --stats=true ./main

# python demo
nsys profile -o timeline --trace=cuda,nvtx,cudnn,cublas --force-overwrite true --stats=true python test.py

参数含义介绍:

profile: 查看profile性能
-o timeline # 输出kernel的timeline信息
--trace=cuda,nvtx,cudnn,cublas # trace表示搜集哪些runtime的信息,比如cuda, cublas...,不写输出没有cuda的kernel信息

其他参数可以参考: User Guide — nsight-systems 2024.5 documentation

运行成功后会输出文件:

 Time (%)  Total Time (ns)  Num Calls    Avg (ns)    Med (ns)   Min (ns)   Max (ns)     StdDev (ns)            Name
 --------  ---------------  ---------  ------------  ---------  --------  -----------  -------------  ----------------------
     99.1      310,736,756          6  51,789,459.3    1,276.0       633  310,730,993  126,854,926.1  cudaEventCreate
      0.3        1,097,032          9     121,892.4    2,689.0     1,909      810,070      265,157.0  cudaMalloc
      0.3          908,213          9     100,912.6   11,392.0     3,266      644,211      208,300.2  cudaFree
      0.2          513,364          3     171,121.3  146,184.0   136,512      230,668       51,795.2  cudaLaunchKernel
      0.1          177,977          9      19,775.2   12,369.0     7,706       54,133       15,098.4  cudaMemcpy
      0.0           47,287          3      15,762.3    9,654.0     3,900       33,733       15,826.7  cudaDeviceSynchronize
      0.0           25,424          3       8,474.7    7,739.0     7,643       10,042        1,358.2  cudaEventSynchronize
      0.0           20,378          1      20,378.0   20,378.0    20,378       20,378            0.0  cuModuleGetLoadingMode
      0.0           16,582          6       2,763.7    2,344.5     2,234        4,543          894.5  cudaEventRecord

[5/7] Executing 'gpukernsum' stats report

 Time (%)  Total Time (ns)  Instances  Avg (ns)  Med (ns)  Min (ns)  Max (ns)  StdDev (ns)     GridXYZ         BlockXYZ                                    Name
 --------  ---------------  ---------  --------  --------  --------  --------  -----------  --------------  --------------  -------------------------------------------------------------------
     73.7           30,815          1  30,815.0  30,815.0    30,815    30,815          0.0     1    1    1    32   32    1  mm_cuda_naive(float *, float *, float *, int, int, int)
     14.4            6,016          1   6,016.0   6,016.0     6,016     6,016          0.0     2    2    1   256    1    1  mm_cuda_memory_coalescing(float *, float *, float *, int, int, int)
     11.9            4,960          1   4,960.0   4,960.0     4,960     4,960          0.0     2    2    1    16   16    1  mm_cuda_sub_shared_memory(float *, float *, float *, int, int, int)

[6/7] Executing 'gpumemtimesum' stats report

 Time (%)  Total Time (ns)  Count  Avg (ns)  Med (ns)  Min (ns)  Max (ns)  StdDev (ns)      Operation
 --------  ---------------  -----  --------  --------  --------  --------  -----------  ------------------
     65.0           14,017      6   2,336.2   2,368.0     2,112     2,593        182.4  [CUDA memcpy HtoD]
     35.0            7,553      3   2,517.7   2,625.0     2,240     2,688        242.5  [CUDA memcpy DtoH]

[7/7] Executing 'gpumemsizesum' stats report

 Total (MB)  Count  Avg (MB)  Med (MB)  Min (MB)  Max (MB)  StdDev (MB)      Operation
 ----------  -----  --------  --------  --------  --------  -----------  ------------------
      0.025      6     0.004     0.004     0.004     0.004        0.000  [CUDA memcpy HtoD]
      0.012      3     0.004     0.004     0.004     0.004        0.000  [CUDA memcpy DtoH]

Generated:
    /share/workspace/matmul/timeline.nsys-rep
    /share/workspace/matmul/timeline.sqlite

timeline.nsys-rep分析报告 

2. 打开Nsight System

选择File->Open找到timeline.nsys-rep(注意这个nsys-rep文件是通用的,比如可以在linux上生成,在mac上用nsight system打开)

可以在CUDA API里看到cudac的算子和占比,在下面stats system view的CUD GPU Kernel Summary里有具体分析。

如果只希望看一段区间的timeline怎么做

鼠标选择需要的区间->右键->选Filter and Recoder则只分析一段时间的信息

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值