Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cuda

БесплатноБез исполняемых скриптовНе проверен

CUDA kernel development, debugging, and performance optimization for Claude Code. Use when writing, debugging, or optimizing CUDA code, GPU kernels, or…

technillogueот technillogue★ 231 звезда на GitHub19 установок в других каталогах

Об этом скилле

CUDA Programming Skill

Core Philosophy

Measure before guessing. GPU performance is deeply counterintuitive. Profile first, hypothesize second, change third, verify fourth.

Small, isolated changes. CUDA bugs compound. Make one change, test it, commit it. Resist the urge to "fix everything at once."

printf is your strongest tool. When debuggers fail, when tools produce inscrutable output, printf in device code reveals truth. Don't be embarrassed to use it extensively.

Sometimes, stare at the diff. Inscrutable segfaults are common. Tools often don't help. The human approach: minimize the diff, read it carefully, see the bug. This is legitimate and often faster than tooling.

Debugging Workflow

First Response to a Bug

  1. Reproduce minimally — Isolate the failing kernel with smallest possible input
  2. Add printf — Before any tool, add printf in device code to trace execution
  3. Run compute-sanitizer — Catch memory errors non-interactively:
    compute-sanitizer --tool memcheck ./your_program
    compute-sanitizer --tool racecheck ./your_program  # for race conditions
    compute-sanitizer --tool initcheck ./your_program  # uninitialized memory
    
  4. If still stuck, try cuda-gdb non-interactively for backtrace:
    cuda-gdb -batch -ex "run" -ex "bt" ./your_program
    
  5. When tools fail — Minimize the diff between working and broken code. Read it. The bug is in the diff.

printf in Device Code

__global__ void myKernel(float* data, int n) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx == 0) {  // Limit output
        printf("Kernel launched, n=%d, data[0]=%f\n", n, data[0]);
    }
    // ... kernel logic ...
    if (idx < 10) {  // Sample a few threads
        printf("Thread %d: result=%f\n", idx, someValue);
    }
}

Key patterns:

  • Guard with if (idx == 0) or if (idx < N) to avoid output flood
  • Print at kernel entry to confirm launch
  • Print intermediate values at suspected failure points
  • Flush is automatic at kernel completion

compute-sanitizer Quick Reference

Common gotcha: "Invalid shared write... out of bounds" usually means insufficient dynamic shared memory allocation in the kernel launch, not wrong array indexing. Check <<<grid, block, smem_size>>>.

# Memory errors (most common)
compute-sanitizer --tool memcheck ./program

# Other tools: racecheck, initcheck, synccheck
# For detailed options, see references/debugging-tools.md

cuda-gdb Non-Interactive

# Get backtrace on crash
cuda-gdb -batch -ex "run" -ex "bt" ./program

# For breakpoints, thread inspection, see references/debugging-tools.md

Compile with debug info:

nvcc -g -G -lineinfo program.cu -o program

cuobjdump for Binary Inspection

# Dump PTX and SASS
cuobjdump -ptx ./program
cuobjdump -sass ./program

# For resource usage, symbol listing, see references/debugging-tools.md

For complete debugging tool reference: See references/debugging-tools.md for detailed compute-sanitizer options, cuda-gdb workflows, and cuobjdump analysis patterns.

Performance Optimization Workflow

Golden Rule

Never optimize without profiling first. Intuition about GPU bottlenecks is almost always wrong. The profile → fix → verify loop is the actual optimization work, not a preliminary step.

Performance Investigation Steps

  1. Establish baseline — Time the operation, record it
  2. Profile with nsys — Get timeline, identify which kernels matter
  3. Deep-dive with ncu — Analyze specific bottleneck kernels
  4. Hypothesize — Based on metrics, form specific hypothesis
  5. Change one thing — Make a single targeted change
  6. Verify — Re-profile, confirm improvement
  7. Repeat

nsys (Nsight Systems) — Timeline Profiling

Use nsys for: "Where is time being spent?" — CPU/GPU interaction, kernel launch patterns, memory transfers, overall timeline.

# Basic profile
nsys profile -o report ./program
nsys stats report.nsys-rep --report cuda_gpu_kern_sum

# With NVTX markers
nsys profile --trace=cuda,nvtx -o report ./program

# Key reports: cuda_gpu_kern_sum, cuda_api_sum, cuda_gpu_mem_time_sum, nvtx_sum
# For detailed usage, see references/nsys-guide.md

For detailed nsys analysis patterns: See references/nsys-guide.md for timeline interpretation, identifying common bottlenecks, and analysis workflows.

ncu (Nsight Compute) — Kernel Analysis

Use ncu for: "Why is this kernel slow?" — Detailed metrics, roofline, memory analysis, occupancy.

# Profile specific kernel
ncu --kernel-name "myKernel" -o report ./program

# Quick summary to stdout
ncu --set basic ./program

# Sets: basic, full, memory, launch, roofline
# Sections: ComputeWorkloadAnalysis, MemoryWorkloadAnalysis, Occupancy
# For detailed metrics and interpretation, see references/ncu-guide.md

Warning: ncu expert system recommendations c

Полный SKILL.md на GitHub

Установить cuda в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/cuda-driver-docs/INDEX.mdreferences/cuda-driver-docs/data-structures/structcu__dev__sm__resource__group__params.mdreferences/cuda-driver-docs/data-structures/structcuaccesspolicywindow__v1.mdreferences/cuda-driver-docs/data-structures/structcuarraymapinfo__v1.mdreferences/cuda-driver-docs/data-structures/structcuasyncnotificationinfo.mdreferences/cuda-driver-docs/data-structures/structcucheckpointcheckpointargs.mdreferences/cuda-driver-docs/data-structures/structcucheckpointgpupair.mdreferences/cuda-driver-docs/data-structures/structcucheckpointlockargs.mdreferences/cuda-driver-docs/data-structures/structcucheckpointrestoreargs.mdreferences/cuda-driver-docs/data-structures/structcucheckpointunlockargs.mdreferences/cuda-driver-docs/data-structures/structcuctxcigparam.mdreferences/cuda-driver-docs/data-structures/structcuctxcreateparams.mdreferences/cuda-driver-docs/data-structures/structcuda__array3d__descriptor__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__array__descriptor__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__array__memory__requirements__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__array__sparse__properties__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__batch__mem__op__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__child__graph__node__params.mdreferences/cuda-driver-docs/data-structures/structcuda__conditional__node__params.mdreferences/cuda-driver-docs/data-structures/structcuda__event__record__node__params.mdreferences/cuda-driver-docs/data-structures/structcuda__event__wait__node__params.mdreferences/cuda-driver-docs/data-structures/structcuda__ext__sem__signal__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__ext__sem__signal__node__params__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__ext__sem__wait__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__ext__sem__wait__node__params__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__external__memory__buffer__desc__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__external__memory__handle__desc__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__external__memory__mipmapped__array__desc__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__external__semaphore__handle__desc__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__external__semaphore__signal__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__external__semaphore__wait__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__graph__instantiate__params.mdreferences/cuda-driver-docs/data-structures/structcuda__host__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__host__node__params__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__kernel__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__kernel__node__params__v2.mdreferences/cuda-driver-docs/data-structures/structcuda__kernel__node__params__v3.mdreferences/cuda-driver-docs/data-structures/structcuda__launch__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__mem__alloc__node__params__v1.mdreferences/cuda-driver-docs/data-structures/structcuda__mem__alloc__node__params__v2.md

FAQ

Что делает скилл cuda?

CUDA kernel development, debugging, and performance optimization for Claude Code. Use when writing, debugging, or optimizing CUDA code, GPU kernels, or parallel algorithms. Covers non-interactive profiling with nsys/ncu, debugging with cuda-gdb/compute-sanitizer, binary inspection with cuobjdump, and performance analysis workflows. Triggers on CUDA, GPU programming, kernel optimization, nsys, ncu, cuda-gdb, compute-sanitizer, PTX, GPU profiling, parallel performance.

Как установить скилл cuda?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cuda запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cuda с