triton-latency-optimizer

Optimizes Triton kernel latency on Ascend NPU through sequential single-point optimization passes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, triton, and includes references (resource) and scripts (resource) components.

What problem does it solve? Triton kernels running on Ascend NPU hardware often underperform due to suboptimal tiling, scalar degradation, discrete memory access, and missing autotune configurations. This Skill applies a disciplined, ordered scan of 33 documented optimization points to reduce kernel latency while guaranteeing functional and numerical consistency with the original code. ## Core Features & Use Cases - Ordered Optimization Scan: Loads an index of 33 optimization points (constexpr parameterization, tiling, core partitioning, scalar-to-vector conversion, CV fusion, FlashAttention/MLA specialization, autotune, block size scaling) and applies the first matching point per invocation. - Consistency Guarantees: Enforces a code checklist before any verification, requiring functional equivalence and no precision regression between original and optimized kernels. - IR-Based Analysis: Extracts final-stage MLIR (last_pass.mlir) via bishengir-compile to drive multi-round IR-guided optimization suggestions. - Use Case: Given a slow Triton-Ascend kernel for a matmul or pooling operator, invoke this Skill repeatedly from an outer loop; each call applies one optimization, writes the improved code to the output path, and reports which optimization point was hit. ## Quick Start Optimize my Triton kernel at kernels/bmm.py on Ascend NPU and write the improved version to output/bmm_opt.py, applying one optimization point per call.

Frequently Asked Questions about triton-latency-optimizer

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

FAQPage Schema
How do I optimize Triton kernel performance on Ascend NPU?

Provide the kernel file path and an output path; the Skill scans 33 ordered optimization points, applies the first matching one, and writes improved code. The calling loop handles verification, benchmarking, and rollback between iterations.

What optimization techniques does Triton Ascend kernel tuning support?

Supported techniques include constexpr parameter staticization, tiling optimization, core partitioning, scalar-to-vector conversion, discrete memory access fixes, kernel splitting, CV fusion pipelining, autotune configuration, and block size scaling.

Does Triton autotune work on Ascend NPU hardware?

Yes, Triton-Ascend supports autotune for block sizes and the multibuffer compile option, but not num_warps or num_stages due to NPU architecture differences. Automatic, hint-based, and custom Config modes are available.

Why does my Triton kernel produce wrong results after optimization?

A common cause is relying on implicit mask behavior in tl.load with tl.where on Ascend, or padding pollution when BLOCK_SIZE exceeds the tiled dimension. The Skill's checklist enforces explicit mask AND conditions and BLOCK_SIZE bounds before verification.

Can this optimize FlashAttention or MLA kernels on Ascend?

Yes, dedicated optimization points cover FlashAttention-style kernels (online softmax, KV loop compression) and MLA paged attention (BLOCK_QO=1 affine store fix, P_SPLIT precision compensation), with specialized reference documents for each.

What are the limitations of single-call Triton optimization?

Each invocation applies exactly one optimization point and performs no verification or benchmarking itself; the external caller must manage the iteration loop, accuracy checks, performance measurement, and rollback of regressing changes.