Tilelang torch profiler

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

Tilelang torch profiler is an AI agent skill from the GitHub repository wenyi-li/awesome-agent-kernel-skills. Profiles TileLang and mixed PyTorch+TileLang workloads with torch.profiler. Invoke when users want traces, operator breakdowns, memory profiling, or a lightweight first-pass performance diagnosis.

How to use this skill

Skill file

TileLang Torch Profiler

Use this skill when the user wants a lightweight, always-available profiling

workflow for TileLang kernels or mixed PyTorch + TileLang programs using

torch.profiler.

This skill is the first-pass profiling tool. It answers:

Tensor-core bound from profiler timing

Keep the analysis grounded in the assets bundled with this skill:

Do not rely on outside docs unless the user explicitly asks for them.

When To Invoke

Invoke this skill when the user asks to:

Also invoke when the user uses phrases such as:

When Not To Invoke

Do not use this skill as the primary tool when the user needs:

profileable

conflicts, or register pressure confirmation

In those cases, collaborate instead of forcing this skill to do everything:

profiler timing alone cannot explain underperformance

Core Workflow

1. Separate compile time from profile time

TileLang JIT compilation must not contaminate the measured trace.

If the first iteration in the trace is far slower, or compile log lines appear

inside the trace, the warmup was insufficient.

2. Capture both CPU and CUDA activity

Use torch.profiler.profile(...) with:

Without CUDA activity, the user only sees host-side launch overhead.

3. Label regions intentionally

Wrap candidate implementations with record_function(...) so the trace and

summary table contain user-meaningful names.

Typical labels:

This makes one-profile comparisons much easier.

4. Read the summary table first

Start triage from:

prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=20)

Use the table to answer:

as the underlying CUDA kernel row

5. Export and inspect a trace

Always offer trace export when the user needs timing structure or overlap:

View in:

Use the trace for:

6. Convert timing into a diagnosis

Use references/bottleneck-classification.md for the decision flow.

High-level rules:

step is source inspection or deeper GPU tooling

7. Corroborate with generated source when needed

When the user asks whether TileLang actually lowered to tensor-core code, use

the generated CUDA source as a quick corroboration step.

Important caution:

related async-path indicators before concluding the kernel is scalar-only

If the source suggests tensor-core lowering but achieved performance is still

poor, timing attribution has reached its limit and the user should escalate to

deeper GPU analysis.

Practical Patterns

Single kernel profile

Use scripts/profile_template.py as the starting point when the user wants a

minimal script that:

Long-running loop or model profile

Prefer scheduled profiling when the user is profiling:

The scheduled profiler avoids over-weighting cold startup behavior and bounds

profiling overhead.

Memory profiling

Turn on memory profiling when the user is debugging:

Use profile_memory=True and export a memory timeline, or advise the newer

CUDA memory snapshot path when allocator-level inspection is required.

Interoperability

This skill should cooperate cleanly with other skills instead of duplicating

their roles.

With `kernel-creator`

Use kernel-creator when the user needs to restructure code so profiling is

easy and reusable. This skill assumes there is a kernel entrypoint that can be

imported and called in a small harness. If that is not true yet:

With `tilelang-wiki`

Use tilelang-wiki when the user's blocker is not "where is the time going?"

but instead:

A common collaboration pattern is:

  1. use tilelang-wiki to ground semantics or operator choice
  2. use kernel-creator to make the kernel importable and profileable
  3. use this skill to attribute runtime and inspect traces

Answering Rules

When helping the user with this skill:

Output Style

A strong answer from this skill usually includes:

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.