cuda

Debug, profile, and optimize CUDA kernels using nsys, ncu, compute-sanitizer, and PTX documentation.

Updated Mar 4, 2026
One-click install
npx skills add https://github.com/chisuhua/home --skill cuda-chisuhua
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cuda
Source: https://github.com/chisuhua/home/tree/main/.config/opencode/skills/cuda-ptx
Command: npx skills add https://github.com/chisuhua/home --skill cuda-chisuhua

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? GPU performance is counterintuitive and CUDA bugs are hard to diagnose with standard tools. This Skill provides systematic workflows for debugging CUDA kernels, profiling GPU applications, and optimizing performance using NVIDIA's toolchain, plus local searchable copies of the PTX ISA, CUDA Runtime API, and CUDA Driver API documentation. ## Core Features & Use Cases - Non-Interactive Debugging: Catch memory errors, race conditions, and uninitialized reads with compute-sanitizer, get crash backtraces with cuda-gdb batch mode, and inspect binaries with cuobjdump. - Profile-Driven Optimization: Identify timeline bottlenecks with nsys, analyze kernel metrics (occupancy, coalescing, bank conflicts, roofline) with ncu, and add custom instrumentation with NVTX. - Local API Reference: Grep-searchable local copies of PTX ISA 9.1 (405 files), CUDA Runtime API 13.1 (107 files), and CUDA Driver API 13.1 (128 files) for instruction-level and API-level questions. - Use Case: A kernel runs slower than expected. Profile with nsys to find the dominant kernel, deep-dive with ncu to discover 16-way shared memory bank conflicts, apply padding, and verify the 2x speedup with a follow-up profile. ## Quick Start Ask the assistant to debug a failing CUDA kernel or profile a slow GPU program using nsys and ncu.

Frequently Asked Questions about cuda

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I debug a CUDA kernel crash?▼

Start by adding printf in device code guarded by thread index, then run compute-sanitizer --tool memcheck to catch memory errors. If still stuck, use cuda-gdb -batch -ex "run" -ex "bt" for a backtrace, compiled with -g -G -lineinfo.

How do I profile a slow CUDA kernel with nsys and ncu?▼

Run nsys profile -o report ./program first to see the timeline and identify which kernels dominate runtime. Then run ncu --kernel-name "myKernel" --set basic ./program to analyze that kernel's memory throughput, occupancy, and compute utilization.

What is the difference between nsys and ncu profiling?▼

nsys answers where time is spent across the whole system: CPU/GPU interaction, kernel launches, and memory transfers. ncu answers why a specific kernel is slow, providing detailed metrics like occupancy, coalescing, bank conflicts, and roofline analysis.

Why does compute-sanitizer report invalid shared memory writes?▼

An "Invalid __shared__ write out of bounds" error usually means insufficient dynamic shared memory was allocated in the kernel launch configuration, not wrong array indexing. Check the third parameter in the <<<grid, block, smem_size>>> launch syntax.

How do I check for shared memory bank conflicts in CUDA?▼

Profile with ncu using the l1tex__data_bank_conflicts_pipe_lsu_mem_shared metrics divided by wavefront counts; more than one conflict per operation indicates a problem. Fixes include padding shared memory arrays or changing thread-to-data mapping.

When should I use printf instead of cuda-gdb for GPU debugging?▼

Use printf first, before any tool, since it works when debuggers produce inscrutable output. Guard output with conditions like if (idx == 0) to avoid flooding, and print at kernel entry and suspected failure points.