error-handling

error-handling is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 14 tokens per session (2,661 once invoked), scanned A, original, Apache-2.0.

A guide to detecting and reporting errors in GPU code, especially CUDA programs. It covers checks during compilation-related setup, kernel launch, and execution.

In plain words
What is it for?
Checking memory allocation and copies, detecting kernel launch errors, detecting execution errors after synchronization, and wrapping CUDA errors in C++ exceptions.
Why use it?
GPU failures can otherwise appear far away from the operation that caused them. The provided checking patterns report the error location and CUDA's explanation, making failures easier to diagnose.

Skill for Claude CodeCodex

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

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.

agentmods
npx agentmods add skills/mindspore-ai/akg/error-handling
Any agent
npx skills add mindspore-ai/akg --skill error-handling
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 error-handling

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/error-handling.svg)](https://agentmods.dev/skills/mindspore-ai/akg/error-handling)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/error-handling"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/error-handling.svg" alt="Measured on agentmods" height="20"></a>
Per session 14 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,661 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.00014 $0.02661
Opus 5 $0.00007 $0.01331
Sonnet 5 $0.00003 $0.00532
Haiku 4.5 $0.00001 $0.00266

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

Security

Grade A, and why

error-handling 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 6d 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/examples/run_skill/skills/error-handling/SKILL.md · 420 lines

How it starts

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

GPU代码错误处理

概述

良好的错误处理是生产级GPU代码的关键,包括编译时检查、运行时检查和调试支持。

CUDA错误检查

基础宏定义

#define CUDA_CHECK(call) \
do { \
    cudaError_t error = call; \
    if (error != cudaSuccess) { \
        fprintf(stderr, "CUDA Error: %s:%d, ", __FILE__, __LINE__); \
        fprintf(stderr, "code: %d, reason: %s\n", error, \
                cudaGetErrorString(error)); \
        exit(1); \
    } \
} while(0)

// 使用示例
CUDA_CHECK(cudaMalloc(&d_data, size));
CUDA_CHECK(cudaMemcpy(d_data, h_data, size, cudaMemcpyHostToDevice));

Kernel启动错误检查

// Kernel启动
my_kernel<<<grid, block>>>(args);

// 检查启动错误
CUDA_CHECK(cudaGetLastError());

// 检查执行错误
CUDA_CHECK(cudaDeviceSynchronize());

C++异常封装

class CUDAException : public std::runtime_exception {
public:
    CUDAException(cudaError_t error, const char* file, int line)
        : std::runtime_error(
            std::string("CUDA Error: ") + 
            cudaGetErrorString(error) +
            " at " + file + ":" + std::to_string(line)
        ) {}
};

#define CUDA_THROW(call) \
do { \
    cudaError_t error = call; \
    if (error != cudaSuccess) { \
        throw CUDAException(error, __FILE__, __LINE__); \
    } \
} while(0)

// 使用示例
try {
    CUDA_THROW(cudaMalloc(&d_data, size));
    my_kernel<<<grid, block>>>(d_data);
    CUDA_THROW(cudaDeviceSynchronize());
} catch (const CUDAException& e) {
    std::cerr << e.what() << std::endl;
    // 清理资源...
}

Kernel内边界检查

基本边界检查

__global__ void safe_kernel(float* data, int N) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    
    // ✅ 边界检查
    if (idx < N) {
        data[idx] = process(data[idx]);
    }
}

2D边界检查

__global__ void safe_2d_kernel(float* data, int M, int N) {
    int row = blockIdx.y * blockDim.y + threadIdx.y;
    int col = blockIdx.x * blockDim.x + threadIdx.x;
    
    // ✅ 2D边界检查
    if (row < M && col < N) {
        int idx = row * N + col;
        data[idx] = process(data[idx]);
    }
}

断言检查

Read the full file on GitHub · 420 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. 6d ago First seen · 420 lines · 14 tokens per session scan A 02cd95b8f5ee

Subscribe to this mod's changes

error-handling is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 26d ago), licensed Apache-2.0. It adds 14 tokens to every session and 2,661 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