tune-incore

Optimizes PyPTO operator kernels through instruction-level tuning, L2 cache policies, and pipeline overlap.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? After swimlane analysis and graph-level tuning, PyPTO operators on Ascend NPU may still have individual tasks with excessive latency. This Skill guides in-kernel performance tuning by analyzing single-task instructions and operations to eliminate remaining bottlenecks. ## Core Features & Use Cases - Special Shape Handling: Reshape small or irregular matmul shapes (e.g., large M with tiny N) using Vector preprocessing, concat, and tile shape configuration. - L2 Cache Policy Tuning: Apply set_cache_policy with NONE_CACHEABLE to large read-once weight matrices, with guidance on batch setting for fused operators. - Pipeline & Memory Optimizations: Enable compute/data-movement overlap via submit_before_loop, fix non-contiguous operands, avoid tail-block zero padding with valid_shape, and optimize Gather/Scatter directions. - Use Case: A fused Pangu 7B layer operator stuck at 437us after prior tuning is reduced to 354us (-19.1%) by setting all five weight matrices to NONE_CACHEABLE, following the documented iteration and failure analysis. ## Quick Start Ask the assistant to perform in-kernel performance tuning on your PyPTO operator after swimlane analysis, providing the latest profiling data and the slow task details.

Frequently Asked Questions about tune-incore

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

FAQPage Schema
How do I optimize in-kernel performance of a PyPTO operator?

First complete swimlane analysis and graph-level tuning, then re-collect fresh profiling data with debug options. Analyze the slow task's instructions and apply targeted fixes: special shape preprocessing, L2 cache policies, redundant computation to break dependencies, and pipeline overlap via submit_before_loop.

How to optimize small shape matmul in PyPTO?

Use Vector operations to preprocess irregular shapes into standard ones, for example concatenating small right matrices into a larger diagonal block matrix before matmul. One documented case reduced a (884736,16)x(16,16) matmul from 500us to 40us.

When should I use set_cache_policy NONE_CACHEABLE in PyPTO?

Apply NONE_CACHEABLE to large weight matrices that are read only once, so they bypass L2 cache and free capacity for frequently accessed data. In fused operators, set all weights together; avoid it for small inputs and output tensors, and always verify with measurement.

Why did performance get worse after setting NONE_CACHEABLE on one weight?

Setting a single weight in a fused operator can unbalance L2 cache contention and slow other weight accesses. The documented fix is to set NONE_CACHEABLE on all large weights simultaneously, which released L2 capacity and achieved a 19.1% improvement.

What are the prerequisites before starting in-kernel tuning?

Swimlane analysis and graph-level tuning must be complete, precision validation must pass, and a slow task must be identified. You must also re-run tests with debug options to collect fresh swimlane data, since reusing old data leads to wrong conclusions.

How do I avoid zero-padding waste on tail blocks in PyPTO?

Use the valid_shape parameter in pypto.view to mark the actual data range of the last tile when it is smaller than BLOCK_SIZE. Only tail blocks need valid_shape; if the tail axis itself is too small, first enlarge it with concat, transpose, or reshape.