Nsight Systems 和 Nsight Compute 有什么区别?
怎么判断 kernel 是 memory bound 还是 compute bound?
先弄清楚:每个概念是什么
- Nsight Systems(nsys)
- 整个程序的 timeline,上面有 CPU thread、CUDA API 调用、每个 kernel 和 memcpy。
- Nsight Compute(ncu)
- 只看一个 kernel,报它的硬件指标。常看 GPU Speed Of Light Throughput、Occupancy、Warp State Statistics 三节。
- Memory bound 和 compute bound
- memory bound 是 kernel 被 memory bandwidth 卡住,算力闲着。compute bound 反过来。
- Arithmetic intensity
- 每读写 1 byte 做几次 FLOP,低于 roofline 的 ridge point 就是 memory bound。
- Warp stall
- 一个 warp 这个 cycle 发不出指令。
看图:先找到 kernel,再看它卡在哪
30 秒回答
Nsight Systems shows the whole program as a timeline. I use it first to find where the time goes: one slow kernel, or gaps where the GPU sits idle. Then Nsight Compute profiles that kernel with hardware counters. If memory throughput is near peak and compute is low, it's memory bound, so I fuse kernels and cut reads and writes. If compute throughput is near peak, it's compute bound, so I use tensor cores or lower precision. If both are low, warps are stalled, so I check occupancy and stall reasons.
两个工具各看什么
| Nsight Systems(nsys) | Nsight Compute(ncu) | |
|---|---|---|
| 回答的问题 | 时间花在哪 | 这个 kernel 为什么慢 |
| 看什么 | GPU 空等、launch 间隙、memcpy、最耗时的 kernel | memory 和 compute throughput 占峰值多少、occupancy、warp stall 原因、roofline chart |
timeline 上 GPU 空白很多时问题不在 kernel 里,见训练慢怎么查。
怎么判断 bound,下一步做什么
| 类型 | 判断依据 | 下一步 |
|---|---|---|
| Memory bound | arithmetic intensity 低于 ridge point;memory throughput 接近峰值,compute 很低 | kernel fusion;少读写 HBM;向量化访存 |
| Compute bound | 高于 ridge point;compute throughput 接近峰值 | 用 tensor core;降精度 |
| 两个都低 | warp 在 stall,或 occupancy 太低 | 看 Warp State Statistics 和 Occupancy 两节 |
手算华为那道题,公式见 roofline。A100 的 ridge point 约 153 FLOP/B,0.5 远低于它,是 memory bound。上限是 0.5 × 2,039 GB/s ≈ 1.0 TFLOPS,只有峰值 312 TFLOPS 的 0.3%,加算力没有用。
必答点
- 先用 nsys 看整条 timeline,再用 ncu 看单个 kernel 的硬件指标
- memory throughput 接近峰值是 memory bound,做 fusion、少读写
- compute throughput 接近峰值是 compute bound,用 tensor core、降精度
- 两个都低就看 warp stall 和 occupancy
- 0.5 FLOP/B 远低于 ridge point,是 memory bound
追问
Nsight Systems 能看到指令级流水吗?
卓驭校招一面 2026-03-03 原题。不能,它的粒度是一次 API 调用或一个 kernel。指令级的统计在 ncu 的 Instruction Statistics 和 Source Counters 两节。
warp stall 有哪几类原因?
long scoreboard 在等 global 或 local memory 的数据,short scoreboard 多在等 shared memory,barrier 在同步点等别的 warp。
agent 为什么要用 Nsight,不用 torch.profiler?
FlashVector 说 torch.profiler 的 summary 太粗,agent 要精确的 kernel trace 和 tensor shape,做 roofline 分析时才少 hallucinate。profiler feedback 的收益见 kernel agent 设计。
最慢的 kernel 快了 2 倍,整体为什么只快一点?
占 timeline 60% 的 kernel 快 2 倍,整体只有 \(1/(0.4+0.3)\approx 1.43\) 倍(见 Amdahl's law 和 局部和端到端)。
来源Nsight Compute Profiling Guide(Sections and Rules 的各节名称,§2.4.7 的 stall 原因,§2.9 Roofline Charts)· Nsight Systems User Guide · FlashVector §4.2 · ml-八股 08 第 3 题 · 面经出处见 面试题与 JD 3.1、3.3 节