tilelang-api-best-practices

Provide best practices for writing Ascend NPU kernels with TileLang API.

346|151|Updated Sep 25, 2025
One-click install
npx skills add https://github.com/tile-ai/tilelang-ascend --skill tilelang-api-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tilelang-api-best-practices
Source: https://github.com/tile-ai/tilelang-ascend/tree/main/.agents/skills/tilelang-custom-skill/tilelang-api-best-practices
Command: npx skills add https://github.com/tile-ai/tilelang-ascend --skill tilelang-api-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides concise, structured best-practice guidance for using the TileLang Ascend API to write correct, efficient, and debuggable Ascend NPU kernels, reducing common mistakes in memory placement, data movement, synchronization, and scheduling.

Core Features & Use Cases

  • API Index: Organized reference for kernel definition, memory allocation primitives, data copy semantics, compute primitives (GEMM, MMA, reductions), and tile-level vector operations.
  • Scheduling & Synchronization: Patterns and examples for T.Pipelined, T.Persistent, barrier and cross-core sync usage to enable pipelining and multi-core coordination.
  • Debugging & Performance: Guidance on device-side printf, dump tensor, msProf profiling, and pass_config tuning for memory planning and auto-sync.
  • Use Case: Implement a high-performance GEMM or attention kernel by following the kernel-memory, compute, and schedule-sync references to allocate shared/fragment buffers, prefetch with pipelining, apply T.gemm_v0 or T.mma, and validate with device dumps and profiling.

Quick Start

Implement a GEMM kernel by defining a prim_func, allocating shared and fragment buffers, using copy to move blocks into L1/L0, invoking gemm operations with correct init semantics, and applying pipelined or persistent scheduling for performance.

Frequently Asked Questions about tilelang-api-best-practices

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

FAQPage Schema
How do I optimize Ascend NPU kernels for memory hierarchy and pipelined prefetching?

Ascend NPU kernel optimization requires allocating shared/fragment buffers, using copy semantics to move data into L1/L0, and applying T.Pipelined or T.Persistent scheduling for multi-core coordination and prefetching.

What is the correct way to use memory allocation primitives in TileLang Ascend API?

The correct way to use memory allocation primitives is to define a prim_func, allocate shared and fragment buffers appropriately, and manage data copy semantics to move tensor blocks into L1/L0 memory levels before invoking compute operations.

How do I implement cross-core synchronization when writing Ascend NPU kernels?

Implement cross-core synchronization by using barrier and cross-core sync primitives provided by the TileLang Ascend API. These primitives enable safe multi-core coordination alongside T.Persistent scheduling patterns for concurrent kernel execution.

Can I use T.gemm_v0 and T.mma for high-performance GEMM operations on Ascend NPU?

Yes, you can use T.gemm_v0 or T.mma to implement high-performance GEMM operations. You must apply correct init semantics for matrix multiplication and ensure data is prefetched into the correct memory hierarchy levels beforehand.

What's the best way to debug and profile Ascend NPU kernel performance?

The best way to debug and profile Ascend NPU kernels is using device-side printf, dumping tensors for validation, and leveraging msProf profiling alongside pass_config tuning for memory planning and auto-sync optimization.

Does the TileLang Ascend API support element-wise and reduction tile-level vector operations?

Yes, the TileLang Ascend API supports element-wise operations, reductions, and tile-level vector operations. It provides structured compute primitives that integrate with kernel definition decorators for correct and efficient hardware-specific tile execution.