Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Expert skill for GPU debugging using CUDA-GDB and NVIDIA Compute Sanitizer. Detect memory errors, race conditions, uninitialized memory access, validate atomic operations, analyze kernel synchronization issues, and generate debugging reports with recommendations.
.claude/skills/a5c-ai-cuda-debugging/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 1775% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 91% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 91% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 121% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 108% | 0% |
You are cuda-debugging - a specialized skill for GPU debugging and error detection using NVIDIA's Compute Sanitizer and CUDA-GDB tools. This skill provides expert capabilities for identifying and resolving correctness issues in CUDA programs.
This skill enables AI-powered GPU debugging operations including:
Detect memory access errors and leaks:
bash# Basic memory check compute-sanitizer --tool memcheck ./cuda_program # With detailed error reporting compute-sanitizer --tool memcheck --report-api-errors all ./cuda_program # Log errors to file compute-sanitizer --tool memcheck --log-file memcheck.log ./cuda_program # Check for memory leaks compute-sanitizer --tool memcheck --leak-check full ./cuda_program # Track allocations compute-sanitizer --tool memcheck --track-alloc-dealloc yes ./cuda_program
Common memory errors detected:
Detect shared memory data access hazards:
bash# Basic race check compute-sanitizer --tool racecheck ./cuda_program # With detailed analysis compute-sanitizer --tool racecheck --racecheck-report all ./cuda_program # Save analysis to file compute-sanitizer --tool racecheck --save racecheck.nvsanreport ./cuda_program # Analyze previous run compute-sanitizer --tool racecheck --import racecheck.nvsanreport --print-analysis ./cuda_program
Race condition types detected:
Detect uninitialized global memory access:
bash# Basic initcheck compute-sanitizer --tool initcheck ./cuda_program # Track all memory accesses compute-sanitizer --tool initcheck --track-unused-memory yes ./cuda_program # With error details compute-sanitizer --tool initcheck --show-backtrace yes ./cuda_program
Detect illegal synchronization in CUDA code:
bash# Basic synccheck compute-sanitizer --tool synccheck ./cuda_program # With detailed reporting compute-sanitizer --tool synccheck --show-backtrace all ./cuda_program
Synchronization issues detected:
__syncthreads() callsInteractive debugging with CUDA-GDB:
bash# Launch CUDA-GDB cuda-gdb ./cuda_program # Common debugging commands (cuda-gdb) set cuda memcheck on # Enable memory checking (cuda-gdb) set cuda break_on_launch # Break at kernel launch (cuda-gdb) break kernel_name # Set breakpoint at kernel (cuda-gdb) run # Start execution # Thread navigation (cuda-gdb) info cuda threads # List all GPU threads (cuda-gdb) cuda thread (0,0,0) (0,0,0) # Switch to specific thread (cuda-gdb) cuda block # Show current block (cuda-gdb) cuda kernel # Show current kernel # Memory inspection (cuda-gdb) print *d_array@10 # Print device array (cuda-gdb) print __shared_memory__ # Inspect shared memory (cuda-gdb) info cuda devices # List CUDA devices # Stepping through code (cuda-gdb) cuda step # Step one warp instruction (cuda-gdb) cuda next # Step over function calls (cuda-gdb) continue # Continue execution
cuda// Add bounds checking to kernel __global__ void safeKernel(float* data, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; // Bounds check if (idx >= n) return; // Safe access data[idx] = data[idx] * 2.0f; }
cuda__global__ void reductionKernel(float* input, float* output, int n) { __shared__ float sdata[256]; int tid = threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x; // Load to shared memory sdata[tid] = (idx < n) ? input[idx] : 0.0f; __syncthreads(); // Required before reading shared memory // Reduction in shared memory for (int s = blockDim.x / 2; s > 0; s >>= 1) { if (tid < s) { sdata[tid] += sdata[tid + s]; } __syncthreads(); // Required after each reduction step } if (tid == 0) { output[blockIdx.x] = sdata[0]; } }
cuda// Validate atomic operations __global__ void atomicTest(int* counter, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // Use atomicAdd for thread-safe increment atomicAdd(counter, 1); } } // Verify result on host int h_counter; cudaMemcpy(&h_counter, d_counter, sizeof(int), cudaMemcpyDeviceToHost); assert(h_counter == n); // Should equal number of threads
Comprehensive CUDA error checking:
cuda// Error checking macro #define CUDA_CHECK(call) \ do { \ cudaError_t err = call; \ if (err != cudaSuccess) { \ fprintf(stderr, "CUDA Error at %s:%d: %s\n", \ __FILE__, __LINE__, cudaGetErrorString(err)); \ exit(EXIT_FAILURE); \ } \ } while(0) // Usage CUDA_CHECK(cudaMalloc(&d_data, size)); CUDA_CHECK(cudaMemcpy(d_data, h_data, size, cudaMemcpyHostToDevice)); // Check for kernel errors myKernel<<<blocks, threads>>>(d_data, n); CUDA_CHECK(cudaGetLastError()); // Check launch errors CUDA_CHECK(cudaDeviceSynchronize()); // Check execution errors
Generate comprehensive debugging reports:
bash# Full debugging session compute-sanitizer --tool memcheck \ --report-api-errors all \ --show-backtrace yes \ --log-file debug_report.txt \ ./cuda_program 2>&1 | tee debug_output.log # Summary report generation echo "=== CUDA Debugging Report ===" > debug_summary.md echo "Date: $(date)" >> debug_summary.md echo "" >> debug_summary.md echo "## Memory Check Results" >> debug_summary.md compute-sanitizer --tool memcheck ./cuda_program 2>&1 >> debug_summary.md echo "" >> debug_summary.md echo "## Race Check Results" >> debug_summary.md compute-sanitizer --tool racecheck ./cuda_program 2>&1 >> debug_summary.md
This skill can leverage the following MCP servers:
| Server | Description | Installation | |--------|-------------|--------------| | claude-debugs-for-you | Interactive debugging via Claude | GitHub |
makefile# Debug build flags DEBUG_FLAGS = -G -lineinfo -Xcompiler -rdynamic -O0 # Release build with symbols RELEASE_FLAGS = -O3 -lineinfo # Compile for debugging nvcc $(DEBUG_FLAGS) -o program_debug program.cu # Compile for profiling (with symbols) nvcc $(RELEASE_FLAGS) -o program_release program.cu
| Issue | Symptom | Solution | |-------|---------|----------| | Uncoalesced access | Memory errors at specific offsets | Align data to 128 bytes | | Missing sync | Intermittent wrong results | Add __syncthreads() | | Out of bounds | Access violation errors | Add bounds checking | | Uninitialized shared memory | Random values | Initialize before use |
This skill integrates with the following processes:
gpu-debugging-techniques.js - Comprehensive debugging workflowsgpu-performance-regression-testing.js - Correctness verificationatomic-operations-synchronization.js - Synchronization validationWhen executing operations, provide structured output:
json{ "operation": "memory-check", "status": "errors_found", "tool": "compute-sanitizer", "summary": { "total_errors": 3, "memory_errors": 2, "leak_errors": 1 }, "errors": [ { "type": "Invalid __global__ read", "size": 4, "address": "0x7f1234567890", "location": { "file": "kernel.cu", "line": 42, "function": "processData" }, "thread": "(128, 0, 0)", "block": "(3, 0, 0)" } ], "recommendations": [ "Add bounds check at line 42", "Verify array size matches grid dimensions" ], "artifacts": ["debug_report.txt", "memcheck.log"] }
| Error | Cause | Resolution | |-------|-------|------------| | Invalid __global__ read | Out-of-bounds access | Add bounds checking | | Potential WAW hazard | Missing synchronization | Add __syncthreads() | | Memory leak | Missing cudaFree | Free all allocations | | Uninitialized __global__ read | Reading before write | Initialize memory |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 10,777 | 20,353 | +89% | 1 | 1 | 0% | 271 | 5,082 | +1775% | 0 | 0 | — |
case-02 | fail→pass | 16,700 | 15,532 | -7% | 1 | 1 | 0% | 2,803 | 5,344 | +91% | 0 | 0 | — |
case-03 | fail→pass | 20,529 | 11,620 | -43% | 1 | 1 | 0% | 2,677 | 5,119 | +91% | 0 | 0 | — |
case-04 | fail→pass | 12,146 | 5,179 | -57% | 1 | 1 | 0% | 1,689 | 3,737 | +121% | 0 | 0 | — |
case-05 | fail→pass | 14,510 | 8,062 | -44% | 1 | 1 | 0% | 1,945 | 4,037 | +108% | 0 | 0 | — |
case-06 | fail→pass | 11,810 | 7,191 | -39% | 1 | 1 | 0% | 827 | 3,791 | +358% | 0 | 0 | — |
case-07 | fail→pass | 11,183 | 6,088 | -46% | 1 | 1 | 0% | 1,553 | 3,747 | +141% | 0 | 0 | — |
case-08 | pass→pass | 7,241 | 5,548 | -23% | 1 | 1 | 0% | 983 | 3,529 | +259% | 0 | 0 | — |
case-09 | fail→pass | 6,153 | 4,031 | -34% | 1 | 1 | 0% | 881 | 3,573 | +306% | 0 | 0 | — |
case-10 | pass→pass | 18,146 | 8,204 | -55% | 1 | 1 | 0% | 2,385 | 4,231 | +77% | 0 | 0 | — |
case-11 | pass→pass | 13,000 | 10,124 | -22% | 1 | 1 | 0% | 1,852 | 4,126 | +123% | 0 | 0 | — |
case-12 | pass→pass | 10,923 | 12,155 | +11% | 1 | 1 | 0% | 1,667 | 4,763 | +186% | 0 | 0 | — |
case-13 | pass→pass | 12,808 | 8,639 | -33% | 1 | 1 | 0% | 1,864 | 4,226 | +127% | 0 | 0 | — |
case-14 | pass→pass | 4,464 | 6,718 | +50% | 1 | 1 | 0% | 691 | 3,970 | +475% | 0 | 0 | — |
case-15 | pass→pass | 8,119 | 6,812 | -16% | 1 | 1 | 0% | 1,181 | 4,210 | +256% | 0 | 0 | — |
case-16 | fail→pass | 13,154 | 11,142 | -15% | 1 | 1 | 0% | 1,993 | 5,063 | +154% | 0 | 0 | — |
case-17 | fail→pass | 15,637 | 6,690 | -57% | 1 | 1 | 0% | 2,410 | 3,868 | +60% | 0 | 0 | — |
case-18 | fail→pass | 19,589 | 19,665 | +0% | 1 | 1 | 0% | 3,319 | 5,621 | +69% | 0 | 0 | — |
case-19 | fail→fail | 17,504 | 20,587 | +18% | 1 | 1 | 0% | 2,529 | 6,028 | +138% | 0 | 0 | — |
case-20 | pass→fail | 5,014 | 8,755 | +75% | 1 | 1 | 0% | 859 | 4,156 | +384% | 0 | 0 | — |
case-21 | fail→pass | 15,979 | 13,666 | -14% | 1 | 1 | 0% | 2,298 | 4,845 | +111% | 0 | 0 | — |
case-22 | pass→pass | 9,731 | 11,188 | +15% | 1 | 1 | 0% | 1,940 | 4,534 | +134% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +50 percentage points is the difference between those two pass rates over the 21 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.