tune-frontend

Optimizes PyPTO operator frontend code through loop, reshape, and TileShape analysis.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? PyPTO operators on Ascend NPU often ship with suboptimal out-of-box performance due to inefficient loop structures, redundant reshapes, and mismatched TileShape configurations. This Skill provides a disciplined three-phase workflow to diagnose and fix code-level performance issues before deeper pipeline tuning. ## Core Features & Use Cases - Three-Phase Tuning Workflow: Enforces Phase A global analysis (loop structure, constant dependencies, reshape audit, TileShape review), Phase B local data-operation analysis (NZ format, transpose fusion, concat-to-assemble, broadcast combine), and Phase C item-by-item optimization with verification. - Structured Analysis Tables: Produces mandatory artifacts such as loop structure tables, reshape analysis tables, and basic-block TileShape boundary reviews so no optimization is applied without evidence. - Concrete Optimization Catalog: Covers loop unroll/tiling, reshape hoisting with inplace, per-matmul cube TileShape settings, vector TileShape rules, and combine_axis broadcast inlining, backed by real case studies with measured gains. - Use Case: Given a decode attention or matmul-based PyPTO kernel with poor initial latency, run the three-phase analysis to identify that a unified cube TileShape wastes L1 space, then set per-matmul tiles to cut execution time by 7.8%. ## Quick Start Analyze my PyPTO operator kernel code with the frontend tuning workflow and produce the Phase A loop structure and TileShape review tables before suggesting optimizations.

Frequently Asked Questions about tune-frontend

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

FAQPage Schema
How do I tune PyPTO operator performance at the code level?

Follow the three-phase workflow: Phase A analyzes loop structure, constants, reshapes, and TileShapes globally; Phase B reviews data operations like transpose, concat, and broadcast; Phase C applies one optimization at a time with precision and performance verification.

How to optimize loop structure in PyPTO kernels?

Use Python for loops on static axes and pypto.loop with tiling on large dynamic axes. Apply loop_unroll only on the innermost loop, merge independent loops over the same axis, and tile outer axes to increase task granularity and parallelism.

How do I set cube and vector TileShapes in PyPTO?

Set cube TileShapes independently before each matmul, keeping L1 within actual axis lengths and L0 16-element aligned. Vector tiles should keep data blocks between 16 and 64KB, fill the tail axis, and never split reduction axes.

When should reshape be hoisted out of PyPTO loops?

Hoist reshapes of original input tensors to the kernel entry using inplace=True, especially when loop bodies contain 3D or 4D computations. Delete redundant reshapes where source and target shapes are identical, and replace squeeze/unsqueeze with inplace reshape.

Does combine_axis optimization help Cube-heavy PyPTO operators?

No, combine_axis=True mainly benefits vector-dense operators where tail-axis-1 broadcasts run in hot inner loops. For Cube-dominated kernels where matmul takes over 80% of time, the measured gain is within noise.

Why does PyPTO compilation fail after changing vec_tile_shapes?

Failures occur when tile data exceeds UB capacity or the reduction axis tail is not 32-byte aligned. Reduce the first tile dimension so total bytes stay under roughly 128KB, and set the reduction axis tile to its full aligned length.