tilelang-cuda-synchronization

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

A set of rules for synchronizing CUDA threads in TileLang, especially when they share memory or work together. It explains how to avoid deadlocks, where threads wait forever for one another.

In plain words
What is it for?
Use it when writing or reviewing TileLang CUDA kernels that use shared memory, thread cooperation, synchronization, or reductions.
Why use it?
Incorrect synchronization in conditional code, loops, or manual reductions can make a kernel hang. The rules show how all threads must reach synchronization points safely.

Skill for Claude CodeCodex

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

Good fit Use it when writing or reviewing TileLang CUDA kernels that use shared memory, thread cooperation, synchronization, or reductions.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/tilelang-cuda-synchronization
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-synchronization
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-synchronization

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-synchronization/github.svg)](https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-synchronization)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-synchronization"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-synchronization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for tilelang-cuda-synchronization

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-synchronization"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-synchronization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 62 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,208 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.00062 $0.02208
Opus 5 $0.00031 $0.01104
Sonnet 5 $0.00012 $0.00442
Haiku 4.5 $0.00006 $0.00221

Measured 9d ago against content hash 08ac4b07e61a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

tilelang-cuda-synchronization 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 9d 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-synchronization/SKILL.md · 291 lines

How it starts

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

TileLang CUDA 同步和线程安全

本文档详细说明 TileLang 中 T.sync_threads() 的使用规范和线程安全最佳实践。同步问题是 TileLang 编程中最常见也是最危险的错误来源


1. T.sync_threads() 使用规范

⚠️ 严格禁止的使用场景

1.1 条件分支中的同步
# ❌ 错误示例 - 会导致死锁
if condition:
    T.sync_threads()  # 只有部分线程执行,其他线程永远等待

# ✅ 正确做法 - 所有线程都执行同步
T.sync_threads()
if condition:
    # 同步后的操作
1.2 循环中的条件同步
# ❌ 错误示例 - 死锁风险
for i in range(n):
    if tid < threshold:
        T.sync_threads()  # 死锁风险

# ✅ 正确做法
for i in range(n):
    T.sync_threads()  # 所有线程都同步
    if tid < threshold:
        # 同步后的操作
1.3 共享内存分配后的条件同步
# ❌ 错误示例
if tid < N:
    shared_mem = T.alloc_shared((N,), dtype)
    T.sync_threads()  # 只有部分线程分配了共享内存

# ✅ 正确做法
shared_mem = T.alloc_shared((N,), dtype)
T.sync_threads()
if tid < N:
    # 使用共享内存

2. ❌ 绝对禁止:手动归约

手动归约是导致线程卡死的最常见原因。必须使用内置归约函数

手动归约的危险

# ❌ 绝对禁止:手动归约会导致线程卡死
while stride > 0:
    if tid < stride:
        shared[tid] += shared[tid + stride]
    T.sync_threads()  # 死锁风险,线程卡死
    stride //= 2

# ❌ 绝对禁止:条件分支中的同步
if condition:
    T.sync_threads()  # 死锁风险

# ❌ 绝对禁止:循环中的条件同步
for i in range(n):
    if tid < threshold:
        T.sync_threads()  # 死锁风险

症状识别

  • UTL(GPU 利用率)打满但 MEM 低: 通常是线程卡死在同步点
  • 内核永远不返回: 死锁导致的无限等待
  • 性能极差: 不当的同步模式导致串行化

3. ✅ 正确的同步模式

3.1 在共享内存操作前后同步

# ✅ 写入共享内存后同步
shared_mem[tid] = value
T.sync_threads()  # 确保所有写入完成

# ✅ 读取共享内存前同步
T.sync_threads()  # 确保所有写入完成
result = shared_mem[tid]

3.2 确保所有线程参与同步

# ✅ 正确的同步模式
T.sync_threads()  # 所有线程都必须执行
# 后续操作

3.3 避免不必要的同步

# ❌ 过度同步
for i in range(n):
    T.sync_threads()  # 每次迭代都同步,开销大

# ✅ 只在必要时同步
# 只在数据依赖需要时添加同步

4. ✅ 推荐的内置函数(替代手动同步)

4.1 内置归约函数

# ✅ 推荐:内置归约函数,无需手动同步
T.reduce_sum(input_tensor, output_tensor, dim=axis)     # 求和归约
T.reduce_max(input_tensor, output_tensor, dim=axis)     # 最大值归约
T.reduce_min(input_tensor, output_tensor, dim=axis)     # 最小值归约
T.reduce_mean(input_tensor, output_tensor, dim=axis)    # 平均值归约

Read the full file on GitHub · 291 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. 9d ago First seen · 291 lines · 62 tokens per session scan A 08ac4b07e61a

Subscribe to this mod's changes

tilelang-cuda-synchronization is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 29d ago), licensed Apache-2.0. It adds 62 tokens to every session and 2,208 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

ai-loop

Runs a bounded spec-build-review development loop with explicit scope, stop conditions, and human approval gates for risky or ambiguous work.

sickn33/agentic-awesome-skills · 28 tokens

software-implementation

Write the minimal production code needed to make failing TDD tests pass (Green phase of red-green-refactor). Use when failing tests exist and production code must be written or modified to satisfy them. Reads and interprets failing test output, discovers codebase conventions (module layout, naming, import patterns…

stencila/stencila · 124 tokens

project-execution

Executes implementation plans with progress tracking, checkpoint validation, and quality gates. Use after planning is complete and tasks are ready to implement.

athola/claude-night-market · 31 tokens

architecture-paradigms

Selects and routes to the right architecture paradigm. Use when choosing patterns for a new system or comparing trade-offs before making architecture decisions.

athola/claude-night-market · 33 tokens

choosing-and-executing

Provides a toolkit for moving from deliberation to commitment and from commitment to results. Covers the cost of decision paralysis, the 70% rule for when to stop gathering information, implementation planning after the choice is made, transparency as a trust mechanism, handling challenges to decisions, and combating…

fatihguner/foreman · 118 tokens

kotter-change-model

Guides organizational change initiatives using Kotter's eight-step model: creating urgency, forming a guiding coalition, developing a vision, communicating the vision, empowering action, generating short-term wins, consolidating gains, and anchoring changes in culture. Use when leading a strategic pivot, implementing…

fatihguner/foreman · 90 tokens