tilelang-cuda-optimization

tilelang-cuda-optimization is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 64 tokens per session (2,451 once invoked), scanned A, original, Apache-2.0.

A reference guide for optimizing and debugging TileLang programs that run CUDA GPU kernels. TileLang is a programming language for describing GPU computations.

In plain words
What is it for?
Tuning TileLang kernels for element-wise work, matrix multiplication, and reductions; overlapping memory transfers with computation; choosing mixed precision; and investigating performance or execution issues.
Why use it?
It helps choose block sizes, pipeline stages, parallel loops, and data types without relying only on trial and error. It also covers common causes of compilation, runtime, and hardware-limit problems.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Tuning TileLang kernels for element-wise work, matrix multiplication, and reductions; overlapping memory transfers with computation; choosing mixed precision; and investigating performance or execution issues.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/tilelang-cuda-optimization
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add mindspore-ai/akg --skill tilelang-cuda-optimization
Clone the repo
git clone --depth 1 https://github.com/mindspore-ai/akg

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for tilelang-cuda-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-optimization.svg)](https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-optimization)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-optimization"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 64 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,451 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00064 $0.02451
Opus 5 $0.00032 $0.01226
Sonnet 5 $0.00013 $0.00490
Haiku 4.5 $0.00006 $0.00245

Measured 8d ago against content hash 986710310db3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

tilelang-cuda-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

akg_agents/python/akg_agents/op/resources/skills/tilelang-cuda/guides/tilelang-cuda-optimization/SKILL.md · 256 lines

How it starts

The opening of the file, as written. The whole thing — 256 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TileLang CUDA 性能优化指南

1. 性能优化策略

1.1 分块大小选择

  • 原则: 平衡并行度与资源占用
  • 建议: 使用 2 的幂次
  • 常用值: block_M/block_N = 64, 128, 256; block_K = 16, 32, 64
算子类型 推荐分块大小 线程数
Element-wise block = 256-1024 128-256
GEMM block_M=128, block_N=128, block_K=32 128
Reduce block = 256-512 128-256

1.2 软件流水线优化

def pipelined_computation():
    # 选择合适的流水线深度
    num_stages = 3  # 通常 2-4 个阶段效果最好
    
    for ko in T.Pipelined(T.ceildiv(K, block_K), num_stages=num_stages):
        # 重叠内存操作和计算
        T.copy(A[by * block_M, ko * block_K], A_shared)
        T.copy(B[ko * block_K, bx * block_N], B_shared)
        T.gemm(A_shared, B_shared, C_local)

流水线深度选择

  • num_stages=2: 最少的共享内存使用
  • num_stages=3: 通常最优(推荐默认值)
  • num_stages=4: 更多重叠但占用更多共享内存
  • num_stages=5+: 可能超出共享内存限制

1.3 并行化策略

# 1. 细粒度并行
for i, j in T.Parallel(block_M, block_N):
    # 自动映射到线程
    pass

# 2. 向量化优化
for k in T.vectorized(TILE_K):
    A_local[k] = A[bk * BLOCK_K + tk * TILE_K + k]

# 3. 串行循环(必要时使用)
for k in T.serial(block_K):
    # 顺序执行
    pass

1.4 数据类型优化

# 1. 使用混合精度
input_dtype = "float16"    # 输入数据
accum_dtype = "float"      # 累加器使用更高精度

# 2. 类型转换优化
result = A[i].astype(accum_dtype) * B[i].astype(accum_dtype)

# 3. 避免不必要的类型转换(在计算前统一转换)

2. 内存优化策略

2.1 内存层次结构优化

def memory_optimized_matmul(M, N, K, block_M, block_N, block_K):
    @T.prim_func
    def main(A: T.Tensor((M, K), "float16"),
             B: T.Tensor((K, N), "float16"),
             C: T.Tensor((M, N), "float16")):
        
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=128) as (bx, by):
            # 1. 共享内存分配 - 缓存频繁访问的数据
            A_shared = T.alloc_shared((block_M, block_K), "float16")
            B_shared = T.alloc_shared((block_K, block_N), "float16")
            
            # 2. 寄存器片段分配 - 累加和临时存储
            C_local = T.alloc_fragment((block_M, block_N), "float")
            
            # 3. 启用 swizzle 以提高 L2 缓存局部性
            T.use_swizzle(panel_size=10, enable=True)
            
            T.clear(C_local)
            
            # 4. 软件流水线优化内存带宽
            for ko in T.Pipelined(T.ceildiv(K, block_K), num_stages=3):
                T.copy(A[by * block_M, ko * block_K], A_shared)
                T.copy(B[ko * block_K, bx * block_N], B_shared)
                T.gemm(A_shared, B_shared, C_local)
            
            T.copy(C_local, C[by * block_M, bx * block_N])
    
    return main

Read the full file on GitHub · 256 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 256 lines · 64 tokens per session scan A 986710310db3

Subscribe to this mod's changes

tilelang-cuda-optimization is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 28d ago), licensed Apache-2.0. It adds 64 tokens to every session and 2,451 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

trace

Evidence-driven tracing lane that orchestrates competing tracer hypotheses in Claude built-in team mode.

Yeachan-Heo/oh-my-claudecode · 18 tokens

smiles-validation

Strict SMILES validation, structural comparison, and modification verification. Catches invalid LLM-generated molecules.

synthetic-sciences/openscience · 24 tokens

social-physics-filter

Unified boundary enforcement, interpersonal diagnostic, and relational audit engine. Absorbs 40 psychology + 2 social protocols and all relationship case studies.

winstonkoh87/Athena-Public · 34 tokens

cnsplots

Create, revise, and troubleshoot publication-ready scientific plots in Python with cnsplots, including distribution, regression, heatmap, genomics, survival, set, flow, and multi-panel figures. Use when a user asks for cnsplots code, Cell/Nature/Science-style visualization, precise physical figure dimensions…

faridrashidi/cnsplots · 79 tokens

relax-dev-debug

Develop and debug the Relax reinforcement learning project. Use this skill whenever modifying code in the relax/ directory, or running remote training jobs on a Ray cluster for validation. Also use it when the user mentions training, debugging training runs, submitting Ray jobs, or fixing training errors.

redai-infra/Relax · 60 tokens

thinking-scientific-method

When a symptom has several plausible causes, rank falsifiable hypotheses and run the cheapest discriminating observation first; prefer least-assumptive survivors only after evidence fit.

tjboudreaux/cc-thinking-skills · 38 tokens