Tilelang ascend kernel

From wenyi-li/awesome-agent-kernel-skills · View interactive version

Tilelang ascend kernel is an AI agent skill from the GitHub repository wenyi-li/awesome-agent-kernel-skills. Use when the user wants to add, modify, debug, or review an xLLM TileLang Ascend kernel or specialization, including Python kernel definitions, generated Ascend-C source, runtime wrapper dispatch, TileLang CMake wiring, and NPU tests.

How to use this skill

Skill file

TileLang Ascend Kernel

When to use

Use this skill when the task involves any of the following in the xLLM repo:

Run build and test commands inside the NPU container.

Run TileLang commands from the xLLM repo root, not from an installed-package environment.

Entry points and TL_ROOT

cd xllm
python -m compiler.tilelang.targets.ascend.kernels.rope \
  --output ../.tmp/rope.cpp
# Expected: [INFO] RoPE output matches torch reference

Primary Reference And Mode Preference

Primary reference:

Use third_party/tilelang-ascend/.agents/skills/tilelang-custom-skill/tilelang-api-best-practices/references/api-tile-ops.md when the task depends on T.tile.xxx semantics such as compare, select, cast, or other vector intrinsics.

Default to Expert mode for xLLM Ascend kernels:

Common Triton To TileLang-Ascend Semantics

Use this table as the quick semantic mapping when translating Triton kernels:

| Triton pattern | TileLang-Ascend pattern | Notes |

| --- | --- | --- |

| x + y, x - y, x * y, x / y | T.tile.add/sub/mul/div | Prefer tile ops in Expert-style vector code instead of hand-written scalar loops. |

| tl.exp(x), tl.log(x), tl.abs(x) | T.tile.exp, T.tile.ln, T.tile.abs | TileLang uses ln, not log. |

| x.to(tl.float32) or tl.cast(...) | T.tile.cast(dst, src, "CAST_NONE", count) | Pick a non-default cast mode only when rounding semantics are required. |

| x <= y, x < y, x >= y, x == y | T.tile.compare(mask, x, y, "LE"/"LT"/"GE"/"EQ") | T.tile.compare produces a bit mask, not a float tensor. |

| tl.where(cond, a, b) | T.tile.select(dst, selMask, a, b, selMode) | API-level match. If cond is a comparison expression such as x <= y, materialize selMask with T.tile.compare(...) first; use the matching VSEL_* mode for tensor-tensor or tensor-scalar selection. |

| tl.full(shape, value, dtype) | allocate buffer + T.tile.fill(dst, value) | Separate allocation from initialization. |

| tl.arange(0, N) | T.tile.createvecindex(dst, 0) or explicit loop indices | Prefer createvecindex only when the kernel truly needs a vector index tensor. |

Rules for semantic-preserving lowering:

New kernel

Follow this order:

  1. Implement build_<kernel>_kernel(...)
  2. Implement generate_source(...)
  3. Declare DISPATCH_SCHEMA and SPECIALIZATIONS
  4. Run TileLang compilation once and inspect registry.inc
  5. Add or update <kernel>_wrapper.cpp
  6. Register the kernel in xllm/core/kernels/npu/tilelang/CMakeLists.txt with:

For wrapper work:

New specialization

Use this path when the kernel logic and wrapper ABI stay the same.

  1. Update the existing kernel's SPECIALIZATIONS
  2. Confirm every runtime dispatch field still matches DISPATCH_SCHEMA
  3. Re-run TileLang compilation
  4. Check that registry.inc contains the new entry
  5. Check that the wrapper's build_runtime_specialization(...) still constructs matching values

Debug generated Ascend-C

When the task is to inspect codegen or compare two kernel implementations, use an isolated output root:

python xllm/compiler/tilelang_launcher.py compile-kernels \
  --target ascend \
  --device a3 \
  --output-root .tmp/tilelang_debug \
  --kernels <kernel> \
  --force

Then inspect:

Use this path before changing wrapper code when you need to understand generated symbols, field order, or ABI.

Validate

Prefer the narrowest command first:

References

Read docs/en/dev_guide/tilelang_ascend_kernel_dev.md for mechanism details.

Use rope as the concrete template:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.