关于 intel-vtune-amd-uprof
为 Agent 提供 Intel VTune 和 AMD uProf 的 CPU 微架构分析指导,涵盖热点、流水线停顿、内存访问与 Roofline 分析。适用于需要定位 CPU 性能瓶颈并优化代码的开发者。
主要功能
- 01热点与 CPU 时间分析
- 02微架构指标和流水线停顿诊断
- 03缓存、DRAM 带宽与 NUMA 分析
- 04线程和 I/O 性能分析
- 05Roofline 模型评估
适用场景
- 01找出 CPU 时间消耗最多的函数
- 02诊断代码中的流水线停顿
- 03检查内存带宽与缓存访问
- 04评估 HPC 代码的计算或内存限制
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mohitmishra786/ low-level-dev-skills --skill intel-vtune-amd-uprof安装后在 Claude Code 中输入/intel-vtune-amd-uprof确认已加载。
详细介绍
Intel VTune & AMD uProf
用途
指导 Agent 使用 Intel VTune Profiler(免费社区版)和 AMD uProf 进行 CPU 微架构性能分析:识别热点、分析微架构、优化内存访问模式、诊断流水线停顿,以及分析 Roofline 模型。
触发条件
- “如何使用 Intel VTune 分析我的代码?”
- “什么是流水线停顿?如何减少停顿?”
- “如何使用 VTune 分析内存带宽?”
- “什么是 Roofline 模型?如何使用它?”
- “如何使用 AMD uProf 作为 VTune 的免费替代方案?”
- “我的代码缓存命中率很高,但运行仍然很慢”
工作流
1. 设置 VTune(免费社区版)
# Download Intel VTune Profiler (Community Edition — free)
# https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler.html
# Install on Linux
source /opt/intel/oneapi/vtune/latest/env/vars.sh
# CLI usage
vtune -collect hotspots ./prog
vtune -collect microarchitecture-exploration ./prog
vtune -collect memory-access ./prog
# View results in GUI
vtune-gui &
# File → Open Result → select .vtune directory
# Or use amplxe-cl (legacy CLI)
amplxe-cl -collect hotspots ./prog
amplxe-cl -report hotspots -r result/
2. 分析类型
| 分析 | 可发现的问题 | 适用场景 |
|---|---|---|
| 热点分析 | CPU 密集型函数 | 第一步——找出时间花在哪里 |
| 微架构探索 | IPC、流水线停顿、退役指令 | 找到热点后——分析热点为何运行缓慢 |
| 内存访问 | 缓存未命中、DRAM 带宽、NUMA | 内存密集型代码 |
| 线程分析 | 锁竞争、并行效率 | 多线程代码 |
| HPC 性能分析 | 向量化、内存、Roofline | HPC/科学计算代码 |
| I/O 分析 | 磁盘和网络瓶颈 | I/O 密集型代码 |
3. 热点分析
# Collect and report hotspots
vtune -collect hotspots -result-dir hotspots_result ./prog
# Report top functions by CPU time
vtune -report hotspots -r hotspots_result -format csv | head -20
# CLI output example:
# Function CPU Time Module
# compute_fft 4.532s libfft.so
# matrix_mult 2.108s prog
# parse_input 0.234s prog
使用调试信息构建,以便获得有意义的符号:
gcc -O2 -g ./prog.c -o prog # symbols visible in VTune
gcc -O2 -g -gsplit-dwarf -fno-omit-frame-pointer ./prog.c -o prog # better stacks
4. 微架构探索——流水线停顿
vtune -collect microarchitecture-exploration -r micro_result ./prog
vtune -report summary -r micro_result
需要检查的关键指标:
| 指标 | 含义 | 良好值 |
|---|---|---|
| IPC(每时钟周期指令数) | 每个周期退役的指令数 | x86:目标为 > 2.0 |
| CPI(每条指令的时钟周期数) | IPC 的倒数 | 越低越好 |
| 错误推测 | 分支预测错误 | < 5% |
| 前端受限 | 指令解码瓶颈 | < 15% |
| 后端受限 | 执行单元或内存停顿 | < 30% |
| 退役 | 有效工作所占比例 | 理想值 > 70% |
| 内存受限 | 等待内存的周期百分比 | < 20% |
Pipeline Analysis (Top-Down Methodology):
├── Retiring (good, useful work)
├── Bad Speculation (branch mispredictions)
├── Front-End Bound
│ ├── Fetch Latency (I-cache misses, branch mispredicts)
│ └── Fetch Bandwidth
└── Back-End Bound
├── Memory Bound
│ ├── L1 Bound → L1 cache misses
│ ├── L2 Bound → L2 cache misses
│ ├── L3 Bound → L3 cache misses
│ └── DRAM Bound → main memory bandwidth limited
└── Core Bound → ALU/compute bound
5. 内存访问分析
# Collect memory access profile
vtune -collect memory-access -r mem_result ./prog
# Key output sections:
# - Memory Bound: % time waiting for memory
# - LLC (Last Level Cache) Miss Rate
# - DRAM Bandwidth: GB/s achieved vs theoretical peak
# - NUMA: cross-socket accesses (for multi-socket systems)
查看 DRAM 带宽:
DRAM Bandwidth: 18.4 GB/s
Peak Theoretical: 51.2 GB/s
Utilization: 36% — likely not DRAM-bound
如果受 DRAM 带宽限制:优化数据布局(AoS → SoA)、缩小工作集、改善空间局部性。
6. AMD uProf——AMD CPU 的免费替代方案
# Download AMD uProf
# https://www.amd.com/en/developer/uprof.html
# CLI profiling
AMDuProfCLI collect --config tbp ./prog # time-based profiling
AMDuProfCLI collect --config assess ./prog # microarchitecture assessment
AMDuProfCLI collect --config memory ./prog # memory access
# Generate report
AMDuProfCLI report -i /tmp/uprof_result/ -o report.html
# Open GUI
AMDuProf &
AMD uProf 指标与 VTune 指标的对应关系:
Retired Instructions→ IPC 分析Branch Mispredictions→ 错误推测L1/L2/L3 Cache Misses→ 内存受限级别Data Cache Accesses→ 缓存效率
7. Roofline 模型
Roofline 模型通过将实际性能与硬件上限进行比较,展示代码是受计算能力还是内存带宽限制:
Performance (GFLOPS/s)
| _______________
Peak | /
Perf | / compute bound
| /
| /
| / memory bandwidth bound
| /
+------------------------------→
Arithmetic Intensity (FLOPS/Byte)
# VTune roofline collection
vtune -collect hpc-performance -r roofline_result ./prog
# Then: VTune GUI → Roofline view
# For manual calculation:
# Arithmetic Intensity = FLOPS / memory_bytes_accessed
# Peak FLOPS = CPUs × cores × freq × FLOPS_per_cycle_per_core
# Peak BW = from hardware spec (e.g., 51.2 GB/s for DDR4-3200 dual channel)
# likwid-perfctr for manual roofline data (Linux)
likwid-perfctr -C 0 -g FLOPS_DP ./prog # double-precision FLOPS
likwid-perfctr -C 0 -g MEM ./prog # memory bandwidth
相关技能
- 使用
skills/profilers/hardware-counters,通过 perf stat 收集原始 PMU 事件 - 使用
skills/profilers/linux-perf,在 Linux 上通过 perf 进行性能分析 - 使用
skills/low-level-programming/cpu-cache-opt,优化内存访问模式 - 使用
skills/low-level-programming/simd-intrinsics,通过向量化提高 FLOPS
评论
支持 Markdown