Stepping Kernels in cuda-gdb
Breakpoints and per-thread inspection.
Stepping Kernels in cuda-gdb is a free CUDA Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet cuda-gdb
When a kernel misbehaves, cuda-gdb lets you pause it and look inside, just like gdb does for ordinary CPU programs. 🔍
Build with Debug Info
cuda-gdb needs symbols, so compile your kernel with -G to add full device debug information before you debug.
nvcc -g -G vecadd.cu -o vecaddWhy -G Matters
The -G flag disables many optimizations so line numbers and variables stay accurate, which makes stepping through device code trustworthy.
Launch the Debugger
Start a session by handing your binary to cuda-gdb, then type run to execute it under debugger control.
cuda-gdb ./vecaddSet a Breakpoint in a Kernel
Place a breakpoint right inside the kernel by naming the function, so execution pauses the moment a thread reaches it.
(cuda-gdb) break vecAddKernelMany Threads, One Stop
Thousands of threads may hit that breakpoint, so cuda-gdb stops and focuses on one thread at a time for inspection.
Step Line by Line
Use next to run the current line and pause on the following one, walking through your kernel's logic step by step.
(cuda-gdb) nextInspect a Variable
Check what a thread actually computed by asking cuda-gdb to print a local variable while you are paused inside the kernel.
(cuda-gdb) print iSwitch the Focused Thread
Move attention to a specific thread with cuda thread, picking the exact block and lane you want to inspect.
(cuda-gdb) cuda block 0 thread 5Read the Built-in Indices
You can print threadIdx and blockIdx just like normal variables, confirming exactly which data element this thread handles.
(cuda-gdb) print threadIdx.xContinue Execution
When you are done poking around, type continue to resume the program until the next breakpoint or until it finishes.
(cuda-gdb) continueQuick Check
Which compiler flag adds device debug information for cuda-gdb?
Recap
You compiled with -G, set a kernel breakpoint, stepped lines, switched threads, and printed indices. That is the core cuda-gdb loop. 🎉
Frequently asked questions
Is the “Stepping Kernels in cuda-gdb” lesson free?
Yes — the full text of “Stepping Kernels in cuda-gdb” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.
What will I learn in “Stepping Kernels in cuda-gdb”?
Breakpoints and per-thread inspection. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CUDA Academy?
No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Stepping Kernels in cuda-gdb” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CUDA Academy lesson?
Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Stepping Kernels in cuda-gdb
- Finding Leaks with memcheck
- Hunting Races with racecheck
- Catching Sync Errors with synccheck