tilelang-cuda-examples-torch

tilelang-cuda-examples-torch is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 20 tokens per session (3,293 once invoked), scanned A, original, Apache-2.0.

A collection of runnable examples showing how to write CUDA kernels in TileLang, a Python-like language for GPU code, and use them with PyTorch, a machine-learning library.

In plain words
What is it for?
Use it to study or adapt TileLang implementations of matrix multiplication and similar PyTorch operations, including shared-memory caching, Tensor Cores, pipelining, and mixed-precision accumulation.
Why use it?
It gives you working patterns for common GPU operations without starting from an empty file.

Skill for Claude CodeCodex

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

Good fit Use it to study or adapt TileLang implementations of matrix multiplication and similar PyTorch operations, including shared-memory caching, Tensor Cores, pipelining, and mixed-precision accumulation.

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-examples-torch/github.svg)](https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-examples-torch)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-examples-torch/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-examples-torch

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/tilelang-cuda-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/tilelang-cuda-examples-torch.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 20 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,293 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.00020 $0.03293
Opus 5 $0.00010 $0.01647
Sonnet 5 $0.00004 $0.00659
Haiku 4.5 $0.00002 $0.00329

Measured 10d ago against content hash 389f04e38947, 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-examples-torch 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 10d 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-examples-torch/SKILL.md · 371 lines

How it starts

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

PyTorch + TileLang CUDA 示例代码

本 Skill 包含完整的可运行示例代码,展示如何在 PyTorch 中使用 TileLang CUDA 编写高性能 kernel。

示例列表

1. 矩阵乘法(GEMM)

算子类型: MatMul 关键点:

  • 共享内存缓存输入块
  • T.gemm 利用 Tensor Core
  • 软件流水线 T.Pipelined
  • 混合精度(float32 累加器)
import torch
import tilelang
import tilelang.language as T

@tilelang.jit(out_idx=[-1])
def 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):
            A_shared = T.alloc_shared((block_M, block_K), "float16")
            B_shared = T.alloc_shared((block_K, block_N), "float16")
            C_local = T.alloc_fragment((block_M, block_N), "float")
            
            T.clear(C_local)
            
            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

# 调用方式
def matmul_call(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
    M, K = A.shape
    K2, N = B.shape
    block_M, block_N, block_K = 128, 128, 32
    kernel = matmul(M, N, K, block_M, block_N, block_K)
    C = kernel(A, B)  # out_idx=[-1],只传输入
    return C

2. 矩阵乘法(float32,手动管理输出)

算子类型: MatMul 关键点:

  • 不使用 out_idx,手动管理输出
  • float32 数据类型
  • 需要手动创建输出张量并一起传入
import torch
import tilelang
import tilelang.language as T

@tilelang.jit
def square_matrix_multiply(M, N, K, block_M, block_N, block_K):
    @T.prim_func
    def main(
            A: T.Tensor((M, K), "float32"),
            B: T.Tensor((K, N), "float32"),
            C: T.Tensor((M, N), "float32")):
        with T.Kernel(T.ceildiv(N, block_N), T.ceildiv(M, block_M), threads=128) as (bx, by):
            A_shared = T.alloc_shared((block_M, block_K), "float32")
            B_shared = T.alloc_shared((block_K, block_N), "float32")
            C_local = T.alloc_fragment((block_M, block_N), "float")
            
            T.clear(C_local)

            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

def square_matrix_multiply_call(A: torch.Tensor, B: torch.Tensor) -> torch.Tensor:
    N = A.size(0)
    block_M, block_N, block_K = 128, 128, 32
    # 不使用 out_idx 时,需要手动创建输出张量
    C = torch.empty_like(A)
    kernel = square_matrix_multiply(N, N, N, block_M, block_N, block_K)
    kernel(A, B, C)  # 传入所有参数包括输出
    return C

Read the full file on GitHub · 371 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. 10d ago First seen · 371 lines · 20 tokens per session scan A 389f04e38947

Subscribe to this mod's changes

tilelang-cuda-examples-torch is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 20 tokens to every session and 3,293 once invoked, about $0.0001 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.