OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add ascend/agent-skills --skill triton-operator-performance-optim
优化 Ascend NPU 亲和的 Triton 算子性能。解决 UB 溢出、提高 Cube 利用率、Tiling 策略设计。关键词:性能优化、performance optimization、tiling、UB。
npx skills add ascend/agent-skills --skill triton-operator-performance-optim
性能比定义:Ratio = torch_npu 耗时 / Triton 耗时(耗时倒数)。Ratio > 1.0 表示 Triton 更快。
优先级:正确性 > 泛化性 > 性能。
优化前先审视算法本身。低效算法再优化也有先天不足。
time.time() 测端到端(覆盖小/中/大),达标则完成msprof 测 kernel 侧耗时,定位真正瓶颈| 瓶颈 | 优化重点 |
|---|---|
| Memory-Bound | 向量化访存、UB 缓存复用、算子融合 |
| Compute-Bound | Cube 适配、Block 尺寸调优 |
| Latency-Bound | 增大并行度、减少同步 |
基础四板斧(按顺序):Block/Grid Size → 连续访存 → UB 复用 → 编译时常量
加载:optimization-patterns.md, ascend-terminology.md
tl.parallel(bind_sub_block=True) 分配到 2 个 vector cores加载:triton-ascend-api.md, tiling-strategies.md, triton-api-reference.md
算子融合、Double Buffer(tl.multibuffer(tensor, 2) 或 tl.compile_hint(tensor, "multi_buffer", 2))
精度 + 泛化性 + 性能 + 端到端回归
tensor.item()(触发 CPU-NPU 同步)| msprof 指标 | 瓶颈 | 典型优化 |
|---|---|---|
| aiv_scalar > 80% | Scalar Bound | 检查双 pass / 逐行循环+tl.where 累加,改单 pass |
| aiv_mte2 > 50% | Memory Bound | 连续访存、expand+contiguous、增大 BLOCK |
| aiv_vec > 50% | Compute Bound | 算法优化、减少冗余计算 |
| aic_cube_ratio < 50% | Cube 利用率低 | 检查对齐(512B/元素大小)、BLOCK 是否 16 倍数、用 compile_hint('dot_pad_only_k') |