msprof-report-skill:基于 Claude Code 的华为昇腾 NPU 内核剖析技能项目

用户可借助此项目在华为昇腾 NPU 上使用 msprof 进行内核剖析,生成优化报告。它涵盖完整工作流,提供独立测试 harness、JSON 报告解析、多维度分析及诊断手册,含可复用脚本与编程参考。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago

msprof-report-skill

A Claude Code skill for profiling Ascend NPU kernels with msprof on 华为昇腾 (Ascend 910B / 910A / 310P). Covers the full workflow: build a standalone harness, run msprof, parse JSON reports, walk through six analysis dimensions, match patterns to a diagnosis playbook, and write an evidence-backed optimization report.

The skill is self-contained: reference docs, reusable helper scripts (harness template, report-analysis Python), and a companion Ascend programming reference.


What's in this repo

.
├── SKILL.md                          ← skill entry point (with YAML frontmatter)
├── README.md                         ← this file
├── PLAN.md                           ← project planning document
├── helpers/                          ← reusable code
│   ├── harness_template.cpp          ← standalone profiling harness template (ACL/Ascend C)
│   ├── analyze_reports.py            ← extract + compare key metrics from msprof output
│   ├── extract_stall_hotspots.py     ← per-operator stall aggregation
│   ├── plot_timeline.py              ← ASCII timeline plots (reveals tail effects)
│   ├── msprof_utils.py               ← shared Python helpers
│   └── README.md
├── reference/                        ← detailed reference docs
│   ├── 00-directory-layout.md        ← profile/ directory conventions (read first)
│   ├── 01-workflow.md                ← end-to-end profiling checklist
│   ├── 02-harness-guide.md           ← how to build a standalone profiling harness
│   ├── 03-collection.md              ← msprof command recipes
│   ├── 04-python-api.md              ← msprof JSON parsing patterns
│   ├── 05-analysis-dimensions.md     ← six analysis dimensions
│   ├── 06-diagnosis-playbook.md      ← pattern → cause → fix
│   ├── 07-report-template.md         ← final report structure
│   ├── 08-metric-names.md            ← Ascend NPU metric name reference
│   └── 09-common-issues.md           ← permissions, configuration, ACL issues, etc.
└── ascend-programming.md             ← companion reference: Ascend programming principles (optional)

Installation

Claude Code discovers skills in two locations:

  • ~/.claude/skills/<skill_name>/SKILL.md — user-level, available in every project
  • <repo>/.claude/skills/<skill_name>/SKILL.md — project-level, scoped to one repo

Three ways to install this skill:

Keeps the skill version-controlled and easy to update; edits in the clone are picked up instantly.

# Clone somewhere stable
git clone <repo_url> ~/workspace/msprof-report-skill

# User-level install: make the skill available in every project
mkdir -p ~/.claude/skills
ln -s ~/workspace/msprof-report-skill ~/.claude/skills/msprof-report-skill

# Or project-level install: scope to one repo
cd /path/to/other-repo
mkdir -p .claude/skills
ln -s ~/workspace/msprof-report-skill .claude/skills/msprof-report-skill

Pull updates with cd ~/workspace/msprof-report-skill && git pull. The symlinks pick up the new content automatically.

Option 2 — Copy into place

If you prefer a static copy over a symlink:

git clone <repo_url> /tmp/msprof
mkdir -p ~/.claude/skills
cp -r /tmp/msprof ~/.claude/skills/msprof-report-skill

Option 3 — Git submodule (for a project-level install committed alongside the repo)

cd /path/to/other-repo
git submodule add <repo_url> .claude/skills/msprof-report-skill
git commit -m "Add msprof-report-skill as a submodule"

How Claude uses this skill

Once installed at ~/.claude/skills/msprof-report-skill/ (or project-level), Claude Code will:

  1. Advertise the skill's name + description in the system reminder of new conversations.
  2. Let the user invoke it manually via /msprof-report-skill or let the model invoke it with the Skill tool when the conversation matches the description triggers.

When invoked, Claude reads SKILL.md, follows its workflow (phases 0 → 6 in reference/01-workflow.md), and uses the helper scripts in helpers/ as needed.


Running the helpers directly (no Claude needed)

The Python helpers work standalone for any msprof output you have:

# Make sure msprof output directory exists
export PROF_DIR=/path/to/your/profile/msprof_baseline

# Extract key metrics from msprof output
python3 ~/.claude/skills/msprof-report-skill/helpers/analyze_reports.py \
    --run-dir "$PROF_DIR/../" --tag baseline

# Per-operator stall hotspots (requires detailed profiling)
python3 ~/.claude/skills/msprof-report-skill/helpers/extract_stall_hotspots.py \
    --run-dir "$PROF_DIR/../" --tag baseline

# ASCII timeline plots
python3 ~/.claude/skills/msprof-report-skill/helpers/plot_timeline.py \
    --run-dir "$PROF_DIR/../" --tag baseline

The ACL harness template lives under helpers/; copy it into your profile run's harness/ directory and fill in the kernel body. See reference/02-harness-guide.md for details.


Requirements

  • CANN Toolkit with msprof CLI
  • Ascend NPU (910B / 910A / 310P or other supported models)
  • ACL runtime or Ascend C compiler (for harness builds)
  • Python 3.x (for parsing helpers)
  • An Ascend NPU with proper access permissions

The skill is optimized for Ascend 910B metric names, but the workflow and helpers work on any Ascend NPU msprof supports. Metric names may differ on different NPU models — see reference/08-metric-names.md for guidance.


Comparison with ncu-report-skill

This skill is modeled after ncu-report-skill for NVIDIA NCU profiling, adapted for Ascend NPU:

Aspect ncu-report-skill (NVIDIA) msprof-report-skill (Ascend)
Profiling tool ncu (Nsight Compute) msprof (MindStudio Profiler)
Output format .ncu-rep binary file JSON/CSV directory
Parse library ncu_report Python module Built-in json/csv modules
Compute unit SM (Streaming Multiprocessor) AICore
Matrix acceleration Tensor Core Cube
Vector computation CUDA Core Vector
On-chip cache Shared Memory Unified Buffer (UB)
Global memory Global Memory (GMEM) Global Memory (GM)
Communication NCCL HCCL

Ascend NPU Architecture Quick Reference

Ascend NPU 核心 AICore 包含三个计算单元:

Unit Function Best for
Cube Matrix multiply (MMA) MatMul, Attention, Conv
Vector Vector computation Element-wise, Activation
Scalar Control flow, scalar ops Control logic, indexing

Memory hierarchy:

  • Global Memory (GM): HBM/DDR — large capacity, high latency
  • Unified Buffer (UB): On-chip cache — fast, limited size
  • L2 Buffer: L2 cache — intermediate layer

License

MIT

Introduction

用户可借助此项目在华为昇腾 NPU 上使用 msprof 进行内核剖析,生成优化报告。它涵盖完整工作流,提供独立测试 harness、JSON 报告解析、多维度分析及诊断手册,含可复用脚本与编程参考。【此简介由AI生成】

Customize your domain