tilelang-ascend-attention

Guides implementation of Attention operators using TileLang Cube and Vector fusion on Ascend hardware.

6|1|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/xchang1121/op-autoresearch --skill tilelang-ascend-attention-xchang1121
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tilelang-ascend-attention
Source: https://github.com/xchang1121/op-autoresearch/tree/main/skills/tilelang-ascend/guides/tilelang-ascend-attention
Command: npx skills add https://github.com/xchang1121/op-autoresearch --skill tilelang-ascend-attention-xchang1121

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Attention operators for Ascend NPUs requires coordinating Cube cores for GEMM and Vector cores for softmax through workspace memory, plus numerically stable online softmax accumulation, which is error-prone without a proven pattern. ## Core Features & Use Cases - Cube+Vector Fusion Paradigm: Explains how QK^T and PV GEMMs run on Cube cores while softmax runs on Vector cores, communicating through workspace tensors declared via workspace_idx. - Online Softmax Accumulation: Documents the running-state algorithm (m_i, sumexp, acc_o) with correction factor decomposition for numerically stable block-wise softmax. - Required pass_configs: Lists the TileLang Ascend pass configurations (AUTO_CV_COMBINE, AUTO_CV_SYNC, AUTO_SYNC, MEMORY_PLANNING) needed for automatic C/V fusion and synchronization. - Use Case: When generating a sparse flash attention kernel for Atlas A2/A3 hardware, follow this guide to structure workspace communication, apply correction factors, and avoid pitfalls like reducing directly on L0C. ## Quick Start Ask the agent to generate a TileLang Ascend attention kernel following this guide, using workspace-based Cube/Vector communication and online softmax accumulation.

Frequently Asked Questions about tilelang-ascend-attention

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

FAQPage Schema
How do I write an Attention kernel in TileLang for Ascend NPU?▼

Structure it as Cube+Vector fusion: QK^T and PV GEMMs run on Cube cores, softmax on Vector cores, with workspace tensors declared via workspace_idx in @tilelang.jit carrying intermediate results between cores. Enable AUTO_CV_COMBINE and AUTO_CV_SYNC pass configs for automatic synchronization.

How does online softmax work in TileLang Ascend attention kernels?▼

Online softmax maintains three running states: m_i (row max), sumexp (row exponential sum), and acc_o (output accumulator). Each KV block updates them using the correction factor exp(m_prev - m_new), which rescales historical sumexp and acc_o for numerical stability.

What pass_configs are required for TileLang Ascend Cube Vector fusion?▼

Enable TL_ASCEND_AUTO_CV_COMBINE, TL_ASCEND_AUTO_CV_SYNC, TL_ASCEND_AUTO_SYNC, and TL_ASCEND_MEMORY_PLANNING in pass_configs. These let Developer mode handle C/V fusion, synchronization, and memory planning automatically instead of manual set_flag/wait_flag.

Which Ascend hardware does TileLang attention support?▼

This guide targets Atlas A2 and Atlas A3 hardware. It uses Ascend-specific features like L0C accumulators, UB memory, and Cube/Vector core partitioning that are specific to these NPU architectures.

Why can't I do softmax reduction directly on L0C in Ascend kernels?▼

L0C is an accumulator buffer that does not support reduce operations. You must T.copy the data from L0C to UB (unified buffer) first, then perform softmax reduction on the Vector core.

How do I handle non-aligned sequence lengths in TileLang attention?▼

Use T.ceildiv to compute block counts instead of assuming SEQ_LEN divides evenly. Never assume exact divisibility when partitioning KV blocks across iterations.