cuda-c-patterns

cuda-c-patterns is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 24 tokens per session (3,079 once invoked), scanned A, original, Apache-2.0.

A set of three CUDA C programming patterns for running calculations on NVIDIA graphics processors: element-by-element operations, combining many values into one result, and matrix multiplication. It includes code structures and examples for common mathematical functions.

In plain words
What is it for?
Use it when implementing vector operations such as addition or activation functions, reductions such as combining values, or matrix multiplication in CUDA C.
Why use it?
It gives developers a starting structure for writing these GPU calculations, including indexing and boundary checks. The input does not describe a complete library or automatic code generator.

Skill for Claude CodeCodex

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

Good fit Use it when implementing vector operations such as addition or activation functions…

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-patterns.svg)](https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-patterns)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-patterns"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 24 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,079 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.00024 $0.03079
Opus 5 $0.00012 $0.01540
Sonnet 5 $0.00005 $0.00616
Haiku 4.5 $0.00002 $0.00308

Measured 7d ago against content hash 7627294e09bd, 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-patterns 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-patterns/SKILL.md · 345 lines

How it starts

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

CUDA C 编程模式

1. 向量操作模式

适用于元素级运算:加法、乘法、激活函数等。

标准代码结构

__global__ void vector_add_kernel(
    const float* a, const float* b, float* c, int n_elements
) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    
    if (idx < n_elements) {
        c[idx] = a[idx] + b[idx];
    }
}

适用算子

  • 算术运算: add, mul, sub, div
  • 激活函数: relu, sigmoid, tanh, gelu, silu
  • 数学函数: exp, log, sqrt, pow, abs
  • 类型转换: cast
  • 广播操作: broadcast

关键要点

  • 使用一维索引 blockIdx.x * blockDim.x + threadIdx.x
  • 边界检查 if (idx < n_elements)
  • 简单直接的数据流:加载 → 计算 → 存储
  • 推荐块大小: 256 或 512

ReLU 示例

__global__ void relu_kernel(
    const float* input, float* output, int n
) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < n) {
        output[idx] = fmaxf(input[idx], 0.0f);
    }
}

GELU 示例

__global__ void gelu_kernel(
    const float* input, float* output, int n
) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < n) {
        float x = input[idx];
        // 近似 GELU: 0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3)))
        float cdf = 0.5f * (1.0f + tanhf(0.7978845608f * (x + 0.044715f * x * x * x)));
        output[idx] = x * cdf;
    }
}

多输入逐元素操作

__global__ void fused_multiply_add_kernel(
    const float* a, const float* b, const float* c,
    float* output, int n
) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < n) {
        output[idx] = a[idx] * b[idx] + c[idx];
    }
}

2. 归约模式

适用于求和、最大值、最小值等聚合操作。

标准代码结构(共享内存归约)

__global__ void reduction_sum_kernel(
    const float* input, float* output, int n_elements
) {
    extern __shared__ float sdata[];
    
    int tid = threadIdx.x;
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    
    // 加载数据到共享内存
    sdata[tid] = (idx < n_elements) ? input[idx] : 0.0f;
    __syncthreads();
    
    // 块内归约(树形归约)
    for (int s = blockDim.x / 2; s > 0; s >>= 1) {
        if (tid < s) {
            sdata[tid] += sdata[tid + s];
        }
        __syncthreads();
    }
    
    // 第一个线程写入块级结果
    if (tid == 0) {
        atomicAdd(output, sdata[0]);
    }
}

Read the full file on GitHub · 345 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 · 345 lines · 24 tokens per session scan A 7627294e09bd

Subscribe to this mod's changes

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