cuda-c-optimization

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

A guide for improving CUDA C programs, which run computations on NVIDIA GPUs. It covers GPU memory access, thread-block sizing, numerical stability, and debugging.

In plain words
What is it for?
Use it when tuning element-wise operations, reductions, matrix multiplication, image processing, or other CUDA kernels.
Why use it?
It helps identify common causes of slow or unreliable GPU code, such as inefficient memory access, shared-memory conflicts, and threads taking different branches.

Skill for Claude CodeCodex

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

Good fit Use it when tuning element-wise operations, reductions, matrix multiplication, image processing, or…

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-optimization.svg)](https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-optimization)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-optimization"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-optimization.svg" alt="Measured on agentmods" 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 2,269 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.
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.02269
Opus 5 $0.00010 $0.01135
Sonnet 5 $0.00004 $0.00454
Haiku 4.5 $0.00002 $0.00227

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

Security

Grade A, and why

cuda-c-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 7d 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/cuda-c/guides/cuda-c-optimization/SKILL.md · 246 lines

How it starts

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

CUDA C 性能优化指南

1. 性能优化策略

1.1 块大小选择策略

  • 基础: 使用 2 的幂(128, 256, 512, 1024)
  • 推荐: 256 或 512 线程每块
  • 限制: 每块最多 1024 线程(大多数 GPU)
  • 调优: 平衡并行度与资源占用,避免过大或过小
算子类型 推荐块大小 网格配置
Element-wise 256 / 512 一维
Reduce 256 一维 + 共享内存
MatMul dim3(16,16) 或 dim3(32,32) 二维
图像处理 dim3(16,16) 二维

1.2 内存访问优化

合并访问 (Coalesced Access)

连续线程访问连续内存地址,GPU 将多次请求合并为少量内存事务。

// ✅ 合并访问(连续线程访问连续地址)
__global__ void coalesced(float* data, int n) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < n) {
        data[idx] = data[idx] * 2.0f;  // 连续访问
    }
}

// ❌ 非合并访问(跳跃访问)
__global__ void strided(float* data, int n, int stride) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx * stride < n) {
        data[idx * stride] = data[idx * stride] * 2.0f;  // 跳跃访问
    }
}
对齐访问

数据按 128 字节边界对齐,提高内存带宽利用率。

避免 Bank 冲突

共享内存由 32 个 bank 组成,避免同一 warp 内多个线程访问同一 bank。

// ✅ 无 bank 冲突
__shared__ float s[256];
s[threadIdx.x] = input[idx];  // 连续线程访问连续 bank

// ❌ bank 冲突
s[threadIdx.x * 32] = input[idx];  // 所有线程访问同一 bank

1.3 计算优化

避免分支发散

同一 warp 内的 32 个线程应执行相同的控制路径。

// ❌ 分支发散:同一 warp 内线程走不同路径
if (threadIdx.x % 2 == 0) {
    // 偶数线程路径
} else {
    // 奇数线程路径
}

// ✅ 使用条件赋值替代分支
float result = (threadIdx.x % 2 == 0) ? value_a : value_b;
使用内置快速数学函数
// 标准精度
float r = expf(x);

// ✅ 快速版本(精度略低但速度更快)
float r = __expf(x);
float r = __logf(x);
float r = __sinf(x);
减少原子操作

尽量使用块内归约代替全局原子操作。

// ❌ 大量原子操作
atomicAdd(&global_sum, local_val);

// ✅ 先块内归约,再原子写回
__shared__ float sdata[256];
sdata[tid] = local_val;
__syncthreads();

// 块内归约
for (int s = blockDim.x / 2; s > 0; s >>= 1) {
    if (tid < s) sdata[tid] += sdata[tid + s];
    __syncthreads();
}

// 只有一次原子操作
if (tid == 0) atomicAdd(&global_sum, sdata[0]);

1.4 Occupancy 优化

  • 寄存器使用: 减少每个线程的寄存器使用量,增加并发 block 数
  • 共享内存: 合理使用共享内存,不超过硬件限制
  • Block 大小: 选择能整除 SM 最大线程数的 block 大小

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

Subscribe to this mod's changes

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

Related

Other skills, from other repositories

cuda-c-optimization

A set of guidance for optimizing CUDA C programs, keeping numerical results stable, and investigating bugs. CUDA C is used to run parts of programs on NVIDIA graphics processors.

wenyi-li/awesome-agent-kernel-skills · 20 tokens

cpp-pro

Writes, optimizes, and debugs C++ applications using modern C++20/23 features, template metaprogramming, and high-performance systems techniques. Use when building or refactoring C++ code requiring concepts, ranges, coroutines, SIMD optimization, or careful memory management — or when addressing performance…

Jeffallan/claude-skills · 79 tokens

memory-safety-patterns

Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs.

rmyndharis/antigravity-skills · 45 tokens

cpp

Comprehensive C/C++ programming reference covering everything from C11-C23 and C++11-C++23, system programming, CUDA GPU computing, debugging tools, Rust interop, and advanced topics. Use for: C/C++ questions, C/C++ interview preparation, modern language features, RAII/memory management, templates/generics, CUDA…

crazyguitar/cppcheatsheet · 0 tokens

cutlass-skill

Write, debug, and optimize CUTLASS, CuTe, and CuTeDSL GPU kernels from local upstream source, examples, and headers. Use when the task explicitly involves CUTLASS/CuTe/CuTeDSL, cute::Layout, cute::Tensor, TiledMMA, TiledCopy, CollectiveBuilder, CollectiveMainloop, CollectiveEpilogue, GemmUniversal, KernelSchedule…

slowlyC/agent-gpu-skills · 137 tokens

cpp-debugging

Use when a C++ failure involves memory lifetime, undefined behavior, native crashes, or debugger-only state — debug with symbols, sanitizers, and platform-native debuggers before patching symptoms.

drvoss/everything-copilot-cli · 42 tokens