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-examples-torchgit 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-examples-torch)<a href="https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-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.
<a href="https://agentmods.dev/skills/mindspore-ai/akg/cuda-c-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/cuda-c-examples-torch.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
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.00019 | $0.04204 |
| Opus 5 | $0.00010 | $0.02102 |
| Sonnet 5 | $0.00004 | $0.00841 |
| Haiku 4.5 | $0.00002 | $0.00420 |
Grade A, and why
cuda-c-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.
How it starts
The opening of the file, as written. The whole thing — 579 lines — stays where its author put it; the contents beside it link to each section on GitHub.
PyTorch + CUDA C 示例代码
本 Skill 包含完整的可运行示例代码,展示如何在 PyTorch 中使用 CUDA C 编写高性能 kernel,通过 load_inline JIT 编译集成。
集成模式
所有 CUDA C 内核都通过以下模式与 PyTorch 集成:
import torch
from torch.utils.cpp_extension import load_inline
# 1. CUDA 源代码(内核定义 + 调用函数)
cuda_source = """
#include <torch/extension.h>
#include <cuda_runtime.h>
__global__ void my_kernel(const float* input, float* output, int size) {
// 内核实现
}
torch::Tensor my_kernel_call(torch::Tensor input) {
auto size = input.numel();
auto output = torch::zeros_like(input);
int block_size = 256;
int num_blocks = (size + block_size - 1) / block_size;
my_kernel<<<num_blocks, block_size>>>(
input.data_ptr<float>(), output.data_ptr<float>(), size);
return output;
}
"""
# 2. C++ 函数声明
cpp_source = "torch::Tensor my_kernel_call(torch::Tensor input);"
# 3. JIT 编译
module = load_inline(
name="my_cuda",
cpp_sources=cpp_source,
cuda_sources=cuda_source,
functions=["my_kernel_call"],
verbose=True,
extra_cflags=[""],
extra_ldflags=[""],
)
# 4. 调用
def my_op(x):
return module.my_kernel_call(x)
示例列表
1. 向量加法(Vector Add)
算子类型: Element-wise 关键点:
- 最简单的 CUDA C 内核示例
- 一维索引和边界检查
- 标准五步模式
import torch
from torch.utils.cpp_extension import load_inline
cuda_source = """
#include <torch/extension.h>
#include <cuda_runtime.h>
__global__ void vector_add_kernel(
const float* a, const float* b, float* c, int n
) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < n) {
c[idx] = a[idx] + b[idx];
}
}
torch::Tensor vector_add_call(torch::Tensor a, torch::Tensor b) {
auto n = a.numel();
auto c = torch::empty_like(a);
int block_size = 256;
int num_blocks = (n + block_size - 1) / block_size;
vector_add_kernel<<<num_blocks, block_size>>>(
a.data_ptr<float>(), b.data_ptr<float>(),
c.data_ptr<float>(), n);
return c;
}
"""
cpp_source = "torch::Tensor vector_add_call(torch::Tensor a, torch::Tensor b);"
module = load_inline(
name="vector_add_cuda",
cpp_sources=cpp_source,
cuda_sources=cuda_source,
functions=["vector_add_call"],
verbose=True,
extra_cflags=[""],
extra_ldflags=[""],
)
def vector_add(a, b):
return module.vector_add_call(a, b)
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.
- 10d ago First seen · 579 lines · 19 tokens per session scan A 1c1a40230cda
cuda-c-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 19 tokens to every session and 4,204 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
ax-cpp-ai
Use when writing C++ code with axllm for named deployment profiles, generic provider clients, model selection, OpenAI-compatible calls, Responses, Gemini, Anthropic, routers, and balancers.
ax-cpp-gen
Use when writing C++ code with axllm for AxGen programs, forward calls, indexed multi-sampling, result pickers, streaming, tools, assertions, traces, usage, and output parsing.
ax-cpp-llm
Use when writing C++ code with axllm for using the generated Ax package, factory functions, package docs, examples, and API reference.
ax-cpp-signature
Use when writing C++ code with axllm for string signatures, field descriptors, JSON schema output, validation, and typed tool argument shapes.
ax-cpp-gepa
Use when writing C++ code with axllm for GEPA, Pareto tradeoffs, reflection clients, metric budgets, optimizer state, and artifacts.
cuda-kernels
Provides guidance for writing and benchmarking optimized CUDA kernels for NVIDIA GPUs (H100, A100, T4) targeting HuggingFace diffusers and transformers libraries. Kernels must be kernel-builder/ABI3-compliant: no pybind11, no setup.py, TORCHLIBRARYEXPAND bindings only. Supports models like LTX-Video, Stable Diffusion…