Skip to content
Agentmart
Submit a tool

ascendc-operator-performance-optim

排查并优化 Ascend C 算子性能。当用户开发、审查或优化 Ascend C kernel 算子时使用,或当用户提及 Ascend C 性能优化、算子优化、tiling、流水、搬运、 内存优化、NPU/昇腾等关键词时触发。

Skill by Ascend

IndexedMulanPSL-2.0★ 52
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/ascend-ascendc-operator-performance-optim

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

排查并优化 Ascend C 算子性能。当用户开发、审查或优化 Ascend C kernel 算子时使用,或当用户提及 Ascend C 性能优化、算子优化、tiling、流水、搬运、 内存优化、NPU/昇腾等关键词时触发。

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/ascendc-operator-performance-optim

What's inside

Skill name
ascendc-operator-performance-optim
Description
排查并优化 Ascend C 算子性能。当用户开发、审查或优化 Ascend C kernel 算子时使用,或当用户提及 Ascend C 性能优化、算子优化、tiling、流水、搬运、 内存优化、NPU/昇腾等关键词时触发。
License
MulanPSL-2.0
Instructions
438 lines in SKILL.md · view on GitHub

Files (6)

  • SKILL.md
  • api-usage-prof.md · references/
  • data-copy-prof.md · references/
  • memory-prof.md · references/
  • pipeline-prof.md · references/
  • tiling-prof.md · references/

SKILL.md (first lines)

# Ascend C 算子性能优化(排查 → 修改 → 验证 闭环) 

本 skill 不仅排查性能问题,还负责 **修改代码并验证优化效果**。完整流程为:

```
Phase 1: 排查 — 审查代码 + 学习设计文档,发现优化点
Phase 2: 基线 — 保存当前性能测试结果(自定义算子 vs 标杆)
Phase 3: 优化 — 学习 code-gen 知识后修改算子代码
Phase 4: 精度 — 精度验证(确保优化后功能正确)
Phase 5: 性能 — 同 case 性能对比(优化后 vs 标杆)
Phase 6: 迭代 — 未提升则继续优化,最多 3 轮
```

---

## Phase 1: 排查 — 发现优化点

### 1.1 学习算子设计文档

**MANDATORY — 排查前必须先理解算子设计**:

1. 读取 `ascend-kernel/csrc/ops/<op_name>/design.md`(若存在),提取:
   - 算子类型(elementwise / 行处理 / Cube)
   - Tiling 策略(核间切分 / 核内切分)
   - UB 空间分配方案
   - 计算逻辑与数据流
2. 读取 `op_host/<op_name>.cpp` 和 `op_kernel/<op_name>.cpp` 全部源码

### 1.2 逐阶段排查

按以下顺序逐阶段审查算子代码。对每个阶段,加载对应的 reference 文件,逐项
对照代码检查。

```
- [ ] 1. Tiling    — 数据在多核与 L2Cache 间的切分策略
- [ ] 2. 搬运      — DataCopy 的带宽利用率
- [ ] 3. API 使用  — Ascend C API 的高效用法
- [ ] 4. 内存      — 数据在存储层级中的放置策略
- [ ] 5. 流水      — CopyIn / Compute / CopyOut 的重叠执行
```

每个阶段有独立的 reference 文件,排查时**仅加载当前阶段**的文件:

- 阶段 1:[references/tiling-prof.md](references/tiling-prof.md)
- 阶段 2:[references/data-copy-prof.md](references/data-copy-prof.md)
- 阶段 3:[references/api-usage-prof.md](references/api-usage-prof.md)
- 阶段 4:[references/memory-prof.md](references/memory-prof.md)
- 阶段 5:[references/pipeline-prof.md](references/pipeline-prof.md)

#### 1. Tiling

> 详细示例:[references/tiling-prof.md](references/tiling-prof.md)

排查项:

- [ ] **1.1 多核切分**:`blockDim` 是否设为硬件核数?
  - 耦合架构:`GetCoreNumAiv()` 或 `GetCoreNumAic()`
  - 分离架构 Vector 算子:AIV 核数(如 40)
  - 分离架构 Cube 算子:AIC 核数(如 20)
  - 分离架构 MIX 算子:物理核组数(如 20 = 40 AIV / 2),不可超过物理核数
- [ ] **1.2 L2Cache 切分**:当 `输入 + 输出 > L2Cache 容量` 时,是否将数据
  按 L2Cache 大小分块,所有核协同处理同一块后再切换下一块?
- [ ] **1.3 核间负载均衡**:L2Cache 切分后,尾块是否在各 pass 间交替分配,
  避免固定某些核始终拖尾?

#### 2. 搬运

> 详细示例:[references/data-copy-prof.md](references/data-copy-prof.md)

排查项:

- [ ] **2.1 单次搬运量 >= 16 KB**:每次 `DataCopy` 是否搬运至少 16 KB?
  小于此值带宽利用率显著下降。
- [ ] **2.2 GM 地址 512B 对齐**:GM 起始地址是否 512 字节对齐?
  (Atlas A2 系列上,32B 对齐比 512B 对齐带宽最多低 30%。)
- [ ] **2.3 stride 参数代替 for 循环**:间隔搬运是否使用 `DataCopyParams`
  (blockCount/blockLen/srcStride/dstStride)一次下发,而非用 for 循环逐行搬运?

#### 3. API 使用

> 详细示例:[references/api-usage-prof.md](references/api-usage-prof.md)

排查项:

- [ ] **3.1 TPipe 在 kernel 类外创建**:`TPipe` 是否在 kernel 入口函数中创建
  并以指针传入类?(类内 TPipe 会阻止 Scalar 常量折叠,增加约 17% scalar_time。)
- [ ] **3.2 纯搬运算子使用 TQueBind**:无 Vector 计算的算子是否用
  `TQueBind<VECIN, VECOUT>` 替代了分离的 `TQue<VECIN>` + `TQue<VECOUT>`?
  (消除冗余的 LocalTensor 间 DataCopy,`aiv_vec_time` 降至约 0。)
- [ ] **3.3 Counter 模式(SetMaskCount)**:Vector 指令是否使用 Counter 模式,
  而非 Normal 模式手动计算主块/尾块 mask?
- [ ] **3.4 Matmul AtomicAdd**:Matmul 结果 C 需要与 GM 矩阵 D 相加时,
  是否在 `IterateAll`/`GetTensorC` 中设置 `enAtomic=1` 融合累加?
  (可减少约 12% cycle。)
- [ ] **3.5 归约指令组合**:连续 buffer 归约到标量时,是否使用
  `BlockReduceSum` + `WholeReduceSum` 组合,而非多次相同归约指令?

#### 4. 内存

> 详细示例:[references/memory-prof.md](references/memory-prof.md)

排查项:

- [ ] **4.1 UB Buffer 融合**:连续 Vector 运算(如 Exp → Abs)的中间结果
  是否留在 UB 内,而非经 GM 往返?
- [ ] **4.2 L0C 累加矩阵乘**:`A1*B1 + A2*B2 + ...` 场景下,Mmad 结果是否
  在 CO1(L0C)中原地累加,而非逐次写 GM 再在 UB 求和?
- [ ] **4.3 小矩阵长驻 L1**:当 L1 无法同时容纳左右矩阵时,较小矩阵是否
  一次加载后常驻 L1,仅循环搬运较大矩阵?
- [ ] **4.4 BT Buffer 存放 bias**(分离架构):bias 是否存入 BT Buffer(C2)
  并通过 `Mmad` 一步融合,而非在 UB 中单独做 Add?
- [ ] **4.5 FP Buffer 存放量化参数**(分离架构):量化参数是否存入
  FP Buffer(C2PIPE2GM)并通过 `Fixpipe` 随路量化,而非在 UB 中单独计算?

#### 5. 流水

> 详细示例:[references/pipeline-prof.md](references/pipeline-prof.md)

排查项:

From Ascend/agent-skills, MulanPSL-2.0.

More from Ascend/agent-skills

Signals

Stars
52
Forks
3
Open issues
2
Last commit (this folder)
May 7, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MulanPSL-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Ascend

Cite this page

ascendc-operator-performance-optim skill. Agent Mart. https://agentmart.dev/skills/ascend-ascendc-operator-performance-optim (last updated 2026-10-24)