triton-op-coding

Generates and iteratively fixes Triton Ascend NPU kernel code from operator task descriptions.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing high-performance Triton kernels for Ascend NPU hardware requires deep knowledge of Ascend-specific APIs, memory alignment rules, core configuration, and strict constraints (no PyTorch fallback in forward, no GPU-only tuning parameters). This Skill turns an operator task description into a complete, runnable Triton Ascend kernel implementation and supports iterative repair based on verifier errors. ## Core Features & Use Cases - Pure Triton Ascend code generation: Produces a complete Python file with @triton.jit kernels and a ModelNew(nn.Module) class whose forward() only allocates buffers, queries metadata, and launches kernels—never falling back to PyTorch compute. - Four generation modes: First-time generation from task descriptions, targeted code modification, iterative repair driven by verifier_error and conductor_suggestion, and architecture correction when a design sketch conflicts with validated Layer 1 constraints. - Operator-type knowledge routing: Loads dedicated reference guides for elementwise, matmul, reduce, attention/flash-attention, sort/select, interpolate, and layout-transform operators, plus NPU hardware specs. - Use Case: Given a softmax operator task file for Ascend A2, generate a ModelNew class with a numerically stable softmax kernel using tl.load/tl.store, proper masking, and VEC core grid configuration, then fix it across verification rounds until it passes. ## Quick Start Ask the assistant to generate Triton Ascend kernel code for your operator by providing the operator name, task description file content, and target architecture such as A2.

Frequently Asked Questions about triton-op-coding

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

FAQPage Schema
How do I generate a Triton Ascend kernel for an NPU operator?

Provide the operator name, the task description containing the reference Model class, and the target architecture such as A2. The Skill loads operator-type-specific references and outputs a complete Python file with @triton.jit kernels and a ModelNew class matching the original Model's interface.

Can I reuse GPU Triton kernel code on Ascend NPU?

GPU Triton kernels can only serve as structural references for signatures, grid patterns, and data flow. GPU-specific parameters like num_warps, num_stages, and num_ctas have no effect on NPU and must be removed in favor of Ascend configurations such as num_cores.

Why does my generated kernel fail verification with wrong values?

Common causes include missing fp32 accumulation in reductions, incorrect mask handling on non-divisible tails, or mismatched random weights. For operators with nn.Linear or nn.Conv2d, ModelNew must call torch.manual_seed(0) first and recreate modules in the exact original order.

What operations are forbidden in the forward method?

All core computation must live inside @triton.jit kernels. The forward method may only allocate buffers with torch.empty, perform shape operations like view or permute, query metadata like shape and dtype, and launch kernels—torch.matmul, tensor methods, and arithmetic operators are prohibited.

When should the design sketch be overridden during code generation?

When the project template's Layer 1 constraints conflict with the sketch architecture, the Layer 1 hard rules take priority. The generator redesigns the code structure accordingly, preserves non-conflicting sketch details like tile sizes, and annotates each deviation in code comments.

How are large tensors handled when grid size exceeds 65535?

Use an interleaved loop where a fixed grid equal to the core count strides over blocks, or a continuous block method mapping one grid to multiple data chunks. Core counts are queried once in __init__ via the driver device properties API, never inside forward.