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.
npx skills add mindspore-ai/akg --skill cuda-c-optimizationgit clone --depth 1 https://github.com/mindspore-ai/akgWrote 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.
[](https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-optimization)<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>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.
| Model | Per session | Once 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 |
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.
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 大小
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.
- 7d ago First seen · 246 lines · 20 tokens per session scan A fe6bae817ebd
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.
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.
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…
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.
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…
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…
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.