code-performance-advisor

Diagnose AscendC kernel performance bottlenecks from msprof profiling data and generate optimization suggestions.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill code-performance-advisor-wangwindow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-performance-advisor
Source: https://github.com/WangWindow/CANN-BatchMatMulMaxsum/tree/main/.agents/skills/code-performance-advisor
Command: npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill code-performance-advisor-wangwindow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? AscendC kernel developers on Ascend NPU hardware often pass correctness tests but miss performance targets, and manually interpreting msprof profiling CSVs to find bottlenecks is slow and error-prone. This Skill turns profiling data and operator code into concrete, evidence-backed optimization actions through a structured state-machine workflow. ## Core Features & Use Cases - Rule-first diagnosis with LLM fallback: Matches operator feature tags against an indexed library of expert optimization rules; when rule confidence is low, routes to deep pipeline analysis or algorithmic redesign subskills. - Closed-loop optimization workflow: Orchestrates INIT → TAG → SCORE → ROUTE → SUGGEST → APPLY → BUILD → EVALUATE → COMPARE → UPDATE phases with session isolation, resumable state, and automatic baseline comparison. - Knowledge capture: Verified optimizations are固化 back into the rule library via the rule_update subskill, so successful patterns become reusable. - Use Case: An operator like fused_adamw runs at 0.65x of the PyTorch baseline. Initialize the workspace from CAKE2 output, run the workflow, and receive ranked suggestions (tiling load balance, double buffering, UB fusion) that raise it to 2.48x with profiling-verified evidence. ## Quick Start Ask the assistant to run the code-performance-advisor workflow for your operator after initializing its workspace with init_workspace.py, for example: optimize the fastgelu operator using its latest profiling data.

Frequently Asked Questions about code-performance-advisor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize an AscendC operator that is slower than the PyTorch baseline?

Initialize the workspace with init_workspace.py to copy the operator code and latest profiling CSV, then run workflow.py in interactive mode. The state machine tags the code, scores expert rules, and routes to suggestion, deep research, or algorithm redesign subskills based on confidence.

What profiling data does AscendC kernel performance analysis need?

The workflow expects an op_summary CSV produced by msprof, placed under workspace/inputs/<op>/profiling/. Metrics such as aiv_scalar_ratio, aiv_vec_ratio, and mte bandwidth ratios drive bottleneck detection; without profiling data, symptom tags are unreliable.

How does the rule matching and routing logic work?

Generated code tags are scored against the rule index. A max score of 0.7 or higher takes the Fast path with direct rule-based suggestions, 0.3 to 0.7 triggers deep research, below 0.3 triggers pipeline-level diagnosis, and persistently high scalar ratio after iterations triggers algorithm redesign.

Can I resume an interrupted optimization session?

Yes. Run workflow.py resume with the operator name or a specific session ID. Each session is isolated under workspace/sessions with its own working code, baseline snapshot, and workflow state file, so concurrent optimizations of multiple operators do not conflict.

Why did my measured speedup differ between baseline and optimized runs?

A known issue is mixing evaluation modes: basic MsprofProfiler runs warmup outside the profiling window while advanced mode clears HBM and L2 cache per iteration, making results non-comparable. Use the same evaluation flags for baseline and optimized runs, and rely on median values rather than minimum.

When should I use algorithm redesign instead of rule-based suggestions?

Use it only after at least one apply-evaluate cycle when rule scores stay below 0.40 and scalar ratio remains above threshold, indicating the bottleneck is structural. Every proposed reformulation must be classified as exact, within-tolerance, approximate, or monotone-only with quantified error bounds before code changes.